Trait for 1d to nd index conversion

Đang mở
#485 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
30/100
Loại issue
Tính năng
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
rust
Lĩnh vực
data

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Rust
Star
4.3k
Fork
391
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rust-ndarray/ndarray

Tất cả issue của rust-ndarray/ndarray

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.