Hi everybody,
I am using ArrayD from the ndarray crate. Sometime I need to cast to a normal Array with a fix dimension therefore I need to use the into_dimensionality method. However this function can't be call from a reference, thus neither from a function with a reference, which is inconvenient because when working with array with generally want to pass reference rather than by copy.
Here is the code that don't work and I don't understand why:
use ndarray::{ArrayD,Ix1};
fn main(
)
{
println!("Testing some code :°)");
let a = ArrayD::<f64>::zeros(IxDyn(&[1]));
let b = a.into_dimensionality::<Ix1>().unwrap(); // every thing fine here
let ref x = ArrayD::<f64>::zeros(IxDyn(&[1]));
let y = x.into_dimensionality::<Ix1>().unwrap(); // it fails here
}
with the following error message:
error[E0507]: cannot move out of `*x` which is behind a shared reference
--> src/main.rs:18:12
|
18 | let y = x.into_dimensionality::<Ix1>().unwrap();
| ^ move occurs because `*x` has type `ArrayBase<OwnedRepr<f64>, Dim<IxDynImpl>>`, which does not implement the `Copy` trait
This behavior seems not to be documented anywhere, is it a bug ? Or is there an other way apply this method from a reference ?
Thanks in advance