I have been testing the Tensor module from Eigen3 for a new project. Even when the module is not yet finished, it seems to have most of the functionality that I need.
But there is one part that I quite not get. Whenever I have a big Tensor and I want to extract a slice from it, Eigen makes a copy of the data.
Is there a way to not copy the data, but instead point to the original data block in the slice?
For example if I do:
Tensor<float, 3> A(100,1000,1000); A.setZero();
Eigen::array<int, 3> offsets = {0, 0, 0};
Eigen::array<int, 3> extents = {2, 2, 2};
Tensor<float, 3> c = A.slice(offsets, extents);
A(0,0,0) = 1.0;
cerr << c << endl;
But the first element of "c" is still zero, instead of mapping to the modified "A(0,0,0)" data block.
You can use a TensorMap to create a tensor based on shared memory space of your slice. However this only works if your slice occupies contiguous portion of the data array. Otherwise you would need to do some tensor arithmetic to figure out the begin and end 1d indices of various parts of your single slice.
TensorMap<Tensor<float, 3, RowMajor> > row_major(data, ...);
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