Compare commits

...

4 Commits

Author SHA1 Message Date
936fdf51d4 add test 2024-09-03 10:58:34 -07:00
e9a9689e86 WE ARE 10 LAYERS DEEP 2024-09-03 10:43:25 -07:00
c24ce58dbf matrix wide dot 2024-09-03 10:41:46 -07:00
014b8333ff wip 2024-09-03 10:41:46 -07:00
3 changed files with 129 additions and 6 deletions

View File

@ -84,6 +84,109 @@ macro_rules! impl_wide_vector_operations {
}
// Notes:
// Mat3<Vec2>.dot(Vec2) -> Vec3
// Mat3<Vec4>.dot(Mat4<Vec2>) -> Mat3<Vec2>
// 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<fixed_wide::fixed::Fixed<{$lhs},{$lhs*32}>>>{
paste::item!{
#[inline]
pub fn [<wide_dot_ $size_outer x $size_inner _ $size_inner x $rhs_size_inner _ $lhs _ $rhs>](self,rhs:$matrix_inner<$rhs_struct_inner<fixed_wide::fixed::Fixed<{$rhs},{$rhs*32}>>>)->$struct_outer<$rhs_struct_inner<fixed_wide::fixed::Fixed<{$lhs+$rhs},{($lhs+$rhs)*32}>>>{
//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_ $lhs _ $rhs>](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<U:std::ops::Add<Output=U>,T:Copy+fixed_wide_traits::wide::WideMul<Output=U>> $struct<T> {
#[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<U:std::ops::Add<Output=U>,T:Copy+fixed_wide_traits::wide::WideMul<Output=U>> $struct<T> {
#[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)]

View File

@ -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)]

View File

@ -1,4 +1,4 @@
use crate::{Vector2,Vector3,Matrix3};
use crate::{Vector2,Vector3,Vector4,Matrix3,Matrix4};
type Planar64=fixed_wide::types::I32F32;
type Planar64Wide1=fixed_wide::types::I64F64;
@ -37,9 +37,27 @@ fn wide_vec3_length_squared(){
#[test]
fn wide_matrix_dot(){
let m=Matrix3::<Vector3<_>>::from_value_2d(Planar64::from(3));
//normal matrix product
todo!()
//let m_dot=m.wide_dot_1_1(m);
//assert_eq!(m_dot,Matrix3::<Vector3<_>>::from_value_2d(Planar64Wide1::from(3i128.pow(2))));
let lhs=Matrix3::from([
Vector4::from([Planar64::from(1),Planar64::from(2),Planar64::from(3),Planar64::from(4)]),
Vector4::from([Planar64::from(5),Planar64::from(6),Planar64::from(7),Planar64::from(8)]),
Vector4::from([Planar64::from(9),Planar64::from(10),Planar64::from(11),Planar64::from(12)]),
]);
let rhs=Matrix4::from([
Vector2::from([Planar64::from(1),Planar64::from(2)]),
Vector2::from([Planar64::from(3),Planar64::from(4)]),
Vector2::from([Planar64::from(5),Planar64::from(6)]),
Vector2::from([Planar64::from(7),Planar64::from(8)]),
]);
// Mat3<Vec4>.dot(Mat4<Vec2>) -> Mat3<Vec2>
let m_dot=lhs.wide_dot_3x4_4x2_1_1(rhs);
//In[1]:= {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}} . {{1, 2}, {3, 4}, {5, 6}, {7, 8}}
//Out[1]= {{50, 60}, {114, 140}, {178, 220}}
assert_eq!(
m_dot,
Matrix3::from([
Vector2::from([Planar64Wide1::from(50),Planar64Wide1::from(60)]),
Vector2::from([Planar64Wide1::from(114),Planar64Wide1::from(140)]),
Vector2::from([Planar64Wide1::from(178),Planar64Wide1::from(220)]),
])
);
}