提交 249591b5 authored 作者: Brandon T. Willard's avatar Brandon T. Willard 提交者: Brandon T. Willard

Rename Type.Variable and Type.Constant to Type.variable_type and Type.constant_type

上级 c3f16b6d
...@@ -351,7 +351,7 @@ class GpuArrayType(CType): ...@@ -351,7 +351,7 @@ class GpuArrayType(CType):
other = other._as_GpuArrayVariable(self.context_name) other = other._as_GpuArrayVariable(self.context_name)
if not isinstance(other, Variable): if not isinstance(other, Variable):
other = self.Constant(type=self, data=other) other = self.constant_type(type=self, data=other)
if other.type == self: if other.type == self:
return other return other
...@@ -677,7 +677,7 @@ class GpuArrayVariable(_operators, Variable): ...@@ -677,7 +677,7 @@ class GpuArrayVariable(_operators, Variable):
return repr(np.array(aesara.graph.op.get_test_value(self))) return repr(np.array(aesara.graph.op.get_test_value(self)))
GpuArrayType.Variable = GpuArrayVariable GpuArrayType.variable_type = GpuArrayVariable
class GpuArraySignature(TensorConstantSignature): class GpuArraySignature(TensorConstantSignature):
...@@ -715,7 +715,7 @@ class GpuArrayConstant(_operators, Constant): ...@@ -715,7 +715,7 @@ class GpuArrayConstant(_operators, Constant):
return "GpuArrayConstant{%s}" % np_data return "GpuArrayConstant{%s}" % np_data
GpuArrayType.Constant = GpuArrayConstant GpuArrayType.constant_type = GpuArrayConstant
class GpuArraySharedVariable(_operators, SharedVariable): class GpuArraySharedVariable(_operators, SharedVariable):
......
...@@ -35,12 +35,12 @@ class Type(MetaObject): ...@@ -35,12 +35,12 @@ class Type(MetaObject):
""" """
Variable: TypeAlias = Variable variable_type: TypeAlias = Variable
""" """
The `Type` that will be created by a call to `Type.make_variable`. The `Type` that will be created by a call to `Type.make_variable`.
""" """
Constant: TypeAlias = Constant constant_type: TypeAlias = Constant
""" """
The `Type` that will be created by a call to `Type.make_constant`. The `Type` that will be created by a call to `Type.make_constant`.
""" """
...@@ -136,7 +136,7 @@ class Type(MetaObject): ...@@ -136,7 +136,7 @@ class Type(MetaObject):
def filter_variable( def filter_variable(
self, other: Union[Variable, D], allow_convert: bool = True self, other: Union[Variable, D], allow_convert: bool = True
) -> Variable: ) -> variable_type:
r"""Convert a `other` into a `Variable` with a `Type` that's compatible with `self`. r"""Convert a `other` into a `Variable` with a `Type` that's compatible with `self`.
If the involved `Type`\s are not compatible, a `TypeError` will be raised. If the involved `Type`\s are not compatible, a `TypeError` will be raised.
...@@ -144,7 +144,7 @@ class Type(MetaObject): ...@@ -144,7 +144,7 @@ class Type(MetaObject):
if not isinstance(other, Variable): if not isinstance(other, Variable):
# The value is not a Variable: we cast it into # The value is not a Variable: we cast it into
# a Constant of the appropriate Type. # a Constant of the appropriate Type.
other = self.Constant(type=self, data=other) other = self.constant_type(type=self, data=other)
if other.type != self and allow_convert: if other.type != self and allow_convert:
other2 = self.convert_variable(other) other2 = self.convert_variable(other)
...@@ -193,7 +193,7 @@ class Type(MetaObject): ...@@ -193,7 +193,7 @@ class Type(MetaObject):
except (TypeError, ValueError): except (TypeError, ValueError):
return False return False
def make_variable(self, name: Optional[Text] = None) -> Variable: def make_variable(self, name: Optional[Text] = None) -> variable_type:
"""Return a new `Variable` instance of this `Type`. """Return a new `Variable` instance of this `Type`.
Parameters Parameters
...@@ -202,9 +202,9 @@ class Type(MetaObject): ...@@ -202,9 +202,9 @@ class Type(MetaObject):
A pretty string for printing and debugging. A pretty string for printing and debugging.
""" """
return self.Variable(self, name=name) return self.variable_type(self, name=name)
def make_constant(self, value: D, name: Optional[Text] = None) -> Constant: def make_constant(self, value: D, name: Optional[Text] = None) -> constant_type:
"""Return a new `Constant` instance of this `Type`. """Return a new `Constant` instance of this `Type`.
Parameters Parameters
...@@ -215,13 +215,13 @@ class Type(MetaObject): ...@@ -215,13 +215,13 @@ class Type(MetaObject):
A pretty string for printing and debugging. A pretty string for printing and debugging.
""" """
return self.Constant(type=self, data=value, name=name) return self.constant_type(type=self, data=value, name=name)
def clone(self, *args, **kwargs): def clone(self, *args, **kwargs):
"""Clone a copy of this type with the given arguments/keyword values, if any.""" """Clone a copy of this type with the given arguments/keyword values, if any."""
return type(self)(*args, **kwargs) return type(self)(*args, **kwargs)
def __call__(self, name: Optional[Text] = None) -> Variable: def __call__(self, name: Optional[Text] = None) -> variable_type:
"""Return a new `Variable` instance of Type `self`. """Return a new `Variable` instance of Type `self`.
Parameters Parameters
......
...@@ -843,7 +843,7 @@ class ScalarVariable(_scalar_py_operators, Variable): ...@@ -843,7 +843,7 @@ class ScalarVariable(_scalar_py_operators, Variable):
pass pass
Scalar.Variable = ScalarVariable Scalar.variable_type = ScalarVariable
class ScalarConstant(ScalarVariable, Constant): class ScalarConstant(ScalarVariable, Constant):
...@@ -852,7 +852,7 @@ class ScalarConstant(ScalarVariable, Constant): ...@@ -852,7 +852,7 @@ class ScalarConstant(ScalarVariable, Constant):
# Register ScalarConstant as the type of Constant corresponding to Scalar # Register ScalarConstant as the type of Constant corresponding to Scalar
Scalar.Constant = ScalarConstant Scalar.constant_type = ScalarConstant
def constant(x, name=None, dtype=None) -> ScalarConstant: def constant(x, name=None, dtype=None) -> ScalarConstant:
......
...@@ -415,8 +415,8 @@ class SparseConstant(Constant, _sparse_py_operators): ...@@ -415,8 +415,8 @@ class SparseConstant(Constant, _sparse_py_operators):
return str(self) return str(self)
SparseType.Variable = SparseVariable SparseType.variable_type = SparseVariable
SparseType.Constant = SparseConstant SparseType.constant_type = SparseConstant
# for more dtypes, call SparseType(format, dtype) # for more dtypes, call SparseType(format, dtype)
......
...@@ -69,7 +69,7 @@ class SparseType(Type, HasDataType): ...@@ -69,7 +69,7 @@ class SparseType(Type, HasDataType):
ndim = 2 ndim = 2
# Will be set to SparseVariable SparseConstant later. # Will be set to SparseVariable SparseConstant later.
Variable = None variable_type = None
Constant = None Constant = None
def __init__(self, format, dtype, shape=None): def __init__(self, format, dtype, shape=None):
...@@ -151,7 +151,7 @@ class SparseType(Type, HasDataType): ...@@ -151,7 +151,7 @@ class SparseType(Type, HasDataType):
return False return False
def make_variable(self, name=None): def make_variable(self, name=None):
return self.Variable(self, name=name) return self.variable_type(self, name=name)
def __eq__(self, other): def __eq__(self, other):
return ( return (
......
...@@ -245,7 +245,7 @@ class TensorType(CType, HasDataType): ...@@ -245,7 +245,7 @@ class TensorType(CType, HasDataType):
if not isinstance(other, Variable): if not isinstance(other, Variable):
# The value is not a Variable: we cast it into # The value is not a Variable: we cast it into
# a Constant of the appropriate Type. # a Constant of the appropriate Type.
other = self.Constant(type=self, data=other) other = self.constant_type(type=self, data=other)
if other.type == self: if other.type == self:
return other return other
......
...@@ -109,7 +109,7 @@ class SliceConstant(Constant): ...@@ -109,7 +109,7 @@ class SliceConstant(Constant):
) )
SliceType.Constant = SliceConstant SliceType.constant_type = SliceConstant
@_as_symbolic.register(slice) @_as_symbolic.register(slice)
......
...@@ -861,7 +861,7 @@ def _get_vector_length_TensorVariable(op_or_var, var): ...@@ -861,7 +861,7 @@ def _get_vector_length_TensorVariable(op_or_var, var):
return var.type.shape[0] return var.type.shape[0]
TensorType.Variable = TensorVariable TensorType.variable_type = TensorVariable
class TensorConstantSignature(tuple): class TensorConstantSignature(tuple):
...@@ -1039,4 +1039,4 @@ class TensorConstant(TensorVariable, Constant): ...@@ -1039,4 +1039,4 @@ class TensorConstant(TensorVariable, Constant):
) )
TensorType.Constant = TensorConstant TensorType.constant_type = TensorConstant
...@@ -53,7 +53,7 @@ class TypedListVariable(_typed_list_py_operators, Variable): ...@@ -53,7 +53,7 @@ class TypedListVariable(_typed_list_py_operators, Variable):
""" """
TypedListType.Variable = TypedListVariable TypedListType.variable_type = TypedListVariable
class TypedListConstant(_typed_list_py_operators, Constant): class TypedListConstant(_typed_list_py_operators, Constant):
...@@ -63,7 +63,7 @@ class TypedListConstant(_typed_list_py_operators, Constant): ...@@ -63,7 +63,7 @@ class TypedListConstant(_typed_list_py_operators, Constant):
""" """
TypedListType.Constant = TypedListConstant TypedListType.constant_type = TypedListConstant
class GetItem(COp): class GetItem(COp):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论