def test_pod(vector_array, method): A = vector_array # TODO assumption here masks a potential issue with the algorithm # where it fails in internal lapack instead of a proper error assume(len(A) > 1 or A.dim > 1) assume(not contains_zero_vector(A, rtol=1e-13, atol=1e-13)) B = A.copy() orth_tol = 1e-10 U, s = pod(A, method=method, orth_tol=orth_tol) assert np.all(almost_equal(A, B)) assert len(U) == len(s) assert np.allclose(U.gramian(), np.eye(len(s)), atol=orth_tol)
def test_gram_schmidt(vector_array): U = vector_array # TODO assumption here masks a potential issue with the algorithm # where it fails in del instead of a proper error assume(len(U) > 1 or not contains_zero_vector(U)) V = U.copy() onb = gram_schmidt(U, copy=True) assert np.all(almost_equal(U, V)) assert np.allclose(onb.dot(onb), np.eye(len(onb))) # TODO maybe raise tolerances again assert np.all( almost_equal(U, onb.lincomb(onb.dot(U).T), atol=1e-13, rtol=1e-13)) onb2 = gram_schmidt(U, copy=False) assert np.all(almost_equal(onb, onb2)) assert np.all(almost_equal(onb, U))
def test_method_of_snapshots(vector_array, method): A = vector_array[0] # TODO assumption here masks a potential issue with the algorithm # where it fails in internal lapack instead of a proper error assume(len(A) > 1 or A.dim > 1) assume(not contains_zero_vector(A, rtol=1e-13, atol=1e-13)) B = A.copy() with log_levels({"pymor.algorithms": "ERROR"}): U, s, Vh = method(A) assert np.all(almost_equal(A, B)) assert len(U) == len(s) == Vh.shape[0] assert Vh.shape[1] == len(A) assert np.allclose(Vh @ Vh.T.conj(), np.eye(len(s))) U.scal(s) UsVh = U.lincomb(Vh.T) assert np.all(almost_equal(A, UsVh, rtol=4e-8))
def test_gram_schmidt_with_R(vector_array): U = vector_array # TODO assumption here masks a potential issue with the algorithm # where it fails in del instead of a proper error assume(len(U) > 1 or not contains_zero_vector(U)) V = U.copy() onb, R = gram_schmidt(U, return_R=True, copy=True) assert np.all(almost_equal(U, V)) assert np.allclose(onb.dot(onb), np.eye(len(onb))) lc = onb.lincomb(onb.dot(U).T) rtol = atol = 1e-13 assert np.all(almost_equal(U, lc, rtol=rtol, atol=atol)) assert np.all(almost_equal(V, onb.lincomb(R.T), rtol=rtol, atol=atol)) onb2, R2 = gram_schmidt(U, return_R=True, copy=False) assert np.all(almost_equal(onb, onb2)) assert np.all(R == R2) assert np.all(almost_equal(onb, U))