Compare commits

..

No commits in common. "43a39c102540ddaa2b655bcfd75c0a3224d727d8" and "442d8ed531fcfbba68cd823c14e694afe7e63d68" have entirely different histories.

View File

@ -116,6 +116,19 @@ def jacobi_iteration_method(
strictly_diagonally_dominant(table)
"""
denom - a list of values along the diagonal
val - values of the last column of the table array
masks - boolean mask of all strings without diagonal
elements array coefficient_matrix
ttt - coefficient_matrix array values without diagonal elements
ind - column indexes for each row without diagonal elements
arr - list obtained by column indexes from the list init_val
the code below uses vectorized operations based on
the previous algorithm on loopss:
# Iterates the whole matrix for given number of times
for _ in range(iterations):
new_val = []
@ -133,40 +146,18 @@ 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
"""
val_last = table[:, -1]
"""
masks - boolean mask of all strings without diagonal
elements array coefficient_matrix
"""
val = table[:, -1]
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.
"""
ttt = coefficient_matrix[masks].reshape(-1, rows - 1)
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).
"""
# 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
temp = np.sum((-1) * ttt * arr, axis=1)
new_val = (temp + val) / denom
init_val = new_val
return new_val.tolist()