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};
Eigen::array<long,3> extent = {2,2,2};
Eigen::Tensor<int,3> sliced = mapped.slice(startIdx,extent);
std::cout << sliced << std::endl;
This code creates 3 x 3 x 3 TensorMap ( mapped) in a 27-element std-vector ( v), and then cuts a 2 x 2 x 2 ( extent) fragment , starting from the top level, the left corner ( startIdx) and stores it insliced
source
share