Coverage for src / cvx / linalg / __init__.py: 100%
25 statements
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-19 05:40 +0000
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-19 05:40 +0000
1"""Linear algebra utilities for risk models.
3This subpackage provides linear algebra utilities commonly used in risk modeling,
4including Cholesky decomposition, Principal Component Analysis, matrix norms,
5linear-system solving, and matrix validation.
7Example:
8 >>> import numpy as np
9 >>> from cvx.linalg import a_norm, cholesky, eigh, inv_a_norm, pca, qr, rand_cov, solve, svd, valid
10 >>> # Cholesky decomposition
11 >>> cov = np.array([[4.0, 2.0], [2.0, 5.0]])
12 >>> R = cholesky(cov)
13 >>> np.allclose(R.T @ R, cov)
14 True
16Functions:
17 a_norm: Compute the matrix norm of a vector
18 cholesky: Compute upper triangular Cholesky decomposition
19 cond: Return the condition number of a matrix (NaN-aware)
20 det: Compute the determinant of a square matrix
21 eigvals: Compute eigenvalues of a general square matrix
22 eigh: Compute eigenvalues and eigenvectors of a symmetric/Hermitian matrix
23 eigvalsh: Compute eigenvalues of a symmetric/Hermitian matrix
24 inv: Invert a matrix with NaN-aware matrix filtering and condition-number guarding
25 inv_a_norm: Compute the inverse matrix norm of a vector
26 lstsq: Solve least-squares problems with NaN-aware row filtering
27 norm: Compute the norm of a vector or matrix, ignoring non-finite entries
28 pca: Compute principal components of return data
29 qr: Compute reduced QR decomposition of a matrix
30 rand_cov: Generate a random positive semi-definite covariance matrix
31 solve: Solve linear systems with NaN-aware matrix filtering
32 svd: Compute compact singular value decomposition
33 valid: Extract valid submatrix from a matrix with NaN values
35"""
37from .cholesky import cholesky as cholesky
38from .cholesky import is_positive_definite as is_positive_definite
39from .det import det as det
40from .eigh import eigh as eigh
41from .eigh import eigvalsh as eigvalsh
42from .eigvals import eigvals as eigvals
43from .exceptions import DimensionMismatchError as DimensionMismatchError
44from .exceptions import IllConditionedMatrixWarning as IllConditionedMatrixWarning
45from .exceptions import NonSquareMatrixError as NonSquareMatrixError
46from .exceptions import NotAMatrixError as NotAMatrixError
47from .exceptions import SingularMatrixError as SingularMatrixError
48from .exceptions import check_and_warn_condition as check_and_warn_condition
49from .exceptions import cond as cond
50from .inv import inv as inv
51from .lstsq import lstsq as lstsq
52from .norm import a_norm as a_norm
53from .norm import inv_a_norm as inv_a_norm
54from .norm import norm as norm
55from .pca import pca as pca
56from .qr import qr as qr
57from .rand_cov import rand_cov as rand_cov
58from .solve import solve as solve
59from .svd import svd as svd
60from .types import Matrix as Matrix
61from .valid import valid as valid