Skip to content
Snippets Groups Projects
Commit dc23e160 authored by Max Kahnt's avatar Max Kahnt
Browse files

Add asserts. Use consistent iteration scheme.

parent dad27284
No related branches found
No related tags found
No related merge requests found
...@@ -19,27 +19,29 @@ namespace MatrixVector { ...@@ -19,27 +19,29 @@ namespace MatrixVector {
if (ignore != nullptr and (*ignore)[i].all()) if (ignore != nullptr and (*ignore)[i].all())
continue; continue;
auto cIt = it->begin(); auto cIt = it->begin();
assert(cIt.index() == it.index()); assert(cIt.index() == i);
x[i] = b[i] / *cIt; x[i] = b[i] / *cIt;
cIt++; cIt++;
for (; cIt != it->end(); ++cIt) { for (; cIt != it->end(); ++cIt) {
const size_t j = cIt.index(); const size_t j = cIt.index();
assert(j > i);
b[j] -= x[i] * *cIt; b[j] -= x[i] * *cIt;
} }
} }
} else { } else {
for (auto it = L.begin(); it != L.end(); ++it) { for (auto it = L.begin(); it != L.end(); ++it) {
size_t i = it.index(); const size_t i = it.index();
if (ignore != nullptr and (*ignore)[i].all()) if (ignore != nullptr and (*ignore)[i].all())
continue; continue;
for (auto cIt = it->begin(); cIt != it->end(); ++cIt) { for (auto cIt = it->begin(); cIt != it->end(); ++cIt) {
size_t j = cIt.index(); const size_t j = cIt.index();
if (i == j) { assert(j <= i);
x[i] = b[i] / *cIt; if (j < i) {
break; b[i] -= *cIt * x[j];
continue;
} }
assert(j < i); assert(j == i);
b[i] -= *cIt * x[j]; x[i] = b[i] / *cIt;
} }
} }
} }
...@@ -56,36 +58,32 @@ namespace MatrixVector { ...@@ -56,36 +58,32 @@ namespace MatrixVector {
x = 0; x = 0;
if (transpose) { if (transpose) {
for (auto it = U.beforeEnd(); it != U.beforeBegin(); --it) { for (auto it = U.beforeEnd(); it != U.beforeBegin(); --it) {
size_t i = it.index(); const size_t i = it.index();
auto cIt = it->beforeEnd();
assert(cIt.index() == i);
auto diagonal = *cIt;
if (ignore != nullptr and (*ignore)[i].all()) if (ignore != nullptr and (*ignore)[i].all())
continue; continue;
x[i] = b[i] / diagonal; auto cIt = it->beforeEnd();
assert(cIt.index() == i);
x[i] = b[i] / *cIt;
cIt--; cIt--;
for (; cIt != it->beforeBegin(); --cIt) { for (; cIt != it->beforeBegin(); --cIt) {
size_t j = cIt.index(); const size_t j = cIt.index();
assert(j < i); assert(j < i);
b[j] -= *cIt * x[i]; b[j] -= *cIt * x[i];
} }
} }
} else { } else {
for (auto it = U.beforeEnd(); it != U.beforeBegin(); --it) { for (auto it = U.beforeEnd(); it != U.beforeBegin(); --it) {
size_t i = it.index(); const size_t i = it.index();
if (ignore != nullptr and (*ignore)[i].all()) if (ignore != nullptr and (*ignore)[i].all())
continue; continue;
auto cIt = it->begin(); auto cIt = it->beforeEnd();
assert(cIt.index() == i); for (; cIt != it->begin(); --cIt) {
auto diagonal = *cIt; const size_t j = cIt.index();
cIt++;
for (; cIt != it->end(); ++cIt) {
size_t j = cIt.index();
assert(j > i); assert(j > i);
b[i] -= *cIt * x[j]; b[i] -= *cIt * x[j];
} }
x[i] = b[i] / diagonal; assert(cIt.index() == i);
x[i] = b[i] / *cIt;
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment