use crate::*;
impl< E, const ROWS : usize, const COLS : usize, Descriptor : mat::Descriptor > RawSlice
for Mat< ROWS, COLS, E, Descriptor >
where
E : MatEl,
{
#[ inline( always ) ]
fn raw_slice( &self ) -> &[ Self::Scalar ]
{
#[ allow( unsafe_code ) ]
unsafe { std::slice::from_raw_parts( self.as_ptr() as *const Self::Scalar, ROWS * COLS ) }
}
}
impl< E, const ROWS : usize, const COLS : usize, Descriptor : mat::Descriptor > ScalarRef
for Mat< ROWS, COLS, E, Descriptor >
where
E : MatEl,
E : nd::NdFloat,
Self : ConstLayout,
{
#[ inline( always ) ]
fn scalar_ref( &self, index : < Self as Indexable >::Index ) -> &Self::Scalar
{
&self.raw_slice()[ Self::scalar_offset( index ) ]
}
}
impl< E, const ROWS : usize, const COLS : usize, Descriptor : mat::Descriptor > ScalarMut
for Mat< ROWS, COLS, E, Descriptor >
where
E : MatEl,
E : nd::NdFloat,
Self : ConstLayout + RawSliceMut,
{
#[ inline( always ) ]
fn scalar_mut( &mut self, index : < Self as Indexable >::Index ) -> &mut Self::Scalar
{
&mut self.raw_slice_mut()[ Self::scalar_offset( index ) ]
}
}
impl< E, const ROWS : usize, const COLS : usize, Descriptor : mat::Descriptor > Mat< ROWS, COLS, E, Descriptor >
where
E : MatEl,
Self : RawSliceMut< Scalar = E >,
{
pub fn from_row_major< const N : usize >( scalars: impl ArrayRef< E, N > ) -> Self {
debug_assert_eq!( N, ROWS*COLS, "Matrix size should be equal to the size of the input" );
let result = Self::default();
result.with_row_major( scalars.array_ref() )
}
pub fn from_column_major< const N : usize >( scalars: impl ArrayRef< E, N > ) -> Self {
debug_assert_eq!( N, ROWS*COLS, "Matrix size should be equal to the size of the input" );
let result = Self::default();
result.with_column_major( scalars.array_ref() )
}
}