forked from M-Labs/nalgebra
UnitComplex: More efficient sampling
This commit is contained in:
parent
09f26385cc
commit
7417f6cbca
@ -2,10 +2,7 @@
|
||||
use quickcheck::{Arbitrary, Gen};
|
||||
|
||||
#[cfg(feature = "rand-no-std")]
|
||||
use rand::{
|
||||
distributions::{Distribution, Uniform, uniform::SampleUniform, Standard},
|
||||
Rng,
|
||||
};
|
||||
use rand::{distributions::{Distribution, Standard}, Rng};
|
||||
|
||||
use num::One;
|
||||
use num_complex::Complex;
|
||||
@ -401,13 +398,13 @@ where
|
||||
impl<N: SimdRealField> Distribution<UnitComplex<N>> for Standard
|
||||
where
|
||||
N::Element: SimdRealField,
|
||||
N: SampleUniform,
|
||||
rand_distr::UnitCircle: Distribution<[N; 2]>,
|
||||
{
|
||||
/// Generate a uniformly distributed random `UnitComplex`.
|
||||
#[inline]
|
||||
fn sample<'a, R: Rng + ?Sized>(&self, rng: &mut R) -> UnitComplex<N> {
|
||||
let twopi = Uniform::new(N::zero(), N::simd_two_pi());
|
||||
UnitComplex::from_angle(rng.sample(twopi))
|
||||
let x = rng.sample(rand_distr::UnitCircle);
|
||||
UnitComplex::new_unchecked(Complex::new(x[0], x[1]))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user