Skip to content

Refactoring and optimization of the lu_decomposition algorithm #9231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 16, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Replacing the generator with numpy vector operations from lu_decompos…
…ition.
  • Loading branch information
quant12345 committed Sep 29, 2023
commit ad217c66165898d62b76cc89ba09c2d7049b6448
8 changes: 6 additions & 2 deletions arithmetic_analysis/lu_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,19 @@ def lower_upper_decomposition(table: np.ndarray) -> tuple[np.ndarray, np.ndarray

lower = np.zeros((rows, columns))
upper = np.zeros((rows, columns))

# in 'total', the necessary data is extracted through slices
# and the sum of the products is obtained.

for i in range(columns):
for j in range(i):
total = sum(lower[i][k] * upper[k][j] for k in range(j))
total = np.sum(lower[i, :i] * upper[:i, j])
if upper[j][j] == 0:
raise ArithmeticError("No LU decomposition exists")
lower[i][j] = (table[i][j] - total) / upper[j][j]
lower[i][i] = 1
for j in range(i, columns):
total = sum(lower[i][k] * upper[k][j] for k in range(j))
total = np.sum(lower[i, :i] * upper[:i, j])
upper[i][j] = table[i][j] - total
return lower, upper

Expand Down