[C++ API] Simple assignation

Hey there!

I’m trying out the PyTorch 1.0 C++ API, and I can’t find how to do a simple assignation, like in the following python snippet:

my_tensor[0, 0] = 1

I tried the following:

my_tensor[0, 0] = 1.f;

I was surprised to see that it compiles; but unfortunately it’s just equivalent to calling:

my_tensor[0] = 1.f;

(Only the first index is used.)

So, how can I perform multidimensional indexing from C++?


Not sure, if that’s the recommended way, but my_tensor[0][0] = 1.f; works for me. :wink:

Makes sense, thanks!

Where could one find this kind of information?

As the cppdocs are still being updated, I usually have a look at some core implementations to see, how others are using ATen.
For me personally, @tom’s LossCTC is a good cheat sheet, as there is some tensor indexing using accessors etc.