Exemplo n.º 1
0
def test_cholesky_inv_contract_scalar_direct_upper_cholesky_given_identical(test_mat):
    """test cholesky_inv_contract works with a scalar upper triangular"""
    A_i = test_mat.A_i.copy()
    chol_i = test_mat.chol_i_u.copy()
    vec1 = np.random.rand(A_i.shape[0])
    vec2 = vec1
    contract_res = np.dot(np.dot(vec1.T,A_i),vec2)
    contract_res_test = cholesky_inv_contract(chol_i,vec1,vec2,cholesky_given=True,identical_inputs=True,lower=False)

    atol_loc = np.max(np.abs(contract_res))*atol_rel_use

    assert np.allclose(contract_res,contract_res_test,atol=atol_loc,rtol=rtol_use)
Exemplo n.º 2
0
def test_cholesky_inv_contract_matrix_direct_upper_cholesky_given_identical_view(test_mat):
    """test cholesky_inv_contract works with a general upper triangular same matrix twice"""
    A_i = test_mat.A_i.copy()
    chol_i = npl.pinv(spl.cholesky(test_mat.A,lower=False))
    dim1 = A_i.shape[0]
    if dim1==1:
        dim2 = 1
    else:
        dim2 = dim1-1
    vec1 = np.random.rand(dim1,dim2)
    vec2 = vec1
    contract_res = np.dot(np.dot(vec1.T,A_i),vec2)
    contract_res_test = cholesky_inv_contract(chol_i,vec1,vec2,cholesky_given=True,identical_inputs=True,lower=False)

    atol_loc = np.max(np.abs(contract_res))*atol_rel_use

    assert np.allclose(contract_res,contract_res_test,atol=atol_loc,rtol=rtol_use)
Exemplo n.º 3
0
def test_cholesky_inv_contract_matrix_direct_lower_identical_copy(test_mat):
    """test cholesky_inv_contract works with a general lower triangular copy"""
    A_i = test_mat.A_i.copy()
    A_test = test_mat.A.copy()
    dim1 = A_i.shape[0]
    if dim1==1:
        dim2 = 1
    else:
        dim2 = dim1-1
    vec1 = np.random.rand(dim1,dim2)
    vec2 = (vec1).copy()
    contract_res = np.dot(np.dot(vec1.T,A_i),vec2)
    contract_res_test = cholesky_inv_contract(A_test,vec1,vec2,cholesky_given=False,identical_inputs=True,lower=True)

    atol_loc = np.max(np.abs(contract_res))*atol_rel_use

    assert np.allclose(contract_res,contract_res_test,atol=atol_loc,rtol=rtol_use)