Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
proc
/
self
/
root
/
opt
/
alt
/
python35
/
lib64
/
python3.5
/
site-packages
/
scipy
/
linalg
/
File Content:
decomp_lu.py
"""LU decomposition functions.""" from __future__ import division, print_function, absolute_import from warnings import warn from numpy import asarray, asarray_chkfinite # Local imports from .misc import _datacopied from .lapack import get_lapack_funcs from .flinalg import get_flinalg_funcs __all__ = ['lu', 'lu_solve', 'lu_factor'] def lu_factor(a, overwrite_a=False, check_finite=True): """ Compute pivoted LU decomposition of a matrix. The decomposition is:: A = P L U where P is a permutation matrix, L lower triangular with unit diagonal elements, and U upper triangular. Parameters ---------- a : (M, M) array_like Matrix to decompose overwrite_a : bool, optional Whether to overwrite data in A (may increase performance) check_finite : bool, optional Whether to check that the input matrix contains only finite numbers. Disabling may give a performance gain, but may result in problems (crashes, non-termination) if the inputs do contain infinities or NaNs. Returns ------- lu : (N, N) ndarray Matrix containing U in its upper triangle, and L in its lower triangle. The unit diagonal elements of L are not stored. piv : (N,) ndarray Pivot indices representing the permutation matrix P: row i of matrix was interchanged with row piv[i]. See also -------- lu_solve : solve an equation system using the LU factorization of a matrix Notes ----- This is a wrapper to the ``*GETRF`` routines from LAPACK. """ if check_finite: a1 = asarray_chkfinite(a) else: a1 = asarray(a) if len(a1.shape) != 2 or (a1.shape[0] != a1.shape[1]): raise ValueError('expected square matrix') overwrite_a = overwrite_a or (_datacopied(a1, a)) getrf, = get_lapack_funcs(('getrf',), (a1,)) lu, piv, info = getrf(a1, overwrite_a=overwrite_a) if info < 0: raise ValueError('illegal value in %d-th argument of ' 'internal getrf (lu_factor)' % -info) if info > 0: warn("Diagonal number %d is exactly zero. Singular matrix." % info, RuntimeWarning) return lu, piv def lu_solve(lu_and_piv, b, trans=0, overwrite_b=False, check_finite=True): """Solve an equation system, a x = b, given the LU factorization of a Parameters ---------- (lu, piv) Factorization of the coefficient matrix a, as given by lu_factor b : array Right-hand side trans : {0, 1, 2}, optional Type of system to solve: ===== ========= trans system ===== ========= 0 a x = b 1 a^T x = b 2 a^H x = b ===== ========= overwrite_b : bool, optional Whether to overwrite data in b (may increase performance) check_finite : bool, optional Whether to check that the input matrices contain only finite numbers. Disabling may give a performance gain, but may result in problems (crashes, non-termination) if the inputs do contain infinities or NaNs. Returns ------- x : array Solution to the system See also -------- lu_factor : LU factorize a matrix """ (lu, piv) = lu_and_piv if check_finite: b1 = asarray_chkfinite(b) else: b1 = asarray(b) overwrite_b = overwrite_b or _datacopied(b1, b) if lu.shape[0] != b1.shape[0]: raise ValueError("incompatible dimensions.") getrs, = get_lapack_funcs(('getrs',), (lu, b1)) x,info = getrs(lu, piv, b1, trans=trans, overwrite_b=overwrite_b) if info == 0: return x raise ValueError('illegal value in %d-th argument of internal gesv|posv' % -info) def lu(a, permute_l=False, overwrite_a=False, check_finite=True): """ Compute pivoted LU decomposition of a matrix. The decomposition is:: A = P L U where P is a permutation matrix, L lower triangular with unit diagonal elements, and U upper triangular. Parameters ---------- a : (M, N) array_like Array to decompose permute_l : bool, optional Perform the multiplication P*L (Default: do not permute) overwrite_a : bool, optional Whether to overwrite data in a (may improve performance) check_finite : bool, optional Whether to check that the input matrix contains only finite numbers. Disabling may give a performance gain, but may result in problems (crashes, non-termination) if the inputs do contain infinities or NaNs. Returns ------- **(If permute_l == False)** p : (M, M) ndarray Permutation matrix l : (M, K) ndarray Lower triangular or trapezoidal matrix with unit diagonal. K = min(M, N) u : (K, N) ndarray Upper triangular or trapezoidal matrix **(If permute_l == True)** pl : (M, K) ndarray Permuted L matrix. K = min(M, N) u : (K, N) ndarray Upper triangular or trapezoidal matrix Notes ----- This is a LU factorization routine written for Scipy. """ if check_finite: a1 = asarray_chkfinite(a) else: a1 = asarray(a) if len(a1.shape) != 2: raise ValueError('expected matrix') overwrite_a = overwrite_a or (_datacopied(a1, a)) flu, = get_flinalg_funcs(('lu',), (a1,)) p, l, u, info = flu(a1, permute_l=permute_l, overwrite_a=overwrite_a) if info < 0: raise ValueError('illegal value in %d-th argument of ' 'internal lu.getrf' % -info) if permute_l: return l, u return p, l, u
Submit
FILE
FOLDER
Name
Size
Permission
Action
__pycache__
---
0755
tests
---
0755
__init__.py
6351 bytes
0644
_calc_lwork.cpython-35m-x86_64-linux-gnu.so
56296 bytes
0755
_cblas.cpython-35m-x86_64-linux-gnu.so
41224 bytes
0755
_clapack.cpython-35m-x86_64-linux-gnu.so
68984 bytes
0755
_cython_signature_generator.py
8369 bytes
0644
_cython_wrapper_generators.py
23463 bytes
0644
_decomp_polar.py
3623 bytes
0644
_decomp_qz.py
12986 bytes
0644
_decomp_update.cpython-35m-x86_64-linux-gnu.so
307856 bytes
0755
_expm_frechet.py
12182 bytes
0644
_fblas.cpython-35m-x86_64-linux-gnu.so
388576 bytes
0755
_flapack.cpython-35m-x86_64-linux-gnu.so
934896 bytes
0755
_flinalg.cpython-35m-x86_64-linux-gnu.so
70744 bytes
0755
_interpolative.cpython-35m-x86_64-linux-gnu.so
584544 bytes
0755
_interpolative_backend.py
44935 bytes
0644
_matfuncs_inv_ssq.py
28050 bytes
0644
_matfuncs_sqrtm.py
5867 bytes
0644
_procrustes.py
2375 bytes
0644
_solve_toeplitz.cpython-35m-x86_64-linux-gnu.so
183728 bytes
0755
_solvers.py
10185 bytes
0644
_testutils.py
1814 bytes
0644
basic.py
39332 bytes
0644
blas.py
6855 bytes
0644
calc_lwork.py
666 bytes
0644
cython_blas.cpython-35m-x86_64-linux-gnu.so
204424 bytes
0755
cython_blas.pxd
14416 bytes
0644
cython_lapack.cpython-35m-x86_64-linux-gnu.so
574600 bytes
0755
cython_lapack.pxd
169411 bytes
0644
decomp.py
31223 bytes
0644
decomp_cholesky.py
9601 bytes
0644
decomp_lu.py
5796 bytes
0644
decomp_qr.py
12675 bytes
0644
decomp_schur.py
8375 bytes
0644
decomp_svd.py
7226 bytes
0644
flinalg.py
1727 bytes
0644
interpolative.py
31146 bytes
0644
lapack.py
8103 bytes
0644
linalg_version.py
159 bytes
0644
matfuncs.py
19939 bytes
0644
misc.py
5881 bytes
0644
setup.py
5888 bytes
0644
special_matrices.py
29225 bytes
0644
N4ST4R_ID | Naxtarrr