Skip to content

Commit 3fa6de4

Browse files
committed
TST: add max_dim support for RitzDecomposition.
1 parent f33d24d commit 3fa6de4

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/test_decomposition.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ def sort_by_criteria(x):
2020
return x[idx]
2121

2222

23+
def inject_noise(A):
24+
A[:] = np.random.randn(*A.shape)
25+
26+
2327
def basis_vector(n, k, dtype=np.int64):
2428
"""Create the basis vector e_k in R^n, aka e_k is (n,), and with e_k[k] =
2529
1
@@ -267,3 +271,34 @@ def test_residual_computation(self, A, m):
267271
residuals, rtol=RTOL, atol=ATOL)
268272
np.testing.assert_allclose(ritz.approximate_residuals, residuals,
269273
rtol=RTOL, atol=ATOL)
274+
275+
def test_max_dim(self):
276+
# Ensure max_dim is correctly implemented in RitzDecomposition
277+
## Given
278+
A = mark(10)
279+
n = A.shape[0]
280+
m = 20
281+
k = 2
282+
max_dim = m - 5
283+
284+
## When
285+
arnoldi = ArnoldiDecomposition(n, m)
286+
arnoldi.initialize()
287+
arnoldi.iterate(A)
288+
V, H = arnoldi.V, arnoldi.H
289+
290+
inject_noise(V[:, max_dim:])
291+
inject_noise(H[max_dim+1:,max_dim:])
292+
293+
broken_ritz = RitzDecomposition.from_v_and_h(V, H, k)
294+
ritz = RitzDecomposition.from_v_and_h(V, H, k, max_dim=max_dim)
295+
296+
## Then
297+
with pytest.raises(AssertionError):
298+
np.testing.assert_allclose(broken_ritz.compute_true_residuals(A),
299+
broken_ritz.approximate_residuals,
300+
rtol=RTOL, atol=ATOL)
301+
302+
np.testing.assert_allclose(ritz.compute_true_residuals(A),
303+
ritz.approximate_residuals, rtol=RTOL,
304+
atol=ATOL)

0 commit comments

Comments
 (0)