0

I want to round a tensor variable to a lower resolution representation (e.g. round a float64 value to it's float48 representation while keeping it float64). Is there an efficient way of doing this?

The closest thing I could find is the tensor.round function but I am not experienced enough to understand how to implement it. I would appreciate any help. Thank you.

kkawabat
  • 1,530
  • 1
  • 14
  • 37

1 Answers1

0

I figured it out.

First determine the cast of the original tensor used in theano, usually float64 or float32 which uses 23 or 52 bits to represent the mantissa

Then to quantize the variable by x-bits multiply by 2^(n-x), round then divide by 2^(n-x) where n is the number of bits used to represent the data in the original tensor variable.

if orig_tensor.type == 'float64':
    n = 52 
else:
    n = 23 

quantized_tensor = T.round(orig_tensor*(2**(n-x)))/(2**(n-x))
Community
  • 1
  • 1
kkawabat
  • 1,530
  • 1
  • 14
  • 37