Trait for 1d to nd index conversion

Aberta
#485 1 comentário 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
5/5
Tempo estimado
Mais de uma semana
Facilidade para iniciantes
30/100
Tipo de issue
Funcionalidade
Clareza
Precisa de esclarecimento
Status de atividade
Estagnada
Stack de tecnologia
rust
Domínio
data

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

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.