quantize_multiplier
PythonConvert a floating point multiplier into a fixed-point multiplier and shift.
quantize_multiplier(real_multiplier: float) -> tuple[int, int]Convert a floating point multiplier into a fixed-point multiplier and shift.
Given a real multiplier, this function computes a pair (quantized_multiplier, shift) such that the fixed-point multiplication approximates the real multiplier:
real_multiplier ~ quantized_multiplier / (2^(31 - shift))
This is typically used in quantized inference to convert floating-point scaling factors to fixed-point representation.
The CMSIS-NN arm_nn_divide_by_power_of_two function only supports
exponent values in [0, 31], so the resulting shift is clamped to [-31, 30].
When the real multiplier is so small that the shift would fall below -31
the contribution is negligible and the multiplier is flushed to zero.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
real_multiplier | float | Required | The floating-point multiplier. |
Returns
| Value | Type | Description |
|---|---|---|
tuple | tuple[int, int] | (quantized_multiplier, shift) |