Slice with negative step inconsistent with python result
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 35/100
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- Rust
- Estrelas
- 4.3k
- Forks
- 391
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Guia de contribuição
Nenhum guia de contribuição indexado para este repositório
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de rust-ndarray/ndarray
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
rust-ndarray/ndarray#1612 · 1 comentário ·
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 48/100
rust-ndarray/ndarray#1617 · 1 comentário ·
-
Stack overflow in `triu` Abertabug good first issue
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 68/100
rust-ndarray/ndarray#1615 · 1 comentário ·
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 48/100
rust-ndarray/ndarray#1610 ·
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 72/100
rust-ndarray/ndarray#1609 ·
Todas as issues de rust-ndarray/ndarray
Issues semelhantes
-
risk:low runtime status:in-progress type:test
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 92/100
zeroclaw-labs/zeroclaw#11023 ·
-
good first issue refactor
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 72/100
bevyengine/bevy#25861 ·