Skip to content

Commit 1417f39

Browse files
committed
Revise cauchy support
1 parent 5be2ed2 commit 1417f39

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

src/generate.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! Generator functions for matrices
22
33
use ndarray::*;
4-
use rand::*;
5-
use std::ops::*;
4+
use rand::{distributions::Standard, prelude::*};
65

76
use super::convert::*;
87
use super::error::*;
@@ -11,40 +10,41 @@ use super::types::*;
1110
/// Hermite conjugate matrix
1211
pub fn conjugate<A, Si, So>(a: &ArrayBase<Si, Ix2>) -> ArrayBase<So, Ix2>
1312
where
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
2625
pub fn random<A, S, Sh, D>(sh: Sh) -> ArrayBase<S, D>
2726
where
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
3837
pub fn random_hermite<A, S>(n: usize) -> ArrayBase<S, Ix2>
3938
where
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
@@ -56,8 +56,9 @@ where
5656
///
5757
pub fn random_hpd<A, S>(n: usize) -> ArrayBase<S, Ix2>
5858
where
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);
@@ -67,7 +68,7 @@ where
6768
/// construct matrix from diag
6869
pub fn from_diag<A>(d: &[A]) -> Array2<A>
6970
where
70-
A: LinalgScalar,
71+
A: Scalar,
7172
{
7273
let n = d.len();
7374
let mut e = Array::zeros((n, n));
@@ -80,7 +81,7 @@ where
8081
/// stack vectors into matrix horizontally
8182
pub fn hstack<A, S>(xs: &[ArrayBase<S, Ix1>]) -> Result<Array<A, Ix2>>
8283
where
83-
A: LinalgScalar,
84+
A: Scalar,
8485
S: Data<Elem = A>,
8586
{
8687
let views: Vec<_> = xs
@@ -96,7 +97,7 @@ where
9697
/// stack vectors into matrix vertically
9798
pub fn vstack<A, S>(xs: &[ArrayBase<S, Ix1>]) -> Result<Array<A, Ix2>>
9899
where
99-
A: LinalgScalar,
100+
A: Scalar,
100101
S: Data<Elem = A>,
101102
{
102103
let views: Vec<_> = xs

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub mod convert;
2323
pub mod diagonal;
2424
pub mod eigh;
2525
pub mod error;
26-
// pub mod generate;
26+
pub mod generate;
2727
pub mod lapack_traits;
2828
pub mod layout;
2929
pub mod norm;
@@ -42,7 +42,7 @@ pub use cholesky::*;
4242
pub use convert::*;
4343
pub use diagonal::*;
4444
pub use eigh::*;
45-
// pub use generate::*;
45+
pub use generate::*;
4646
pub use layout::*;
4747
pub use norm::*;
4848
pub use operator::*;

src/solve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ where
438438
Ok(fac) => fac.sln_det(),
439439
Err(LinalgError::Lapack { return_code }) if return_code > 0 => {
440440
// The determinant is zero.
441-
Ok((A::zero(), A::Real::NEG_INFINITY))
441+
Ok((A::zero(), A::Real::neg_infinity()))
442442
}
443443
Err(err) => Err(err),
444444
}
@@ -456,7 +456,7 @@ where
456456
Ok(fac) => fac.sln_det_into(),
457457
Err(LinalgError::Lapack { return_code }) if return_code > 0 => {
458458
// The determinant is zero.
459-
Ok((A::zero(), A::Real::NEG_INFINITY))
459+
Ok((A::zero(), A::Real::neg_infinity()))
460460
}
461461
Err(err) => Err(err),
462462
}

src/solveh.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ where
416416
Ok(fac) => Ok(fac.sln_deth()),
417417
Err(LinalgError::Lapack { return_code }) if return_code > 0 => {
418418
// Determinant is zero.
419-
Ok((A::Real::zero(), A::Real::NEG_INFINITY))
419+
Ok((A::Real::zero(), A::Real::neg_infinity()))
420420
}
421421
Err(err) => Err(err),
422422
}
@@ -440,7 +440,7 @@ where
440440
Ok(fac) => Ok(fac.sln_deth_into()),
441441
Err(LinalgError::Lapack { return_code }) if return_code > 0 => {
442442
// Determinant is zero.
443-
Ok((A::Real::zero(), A::Real::NEG_INFINITY))
443+
Ok((A::Real::zero(), A::Real::neg_infinity()))
444444
}
445445
Err(err) => Err(err),
446446
}

src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Basic types and their methods for linear algebra
22
33
pub use super::lapack_traits::Lapack;
4-
pub use cauchy::{RealScalar, Scalar};
4+
pub use cauchy::Scalar;
55

66
pub use num_complex::Complex32 as c32;
77
pub use num_complex::Complex64 as c64;

0 commit comments

Comments
 (0)