How could I return a tensor from c++ to python?

Hi,

I am trying to load data with c++ and return the c++ data to pytorch directly as a tensor. Is there any tutorial on how could I do this? By the way, is pytorch tensor always contiguous in the memory ? Namely, if I need a (N, M) tensor, is it likely that I prepare N c++ pointers each of which holds the data for a (1, M) tensor and I pass these pointers to some api to compose a pytorch tensor without copying memory?

Hi,

The pytorch Tensor will require a contiguous chunk of memory. But you can specify size and stride so it does not have to be stored in a conitguous way in that contiguous chunk of memory.
You have some information in the cpp extension doc here or in the cpp API doc here.
But the simplest solution is most likely going to be to create a Tensor of the right size and then copy your content into it.