Skip to content

Commit 4b8b24d

Browse files
refactor
1 parent 1bfbd42 commit 4b8b24d

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

linear_algebra/determinant.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,16 @@
1414

1515
def determinant_recursive(matrix: NDArray[float64]) -> float:
1616
"""
17-
Calculate the determinant of a square matrix using recursive cofactor expansion.
18-
19-
This method is suitable for small matrices but becomes inefficient for large matrices.
20-
17+
Calculate the determinant of a square matrix
18+
using recursive cofactor expansion.
19+
This method is suitable for
20+
small matrices but becomes inefficient for large matrices.
2121
Parameters:
2222
matrix (NDArray[float64]): A square matrix
23-
2423
Returns:
2524
float: The determinant of the matrix
26-
2725
Raises:
2826
ValueError: If the matrix is not square
29-
3027
Examples:
3128
>>> import numpy as np
3229
>>> matrix = np.array([[1.0, 2.0], [3.0, 4.0]], dtype=float)
@@ -65,15 +62,12 @@ def determinant_recursive(matrix: NDArray[float64]) -> float:
6562
def determinant_lu(matrix: NDArray[float64]) -> float:
6663
"""
6764
Calculate the determinant using LU decomposition.
68-
69-
This method is more efficient for larger matrices than recursive expansion.
70-
65+
This method is more efficient for larger matrices
66+
than recursive expansion.
7167
Parameters:
7268
matrix (NDArray[float64]): A square matrix
73-
7469
Returns:
7570
float: The determinant of the matrix
76-
7771
Raises:
7872
ValueError: If the matrix is not square
7973
"""
@@ -125,16 +119,14 @@ def determinant_lu(matrix: NDArray[float64]) -> float:
125119

126120
def determinant(matrix: NDArray[float64]) -> float:
127121
"""
128-
Calculate the determinant of a square matrix using the most appropriate method.
129-
130-
Uses recursive expansion for small matrices (≤3x3) and LU decomposition for larger ones.
131-
122+
Calculate the determinant of a square matrix using
123+
the most appropriate method.
124+
Uses recursive expansion for small matrices (≤3x3)
125+
and LU decomposition for larger ones.
132126
Parameters:
133127
matrix (NDArray[float64]): A square matrix
134-
135128
Returns:
136129
float: The determinant of the matrix
137-
138130
Examples:
139131
>>> import numpy as np
140132
>>> matrix = np.array([[1.0, 2.0], [3.0, 4.0]], dtype=float)

0 commit comments

Comments
 (0)