Skip to content

Commit 2da148c

Browse files
KAAtheWiseGitRalith
authored andcommitted
feat: upgrade rand to 0.9.0 in base
1 parent a3c2610 commit 2da148c

16 files changed

+92
-79
lines changed

Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ rkyv-serialize = ["rkyv-serialize-no-std", "rkyv/std", "rkyv/validation"]
6666
## To use rand in a #[no-std] environment, enable the
6767
## `rand-no-std` feature instead of `rand`.
6868
rand-no-std = ["rand-package"]
69-
rand = ["rand-no-std", "rand-package/std", "rand-package/std_rng", "rand_distr"]
69+
rand = ["rand-no-std", "rand-package/std", "rand-package/std_rng", "rand-package/thread_rng", "rand_distr"]
7070

7171
# Tests
7272
arbitrary = ["quickcheck"]
@@ -77,14 +77,14 @@ rkyv-safe-deser = ["rkyv-serialize", "rkyv/validation"]
7777
[dependencies]
7878
nalgebra-macros = { version = "0.2.2", path = "nalgebra-macros", optional = true }
7979
typenum = "1.12"
80-
rand-package = { package = "rand", version = "0.8", optional = true, default-features = false }
80+
rand-package = { package = "rand", version = "0.9", optional = true, default-features = false }
8181
num-traits = { version = "0.2", default-features = false }
8282
num-complex = { version = "0.4", default-features = false }
8383
num-rational = { version = "0.4", default-features = false }
8484
approx = { version = "0.5", default-features = false }
8585
simba = { version = "0.9", default-features = false }
8686
alga = { version = "0.9", default-features = false, optional = true }
87-
rand_distr = { version = "0.4", default-features = false, optional = true }
87+
rand_distr = { version = "0.5", default-features = false, optional = true }
8888
matrixmultiply = { version = "0.3", optional = true }
8989
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
9090
rkyv = { version = "0.7.41", default-features = false, optional = true }
@@ -114,7 +114,7 @@ rayon = { version = "1.6", optional = true }
114114

115115
[dev-dependencies]
116116
serde_json = "1.0"
117-
rand_xorshift = "0.3"
117+
rand_xorshift = "0.4"
118118
rand_isaac = "0.3"
119119
criterion = { version = "0.4", features = ["html_reports"] }
120120
nalgebra = { path = ".", features = ["debug", "compare", "rand", "macros"] }

src/base/construction.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use quickcheck::{Arbitrary, Gen};
99
use num::{Bounded, One, Zero};
1010
#[cfg(feature = "rand-no-std")]
1111
use rand::{
12-
distributions::{Distribution, Standard},
12+
distr::{Distribution, StandardUniform},
1313
Rng,
1414
};
1515

@@ -293,10 +293,10 @@ where
293293
#[cfg(feature = "rand")]
294294
pub fn new_random_generic(nrows: R, ncols: C) -> Self
295295
where
296-
Standard: Distribution<T>,
296+
StandardUniform: Distribution<T>,
297297
{
298-
let mut rng = rand::thread_rng();
299-
Self::from_fn_generic(nrows, ncols, |_, _| rng.gen())
298+
let mut rng = rand::rng();
299+
Self::from_fn_generic(nrows, ncols, |_, _| rng.random())
300300
}
301301

302302
/// Creates a matrix filled with random values from the given distribution.
@@ -637,7 +637,7 @@ macro_rules! impl_constructors(
637637
#[inline]
638638
#[cfg(feature = "rand")]
639639
pub fn new_random($($args: usize),*) -> Self
640-
where Standard: Distribution<T> {
640+
where StandardUniform: Distribution<T> {
641641
Self::new_random_generic($($gargs),*)
642642
}
643643
}
@@ -856,17 +856,19 @@ where
856856
}
857857

858858
#[cfg(feature = "rand-no-std")]
859-
impl<T: Scalar, R: Dim, C: Dim> Distribution<OMatrix<T, R, C>> for Standard
859+
impl<T: Scalar, R: Dim, C: Dim> Distribution<OMatrix<T, R, C>> for StandardUniform
860860
where
861861
DefaultAllocator: Allocator<R, C>,
862-
Standard: Distribution<T>,
862+
StandardUniform: Distribution<T>,
863863
{
864864
#[inline]
865865
fn sample<G: Rng + ?Sized>(&self, rng: &mut G) -> OMatrix<T, R, C> {
866-
let nrows = R::try_to_usize().unwrap_or_else(|| rng.gen_range(0..10));
867-
let ncols = C::try_to_usize().unwrap_or_else(|| rng.gen_range(0..10));
866+
let nrows = R::try_to_usize().unwrap_or_else(|| rng.random_range(0..10));
867+
let ncols = C::try_to_usize().unwrap_or_else(|| rng.random_range(0..10));
868868

869-
OMatrix::from_fn_generic(R::from_usize(nrows), C::from_usize(ncols), |_, _| rng.gen())
869+
OMatrix::from_fn_generic(R::from_usize(nrows), C::from_usize(ncols), |_, _| {
870+
rng.random()
871+
})
870872
}
871873
}
872874

@@ -892,7 +894,7 @@ where
892894

893895
// TODO(specialization): faster impls possible for D≤4 (see rand_distr::{UnitCircle, UnitSphere})
894896
#[cfg(feature = "rand")]
895-
impl<T: crate::RealField, D: DimName> Distribution<Unit<OVector<T, D>>> for Standard
897+
impl<T: crate::RealField, D: DimName> Distribution<Unit<OVector<T, D>>> for StandardUniform
896898
where
897899
DefaultAllocator: Allocator<D>,
898900
rand_distr::StandardNormal: Distribution<T>,

src/base/helper.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use quickcheck::{Arbitrary, Gen};
33

44
#[cfg(feature = "rand-no-std")]
55
use rand::{
6-
distributions::{Distribution, Standard},
6+
distr::{Distribution, StandardUniform},
77
Rng,
88
};
99

@@ -24,8 +24,8 @@ pub fn reject<F: FnMut(&T) -> bool, T: Arbitrary>(g: &mut Gen, f: F) -> T {
2424
#[cfg(feature = "rand-no-std")]
2525
pub fn reject_rand<G: Rng + ?Sized, F: FnMut(&T) -> bool, T>(g: &mut G, f: F) -> T
2626
where
27-
Standard: Distribution<T>,
27+
StandardUniform: Distribution<T>,
2828
{
2929
use std::iter;
30-
iter::repeat(()).map(|_| g.gen()).find(f).unwrap()
30+
iter::repeat(()).map(|_| g.random()).find(f).unwrap()
3131
}

src/geometry/isometry_construction.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use quickcheck::{Arbitrary, Gen};
66
use num::One;
77
#[cfg(feature = "rand-no-std")]
88
use rand::{
9-
distributions::{Distribution, Standard},
9+
distr::{Distribution, StandardUniform},
1010
Rng,
1111
};
1212

@@ -89,14 +89,14 @@ where
8989
}
9090

9191
#[cfg(feature = "rand-no-std")]
92-
impl<T: crate::RealField, R, const D: usize> Distribution<Isometry<T, R, D>> for Standard
92+
impl<T: crate::RealField, R, const D: usize> Distribution<Isometry<T, R, D>> for StandardUniform
9393
where
9494
R: AbstractRotation<T, D>,
95-
Standard: Distribution<T> + Distribution<R>,
95+
StandardUniform: Distribution<T> + Distribution<R>,
9696
{
9797
#[inline]
9898
fn sample<G: Rng + ?Sized>(&self, rng: &mut G) -> Isometry<T, R, D> {
99-
Isometry::from_parts(rng.gen(), rng.gen())
99+
Isometry::from_parts(rng.random(), rng.random())
100100
}
101101
}
102102

src/geometry/orthographic.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use quickcheck::{Arbitrary, Gen};
33
#[cfg(feature = "rand-no-std")]
44
use rand::{
5-
distributions::{Distribution, Standard},
5+
distr::{Distribution, StandardUniform},
66
Rng,
77
};
88
#[cfg(feature = "serde-serialize-no-std")]
@@ -741,18 +741,18 @@ impl<T: RealField> Orthographic3<T> {
741741
}
742742

743743
#[cfg(feature = "rand-no-std")]
744-
impl<T: RealField> Distribution<Orthographic3<T>> for Standard
744+
impl<T: RealField> Distribution<Orthographic3<T>> for StandardUniform
745745
where
746-
Standard: Distribution<T>,
746+
StandardUniform: Distribution<T>,
747747
{
748748
/// Generate an arbitrary random variate for testing purposes.
749749
fn sample<R: Rng + ?Sized>(&self, r: &mut R) -> Orthographic3<T> {
750750
use crate::base::helper;
751-
let left = r.gen();
751+
let left = r.random();
752752
let right = helper::reject_rand(r, |x: &T| *x > left);
753-
let bottom = r.gen();
753+
let bottom = r.random();
754754
let top = helper::reject_rand(r, |x: &T| *x > bottom);
755-
let znear = r.gen();
755+
let znear = r.random();
756756
let zfar = helper::reject_rand(r, |x: &T| *x > znear);
757757

758758
Orthographic3::new(left, right, bottom, top, znear, zfar)

src/geometry/perspective.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use quickcheck::{Arbitrary, Gen};
33
#[cfg(feature = "rand-no-std")]
44
use rand::{
5-
distributions::{Distribution, Standard},
5+
distr::{Distribution, StandardUniform},
66
Rng,
77
};
88

@@ -313,18 +313,18 @@ impl<T: RealField> Perspective3<T> {
313313
}
314314

315315
#[cfg(feature = "rand-no-std")]
316-
impl<T: RealField> Distribution<Perspective3<T>> for Standard
316+
impl<T: RealField> Distribution<Perspective3<T>> for StandardUniform
317317
where
318-
Standard: Distribution<T>,
318+
StandardUniform: Distribution<T>,
319319
{
320320
/// Generate an arbitrary random variate for testing purposes.
321321
fn sample<R: Rng + ?Sized>(&self, r: &mut R) -> Perspective3<T> {
322322
use crate::base::helper;
323-
let znear = r.gen();
323+
let znear = r.random();
324324
let zfar = helper::reject_rand(r, |x: &T| !(x.clone() - znear.clone()).is_zero());
325325
let aspect = helper::reject_rand(r, |x: &T| !x.is_zero());
326326

327-
Perspective3::new(aspect, r.gen(), znear, zfar)
327+
Perspective3::new(aspect, r.random(), znear, zfar)
328328
}
329329
}
330330

src/geometry/point_construction.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use quickcheck::{Arbitrary, Gen};
44
use num::{Bounded, One, Zero};
55
#[cfg(feature = "rand-no-std")]
66
use rand::{
7-
distributions::{Distribution, Standard},
7+
distr::{Distribution, StandardUniform},
88
Rng,
99
};
1010

@@ -159,15 +159,15 @@ where
159159
}
160160

161161
#[cfg(feature = "rand-no-std")]
162-
impl<T: Scalar, D: DimName> Distribution<OPoint<T, D>> for Standard
162+
impl<T: Scalar, D: DimName> Distribution<OPoint<T, D>> for StandardUniform
163163
where
164-
Standard: Distribution<T>,
164+
StandardUniform: Distribution<T>,
165165
DefaultAllocator: Allocator<D>,
166166
{
167167
/// Generate a `Point` where each coordinate is an independent variate from `[0, 1)`.
168168
#[inline]
169169
fn sample<'a, G: Rng + ?Sized>(&self, rng: &mut G) -> OPoint<T, D> {
170-
OPoint::from(rng.gen::<OVector<T, D>>())
170+
OPoint::from(rng.random::<OVector<T, D>>())
171171
}
172172
}
173173

src/geometry/quaternion_construction.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use quickcheck::{Arbitrary, Gen};
77

88
#[cfg(feature = "rand-no-std")]
99
use rand::{
10-
distributions::{uniform::SampleUniform, Distribution, OpenClosed01, Standard, Uniform},
10+
distr::{uniform::SampleUniform, Distribution, OpenClosed01, StandardUniform, Uniform},
1111
Rng,
1212
};
1313

@@ -171,13 +171,13 @@ where
171171
}
172172

173173
#[cfg(feature = "rand-no-std")]
174-
impl<T: SimdRealField> Distribution<Quaternion<T>> for Standard
174+
impl<T: SimdRealField> Distribution<Quaternion<T>> for StandardUniform
175175
where
176-
Standard: Distribution<T>,
176+
StandardUniform: Distribution<T>,
177177
{
178178
#[inline]
179179
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Quaternion<T> {
180-
Quaternion::new(rng.gen(), rng.gen(), rng.gen(), rng.gen())
180+
Quaternion::new(rng.random(), rng.random(), rng.random(), rng.random())
181181
}
182182
}
183183

@@ -866,7 +866,7 @@ where
866866
}
867867

868868
#[cfg(feature = "rand-no-std")]
869-
impl<T: SimdRealField> Distribution<UnitQuaternion<T>> for Standard
869+
impl<T: SimdRealField> Distribution<UnitQuaternion<T>> for StandardUniform
870870
where
871871
T::Element: SimdRealField,
872872
OpenClosed01: Distribution<T>,
@@ -879,7 +879,8 @@ where
879879
// Uniform random rotations.
880880
// In D. Kirk, editor, Graphics Gems III, pages 124-132. Academic, New York, 1992.
881881
let x0 = rng.sample(OpenClosed01);
882-
let twopi = Uniform::new(T::zero(), T::simd_two_pi());
882+
let twopi = Uniform::new(T::zero(), T::simd_two_pi())
883+
.expect("Failed to costruct `Uniform`, should be unreachable");
883884
let theta1 = rng.sample(&twopi);
884885
let theta2 = rng.sample(&twopi);
885886
let s1 = theta1.clone().simd_sin();
@@ -921,7 +922,7 @@ mod tests {
921922
fn random_unit_quats_are_unit() {
922923
let mut rng = rand_xorshift::XorShiftRng::from_seed([0xAB; 16]);
923924
for _ in 0..1000 {
924-
let x = rng.gen::<UnitQuaternion<f32>>();
925+
let x = rng.random::<UnitQuaternion<f32>>();
925926
assert!(relative_eq!(x.into_inner().norm(), 1.0))
926927
}
927928
}

src/geometry/rotation_specialization.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use num::Zero;
77

88
#[cfg(feature = "rand-no-std")]
99
use rand::{
10-
distributions::{uniform::SampleUniform, Distribution, OpenClosed01, Standard, Uniform},
10+
distr::{uniform::SampleUniform, Distribution, OpenClosed01, StandardUniform, Uniform},
1111
Rng,
1212
};
1313

@@ -271,15 +271,17 @@ impl<T: SimdRealField> Rotation2<T> {
271271
}
272272

273273
#[cfg(feature = "rand-no-std")]
274-
impl<T: SimdRealField> Distribution<Rotation2<T>> for Standard
274+
impl<T: SimdRealField> Distribution<Rotation2<T>> for StandardUniform
275275
where
276276
T::Element: SimdRealField,
277277
T: SampleUniform,
278278
{
279279
/// Generate a uniformly distributed random rotation.
280280
#[inline]
281281
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Rotation2<T> {
282-
let twopi = Uniform::new(T::zero(), T::simd_two_pi());
282+
let twopi = Uniform::new(T::zero(), T::simd_two_pi())
283+
.expect("Failed to costruct `Uniform`, should be unreachable");
284+
283285
Rotation2::new(rng.sample(twopi))
284286
}
285287
}
@@ -1153,7 +1155,7 @@ impl<T: SimdRealField> Rotation3<T> {
11531155
}
11541156

11551157
#[cfg(feature = "rand-no-std")]
1156-
impl<T: SimdRealField> Distribution<Rotation3<T>> for Standard
1158+
impl<T: SimdRealField> Distribution<Rotation3<T>> for StandardUniform
11571159
where
11581160
T::Element: SimdRealField,
11591161
OpenClosed01: Distribution<T>,
@@ -1167,7 +1169,8 @@ where
11671169
// In D. Kirk, editor, Graphics Gems III, pages 117-120. Academic, New York, 1992.
11681170

11691171
// Compute a random rotation around Z
1170-
let twopi = Uniform::new(T::zero(), T::simd_two_pi());
1172+
let twopi = Uniform::new(T::zero(), T::simd_two_pi())
1173+
.expect("Failed to costruct `Uniform`, should be unreachable");
11711174
let theta = rng.sample(&twopi);
11721175
let (ts, tc) = theta.simd_sin_cos();
11731176
let a = SMatrix::<T, 3, 3>::new(

src/geometry/scale_construction.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use quickcheck::{Arbitrary, Gen};
66
use num::One;
77
#[cfg(feature = "rand-no-std")]
88
use rand::{
9-
distributions::{Distribution, Standard},
9+
distr::{Distribution, StandardUniform},
1010
Rng,
1111
};
1212

@@ -63,14 +63,14 @@ impl<T: Scalar + One + ClosedMulAssign, const D: usize> One for Scale<T, D> {
6363
}
6464

6565
#[cfg(feature = "rand-no-std")]
66-
impl<T: Scalar, const D: usize> Distribution<Scale<T, D>> for Standard
66+
impl<T: Scalar, const D: usize> Distribution<Scale<T, D>> for StandardUniform
6767
where
68-
Standard: Distribution<T>,
68+
StandardUniform: Distribution<T>,
6969
{
7070
/// Generate an arbitrary random variate for testing purposes.
7171
#[inline]
7272
fn sample<G: Rng + ?Sized>(&self, rng: &mut G) -> Scale<T, D> {
73-
Scale::from(rng.gen::<SVector<T, D>>())
73+
Scale::from(rng.random::<SVector<T, D>>())
7474
}
7575
}
7676

0 commit comments

Comments
 (0)