Skip to content

Commit 9d5ab76

Browse files
Remove TensorType.value_zeros
1 parent 2cf617d commit 9d5ab76

File tree

6 files changed

+13
-26
lines changed

6 files changed

+13
-26
lines changed

aesara/compile/debugmode.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ def _get_preallocated_maps(
807807
for r in considered_outputs:
808808
if isinstance(r.type, TensorType):
809809
# Build a C-contiguous buffer
810-
new_buf = r.type.value_zeros(r_vals[r].shape)
810+
new_buf = np.empty(r_vals[r].shape, dtype=r.type.dtype)
811811
assert new_buf.flags["C_CONTIGUOUS"]
812812
new_buf[...] = np.asarray(def_val).astype(r.type.dtype)
813813

@@ -875,7 +875,8 @@ def _get_preallocated_maps(
875875
buf_shape.append(s)
876876
else:
877877
buf_shape.append(s * 2)
878-
new_buf = r.type.value_zeros(buf_shape)
878+
879+
new_buf = np.empty(buf_shape, dtype=r.type.dtype)
879880
new_buf[...] = np.asarray(def_val).astype(r.type.dtype)
880881
init_strided[r] = new_buf
881882

@@ -950,7 +951,7 @@ def _get_preallocated_maps(
950951
max((s + sd), 0)
951952
for s, sd in zip(r_vals[r].shape, r_shape_diff)
952953
]
953-
new_buf = r.type.value_zeros(out_shape)
954+
new_buf = np.empty(out_shape, dtype=r.type.dtype)
954955
new_buf[...] = np.asarray(def_val).astype(r.type.dtype)
955956
wrong_size[r] = new_buf
956957

aesara/scan/op.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,11 +1380,13 @@ def prepare_fgraph(self, fgraph):
13801380
# the output value, possibly inplace, at the end of the
13811381
# function execution. Also, since an update is defined,
13821382
# a default value must also be (this is verified by
1383-
# DebugMode). Use an array of size 0 with the correct
1384-
# ndim and dtype (use a shape of 1 on broadcastable
1385-
# dimensions, and 0 on the others).
1386-
default_shape = [1 if _b else 0 for _b in inp.broadcastable]
1387-
default_val = inp.type.value_zeros(default_shape)
1383+
# DebugMode).
1384+
# TODO FIXME: Why do we need a "default value" here?
1385+
# This sounds like a serious design issue.
1386+
default_shape = tuple(
1387+
s if s is not None else 0 for s in inp.type.shape
1388+
)
1389+
default_val = np.empty(default_shape, dtype=inp.type.dtype)
13881390
wrapped_inp = In(
13891391
variable=inp,
13901392
value=default_val,

aesara/sparse/type.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,6 @@ def get_size(self, shape_info):
224224
+ (shape_info[2] + shape_info[3]) * np.dtype("int32").itemsize
225225
)
226226

227-
def value_zeros(self, shape):
228-
matrix_constructor = self.format_cls.get(self.format)
229-
230-
if matrix_constructor is None:
231-
raise ValueError(f"Sparse matrix type {self.format} not found in SciPy")
232-
233-
return matrix_constructor(shape, dtype=self.dtype)
234-
235227
def __eq__(self, other):
236228
res = super().__eq__(other)
237229

aesara/tensor/type.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,6 @@ def convert_variable(self, var):
331331
# `specify_shape` will combine the more precise shapes of the two types
332332
return aesara.tensor.specify_shape(var, self.shape)
333333

334-
def value_zeros(self, shape):
335-
"""Create an numpy ndarray full of 0 values.
336-
337-
TODO: Remove this trivial method.
338-
"""
339-
return np.zeros(shape, dtype=self.dtype)
340-
341334
@staticmethod
342335
def values_eq(a, b, force_same_dtype=True):
343336
# TODO: check to see if the shapes must match; for now, we err on safe

tests/compile/test_debugmode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,10 +725,10 @@ def perform(self, node, inp, out):
725725
r, c = out
726726
lv = v.shape[0]
727727
if (r[0] is None) or (r[0].shape != (1, lv)):
728-
r[0] = node.outputs[0].type.value_zeros((1, lv))
728+
r[0] = np.empty((1, lv), dtype=node.outputs[0].type.dtype)
729729

730730
if (c[0] is None) or (c[0].shape != (lv, 1)):
731-
c[0] = node.outputs[1].type.value_zeros((lv, 1))
731+
c[0] = np.empty((lv, 1), dtype=node.outputs[0].type.dtype)
732732

733733
for i in range(lv):
734734
r[0][0, i] = v[i]

tests/tensor/test_type.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ def test_fixed_shape_basic():
234234
t1 = TensorType("float64", (2, 3))
235235
assert t1.shape == (2, 3)
236236
assert t1.broadcastable == (False, False)
237-
assert t1.value_zeros(t1.shape).shape == t1.shape
238237

239238
assert str(t1) == "TensorType(float64, (2, 3))"
240239

0 commit comments

Comments
 (0)