def check_grad_mat(): import pyublas if not pyublas.has_sparse_wrappers(): return grad_mat = op.grad_matrix() #print len(discr), grad_mat.nnz, type(grad_mat) for i in range(10): u = numpy.random.randn(len(discr)) mat_result = grad_mat * u op_result = numpy.hstack(op.grad(u)) err = la.norm(mat_result-op_result)*la.norm(op_result) assert err < 1e-5
def check_grad_mat(): import pyublas if not pyublas.has_sparse_wrappers(): return grad_mat = op.grad_matrix() #print len(discr), grad_mat.nnz, type(grad_mat) for i in range(10): u = numpy.random.randn(len(discr)) mat_result = grad_mat * u op_result = numpy.hstack(op.grad(u)) err = la.norm(mat_result - op_result) * la.norm(op_result) assert err < 1e-5
def do_test_umfpack(self, dtype): if not pyublas.has_sparse_wrappers(): return if not pyublasext.has_umfpack(): return size = 100 #A = make_random_matrix(size, dtype, numpy.SparseExecuteMatrix) #b = make_random_vector(size, dtype) A = tmd.umf_a[dtype] b = tmd.umf_b[dtype] umf_op = pyublasext.UMFPACKOperator.make(A) x = numpy.zeros((size,), dtype) umf_op.apply(b, x) self.assert_(la.norm(b - A * x) < 1e-10)
def test_add_scattered(self): if not pyublas.has_sparse_wrappers(): return self.for_all_dtypes(self.do_test_add_scattered)
def test_sparse_operators(self): if not pyublas.has_sparse_wrappers(): return for flavor in [pyublas.SparseBuildMatrix, pyublas.SparseExecuteMatrix]: self.do_test_sparse_operators(flavor)
def test_sparse(self): if not pyublas.has_sparse_wrappers(): return self.for_all_dtypes(self.do_test_sparse)
def test_arpack_generalized(self): if not pyublas.has_sparse_wrappers(): return self.for_all_dtypes(self.do_test_arpack_generalized)