From fd588d1b60215152e2a2f73ae653b61e742b7e5c Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 2 Sep 2024 14:05:17 -0700 Subject: [PATCH] no transpose trait --- fixed_wide_vectors/src/lib.rs | 7 ----- fixed_wide_vectors/src/macros/matrix.rs | 11 ++----- fixed_wide_vectors/src/macros/wide.rs | 42 ++++++++++++++++--------- 3 files changed, 29 insertions(+), 31 deletions(-) diff --git a/fixed_wide_vectors/src/lib.rs b/fixed_wide_vectors/src/lib.rs index 69891e3..a9c0b41 100644 --- a/fixed_wide_vectors/src/lib.rs +++ b/fixed_wide_vectors/src/lib.rs @@ -10,12 +10,5 @@ pub use matrix::Matrix2; pub use matrix::Matrix3; pub use matrix::Matrix4; -//internal trait for matrix wide_dot -trait Transpose{ - type Inner; - type Output; - fn transpose(self)->Self::Output; -} - #[cfg(test)] mod tests; diff --git a/fixed_wide_vectors/src/macros/matrix.rs b/fixed_wide_vectors/src/macros/matrix.rs index ec7bbc0..7e8b7a0 100644 --- a/fixed_wide_vectors/src/macros/matrix.rs +++ b/fixed_wide_vectors/src/macros/matrix.rs @@ -54,13 +54,6 @@ macro_rules! impl_matrix_inner { } } } - impl $crate::Transpose for $struct_outer<$struct_inner>{ - type Inner=$vector_outer; - type Output=$matrix_inner<$vector_outer>; - fn transpose(self)->Self::Output{ - self.transpose() - } - } impl $struct_outer<$struct_inner> { #[inline(always)] @@ -75,8 +68,8 @@ macro_rules! impl_matrix_inner { // Impl floating-point based methods #[cfg(feature="fixed_wide_traits")] $crate::impl_wide_matrix_operations!( - ($struct_outer { $($field_outer), + }, $vector_outer, $size_outer), - ($struct_inner { $($field_inner), + }, $matrix_inner, $size_inner) + ($struct_outer { $($field_outer), + }, $vector_outer { $($vector_field_outer), + }, $size_outer), + ($struct_inner { $($field_inner), + }, $matrix_inner { $($matrix_field_inner), + }, $size_inner) ); }; } diff --git a/fixed_wide_vectors/src/macros/wide.rs b/fixed_wide_vectors/src/macros/wide.rs index 7c82cd2..4dc6f25 100644 --- a/fixed_wide_vectors/src/macros/wide.rs +++ b/fixed_wide_vectors/src/macros/wide.rs @@ -38,6 +38,33 @@ macro_rules! impl_wide_vector_operations { // Mat3.dot(Mat4) -> Mat3 // mat.mat can be implemented off the back of mat.vec +#[doc(hidden)] +#[macro_export(local_inner_macros)] +macro_rules! impl_wide_matrix_mul { + ( + ($struct_outer: ident { $($field_outer: ident), + }, $vector_outer: ident { $($vector_field_outer: ident), + }, $size_outer: expr), + ($struct_inner: ident { $($field_inner: ident), + }, $matrix_inner: ident { $($matrix_field_inner: ident), + }, $size_inner: expr), + ($rhs_struct_inner: ident { $($rhs_field_inner: ident), + }, $rhs_matrix_inner: ident { $($rhs_matrix_field_inner: ident), + }, $rhs_size_inner: expr) + ) => { + impl fixed_wide_traits::wide::WideDot<$matrix_inner<$rhs_struct_inner>> for $struct_outer<$struct_inner> + where + $struct_inner:fixed_wide_traits::wide::WideDot<$rhs_struct_inner>, + { + type Output=$struct_outer<<$struct_inner as fixed_wide_traits::wide::WideDot<$rhs_struct_inner>::Output>; + #[inline] + fn wide_dot(self,rhs:$matrix_inner<$rhs_struct_inner>)->Self::Output{ + //just made this up, don't trust it + let tr=rhs.transpose(); + //TODO: use a macro expansion instead of transpose and map + self.map(|axis| + tr.map(|trax| + axis.wide_dot(trax) + ).to_vector() + ) + } + } + } +} #[doc(hidden)] #[macro_export(local_inner_macros)] macro_rules! impl_wide_matrix_operations { @@ -45,21 +72,6 @@ macro_rules! impl_wide_matrix_operations { ($struct_outer: ident { $($field_outer: ident), + }, $vector_outer: ident { $($vector_field_outer: ident), + }, $size_outer: expr), ($struct_inner: ident { $($field_inner: ident), + }, $matrix_inner: ident { $($matrix_field_inner: ident), + }, $size_inner: expr) ) => { - // U is a vec type - impl fixed_wide_traits::wide::WideDot<$matrix_inner> for $struct_outer<$struct_inner> - where - $matrix_inner:$crate::Transpose, - $struct_inner:fixed_wide_traits::wide::WideDot, - $struct_outer<$struct_inner>:fixed_wide_traits::wide::WideDot<<$matrix_inner as $crate::Transpose>::Inner>, - { - type Output=$struct_outer<<$struct_inner as fixed_wide_traits::wide::WideDot>::Output>; - #[inline] - fn wide_dot(self, rhs: $matrix_inner) -> Self::Output { - //just made this up, don't trust it - let tr=rhs.transpose(); - self.map(|axis|tr.wide_dot(axis)) - } - } /* TODO: nasty determinant macro impl,T:Copy+fixed_wide_traits::wide::WideMul> $struct { #[inline]