def _imagpart(self, x): """Function returning the imaginary part of a result.""" x_call_oop = x._call_out_of_place def imagpart_oop(x): return np.asarray(x_call_oop(x), dtype=self.out_dtype).imag if is_real_dtype(self.out_dtype): return self.zero() else: rdtype = real_dtype(self.out_dtype) rspace = self.astype(rdtype) return rspace.element(imagpart_oop)
def _imagpart(self, x): """Function returning the imaginary part of a result.""" x_call_oop = x._call_out_of_place def imagpart_oop(x): return np.asarray(x_call_oop(x), dtype=self.out_dtype).imag if is_real_dtype(self.out_dtype): return self.zero() else: rdtype = real_dtype(self.out_dtype) rspace = self.astype(rdtype) return rspace.element(imagpart_oop)
def _realpart(self, x): """Function returning the real part of a result.""" x_call_oop = x._call_out_of_place def realpart_oop(x): return np.asarray(x_call_oop(x), dtype=self.out_dtype).real if is_real_dtype(self.out_dtype): return x else: rdtype = real_dtype(self.out_dtype) rspace = self.astype(rdtype) return rspace.element(realpart_oop)
def _realpart(self, x): """Function returning the real part of a result.""" x_call_oop = x._call_out_of_place def realpart_oop(x): return np.asarray(x_call_oop(x), dtype=self.out_dtype).real if is_real_dtype(self.out_dtype): return x else: rdtype = real_dtype(self.out_dtype) rspace = self.astype(rdtype) return rspace.element(realpart_oop)
def __init__(self, size, dtype): """Initialize a new instance. Parameters ---------- size : non-negative int Number of entries in a tuple. dtype : Data type for each tuple entry. Can be provided in any way the `numpy.dtype` function understands, most notably as built-in type, as one of NumPy's internal datatype objects or as string. Only scalar data types (numbers) are allowed. """ NtuplesBase.__init__(self, size, dtype) if not is_scalar_dtype(self.dtype): raise TypeError('{!r} is not a scalar data type'.format(dtype)) if is_real_dtype(self.dtype): field = RealNumbers() self.__is_real = True self.__real_dtype = self.dtype self.__real_space = self try: self.__complex_dtype = complex_dtype(self.dtype) except ValueError: self.__complex_dtype = None self.__complex_space = None # Set in first call of astype else: field = ComplexNumbers() self.__is_real = False try: self.__real_dtype = real_dtype(self.dtype) except ValueError: self.__real_dtype = None self.__real_space = None # Set in first call of astype self.__complex_dtype = self.dtype self.__complex_space = self self.__is_floating = is_floating_dtype(self.dtype) LinearSpace.__init__(self, field)
def __init__(self, size, dtype): """Initialize a new instance. Parameters ---------- size : non-negative int Number of entries in a tuple. dtype : Data type for each tuple entry. Can be provided in any way the `numpy.dtype` function understands, most notably as built-in type, as one of NumPy's internal datatype objects or as string. Only scalar data types (numbers) are allowed. """ NtuplesBase.__init__(self, size, dtype) if not is_scalar_dtype(self.dtype): raise TypeError('{!r} is not a scalar data type'.format(dtype)) if is_real_dtype(self.dtype): field = RealNumbers() self.__is_real = True self.__real_dtype = self.dtype self.__real_space = self try: self.__complex_dtype = complex_dtype(self.dtype) except ValueError: self.__complex_dtype = None self.__complex_space = None # Set in first call of astype else: field = ComplexNumbers() self.__is_real = False try: self.__real_dtype = real_dtype(self.dtype) except ValueError: self.__real_dtype = None self.__real_space = None # Set in first call of astype self.__complex_dtype = self.dtype self.__complex_space = self self.__is_floating = is_floating_dtype(self.dtype) LinearSpace.__init__(self, field)
def __init__(self, domain, field=None, out_dtype=None): """Initialize a new instance. Parameters ---------- domain : `Set` The domain of the functions field : `Field`, optional The range of the functions, usually the `RealNumbers` or `ComplexNumbers`. If not given, the field is either inferred from ``out_dtype``, or, if the latter is also ``None``, set to ``RealNumbers()``. out_dtype : optional Data type of the return value of a function in this space. Can be given in any way `numpy.dtype` understands, e.g. as string (``'float64'``) or data type (``float``). By default, ``'float64'`` is used for real and ``'complex128'`` for complex spaces. """ if not isinstance(domain, Set): raise TypeError('`domain` {!r} not a Set instance'.format(domain)) if field is not None and not isinstance(field, Field): raise TypeError('`field` {!r} not a `Field` instance' ''.format(field)) # Data type: check if consistent with field, take default for None dtype, dtype_in = np.dtype(out_dtype), out_dtype # Default for both None if field is None and out_dtype is None: field = RealNumbers() out_dtype = np.dtype('float64') # field None, dtype given -> infer field elif field is None: if is_real_dtype(dtype): field = RealNumbers() elif is_complex_floating_dtype(dtype): field = ComplexNumbers() else: raise ValueError('{} is not a scalar data type' ''.format(dtype_in)) # field given -> infer dtype if not given, else check consistency elif field == RealNumbers(): if out_dtype is None: out_dtype = np.dtype('float64') elif not is_real_dtype(dtype): raise ValueError('{} is not a real data type' ''.format(dtype_in)) elif field == ComplexNumbers(): if out_dtype is None: out_dtype = np.dtype('complex128') elif not is_complex_floating_dtype(dtype): raise ValueError('{} is not a complex data type' ''.format(dtype_in)) # Else: keep out_dtype=None, which results in lazy dtype determination LinearSpace.__init__(self, field) FunctionSet.__init__(self, domain, field, out_dtype) # Init cache attributes for real / complex variants if self.field == RealNumbers(): self.__real_out_dtype = self.out_dtype self.__real_space = self self.__complex_out_dtype = complex_dtype(self.out_dtype, default=np.dtype(object)) self.__complex_space = None elif self.field == ComplexNumbers(): self.__real_out_dtype = real_dtype(self.out_dtype) self.__real_space = None self.__complex_out_dtype = self.out_dtype self.__complex_space = self else: self.__real_out_dtype = None self.__real_space = None self.__complex_out_dtype = None self.__complex_space = None
def __init__(self, domain, field=None, out_dtype=None): """Initialize a new instance. Parameters ---------- domain : `Set` The domain of the functions field : `Field`, optional The range of the functions, usually the `RealNumbers` or `ComplexNumbers`. If not given, the field is either inferred from ``out_dtype``, or, if the latter is also ``None``, set to ``RealNumbers()``. out_dtype : optional Data type of the return value of a function in this space. Can be given in any way `numpy.dtype` understands, e.g. as string (``'float64'``) or data type (``float``). By default, ``'float64'`` is used for real and ``'complex128'`` for complex spaces. """ if not isinstance(domain, Set): raise TypeError('`domain` {!r} not a Set instance'.format(domain)) if field is not None and not isinstance(field, Field): raise TypeError('`field` {!r} not a `Field` instance' ''.format(field)) # Data type: check if consistent with field, take default for None dtype, dtype_in = np.dtype(out_dtype), out_dtype # Default for both None if field is None and out_dtype is None: field = RealNumbers() out_dtype = np.dtype('float64') # field None, dtype given -> infer field elif field is None: if is_real_dtype(dtype): field = RealNumbers() elif is_complex_floating_dtype(dtype): field = ComplexNumbers() else: raise ValueError('{} is not a scalar data type' ''.format(dtype_in)) # field given -> infer dtype if not given, else check consistency elif field == RealNumbers(): if out_dtype is None: out_dtype = np.dtype('float64') elif not is_real_dtype(dtype): raise ValueError('{} is not a real data type' ''.format(dtype_in)) elif field == ComplexNumbers(): if out_dtype is None: out_dtype = np.dtype('complex128') elif not is_complex_floating_dtype(dtype): raise ValueError('{} is not a complex data type' ''.format(dtype_in)) # Else: keep out_dtype=None, which results in lazy dtype determination LinearSpace.__init__(self, field) FunctionSet.__init__(self, domain, field, out_dtype) # Init cache attributes for real / complex variants if self.field == RealNumbers(): self.__real_out_dtype = self.out_dtype self.__real_space = self self.__complex_out_dtype = complex_dtype(self.out_dtype, default=np.dtype(object)) self.__complex_space = None elif self.field == ComplexNumbers(): self.__real_out_dtype = real_dtype(self.out_dtype) self.__real_space = None self.__complex_out_dtype = self.out_dtype self.__complex_space = self else: self.__real_out_dtype = None self.__real_space = None self.__complex_out_dtype = None self.__complex_space = None