在Rust中使用einsum进行矩阵乘法
我想使用einsum将数组与随机数相乘。以下是我的实现的要点:在Rust中使用einsum进行矩阵乘法,rust,Rust,我想使用einsum将数组与随机数相乘。以下是我的实现的要点: use ndarray_einsum_beta::*; use ndarray::Array; use ndarray_rand::RandomExt; use ndarray_rand::rand_distr::Uniform; fn main() { let m1 = Array::random((100, 100), Uniform::new(0., 10.)); let m2 = Array::ran
use ndarray_einsum_beta::*;
use ndarray::Array;
use ndarray_rand::RandomExt;
use ndarray_rand::rand_distr::Uniform;
fn main() {
let m1 = Array::random((100, 100), Uniform::new(0., 10.));
let m2 = Array::random((100, 100), Uniform::new(0., 10.));
let res = einsum("ij,jk->ik", &[&m1, &m2]);
}
编译代码时,将抛出以下错误消息:
error[E0277]: the trait bound `ArrayBase<OwnedRepr<{float}>, Dim<[usize; 2]>>: ArrayLike<_>` is not satisfied
--> src/main.rs:11:37
|
11 | let res = einsum("ij,jk->ik", &[&m1, &m2]);
| ^^^ the trait `ArrayLike<_>` is not implemented for `ArrayBase<OwnedRepr<{float}>, Dim<[usize; 2]>>`
|
= note: required for the cast to the object type `dyn ArrayLike<_>`
error[E0277]: the trait bound `ArrayBase<OwnedRepr<{float}>, Dim<[usize; 2]>>: ArrayLike<_>` is not satisfied
--> src/main.rs:11:42
|
11 | let res = einsum("ij,jk->ik", &[&m1, &m2]);
| ^^^ the trait `ArrayLike<_>` is not implemented for `ArrayBase<OwnedRepr<{float}>, Dim<[usize; 2]>>`
|
= note: required for the cast to the object type `dyn ArrayLike<_>`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0277`.
error: could not compile `algebra_test`
您的
Cargo.toml
是什么样子的?你能把它的内容写在帖子里吗?它似乎不会在我这一方抛出错误ndarray@0.15.1
,ndarray\u einsum_beta@0.7.0
和ndarray-rand@0.14.0
@Janson你完全正确。这是一个依赖性的问题。更改依赖项可以解决问题。很高兴听到!我投票以“不可复制”来结束这个问题,这样未来的读者就会明白这不是一个问题。祝你周末愉快。@Jason非常感谢你的帮助!祝你周末愉快!
[dependencies]
ndarray = "0.14"
ndarray_einsum_beta = "0.4.4"
ndarray-rand = "0.13.0"
rand = "0.8"