Skip to content

Commit bf5ab89

Browse files
stefan-kjturner314
authored andcommitted
Update ndarray to version 0.13 (#172)
* Update ndarray to version 0.13 * Apply suggestions from code review Co-Authored-By: Jim Turner <github@turner.link> * revert back to &mut *a in azip! macros of krylov/mgs.rs
1 parent 2bc490f commit bf5ab89

File tree

14 files changed

+33
-44
lines changed

14 files changed

+33
-44
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ num-complex = "0.2.1"
3030
rand = "0.5"
3131

3232
[dependencies.ndarray]
33-
version = "0.12"
33+
version = "0.13"
3434
features = ["blas"]
3535
default-features = false
3636

src/convert.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,14 @@ where
113113
assert!(a.is_square());
114114
match uplo {
115115
UPLO::Upper => {
116-
for row in 0..a.rows() {
116+
for row in 0..a.nrows() {
117117
for col in 0..row {
118118
a[(row, col)] = a[(col, row)].conj();
119119
}
120120
}
121121
}
122122
UPLO::Lower => {
123-
for col in 0..a.cols() {
123+
for col in 0..a.ncols() {
124124
for row in 0..col {
125125
a[(row, col)] = a[(col, row)].conj();
126126
}

src/eigh.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::layout::*;
88
use crate::operator::LinearOperator;
99
use crate::types::*;
1010
use crate::UPLO;
11+
use std::iter::FromIterator;
1112

1213
/// Eigenvalue decomposition of Hermite matrix reference
1314
pub trait Eigh {
@@ -70,7 +71,7 @@ where
7071
MatrixLayout::F(_) => {}
7172
}
7273
let s = unsafe { A::eigh(true, self.square_layout()?, uplo, self.as_allocated_mut()?)? };
73-
Ok((ArrayBase::from_vec(s), self))
74+
Ok((ArrayBase::from(s), self))
7475
}
7576
}
7677

@@ -126,7 +127,7 @@ where
126127

127128
fn eigvalsh_inplace(&mut self, uplo: UPLO) -> Result<Self::EigVal> {
128129
let s = unsafe { A::eigh(true, self.square_layout()?, uplo, self.as_allocated_mut()?)? };
129-
Ok(ArrayBase::from_vec(s))
130+
Ok(ArrayBase::from(s))
130131
}
131132
}
132133

@@ -164,7 +165,7 @@ where
164165

165166
fn ssqrt_into(self, uplo: UPLO) -> Result<Self::Output> {
166167
let (e, v) = self.eigh_into(uplo)?;
167-
let e_sqrt = Array1::from_iter(e.iter().map(|r| Scalar::from_real(r.sqrt())));
168+
let e_sqrt = Array::from_iter(e.iter().map(|r| Scalar::from_real(r.sqrt())));
168169
let ev = e_sqrt.into_diagonal().apply2(&v.t());
169170
Ok(v.apply2(&ev))
170171
}

src/krylov/arnoldi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ where
3838
assert!(ortho.tolerance() < One::one());
3939
// normalize before append because |v| may be smaller than ortho.tolerance()
4040
let norm = v.norm_l2();
41-
azip!(mut v(&mut v) in { *v = v.div_real(norm) });
41+
azip!((v in &mut v) *v = v.div_real(norm));
4242
ortho.append(v.view());
4343
Arnoldi {
4444
a,
@@ -82,7 +82,7 @@ where
8282
self.a.apply_mut(&mut self.v);
8383
let result = self.ortho.div_append(&mut self.v);
8484
let norm = self.v.norm_l2();
85-
azip!(mut v(&mut self.v) in { *v = v.div_real(norm) });
85+
azip!((v in &mut self.v) *v = v.div_real(norm));
8686
match result {
8787
AppendResult::Added(coef) => {
8888
self.h.push(coef.clone());

src/krylov/householder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ where
1818
let alpha = -x[0].mul_real(norm / x[0].abs());
1919
x[0] -= alpha;
2020
let inv_rev_norm = A::Real::one() / x.norm_l2();
21-
azip!(mut a(x) in { *a = a.mul_real(inv_rev_norm)});
21+
azip!((a in x) *a = a.mul_real(inv_rev_norm));
2222
}
2323

2424
/// Take a reflection `P = I - 2ww^T`
@@ -107,7 +107,7 @@ impl<A: Scalar + Lapack> Householder<A> {
107107
let k = self.len();
108108
let res = a.slice(s![k..]).norm_l2();
109109
let mut c = Array1::zeros(k + 1);
110-
azip!(mut c(c.slice_mut(s![..k])), a(a.slice(s![..k])) in { *c = a });
110+
azip!((c in c.slice_mut(s![..k]), &a in a.slice(s![..k])) *c = a);
111111
if k < a.len() {
112112
let ak = a[k];
113113
c[k] = -ak.mul_real(res / ak.abs());
@@ -123,7 +123,7 @@ impl<A: Scalar + Lapack> Householder<A> {
123123
S: DataMut<Elem = A>,
124124
{
125125
let k = self.len();
126-
azip!(mut a( a.slice_mut(s![..k])) in { *a = A::zero() });
126+
azip!((a in a.slice_mut(s![..k])) *a = A::zero());
127127
self.backward_reflection(a);
128128
}
129129
}

src/krylov/mgs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<A: Scalar + Lapack> Orthogonalizer for MGS<A> {
5151
for i in 0..self.len() {
5252
let q = &self.q[i];
5353
let c = q.inner(&a);
54-
azip!(mut a (&mut *a), q (q) in { *a = *a - c * q } );
54+
azip!((a in &mut *a, &q in q) *a = *a - c * q);
5555
coef[i] = c;
5656
}
5757
let nrm = a.norm_l2();
@@ -88,7 +88,7 @@ impl<A: Scalar + Lapack> Orthogonalizer for MGS<A> {
8888
// Linearly dependent
8989
return AppendResult::Dependent(coef);
9090
}
91-
azip!(mut a(&mut *a) in { *a = *a / A::from_real(nrm) });
91+
azip!((a in &mut *a) *a = *a / A::from_real(nrm));
9292
self.q.push(a.to_owned());
9393
AppendResult::Added(coef)
9494
}

src/layout.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ where
9696
let shape = self.shape();
9797
let strides = self.strides();
9898
if shape[0] == strides[1] as usize {
99-
return Ok(MatrixLayout::F((self.cols() as i32, self.rows() as i32)));
99+
return Ok(MatrixLayout::F((self.ncols() as i32, self.nrows() as i32)));
100100
}
101101
if shape[1] == strides[0] as usize {
102-
return Ok(MatrixLayout::C((self.rows() as i32, self.cols() as i32)));
102+
return Ok(MatrixLayout::C((self.nrows() as i32, self.ncols() as i32)));
103103
}
104104
Err(LinalgError::InvalidStride {
105105
s0: strides[0],
@@ -122,8 +122,8 @@ where
122122
Ok(())
123123
} else {
124124
Err(LinalgError::NotSquare {
125-
rows: self.rows() as i32,
126-
cols: self.cols() as i32,
125+
rows: self.nrows() as i32,
126+
cols: self.ncols() as i32,
127127
})
128128
}
129129
}

src/operator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub trait LinearOperator {
2525
S: DataMut<Elem = Self::Elem>,
2626
{
2727
let b = self.apply(a);
28-
azip!(mut a(a), b in { *a = b });
28+
azip!((a in a, &b in &b) *a = b);
2929
}
3030

3131
/// Apply operator with move

src/qr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ where
103103
type R = Array2<A>;
104104

105105
fn qr_into(mut self) -> Result<(Self::Q, Self::R)> {
106-
let n = self.rows();
107-
let m = self.cols();
106+
let n = self.nrows();
107+
let m = self.ncols();
108108
let k = ::std::cmp::min(n, m);
109109
let l = self.layout()?;
110110
let r = unsafe { A::qr(l, self.as_allocated_mut()?)? };

src/solveh.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ where
309309
let mut ln_det = A::Real::zero();
310310
let mut ipiv_enum = ipiv_iter.enumerate();
311311
while let Some((k, ipiv_k)) = ipiv_enum.next() {
312-
debug_assert!(k < a.rows() && k < a.cols());
312+
debug_assert!(k < a.nrows() && k < a.ncols());
313313
if ipiv_k > 0 {
314314
// 1x1 block at k, must be real.
315315
let elem = unsafe { a.uget((k, k)) }.re();

0 commit comments

Comments
 (0)