You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The gist of the issue is the type of the AsRef<[SliceOrIndex]> in (slicer in the example).
|
13 | a.slice(slice)
| ^^^^^ expected reference, found struct `ndarray::SliceInfo`
|
= note: expected type `&ndarray::SliceInfo<[ndarray::SliceOrIndex], ndarray::Dim<ndarray::IxDynImpl>>`
found type `ndarray::SliceInfo<std::vec::Vec<ndarray::SliceOrIndex>, _>`
I can't see how to make the typechecker happy here, and I can't instantiate SliceInfo<[ndarray::SliceOrIndex]> because [ndarray::SliceOrIndex] is not sized. Am I missing something obvious ?
Activity
jturner314 commentedon Oct 11, 2018
The solution is to call
.as_ref()manually onsliceto perform the conversion, like this:This calls this
AsRefimplementation (SliceInfodocs):This is a somewhat ugly part of the API. I have a plan to fix this but haven't gotten around to it yet.
Fwiw, for this particular example, it's simpler to use a series of
.slice_axis()or.slice_axis_inplace()calls, like this:Edit: (Or, if you know the dimension of the array ahead-of-time, you can use the
s![]macro.)kali commentedon Oct 12, 2018
@jturner314 Ha, thanks a lot. for the solution and, and for the slice_axis_inplace tip. Everything is dynamic in my case,
s!is not an option.