Skip to content

Commit 5be2ed2

Browse files
committed
Use cauchy::Scalar
1 parent 32e56e0 commit 5be2ed2

File tree

19 files changed

+119
-434
lines changed

19 files changed

+119
-434
lines changed

src/assert.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn close_max<A, S1, S2, D>(
3232
atol: A::Real,
3333
) -> Result<A::Real, A::Real>
3434
where
35-
A: Scalar,
35+
A: Scalar + Lapack,
3636
S1: Data<Elem = A>,
3737
S2: Data<Elem = A>,
3838
D: Dimension,
@@ -52,7 +52,7 @@ pub fn close_l1<A, S1, S2, D>(
5252
rtol: A::Real,
5353
) -> Result<A::Real, A::Real>
5454
where
55-
A: Scalar,
55+
A: Scalar + Lapack,
5656
S1: Data<Elem = A>,
5757
S2: Data<Elem = A>,
5858
D: Dimension,
@@ -72,7 +72,7 @@ pub fn close_l2<A, S1, S2, D>(
7272
rtol: A::Real,
7373
) -> Result<A::Real, A::Real>
7474
where
75-
A: Scalar,
75+
A: Scalar + Lapack,
7676
S1: Data<Elem = A>,
7777
S2: Data<Elem = A>,
7878
D: Dimension,

src/cholesky.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub struct CholeskyFactorized<S: Data> {
6666

6767
impl<A, S> CholeskyFactorized<S>
6868
where
69-
A: Scalar,
69+
A: Scalar + Lapack,
7070
S: DataMut<Elem = A>,
7171
{
7272
/// Returns `L` from the Cholesky decomposition `A = L * L^H`.
@@ -96,10 +96,10 @@ where
9696

9797
impl<A, S> DeterminantC for CholeskyFactorized<S>
9898
where
99-
A: Absolute,
99+
A: Scalar + Lapack,
100100
S: Data<Elem = A>,
101101
{
102-
type Output = <A as AssociatedReal>::Real;
102+
type Output = <A as Scalar>::Real;
103103

104104
fn detc(&self) -> Self::Output {
105105
self.ln_detc().exp()
@@ -109,17 +109,17 @@ where
109109
self.factor
110110
.diag()
111111
.iter()
112-
.map(|elem| elem.abs_sqr().ln())
112+
.map(|elem| elem.square().ln())
113113
.sum::<Self::Output>()
114114
}
115115
}
116116

117117
impl<A, S> DeterminantCInto for CholeskyFactorized<S>
118118
where
119-
A: Absolute,
119+
A: Scalar + Lapack,
120120
S: Data<Elem = A>,
121121
{
122-
type Output = <A as AssociatedReal>::Real;
122+
type Output = <A as Scalar>::Real;
123123

124124
fn detc_into(self) -> Self::Output {
125125
self.detc()
@@ -132,7 +132,7 @@ where
132132

133133
impl<A, S> InverseC for CholeskyFactorized<S>
134134
where
135-
A: Scalar,
135+
A: Scalar + Lapack,
136136
S: Data<Elem = A>,
137137
{
138138
type Output = Array2<A>;
@@ -148,7 +148,7 @@ where
148148

149149
impl<A, S> InverseCInto for CholeskyFactorized<S>
150150
where
151-
A: Scalar,
151+
A: Scalar + Lapack,
152152
S: DataMut<Elem = A>,
153153
{
154154
type Output = ArrayBase<S, Ix2>;
@@ -163,7 +163,7 @@ where
163163

164164
impl<A, S> SolveC<A> for CholeskyFactorized<S>
165165
where
166-
A: Scalar,
166+
A: Scalar + Lapack,
167167
S: Data<Elem = A>,
168168
{
169169
fn solvec_inplace<'a, Sb>(&self, b: &'a mut ArrayBase<Sb, Ix1>) -> Result<&'a mut ArrayBase<Sb, Ix1>>
@@ -226,7 +226,7 @@ pub trait CholeskyInplace {
226226

227227
impl<A, S> Cholesky for ArrayBase<S, Ix2>
228228
where
229-
A: Scalar,
229+
A: Scalar + Lapack,
230230
S: Data<Elem = A>,
231231
{
232232
type Output = Array2<A>;
@@ -239,7 +239,7 @@ where
239239

240240
impl<A, S> CholeskyInto for ArrayBase<S, Ix2>
241241
where
242-
A: Scalar,
242+
A: Scalar + Lapack,
243243
S: DataMut<Elem = A>,
244244
{
245245
type Output = Self;
@@ -252,7 +252,7 @@ where
252252

253253
impl<A, S> CholeskyInplace for ArrayBase<S, Ix2>
254254
where
255-
A: Scalar,
255+
A: Scalar + Lapack,
256256
S: DataMut<Elem = A>,
257257
{
258258
fn cholesky_inplace(&mut self, uplo: UPLO) -> Result<&mut Self> {
@@ -289,7 +289,7 @@ pub trait FactorizeCInto<S: Data> {
289289

290290
impl<A, S> FactorizeCInto<S> for ArrayBase<S, Ix2>
291291
where
292-
A: Scalar,
292+
A: Scalar + Lapack,
293293
S: DataMut<Elem = A>,
294294
{
295295
fn factorizec_into(self, uplo: UPLO) -> Result<CholeskyFactorized<S>> {
@@ -302,7 +302,7 @@ where
302302

303303
impl<A, Si> FactorizeC<OwnedRepr<A>> for ArrayBase<Si, Ix2>
304304
where
305-
A: Scalar,
305+
A: Scalar + Lapack,
306306
Si: Data<Elem = A>,
307307
{
308308
fn factorizec(&self, uplo: UPLO) -> Result<CholeskyFactorized<OwnedRepr<A>>> {
@@ -343,7 +343,7 @@ pub trait SolveC<A: Scalar> {
343343

344344
impl<A, S> SolveC<A> for ArrayBase<S, Ix2>
345345
where
346-
A: Scalar,
346+
A: Scalar + Lapack,
347347
S: Data<Elem = A>,
348348
{
349349
fn solvec_inplace<'a, Sb>(&self, b: &'a mut ArrayBase<Sb, Ix1>) -> Result<&'a mut ArrayBase<Sb, Ix1>>
@@ -372,7 +372,7 @@ pub trait InverseCInto {
372372

373373
impl<A, S> InverseC for ArrayBase<S, Ix2>
374374
where
375-
A: Scalar,
375+
A: Scalar + Lapack,
376376
S: Data<Elem = A>,
377377
{
378378
type Output = Array2<A>;
@@ -384,7 +384,7 @@ where
384384

385385
impl<A, S> InverseCInto for ArrayBase<S, Ix2>
386386
where
387-
A: Scalar,
387+
A: Scalar + Lapack,
388388
S: DataMut<Elem = A>,
389389
{
390390
type Output = Self;
@@ -430,10 +430,10 @@ pub trait DeterminantCInto {
430430

431431
impl<A, S> DeterminantC for ArrayBase<S, Ix2>
432432
where
433-
A: Scalar,
433+
A: Scalar + Lapack,
434434
S: Data<Elem = A>,
435435
{
436-
type Output = Result<<A as AssociatedReal>::Real>;
436+
type Output = Result<<A as Scalar>::Real>;
437437

438438
fn detc(&self) -> Self::Output {
439439
Ok(self.ln_detc()?.exp())
@@ -446,10 +446,10 @@ where
446446

447447
impl<A, S> DeterminantCInto for ArrayBase<S, Ix2>
448448
where
449-
A: Scalar,
449+
A: Scalar + Lapack,
450450
S: DataMut<Elem = A>,
451451
{
452-
type Output = Result<<A as AssociatedReal>::Real>;
452+
type Output = Result<<A as Scalar>::Real>;
453453

454454
fn detc_into(self) -> Self::Output {
455455
Ok(self.ln_detc_into()?.exp())

src/convert.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use ndarray::*;
55
use super::error::*;
66
use super::lapack_traits::UPLO;
77
use super::layout::*;
8-
use super::types::Conjugate;
8+
use super::types::*;
99

1010
pub fn into_col<S>(a: ArrayBase<S, Ix1>) -> ArrayBase<S, Ix2>
1111
where
@@ -107,7 +107,7 @@ where
107107
/// ***Panics*** if `a` is not square.
108108
pub(crate) fn triangular_fill_hermitian<A, S>(a: &mut ArrayBase<S, Ix2>, uplo: UPLO)
109109
where
110-
A: Conjugate,
110+
A: Scalar + Lapack,
111111
S: DataMut<Elem = A>,
112112
{
113113
assert!(a.is_square());

src/eigh.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub trait EighInto: Sized {
3030

3131
impl<A, S> EighInto for ArrayBase<S, Ix2>
3232
where
33-
A: Scalar,
33+
A: Scalar + Lapack,
3434
S: DataMut<Elem = A>,
3535
{
3636
type EigVal = Array1<A::Real>;
@@ -43,7 +43,7 @@ where
4343

4444
impl<A, S> Eigh for ArrayBase<S, Ix2>
4545
where
46-
A: Scalar,
46+
A: Scalar + Lapack,
4747
S: Data<Elem = A>,
4848
{
4949
type EigVal = Array1<A::Real>;
@@ -57,7 +57,7 @@ where
5757

5858
impl<A, S> EighInplace for ArrayBase<S, Ix2>
5959
where
60-
A: Scalar,
60+
A: Scalar + Lapack,
6161
S: DataMut<Elem = A>,
6262
{
6363
type EigVal = Array1<A::Real>;
@@ -88,7 +88,7 @@ pub trait EigValshInplace {
8888

8989
impl<A, S> EigValshInto for ArrayBase<S, Ix2>
9090
where
91-
A: Scalar,
91+
A: Scalar + Lapack,
9292
S: DataMut<Elem = A>,
9393
{
9494
type EigVal = Array1<A::Real>;
@@ -100,7 +100,7 @@ where
100100

101101
impl<A, S> EigValsh for ArrayBase<S, Ix2>
102102
where
103-
A: Scalar,
103+
A: Scalar + Lapack,
104104
S: Data<Elem = A>,
105105
{
106106
type EigVal = Array1<A::Real>;
@@ -113,7 +113,7 @@ where
113113

114114
impl<A, S> EigValshInplace for ArrayBase<S, Ix2>
115115
where
116-
A: Scalar,
116+
A: Scalar + Lapack,
117117
S: DataMut<Elem = A>,
118118
{
119119
type EigVal = Array1<A::Real>;
@@ -132,7 +132,7 @@ pub trait SymmetricSqrt {
132132

133133
impl<A, S> SymmetricSqrt for ArrayBase<S, Ix2>
134134
where
135-
A: Scalar,
135+
A: Scalar + Lapack,
136136
S: Data<Elem = A>,
137137
{
138138
type Output = Array2<A>;
@@ -151,14 +151,14 @@ pub trait SymmetricSqrtInto {
151151

152152
impl<A, S> SymmetricSqrtInto for ArrayBase<S, Ix2>
153153
where
154-
A: Scalar,
154+
A: Scalar + Lapack,
155155
S: DataMut<Elem = A> + DataOwned,
156156
{
157157
type Output = Array2<A>;
158158

159159
fn ssqrt_into(self, uplo: UPLO) -> Result<Self::Output> {
160160
let (e, v) = self.eigh_into(uplo)?;
161-
let e_sqrt = Array1::from_iter(e.iter().map(|r| AssociatedReal::inject(r.sqrt())));
161+
let e_sqrt = Array1::from_iter(e.iter().map(|r| Scalar::from_real(r.sqrt())));
162162
let ev = e_sqrt.into_diagonal().op(&v.t());
163163
Ok(v.op(&ev))
164164
}

src/generate.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ use super::types::*;
1111
/// Hermite conjugate matrix
1212
pub fn conjugate<A, Si, So>(a: &ArrayBase<Si, Ix2>) -> ArrayBase<So, Ix2>
1313
where
14-
A: Conjugate,
14+
A: Scalar + Lapack
1515
Si: Data<Elem = A>,
1616
So: DataOwned<Elem = A> + DataMut,
1717
{
1818
let mut a = replicate(&a.t());
1919
for val in a.iter_mut() {
20-
*val = Conjugate::conj(*val);
20+
*val = Scalar::conj(*val);
2121
}
2222
a
2323
}
@@ -37,14 +37,14 @@ where
3737
/// Random Hermite matrix
3838
pub fn random_hermite<A, S>(n: usize) -> ArrayBase<S, Ix2>
3939
where
40-
A: RandNormal + Conjugate + Add<Output = A>,
40+
A: RandNormal + Scalar + Add<Output = A>,
4141
S: DataOwned<Elem = A> + DataMut,
4242
{
4343
let mut a = random((n, n));
4444
for i in 0..n {
45-
a[(i, i)] = a[(i, i)] + Conjugate::conj(a[(i, i)]);
45+
a[(i, i)] = a[(i, i)] + Scalar::conj(a[(i, i)]);
4646
for j in (i + 1)..n {
47-
a[(i, j)] = Conjugate::conj(a[(j, i)])
47+
a[(i, j)] = Scalar::conj(a[(j, i)])
4848
}
4949
}
5050
a
@@ -56,7 +56,7 @@ where
5656
///
5757
pub fn random_hpd<A, S>(n: usize) -> ArrayBase<S, Ix2>
5858
where
59-
A: RandNormal + Conjugate + LinalgScalar,
59+
A: RandNormal + Scalar + LinalgScalar,
6060
S: DataOwned<Elem = A> + DataMut,
6161
{
6262
let a: Array2<A> = random((n, n));

src/lapack_traits/eigh.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::types::*;
1010
use super::{into_result, UPLO};
1111

1212
/// Wraps `*syev` for real and `*heev` for complex
13-
pub trait Eigh_: AssociatedReal {
13+
pub trait Eigh_: Scalar {
1414
unsafe fn eigh(calc_eigenvec: bool, l: MatrixLayout, uplo: UPLO, a: &mut [Self]) -> Result<Vec<Self::Real>>;
1515
}
1616

src/lapack_traits/opnorm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::types::*;
88

99
pub use super::NormType;
1010

11-
pub trait OperatorNorm_: AssociatedReal {
11+
pub trait OperatorNorm_: Scalar {
1212
unsafe fn opnorm(t: NormType, l: MatrixLayout, a: &[Self]) -> Self::Real;
1313
}
1414

src/lapack_traits/solve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use super::NormType;
1111
use super::{into_result, Pivot, Transpose};
1212

1313
/// Wraps `*getrf`, `*getri`, and `*getrs`
14-
pub trait Solve_: AssociatedReal + Sized {
14+
pub trait Solve_: Scalar + Sized {
1515
/// Computes the LU factorization of a general `m x n` matrix `a` using
1616
/// partial pivoting with row interchanges.
1717
///

src/lapack_traits/svd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ enum FlagSVD {
1818
}
1919

2020
/// Result of SVD
21-
pub struct SVDOutput<A: AssociatedReal> {
21+
pub struct SVDOutput<A: Scalar> {
2222
/// diagonal values
2323
pub s: Vec<A::Real>,
2424
/// Unitary matrix for destination space
@@ -28,7 +28,7 @@ pub struct SVDOutput<A: AssociatedReal> {
2828
}
2929

3030
/// Wraps `*gesvd`
31-
pub trait SVD_: AssociatedReal {
31+
pub trait SVD_: Scalar {
3232
unsafe fn svd(l: MatrixLayout, calc_u: bool, calc_vt: bool, a: &mut [Self]) -> Result<SVDOutput<Self>>;
3333
}
3434

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::*;

0 commit comments

Comments
 (0)