Skip to content

Commit

Permalink
Rename ReduceAdd to Reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
Canleskis committed Jan 15, 2024
1 parent cb23e5a commit 9e0abf2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
2 changes: 1 addition & 1 deletion particular/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
40 changes: 21 additions & 19 deletions particular/src/compute_method/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ pub trait SIMDElement<const L: usize>: Sized {
type SIMD: SIMD<Element = Self, Lane = [Self; L]>;
}

/// 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.
Expand Down Expand Up @@ -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) => {
Expand Down
6 changes: 3 additions & 3 deletions particular/src/compute_method/parallel.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand Down Expand Up @@ -40,7 +40,7 @@ impl<const L: usize, V, S> ComputeMethod<ParticleSliceSystem<'_, V, S>> for Brut
where
V: SIMDElement<L> + Copy + Zero + Send + Sync,
S: SIMDElement<L> + Copy + Zero + Sync,
V::SIMD: FloatVector<Float = S::SIMD> + ReduceAdd + Copy + Send + Sync,
V::SIMD: FloatVector<Float = S::SIMD> + Reduce + Copy + Send + Sync,
S::SIMD: Float + InfToZero + Copy + Sync,
{
type Output = Vec<V>;
Expand All @@ -57,7 +57,7 @@ where
acceleration + p1.acceleration_simd::<true>(p2)
})
})
.map(ReduceAdd::reduce_add)
.map(Reduce::reduce_sum)
.collect()
}
}
Expand Down
6 changes: 3 additions & 3 deletions particular/src/compute_method/sequential.rs
Original file line number Diff line number Diff line change
@@ -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,
},
Expand Down Expand Up @@ -39,7 +39,7 @@ impl<const L: usize, V, S> ComputeMethod<ParticleSliceSystem<'_, V, S>> for Brut
where
V: SIMDElement<L> + Copy + Zero,
S: SIMDElement<L> + Copy + Zero,
V::SIMD: FloatVector<Float = S::SIMD> + Copy + ReduceAdd,
V::SIMD: FloatVector<Float = S::SIMD> + Copy + Reduce,
S::SIMD: Float + Copy + InfToZero,
{
type Output = Vec<V>;
Expand All @@ -56,7 +56,7 @@ where
acceleration + p1.acceleration_simd::<true>(p2)
})
})
.map(ReduceAdd::reduce_add)
.map(Reduce::reduce_sum)
.collect()
}
}
Expand Down

0 comments on commit 9e0abf2

Please sign in to comment.