Skip to content
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

jacobi_iteration_method.py the use of vector operations, which reduces the calculation time by dozens of times #8938

Merged
merged 15 commits into from
Sep 11, 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
Prev Previous commit
Next Next commit
Update jacobi_iteration_method.py
Edits upon request.
  • Loading branch information
quant12345 authored Sep 11, 2023
commit 5c1a12bf01e6ab11595aac10fc517b98cc0297ab
45 changes: 19 additions & 26 deletions arithmetic_analysis/jacobi_iteration_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,40 +133,33 @@ def jacobi_iteration_method(
init_val = new_val
"""

"""
denom - a list of values along the diagonal
"""
denom = np.diag(coefficient_matrix)
"""
val_last - values of the last column of the table array
"""
# denominator - a list of values along the diagonal
denominator = np.diag(coefficient_matrix)

#val_last - values of the last column of the table array
val_last = table[:, -1]
"""
masks - boolean mask of all strings without diagonal
elements array coefficient_matrix
"""

#masks - boolean mask of all strings without diagonal
#elements array coefficient_matrix
masks = ~np.eye(coefficient_matrix.shape[0], dtype=bool)
"""
no_diag - coefficient_matrix array values without diagonal elements
"""
no_diag = coefficient_matrix[masks].reshape(-1, rows - 1)
"""
Here we get 'i_col' - these are the column numbers, for each row
without diagonal elements, except for the last column.
"""

#no_diagonals - coefficient_matrix array values without diagonal elements
no_diagonals = coefficient_matrix[masks].reshape(-1, rows - 1)

#Here we get 'i_col' - these are the column numbers, for each row
#without diagonal elements, except for the last column.
i_row, i_col = np.where(masks)
ind = i_col.reshape(-1, rows - 1)
"""
'i_col' is converted to a two-dimensional list 'ind',
which will be used to make selections from 'init_val'
('arr' array see below).
"""

#'i_col' is converted to a two-dimensional list 'ind', which will be
#used to make selections from 'init_val' ('arr' array see below).


# Iterates the whole matrix for given number of times
for _ in range(iterations):
arr = np.take(init_val, ind)
temp = np.sum((-1) * no_diag * arr, axis=1)
new_val = (temp + val_last) / denom
sum_product_rows = np.sum((-1) * no_diagonals * arr, axis=1)
new_val = (sum_product_rows + val_last) / denominator
init_val = new_val

return new_val.tolist()
Expand Down