Closed
Description
Hey folks,
I'm struggling to find a way to call slice() on a dynamic ranked array, and can find a way to make it work.
extern crate ndarray;
use ndarray::*;
fn main() {
let array: ArrayD<f32> = Array::zeros(vec![8, 8, 8]);
foo(&array.view());
}
fn foo<'a>(a: &'a ArrayViewD<'a, f32>) -> ArrayViewD<'a, f32> {
let slicer: Vec<SliceOrIndex> = (0..a.ndim())
.map(|_| SliceOrIndex::Slice {
start: 2,
end: Some(6),
step: 1,
}).collect();
let slice = SliceInfo::new(slicer).unwrap();
a.slice(slice)
}
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 ?
Metadata
Metadata
Assignees
Labels
No labels