Description
I am writing a function in which I need to compute the first quartile without modifying the underlying array. I have thus tried to call clone
on the array to get a copy but this stub
fn example<S, T>(a: ArrayBase<S, Ix1>) -> [...]
where
S: Data<Elem=T>,
T: Clone,
{
let first_quartile = a.clone().quantile_axis_mut(0.25, Axis(0));
[...]
}
will not compile:
|
126 | let first_quartile = a.clone().quantile_axis_mut(0.25, Axis(0));
| ^^^^^
|
= note: the method `clone` exists but the following trait bounds were not satisfied:
`ndarray::ArrayBase<S, ndarray::Dim<[usize; 1]>> : std::clone::Clone`
I have checked Clone
implementation on ArrayBase
(here) and it turns out that there is a bound on the Data
associated type: it needs to implement the DataClone
trait (here).
DataClone
is implemented by all Data variants in ndarray
apart from ViewRepr<&'a mut A>
- why is that? Is there a deep reason or is it simply something that was never needed?
Edit: reading the finer details in the implementation of ViewRepr
and DataClone
it seems to me that implementing DataClone
for ViewRepr<&'a mut A>
might lead to multiple views on the same array with mut
privilege - ViewRepr
doesn't have access to the underlying data, hence we cannot duplicate it as we do for OwnedRepr
, is my understanding correct?