Shuffle for RowMajor Tensor
Problem
I know that the Tensor docs say that Eigen::RowMajor is not fully supported and I'm encountering an issue when I try to take the transpose (e.g. use shuffle) of a 2D tensor. See the below (I also created a compiler explorer example here).
#include <Eigen/Dense>
#include <unsupported/Eigen/CXX11/Tensor>
int main()
{
int N = 8;
Eigen::Tensor<double, 2, Eigen::RowMajor> F(N,N);
F.setRandom();
Eigen::Tensor<double, 2, Eigen::RowMajor> F_new = F.shuffle({1,0});
}
Below is a snippet of the compiler error (using gcc@10.2.0):
<source>: In function 'int main()':
<source>:12:66: error: no matching function for call to 'Eigen::Tensor<double, 2, 1>::shuffle(<brace-enclosed initializer list>)'
12 | Eigen::Tensor<double, 2, Eigen::RowMajor> F_new = F.shuffle({1,0});
Possible Solution
Is this error coming from the fact that shuffle isn't supported yet for Eigen:RowMajor tensors or is there something else going on? If it's not supported is there a suggested workaround to use now? The following solution is pretty inelegant so sleaker solutions would be much appreciated.
#include <Eigen/Dense>
#include <unsupported/Eigen/CXX11/Tensor>
int main() {
int N = 8;
Eigen::Tensor<double, 2, Eigen::RowMajor> F(N, N);
F.setRandom();
Eigen::Map<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>> F_map(F.data(), N, N);
Eigen::TensorMap<Eigen::Tensor<double, 2, Eigen::RowMajor>> F_tmp(F_map.transpose().data(), N, N);
}
Edited by James E T Smith