Slice with negative step inconsistent with python result
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Start with the Si documentation linked in the issue and the slice macro behavior exercised by the Rust example. Compare negative-step defaults against the Python cases, then determine whether the documented semantics or implementation should change; done means the behavior is decided and either corrected or clearly documented with regression coverage.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
First of all, I understand that this crate is not meant to reproduce all feature in python, but since in the docs about Si python slice is used as comparison, so I believe this is worth to bring up.
Here is some test case with ndarray:
#[macro_use(s)]
extern crate ndarray;
use ndarray::prelude::*;
fn main() {
let x: Array1<usize> = Array::zeros(16);
println!("{}", x.slice(s![..4;1]).len());
println!("{}", x.slice(s![4..;1]).len());
println!("{}", x.slice(s![..-4;1]).len());
println!("{}", x.slice(s![-4..;1]).len());
println!("{}", x.slice(s![..4;-1]).len());
println!("{}", x.slice(s![4..;-1]).len());
println!("{}", x.slice(s![..-4;-1]).len());
println!("{}", x.slice(s![-4..;-1]).len());
}
which return:
4
12
12
4
4
12
12
4
and in the corresponding python test case (in both python 2.7.6 and python 3.4.3):
def main():
x = [0] * 16
print(len(x[:4:1]))
print(len(x[4::1]))
print(len(x[:-4:1]))
print(len(x[-4::1]))
print(len(x[:4:-1]))
print(len(x[4::-1]))
print(len(x[:-4:-1]))
print(len(x[-4::-1]))
if __name__ == '__main__':
main()
which return:
4
12
12
4
11
5
3
13
It seems that, with negative step, the default begin is n - 1 and the default end is 0 for python. To be honest, I prefer the ndarray approach to kept the default consistance, but I believe this should either mention in the docs or changed.
- 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