提交 7ba74079 authored 作者: Brandon T. Willard's avatar Brandon T. Willard 提交者: Brandon T. Willard

Create HasDataType mixin

上级 8a4505c0
...@@ -267,6 +267,12 @@ class Type(MetaObject): ...@@ -267,6 +267,12 @@ class Type(MetaObject):
return cls.values_eq(a, b) return cls.values_eq(a, b)
class HasDataType:
"""A mixing for an `Op` type that has a :attr:`dtype` attribute."""
dtype: str
class CType(Type, CLinkerType): class CType(Type, CLinkerType):
"""Convenience wrapper combining `Type` and `CLinkerType`. """Convenience wrapper combining `Type` and `CLinkerType`.
......
...@@ -2,7 +2,7 @@ import numpy as np ...@@ -2,7 +2,7 @@ import numpy as np
import scipy.sparse import scipy.sparse
import aesara import aesara
from aesara.graph.type import Type from aesara.graph.type import HasDataType, Type
def _is_sparse(x): def _is_sparse(x):
...@@ -24,7 +24,7 @@ def _is_sparse(x): ...@@ -24,7 +24,7 @@ def _is_sparse(x):
return isinstance(x, scipy.sparse.spmatrix) return isinstance(x, scipy.sparse.spmatrix)
class SparseType(Type): class SparseType(Type, HasDataType):
""" """
Fundamental way to create a sparse node. Fundamental way to create a sparse node.
......
...@@ -8,7 +8,7 @@ import aesara ...@@ -8,7 +8,7 @@ import aesara
from aesara import scalar as aes from aesara import scalar as aes
from aesara.configdefaults import config from aesara.configdefaults import config
from aesara.graph.basic import Variable from aesara.graph.basic import Variable
from aesara.graph.type import CType from aesara.graph.type import CType, HasDataType
from aesara.misc.safe_asarray import _asarray from aesara.misc.safe_asarray import _asarray
from aesara.utils import apply_across_args from aesara.utils import apply_across_args
...@@ -46,7 +46,7 @@ dtype_specs_map = { ...@@ -46,7 +46,7 @@ dtype_specs_map = {
} }
class TensorType(CType): class TensorType(CType, HasDataType):
r"""Symbolic `Type` representing `numpy.ndarray`\s.""" r"""Symbolic `Type` representing `numpy.ndarray`\s."""
__props__ = ("dtype", "shape") __props__ = ("dtype", "shape")
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论