def test_project_array(): np.random.seed(123) U = NumpyVectorSpace.from_numpy(np.random.random((2, 10))) basis = NumpyVectorSpace.from_numpy(np.random.random((3, 10))) U_p = project_array(U, basis, orthonormal=False) onb = gram_schmidt(basis) U_p2 = project_array(U, onb, orthonormal=True) assert np.all(relative_error(U_p, U_p2) < 1e-10)
def test_project_array(arrays): U, basis = arrays U_p = project_array(U, basis, orthonormal=False) onb = gram_schmidt(basis) U_p2 = project_array(U, onb, orthonormal=True) err = relative_error(U_p, U_p2) tol = np.finfo(np.float64).eps * np.linalg.cond(basis.gramian()) * 100. assert np.all(err < tol)
def test_project_array(bases): U = bases[0][:-2] basis = bases[1] U_p = project_array(U, basis, orthonormal=False) onb = gram_schmidt(basis) U_p2 = project_array(U, onb, orthonormal=True) err = relative_error(U_p, U_p2) tol = 3e-10 assert np.all(err < tol)
def test_project_array_with_product(): np.random.seed(123) U = NumpyVectorSpace.from_numpy(np.random.random((1, 10))) basis = NumpyVectorSpace.from_numpy(np.random.random((3, 10))) product = np.random.random((10, 10)) product = NumpyMatrixOperator(product.T.dot(product)) U_p = project_array(U, basis, product=product, orthonormal=False) onb = gram_schmidt(basis, product=product) U_p2 = project_array(U, onb, product=product, orthonormal=True) assert np.all(relative_error(U_p, U_p2, product) < 1e-10)