From 0f9d0c8c394761a3697628f3fd483406426e284e Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 2 Sep 2024 19:05:52 -0700 Subject: [PATCH] matrix wide dot --- fixed_wide_vectors/src/macros/fixed_wide.rs | 103 ++++++++++++++++++++ fixed_wide_vectors/src/macros/matrix.rs | 2 + 2 files changed, 105 insertions(+) diff --git a/fixed_wide_vectors/src/macros/fixed_wide.rs b/fixed_wide_vectors/src/macros/fixed_wide.rs index f0f5ca7..6d882f9 100644 --- a/fixed_wide_vectors/src/macros/fixed_wide.rs +++ b/fixed_wide_vectors/src/macros/fixed_wide.rs @@ -84,6 +84,109 @@ macro_rules! impl_wide_vector_operations { } +// Notes: +// Mat3.dot(Vec2) -> Vec3 +// 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_matrix_wide_mul { + ( + //TODO: Fixed point impls + ($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), + ($lhs: expr, $rhs: expr) + ) => { + impl $struct_outer<$struct_inner>>{ + paste::item!{ + #[inline] + pub fn [](self,rhs:$matrix_inner<$rhs_struct_inner>>)->$struct_outer<$rhs_struct_inner>>{ + //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.[](trax) + ).to_vector() + ) + } + } + } + } +} + +#[doc(hidden)] +#[macro_export(local_inner_macros)] +macro_rules! impl_matrix_wide_mul_shim3 { + ( + ($outer_info:tt,$inner_info:tt,$rhs_info:tt), + ($lhs: expr, $rhs: expr) + ) => { + $crate::impl_matrix_wide_mul!($outer_info,$inner_info,$rhs_info,($lhs,$rhs)); + } +} +#[doc(hidden)] +#[macro_export(local_inner_macros)] +macro_rules! impl_matrix_wide_mul_shim2 { + ( + ($outer_info:tt,$inner_info:tt), + $rhs_info:tt + ) => { + $crate::do_macro_8x8!(impl_matrix_wide_mul_shim3,($outer_info,$inner_info,$rhs_info)); + } +} +#[doc(hidden)] +#[macro_export(local_inner_macros)] +macro_rules! impl_matrix_wide_mul_shim1 { + ( + ($outer_info:tt,($($rhs_info:tt),+)), + $inner_info:tt + ) => { + $crate::macro_repeated!(impl_matrix_wide_mul_shim2,($outer_info,$inner_info),$($rhs_info),+); + } +} +#[doc(hidden)] +#[macro_export(local_inner_macros)] +macro_rules! impl_wide_matrix_operations_2arg_not_const_generic { + ( + $lhs: expr, $rhs: expr, + ($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) + ) => { + /* TODO: nasty determinant macro + impl,T:Copy+fixed_wide_traits::wide::WideMul> $struct { + #[inline] + pub fn wide_dot(&self) -> U { + $crate::sum_repeating!( + $( + self.$field.wide_mul(self.$field) ) + + ) + } + } + */ + }; +} +#[doc(hidden)] +#[macro_export(local_inner_macros)] +macro_rules! impl_wide_matrix_operations_1arg_not_const_generic { + ( + $n: expr, + ($struct_outer: ident { $($field_outer: ident), + }, $vector_outer: ident { $($vector_field_outer: ident), + }, $size_outer: expr), + ) => { + /* TODO: nasty determinant macro + impl,T:Copy+fixed_wide_traits::wide::WideMul> $struct { + #[inline] + pub fn wide_det(&self) -> U { + $crate::sum_repeating!( + $( + self.$field.wide_mul(self.$field) ) + + ) + } + } + */ + }; +} + // HACK: Allows us to sum repeating tokens in macros. // See: https://stackoverflow.com/a/60187870/17452730 #[doc(hidden)] diff --git a/fixed_wide_vectors/src/macros/matrix.rs b/fixed_wide_vectors/src/macros/matrix.rs index d442488..98d72aa 100644 --- a/fixed_wide_vectors/src/macros/matrix.rs +++ b/fixed_wide_vectors/src/macros/matrix.rs @@ -47,6 +47,8 @@ macro_rules! impl_matrix_inner_shim { $matrix_info:tt ) => { $crate::macro_repeated!(impl_matrix_inner,$matrix_info,$($vector_info),+); + #[cfg(feature="fixed_wide")] + $crate::macro_repeated!(impl_matrix_wide_mul_shim1,($matrix_info,($($vector_info),+)),$($vector_info),+); } } #[doc(hidden)]