summaryrefslogtreecommitdiffstats
path: root/eval
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2017-12-18 15:08:00 +0100
committerHenning Baldersheim <balder@yahoo-inc.com>2017-12-18 15:08:00 +0100
commit4c2e8e00ea79f039ced9b41504bb5ad304687706 (patch)
treeaedd163745a50ccbcd78d9f958e9f80c989e0e1c /eval
parent569c613760dc4d72d172dd0af07b1fa9ef6dbfa4 (diff)
Estimate number of cells needed in the hashmap.
Diffstat (limited to 'eval')
-rw-r--r--eval/src/vespa/eval/tensor/sparse/sparse_tensor_apply.hpp4
-rw-r--r--eval/src/vespa/eval/tensor/sparse/sparse_tensor_reduce.hpp1
2 files changed, 3 insertions, 2 deletions
diff --git a/eval/src/vespa/eval/tensor/sparse/sparse_tensor_apply.hpp b/eval/src/vespa/eval/tensor/sparse/sparse_tensor_apply.hpp
index ea3e2dae09b..0b9e127dd82 100644
--- a/eval/src/vespa/eval/tensor/sparse/sparse_tensor_apply.hpp
+++ b/eval/src/vespa/eval/tensor/sparse/sparse_tensor_apply.hpp
@@ -15,10 +15,10 @@ apply(const SparseTensor &lhs, const SparseTensor &rhs, Function &&func)
{
DirectTensorBuilder<SparseTensor> builder(lhs.combineDimensionsWith(rhs));
TensorAddressCombiner addressCombiner(lhs.fast_type(), rhs.fast_type());
+ builder.reserve((lhs.cells().size() * rhs.cells())*2);
for (const auto &lhsCell : lhs.cells()) {
for (const auto &rhsCell : rhs.cells()) {
- bool combineSuccess = addressCombiner.combine(lhsCell.first,
- rhsCell.first);
+ bool combineSuccess = addressCombiner.combine(lhsCell.first, rhsCell.first);
if (combineSuccess) {
builder.insertCell(addressCombiner.getAddressRef(),
func(lhsCell.second, rhsCell.second));
diff --git a/eval/src/vespa/eval/tensor/sparse/sparse_tensor_reduce.hpp b/eval/src/vespa/eval/tensor/sparse/sparse_tensor_reduce.hpp
index 174e4c5237c..8a43c6b52bd 100644
--- a/eval/src/vespa/eval/tensor/sparse/sparse_tensor_reduce.hpp
+++ b/eval/src/vespa/eval/tensor/sparse/sparse_tensor_reduce.hpp
@@ -48,6 +48,7 @@ reduce(const SparseTensor &tensor,
return reduceAll(tensor, builder, func);
}
TensorAddressReducer addressReducer(tensor.fast_type(), dimensions);
+ builder.reserve(tensor.cells().size()*2);
for (const auto &cell : tensor.cells()) {
addressReducer.reduce(cell.first);
builder.insertCell(addressReducer.getAddressRef(), cell.second, func);