Slice with negative step inconsistent with python result

Aberta
#312 4 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
35/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Estagnada
Stack de tecnologia
rust
Domínio
data

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

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de rust-ndarray/ndarray

Todas as issues de rust-ndarray/ndarray

Issues semelhantes

Mais issues de Rust

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.