|
5 | 5 | from pytensor import function
|
6 | 6 | from pytensor import tensor as at
|
7 | 7 | from pytensor.configdefaults import config
|
8 |
| -from pytensor.sandbox.linalg.ops import inv_as_solve, spectral_radius_bound |
9 | 8 | from pytensor.tensor.elemwise import DimShuffle
|
10 | 9 | from pytensor.tensor.math import _allclose
|
11 | 10 | from pytensor.tensor.nlinalg import MatrixInverse, matrix_inverse
|
| 11 | +from pytensor.tensor.rewriting.linalg import inv_as_solve |
12 | 12 | from pytensor.tensor.slinalg import Cholesky, Solve, solve
|
13 | 13 | from pytensor.tensor.type import dmatrix, matrix, vector
|
14 | 14 | from tests import unittest_tools as utt
|
@@ -65,53 +65,6 @@ def test_rop_lop():
|
65 | 65 | assert _allclose(v1, v2), f"LOP mismatch: {v1} {v2}"
|
66 | 66 |
|
67 | 67 |
|
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 |
| - |
115 | 68 | def test_transinv_to_invtrans():
|
116 | 69 | X = matrix("X")
|
117 | 70 | Y = matrix_inverse(X)
|
|
0 commit comments