From 1984d9717158c89f9acca2b635a373bad7048633 Mon Sep 17 00:00:00 2001 From: Dom <97384583+tosemml@users.noreply.github.com> Date: Sun, 20 Aug 2023 16:43:09 -0700 Subject: [PATCH] Refactorings (#8987) * use np.dot * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * further improvements using array slicing Co-authored-by: Tianyi Zheng --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Tianyi Zheng --- arithmetic_analysis/gaussian_elimination.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/arithmetic_analysis/gaussian_elimination.py b/arithmetic_analysis/gaussian_elimination.py index f0f20af8e..13f509a4f 100644 --- a/arithmetic_analysis/gaussian_elimination.py +++ b/arithmetic_analysis/gaussian_elimination.py @@ -33,10 +33,7 @@ def retroactive_resolution( x: NDArray[float64] = np.zeros((rows, 1), dtype=float) for row in reversed(range(rows)): - total = 0 - for col in range(row + 1, columns): - total += coefficients[row, col] * x[col] - + total = np.dot(coefficients[row, row + 1 :], x[row + 1 :]) x[row, 0] = (vector[row] - total) / coefficients[row, row] return x