不能用本征在二维上收缩吗?
can't do contraction on two dimensions with eigen?
我试图在最后两个维度上进行第三级张量(1 x 1 x 1)的张量收缩,并使用两个等级张量(1 x 1)进行张量。结果应该是向量。
以下主张:
#include <Eigen/Core>
#include <unsupported/Eigen/CXX11/Tensor>
#include <iostream>
#include <array>
#include <iostream>
#include <memory>
#include <thread>
#include <chrono>
#include <mutex>
using namespace Eigen;
using namespace std;
int main()
{
Eigen::Tensor<double, 3> tensor(1, 1, 1);
Eigen::Tensor<double, 2> tensor2(1,1);
Eigen::Tensor<double, 1> tensor1;
std::array<Eigen::IndexPair<int>, 1> product_dims;
product_dims[0] = { IndexPair<int>(1, 0) };
product_dims[1] = { IndexPair<int>(2, 1) };
auto vv = tensor.contract(tensor2, product_dims);
cerr<<"value: "<<vv<<endl;
tensor1 = vv;
}
但打印值:0如预期。
断言是:
a.out: /eigen-eigen-7c567a7c10e1/unsupported/Eigen/CXX11/src/Tensor/TensorAssign.h:125: bool Eigen::TensorEvaluator<const Eigen::TensorAssignOp<LhsXprType, RhsXprType>, Device>::evalSubExprsIfNeeded(Eigen::TensorEvaluator<const Eigen::TensorAssignOp<LhsXprType, RhsXprType>, Device>::Scalar*) [with LeftArgType = Eigen::Tensor<double, 0>; RightArgType = const Eigen::TensorContractionOp<const std::array<Eigen::IndexPair<int>, 1ul>, const Eigen::Tensor<double, 3>, const Eigen::Tensor<double, 2> >; Device = Eigen::DefaultDevice; Eigen::TensorEvaluator<const Eigen::TensorAssignOp<LhsXprType, RhsXprType>, Device>::Scalar = double]: Assertion `dimensions_match(m_leftImpl.dimensions(), m_rightImpl.dimensions())' failed.
有什么想法为什么我有这个维度不匹配的主张?
您的数组是一个大小1,因此您有效地收缩了一对尺寸。相反,您应该创建数组如下:
std::array<Eigen::IndexPair<int>, 2> product_dims;
相关文章:
- 具有随机数的二维数组不会更改
- C++ 中的二维整数数组,每行中的元素数量不均匀
- 为什么一个二维阵列会导致赛段故障,而另一个则不会导致?
- 为什么我的二维表不正确显示
- 为什么不能在以下数组上使用二叉搜索
- 我可以在不知道文本文件的列数的情况下读取二维数组中的文件吗?
- 不能用本征在二维上收缩吗?
- 打印空白,而不是二维数组c++中的整数
- 二维矢量的C++Insert命令不起作用
- 不带列号的二维数组提供地址
- 在 Mac 中将一维数组转换为二维不起作用
- 如何在不分配内存的情况下将一维数组转换为二维数组
- 如何在C++中为矢量数据结构中的二维数组获取用户输入,而不使用行和列上的两个for循环
- 为什么我将数字数据从文本文件导入二维数组的代码不起作用
- 在objective-c项目中导入iOS二维码生成器文件:c++类不编译
- 传递二维数组,在C中工作,但在C++中不工作
- 用一些逻辑比较二维数组,想不出来
- 为什么使用一维数组而不是二维数组?
- 为什么运算符 new 不能构造非恒定大小的多维数组?
- **运算符不能将二维数组作为参数