From c51dc6098c2e3789c4b97b4737b8b79f9178602c Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 4 Sep 2024 12:03:12 -0700 Subject: [PATCH] matrix: directly implement dot product to avoid a copy --- fixed_wide_vectors/src/macros/fixed_wide.rs | 35 ++++++++++----------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/fixed_wide_vectors/src/macros/fixed_wide.rs b/fixed_wide_vectors/src/macros/fixed_wide.rs index 96e43c1..da74531 100644 --- a/fixed_wide_vectors/src/macros/fixed_wide.rs +++ b/fixed_wide_vectors/src/macros/fixed_wide.rs @@ -87,16 +87,14 @@ macro_rules! impl_wide_vector_operations { #[macro_export(local_inner_macros)] macro_rules! impl_matrix_wide_mul_transpose_helper { ( - $value:ident, + $lhs_axis:expr, $wide_mul:ident, $rhs:ident, ($struct: ident { $($field: ident), + }), ($from_struct: ident { $($from_field: ident), + }), $static_field: ident ) => { - $struct { - $( - $field: $value.$from_field.$static_field - ), + - } + $crate::sum_repeating!( + $( + $lhs_axis.$field.$wide_mul($rhs.$from_field.$static_field) ) + + ) } } #[doc(hidden)] @@ -104,7 +102,7 @@ macro_rules! impl_matrix_wide_mul_transpose_helper { macro_rules! impl_matrix_wide_mul_inner { ( // MatY.MatX = MatY - $lhs:ident, $lhs_field_outer:ident, $wide_dot:ident, $rhs:ident, + $lhs:ident, $lhs_field_outer:ident, $wide_mul:ident, $rhs:ident, $struct_inner_thru: tt, //VecX ($struct_inner: ident { $($field_inner: ident), + }), //VecX ($rhs_struct_inner: ident { $($rhs_field_inner: ident), + }), //VecZ @@ -112,15 +110,14 @@ macro_rules! impl_matrix_wide_mul_inner { ) => { $rhs_struct_inner { $( - $rhs_field_inner: $lhs.$lhs_field_outer.$wide_dot( - //construct a transposed vector with the same width as $struct_outer - $crate::impl_matrix_wide_mul_transpose_helper!{ - $rhs, - $struct_inner_thru, //VecZ - $rhs_outer, //MatX - $rhs_field_inner - } - ) + //directly dot product to avoid a copy + $rhs_field_inner: $crate::impl_matrix_wide_mul_transpose_helper!{ + //lhs_axis + $lhs.$lhs_field_outer,$wide_mul,$rhs, + $struct_inner_thru, //VecZ + $rhs_outer, //MatX + $rhs_field_inner + } ), + } } @@ -130,7 +127,7 @@ macro_rules! impl_matrix_wide_mul_inner { macro_rules! impl_matrix_wide_mul_outer { ( // MatY.MatX = MatY - $lhs:ident, $wide_dot:ident, $rhs:ident, + $lhs:ident, $wide_mul:ident, $rhs:ident, //result matrix shape ($struct_outer: ident { $($field_outer: ident), + }),//MatY $rhs_struct_inner: tt,//VecZ @@ -142,7 +139,7 @@ macro_rules! impl_matrix_wide_mul_outer { $struct_outer { $( $field_outer: $crate::impl_matrix_wide_mul_inner!{ - $lhs, $field_outer, $wide_dot, $rhs, + $lhs, $field_outer, $wide_mul, $rhs, $struct_inner, //VecX $struct_inner, //VecX $rhs_struct_inner, //VecZ @@ -182,7 +179,7 @@ macro_rules! impl_matrix_wide_mul { pub fn [](self,rhs:$matrix_inner<$rhs_struct_inner>>)->$struct_outer<$rhs_struct_inner>>{ $crate::impl_matrix_wide_mul_outer!( //constituent idents - self,[],rhs, + self,[],rhs, //result matrix shape ($struct_outer { $($field_outer), + }), ($rhs_struct_inner { $($rhs_field_inner), + }),