# tensorplay.linalg Source: https://www.tensorplay.cn/docs/linalg.html Common linear algebra operations. See [Linear algebra (tensorplay.linalg)](/docs/notes/numerical_accuracy.html#linear-algebra-stability) for some common numerical edge-cases. ## Matrix Properties | tensorplay.linalg.norm | | | --- | --- | | tensorplay.linalg.vector_norm | dim=None norms the whole tensor: the input is flattened first, and keepdim then restores the reduced axes as ones. | | tensorplay.linalg.matrix_norm | | | tensorplay.linalg.diagonal | linalg_diagonal(A, *, offset=0, dim1=-2, dim2=-1) -> Tensor | | tensorplay.linalg.det | | | tensorplay.linalg.slogdet | | | tensorplay.linalg.cond | | | tensorplay.linalg.matrix_rank | Computes the numerical rank of each matrix in A. | ## Decompositions | tensorplay.linalg.cholesky | | | --- | --- | | tensorplay.linalg.qr | | | tensorplay.linalg.polar | | | tensorplay.linalg.lu | linalg_lu(Tensor A, *, bool pivot=True) -> (Tensor P, Tensor L, Tensor U) linalg_lu.out(Tensor A, *, bool pivot=True, Tensor(a!) P, Tensor(b!) L, Tensor(c!) U) -> (Tensor(a!) P, Tensor(b!) L, Tensor(c!) U) | | tensorplay.linalg.lu_factor | linalg_lu_factor(Tensor A, *, bool pivot=True) -> (Tensor LU, Tensor pivots) linalg_lu_factor.out(Tensor A, *, bool pivot=True, Tensor(a!) LU, Tensor(b!) pivots) -> (Tensor(a!) LU, Tensor(b!) pivots) | | tensorplay.linalg.eig | | | tensorplay.linalg.eigvals | | | tensorplay.linalg.eigh | | | tensorplay.linalg.eigvalsh | | | tensorplay.linalg.svd | | | tensorplay.linalg.svdvals | | ## Solvers | tensorplay.linalg.solve | | | --- | --- | | tensorplay.linalg.solve_triangular | linalg_solve_triangular(Tensor A, Tensor B, *, bool upper, bool left=True, bool unitriangular=False) -> Tensor linalg_solve_triangular.out(Tensor self, Tensor B, *, bool upper, bool left=True, bool unitriangular=False, Tensor(a!) out) -> Tensor(a!) | | tensorplay.linalg.lu_solve | linalg_lu_solve(Tensor LU, Tensor pivots, Tensor B, *, bool left=True, bool adjoint=False) -> Tensor linalg_lu_solve.out(Tensor LU, Tensor pivots, Tensor B, *, bool left=True, bool adjoint=False, Tensor(a!) out) -> Tensor(a!) | | tensorplay.linalg.lstsq | | ## Inverses | tensorplay.linalg.inv | | | --- | --- | | tensorplay.linalg.pinv | Moore-Penrose pseudo-inverse. | ## Matrix Functions | tensorplay.linalg.matrix_exp |Square matrix exponential via the degree-13 Pade approximant with scaling and squaring: A is halved until its 1-norm falls under the approximant's accuracy threshold, then the result is squared back. | | --- | --- | | tensorplay.linalg.matrix_sqrth | Matrix square root via the Denman-Beavers fixed-point iteration (converges for matrices with no eigenvalues on the closed negative real axis). | | tensorplay.linalg.matrix_power | | ## Matrix Products | tensorplay.linalg.cross | | | --- | --- | | tensorplay.linalg.matmul | | | tensorplay.linalg.vecdot | Dot product along dim with the first argument conjugated for complex inputs. | | tensorplay.linalg.vdot | Conjugating dot product over 1-D operands: sum(conj(self) * other). | | tensorplay.linalg.multi_dot | Chained matrix product evaluated in the parenthesization that minimizes the scalar multiplication count (matrix-chain dynamic program). | | tensorplay.linalg.householder_product | linalg_householder_product(Tensor input, Tensor tau) -> Tensor linalg_householder_product.out(Tensor input, Tensor tau, *, Tensor(a!) out) -> Tensor(a!) | ## Tensor Operations | tensorplay.linalg.tensorinv |Inverse of A seen as a square matrix over the split at ind: the product of the leading ind dimensions must equal that of the rest. | | --- | --- | | tensorplay.linalg.tensorsolve | Solves the tensor equation A X = B after flattening the contracted dimensions into a square matrix. | ## Misc | tensorplay.linalg.vander | | | --- | --- | ## Experimental Functions | tensorplay.linalg.cholesky_ex | | | --- | --- | | tensorplay.linalg.inv_ex | | | tensorplay.linalg.solve_ex | | | tensorplay.linalg.lu_factor_ex | linalg_lu_factor_ex(Tensor A, *, bool pivot=True, bool check_errors=False) -> (Tensor LU, Tensor pivots, Tensor info) linalg_lu_factor_ex.out(Tensor A, *, bool pivot=True, bool check_errors=False, Tensor(a!) LU, Tensor(b!) pivots, Tensor(c!) info) -> (Tensor(a!) LU, Tensor(b!) pivots, Tensor(c!) info) | | tensorplay.linalg.ldl_factor | linalg_ldl_factor(Tensor A, *, bool hermitian=False) -> (Tensor LD, Tensor pivots) linalg_ldl_factor.out(Tensor self, *, bool hermitian=False, Tensor(a!) LD, Tensor(b!) pivots) -> (Tensor(a!) LD, Tensor(b!) pivots) | | tensorplay.linalg.ldl_factor_ex | linalg_ldl_factor_ex(Tensor A, *, bool hermitian=False, bool check_errors=False) -> (Tensor LD, Tensor pivots, Tensor info) linalg_ldl_factor_ex.out(Tensor self, *, bool hermitian=False, bool check_errors=False, Tensor(a!) LD, Tensor(b!) pivots, Tensor(c!) info) -> (Tensor(a!) LD, Tensor(b!) pivots, Tensor(c!) info) | | tensorplay.linalg.ldl_solve | linalg_ldl_solve(Tensor LD, Tensor pivots, Tensor B, *, bool hermitian=False) -> Tensor linalg_ldl_solve.out(Tensor LD, Tensor pivots, Tensor B, *, bool hermitian=False, Tensor(a!) out) -> Tensor(a!) | ## Result Types Solvers and decompositions that return several tensors package them in the named tuples below; the _ex variants report failures through an info field instead of raising. | tensorplay.linalg.LinAlgError |Raised when a decomposition or solve fails on a numerically invalid input. | | --- | --- | | tensorplay.linalg.EigResult | | | tensorplay.linalg.EighResult | | | tensorplay.linalg.LstsqResult | | | tensorplay.linalg.QRResult | | | tensorplay.linalg.SVDResult | | | tensorplay.linalg.SlogdetResult | | | tensorplay.linalg.CholeskyExResult | |