I am very new to the c++/cuda pytorch API and I would like to manipulate tensors containing integers (int64). I was wondering how to do so. Also the PackedTensorAccessor don’t seems to accepts int as first argument.
So just two examples, first instantiate a 0-valued tensor of type int:
torch::Tensor test = torch::zeros({5}, int);
or trying to get an accessor from an existing tensor:
You need to match the scalar type to the tensor’s scalar_type, so:
If you instantiated a torch::kLong tensor (that’s 64 bit integers), use int64_t. For kInt (32 bit) use int32_t, for nothing (aka kFloat), float.
Note that you usually do not need packed_accessor for CPU tensors, they are intended for passing to CUDA kernels. accessor will do for CPU (pointing to the Tensor’s stride and size arrays) - unless you want 32 indexing (on ARM?, probably not on x86).
(And you can use auto for less repetitive code.)