Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bf5ab89

Browse files
stefan-kjturner314
authored andcommittedOct 9, 2019
Update ndarray to version 0.13 (#172)
* Update ndarray to version 0.13 * Apply suggestions from code review Co-Authored-By: Jim Turner <[email protected]> * 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();

‎src/svd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ where
8181
let vt = svd_res
8282
.vt
8383
.map(|vt| into_matrix(l.resized(m, m), vt).expect("Size of VT mismatches"));
84-
let s = ArrayBase::from_vec(svd_res.s);
84+
let s = ArrayBase::from(svd_res.s);
8585
Ok((u, s, vt))
8686
}
8787
}

‎src/svddc.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,15 @@ pub trait SVDDCInto {
2828
type U;
2929
type VT;
3030
type Sigma;
31-
fn svddc_into(
32-
self,
33-
uvt_flag: UVTFlag,
34-
) -> Result<(Option<Self::U>, Self::Sigma, Option<Self::VT>)>;
31+
fn svddc_into(self, uvt_flag: UVTFlag) -> Result<(Option<Self::U>, Self::Sigma, Option<Self::VT>)>;
3532
}
3633

3734
/// Singular-value decomposition of matrix reference by divide-and-conquer
3835
pub trait SVDDCInplace {
3936
type U;
4037
type VT;
4138
type Sigma;
42-
fn svddc_inplace(
43-
&mut self,
44-
uvt_flag: UVTFlag,
45-
) -> Result<(Option<Self::U>, Self::Sigma, Option<Self::VT>)>;
39+
fn svddc_inplace(&mut self, uvt_flag: UVTFlag) -> Result<(Option<Self::U>, Self::Sigma, Option<Self::VT>)>;
4640
}
4741

4842
impl<A, S> SVDDC for ArrayBase<S, Ix2>
@@ -68,10 +62,7 @@ where
6862
type VT = Array2<A>;
6963
type Sigma = Array1<A::Real>;
7064

71-
fn svddc_into(
72-
mut self,
73-
uvt_flag: UVTFlag,
74-
) -> Result<(Option<Self::U>, Self::Sigma, Option<Self::VT>)> {
65+
fn svddc_into(mut self, uvt_flag: UVTFlag) -> Result<(Option<Self::U>, Self::Sigma, Option<Self::VT>)> {
7566
self.svddc_inplace(uvt_flag)
7667
}
7768
}
@@ -85,10 +76,7 @@ where
8576
type VT = Array2<A>;
8677
type Sigma = Array1<A::Real>;
8778

88-
fn svddc_inplace(
89-
&mut self,
90-
uvt_flag: UVTFlag,
91-
) -> Result<(Option<Self::U>, Self::Sigma, Option<Self::VT>)> {
79+
fn svddc_inplace(&mut self, uvt_flag: UVTFlag) -> Result<(Option<Self::U>, Self::Sigma, Option<Self::VT>)> {
9280
let l = self.layout()?;
9381
let svd_res = unsafe { A::svddc(l, uvt_flag, self.as_allocated_mut()?)? };
9482
let (m, n) = l.size();
@@ -104,7 +92,7 @@ where
10492
let vt = svd_res
10593
.vt
10694
.map(|vt| into_matrix(l.resized(ldvt, tdvt), vt).expect("Size of VT mismatches"));
107-
let s = ArrayBase::from_vec(svd_res.s);
95+
let s = ArrayBase::from(svd_res.s);
10896
Ok((u, s, vt))
10997
}
11098
}

‎tests/det.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ where
88
A: Scalar,
99
S: Data<Elem = A>,
1010
{
11-
let mut select_rows = (0..a.rows()).collect::<Vec<_>>();
11+
let mut select_rows = (0..a.nrows()).collect::<Vec<_>>();
1212
select_rows.remove(row);
13-
let mut select_cols = (0..a.cols()).collect::<Vec<_>>();
13+
let mut select_cols = (0..a.ncols()).collect::<Vec<_>>();
1414
select_cols.remove(col);
1515
a.select(Axis(0), &select_rows).select(Axis(1), &select_cols)
1616
}
@@ -24,8 +24,8 @@ where
2424
A: Scalar,
2525
S: Data<Elem = A>,
2626
{
27-
assert_eq!(a.rows(), a.cols());
28-
match a.cols() {
27+
assert_eq!(a.nrows(), a.ncols());
28+
match a.ncols() {
2929
0 => A::one(),
3030
1 => a[(0, 0)],
3131
cols => (0..cols)

‎tests/triangular.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn test2d<A, Sa, Sb>(uplo: UPLO, a: &ArrayBase<Sa, Ix2>, b: &ArrayBase<Sb, Ix2>,
2020
where
2121
A: Scalar + Lapack,
2222
Sa: Data<Elem = A>,
23-
Sb: DataMut<Elem = A> + DataOwned + DataClone,
23+
Sb: DataMut<Elem = A> + DataOwned + Data + RawDataClone,
2424
{
2525
println!("a = {:?}", a);
2626
println!("b = {:?}", b);

0 commit comments

Comments
 (0)
Please sign in to comment.