type
– Interface for types of variables¶
Reference¶

class
aesara.graph.type.
Type
[source]¶ Interface specification for variable type instances.
A Type instance is mainly responsible for two things:
 creating
Variable
instances (conventionally,__call__
does this), and  filtering a value assigned to a
Variable
so that the value conforms to restrictions imposed by the type (also known as casting, this is done byfilter
).

clone
(*args, **kwargs)[source]¶ Clone a copy of this type with the given arguments/keyword values, if any.

constant_type
[source]¶ The
Type
that will be created by a call toType.make_constant
.alias of
aesara.graph.basic.Constant

convert_variable
(var: aesara.graph.basic.Variable) Optional[aesara.graph.basic.Variable] [source]¶ Produce a
Variable
that’s compatible with bothself
andvar.type
, if possible.A compatible
Variable
is aVariable
with aType
that’s the “narrower” ofself
andvar.type
.If a compatible
Type
cannot be found, this method will returnNone
.

abstract
filter
(data: aesara.graph.type.D, strict: bool = False, allow_downcast: Optional[bool] = None) Union[aesara.graph.type.D, Any] [source]¶ Return data or an appropriately wrapped/converted data.
Subclass implementations should raise a TypeError exception if the data is not of an acceptable type.
Parameters:  data (arraylike) – The data to be filtered/converted.
 strict (bool (optional)) – If
True
, the data returned must be the same as the data passed as an argument.  allow_downcast (bool (optional)) – If
strict
isFalse
, andallow_downcast
isTrue
, the data may be cast to an appropriate type. Ifallow_downcast
isFalse
, it may only be upcast and not lose precision. Ifallow_downcast
isNone
(default), the behaviour can be typedependent, but for now it means only Python floats can be downcasted, and only to floatX scalars.

filter_inplace
(value: aesara.graph.type.D, storage: Any, strict: bool = False, allow_downcast: Optional[bool] = None)[source]¶ Return data or an appropriately wrapped/converted data by converting it inplace.
This method allows one to reuse old allocated memory. If this method is implemented, it will be called instead of
Type.filter
.As of now, this method is not implemented and was previously used for transferring memory to and from GPU.
Parameters:  value (arraylike) –
 storage (arraylike) – The old value (e.g. the old NumPy array)
 strict (bool) –
 allow_downcast (bool (optional)) –
Raises: NotImplementedError –

filter_variable
(other: Union[aesara.graph.basic.Variable, aesara.graph.type.D], allow_convert: bool = True) aesara.graph.basic.Variable [source]¶ Convert a
other
into aVariable
with aType
that’s compatible withself
.If the involved
Type
s are not compatible, aTypeError
will be raised.

in_same_class
(otype: aesara.graph.type.Type) Optional[bool] [source]¶ Determine if another
Type
represents a subset from the same “class” of types represented byself
.A “class” of types could be something like “float64 tensors with four dimensions”. One
Type
could represent a set containing only a type for “float64 tensors with shape (1, 2, 3, 4)” and another the set of “float64 tensors with shape (1, x, x, x)” for all suitable “x”.It’s up to each subclass of
Type
to determine to which “classes” of types this method applies.The default implementation assumes that all “classes” have only one unique element (i.e. it uses
self.__eq__
).

is_super
(otype: aesara.graph.type.Type) Optional[bool] [source]¶ Determine if
self
is a supertype ofotype
.This method effectively implements the type relation
>
.In general,
t1.is_super(t2) == True
implies thatt1
can be replaced witht2
.See
Type.in_same_class
.Return type: None
if the type relation cannot be applied/determined.

is_valid_value
(data: aesara.graph.type.D) bool [source]¶ Return
True
for any python object that would be a legal value for aVariable
of thisType
.

make_constant
(value: aesara.graph.type.D, name: Optional[str] = None) aesara.graph.basic.Constant [source]¶ Return a new
Constant
instance of thisType
.Parameters:  value (arraylike) – The constant value.
 name (None or str) – A pretty string for printing and debugging.

make_variable
(name: Optional[str] = None) aesara.graph.basic.Variable [source]¶ Return a new
Variable
instance of thisType
.Parameters: name (None or str) – A pretty string for printing and debugging.

classmethod
values_eq
(a: aesara.graph.type.Type, b: aesara.graph.type.Type) bool [source]¶ Return
True
ifa
andb
can be considered exactly equal.a
andb
are assumed to be valid values of thisType
.

classmethod
values_eq_approx
(a: Any, b: Any)[source]¶ Return
True
ifa
andb
can be considered approximately equal.This function is used by Aesara debugging tools to decide whether two values are equivalent, admitting a certain amount of numerical instability. For example, for floatingpoint numbers this function should be an approximate comparison.
By default, this does an exact comparison.
Parameters: Return type: bool

variable_type
[source]¶ The
Type
that will be created by a call toType.make_variable
.alias of
aesara.graph.basic.Variable
 creating