如何解决如何使Eigen :: Tensor代码更简洁?
我对Eigen/Core
很满意,但需要一些更高维的数组。因此,我正在学习Eigen::Tensor
。我可以获取以下代码进行编译,但发现语法不干净。我可以做得更好吗?评论中有两个问题。
Eigen::Tensor<float,3> t_3d(2,3,4);
t_3d.setZero();
// Is there a shorter and less repetitive way to write this? e.g. like this
// t_3d.chip(/*offset=*/1,/*dim=*/0) *= 0.5;
// auto seems to work:
// auto c = t_3d.chip(/*offset=*/1,/*dim=*/0);
// c *= c.constant(0.5);
t_3d.chip(/*offset=*/1,/*dim=*/0) *=
t_3d.chip(/*offset=*/1,/*dim=*/0).constant(0.5);
Eigen::Tensor<float,3> expected(2,4);
expected.setZero();
// Is there a shorter way to write this? e.g. by not declaring eq and using
// 1 line.
// Maybe this is the best we can do as doc also does that?
// doc: https://eigen.tuxfamily.org/dox/unsupported/eigen_tensors.html#title7
// related: https://stackoverflow.com/questions/52392465/how-to-multiply-an-eigen-tensor-by-the-scalar-sum-of-another-eigen-tensor-in-c/52403691
Eigen::Tensor<bool,0> eq = (t_3d == expected).all();
EXPECT_TRUE(eq(0));
此外,由于不支持Eigen::Tensor
,有没有很好的选择? (我已经在代码库中使用了Eigen::Matrix
等。)谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。