I understand that the Tensor class supports slicing, but when I tried to do slicing on a TensorMap instance, the error is that the operation is not supported. How can I slice a TensorMap?
std::vector<int> v(27);
std::iota(v.begin(),v.end(),1);
Eigen::TensorMap<Eigen::Tensor<int,3>> mapped(v.data(), 3, 3, 3 );
Eigen::array<long,3> startIdx = {0,0,0}; //Start at top left corner
Eigen::array<long,3> extent = {2,2,2}; // take 2 x 2 x 2 elements
Eigen::Tensor<int,3> sliced = mapped.slice(startIdx,extent);
std::cout << sliced << std::endl;
This code creates a 3 x 3 x 3 TensorMap (mapped
) on a std vector of 27 elements (v
) and then slices a 2 x 2 x 2 chunk (extent
) starting in the top-left-front corner (startIdx
) and stores it in sliced
Edit: The type of the result can also be inferred with auto
:
auto sliced = mapped.slice(startIdx,extent);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With