code: def ref_fixed_point_quantize(
      x, sign, n, delta, quantize, ste_fine_grained
  ):
      assert n > 0 and delta > 0
  
      ref_delta = delta
      if sign:
          ref_max = ((1 << (n - 1)) - 1.0) * ref_delta
          ref_min = -ref_max
      else:
          ref_max = ((1 << n) - 1.0) * ref_delta
          ref_min = 0.0
  
      if quantize:
          x_q = (
              (np.abs(x) / ref_delta + 0.5).astype(np.int32) * ref_delta
          ) * np.sign(x)
          x_q[np.where(x > ref_max)] = ref_max
          x_q[np.where(x < ref_min)] = ref_min
      else:
          x_q = x
      return x_q
  
file_path: nnabla/python/test/function/test_fixed_point_quantize.py
imports: import pytest
  import numpy
  import nnabla
  import nnabla.functions
  from nbla_test_utils import list_context
label_desc: Use image node_id 1 for calling a global function with example usage: ref_fixed_point_quantize(x, sign, n, delta, quantize, ste_fine_grained) and returns: x_q