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::*;
6
6
7
7
use super :: convert:: * ;
8
8
use super :: error:: * ;
9
+ use super :: qr:: * ;
9
10
use super :: types:: * ;
10
11
11
12
/// Hermite conjugate matrix
34
35
ArrayBase :: from_shape_fn ( sh, |_| A :: randn ( & mut rng) )
35
36
}
36
37
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
+
37
61
/// Random Hermite matrix
38
62
pub fn random_hermite < A , S > ( n : usize ) -> ArrayBase < S , Ix2 >
39
63
where
You can’t perform that action at this time.
0 commit comments