Skip to content
DeepForgeby svx
All problems
EasyDeep Learningdl-360

Static Activation Quantization

Problem

Quantize activations with a precomputed static scale: code = clamp(round(x/scale), qmin, qmax) applied element-wise. Return the list of integer codes; a zero scale yields zeros.

The signature is static_activation_quant(x, scale, qmin=-128, qmax=127).

Hint

Static scales are calibrated once and reused, so values saturate at qmin/qmax.

Test cases

case 1
in: [[1,-1],0.01,-128,127]
expected: [100,-100]
case 2
in: [[1000],1,-128,127]
expected: [127]
case 3
in: [[-1000],1,-128,127]
expected: [-128]
case 4
in: [[0.5],0.5,-8,7]
expected: [1]
Starter codePython
def static_activation_quant(x, scale, qmin=-128, qmax=127):
    # Your code here
    pass

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