rust-ndarray / ndarray

ndarray: an N-dimensional array with array views, multidimensional slicing, and efficient operations

Home Page:https://docs.rs/ndarray/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Callling clone on collapsed array also clones collapsed values

Janmajayamall opened this issue · comments

Callling clone on collapsed array also clones collaposed values. For example,

let mut a = Array2::<u64>::zeros((10, 100));
a.slice_collapse(s![..5, ..]);
// Calling clone on `a` clones all values including from subview `s![5.., ..]`
let b = a.clone();

Is this expected?

commented

In general, yes.

ah, I seem to have landed on a situation where I can't move ownership of type that owns Array2. This means I can't use slice_move.

Is there an alternative that collpases the view and clones only restricted view? Or a way that I can copy only values in collapsed view?

If you want to clone the data, maybe to_owned does what you need? (The docs also list some alternative which give further control over memory layout.)

Yup that's what I need. Thanks!