(data, device, non_zero)
| 221 | |
| 222 | |
| 223 | def quantize(data, device, non_zero): |
| 224 | np_data = np.array(data).astype(float) |
| 225 | in_min = np_data.min() |
| 226 | in_max = np_data.max() |
| 227 | scale, zero, out_min, out_max = adjust_range(in_min, in_max, device, |
| 228 | non_zero=non_zero) |
| 229 | output = np.clip((np.round(zero + np_data / scale).astype(np.int32)), |
| 230 | 0, 255) |
| 231 | |
| 232 | quantized_data = QuantizedData() |
| 233 | quantized_data.data = output |
| 234 | quantized_data.scale = scale |
| 235 | quantized_data.zero = zero |
| 236 | quantized_data.minval = out_min |
| 237 | quantized_data.maxval = out_max |
| 238 | return quantized_data |
| 239 | |
| 240 | |
| 241 | # only support int16 symmetric quantization. |
nothing calls this directly
no test coverage detected