Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 94b3777

Browse files
MaximSmolskiypre-commit-ci[bot]
andauthored
Fix sphinx/build_docs warnings for linear_algebra (TheAlgorithms#12483)
* Fix sphinx/build_docs warnings for linear_algebra/ * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 3622e94 commit 94b3777

File tree

6 files changed

+54
-34
lines changed

6 files changed

+54
-34
lines changed

‎linear_algebra/gaussian_elimination.py‎

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
2-
Gaussian elimination method for solving a system of linear equations.
3-
Gaussian elimination - https://en.wikipedia.org/wiki/Gaussian_elimination
2+
| Gaussian elimination method for solving a system of linear equations.
3+
| Gaussian elimination - https://en.wikipedia.org/wiki/Gaussian_elimination
44
"""
55

66
import numpy as np
@@ -13,12 +13,17 @@ def retroactive_resolution(
1313
) -> NDArray[float64]:
1414
"""
1515
This function performs a retroactive linear system resolution
16-
for triangular matrix
16+
for triangular matrix
1717
1818
Examples:
19-
2x1 + 2x2 - 1x3 = 5 2x1 + 2x2 = -1
20-
0x1 - 2x2 - 1x3 = -7 0x1 - 2x2 = -1
21-
0x1 + 0x2 + 5x3 = 15
19+
1.
20+
* 2x1 + 2x2 - 1x3 = 5
21+
* 0x1 - 2x2 - 1x3 = -7
22+
* 0x1 + 0x2 + 5x3 = 15
23+
2.
24+
* 2x1 + 2x2 = -1
25+
* 0x1 - 2x2 = -1
26+
2227
>>> gaussian_elimination([[2, 2, -1], [0, -2, -1], [0, 0, 5]], [[5], [-7], [15]])
2328
array([[2.],
2429
[2.],
@@ -45,9 +50,14 @@ def gaussian_elimination(
4550
This function performs Gaussian elimination method
4651
4752
Examples:
48-
1x1 - 4x2 - 2x3 = -2 1x1 + 2x2 = 5
49-
5x1 + 2x2 - 2x3 = -3 5x1 + 2x2 = 5
50-
1x1 - 1x2 + 0x3 = 4
53+
1.
54+
* 1x1 - 4x2 - 2x3 = -2
55+
* 5x1 + 2x2 - 2x3 = -3
56+
* 1x1 - 1x2 + 0x3 = 4
57+
2.
58+
* 1x1 + 2x2 = 5
59+
* 5x1 + 2x2 = 5
60+
5161
>>> gaussian_elimination([[1, -4, -2], [5, 2, -2], [1, -1, 0]], [[-2], [-3], [4]])
5262
array([[ 2.3 ],
5363
[-1.7 ],

‎linear_algebra/lu_decomposition.py‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
Lower-upper (LU) decomposition factors a matrix as a product of a lower
33
triangular matrix and an upper triangular matrix. A square matrix has an LU
44
decomposition under the following conditions:
5+
56
- If the matrix is invertible, then it has an LU decomposition if and only
6-
if all of its leading principal minors are non-zero (see
7-
https://en.wikipedia.org/wiki/Minor_(linear_algebra) for an explanation of
8-
leading principal minors of a matrix).
7+
if all of its leading principal minors are non-zero (see
8+
https://en.wikipedia.org/wiki/Minor_(linear_algebra) for an explanation of
9+
leading principal minors of a matrix).
910
- If the matrix is singular (i.e., not invertible) and it has a rank of k
10-
(i.e., it has k linearly independent columns), then it has an LU
11-
decomposition if its first k leading principal minors are non-zero.
11+
(i.e., it has k linearly independent columns), then it has an LU
12+
decomposition if its first k leading principal minors are non-zero.
1213
1314
This algorithm will simply attempt to perform LU decomposition on any square
1415
matrix and raise an error if no such decomposition exists.
@@ -25,6 +26,7 @@ def lower_upper_decomposition(table: np.ndarray) -> tuple[np.ndarray, np.ndarray
2526
"""
2627
Perform LU decomposition on a given matrix and raises an error if the matrix
2728
isn't square or if no such decomposition exists
29+
2830
>>> matrix = np.array([[2, -2, 1], [0, 1, 2], [5, 3, 1]])
2931
>>> lower_mat, upper_mat = lower_upper_decomposition(matrix)
3032
>>> lower_mat
@@ -45,7 +47,7 @@ def lower_upper_decomposition(table: np.ndarray) -> tuple[np.ndarray, np.ndarray
4547
array([[ 4. , 3. ],
4648
[ 0. , -1.5]])
4749
48-
# Matrix is not square
50+
>>> # Matrix is not square
4951
>>> matrix = np.array([[2, -2, 1], [0, 1, 2]])
5052
>>> lower_mat, upper_mat = lower_upper_decomposition(matrix)
5153
Traceback (most recent call last):
@@ -54,14 +56,14 @@ def lower_upper_decomposition(table: np.ndarray) -> tuple[np.ndarray, np.ndarray
5456
[[ 2 -2 1]
5557
[ 0 1 2]]
5658
57-
# Matrix is invertible, but its first leading principal minor is 0
59+
>>> # Matrix is invertible, but its first leading principal minor is 0
5860
>>> matrix = np.array([[0, 1], [1, 0]])
5961
>>> lower_mat, upper_mat = lower_upper_decomposition(matrix)
6062
Traceback (most recent call last):
6163
...
6264
ArithmeticError: No LU decomposition exists
6365
64-
# Matrix is singular, but its first leading principal minor is 1
66+
>>> # Matrix is singular, but its first leading principal minor is 1
6567
>>> matrix = np.array([[1, 0], [1, 0]])
6668
>>> lower_mat, upper_mat = lower_upper_decomposition(matrix)
6769
>>> lower_mat
@@ -71,7 +73,7 @@ def lower_upper_decomposition(table: np.ndarray) -> tuple[np.ndarray, np.ndarray
7173
array([[1., 0.],
7274
[0., 0.]])
7375
74-
# Matrix is singular, but its first leading principal minor is 0
76+
>>> # Matrix is singular, but its first leading principal minor is 0
7577
>>> matrix = np.array([[0, 1], [0, 1]])
7678
>>> lower_mat, upper_mat = lower_upper_decomposition(matrix)
7779
Traceback (most recent call last):

‎linear_algebra/src/gaussian_elimination_pivoting.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@ def solve_linear_system(matrix: np.ndarray) -> np.ndarray:
66
Solve a linear system of equations using Gaussian elimination with partial pivoting
77
88
Args:
9-
- matrix: Coefficient matrix with the last column representing the constants.
9+
- `matrix`: Coefficient matrix with the last column representing the constants.
1010
1111
Returns:
12-
- Solution vector.
12+
- Solution vector.
1313
1414
Raises:
15-
- ValueError: If the matrix is not correct (i.e., singular).
15+
- ``ValueError``: If the matrix is not correct (i.e., singular).
1616
1717
https://courses.engr.illinois.edu/cs357/su2013/lect.htm Lecture 7
1818
1919
Example:
20+
2021
>>> A = np.array([[2, 1, -1], [-3, -1, 2], [-2, 1, 2]], dtype=float)
2122
>>> B = np.array([8, -11, -3], dtype=float)
2223
>>> solution = solve_linear_system(np.column_stack((A, B)))

‎linear_algebra/src/rank_of_matrix.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
def rank_of_matrix(matrix: list[list[int | float]]) -> int:
99
"""
1010
Finds the rank of a matrix.
11+
1112
Args:
12-
matrix: The matrix as a list of lists.
13+
`matrix`: The matrix as a list of lists.
14+
1315
Returns:
1416
The rank of the matrix.
17+
1518
Example:
19+
1620
>>> matrix1 = [[1, 2, 3],
1721
... [4, 5, 6],
1822
... [7, 8, 9]]

‎linear_algebra/src/schur_complement.py‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ def schur_complement(
1212
) -> np.ndarray:
1313
"""
1414
Schur complement of a symmetric matrix X given as a 2x2 block matrix
15-
consisting of matrices A, B and C.
16-
Matrix A must be quadratic and non-singular.
17-
In case A is singular, a pseudo-inverse may be provided using
18-
the pseudo_inv argument.
15+
consisting of matrices `A`, `B` and `C`.
16+
Matrix `A` must be quadratic and non-singular.
17+
In case `A` is singular, a pseudo-inverse may be provided using
18+
the `pseudo_inv` argument.
19+
20+
| Link to Wiki: https://en.wikipedia.org/wiki/Schur_complement
21+
| See also Convex Optimization - Boyd and Vandenberghe, A.5.5
1922
20-
Link to Wiki: https://en.wikipedia.org/wiki/Schur_complement
21-
See also Convex Optimization - Boyd and Vandenberghe, A.5.5
2223
>>> import numpy as np
2324
>>> a = np.array([[1, 2], [2, 1]])
2425
>>> b = np.array([[0, 3], [3, 0]])

‎linear_algebra/src/transformations_2d.py‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
44
I have added the codes for reflection, projection, scaling and rotation 2D matrices.
55
6+
.. code-block:: python
7+
68
scaling(5) = [[5.0, 0.0], [0.0, 5.0]]
7-
rotation(45) = [[0.5253219888177297, -0.8509035245341184],
8-
[0.8509035245341184, 0.5253219888177297]]
9-
projection(45) = [[0.27596319193541496, 0.446998331800279],
10-
[0.446998331800279, 0.7240368080645851]]
11-
reflection(45) = [[0.05064397763545947, 0.893996663600558],
12-
[0.893996663600558, 0.7018070490682369]]
9+
rotation(45) = [[0.5253219888177297, -0.8509035245341184],
10+
[0.8509035245341184, 0.5253219888177297]]
11+
projection(45) = [[0.27596319193541496, 0.446998331800279],
12+
[0.446998331800279, 0.7240368080645851]]
13+
reflection(45) = [[0.05064397763545947, 0.893996663600558],
14+
[0.893996663600558, 0.7018070490682369]]
1315
"""
1416

1517
from math import cos, sin

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /