|
10 | 10 |
|
11 | 11 | Reference: https://en.wikipedia.org/wiki/QR_decomposition |
12 | 12 | """ |
13 | | - |
14 | | -from __future__ import annotations |
15 | 13 | import numpy as np |
| 14 | +from __future__ import annotations |
16 | 15 | from scipy.linalg import qr |
17 | 16 |
|
18 | 17 | def qr_decomposition(matrix_a: np.ndarray) -> tuple[np.ndarray, np.ndarray]: |
19 | 18 | """ |
20 | 19 | Perform QR decomposition on a given matrix and raises an error if in |
21 | | - m×n matrix a if m is smaller than n or m,n is less than 2 |
| 20 | + rowXcolumn matrix a if row is smaller than column or row,column is less than 2 |
22 | 21 |
|
23 | 22 | >>> matrix_a = np.array([[1, 2, 3], [4, 5, 9], [7, 8, 15]]) |
24 | 23 | >>> (matrix_q,matrix_r) = qr_decomposition(matrix_a) |
@@ -71,12 +70,11 @@ def qr_decomposition(matrix_a: np.ndarray) -> tuple[np.ndarray, np.ndarray]: |
71 | 70 | raise ValueError(msg) |
72 | 71 | # Perform QR decomposition with pivoting |
73 | 72 | # matrix_q: Orthogonal matrix |
74 | | - # matrix_v: Upper triangular matrix |
| 73 | + # matrix_r: Upper triangular matrix |
75 | 74 | # pivot: Pivot indices (permutation vector) |
76 | 75 |
|
77 | 76 | matrix_q, matrix_r, pivot = qr(matrix_a, pivoting=True) |
78 | 77 |
|
79 | | - # Note: The bottom row of matrix_r is all zeros because the matrix is rank-deficient. |
80 | 78 | # Verification: matrix_a[:, pivot] should equal matrix_q @ matrix_r |
81 | 79 | permute_matrix = matrix_a[:, pivot] |
82 | 80 | if(np.allclose(permute_matrix, matrix_q @ matrix_r)): |
|
0 commit comments