Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pytensor/tensor/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3780,15 +3780,16 @@ class AllocDiag(OpFromGraph):
Wrapper Op for alloc_diag graphs
"""

__props__ = ("axis1", "axis2")

def __init__(self, *args, axis1, axis2, offset, **kwargs):
self.axis1 = axis1
self.axis2 = axis2
self.offset = offset

super().__init__(*args, **kwargs, strict=True)

def __str__(self):
return f"AllocDiag{{{self.axis1=}, {self.axis2=}, {self.offset=}}}"

@staticmethod
def is_offset_zero(node) -> bool:
"""
Expand Down
5 changes: 3 additions & 2 deletions pytensor/tensor/einsum.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@
desired. We haven't decided whether we want to provide this functionality.
"""

__props__ = ("subscripts", "path", "optimized")

def __init__(self, *args, subscripts: str, path: PATH, optimized: bool, **kwargs):
self.subscripts = subscripts
self.path = path
self.optimized = optimized
super().__init__(*args, **kwargs, strict=True)

def __str__(self):
return f"Einsum{{{self.subscripts=}, {self.path=}, {self.optimized=}}}"

Check warning on line 62 in pytensor/tensor/einsum.py

View check run for this annotation

Codecov / codecov/patch

pytensor/tensor/einsum.py#L62

Added line #L62 was not covered by tests


def _iota(shape: TensorVariable, axis: int) -> TensorVariable:
"""
Expand Down
10 changes: 8 additions & 2 deletions tests/link/numba/test_cython_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,25 @@ def test_signature_provides(have, want, should_provide):
[np.float64],
float64(float64, int32),
),
(
pytest.param(
# expn doesn't have a float32 implementation
scipy.special.cython_special.expn,
np.float32,
[np.float32, np.float32],
float64(float64, float64, int32),
marks=pytest.mark.xfail(
reason="Failing in newer versions: https://github.com/pymc-devs/pytensor/issues/980"
),
),
(
pytest.param(
# We choose the integer implementation if possible
scipy.special.cython_special.expn,
np.float32,
[np.int64, np.float32],
float64(int64, float64, int32),
marks=pytest.mark.xfail(
reason="Failing in newer versions: https://github.com/pymc-devs/pytensor/issues/980"
),
),
],
)
Expand Down
13 changes: 13 additions & 0 deletions tests/tensor/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
TensorFromScalar,
Tri,
alloc,
alloc_diag,
arange,
as_tensor_variable,
atleast_Nd,
Expand Down Expand Up @@ -3793,6 +3794,18 @@ def test_alloc_diag_values(self):
)
assert np.all(true_grad_input == grad_input)

def test_multiple_ops_same_graph(self):
"""Regression test when AllocDiag OFG was given insufficient props, causing incompatible Ops to be merged."""
v1 = vector("v1", shape=(2,), dtype="float64")
v2 = vector("v2", shape=(3,), dtype="float64")
a1 = alloc_diag(v1)
a2 = alloc_diag(v2)

fn = function([v1, v2], [a1, a2])
res1, res2 = fn(v1=[np.e, np.e], v2=[np.pi, np.pi, np.pi])
np.testing.assert_allclose(res1, np.eye(2) * np.e)
np.testing.assert_allclose(res2, np.eye(3) * np.pi)


def test_diagonal_negative_axis():
x = np.arange(2 * 3 * 3).reshape((2, 3, 3))
Expand Down
Loading