Skip to content

Commit 6d431aa

Browse files
dehorsleyricardoV94
authored andcommitted
Move linalg rewrites, delete sandbox
Moving caused a circular dependency with tensor.blas. It seems most linalg rewrites are in the stablize set, so should run before the blas specializers anyway, so these checks were removed. This also deleted the unused `spectral_radius_bound` and dummy `Minimal(Op)`.
1 parent c655b02 commit 6d431aa

File tree

9 files changed

+2
-127
lines changed

9 files changed

+2
-127
lines changed

pytensor/sandbox/__init__.py

Whitespace-only changes.

pytensor/sandbox/linalg/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

pytensor/sandbox/minimal.py

Lines changed: 0 additions & 46 deletions
This file was deleted.

pytensor/tensor/rewriting/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
# Register JAX specializations
99
import pytensor.tensor.rewriting.jax
10+
import pytensor.tensor.rewriting.linalg
1011
import pytensor.tensor.rewriting.math
1112
import pytensor.tensor.rewriting.shape
1213
import pytensor.tensor.rewriting.special
File renamed without changes.

tests/sandbox/__init__.py

Whitespace-only changes.

tests/sandbox/linalg/__init__.py

Whitespace-only changes.

tests/sandbox/test_minimal.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

tests/sandbox/linalg/test_linalg.py renamed to tests/tensor/rewriting/test_linalg.py

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
from pytensor import function
66
from pytensor import tensor as at
77
from pytensor.configdefaults import config
8-
from pytensor.sandbox.linalg.ops import inv_as_solve, spectral_radius_bound
98
from pytensor.tensor.elemwise import DimShuffle
109
from pytensor.tensor.math import _allclose
1110
from pytensor.tensor.nlinalg import MatrixInverse, matrix_inverse
11+
from pytensor.tensor.rewriting.linalg import inv_as_solve
1212
from pytensor.tensor.slinalg import Cholesky, Solve, solve
1313
from pytensor.tensor.type import dmatrix, matrix, vector
1414
from tests import unittest_tools as utt
@@ -65,53 +65,6 @@ def test_rop_lop():
6565
assert _allclose(v1, v2), f"LOP mismatch: {v1} {v2}"
6666

6767

68-
def test_spectral_radius_bound():
69-
tol = 10 ** (-6)
70-
rng = np.random.default_rng(utt.fetch_seed())
71-
x = matrix()
72-
radius_bound = spectral_radius_bound(x, 5)
73-
f = pytensor.function([x], radius_bound)
74-
75-
shp = (3, 4)
76-
m = rng.random(shp)
77-
m = np.cov(m).astype(config.floatX)
78-
radius_bound_pytensor = f(m)
79-
80-
# test the approximation
81-
mm = m
82-
for i in range(5):
83-
mm = np.dot(mm, mm)
84-
radius_bound_numpy = np.trace(mm) ** (2 ** (-5))
85-
assert abs(radius_bound_numpy - radius_bound_pytensor) < tol
86-
87-
# test the bound
88-
eigen_val = numpy.linalg.eig(m)
89-
assert (eigen_val[0].max() - radius_bound_pytensor) < tol
90-
91-
# test type errors
92-
xx = vector()
93-
ok = False
94-
try:
95-
spectral_radius_bound(xx, 5)
96-
except TypeError:
97-
ok = True
98-
assert ok
99-
ok = False
100-
try:
101-
spectral_radius_bound(x, 5.0)
102-
except TypeError:
103-
ok = True
104-
assert ok
105-
106-
# test value error
107-
ok = False
108-
try:
109-
spectral_radius_bound(x, -5)
110-
except ValueError:
111-
ok = True
112-
assert ok
113-
114-
11568
def test_transinv_to_invtrans():
11669
X = matrix("X")
11770
Y = matrix_inverse(X)

0 commit comments

Comments
 (0)