Compare commits
No commits in common. '35bbbc252000b1ef71cb210fc4bb9584392361b5' and '1ae5d329f22dfb9bb14f247b4f6a454510b9040e' have entirely different histories.
35bbbc2520
...
1ae5d329f2
@ -1,29 +0,0 @@
|
||||
import numpy as np
|
||||
import numpy.linalg as LA
|
||||
from afgl.lanczos import lanczos
|
||||
|
||||
"""
|
||||
Todo: better test case
|
||||
"""
|
||||
|
||||
|
||||
def test_lanczos_return_correct_solution():
|
||||
N = 1000
|
||||
M = 999
|
||||
|
||||
eigvals = np.random.uniform(10000, 100000, N)
|
||||
Q, _ = LA.qr(np.random.randn(N, N))
|
||||
L = Q @ np.diag(eigvals) @ Q.T
|
||||
|
||||
s = np.random.randint(1, 10, N)
|
||||
[V, alp, beta] = lanczos(L, s, M)
|
||||
|
||||
T = np.diag(alp) + np.diag(beta, -1) + np.diag(beta, 1)
|
||||
|
||||
x = LA.solve(L, s)
|
||||
e_1 = np.zeros(M)
|
||||
e_1[0] = 1
|
||||
y = (LA.inv(T) @ e_1) * LA.norm(s)
|
||||
x_lanczos = V @ y
|
||||
|
||||
assert LA.norm(x - x_lanczos) < 1e-10
|
||||
Loading…
Reference in New Issue