From a4174ec43d24ff1b5cffa39f7d9ec8e9c15b9cbe Mon Sep 17 00:00:00 2001 From: Tobias Ribizel Date: Mon, 9 May 2022 16:59:06 +0200 Subject: [PATCH] reserve storage in matrix_data constructor --- include/ginkgo/core/base/matrix_data.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/ginkgo/core/base/matrix_data.hpp b/include/ginkgo/core/base/matrix_data.hpp index 9948b8dd3ae..f7f88694611 100644 --- a/include/ginkgo/core/base/matrix_data.hpp +++ b/include/ginkgo/core/base/matrix_data.hpp @@ -169,6 +169,7 @@ struct matrix_data { if (is_zero(value)) { return; } + nonzeros.reserve(size[0] * size[1]); for (size_type row = 0; row < size[0]; ++row) { for (size_type col = 0; col < size[1]; ++col) { nonzeros.emplace_back(row, col, value); @@ -190,6 +191,7 @@ struct matrix_data { matrix_data(dim<2> size_, RandomDistribution&& dist, RandomEngine&& engine) : size{size_} { + nonzeros.reserve(size[0] * size[1]); for (size_type row = 0; row < size[0]; ++row) { for (size_type col = 0; col < size[1]; ++col) { const auto value =