Skip to content
DeepForgeby svx
All problems
MediumDeep Learningdl-345

Zero-Point Computation

Problem

Compute the asymmetric zero point: step = (max - min) / (2^bits - 1), z = round(qmin - min/step) clamped to [qmin, qmax], where qmin/qmax are -2^(bits-1) and 2^(bits-1)-1 for signed mode, or 0 and 2^bits-1 otherwise. A constant range returns 0. Return an integer.

The signature is zero_point_computation(min_val, max_val, bits=8, signed=True).

Hint

The zero point shifts the real zero into the integer code grid.

Test cases

case 1
in: [-1,2,8,true]
expected: -43
case 2
in: [-0.5,1.5,8,true]
expected: -64
case 3
in: [-1.5,0.5,8,true]
expected: 63
case 4
in: [0,0,8,true]
expected: 0
case 5
in: [-2,3,4,true]
expected: -2
Starter codePython
def zero_point_computation(min_val, max_val, bits=8, signed=True):
    # Your code here
    pass

5 test cases · run your code against them in the editor