concision_core/init/
utils.rs1use ndarray::*;
6use ndrand::RandomExt;
7use num::complex::{Complex, ComplexDistribution};
8use num::Num;
9use rand::distributions::uniform::{SampleUniform, Uniform};
10use rand::rngs::StdRng;
11use rand::{rngs, SeedableRng};
12use rand_distr::{Distribution, StandardNormal};
13
14pub fn randc<A, S, D>(shape: impl IntoDimension<Dim = D>) -> ArrayBase<S, D>
16where
17 A: Clone + Num,
18 D: Dimension,
19 S: DataOwned<Elem = Complex<A>>,
20 ComplexDistribution<A, A>: Distribution<Complex<A>>,
21{
22 let distr = ComplexDistribution::<A, A>::new(A::one(), A::one());
23 ArrayBase::random(shape, distr)
24}
25
26pub fn stdnorm<S, D, Sh>(shape: Sh) -> ArrayBase<S, D>
28where
29 D: Dimension,
30 S: DataOwned,
31 Sh: ShapeBuilder<Dim = D>,
32 StandardNormal: Distribution<S::Elem>,
33{
34 ArrayBase::random(shape, StandardNormal)
35}
36
37pub fn stdnorm_from_seed<S, D, Sh>(shape: Sh, seed: u64) -> ArrayBase<S, D>
38where
39 D: Dimension,
40 S: DataOwned,
41 Sh: ShapeBuilder<Dim = D>,
42 StandardNormal: Distribution<S::Elem>,
43{
44 ArrayBase::random_using(shape, StandardNormal, &mut StdRng::seed_from_u64(seed))
45}
46pub fn uniform_from_seed<T, D>(
48 key: u64,
49 start: T,
50 stop: T,
51 shape: impl IntoDimension<Dim = D>,
52) -> Array<T, D>
53where
54 D: Dimension,
55 T: SampleUniform,
56{
57 Array::random_using(
58 shape,
59 Uniform::new(start, stop),
60 &mut rngs::StdRng::seed_from_u64(key),
61 )
62}