Beispiel #1
0
def test_basic_spsolve_matrix():
    ps.remove_stored_factorization()
    ps.free_memory()
    A, b = create_test_A_b_rand(matrix=True)
    xpp = spsolve(A, b)
    xscipy = scipyspsolve(A, b)
    np.testing.assert_array_almost_equal(xpp, xscipy)
Beispiel #2
0
def test_input_b_shape():
    A, b = create_test_A_b_rand()
    x_array = ps.solve(A,b)
    assert x_array.shape == b.shape
    x_vector = ps.solve(A, b.squeeze())
    assert x_vector.shape == b.squeeze().shape
    np.testing.assert_array_equal(x_array.squeeze(), x_vector)
Beispiel #3
0
def test_input_A_empty_row():
    A, b = create_test_A_b_rand(25, 0.7)
    A = np.array(A.todense())
    A[0,:] = 0
    A[1, 0] = 1
    Asp = sp.csr_matrix(A)
    with pytest.raises(ValueError):
        basic_solve(Asp,b)
Beispiel #4
0
def test_spsolve_csc_matrix():
    ps.remove_stored_factorization()
    ps.free_memory()
    A, b = create_test_A_b_rand()
    x_csc = spsolve(A.tocsc(), b)
    assert sp.isspmatrix_csr(ps.factorized_A)
    x_csr = spsolve(A, b)
    np.testing.assert_array_equal(x_csr, x_csc)
Beispiel #5
0
def test_basic_factorized():
    ps.remove_stored_factorization()
    ps.free_memory()
    A, b = create_test_A_b_rand()
    ppfact = factorized(A)
    xpp = ppfact(b)
    scipyfact = scipyfactorized(A)
    xscipy = scipyfact(b)
    np.testing.assert_array_almost_equal(xpp, xscipy)
Beispiel #6
0
def test_factorized_csc_matrix():
    ps.remove_stored_factorization()
    ps.free_memory()
    A, b = create_test_A_b_rand()
    Afact_csr = factorized(A)
    Afact_csc = factorized(A.tocsc())
    assert sp.isspmatrix_csr(Afact_csc.args[0])
    x1 = Afact_csr(b)
    x2 = Afact_csc(b)
    np.testing.assert_array_equal(x1, x2)
Beispiel #7
0
def test_input_b_dtypes():
    A, b = create_test_A_b_rand()
    for dt in [np.float16, np.float32, np.int16, np.int32, np.int64]:
        bdt = b.astype(dt)
        with pytest.warns(PyPardisoWarning):
            basic_solve(A, bdt)
            
    for dt in [np.complex64, np.complex128, np.complex128, np.uint16, np.uint32, np.uint64]:
        bdt = b.astype(dt)
        with pytest.raises(TypeError):
            basic_solve(A, bdt)
Beispiel #8
0
def test_input_A_non_sparse():
    A, b = create_test_A_b_rand(10,0.9)
    A = A.todense()
    assert not sp.issparse(A)
    with pytest.raises(TypeError):
        ps.solve(A,b)
Beispiel #9
0
def test_input_A_dtypes():
    A, b = create_test_A_b_rand(10,0.5)
    for d in [np.float16, np.float32, np.int16, np.int32, np.int64, np.complex64, 
              np.complex128, np.complex128, np.uint16, np.uint32, np.uint64]:
        with pytest.raises(TypeError):
            ps.solve(A.astype(d), b)
Beispiel #10
0
def test_input_A_other_sparse():
    A, b = create_test_A_b_rand(50)
    for f in ['coo', 'lil', 'dia']:
        Aother = A.asformat(f)
        with pytest.raises(TypeError):
            ps.solve(Aother,b)
Beispiel #11
0
def test_bvector_smoketest():
    A, b = create_test_A_b_rand()
    basic_solve(A, b)
Beispiel #12
0
def test_input_A_nonsquare():
    A, b = create_test_A_b_rand()
    A = sp.csr_matrix(np.concatenate([A.todense(), np.ones((A.shape[0], 1))], axis=1))
    with pytest.raises(ValueError):
        basic_solve(A,b)
Beispiel #13
0
def test_bmatrix_smoketest():
    A, b = create_test_A_b_rand(matrix=True)
    basic_solve(A, b)
Beispiel #14
0
def test_input_b_wrong_shape():
    A, b = create_test_A_b_rand()
    b = np.append(b, 1)
    with pytest.raises(ValueError):
        basic_solve(A,b)
Beispiel #15
0
def test_input_b_fortran_order():
    A, b = create_test_A_b_rand(matrix=True)
    x = ps.solve(A,b)
    xfort = ps.solve(A, np.asfortranarray(b))
    np.testing.assert_array_equal(x, xfort)
Beispiel #16
0
def test_input_A_csc():
    A, b = create_test_A_b_rand()
    x_csr = ps.solve(A,b)
    Acsc = A.copy().asformat('csc')
    x_csc = ps.solve(Acsc, b)
    np.testing.assert_array_almost_equal(x_csr, x_csc)
Beispiel #17
0
def test_input_b_sparse():
    A, b = create_test_A_b_rand()
    bsparse = sp.csr_matrix(b)
    with pytest.warns(SparseEfficiencyWarning):
        x = ps.solve(A, bsparse)
        np.testing.assert_array_almost_equal(A*x, b)