This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Tensor slicing without copying any data

Tags: eigen, tensor eigen, tensor eigen, tensor
(comma "," separated)
TunkeJazz
Registered Member
Posts
1
Karma
0
I am starting a large new project where I need multidimensional arrays to store data.
I have been comparing the Tensor class from Eigen to blitz++. In all my tests, Eigen is significantly faster when performing operations with full tensors, so I would like to use it.

The one feature that I feel is missing compared to Blitz is the possibility to extract a slice without actually copying any data, but instead pointing to the original data block.
In Blitz the user can basically use to copy or not depending on how the assignment is done. For example (using Tensor notation), the following code would make a copy of the data from "a" to "c":
Code: Select all
Tensor<float,3> a(10,10,20);
a.setZero();
a(1,1,1) = 1;
Eigen::array<int, 3> offsets = {0, 0, 0};
Eigen::array<int, 3> extents = {2, 2, 2};
Tensor<float,3> c = a.slice(offsets, extents);


However if we replace the way c is assigned, it would still point to the original data block without making a copy:
Code: Select all
Tensor<float,3> c;
c =  a.slice(offsets, extents);


This behaviour cannot be reproduced with the Map feature because (as far as I understood it), it assumes that the data are strictly consecutive in memory, which is not true if we slice over the non-fast axes. I have read the updated version of README inside the Tensor class directory and I think I have tried everything I could but I could not reproduce this behaviour as in blitz.

But the feature itself would be excellent to have because it would allow to visualise subsets of the tensor very efficiently. Would it be possible to implement such feature into the Tensor class? ...or is it already implemented and I completely missed it? I tried to ask in Stackoverflow but no success...


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rblackwell