Open jimy-byerley opened 3 years ago
That's interesting. It works using a function with explicit lifetime annotations instead of a closure:
fn scan<'a, T>(last: ArrayViewMutD<'a, T>, mut current: ArrayViewMutD<'a, T>) -> ArrayViewMutD<'a, T> {
Zip::from(last).and(&mut current).for_each(|l, c| {
*c = // do stuff
});
current
};
array.axis_iter_mut(Axis(i)).reduce(scan);
At first glance, I'm not sure how to achieve the same thing with a closure, since, AFAIK, there's no way to declare explicit lifetime annotations for a closure.
Anyway, for this application, I'd suggest the accumulate_axis_inplace
method.
Hello, that's me again. I apologize for my likely dump questions.
I'm in a situation where I want to process an array slice by slice, where each slice is computed in term of the previous. And my issue is that I cannot achieve this using
.reduce
instead of a for-loop.This works:
But the following doesn't work, though it should be more idiomatic:
compiler output is
I suspect this comes from the fact axis_iter doesn't provide elements with lifetime
'a
(same as the original array) but instead provide an anonymous lifetime'_
? Not a big issue in my program since I found the first code sample to avoid my issue, but I'm curious :)Thanks in advance