epic const generic array transpose

verified that this loop unrolls on compiler explorer
This commit is contained in:
Quaternions 2024-09-05 17:15:41 -07:00
parent e95f675e91
commit 1a6ece1312

View File

@ -20,6 +20,18 @@ macro_rules! impl_matrix {
array:self.array.map(|inner|inner.map(&f)),
}
}
#[inline]
pub fn transpose(self)->Matrix<Y,X,T>{
//how did I think of this
let mut array_of_iterators=self.array.map(|axis|axis.into_iter());
Matrix{
array:core::array::from_fn(|_|
array_of_iterators.each_mut().map(|iter|
iter.next().unwrap()
)
)
}
}
}
impl<const X:usize,const Y:usize,T> Matrix<X,Y,T>
where