code: def ref_pow2_quantize(
      x, sign, with_zero, n, m, quantize, ste_fine_grained
  ):
      assert n > 0
  
      n_ = n - 1 if sign else n
      n_ = n_ - 1 if with_zero else n_
      ref_p_max = 2**m
      ref_p_min = 2 ** (m - ((1 << n_) - 1))
      ref_pruning_threshold = ref_p_min * (2.0**-0.5)
      if quantize:
          x_q = 2.0 ** np.round(np.log2(np.abs(x)))
          x_q[np.where(x_q > ref_p_max)] = ref_p_max
          if with_zero:
              x_q_ = x_q.copy()
              x_q[np.where(x_q_ < ref_p_min)] = ref_p_min
              x_q[np.where(np.abs(x) < ref_pruning_threshold)] = 0.0
          if not with_zero:
              x_q[np.where(x_q < ref_p_min)] = ref_p_min
          if sign:
              x_q = np.sign(x) * x_q
          else:
              if with_zero:
                  x_q[np.where(np.sign(x) < 0.0)] = 0.0
              else:
                  x_q[np.where(np.sign(x) < 0.0)] = ref_p_min
      else:
          x_q = x
      return x_q
  
file_path: nnabla/python/test/function/test_pow2_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_pow2_quantize(x, sign, with_zero, n, m, quantize, ste_fine_grained) and returns: x_q