diff --git a/particular/CHANGELOG.md b/particular/CHANGELOG.md index 5e3d638..25aa6e2 100644 --- a/particular/CHANGELOG.md +++ b/particular/CHANGELOG.md @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `GpuData` struct used for `gpu::BruteForce`. - `ParticleSystem`, `ParticleTree`, `ParticleOrdered` and `ParticleReordered` structs used for storages in built-in compute methods. -- `Array`, `Zero`, `One`, `Infinty`, `FloatOps`, `Float`, `IntoArray`, `FloatVectorOps`, `FloatVector`, `SIMD`, `SIMDElement`, `ReduceAdd`, `InfToZero`, `FromPrimitive` and `AsPrimitive` traits for math operation abstractions. +- `Array`, `Zero`, `One`, `Infinty`, `FloatOps`, `Float`, `IntoArray`, `FloatVectorOps`, `FloatVector`, `SIMD`, `SIMDElement`, `Reduce`, `InfToZero`, `FromPrimitive` and `AsPrimitive` traits for math operation abstractions. - `force_mul_mass_scalar`, `force_mul_mass_simd` `acceleration_tree`, `force_scalar` and `force_simd` methods for `PointMass` and various `new` methods. - `ScalarArray` trait to bind a `FloatVector` and an array for `Particle` to `PointMass` conversion. - Marker `ReorderedCompute` trait. diff --git a/particular/src/compute_method/math.rs b/particular/src/compute_method/math.rs index 455f23c..037ac34 100644 --- a/particular/src/compute_method/math.rs +++ b/particular/src/compute_method/math.rs @@ -162,10 +162,10 @@ pub trait SIMDElement: Sized { type SIMD: SIMD; } -/// Trait to sum the lanes of a SIMD vector. -pub trait ReduceAdd: SIMD { +/// Trait to reduce the lanes of a SIMD vector. +pub trait Reduce: SIMD { /// Sums the lanes of a SIMD vector. - fn reduce_add(self) -> Self::Element; + fn reduce_sum(self) -> Self::Element; } /// Trait to replace infinites values with zeros in `SIMD` types. @@ -400,29 +400,31 @@ impl_simd_vector!(DVec3x4, [DVec3; 4]); impl_simd_vector!(DVec4x2, [DVec4; 2]); impl_simd_vector!(DVec4x4, [DVec4; 4]); -macro_rules! impl_reduce_add { +macro_rules! impl_reduce { ($vector: ty, [$($f: ident),+]) => { - impl ReduceAdd for $vector { + impl Reduce for $vector { #[inline] - fn reduce_add(self) -> Self::Element { - From::from([$(self.$f.reduce_add()),+]) + fn reduce_sum(self) -> Self::Element { + Self::Element { + $($f: self.$f.reduce_add()),+ + } } } }; } -impl_reduce_add!(Vec2x4, [x, y]); -impl_reduce_add!(Vec2x8, [x, y]); -impl_reduce_add!(Vec3x4, [x, y, z]); -impl_reduce_add!(Vec3x8, [x, y, z]); -impl_reduce_add!(Vec4x4, [x, y, z, w]); -impl_reduce_add!(Vec4x8, [x, y, z, w]); -impl_reduce_add!(DVec2x2, [x, y]); -impl_reduce_add!(DVec2x4, [x, y]); -impl_reduce_add!(DVec3x2, [x, y, z]); -impl_reduce_add!(DVec3x4, [x, y, z]); -impl_reduce_add!(DVec4x2, [x, y, z, w]); -impl_reduce_add!(DVec4x4, [x, y, z, w]); +impl_reduce!(Vec2x4, [x, y]); +impl_reduce!(Vec2x8, [x, y]); +impl_reduce!(Vec3x4, [x, y, z]); +impl_reduce!(Vec3x8, [x, y, z]); +impl_reduce!(Vec4x4, [x, y, z, w]); +impl_reduce!(Vec4x8, [x, y, z, w]); +impl_reduce!(DVec2x2, [x, y]); +impl_reduce!(DVec2x4, [x, y]); +impl_reduce!(DVec3x2, [x, y, z]); +impl_reduce!(DVec3x4, [x, y, z]); +impl_reduce!(DVec4x2, [x, y, z, w]); +impl_reduce!(DVec4x4, [x, y, z, w]); macro_rules! impl_inf_to_zero { ($float: ty) => { diff --git a/particular/src/compute_method/parallel.rs b/particular/src/compute_method/parallel.rs index 636625a..f8295ab 100644 --- a/particular/src/compute_method/parallel.rs +++ b/particular/src/compute_method/parallel.rs @@ -1,5 +1,5 @@ use crate::compute_method::{ - math::{Float, FloatVector, InfToZero, ReduceAdd, SIMDElement, Zero}, + math::{Float, FloatVector, InfToZero, Reduce, SIMDElement, Zero}, storage::{ParticleSliceSystem, ParticleTreeSystem, PointMass}, ComputeMethod, }; @@ -40,7 +40,7 @@ impl ComputeMethod> for Brut where V: SIMDElement + Copy + Zero + Send + Sync, S: SIMDElement + Copy + Zero + Sync, - V::SIMD: FloatVector + ReduceAdd + Copy + Send + Sync, + V::SIMD: FloatVector + Reduce + Copy + Send + Sync, S::SIMD: Float + InfToZero + Copy + Sync, { type Output = Vec; @@ -57,7 +57,7 @@ where acceleration + p1.acceleration_simd::(p2) }) }) - .map(ReduceAdd::reduce_add) + .map(Reduce::reduce_sum) .collect() } } diff --git a/particular/src/compute_method/sequential.rs b/particular/src/compute_method/sequential.rs index 4603d04..d576113 100644 --- a/particular/src/compute_method/sequential.rs +++ b/particular/src/compute_method/sequential.rs @@ -1,5 +1,5 @@ use crate::compute_method::{ - math::{Float, FloatVector, InfToZero, ReduceAdd, SIMDElement, Zero}, + math::{Float, FloatVector, InfToZero, Reduce, SIMDElement, Zero}, storage::{ ParticleOrdered, ParticleReordered, ParticleSliceSystem, ParticleTreeSystem, PointMass, }, @@ -39,7 +39,7 @@ impl ComputeMethod> for Brut where V: SIMDElement + Copy + Zero, S: SIMDElement + Copy + Zero, - V::SIMD: FloatVector + Copy + ReduceAdd, + V::SIMD: FloatVector + Copy + Reduce, S::SIMD: Float + Copy + InfToZero, { type Output = Vec; @@ -56,7 +56,7 @@ where acceleration + p1.acceleration_simd::(p2) }) }) - .map(ReduceAdd::reduce_add) + .map(Reduce::reduce_sum) .collect() } }