pytorch replace data in a tensor with a view

Viewed 106

I am trying to build a TreeTensor data structure that would still be a pytorch tensor: it's a Binary Tree with each node either a normal torch.Tensor or a TreeTensor. The root of it contains all the data in it's storage as a flat 1D tensor, and all children nodes are views of this parent data.

When doing this I face following issue: to be able to construct my TreeTensor, some nodes need to change from owning the data to being a view on the same data now stored in parent 1D array. This is because when building it, I need the flexibility of bottom-up approach - I first create children, then parents pointing to those children. How can I move the data out of a tensor and replace it with a view of the same dimension?

Motivation: I'd like to create a hierarchical structure of signals which can be nicely accessed with x.y kind of notation.

0 Answers
Related