如何在本征中转置张量 [英] How to transpose Tensor in Eigen
本文介绍了如何在本征中转置张量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获得两个张量的矩阵乘积,其中一个张量应在相乘之前变换( At * B
)。
到目前为止,我在本征文档是矩阵产品,不进行任何转置,并且两个矩阵都转置。
$我正在寻找一种方法来要么直接收缩两个张量,要么将其中一个张量转置,要么通过在收缩之前转置一个张量。解决方案
我知道了,可以使用随机播放方法来完成转置效果。
Eigen :: Tensor< int,2> m(3,5);
m.setValues(
{
{1,2,3,4,5},
{6,7,8,9,10},
{ 11,12,13,14,15}
});
Eigen :: array< int,2>改组({1,0});
Eigen :: Tensor< int,2>转置= m.shuffle(shuffling);
Eigen :: Tensor< int,2>原始= transposed.shuffle(shuffling);
I'm trying to get matrix product of two tensors, where one of the tensor should be transposed before it multiplied (At*B
).
So far what I've found in eigen documentation is matrix product without any transposed and with both matrix transposed.
I'm looking for a way to either directly contracting two tensor with one of the tensor is transposed, or either by transposing one tensor before contracting it.
解决方案
I figured it out, transpose effect can be done using shuffle method.
Eigen::Tensor<int, 2> m(3, 5);
m.setValues(
{
{1, 2, 3, 4, 5},
{6, 7, 8, 9, 10},
{11, 12, 13, 14, 15}
});
Eigen::array<int, 2> shuffling({1, 0});
Eigen::Tensor<int, 2> transposed = m.shuffle(shuffling);
Eigen::Tensor<int, 2> original = transposed.shuffle(shuffling);
这篇关于如何在本征中转置张量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文