From 4a7f86d5b079c44c470e14e7e0fa31f13e7f9528 Mon Sep 17 00:00:00 2001 From: Matthew Scroggs Date: Tue, 23 Jan 2024 11:59:57 +0000 Subject: [PATCH] reserve space for vec (#166) --- bem/src/assembly/batched.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bem/src/assembly/batched.rs b/bem/src/assembly/batched.rs index 26304eb2..9d23af06 100644 --- a/bem/src/assembly/batched.rs +++ b/bem/src/assembly/batched.rs @@ -99,6 +99,14 @@ impl SparseMatrixData { shape, } } + fn new_known_size(shape: [usize; 2], size: usize) -> Self { + Self { + data: Vec::with_capacity(size), + rows: Vec::with_capacity(size), + cols: Vec::with_capacity(size), + shape, + } + } fn add(&mut self, other: SparseMatrixData) { debug_assert!(self.shape[0] == other.shape[0]); debug_assert!(self.shape[1] == other.shape[1]); @@ -136,7 +144,10 @@ fn assemble_batch_singular<'a>( trial_table: &Array, 4>, 4>, test_table: &Array, 4>, 4>, ) -> SparseMatrixData { - let mut output = SparseMatrixData::::new(shape); + let mut output = SparseMatrixData::::new_known_size( + shape, + cell_pairs.len() * trial_space.element().dim() * test_space.element().dim(), + ); let npts = weights.len(); debug_assert!(weights.len() == npts); debug_assert!(test_points.shape()[0] == npts);