Data type in Pytorch C++ API


I think the tensor data type is a little bit weird in C++.
I made a tensor variable which is kFloat32 and I thought that it was 4 bytes.
However, when I check the size of it with sizeof(), it says that it is 8 bytes.

And I’ve tried other types such as kFloat64, kInt8, kInt16 and so forth.
But the sizeof() always says that the variable is 8 bytes.

Is tensor variable always 8 bytes in c++? or did I do something wrong?

A Tensor is a Tensor in some sense. So I am not surprised they all have the same size.
If you’re looking for the size of each element in the Tensor, you have a special function for that. It is .element_size() if I recall correctly.

1 Like

With .element_size(), I can see the expected size of variables.
Thanks a lot.