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

Add `DenseMatrix::ravel` function to get the full buffer of a matrix

parent 7e62d302
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,8 @@ use std::ops::Index;
use std::ops::IndexMut;
use std::ops::Range;
use crate::abc::Alphabet;
use crate::abc::Symbol;
use crate::num::ArrayLength;
// --- MatrixElement -----------------------------------------------------------
......@@ -131,18 +133,35 @@ impl<T: MatrixElement, C: ArrayLength> DenseMatrix<T, C> {
Iter::new(self)
}
/// Returns an it,erator that allows modifying each row.
/// Returns an iterator that allows modifying each row.
#[inline]
pub fn iter_mut(&mut self) -> IterMut<'_, T, C> {
IterMut::new(self)
}
/// Return the matrix content as a flat slice, including padding.
#[inline]
pub fn ravel(&self) -> &[T] {
unsafe {
std::slice::from_raw_parts(self.data.as_ptr() as *mut T, self.rows() * self.stride())
}
}
/// Return the matrix content as a flat mutable slice, including padding.
#[inline]
pub fn ravel_mut(&mut self) -> &mut [T] {
unsafe {
std::slice::from_raw_parts_mut(
self.data.as_mut_ptr() as *mut T,
self.rows() * self.stride(),
)
}
}
/// Fill the entire matrix with a constant value.
#[inline]
pub fn fill(&mut self, value: T) {
for row in self.data.iter_mut() {
row.a.fill(value)
}
self.ravel_mut().fill(value);
}
}
......
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