Struct simd_aligned::MatrixD
source · pub struct MatrixD<T, A>where
T: Simd + Default + Clone,
A: AccessStrategy,{ /* private fields */ }
Expand description
A dynamic (heap allocated) matrix with one axis aligned for fast and safe SIMD access that also provides a flat view on its data.
You can use MatrixD
when you need to deal with multiple SIMD vectors, but
want them arranged in a compact cache-friendly manner. Internally this struct is backed by a
continuous vector of aligned vectors, and dynamically sliced according to row / column access.
Example
#![feature(portable_simd)]
use std::simd::*;
use simd_aligned::*;
// Create a matrix of height 10x`f32` and width 5x`f32`, optimized for row access.
let mut m = MatrixD::<f32s, Rows>::with_dimension(10, 5);
// A `RowOptimized` matrix provides `row` access. In this example, you could query
// rows `0` to `9` and receive vectors that can hold a total of at least `5` elements.
let _ = m.row(4);
// But accessing columns doesn't work, as there is no continuous view in memory.
// m.column(3); --> panic!
// However, you can always get a flat view of the matrix, for "scalar-speed"
// query and update all elements:
let mut m_flat = m.flat_mut();
m_flat[(2, 4)] = 42_f32;
Implementations§
source§impl<T, O> MatrixD<T, O>where
T: Simd + Default + Clone,
O: AccessStrategy,
impl<T, O> MatrixD<T, O>where T: Simd + Default + Clone, O: AccessStrategy,
sourcepub fn with_dimension(width: usize, height: usize) -> Self
pub fn with_dimension(width: usize, height: usize) -> Self
Creates a new MatrixD
with the given dimension.
sourcepub fn flat(&self) -> MatrixFlat<'_, T, O>
pub fn flat(&self) -> MatrixFlat<'_, T, O>
Provides a flat, immutable view of the contained data.
sourcepub fn flat_mut(&mut self) -> MatrixFlatMut<'_, T, O>
pub fn flat_mut(&mut self) -> MatrixFlatMut<'_, T, O>
Provides a flat mutable view of the contained data.