From 71e618290f243766b996ad2070b2fe1127e00524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Holzm=C3=BCller?= Date: Sun, 7 Apr 2019 22:24:05 +0200 Subject: [PATCH] moved vector index counting back because it contained an error and was not faster and more ugly --- src/Interpolation.hpp | 36 ++++++++++++++++++++++++++---------- src/Iterators.hpp | 23 +++-------------------- test/main.cpp | 10 +++++----- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/src/Interpolation.hpp b/src/Interpolation.hpp index 5192084..9fee70d 100644 --- a/src/Interpolation.hpp +++ b/src/Interpolation.hpp @@ -77,11 +77,15 @@ void multiply_lower_triangular_inplace(It it, std::vector= data_size) { + second_v_index = 0; + first_v_index += 1; + data_pointer = &v.data[first_v_index][0]; + data_size = v.data[first_v_index].size(); } + + it.next(); } v.swap(w); @@ -124,11 +132,15 @@ void multiply_upper_triangular_inplace(It it, std::vector= data_size) { + second_v_index = 0; + first_v_index += 1; + data_pointer = &v.data[first_v_index][0]; + data_size = v.data[first_v_index].size(); } + + it.next(); } it = it.cycle(); diff --git a/src/Iterators.hpp b/src/Iterators.hpp index ef18dc2..e018ba6 100644 --- a/src/Iterators.hpp +++ b/src/Iterators.hpp @@ -31,16 +31,11 @@ class TemplateBoundedSumIterator { size_t bound; std::vector index_head; // contains all entries of the index except the last one size_t index_head_sum; - size_t middle_dimensions_counter; bool is_done; public: TemplateBoundedSumIterator(size_t bound) - : bound(bound), - index_head(d - 1, 0), - index_head_sum(0), - middle_dimensions_counter(0), - is_done(false){}; + : bound(bound), index_head(d - 1, 0), index_head_sum(0), is_done(false){}; /** * At the current multi-index (i_1, ..., i_{d-1}, 0), return how many multi-indices starting with @@ -49,9 +44,7 @@ class TemplateBoundedSumIterator { */ size_t lastDimensionCount() { return bound - index_head_sum + 1; } - bool next() { - middle_dimensions_counter += lastDimensionCount(); - + void next() { if (bound > index_head_sum) { index_head_sum += 1; index_head[d - 2] += 1; @@ -62,23 +55,16 @@ class TemplateBoundedSumIterator { // reduce dimension until entry is nonzero } - if (dim > 1) { + if (dim > 0) { index_head_sum -= (index_head[dim] - 1); index_head[dim] = 0; index_head[dim - 1] += 1; - } else if (dim == 1) { - index_head_sum -= (index_head[1] - 1); - index_head[1] = 0; - index_head[0] += 1; - middle_dimensions_counter = 0; - return true; } else if (dim == 0) { index_head[dim] = 0; index_head_sum = 0; is_done = true; } } - return false; } size_t firstIndex() const { return index_head[0]; } @@ -87,12 +73,9 @@ class TemplateBoundedSumIterator { bool done() const { return is_done; } - size_t getMiddleDimensionsCounter() const { return middle_dimensions_counter; } - void reset() { index_head = std::vector(d - 1, 0); index_head_sum = 0; - middle_dimensions_counter = 0; is_done = false; } diff --git a/test/main.cpp b/test/main.cpp index 2c9f2d3..d89db42 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -112,8 +112,8 @@ class Timer { // using namespace fsi; int main() { - constexpr size_t d = 8; - size_t bound = 24; + constexpr size_t d = 2; + size_t bound = 2; fsi::TemplateBoundedSumIterator it(bound); // fsi::BoundedSumIterator it(d, bound); std::vector phi(d); @@ -122,7 +122,7 @@ int main() { auto rhs = evaluateFunction(it, f, x); auto op = createInterpolationOperator(it, phi, x); - // std::cout << rhs << "\n"; + std::cout << rhs << "\n"; Timer timer; op.prepareSolve(); @@ -133,12 +133,12 @@ int main() { auto c = op.solve(rhs); // auto c = fsi::interpolate(f, it, phi, x); std::cout << "Time for solve(): " << timer.elapsed() << " s\n"; - // std::cout << c << "\n"; + std::cout << c << "\n"; timer.reset(); auto b = op.apply(c); std::cout << "Time for apply(): " << timer.elapsed() << " s\n"; - // std::cout << b << "\n"; + std::cout << b << "\n"; std::cout << "Number of points: " << it.numValues() << "\n";