Creating a new type of Tensor

PyTorch itself has 8 different types of tensors; float, double, half, uint8, int16, int32, and int64. I looked at this blog post and they explained how they created these types of tensor:

A Tour of PyTorch Internals (Part I)

The type of tensor I want to create is fixed-point tensor instead of float-point that is used by pytorch in float, double and half types.

I was wondering if there is an easier way to create a new type of tensor without modifying the backend (C++) code?

In general, there isn’t an easy way now to create a new tensor type. Depending on the design of your fixed-point tensor, it might be possible to use the built-in tensors to implement it. What exactly do you mean by “fixed-point”?

PyTorch uses floating-point to store decimal number. Due to the structure of floating-point the numbers are not stored properly and it causes precision loss.

Structure of floating point

I was thinking about using integers to perform math operations and then use the new object to store those numbers to preserve the decimal points without any precision loss.

if you’re using ints, one thing you could do is use LongTensor and write custom functions of your own (i.e., add_fixed_point(LongTensor, LongTensor))

Is there any way to inherit the IntTensor for example and add my own methods?