From 1a6ece13121d5420cb037f978e3b98c13047df6c Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 5 Sep 2024 17:15:41 -0700 Subject: [PATCH] epic const generic array transpose verified that this loop unrolls on compiler explorer --- fixed_wide_vectors/src/macros/matrix.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fixed_wide_vectors/src/macros/matrix.rs b/fixed_wide_vectors/src/macros/matrix.rs index 1964dff..bba1e65 100644 --- a/fixed_wide_vectors/src/macros/matrix.rs +++ b/fixed_wide_vectors/src/macros/matrix.rs @@ -20,6 +20,18 @@ macro_rules! impl_matrix { array:self.array.map(|inner|inner.map(&f)), } } + #[inline] + pub fn transpose(self)->Matrix{ + //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 Matrix where