Skip to content

Commit

Permalink
feat: add a SupersetOf<f32> requirement for the ComplexField and Simd…
Browse files Browse the repository at this point in the history
…ComplexField traits (#59)
  • Loading branch information
sebcrozet authored Jun 22, 2024
1 parent 5bb3fd6 commit 32543cd
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- Add the `portable_simd` feature for supporting `std::simd`.
- The `ClosedAdd, ClosedMul, etc.` traits no longer require `AddAssign, MulAssign`. Instead they are required for new
traits named `ClosedAddAssign, ClosedMulAssign, etc.`
- The `ComplexField` and `SimdComplexField` (and, by extension, `RealField` and `SimdRealField`) traits now depend on the
`SupersetOf<f32>` trait in addition to `SupersetOf<f64>`.

## Release v0.8.1 (04 Apr. 2023)
- Add implementation of `rkyv` serialization/deserialization to the `Wide*` wrapper types.
Expand Down
1 change: 1 addition & 0 deletions src/scalar/complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ macro_rules! complex_trait_methods (
#[allow(missing_docs)]
pub trait ComplexField:
SubsetOf<Self>
+ SupersetOf<f32>
+ SupersetOf<f64>
+ FromPrimitive
+ Field<Element=Self, SimdBool=bool>
Expand Down
22 changes: 22 additions & 0 deletions src/scalar/fixed_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,28 @@ macro_rules! impl_fixed_type (
}
}

impl<Fract: $LeEqDim> SubsetOf<$FixedI<Fract>> for f32 {
#[inline]
fn to_superset(&self) -> $FixedI<Fract> {
$FixedI(fixed::$FixedI::from_num(*self))
}

#[inline]
fn from_superset(element: &$FixedI<Fract>) -> Option<Self> {
Some(Self::from_superset_unchecked(element))
}

#[inline]
fn from_superset_unchecked(element: &$FixedI<Fract>) -> Self {
element.0.to_num::<f32>()
}

#[inline]
fn is_in_subset(_: &$FixedI<Fract>) -> bool {
true
}
}

impl<Fract: $LeEqDim> SubsetOf<$FixedI<Fract>> for $FixedI<Fract> {
#[inline]
fn to_superset(&self) -> $FixedI<Fract> {
Expand Down
29 changes: 15 additions & 14 deletions src/simd/simd_complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,25 @@ use crate::simd::{SimdRealField, SimdValue};
/// Each lane of an SIMD complex field should contain one complex field.
#[allow(missing_docs)]
pub trait SimdComplexField:
SubsetOf<Self>
+ SupersetOf<f64>
+ Field
+ Clone
+ Neg<Output = Self>
SubsetOf<Self>
+ SupersetOf<f32>
+ SupersetOf<f64>
+ Field
+ Clone
+ Neg<Output=Self>
// + MeetSemilattice
// + JoinSemilattice
+ Send
+ Sync
+ Any
+ 'static
+ Debug
+ NumAssignOps
+ NumOps
+ PartialEq
+ Send
+ Sync
+ Any
+ 'static
+ Debug
+ NumAssignOps
+ NumOps
+ PartialEq
{
/// Type of the coefficients of a complex number.
type SimdRealField: SimdRealField<SimdBool = <Self as SimdValue>::SimdBool>;
type SimdRealField: SimdRealField<SimdBool=<Self as SimdValue>::SimdBool>;
complex_trait_methods!(SimdRealField, simd_);

/// Computes the sum of all the lanes of `self`.
Expand Down

0 comments on commit 32543cd

Please sign in to comment.