lifetime issues with `axis_iter`
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Start with src/lib.rs around lines 66-85 and the axis_iter_mut(...).reduce(scan) call, then compare it with the manual loop and the ArrayViewMutD/Zip closure. Reproduce the reported compiler error and determine whether this lifetime pattern is supported; done means a documented explanation or a confirmed actionable fix.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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:
// iterate slices
let mut it = array.axis_iter_mut(Axis(i));
let mut last = it.next().unwrap();
for mut current in it {
// compute 'current' slice in term of the previous 'last' slice
Zip::from(last).and(&mut current)
.for_each(|l, c| {
*c = /* some expression in term of `l` */;
});
last = current;
}
But the following doesn't work, though it should be more idiomatic:
// compute 'current' slice in term of the previous 'last' slice
let scan = |last: ArrayViewMutD<T>, mut current: ArrayViewMutD<T>| {
Zip::from(last).and(&mut current)
.for_each(|l, c| {
*c = /* some expression in term of `l` */;
});
current
};
// iterate slices
array.axis_iter_mut(Axis(i)).reduce(scan);
compiler output is
error[E0495]: cannot infer an appropriate lifetime for autoref due to conflicting requirements
--> src/lib.rs:85:10
|
85 | array.axis_iter_mut(Axis(i)).reduce(scan);
| ^^^^^^^^^^^^^
|
note: first, the lifetime cannot outlive the anonymous lifetime defined on the function body at 66:15...
--> src/lib.rs:66:15
|
66 | mut array: ArrayViewMutD<T>,
| ^^^^^^^^^^^^^^^^
note: ...so that the type `ArrayBase<ViewRepr<&mut T>, ndarray::Dim<IxDynImpl>>` is not borrowed for too long
--> src/lib.rs:85:4
|
85 | array.axis_iter_mut(Axis(i)).reduce(scan);
| ^^^^^
note: but, the lifetime must be valid for the anonymous lifetime #2 defined on the body at 76:16...
--> src/lib.rs:76:16
|
76 | let scan = |last: ArrayViewMutD<T>, mut current: ArrayViewMutD<T>| {
| _________________________^
77 | | let incr = ramp[i];
78 | | Zip::from(last).and(&mut current)
79 | | // .into_par_iter()
... |
83 | | current
84 | | };
| |_____________^
note: ...so that the types are compatible
--> src/lib.rs:85:33
|
85 | array.axis_iter_mut(Axis(i)).reduce(scan);
| ^^^^^^
= note: expected `ArrayBase<ViewRepr<&mut T>, _>`
found `ArrayBase<ViewRepr<&mut T>, _>`
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
- Ngôn ngữ chính
- Rust
- Star
- 4.3k
- Fork
- 391
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của rust-ndarray/ndarray
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
rust-ndarray/ndarray#1612 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
rust-ndarray/ndarray#1617 · 1 bình luận ·
-
Stack overflow in `triu` Đang mởbug good first issue
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
rust-ndarray/ndarray#1615 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
rust-ndarray/ndarray#1610 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
rust-ndarray/ndarray#1609 ·
Tất cả issue của rust-ndarray/ndarray
Issue tương tự
-
risk:low runtime status:in-progress type:test
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
zeroclaw-labs/zeroclaw#11023 ·
-
good first issue refactor
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
EricSpencer00/Resilient#4835 · 1 bình luận ·
-
agent:ready documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
cesarferreira/stax#890 ·
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100