def test_dense_solve_single_rhs(self): solver = QRMUMPSSolver((self.m, self.n, self.arow, self.acol, self.aval), verbose=False) solver.factorize() e = np.ones(self.n, dtype=np.float64) rhs = np.dot(self.A, e) x = solver.solve(rhs) assert np.allclose(np.dot(self.A,x), rhs, 1e-5)
def test_dense_minimum_norm_multiple_rhs(self): solver = QRMUMPSSolver(self.A, verbose=False) B = np.ones([self.m, 3], dtype=np.float64) B[:, 1] = 2 * B[:, 1] B[:, 2] = 3 * B[:, 2] with pytest.raises(RuntimeError): solver = solver.minimum_norm(B)
def test_dense_solve_single_rhs(self): solver = QRMUMPSSolver(self.A, verbose=False) solver.factorize() e = np.ones(self.n, dtype=np.complex64) rhs = self.A * e x = solver.solve(rhs) assert np.allclose(x, e, 1e-5)
def test_dense_least_squares_multiple_rhs(self): solver = QRMUMPSSolver((self.m, self.n, self.arow, self.acol, self.aval), verbose=False) B = np.ones([self.n, 3], dtype=np.complex64) B[:, 1] = 2 * B[:, 1] B[:, 2] = 3 * B[:, 2] rhs = np.dot(self.A, B) x = solver.least_squares(rhs) assert np.allclose(x, B, 1e-5)
def test_dense_minimum_norm_multiple_rhs(self): solver = QRMUMPSSolver((self.m, self.n, self.arow, self.acol, self.aval), verbose=False) B = np.ones([self.n, 3], dtype=np.float64) B[: ,1] = 2 * B[:,1] B[: ,2] = 3 * B[:,2] rhs = np.dot(self.A, B) x = solver.minimum_norm(rhs) assert np.allclose(np.dot(self.A,x), rhs, 1e-5)
def test_dense_minimum_norm_multiple_rhs(self): solver = QRMUMPSSolver((self.m, self.n, self.arow, self.acol, self.aval), verbose=False) B = np.ones([self.n, 3], dtype=np.complex64) B[: ,1] = 2 * B[:,1] B[: ,2] = 3 * B[:,2] rhs = np.dot(self.A, B) with pytest.raises(RuntimeError): x = solver.minimum_norm(rhs)
def test_dense_solve_multiple_rhs(self): solver = QRMUMPSSolver((self.m, self.n, self.arow, self.acol, self.aval), verbose=False) solver.factorize() B = np.ones([self.n, 3], dtype=np.float64) B[: ,1] = 2 * B[:,1] B[: ,2] = 3 * B[:,2] rhs = np.dot(self.A,B) x = solver.solve(rhs) assert np.allclose(x, B, 1e-5)
def test_dense_minimum_norm_multiple_rhs(self): solver = QRMUMPSSolver(self.A, verbose=False) B = np.ones([self.m, 3], dtype=np.float64) B[:, 1] = 2 * B[:, 1] B[:, 2] = 3 * B[:, 2] x = solver.minimum_norm(B) assert np.allclose(self.A * x[:, 0], B[:, 0], 1e-5) assert np.allclose(self.A * x[:, 1], B[:, 1], 1e-5) assert np.allclose(self.A * x[:, 2], B[:, 2], 1e-5)
def test_dense_solve_multiple_rhs(self): solver = QRMUMPSSolver(self.A, verbose=False) solver.factorize() B = np.ones([self.m, 3], dtype=np.float32) B[:, 1] = 2 * B[:, 1] B[:, 2] = 3 * B[:, 2] x = solver.solve(B) assert np.allclose(self.A * x[:, 0], B[:, 0], 1e-5) assert np.allclose(self.A * x[:, 1], B[:, 1], 1e-5) assert np.allclose(self.A * x[:, 2], B[:, 2], 1e-5)
def test_dense_least_squares_multiple_rhs(self): solver = QRMUMPSSolver(self.A, verbose=False) B = np.ones([self.n, 3], dtype=np.float64) B[:, 1] = 2 * B[:, 1] B[:, 2] = 3 * B[:, 2] rhs = np.ones([self.m, 3], dtype=np.float64) rhs[:, 0] = self.A * B[:, 0] rhs[:, 1] = self.A * B[:, 1] rhs[:, 2] = self.A * B[:, 2] x = solver.least_squares(rhs) assert np.allclose(x, B, 1e-5)
def test_dense_solve_multiple_rhs(self): solver = QRMUMPSSolver(self.A, verbose=False) solver.factorize() B = np.ones([self.n, 3], dtype=np.complex64) B[:, 1] = 2 * B[:, 1] B[:, 2] = 3 * B[:, 2] rhs = np.ones([self.m, 3], dtype=np.complex64) rhs[:, 0] = self.A * B[:, 0] rhs[:, 1] = self.A * B[:, 1] rhs[:, 2] = self.A * B[:, 2] x = solver.solve(rhs) assert np.allclose(x, B, 1e-5)
from qr_mumps.solver import QRMUMPSSolver import numpy as np m = 7 n = 5 arow = np.array([1,2,5,0,5,1,3,4,6,1,2,1,3], dtype=np.int32) acol = np.array([0,0,0,1,1,2,2,2,2,3,3,4,4], dtype=np.int32) aval = np.array([0.7,0.6,0.4,0.1,0.1,0.3,0.6,0.7,0.2,0.5,0.2,0.1,0.6], dtype=np.complex64) solver = QRMUMPSSolver((m, n, arow, acol, aval), verbose=False) solver.analyze() solver.factorize() rhs = np.ones(m, dtype=np.complex64) print "rhs:" print rhs x = solver.solve(rhs) print "x:" print x
def test_dense_minimum_norm_wrong_size_rhs(self): solver = QRMUMPSSolver(self.A, verbose=False) rhs = np.ones([self.m + 1, 1], dtype=np.float64) with pytest.raises(ValueError): x = solver.minimum_norm(rhs)
def test_least_squares(self): solver = QRMUMPSSolver(self.A, verbose=False) rhs = np.ones([self.m, 1], dtype=np.float64) with pytest.raises(RuntimeError): x = solver.least_squares(rhs)
def test_factorize(self): solver = QRMUMPSSolver((self.m, self.n, self.arow, self.acol, self.aval), verbose=False) solver.factorize() assert solver.analyzed==True assert solver.factorized==True
def test_dense_least_squares_wrong_size_rhs(self): solver = QRMUMPSSolver(self.A, verbose=False) rhs = np.ones([self.m + 1, 1], dtype=np.float64) with pytest.raises(ValueError): solver = solver.least_squares(rhs)
def test_dense_minimum_norm_wrong_size_rhs(self): solver = QRMUMPSSolver((self.m, self.n, self.arow, self.acol, self.aval), verbose=False) rhs = np.ones([self.m+1, 1], dtype=np.float32) with pytest.raises(ValueError): x = solver.minimum_norm(rhs)
def test_factorize(self): solver = QRMUMPSSolver(self.A, verbose=False) solver.factorize() assert solver.analyzed is True assert solver.factorized is True
def test_dense_least_squares_wrong_size_rhs(self): solver = QRMUMPSSolver((self.m, self.n, self.arow, self.acol, self.aval), verbose=False) rhs = np.ones([self.m+1, 1], dtype=np.complex64) with pytest.raises(ValueError): x = solver.least_squares(rhs)
arow = np.array([0,0,0,1,1,2,2,2,2,3,3,4,4], dtype=np.int32) acol = np.array([1,2,5,0,5,1,3,4,6,1,2,1,3], dtype=np.int32) aval = np.array([0.7,0.6,0.4,0.1,0.1,0.3,0.6,0.7,0.2,0.5,0.2,0.1,0.6], dtype=np.float64) print "A:" print A print "-"*80 print "Loop intantiating a solver and solving with one rhs" print "-"*80 for i in xrange(0,10): print " "+"-"*76 print " i = %d"%i print " "+"-"*76 solver = QRMUMPSSolver((m, n, arow, acol, aval), verbose=False) solver.factorize('scotch') print solver.factorization_statistics e = (i+1)*np.ones(n, dtype=np.float64) rhs = np.dot(A, e) print " rhs:" print rhs x = solver.solve(rhs) print " x:" print x
from qr_mumps.solver import QRMUMPSSolver import numpy as np m = 4 n = 4 A = np.array([[1, 2, 3, 4], [5, 0, 7, 8], [9, 10, 0, 12], [13, 14, 15, 0]], dtype=np.float64) arow = np.array([0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3], dtype=np.int32) acol = np.array([0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3], dtype=np.int32) aval = np.array([1, 2, 3, 4, 5, 0, 7, 8, 9, 10, 0, 12, 13, 14, 15, 0], dtype=np.float64) print "A:" print A solver = QRMUMPSSolver((m, n, arow, acol, aval), verbose=False) solver.analyze() solver.factorize() print "\n\nSolving Ax = b where b is a vector" e = np.ones(n, dtype=np.float64) b = np.dot(A, e) print "b:" print b x = solver.solve(b) np.testing.assert_almost_equal(x, e) print "x: it should be a vector of ones" print x
from qr_mumps.solver import QRMUMPSSolver import numpy as np import sys A = LLSparseMatrix(mm_filename=sys.argv[1], itype=types.INT32_T, dtype=types.COMPLEX128_T) (n, m) = A.shape print "A:" print A e = np.ones(n, dtype=np.complex128) rhs = A * e solver = QRMUMPSSolver(A, verbose=True) solver.analyze() solver.factorize() x = solver.solve(rhs) print "x should be 1-column vector:" print x print "=" * 80 rhs = np.ones([n, 3], dtype=np.complex128) rhs[:, 1] = 2 * rhs[:, 1] rhs[:, 2] = 3 * rhs[:, 2]
def test_least_squares(self): solver = QRMUMPSSolver((self.m, self.n, self.arow, self.acol, self.aval), verbose=False) rhs = np.ones([self.m, 1], dtype=np.float32) with pytest.raises(RuntimeError): x = solver.least_squares(rhs)