Open RReverser opened 1 year ago
For the example above for now found a workaround like this but it's pretty ugly compared to what it could be:
IterSerialize(
(0..self.data.len_of(ndarray::Axis(0))).map(move |column_i| {
IterSerialize((0..self.data.len_of(ndarray::Axis(1))).map(move |row_i| {
self.data
.slice(ndarray::s![column_i, row_i, ..])
.to_slice()
.unwrap()
}))
}),
)
Currently,
ArrayView
has a helpful lifetime-preserving methods liketo_slice
, but no way to preserve lifetimes of iterators likeaxis_iter
,outer_iter
and such.This makes it difficult to return iterables from helper functions like this:
I suggest there should be overrides like
into_outer_iter
,into_axis_iter
etc. onArrayView
that would return iterators tied by the lifetime to the original data instead of theArrayView
itself.Note: while looking for open issues, the only relevant I found was https://github.com/rust-ndarray/ndarray/issues/320, but there the author could afford to just reshape / flatten the data; that might not always be possible, like in my example above. @bluss mentioned issues and suggestions similar to what I'm describing here though: https://github.com/rust-ndarray/ndarray/issues/320#issuecomment-306875751