resize instead of reserve gained some efficiency

This commit is contained in:
David Holzmüller 2019-04-11 17:38:33 +02:00
parent 6cab30f64c
commit 52b0077922
3 changed files with 14 additions and 8 deletions

View File

@ -69,9 +69,10 @@ void multiply_lower_triangular_inplace(It it, std::vector<boost::numeric::ublas:
for (int k = d - 1; k >= 0; --k) {
MultiDimVector w(n[k]);
std::vector<size_t> indexes(n[k], 0);
auto sizes = it.numValuesPerFirstIndex();
for (size_t idx = 0; idx < n[k]; ++idx) {
// TODO: make compatible with other iterators
w.data[idx].reserve(v.data[idx].size());
w.data[idx].resize(sizes[idx]);
}
auto &Lk = L[k];
@ -91,7 +92,8 @@ void multiply_lower_triangular_inplace(It it, std::vector<boost::numeric::ublas:
for (size_t j = 0; j <= i; ++j) {
sum += Lk(i, j) * (*(offset_data_pointer + j));
}
w.data[i].push_back(sum);
w.data[i][indexes[i]] = sum;
++indexes[i];
}
second_v_index += last_dim_count;
if (second_v_index >= data_size) {
@ -124,9 +126,10 @@ void multiply_upper_triangular_inplace(It it, std::vector<boost::numeric::ublas:
for (int k = d - 1; k >= 0; --k) {
MultiDimVector w(n[k]);
std::vector<size_t> indexes(n[k], 0);
auto sizes = it.numValuesPerFirstIndex();
for (size_t idx = 0; idx < n[k]; ++idx) {
// TODO: make compatible with other iterators
w.data[idx].reserve(v.data[idx].size());
w.data[idx].resize(sizes[idx]);
}
auto &Uk = U[k];
@ -146,7 +149,8 @@ void multiply_upper_triangular_inplace(It it, std::vector<boost::numeric::ublas:
for (size_t j = i; j < last_dim_count; ++j) {
sum += Uk(i, j) * (*(offset_data_pointer + j));
}
w.data[i].push_back(sum);
w.data[i][indexes[i]] = sum;
++indexes[i];
}
second_v_index += last_dim_count;
if (second_v_index >= data_size) {

View File

@ -192,6 +192,8 @@ class BoundedSumIterator {
size_t dim() const { return d; }
size_t firstIndexBound() const { return bound + 1; }
std::vector<size_t> indexBounds() const { return std::vector<size_t>(d, bound + 1); }
size_t numValues() const { return binom(bound + d, d); }

View File

@ -26,8 +26,8 @@ limitations under the License.
*/
void runFunctions() {
constexpr size_t d = 3;
size_t bound = 100;
constexpr size_t d = 30;
size_t bound = 8;
fsi::TemplateBoundedSumIterator<d> it(bound);
// fsi::BoundedSumIterator it(d, bound);
std::vector<MonomialFunctions> phi(d);