Coverage for src / cvx / risk / linalg / __init__.py: 100%

3 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2025-12-15 12:21 +0000

1"""Linear algebra utilities for risk models. 

2 

3This subpackage provides linear algebra utilities commonly used in risk modeling, 

4including Cholesky decomposition, Principal Component Analysis, and matrix 

5validation. 

6 

7Example: 

8 >>> import numpy as np 

9 >>> from cvx.risk.linalg import cholesky, pca, 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 

15 

16Functions: 

17 cholesky: Compute upper triangular Cholesky decomposition 

18 pca: Compute principal components of return data 

19 valid: Extract valid submatrix from a matrix with NaN values 

20 

21""" 

22 

23# Copyright 2023 Stanford University Convex Optimization Group 

24# 

25# Licensed under the Apache License, Version 2.0 (the "License"); 

26# you may not use this file except in compliance with the License. 

27# You may obtain a copy of the License at 

28# 

29# http://www.apache.org/licenses/LICENSE-2.0 

30# 

31# Unless required by applicable law or agreed to in writing, software 

32# distributed under the License is distributed on an "AS IS" BASIS, 

33# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

34# See the License for the specific language governing permissions and 

35# limitations under the License. 

36from .cholesky import cholesky as cholesky # noqa: F401 

37from .pca import pca as pca # noqa: F401 

38from .valid import valid as valid # noqa: F401