【发布时间】:2018-12-13 00:57:30
【问题描述】:
我想在ndarray 中有一个矩阵作为可用于其他模块的常量。不幸的是,构造函数本身并不是一个常数函数。有什么办法可以绕过这个限制吗?
代码:
extern crate ndarray;
use ndarray::prelude::*;
const foo: Array2<f32> = arr2(&[
[1.26, 0.09], [0.79, 0.92]
]);
fn main() {
println!("{}", foo);
}
错误:
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
--> src\main.rs:5:26
|
5 | const foo: Array2<f32> = arr2(&[
| __________________________^
6 | | [1.26, 0.09], [0.79, 0.92]
7 | | ]);
| |__^
【问题讨论】:
标签: rust