mojolearn.lu_factor#
- mojolearn.lu_factor(a, *, numeric_mode=None)[source]#
LU factorization of a square matrix with partial pivoting.
Follows
scipy.linalg.lu_factor: returns(lu, piv), whereluholds the unit lower-triangular L (diagonal not stored) and U in one float32 matrix, andpivholds the 0-based row interchanges, applied in order. Pivoting picks the largest absolute value in the column; ties go to the lowest row. A zero pivot is kept and aRuntimeWarningis issued, as scipy does.- Parameters:
a (array-like of shape (n, n)) – The matrix to factor; must be finite.
numeric_mode ({“identical”, “fast”} or None, default None) – Numeric mode for this call. None uses the package default (
"identical"unless changed)."identical"gives the same bits on NVIDIA and AMD GPUs;"fast"applies on Apple GPUs.
- Returns:
lu (ndarray of shape (n, n), float32)
piv (ndarray of shape (n,), int32) – Pass the pair to lu_solve().
- Raises:
ValueError – If
ais not square, is empty, or contains NaN or infinity.
Examples
>>> import numpy as np, mojolearn >>> A = np.random.default_rng(0).random((8, 8), dtype=np.float32) + 8 * np.eye(8, dtype=np.float32) >>> lu, piv = mojolearn.lu_factor(A) >>> x = mojolearn.lu_solve((lu, piv), np.ones(8, dtype=np.float32))