Пример #1
0
def lu_solve(lu_and_piv: tp.Tuple[ndarray, ndarray],
             b: ndarray,
             trans: int = 0,
             overwrite_b: bool = False,
             check_finite: bool = True) -> ndarray:
    """
    Solve an equation system, a x = b, given the LU factorization of a
    """

    if len(lu_and_piv) != 2:
        raise ValueError("lu_and_piv must be a two-dimensional tuple")

    lu, piv = lu_and_piv
    options = convert_trans_to_af_matprop(trans)

    return ndarray(af.solve_lu(lu._af_array,
                               piv._af_array,
                               b._af_array,
                               options=options))
Пример #2
0
def simple_lapack(verbose=False):
    display_func = _util.display_func(verbose)
    print_func = _util.print_func(verbose)
    a = af.randu(5, 5)

    l, u, p = af.lu(a)

    display_func(l)
    display_func(u)
    display_func(p)

    p = af.lu_inplace(a, "full")

    display_func(a)
    display_func(p)

    a = af.randu(5, 3)

    q, r, t = af.qr(a)

    display_func(q)
    display_func(r)
    display_func(t)

    af.qr_inplace(a)

    display_func(a)

    a = af.randu(5, 5)
    a = af.matmulTN(a, a.copy()) + 10 * af.identity(5, 5)

    R, info = af.cholesky(a)
    display_func(R)
    print_func(info)

    af.cholesky_inplace(a)
    display_func(a)

    a = af.randu(5, 5)
    ai = af.inverse(a)

    display_func(a)
    display_func(ai)

    x0 = af.randu(5, 3)
    b = af.matmul(a, x0)
    x1 = af.solve(a, b)

    display_func(x0)
    display_func(x1)

    p = af.lu_inplace(a)

    x2 = af.solve_lu(a, p, b)

    display_func(x2)

    print_func(af.rank(a))
    print_func(af.det(a))
    print_func(af.norm(a, af.NORM.EUCLID))
    print_func(af.norm(a, af.NORM.MATRIX_1))
    print_func(af.norm(a, af.NORM.MATRIX_INF))
    print_func(af.norm(a, af.NORM.MATRIX_L_PQ, 1, 1))

    a = af.randu(10, 10)
    display_func(a)
    u, s, vt = af.svd(a)
    display_func(af.matmul(af.matmul(u, af.diag(s, 0, False)), vt))
    u, s, vt = af.svd_inplace(a)
    display_func(af.matmul(af.matmul(u, af.diag(s, 0, False)), vt))
Пример #3
0
def simple_lapack(verbose=False):
    display_func = _util.display_func(verbose)
    print_func   = _util.print_func(verbose)
    a = af.randu(5,5)

    l,u,p = af.lu(a)

    display_func(l)
    display_func(u)
    display_func(p)

    p = af.lu_inplace(a, "full")

    display_func(a)
    display_func(p)

    a = af.randu(5,3)

    q,r,t = af.qr(a)

    display_func(q)
    display_func(r)
    display_func(t)

    af.qr_inplace(a)

    display_func(a)

    a = af.randu(5, 5)
    a = af.matmulTN(a, a) + 10 * af.identity(5,5)

    R,info = af.cholesky(a)
    display_func(R)
    print_func(info)

    af.cholesky_inplace(a)
    display_func(a)

    a = af.randu(5,5)
    ai = af.inverse(a)

    display_func(a)
    display_func(ai)

    x0 = af.randu(5, 3)
    b = af.matmul(a, x0)
    x1 = af.solve(a, b)

    display_func(x0)
    display_func(x1)

    p = af.lu_inplace(a)

    x2 = af.solve_lu(a, p, b)

    display_func(x2)

    print_func(af.rank(a))
    print_func(af.det(a))
    print_func(af.norm(a, af.NORM.EUCLID))
    print_func(af.norm(a, af.NORM.MATRIX_1))
    print_func(af.norm(a, af.NORM.MATRIX_INF))
    print_func(af.norm(a, af.NORM.MATRIX_L_PQ, 1, 1))
print(info)

af.cholesky_inplace(a)
af.display(a)

a = af.randu(5, 5)
ai = af.inverse(a)

af.display(a)
af.display(ai)

x0 = af.randu(5, 3)
b = af.matmul(a, x0)
x1 = af.solve(a, b)

af.display(x0)
af.display(x1)

p = af.lu_inplace(a)

x2 = af.solve_lu(a, p, b)

af.display(x2)

print(af.rank(a))
print(af.det(a))
print(af.norm(a, af.AF_NORM_EUCLID))
print(af.norm(a, af.AF_NORM_MATRIX_1))
print(af.norm(a, af.AF_NORM_MATRIX_INF))
print(af.norm(a, af.AF_NORM_MATRIX_L_PQ, 1, 1))