Skip to content
Snippets Groups Projects
Commit 8aab22de authored by Martin Larralde's avatar Martin Larralde
Browse files

Manually implement `Clone` for `DenseMatrix` to enforce memory alignment

parent 9b24165a
No related branches found
No related tags found
No related merge requests found
......@@ -42,7 +42,7 @@ impl MatrixCoordinates {
// --- DenseMatrix -------------------------------------------------------------
/// A memory-aligned dense matrix with a constant number of columns.
#[derive(Clone, Eq)]
#[derive(Eq)]
pub struct DenseMatrix<T: Default + Copy, C: Unsigned, A: Unsigned + PowerOfTwo = DefaultAlignment>
{
data: Vec<T>,
......@@ -202,6 +202,18 @@ impl<T: Default + Copy, C: Unsigned, A: Unsigned + PowerOfTwo> DenseMatrix<T, C,
}
}
impl<T: Default + Copy + Debug, C: Unsigned, A: Unsigned + PowerOfTwo> Clone
for DenseMatrix<T, C, A>
{
fn clone(&self) -> Self {
let mut clone = unsafe { Self::uninitialized(self.rows) };
let l = self.rows() * self.stride();
clone.data[clone.offset..clone.offset + l]
.copy_from_slice(&self.data[self.offset..self.offset + l]);
clone
}
}
impl<T: Default + Copy + Debug, C: Unsigned, A: Unsigned + PowerOfTwo> Debug
for DenseMatrix<T, C, A>
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment