提交 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):
other = other._as_GpuArrayVariable(self.context_name)
if not isinstance(other, Variable):
other = self.Constant(type=self, data=other)
other = self.constant_type(type=self, data=other)
if other.type == self:
return other
......@@ -677,7 +677,7 @@ class GpuArrayVariable(_operators, Variable):
return repr(np.array(aesara.graph.op.get_test_value(self)))
GpuArrayType.Variable = GpuArrayVariable
GpuArrayType.variable_type = GpuArrayVariable
class GpuArraySignature(TensorConstantSignature):
......@@ -715,7 +715,7 @@ class GpuArrayConstant(_operators, Constant):
return "GpuArrayConstant{%s}" % np_data
GpuArrayType.Constant = GpuArrayConstant
GpuArrayType.constant_type = GpuArrayConstant
class GpuArraySharedVariable(_operators, SharedVariable):
......
......@@ -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`.
"""
Constant: TypeAlias = Constant
constant_type: TypeAlias = Constant
"""
The `Type` that will be created by a call to `Type.make_constant`.
"""
......@@ -136,7 +136,7 @@ class Type(MetaObject):
def filter_variable(
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`.
If the involved `Type`\s are not compatible, a `TypeError` will be raised.
......@@ -144,7 +144,7 @@ class Type(MetaObject):
if not isinstance(other, Variable):
# The value is not a Variable: we cast it into
# 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:
other2 = self.convert_variable(other)
......@@ -193,7 +193,7 @@ class Type(MetaObject):
except (TypeError, ValueError):
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`.
Parameters
......@@ -202,9 +202,9 @@ class Type(MetaObject):
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`.
Parameters
......@@ -215,13 +215,13 @@ class Type(MetaObject):
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):
"""Clone a copy of this type with the given arguments/keyword values, if any."""
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`.
Parameters
......
......@@ -843,7 +843,7 @@ class ScalarVariable(_scalar_py_operators, Variable):
pass
Scalar.Variable = ScalarVariable
Scalar.variable_type = ScalarVariable
class ScalarConstant(ScalarVariable, Constant):
......@@ -852,7 +852,7 @@ class ScalarConstant(ScalarVariable, Constant):
# 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:
......
......@@ -415,8 +415,8 @@ class SparseConstant(Constant, _sparse_py_operators):
return str(self)
SparseType.Variable = SparseVariable
SparseType.Constant = SparseConstant
SparseType.variable_type = SparseVariable
SparseType.constant_type = SparseConstant
# for more dtypes, call SparseType(format, dtype)
......
......@@ -69,7 +69,7 @@ class SparseType(Type, HasDataType):
ndim = 2
# Will be set to SparseVariable SparseConstant later.
Variable = None
variable_type = None
Constant = None
def __init__(self, format, dtype, shape=None):
......@@ -151,7 +151,7 @@ class SparseType(Type, HasDataType):
return False
def make_variable(self, name=None):
return self.Variable(self, name=name)
return self.variable_type(self, name=name)
def __eq__(self, other):
return (
......
......@@ -245,7 +245,7 @@ class TensorType(CType, HasDataType):
if not isinstance(other, Variable):
# The value is not a Variable: we cast it into
# 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:
return other
......
......@@ -109,7 +109,7 @@ class SliceConstant(Constant):
)
SliceType.Constant = SliceConstant
SliceType.constant_type = SliceConstant
@_as_symbolic.register(slice)
......
......@@ -861,7 +861,7 @@ def _get_vector_length_TensorVariable(op_or_var, var):
return var.type.shape[0]
TensorType.Variable = TensorVariable
TensorType.variable_type = TensorVariable
class TensorConstantSignature(tuple):
......@@ -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):
"""
TypedListType.Variable = TypedListVariable
TypedListType.variable_type = TypedListVariable
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):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论