# tensorplay.functional.fake_quantize_per_tensor_affine Source: https://www.tensorplay.cn/docs/generated/tensorplay.functional.fake_quantize_per_tensor_affine.html ```python tensorplay.functional.fake_quantize_per_tensor_affine(input, scale, zero_point, quant_min, quant_max) → Tensor ``` Returns a new tensor with the data in input fake quantized using scale, zero_point, quant_min and quant_max. $$\text{output} = ( min( \text{quant\_max}, max( \text{quant\_min}, \text{std::nearby\_int}(\text{input} / \text{scale}) + \text{zero\_point} ) ) - \text{zero\_point} ) \times \text{scale}$$ Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input value(s), tensorplay.float32 tensor - scale (double scalar or float32 Tensor) – quantization scale - zero_point (int64 scalar or int32 Tensor) – quantization zero_point - quant_min (int64) – lower bound of the quantized domain - quant_max (int64) – upper bound of the quantized domain Returns: A newly fake_quantized tensorplay.float32 tensor Return type: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) Example: ``` >>> x = tensorplay.randn(4) >>> x tensor([ 0.0552, 0.9730, 0.3973, -1.0780]) >>> tensorplay.fake_quantize_per_tensor_affine(x, 0.1, 0, 0, 255) tensor([0.1000, 1.0000, 0.4000, 0.0000]) >>> tensorplay.fake_quantize_per_tensor_affine(x, tensorplay.tensor(0.1), tensorplay.tensor(0), 0, 255) tensor([0.1000, 1.0000, 0.4000, 0.0000]) ```