rust-ndarray / ndarray

ndarray: an N-dimensional array with array views, multidimensional slicing, and efficient operations

Home Page:https://docs.rs/ndarray/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`FixedInitializer` is limited to fixed sizes, hampering creation of large matricies with `arr2`, `arr3`, etc

Jasha10 opened this issue · comments

Only small-sized arguments work for arr2, arr3, etc.
This is a duplicate of issue #446 which (IMO) was closed prematurely.

use ndarray::prelude::*;

fn main() {
    // This works
    let _: Array1<u16> = arr1(&[
        1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
    ]);
    // This works
    let _: Array1<u16> = arr1(&[
        1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
        11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
    ]);
    // This works
    let _: Array2<u16> = arr2(&[[
        1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
    ]]);
    // This fails
    let _: Array2<u16> = arr2(&[[
        1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
        11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
    ]]);
}
 1  error[E0277]: the trait bound `[{integer}; 20]: FixedInitializer` is not satisfied
    --> src/main.rs:18:31
     |
 18  |       let _: Array2<u16> = arr2(&[[
     |  __________________________----_^
     | |                          |
     | |                          required by a bound introduced by this call
 19  | |         1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
 20  | |         11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
 21  | |     ]]);
     | |______^ the trait `FixedInitializer` is not implemented for `[{integer}; 20]`
     |
     = help: the following other types implement trait `FixedInitializer`:
               [T; 0]
               [T; 1]
               [T; 2]
               [T; 3]
               [T; 4]
               [T; 5]
               [T; 6]
               [T; 7]
             and 9 others
 note: required by a bound in `ndarray::arr2`

See #446 for some suggested workarounds.

Regarding a fix for this issue:

My understanding based on this comment on #446 is that implementing arbitrary initalizer sizes was blocked until the const-generics rust feature became available. It seems const-generics is now stabilized... so maybe it's possible to implement arbitrary initializer sizes now?