def test_solve_block_toeplitz(): A = BlockToeplitzMatrix([[(lambda: np.random.rand(1, 1))() for _ in range(7)]]) b = np.random.rand(A.shape[0]) assert np.allclose(BlockMatrix.matvec(A, b), A.full_matrix() @ b) assert np.allclose(A @ b, A.full_matrix() @ b) x_gmres = solve_gmres(A, b) x_dumb_gmres = solve_gmres(A.full_matrix(), b) assert np.allclose(x_gmres, x_dumb_gmres, rtol=1e-6)
def test_solve_nested_block_circulant(): A = BlockCirculantMatrix( [[random_block_matrix([1, 1], [1, 1]) for _ in range(6)]]) b = np.random.rand(A.shape[0]) x_circ = solve_directly(A, b) x_dumb = np.linalg.solve(A.full_matrix(), b) assert np.allclose(x_circ, x_dumb, rtol=1e-6) x_gmres = solve_gmres(A, b) x_dumb_gmres = solve_gmres(A.full_matrix(), b) assert np.allclose(x_gmres, x_dumb_gmres, rtol=1e-6)