Slice with negative step inconsistent with python result
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Rust
- Stelle
- 4.3k
- Fork
- 391
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di rust-ndarray/ndarray
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
rust-ndarray/ndarray#1612 · 1 commento ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
rust-ndarray/ndarray#1617 · 1 commento ·
-
Stack overflow in `triu` Apertabug good first issue
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
rust-ndarray/ndarray#1615 · 1 commento ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
rust-ndarray/ndarray#1610 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
rust-ndarray/ndarray#1609 ·
Tutte le issue di rust-ndarray/ndarray
Issue simili
-
risk:low runtime status:in-progress type:test
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
zeroclaw-labs/zeroclaw#11023 ·
-
good first issue refactor
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
EricSpencer00/Resilient#4835 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
bisq-network/bisq-musig#204 ·
-
agent:ready documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
cesarferreira/stax#890 ·