resize instead of reserve gained some efficiency
This commit is contained in:
parent
6cab30f64c
commit
52b0077922
|
|
@ -69,9 +69,10 @@ void multiply_lower_triangular_inplace(It it, std::vector<boost::numeric::ublas:
|
||||||
|
|
||||||
for (int k = d - 1; k >= 0; --k) {
|
for (int k = d - 1; k >= 0; --k) {
|
||||||
MultiDimVector w(n[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) {
|
for (size_t idx = 0; idx < n[k]; ++idx) {
|
||||||
// TODO: make compatible with other iterators
|
w.data[idx].resize(sizes[idx]);
|
||||||
w.data[idx].reserve(v.data[idx].size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto &Lk = L[k];
|
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) {
|
for (size_t j = 0; j <= i; ++j) {
|
||||||
sum += Lk(i, j) * (*(offset_data_pointer + 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;
|
second_v_index += last_dim_count;
|
||||||
if (second_v_index >= data_size) {
|
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) {
|
for (int k = d - 1; k >= 0; --k) {
|
||||||
MultiDimVector w(n[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) {
|
for (size_t idx = 0; idx < n[k]; ++idx) {
|
||||||
// TODO: make compatible with other iterators
|
w.data[idx].resize(sizes[idx]);
|
||||||
w.data[idx].reserve(v.data[idx].size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto &Uk = U[k];
|
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) {
|
for (size_t j = i; j < last_dim_count; ++j) {
|
||||||
sum += Uk(i, j) * (*(offset_data_pointer + 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;
|
second_v_index += last_dim_count;
|
||||||
if (second_v_index >= data_size) {
|
if (second_v_index >= data_size) {
|
||||||
|
|
|
||||||
|
|
@ -192,6 +192,8 @@ class BoundedSumIterator {
|
||||||
|
|
||||||
size_t dim() const { return d; }
|
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); }
|
std::vector<size_t> indexBounds() const { return std::vector<size_t>(d, bound + 1); }
|
||||||
|
|
||||||
size_t numValues() const { return binom(bound + d, d); }
|
size_t numValues() const { return binom(bound + d, d); }
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void runFunctions() {
|
void runFunctions() {
|
||||||
constexpr size_t d = 3;
|
constexpr size_t d = 30;
|
||||||
size_t bound = 100;
|
size_t bound = 8;
|
||||||
fsi::TemplateBoundedSumIterator<d> it(bound);
|
fsi::TemplateBoundedSumIterator<d> it(bound);
|
||||||
// fsi::BoundedSumIterator it(d, bound);
|
// fsi::BoundedSumIterator it(d, bound);
|
||||||
std::vector<MonomialFunctions> phi(d);
|
std::vector<MonomialFunctions> phi(d);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue