Trait for 1d to nd index conversion

Aperta
#485 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
30/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
rust
Ambito
data

Direzione di ricerca

Start with the generic shuffle example and inspect the Array, Array1, and Dimension indexing, flattening, and reshaping APIs mentioned in the issue. A complete contribution would establish whether a single usize can be converted safely for arbitrary dimensions and document or test the resulting behavior.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Given an array of arbitrary dimension, is it possible to index into it using a single usize?

fn shuffle1<E>(values: &mut Array1<E>) {
    let mut i = values.len();
    while i >= 2 {
        // invariant: elements with index >= i have been locked in place.
        i -= 1;
        // lock element i in place.
        values.swap(i, thread_rng().gen_range(0, i + 1));
    }
}

fn shuffle<E, D: Dimension>(values: &mut Array<E, D>) {
    let mut i = values.len();
    while i >= 2 {
        i -= 1;
        values.swap(i, thread_rng().gen_range(0, i + 1));
        // This won't work as a single usize is not necessarily a valid index,
       // the usize must be converted to a index of dimension D
    }
}

One possible solution is probably to flatten the array, then shuffle it, then reshape it back, although I do think a method for indexing into the array with a single integer could be useful in general.

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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rust-ndarray/ndarray

Tutte le issue di rust-ndarray/ndarray

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.