How to convert a faer Mat into a Rust normal array?
hunter1992 opened this issue · 1 comments
hunter1992 commented
I can't find the right way to convert faer Mat into Rust array, the code and error I got:
My code:
use faer::Mat;
type Dtype = f32;
fn main() {
let mut a = Mat::<Dtype>::zeros(4, 3);
for i in 0..a.ncols() {
for j in 0..a.nrows() {
a[(i, j)] = 11.0;
}
}
let b: [[Dtype; 3]; 4] = a.into();
}
Error:
error[E0277]: the trait bound `[[f32; 3]; 4]: From<Mat<f32>>` is not satisfied
--> src/main.rs:13:32
|
13 | let b: [[Dtype; 3]; 4] = a.into();
| ^^^^ the trait `From<Mat<f32>>` is not implemented for `[[f32; 3]; 4]`, which is required by `Mat<f32>: Into<_>`
|
= help: the following other types implement trait `From<T>`:
<[T; 10] as From<(T, T, T, T, T, T, T, T, T, T)>>
<[T; 11] as From<(T, T, T, T, T, T, T, T, T, T, T)>>
<[T; 12] as From<(T, T, T, T, T, T, T, T, T, T, T, T)>>
<[T; 1] as From<(T,)>>
<[T; 2] as From<(T, T)>>
<[T; 3] as From<(T, T, T)>>
<[T; 4] as From<(T, T, T, T)>>
<[T; 5] as From<(T, T, T, T, T)>>
and 7 others
= note: required for `Mat<f32>` to implement `Into<[[f32; 3]; 4]>`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `faer_basic` (bin "faer_basic") due to 1 previous error
Please help me solve this problem, thank you.
sarah-quinones commented
you can just initialize the array to zero and use a for
loop. faer
doesn't really target statically sized arrays