Skip to content

Commit a56fbc4

Browse files
committed
Add generate::random(n, m)
1 parent 0c28823 commit a56fbc4

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/generate.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,22 @@ pub fn conjugate<A, Si, So>(a: &ArrayBase<Si, Ix2>) -> ArrayBase<So, Ix2>
1919
a
2020
}
2121

22+
/// Random matrix
23+
pub fn random<A, S>(n: usize, m: usize) -> ArrayBase<S, Ix2>
24+
where A: RandNormal,
25+
S: DataOwned<Elem = A>
26+
{
27+
let mut rng = thread_rng();
28+
let v: Vec<A> = (0..n * m).map(|_| A::randn(&mut rng)).collect();
29+
ArrayBase::from_shape_vec((n, m), v).unwrap()
30+
}
31+
2232
/// Random square matrix
2333
pub fn random_square<A, S>(n: usize) -> ArrayBase<S, Ix2>
2434
where A: RandNormal,
2535
S: DataOwned<Elem = A>
2636
{
27-
let mut rng = thread_rng();
28-
let v: Vec<A> = (0..n * n).map(|_| A::randn(&mut rng)).collect();
29-
ArrayBase::from_shape_vec((n, n), v).unwrap()
37+
random(n, n)
3038
}
3139

3240
/// Random Hermite matrix

0 commit comments

Comments
 (0)