11//! Generator functions for matrices
22
33use ndarray:: * ;
4- use rand:: * ;
5- use std:: ops:: * ;
4+ use rand:: { distributions:: Standard , prelude:: * } ;
65
76use super :: convert:: * ;
87use super :: error:: * ;
@@ -11,40 +10,41 @@ use super::types::*;
1110/// Hermite conjugate matrix
1211pub fn conjugate < A , Si , So > ( a : & ArrayBase < Si , Ix2 > ) -> ArrayBase < So , Ix2 >
1312where
14- A : Scalar + Lapack
13+ A : Scalar ,
1514 Si : Data < Elem = A > ,
1615 So : DataOwned < Elem = A > + DataMut ,
1716{
18- let mut a = replicate ( & a. t ( ) ) ;
17+ let mut a: ArrayBase < So , Ix2 > = replicate ( & a. t ( ) ) ;
1918 for val in a. iter_mut ( ) {
20- * val = Scalar :: conj ( * val ) ;
19+ * val = val . conj ( ) ;
2120 }
2221 a
2322}
2423
2524/// Generate random array
2625pub fn random < A , S , Sh , D > ( sh : Sh ) -> ArrayBase < S , D >
2726where
28- A : RandNormal ,
2927 S : DataOwned < Elem = A > ,
3028 D : Dimension ,
3129 Sh : ShapeBuilder < Dim = D > ,
30+ Standard : Distribution < A > ,
3231{
3332 let mut rng = thread_rng ( ) ;
34- ArrayBase :: from_shape_fn ( sh, |_| A :: randn ( & mut rng) )
33+ ArrayBase :: from_shape_fn ( sh, |_| rng. sample ( Standard ) )
3534}
3635
3736/// Random Hermite matrix
3837pub fn random_hermite < A , S > ( n : usize ) -> ArrayBase < S , Ix2 >
3938where
40- A : RandNormal + Scalar + Add < Output = A > ,
39+ A : Scalar ,
4140 S : DataOwned < Elem = A > + DataMut ,
41+ Standard : Distribution < A > ,
4242{
43- let mut a = random ( ( n, n) ) ;
43+ let mut a: ArrayBase < S , Ix2 > = random ( ( n, n) ) ;
4444 for i in 0 ..n {
45- a[ ( i, i) ] = a[ ( i, i) ] + Scalar :: conj ( a[ ( i, i) ] ) ;
45+ a[ ( i, i) ] = a[ ( i, i) ] + a[ ( i, i) ] . conj ( ) ;
4646 for j in ( i + 1 ) ..n {
47- a[ ( i, j) ] = Scalar :: conj ( a[ ( j, i) ] )
47+ a[ ( i, j) ] = a[ ( j, i) ] . conj ( ) ;
4848 }
4949 }
5050 a
5656///
5757pub fn random_hpd < A , S > ( n : usize ) -> ArrayBase < S , Ix2 >
5858where
59- A : RandNormal + Scalar + LinalgScalar ,
59+ A : Scalar ,
6060 S : DataOwned < Elem = A > + DataMut ,
61+ Standard : Distribution < A > ,
6162{
6263 let a: Array2 < A > = random ( ( n, n) ) ;
6364 let ah: Array2 < A > = conjugate ( & a) ;
6768/// construct matrix from diag
6869pub fn from_diag < A > ( d : & [ A ] ) -> Array2 < A >
6970where
70- A : LinalgScalar ,
71+ A : Scalar ,
7172{
7273 let n = d. len ( ) ;
7374 let mut e = Array :: zeros ( ( n, n) ) ;
8081/// stack vectors into matrix horizontally
8182pub fn hstack < A , S > ( xs : & [ ArrayBase < S , Ix1 > ] ) -> Result < Array < A , Ix2 > >
8283where
83- A : LinalgScalar ,
84+ A : Scalar ,
8485 S : Data < Elem = A > ,
8586{
8687 let views: Vec < _ > = xs
9697/// stack vectors into matrix vertically
9798pub fn vstack < A , S > ( xs : & [ ArrayBase < S , Ix1 > ] ) -> Result < Array < A , Ix2 > >
9899where
99- A : LinalgScalar ,
100+ A : Scalar ,
100101 S : Data < Elem = A > ,
101102{
102103 let views: Vec < _ > = xs
0 commit comments