Skip to content

Commit

Permalink
reserve space for vec (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
mscroggs authored Jan 23, 2024
1 parent 12dca4c commit 4a7f86d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion bem/src/assembly/batched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ impl<T: Scalar> SparseMatrixData<T> {
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<T>) {
debug_assert!(self.shape[0] == other.shape[0]);
debug_assert!(self.shape[1] == other.shape[1]);
Expand Down Expand Up @@ -136,7 +144,10 @@ fn assemble_batch_singular<'a>(
trial_table: &Array<f64, BaseArray<f64, VectorContainer<f64>, 4>, 4>,
test_table: &Array<f64, BaseArray<f64, VectorContainer<f64>, 4>, 4>,
) -> SparseMatrixData<f64> {
let mut output = SparseMatrixData::<f64>::new(shape);
let mut output = SparseMatrixData::<f64>::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);
Expand Down

0 comments on commit 4a7f86d

Please sign in to comment.