aboutsummaryrefslogtreecommitdiff
path: root/src/lu.cpp
diff options
context:
space:
mode:
authory-jan137 <yousefjan24000@gmail.com>2026-03-16 11:52:36 +0300
committery-jan137 <yousefjan24000@gmail.com>2026-03-16 11:52:36 +0300
commitb27583941c200f98ab328901e81c9188945bf708 (patch)
treec9b0c2bddb8d89e4398e6dbf2d787bea10cffaac /src/lu.cpp
parent606ad99e8363bd520506ea2e88b831911fe03c18 (diff)
Cleanup
Diffstat (limited to 'src/lu.cpp')
-rw-r--r--src/lu.cpp8
1 files changed, 0 insertions, 8 deletions
diff --git a/src/lu.cpp b/src/lu.cpp
index 9b2c950..f6840ea 100644
--- a/src/lu.cpp
+++ b/src/lu.cpp
@@ -19,10 +19,8 @@ LUResult lu_factor(const Matrix& A, double singular_tolerance) {
const std::size_t n = A.rows();
- // Working copy: elimination is performed in-place here.
Matrix work = A;
- // L starts as identity; multipliers fill the strict lower triangle.
Matrix L = Matrix::zeros(n, n);
for (std::size_t i = 0; i < n; ++i) {
L(i, i) = 1.0;
@@ -30,7 +28,6 @@ LUResult lu_factor(const Matrix& A, double singular_tolerance) {
Matrix U = Matrix::zeros(n, n);
- // perm[i] = original row index now at position i.
std::vector<std::size_t> perm(n);
std::iota(perm.begin(), perm.end(), std::size_t{0});
int sign = 1;
@@ -48,11 +45,9 @@ LUResult lu_factor(const Matrix& A, double singular_tolerance) {
}
if (pivot_row != k) {
- // Swap rows in the working matrix.
for (std::size_t j = 0; j < n; ++j) {
std::swap(work(k, j), work(pivot_row, j));
}
- // Swap already-computed multipliers in L (columns 0 .. k-1).
for (std::size_t j = 0; j < k; ++j) {
std::swap(L(k, j), L(pivot_row, j));
}
@@ -95,17 +90,14 @@ Vector lu_solve(const LUResult& lu, const Vector& b) {
throw DimensionMismatchError(oss.str());
}
- // Step 1: apply permutation P. (Pb)[i] = b[perm[i]]
Vector pb(n);
for (std::size_t i = 0; i < n; ++i) {
pb[i] = b[lu.perm[i]];
}
- // Step 2: forward substitution Ly = Pb (L has unit diagonal)
const Vector y = forward_substitution(lu.L, pb, /*singular_tolerance=*/1e-14,
/*unit_diagonal=*/true);
- // Step 3: backward substitution Ux = y
return backward_substitution(lu.U, y);
}