Skip to content
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

Improve stride copying in generalize a bit #288

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 13 additions & 10 deletions ndarray-linalg/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,21 @@ where
{
// FIXME
// https:/bluss/rust-ndarray/issues/325
let strides: Vec<isize> = a.strides().to_vec();
let new = if a.is_standard_layout() {
ArrayBase::from_shape_vec(a.dim(), a.into_raw_vec()).unwrap()
} else {
ArrayBase::from_shape_vec(a.dim().f(), a.into_raw_vec()).unwrap()
};
//
// copy strides
let mut strides = D::zeros(a.ndim());
for (index, &s) in a.strides().iter().enumerate() {
strides[index] = s as usize;
}
let a_dim = a.raw_dim();
let a_len = a.len();
let data = a.into_raw_vec();
assert_eq!(
new.strides(),
strides.as_slice(),
"Custom stride is not supported"
a_len,
data.len(),
"generalize: non-contig arrays are not supported"
);
new
ArrayBase::from_shape_vec(a_dim.strides(strides), data).unwrap()
}

/// Fills in the remainder of a Hermitian matrix that's represented by only one
Expand Down