All problems
Quantize Int8
Problem
Quantize a list of floats to int8 with a symmetric scale: q_i = round(x_i / scale), clamped to [-128, 127].
The signature is quantize_int8(x, scale). Return the integer codes.
Hint
Round first, then saturate at the int8 bounds.
Test cases
case 1
in: [[0,0.1,-0.1],0.1]
expected: [0,1,-1]
case 2
in: [[100,-100],0.5]
expected: [127,-128]
case 3
in: [[3,-3,0.4],1]
expected: [3,-3,0]
case 4
in: [[1.4,-1.6],0.5]
expected: [3,-3]
Starter codePython
def quantize_int8(x, scale):
# Your code here
pass4 test cases · run your code against them in the editor