File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ use std::ops::*;
66
77use super :: convert:: * ;
88use super :: error:: * ;
9+ use super :: qr:: * ;
910use super :: types:: * ;
1011
1112/// Hermite conjugate matrix
3435 ArrayBase :: from_shape_fn ( sh, |_| A :: randn ( & mut rng) )
3536}
3637
38+ /// Generate random unitary matrix using QR decomposition
39+ pub fn random_unitary < A > ( n : usize ) -> Array2 < A >
40+ where
41+ A : Scalar + RandNormal ,
42+ {
43+ let a: Array2 < A > = random ( ( n, n) ) ;
44+ let ( q, _r) = a. qr_into ( ) . unwrap ( ) ;
45+ q
46+ }
47+
48+ /// Generate random regular matrix
49+ pub fn random_regular < A > ( n : usize ) -> Array2 < A >
50+ where
51+ A : Scalar + RandNormal ,
52+ {
53+ let a: Array2 < A > = random ( ( n, n) ) ;
54+ let ( q, mut r) = a. qr_into ( ) . unwrap ( ) ;
55+ for i in 0 ..n {
56+ r[ ( i, i) ] = A :: from_f64 ( 1.0 ) + AssociatedReal :: inject ( r[ ( i, i) ] . abs ( ) ) ;
57+ }
58+ q. dot ( & r)
59+ }
60+
3761/// Random Hermite matrix
3862pub fn random_hermite < A , S > ( n : usize ) -> ArrayBase < S , Ix2 >
3963where
You can’t perform that action at this time.
0 commit comments