dfalbel / torch

torch from R!
http://dfalbel.github.io/torch
Other
51 stars 5 forks source link

Make tensor from R zero copy #1

Closed dfalbel closed 5 years ago

dfalbel commented 5 years ago

In python, when creating a tensor from a numpy array pytorch makes no copy. At the moment we are making 2 copies when casting from R to a tensor.

The first one (inside R) to convert from the col-major representation to a row-major (used by libtorch). The other when after creating the tensor inside cpp code, because R doesn't know that torch points to the data address when the R object is removed.

I think it should be possible to make at most one copy, but maybe with ALTREP we could make the casting zero copy.

I would love some help on it!