Skip to content

Commit ad217c6

Browse files
committed
Replacing the generator with numpy vector operations from lu_decomposition.
1 parent 211247e commit ad217c6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

arithmetic_analysis/lu_decomposition.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,19 @@ def lower_upper_decomposition(table: np.ndarray) -> tuple[np.ndarray, np.ndarray
8888

8989
lower = np.zeros((rows, columns))
9090
upper = np.zeros((rows, columns))
91+
92+
# in 'total', the necessary data is extracted through slices
93+
# and the sum of the products is obtained.
94+
9195
for i in range(columns):
9296
for j in range(i):
93-
total = sum(lower[i][k] * upper[k][j] for k in range(j))
97+
total = np.sum(lower[i, :i] * upper[:i, j])
9498
if upper[j][j] == 0:
9599
raise ArithmeticError("No LU decomposition exists")
96100
lower[i][j] = (table[i][j] - total) / upper[j][j]
97101
lower[i][i] = 1
98102
for j in range(i, columns):
99-
total = sum(lower[i][k] * upper[k][j] for k in range(j))
103+
total = np.sum(lower[i, :i] * upper[:i, j])
100104
upper[i][j] = table[i][j] - total
101105
return lower, upper
102106

0 commit comments

Comments
 (0)