提交 9d5ab765 authored 作者: Brandon T. Willard's avatar Brandon T. Willard 提交者: Brandon T. Willard

Remove TensorType.value_zeros

上级 2cf617d5
......@@ -807,7 +807,7 @@ def _get_preallocated_maps(
for r in considered_outputs:
if isinstance(r.type, TensorType):
# Build a C-contiguous buffer
new_buf = r.type.value_zeros(r_vals[r].shape)
new_buf = np.empty(r_vals[r].shape, dtype=r.type.dtype)
assert new_buf.flags["C_CONTIGUOUS"]
new_buf[...] = np.asarray(def_val).astype(r.type.dtype)
......@@ -875,7 +875,8 @@ def _get_preallocated_maps(
buf_shape.append(s)
else:
buf_shape.append(s * 2)
new_buf = r.type.value_zeros(buf_shape)
new_buf = np.empty(buf_shape, dtype=r.type.dtype)
new_buf[...] = np.asarray(def_val).astype(r.type.dtype)
init_strided[r] = new_buf
......@@ -950,7 +951,7 @@ def _get_preallocated_maps(
max((s + sd), 0)
for s, sd in zip(r_vals[r].shape, r_shape_diff)
]
new_buf = r.type.value_zeros(out_shape)
new_buf = np.empty(out_shape, dtype=r.type.dtype)
new_buf[...] = np.asarray(def_val).astype(r.type.dtype)
wrong_size[r] = new_buf
......
......@@ -1380,11 +1380,13 @@ class Scan(Op, ScanMethodsMixin, HasInnerGraph):
# the output value, possibly inplace, at the end of the
# function execution. Also, since an update is defined,
# a default value must also be (this is verified by
# DebugMode). Use an array of size 0 with the correct
# ndim and dtype (use a shape of 1 on broadcastable
# dimensions, and 0 on the others).
default_shape = [1 if _b else 0 for _b in inp.broadcastable]
default_val = inp.type.value_zeros(default_shape)
# DebugMode).
# TODO FIXME: Why do we need a "default value" here?
# This sounds like a serious design issue.
default_shape = tuple(
s if s is not None else 0 for s in inp.type.shape
)
default_val = np.empty(default_shape, dtype=inp.type.dtype)
wrapped_inp = In(
variable=inp,
value=default_val,
......
......@@ -224,14 +224,6 @@ class SparseTensorType(TensorType, HasDataType):
+ (shape_info[2] + shape_info[3]) * np.dtype("int32").itemsize
)
def value_zeros(self, shape):
matrix_constructor = self.format_cls.get(self.format)
if matrix_constructor is None:
raise ValueError(f"Sparse matrix type {self.format} not found in SciPy")
return matrix_constructor(shape, dtype=self.dtype)
def __eq__(self, other):
res = super().__eq__(other)
......
......@@ -331,13 +331,6 @@ class TensorType(CType[np.ndarray], HasDataType, HasShape):
# `specify_shape` will combine the more precise shapes of the two types
return aesara.tensor.specify_shape(var, self.shape)
def value_zeros(self, shape):
"""Create an numpy ndarray full of 0 values.
TODO: Remove this trivial method.
"""
return np.zeros(shape, dtype=self.dtype)
@staticmethod
def values_eq(a, b, force_same_dtype=True):
# TODO: check to see if the shapes must match; for now, we err on safe
......
......@@ -725,10 +725,10 @@ class VecAsRowAndCol(Op):
r, c = out
lv = v.shape[0]
if (r[0] is None) or (r[0].shape != (1, lv)):
r[0] = node.outputs[0].type.value_zeros((1, lv))
r[0] = np.empty((1, lv), dtype=node.outputs[0].type.dtype)
if (c[0] is None) or (c[0].shape != (lv, 1)):
c[0] = node.outputs[1].type.value_zeros((lv, 1))
c[0] = np.empty((lv, 1), dtype=node.outputs[0].type.dtype)
for i in range(lv):
r[0][0, i] = v[i]
......
......@@ -234,7 +234,6 @@ def test_fixed_shape_basic():
t1 = TensorType("float64", (2, 3))
assert t1.shape == (2, 3)
assert t1.broadcastable == (False, False)
assert t1.value_zeros(t1.shape).shape == t1.shape
assert str(t1) == "TensorType(float64, (2, 3))"
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论