コード例 #1
0
ファイル: linalg.py プロジェクト: eeeedgar/model_1
def _lu_internal(a: ndarray,
                 permute_l: bool = False,
                 overwrite_a: bool = False,
                 is_lapack_piv: bool = True) \
        -> tp.Union[tp.Tuple[ndarray, ndarray],
                    tp.Tuple[ndarray, ndarray, ndarray]]:
    if overwrite_a:
        if permute_l:
            if is_lapack_piv:
                pivot = "lapack"
            else:
                pivot = "full"

            P = af.lu_inplace(a._af_array, pivot=pivot)
            return ndarray(P), a
        else:
            raise ValueError("cannot overwrite a without permuting l")
    else:
        if permute_l:
            raise ValueError("cannot permute l without overwriting a")
        else:
            (L, U, P) = af.lu(a._af_array)
            return ndarray(P), ndarray(L), ndarray(U)
コード例 #2
0
ファイル: lapack.py プロジェクト: eeeedgar/model_1
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
ファイル: lapack.py プロジェクト: syurkevi/arrayfire-python
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))
コード例 #4
0
#!/usr/bin/python
#######################################################
# Copyright (c) 2015, ArrayFire
# All rights reserved.
#
# This file is distributed under 3-clause BSD license.
# The complete license agreement can be obtained at:
# http://arrayfire.com/licenses/BSD-3-Clause
########################################################
import arrayfire as af

a = af.randu(5, 5)

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

af.display(l)
af.display(u)
af.display(p)

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

af.display(a)
af.display(p)

a = af.randu(5, 3)

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

af.display(q)
af.display(r)
af.display(t)