use crate::*;
#[ inline ]
pub fn add< E, A, B, R >( r : &mut R, a : &A, b : &B )
where
E : MatEl,
E : nd::NdFloat,
R : Indexable< Index = Ix2 > + IndexingMut< Scalar = E >,
A : Indexable< Index = Ix2 > + IndexingRef< Scalar = E >,
B : Indexable< Index = Ix2 > + IndexingRef< Scalar = E >,
{
let rdim = r.dim();
let adim = a.dim();
let bdim = b.dim();
#[ cfg( debug_assertions ) ]
if adim != bdim || rdim != adim
{
panic!
(
"Incompatible dimensions for matrix addition: a: {:?}, b: {:?}, r: {:?}",
adim, bdim, rdim
);
}
for ( ( r_val, a_val ), b_val ) in r.iter_lsfirst_mut().zip( a.iter_lsfirst() ).zip( b.iter_lsfirst() )
{
*r_val = *a_val + *b_val;
}
}
impl< E, const ROWS : usize, const COLS : usize, Descriptor : mat::Descriptor > Add
for Mat< ROWS, COLS, E, Descriptor >
where
E : MatEl,
E : nd::NdFloat,
Descriptor : mat::Descriptor,
Mat< ROWS, COLS, E, Descriptor > : Indexable< Index = Ix2 > + IndexingMut< Scalar = E >,
{
type Output = Self;
#[ inline ]
fn add( self, rhs : Self ) -> Self::Output
{
let mut result = Self::Output::default();
add( &mut result, &self, &rhs );
result
}
}
impl< E, const ROWS : usize, const COLS : usize, Descriptor > Add< &Mat< ROWS, COLS, E, Descriptor > >
for &Mat< ROWS, COLS, E, Descriptor >
where
Descriptor : mat::Descriptor,
E : MatEl,
E : nd::NdFloat,
Mat< ROWS, COLS, E, Descriptor > : Indexable< Index = Ix2 > + IndexingMut< Scalar = E >,
{
type Output = Mat< ROWS, COLS, E, Descriptor >;
fn add( self, rhs : &Mat< ROWS, COLS, E, Descriptor > ) -> Self::Output
{
let mut result = Self::Output::default();
add( &mut result, self, rhs );
result
}
}