Пример #1
0
def test_get_cholesky_inv_upper(test_mat):
    """test get_cholesky_inv with upper triangular"""
    A = test_mat.A.copy()
    A_i = test_mat.A_i.copy()
    chol_test_inv = get_cholesky_inv(A,lower=False)
    chol_test = get_cholesky_inv(A_i,lower=False)

    assert check_is_cholesky(chol_test_inv,A_i,lower=False,atol_rel=atol_rel_use,rtol=rtol_use)
    assert check_is_cholesky(chol_test,A,lower=False,atol_rel=atol_rel_use,rtol=rtol_use)
Пример #2
0
def test_basic_setup_succeeded(test_mat):
    """test self consistency of setup"""
    chol_i1 = test_mat.chol_i.copy()
    chol1 = test_mat.chol.copy()
    chol_i1_u = test_mat.chol_i_u.copy()
    chol1_u = test_mat.chol_u.copy()
    A = test_mat.A.copy()
    A_i = test_mat.A_i.copy()

    assert check_is_cholesky_inv(chol_i1,A,atol_rel=atol_rel_use,rtol=rtol_use,lower=True)
    assert check_is_cholesky(chol1,A,lower=True,atol_rel=atol_rel_use,rtol=rtol_use)
    assert check_is_cholesky_inv(chol_i1_u,A,atol_rel=atol_rel_use,rtol=rtol_use,lower=False)
    assert check_is_cholesky(chol1_u,A,lower=False,atol_rel=atol_rel_use,rtol=rtol_use)
    assert np.allclose(npl.pinv(A_i),A,atol=relax_atol,rtol=relax_rtol)
    assert np.allclose(npl.pinv(chol_i1),chol1,atol=relax_atol,rtol=relax_rtol)
Пример #3
0
def test_cholesky_inplace_not_inplace_C_order(test_mat):
    """test cholesky_inplace works C ordering """
    A = test_mat.A.copy()
    chol1 = test_mat.chol.copy()
    #Test doing cholesky not in place with C ordering
    test_chol_inplace2 = A.copy('C')
    test_chol_inplace2_res = cholesky_inplace(test_chol_inplace2,inplace=False,lower=True)

    atol_loc1 = np.max(np.abs(A))*atol_rel_use
    atol_loc3 = np.max(np.abs(chol1))*atol_rel_use

    assert check_is_cholesky(test_chol_inplace2_res,A,lower=True,atol_rel=atol_rel_use,rtol=rtol_use)
    assert np.allclose(chol1,test_chol_inplace2_res,atol=atol_loc3,rtol=rtol_use)
    assert np.allclose(test_chol_inplace2,A,atol=atol_loc1,rtol=rtol_use)
Пример #4
0
def test_cholesky_inplace_inplace_F_order(test_mat):
    """test cholesky_inplace works F ordering """
    A = test_mat.A.copy()
    chol1 = test_mat.chol.copy()

    #Test doing cholesky in place with cholesky_inplace
    test_chol_inplace1 = A.copy('F')
    cholesky_inplace(test_chol_inplace1,inplace=True,lower=True)

    atol_loc3 = np.max(np.abs(chol1))*atol_rel_use

    assert check_is_cholesky(test_chol_inplace1,A,lower=True,atol_rel=atol_rel_use,rtol=rtol_use)
    assert np.allclose(chol1,test_chol_inplace1,atol=atol_loc3,rtol=rtol_use)
    test_chol_inplace1 = None
Пример #5
0
def test_cholesky_inplace_inplace_C_order_nonfatal(test_mat):
    """test cholesky_inplace works C ordering with error recovery"""
    A = test_mat.A.copy()
    chol1 = test_mat.chol.copy()
    #Test doing cholesky in place with C ordering (should cause warning unless also F ordering)
    test_chol_inplace4 = A.copy('C')

    atol_loc1 = np.max(np.abs(A))*atol_rel_use
    atol_loc3 = np.max(np.abs(chol1))*atol_rel_use

    with warnings.catch_warnings(record=True) as w:
        if not test_chol_inplace4.flags['F']:
            warnings.simplefilter("always")
            test_chol_inplace4_res = cholesky_inplace(test_chol_inplace4,inplace=True,fatal_errors=False)
            #check if it caused the warning
            assert len(w)==1
            assert issubclass(w[-1].category,RuntimeWarning)
            assert check_is_cholesky(test_chol_inplace4_res,A,atol_rel=atol_rel_use,rtol=rtol_use,lower=True)
            assert np.allclose(chol1,test_chol_inplace4_res,atol=atol_loc3,rtol=rtol_use)
            assert np.allclose(test_chol_inplace4,A,atol=atol_loc1,rtol=rtol_use)
    test_chol_inplace4 = None
    test_chol_inplace4_res = None