Coverage for cvxrisk/linalg/cholesky.py: 100%

5 statements  

« prev     ^ index     » next       coverage.py v7.8.2, created at 2025-06-18 11:11 +0000

1"""Cholesky decomposition utilities for covariance matrices.""" 

2 

3# Copyright 2023 Stanford University Convex Optimization Group 

4# 

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

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

7# You may obtain a copy of the License at 

8# 

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

10# 

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

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

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

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

15# limitations under the License. 

16from __future__ import annotations 

17 

18import numpy as np 

19from scipy.linalg import cholesky as _cholesky 

20 

21 

22def cholesky(cov: np.ndarray) -> np.ndarray: 

23 """Compute the upper triangular part of the Cholesky decomposition. 

24 

25 This function computes the Cholesky decomposition of a positive definite matrix. 

26 It returns the upper triangular matrix R such that R^T R = cov. 

27 

28 Args: 

29 cov: A positive definite covariance matrix 

30 

31 Returns: 

32 The upper triangular Cholesky factor 

33 

34 Note: 

35 This uses scipy.linalg.cholesky which returns the upper triangular part, 

36 unlike numpy.linalg.cholesky which returns the lower triangular part. 

37 

38 """ 

39 return _cholesky(cov)