code: def quantize(x, max_absval, num_bits):
      y = x
  
      # get maximum/minimum exponent
      n1 = np.floor(np.log2(max_absval)) + (
          np.log2(max_absval) - np.floor(np.log2(max_absval))
          >= np.log2(1.5)
      )
      n2 = n1 + 1 - 2 ** (num_bits - 2)
  
      pruning_threshold = 2 ** (n2 - 1)
  
      # prune all small values
      y[np.abs(x) < pruning_threshold] = 0.0
  
      # quantize remaining values to powers of two
      _i = y != 0
      _s = np.sign(y[_i])
      _b = np.log2(np.abs(y[_i]))
      _d = np.log2(1.5)  # quantization threshold
      # _d = 0.5 use geometric mean
      # _d = np.log2(1.5) use arithmetic mean
      _e = np.floor(_b) + (_b - np.floor(_b) >= _d)
      _e = np.maximum(n2, np.minimum(n1, _e))
      y[_i] = _s * 2 ** (_e)
      return y
  
file_path: nnabla/python/test/function/test_inq_convolution.py
imports: from __future__ import division
  import pytest
  import numpy
  import nnabla
  import nnabla.functions
  import refs
  from nbla_test_utils import list_context
label_desc: Use image node_id 1 for calling a global function with example usage: quantize(x, max_absval, num_bits) and returns: y