Skip to content

Commit 32543cd

Browse files
authored
feat: add a SupersetOf<f32> requirement for the ComplexField and SimdComplexField traits (#59)
1 parent 5bb3fd6 commit 32543cd

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- Add the `portable_simd` feature for supporting `std::simd`.
66
- The `ClosedAdd, ClosedMul, etc.` traits no longer require `AddAssign, MulAssign`. Instead they are required for new
77
traits named `ClosedAddAssign, ClosedMulAssign, etc.`
8+
- The `ComplexField` and `SimdComplexField` (and, by extension, `RealField` and `SimdRealField`) traits now depend on the
9+
`SupersetOf<f32>` trait in addition to `SupersetOf<f64>`.
810

911
## Release v0.8.1 (04 Apr. 2023)
1012
- Add implementation of `rkyv` serialization/deserialization to the `Wide*` wrapper types.

src/scalar/complex.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ macro_rules! complex_trait_methods (
161161
#[allow(missing_docs)]
162162
pub trait ComplexField:
163163
SubsetOf<Self>
164+
+ SupersetOf<f32>
164165
+ SupersetOf<f64>
165166
+ FromPrimitive
166167
+ Field<Element=Self, SimdBool=bool>

src/scalar/fixed_impl.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,28 @@ macro_rules! impl_fixed_type (
316316
}
317317
}
318318

319+
impl<Fract: $LeEqDim> SubsetOf<$FixedI<Fract>> for f32 {
320+
#[inline]
321+
fn to_superset(&self) -> $FixedI<Fract> {
322+
$FixedI(fixed::$FixedI::from_num(*self))
323+
}
324+
325+
#[inline]
326+
fn from_superset(element: &$FixedI<Fract>) -> Option<Self> {
327+
Some(Self::from_superset_unchecked(element))
328+
}
329+
330+
#[inline]
331+
fn from_superset_unchecked(element: &$FixedI<Fract>) -> Self {
332+
element.0.to_num::<f32>()
333+
}
334+
335+
#[inline]
336+
fn is_in_subset(_: &$FixedI<Fract>) -> bool {
337+
true
338+
}
339+
}
340+
319341
impl<Fract: $LeEqDim> SubsetOf<$FixedI<Fract>> for $FixedI<Fract> {
320342
#[inline]
321343
fn to_superset(&self) -> $FixedI<Fract> {

src/simd/simd_complex.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,25 @@ use crate::simd::{SimdRealField, SimdValue};
1212
/// Each lane of an SIMD complex field should contain one complex field.
1313
#[allow(missing_docs)]
1414
pub trait SimdComplexField:
15-
SubsetOf<Self>
16-
+ SupersetOf<f64>
17-
+ Field
18-
+ Clone
19-
+ Neg<Output = Self>
15+
SubsetOf<Self>
16+
+ SupersetOf<f32>
17+
+ SupersetOf<f64>
18+
+ Field
19+
+ Clone
20+
+ Neg<Output=Self>
2021
// + MeetSemilattice
2122
// + JoinSemilattice
22-
+ Send
23-
+ Sync
24-
+ Any
25-
+ 'static
26-
+ Debug
27-
+ NumAssignOps
28-
+ NumOps
29-
+ PartialEq
23+
+ Send
24+
+ Sync
25+
+ Any
26+
+ 'static
27+
+ Debug
28+
+ NumAssignOps
29+
+ NumOps
30+
+ PartialEq
3031
{
3132
/// Type of the coefficients of a complex number.
32-
type SimdRealField: SimdRealField<SimdBool = <Self as SimdValue>::SimdBool>;
33+
type SimdRealField: SimdRealField<SimdBool=<Self as SimdValue>::SimdBool>;
3334
complex_trait_methods!(SimdRealField, simd_);
3435

3536
/// Computes the sum of all the lanes of `self`.

0 commit comments

Comments
 (0)