From 41cdd03b1b1abdc3cb1340afb193708ebc104577 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 5 Sep 2024 16:32:19 -0700 Subject: [PATCH] wip fixed wide --- fixed_wide_vectors/Cargo.lock | 1 + fixed_wide_vectors/Cargo.toml | 3 +- fixed_wide_vectors/src/macros/fixed_wide.rs | 37 ++++++++++++++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/fixed_wide_vectors/Cargo.lock b/fixed_wide_vectors/Cargo.lock index 5bb2156..7c320dd 100644 --- a/fixed_wide_vectors/Cargo.lock +++ b/fixed_wide_vectors/Cargo.lock @@ -28,6 +28,7 @@ name = "fixed_wide_vectors" version = "0.1.0" dependencies = [ "fixed_wide", + "paste", ] [[package]] diff --git a/fixed_wide_vectors/Cargo.toml b/fixed_wide_vectors/Cargo.toml index 556dee1..ce607be 100644 --- a/fixed_wide_vectors/Cargo.toml +++ b/fixed_wide_vectors/Cargo.toml @@ -6,7 +6,8 @@ edition = "2021" [features] default=["fixed_wide","named-fields"] named-fields=[] -fixed_wide=["dep:fixed_wide"] +fixed_wide=["dep:fixed_wide","dep:paste"] [dependencies] fixed_wide = { version = "0.1.0", path = "../fixed_wide", optional = true } +paste = { version = "1.0.15", optional = true } diff --git a/fixed_wide_vectors/src/macros/fixed_wide.rs b/fixed_wide_vectors/src/macros/fixed_wide.rs index 8b13789..dabb773 100644 --- a/fixed_wide_vectors/src/macros/fixed_wide.rs +++ b/fixed_wide_vectors/src/macros/fixed_wide.rs @@ -1 +1,36 @@ - +#[doc(hidden)] +#[macro_export(local_inner_macros)] +macro_rules! impl_wide_vector_operations_2arg_not_const_generic { + ( + ($lhs:expr, $rhs:expr) + ) => { + impl Vector>{ + paste::item!{ + #[inline] + pub fn [](self,rhs:Vector>)->Vector>{ + self.array.map_zip(|(a,b)|a.[](b)) + } + #[inline] + pub fn [](self,rhs:Vector>)->fixed_wide::fixed::Fixed<{$lhs+$rhs},{($lhs+$rhs)*32}>{ + self.array.into_iter().zip(rhs.array).map(|(a,b)|a.[](b)).sum() + } + } + } + } +} +#[doc(hidden)] +#[macro_export(local_inner_macros)] +macro_rules! impl_wide_vector_operations_1arg_not_const_generic { + ( + $n:expr + ) => { + impl $struct>{ + paste::item!{ + #[inline] + pub fn wide_length_squared(&self)->fixed_wide::fixed::Fixed<{$n*2},{$n*2*32}>{ + self.array.into_iter().map(|t|t.[](t)).sum() + } + } + } + }; +}