Skip to content
This repository was archived by the owner on Nov 17, 2025. It is now read-only.

Commit b2b2604

Browse files
committed
Fixed output dtype
1 parent a5de97c commit b2b2604

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

aesara/tensor/blockwise.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from aesara.graph.rewriting.utils import rewrite_graph
1111
from aesara.scalar.basic import constant as scalar_constant
1212
from aesara.scalar.basic import int64
13-
from aesara.tensor import get_gufunc_signature, get_scalar_constant_value
13+
from aesara.tensor import get_scalar_constant_value
1414
from aesara.tensor.basic import atleast_Nd
1515
from aesara.tensor.elemwise import DimShuffle
1616
from aesara.tensor.exceptions import NotScalarConstantError
@@ -216,7 +216,7 @@ def get_output_info(self, *inputs):
216216
else:
217217
core_inputs.append(input)
218218

219-
# remore the core dimension first the then broadcast the rest of the dimension
219+
# remove the core dimension first the then broadcast the rest of the dimension
220220
max_loop_dimension = max(
221221
core_inputs[i].type.ndim - len(self.signature[0][i])
222222
for i in range(len(core_inputs))
@@ -239,13 +239,13 @@ def get_output_info(self, *inputs):
239239
)
240240
inputs = broadcasted_inputs
241241

242-
# TODO: Correct this
243-
out_dtype = inputs[0].dtype
242+
shadow = self.op.make_node(*inputs)
243+
out_dtypes = [o.type.dtype for o in shadow.outputs]
244244

245245
bcast_shape, dim_sizes = _parse_input_dimensions(inputs, self.signature[0])
246246
output_shapes = _calculate_shapes(bcast_shape, dim_sizes, self.signature[1])
247247

248-
return out_dtype, output_shapes, inputs
248+
return out_dtypes, output_shapes, inputs
249249

250250
def make_node(self, *inputs):
251251
num_expected_inps = len(self.signature[0])
@@ -254,7 +254,7 @@ def make_node(self, *inputs):
254254
f"Expected {int(num_expected_inps)} inputs, got {len(inputs)}"
255255
)
256256

257-
out_dtype, output_shapes, inputs = self.get_output_info(*inputs)
257+
out_dtypes, output_shapes, inputs = self.get_output_info(*inputs)
258258

259259
def safe_const_val(x):
260260
try:
@@ -263,8 +263,8 @@ def safe_const_val(x):
263263
return None
264264

265265
outputs = [
266-
TensorType(out_dtype, shape=tuple(safe_const_val(s) for s in shp))()
267-
for shp in output_shapes
266+
TensorType(out_dtypes[i], shape=tuple(safe_const_val(s) for s in output_shapes[i]))()
267+
for i in range(len(output_shapes))
268268
]
269269
return Apply(self, list(inputs), outputs)
270270

tests/tensor/test_blockwise.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,16 @@ def test_infer_shape_to_gufunc_sig():
236236
y = at.diag(at.vector("x"))
237237
res = infer_shape_to_gufunc_sig(y.owner)
238238
assert res == ((("i0",),), (("i0", "i0"),))
239+
240+
241+
def test_Blockwise_get_output_info():
242+
a = at.lscalar("a")
243+
b = at.lscalar("b")
244+
c = at.lscalar("c")
245+
246+
from aesara.tensor.basic import Tri
247+
248+
blk_op = Blockwise(op=Tri(dtype="float64"), signature=(((), (), ()), (('n', 'm'),)))
249+
out_dtype, output_shapes, inputs = blk_op.get_output_info(a, b, c)
250+
251+
assert out_dtype == ["float64"]

0 commit comments

Comments
 (0)