Skip to content

Bump ndarray version to 0.14 #258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions ndarray-linalg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ rand = "0.5"
thiserror = "1.0.20"

[dependencies.ndarray]
version = "0.13.0"
version = "0.14"
features = ["blas", "approx"]
default-features = false

Expand All @@ -46,9 +46,10 @@ path = "../lax"
default-features = false

[dev-dependencies]
paste = "0.1.9"
criterion = "0.3.1"
approx = { version = "0.3.2", features = ["num-complex"] }
paste = "1.0"
criterion = "0.3"
# Keep the same version as ndarray's dependency!
approx = { version = "0.4", features = ["num-complex"] }

[[bench]]
name = "truncated_eig"
Expand Down
20 changes: 4 additions & 16 deletions ndarray-linalg/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,8 @@ where
A: Scalar,
S: Data<Elem = A>,
{
let views: Vec<_> = xs
.iter()
.map(|x| {
let n = x.len();
x.view().into_shape((n, 1)).unwrap()
})
.collect();
stack(Axis(1), &views).map_err(|e| e.into())
let views: Vec<_> = xs.iter().map(|x| x.view()).collect();
stack(Axis(1), &views).map_err(Into::into)
}

/// stack vectors into matrix vertically
Expand All @@ -126,12 +120,6 @@ where
A: Scalar,
S: Data<Elem = A>,
{
let views: Vec<_> = xs
.iter()
.map(|x| {
let n = x.len();
x.view().into_shape((1, n)).unwrap()
})
.collect();
stack(Axis(0), &views).map_err(|e| e.into())
let views: Vec<_> = xs.iter().map(|x| x.view()).collect();
stack(Axis(0), &views).map_err(Into::into)
}
5 changes: 2 additions & 3 deletions ndarray-linalg/src/lobpcg/eig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,11 @@ impl<A: Float + Scalar + ScalarOperand + Lapack + PartialOrd + Default> Iterator

// add the new eigenvector to the internal constrain matrix
let new_constraints = if let Some(ref constraints) = self.eig.constraints {
let eigvecs_arr = constraints
let eigvecs_arr: Vec<_> = constraints
.gencolumns()
.into_iter()
.chain(vecs.gencolumns().into_iter())
.map(|x| x.insert_axis(Axis(1)))
.collect::<Vec<_>>();
.collect();

stack(Axis(1), &eigvecs_arr).unwrap()
} else {
Expand Down
28 changes: 14 additions & 14 deletions ndarray-linalg/src/lobpcg/lobpcg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,17 +354,17 @@ pub fn lobpcg<
};

sorted_eig(
stack![
concatenate![
Axis(0),
stack![Axis(1), xax, xar, xap],
stack![Axis(1), xar.t(), rar, rap],
stack![Axis(1), xap.t(), rap.t(), pap]
concatenate![Axis(1), xax, xar, xap],
concatenate![Axis(1), xar.t(), rar, rap],
concatenate![Axis(1), xap.t(), rap.t(), pap]
],
Some(stack![
Some(concatenate![
Axis(0),
stack![Axis(1), xx, xr, xp],
stack![Axis(1), xr.t(), rr, rp],
stack![Axis(1), xp.t(), rp.t(), pp]
concatenate![Axis(1), xx, xr, xp],
concatenate![Axis(1), xr.t(), rr, rp],
concatenate![Axis(1), xp.t(), rp.t(), pp]
]),
size_x,
&order,
Expand All @@ -374,15 +374,15 @@ pub fn lobpcg<
p_ap = None;

sorted_eig(
stack![
concatenate![
Axis(0),
stack![Axis(1), xax, xar],
stack![Axis(1), xar.t(), rar]
concatenate![Axis(1), xax, xar],
concatenate![Axis(1), xar.t(), rar]
],
Some(stack![
Some(concatenate![
Axis(0),
stack![Axis(1), xx, xr],
stack![Axis(1), xr.t(), rr]
concatenate![Axis(1), xx, xr],
concatenate![Axis(1), xr.t(), rr]
]),
size_x,
&order,
Expand Down
24 changes: 7 additions & 17 deletions ndarray-linalg/src/opnorm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use lax::Tridiagonal;
use ndarray::*;

use crate::convert::*;
use crate::error::*;
use crate::layout::*;
use crate::types::*;
Expand Down Expand Up @@ -71,10 +70,9 @@ where
NormType::One => {
let zl: Array1<A> = Array::zeros(1);
let zu: Array1<A> = Array::zeros(1);
let dl = stack![Axis(0), self.dl.to_owned(), zl];
let du = stack![Axis(0), zu, self.du.to_owned()];
let arr = stack![Axis(0), into_row(du), into_row(arr1(&self.d)), into_row(dl)];
arr
let dl = concatenate![Axis(0), &self.dl, zl]; // n
let du = concatenate![Axis(0), zu, &self.du]; // n
stack![Axis(0), du, &self.d, dl] // 3 x n
}
// opnorm_inf() calculates muximum row sum.
// Therefore, This part align the rows and make a (n x 3) matrix like,
Expand All @@ -86,26 +84,18 @@ where
NormType::Infinity => {
let zl: Array1<A> = Array::zeros(1);
let zu: Array1<A> = Array::zeros(1);
let dl = stack![Axis(0), zl, self.dl.to_owned()];
let du = stack![Axis(0), self.du.to_owned(), zu];
let arr = stack![Axis(1), into_col(dl), into_col(arr1(&self.d)), into_col(du)];
arr
let dl = concatenate![Axis(0), zl, &self.dl]; // n
let du = concatenate![Axis(0), &self.du, zu]; // n
stack![Axis(1), dl, &self.d, du] // n x 3
}
// opnorm_fro() calculates square root of sum of squares.
// Because it is independent of the shape of matrix,
// this part make a (1 x (3n-2)) matrix like,
// [l1, ..., l{n-1}, d0, ..., d{n-1}, u1, ..., u{n-1}]
NormType::Frobenius => {
let arr = stack![
Axis(1),
into_row(arr1(&self.dl)),
into_row(arr1(&self.d)),
into_row(arr1(&self.du))
];
arr
concatenate![Axis(0), &self.dl, &self.d, &self.du].insert_axis(Axis(0))
}
};

let l = arr.layout()?;
let a = arr.as_allocated()?;
Ok(A::opnorm(t, l, a))
Expand Down