diff --git a/CHANGELOG b/CHANGELOG index f140a54..04f8ec5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,5 @@ ## Unreleased +- `rand` dependency updated to 0.9. - Add single-lanes portable-simd trait implementations. ## Release v0.9.1 (05 Sept. 2025) @@ -97,4 +98,4 @@ vectorization, if it can. - Add the `libm_force` cargo feature that forces the use of `libm`, even when we don't target `no-std`. - Add `copysign` to copy the sign from one number to another. - Add `simd_horizontal_min`, `simd_horizontal_max` to compute the min/max among the lanes of a single SIMD number. -- Wrap all SIMD bools from `packed_simd` into our own `Simd<_>` newtype. \ No newline at end of file +- Wrap all SIMD bools from `packed_simd` into our own `Simd<_>` newtype. diff --git a/Cargo.toml b/Cargo.toml index 7f1adf1..de75b6f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ num-complex = { version = "0.4", default-features = false } wide = { version = "0.8.1", default-features = false, optional = true } fixed = { version = "1", optional = true } cordic = { version = "0.1", optional = true } -rand = { version = "0.8", optional = true } +rand = { version = "0.9", optional = true } serde = { version = "1", default-features = false, optional = true } rkyv = { version = "0.7", optional = true } libm_force = { package = "libm", version = "0.2", optional = true } diff --git a/src/scalar/fixed_impl.rs b/src/scalar/fixed_impl.rs index 93734fd..cdddc4e 100644 --- a/src/scalar/fixed_impl.rs +++ b/src/scalar/fixed_impl.rs @@ -76,19 +76,19 @@ macro_rules! impl_fixed_type ( } #[cfg(feature = "rand")] - impl rand::distributions::Distribution<$FixedI> for rand::distributions::Standard { + impl rand::distr::Distribution<$FixedI> for rand::distr::StandardUniform { #[inline] fn sample<'a, G: rand::Rng + ?Sized>(&self, rng: &mut G) -> $FixedI { - let bits = rng.gen(); + let bits = rng.random(); $FixedI(fixed::$FixedI::from_bits(bits)) } } #[cfg(feature = "rand")] - impl rand::distributions::Distribution<$FixedI> for rand::distributions::OpenClosed01 { + impl rand::distr::Distribution<$FixedI> for rand::distr::OpenClosed01 { #[inline] fn sample<'a, G: rand::Rng + ?Sized>(&self, rng: &mut G) -> $FixedI { - let val: f64 = rng.gen(); + let val: f64 = rng.random(); $FixedI(fixed::$FixedI::from_num(val)) } } diff --git a/src/simd/rand_impl.rs b/src/simd/rand_impl.rs index 33edeb8..91bb1b7 100644 --- a/src/simd/rand_impl.rs +++ b/src/simd/rand_impl.rs @@ -9,7 +9,7 @@ macro_rules! ignore_snd ( macro_rules! impl_rand_auto_simd ( ($($t: ty, $($i: ident),*;)*) => ($( - impl rand::distributions::Distribution> for rand::distributions::Standard { + impl rand::distr::Distribution> for rand::distr::StandardUniform { #[inline(always)] fn sample(&self, rng: &mut R) -> AutoSimd<$t> { AutoSimd::<$t>::new($( @@ -49,9 +49,6 @@ impl_rand_auto_simd!( [i8; 16], _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15; [i8; 32], _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31; // [i8; 64], _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63; - [isize; 2], _0, _1; - [isize; 4], _0, _1, _2, _3; - [isize; 8], _0, _1, _2, _3, _4, _5, _6, _7; [u128; 1], _0; [u128; 2], _0, _1; [u128; 4], _0, _1, _2, _3; @@ -73,9 +70,6 @@ impl_rand_auto_simd!( [u8; 16], _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15; [u8; 32], _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31; // [u8; 64], _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63; - [usize; 2], _0, _1; - [usize; 4], _0, _1, _2, _3; - [usize; 8], _0, _1, _2, _3, _4, _5, _6, _7; [bool; 1], _0; [bool; 2], _0, _1; [bool; 4], _0, _1, _2, _3; @@ -85,10 +79,32 @@ impl_rand_auto_simd!( // [bool; 64], _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63; ); +macro_rules! impl_rand_auto_simd_xsize ( + ($($t: ty, $sampler: ident, $($i: ident),*;)*) => ($( + impl rand::distr::Distribution> for rand::distr::StandardUniform { + #[inline(always)] + fn sample(&self, rng: &mut R) -> AutoSimd<$t> { + AutoSimd::<$t>::new($( + ignore_snd!([$sampler(rng)], [$i]) + ),*) + } + } + )*) +); + +impl_rand_auto_simd_xsize!( + [isize; 2], sample_isize, _0, _1; + [isize; 4], sample_isize, _0, _1, _2, _3; + [isize; 8], sample_isize, _0, _1, _2, _3, _4, _5, _6, _7; + [usize; 2], sample_usize, _0, _1; + [usize; 4], sample_usize, _0, _1, _2, _3; + [usize; 8], sample_usize, _0, _1, _2, _3, _4, _5, _6, _7; +); + #[cfg(feature = "wide")] macro_rules! impl_rand_wide_simd ( ($($t: ident, $wrapped: ty, $arr: ty;)*) => ($( - impl rand::distributions::Distribution<$t> for rand::distributions::Standard { + impl rand::distr::Distribution<$t> for rand::distr::StandardUniform { #[inline(always)] fn sample(&self, rng: &mut R) -> $t { $t(<$wrapped as From<$arr>>::from(self.sample(rng))) @@ -107,7 +123,7 @@ impl_rand_wide_simd!( #[cfg(feature = "portable_simd")] macro_rules! impl_rand_portable_simd ( ($($wrapped: ty, $($i: ident),*;)*) => ($( - impl rand::distributions::Distribution<$wrapped> for rand::distributions::Standard { + impl rand::distr::Distribution<$wrapped> for rand::distr::StandardUniform { #[inline(always)] fn sample(&self, rng: &mut R) -> $wrapped { <$wrapped>::new($( @@ -145,9 +161,6 @@ impl_rand_portable_simd!( i8x16, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15; i8x32, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31; i8x64, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63; - isizex2, _0, _1; - isizex4, _0, _1, _2, _3; - isizex8, _0, _1, _2, _3, _4, _5, _6, _7; u16x2, _0, _1; u16x4, _0, _1, _2, _3; u16x8, _0, _1, _2, _3, _4, _5, _6, _7; @@ -166,9 +179,6 @@ impl_rand_portable_simd!( u8x16, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15; u8x32, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31; u8x64, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63; - usizex2, _0, _1; - usizex4, _0, _1, _2, _3; - usizex8, _0, _1, _2, _3, _4, _5, _6, _7; mask16x2, _0, _1; mask16x4, _0, _1, _2, _3; mask16x8, _0, _1, _2, _3, _4, _5, _6, _7; @@ -191,3 +201,41 @@ impl_rand_portable_simd!( masksizex4, _0, _1, _2, _3; masksizex8, _0, _1, _2, _3, _4, _5, _6, _7; ); + +#[cfg(feature = "portable_simd")] +macro_rules! impl_rand_portable_simd_xsize ( + ($($wrapped: ty, $sampler: ident, $($i: ident),*;)*) => ($( + impl rand::distr::Distribution<$wrapped> for rand::distr::StandardUniform { + #[inline(always)] + fn sample(&self, rng: &mut R) -> $wrapped { + <$wrapped>::new($( + ignore_snd!([$sampler(rng)], [$i]) + ),*) + } + } + )*) +); + +#[cfg(feature = "portable_simd")] +impl_rand_portable_simd_xsize!( + isizex2, sample_isize, _0, _1; + isizex4, sample_isize, _0, _1, _2, _3; + isizex8, sample_isize, _0, _1, _2, _3, _4, _5, _6, _7; + usizex2, sample_usize, _0, _1; + usizex4, sample_usize, _0, _1, _2, _3; + usizex8, sample_usize, _0, _1, _2, _3, _4, _5, _6, _7; +); + +#[inline(always)] +fn sample_isize(rng: &mut R) -> isize { + let mut bytes = [0u8; _]; + rng.fill_bytes(&mut bytes); + isize::from_le_bytes(bytes) +} + +#[inline(always)] +fn sample_usize(rng: &mut R) -> usize { + let mut bytes = [0u8; _]; + rng.fill_bytes(&mut bytes); + usize::from_le_bytes(bytes) +}