File tree Expand file tree Collapse file tree 2 files changed +5
-2
lines changed Expand file tree Collapse file tree 2 files changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -51,14 +51,17 @@ where
51
51
}
52
52
53
53
/// Random Hermite Positive-definite matrix
54
+ ///
55
+ /// - Eigenvalue of matrix must be larger than 1 (thus non-singular)
56
+ ///
54
57
pub fn random_hpd < A , S > ( n : usize ) -> ArrayBase < S , Ix2 >
55
58
where
56
59
A : RandNormal + Conjugate + LinalgScalar ,
57
60
S : DataOwned < Elem = A > + DataMut ,
58
61
{
59
62
let a: Array2 < A > = random ( ( n, n) ) ;
60
63
let ah: Array2 < A > = conjugate ( & a) ;
61
- replicate ( & ah. dot ( & a) )
64
+ ArrayBase :: eye ( n ) + & ah. dot ( & a)
62
65
}
63
66
64
67
/// construct matrix from diag
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ fn solve_random_t() {
23
23
fn rcond ( ) {
24
24
macro_rules! rcond {
25
25
( $elem: ty, $rows: expr, $atol: expr) => {
26
- let a: Array2 <$elem> = random ( ( $rows, $rows ) ) ;
26
+ let a: Array2 <$elem> = random_hpd ( $rows) ;
27
27
let rcond = 1. / ( a. opnorm_one( ) . unwrap( ) * a. inv( ) . unwrap( ) . opnorm_one( ) . unwrap( ) ) ;
28
28
assert_aclose!( a. rcond( ) . unwrap( ) , rcond, $atol) ;
29
29
assert_aclose!( a. rcond_into( ) . unwrap( ) , rcond, $atol) ;
You can’t perform that action at this time.
0 commit comments