diff --git a/pytensor/gradient.py b/pytensor/gradient.py index 99dae108eb..96a39e09d9 100644 --- a/pytensor/gradient.py +++ b/pytensor/gradient.py @@ -2302,7 +2302,7 @@ def _is_zero(x): class ZeroGrad(ViewOp): def grad(self, args, g_outs): - return [g_out.zeros_like(g_out) for g_out in g_outs] + return [g_out.zeros_like() for g_out in g_outs] def R_op(self, inputs, eval_points): if eval_points[0] is None: diff --git a/pytensor/scalar/basic.py b/pytensor/scalar/basic.py index f71c7512bd..de92555401 100644 --- a/pytensor/scalar/basic.py +++ b/pytensor/scalar/basic.py @@ -3237,7 +3237,7 @@ def L_op(self, inputs, outputs, gout): else: return [x.zeros_like()] - return (gz * exp2(x) * log(np.array(2, dtype=x.type)),) + return (gz * exp2(x) * log(np.array(2, dtype=x.dtype)),) def c_code(self, node, name, inputs, outputs, sub): (x,) = inputs @@ -3376,7 +3376,7 @@ def L_op(self, inputs, outputs, gout): else: return [x.zeros_like()] - return (gz * np.array(np.pi / 180, dtype=gz.type),) + return (gz * np.array(np.pi / 180, dtype=gz.dtype),) def c_code(self, node, name, inputs, outputs, sub): (x,) = inputs @@ -3411,7 +3411,7 @@ def L_op(self, inputs, outputs, gout): else: return [x.zeros_like()] - return (gz * np.array(180.0 / np.pi, dtype=gz.type),) + return (gz * np.array(180.0 / np.pi, dtype=gz.dtype),) def c_code(self, node, name, inputs, outputs, sub): (x,) = inputs @@ -3484,7 +3484,7 @@ def L_op(self, inputs, outputs, gout): else: return [x.zeros_like()] - return (-gz / sqrt(np.array(1, dtype=x.type) - sqr(x)),) + return (-gz / sqrt(np.array(1, dtype=x.dtype) - sqr(x)),) def c_code(self, node, name, inputs, outputs, sub): (x,) = inputs @@ -3558,7 +3558,7 @@ def L_op(self, inputs, outputs, gout): else: return [x.zeros_like()] - return (gz / sqrt(np.array(1, dtype=x.type) - sqr(x)),) + return (gz / sqrt(np.array(1, dtype=x.dtype) - sqr(x)),) def c_code(self, node, name, inputs, outputs, sub): (x,) = inputs @@ -3630,7 +3630,7 @@ def L_op(self, inputs, outputs, gout): else: return [x.zeros_like()] - return (gz / (np.array(1, dtype=x.type) + sqr(x)),) + return (gz / (np.array(1, dtype=x.dtype) + sqr(x)),) def c_code(self, node, name, inputs, outputs, sub): (x,) = inputs @@ -3753,7 +3753,7 @@ def L_op(self, inputs, outputs, gout): else: return [x.zeros_like()] - return (gz / sqrt(sqr(x) - np.array(1, dtype=x.type)),) + return (gz / sqrt(sqr(x) - np.array(1, dtype=x.dtype)),) def c_code(self, node, name, inputs, outputs, sub): (x,) = inputs @@ -3830,7 +3830,7 @@ def L_op(self, inputs, outputs, gout): else: return [x.zeros_like()] - return (gz / sqrt(sqr(x) + np.array(1, dtype=x.type)),) + return (gz / sqrt(sqr(x) + np.array(1, dtype=x.dtype)),) def c_code(self, node, name, inputs, outputs, sub): (x,) = inputs @@ -3908,7 +3908,7 @@ def L_op(self, inputs, outputs, gout): else: return [x.zeros_like()] - return (gz / (np.array(1, dtype=x.type) - sqr(x)),) + return (gz / (np.array(1, dtype=x.dtype) - sqr(x)),) def c_code(self, node, name, inputs, outputs, sub): (x,) = inputs diff --git a/pytensor/sparse/rewriting.py b/pytensor/sparse/rewriting.py index 4c958dd08f..72d5c1dbb3 100644 --- a/pytensor/sparse/rewriting.py +++ b/pytensor/sparse/rewriting.py @@ -193,7 +193,7 @@ def c_code_cache_version(self): def local_inplace_addsd_ccode(fgraph, node): """Rewrite to insert inplace versions of `AddSD`.""" if isinstance(node.op, sparse.AddSD) and config.cxx: - out_dtype = ps.upcast(*node.inputs) + out_dtype = ps.upcast(*[inp.type.dtype for inp in node.inputs]) if out_dtype != node.inputs[1].dtype: return new_node = AddSD_ccode(format=node.inputs[0].type.format, inplace=True)(