Skip to content

Commit 10cbd91

Browse files
authored
Merge pull request #137 from termoshtt/fix_singular_tests
Fix singular tests
2 parents 8e479fb + 52bb21a commit 10cbd91

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/generate.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,17 @@ where
5151
}
5252

5353
/// Random Hermite Positive-definite matrix
54+
///
55+
/// - Eigenvalue of matrix must be larger than 1 (thus non-singular)
56+
///
5457
pub fn random_hpd<A, S>(n: usize) -> ArrayBase<S, Ix2>
5558
where
5659
A: RandNormal + Conjugate + LinalgScalar,
5760
S: DataOwned<Elem = A> + DataMut,
5861
{
5962
let a: Array2<A> = random((n, n));
6063
let ah: Array2<A> = conjugate(&a);
61-
replicate(&ah.dot(&a))
64+
ArrayBase::eye(n) + &ah.dot(&a)
6265
}
6366

6467
/// construct matrix from diag

tests/solve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn solve_random_t() {
2323
fn rcond() {
2424
macro_rules! rcond {
2525
($elem:ty, $rows:expr, $atol:expr) => {
26-
let a: Array2<$elem> = random(($rows, $rows));
26+
let a: Array2<$elem> = random_hpd($rows);
2727
let rcond = 1. / (a.opnorm_one().unwrap() * a.inv().unwrap().opnorm_one().unwrap());
2828
assert_aclose!(a.rcond().unwrap(), rcond, $atol);
2929
assert_aclose!(a.rcond_into().unwrap(), rcond, $atol);

0 commit comments

Comments
 (0)