code: def test_half_conversion_rounding(self, float_t, shift, offset):
      # Assumes that round to even is used during casting.
      max_pattern = np.float16(np.finfo(np.float16).max).view(np.uint16)
  
      # Test all (positive) finite numbers, denormals are most interesting
      # however:
      f16s_patterns = np.arange(0, max_pattern + 1, dtype=np.uint16)
      f16s_float = f16s_patterns.view(np.float16).astype(float_t)
  
      # Shift the values by half a bit up or a down (or do not shift),
      if shift == "up":
          f16s_float = 0.5 * (f16s_float[:-1] + f16s_float[1:])[1:]
      elif shift == "down":
          f16s_float = 0.5 * (f16s_float[:-1] + f16s_float[1:])[:-1]
      else:
          f16s_float = f16s_float[1:-1]
  
      # Increase the float by a minimal value:
      if offset == "up":
          f16s_float = np.nextafter(f16s_float, float_t(np.inf))
      elif offset == "down":
          f16s_float = np.nextafter(f16s_float, float_t(-np.inf))
  
      # Convert back to float16 and its bit pattern:
      res_patterns = f16s_float.astype(np.float16).view(np.uint16)
  
      # The above calculations tries the original values, or the exact
      # mid points between the float16 values. It then further offsets them
      # by as little as possible. If no offset occurs, "round to even"
      # logic will be necessary, an arbitrarily small offset should cause
      # normal up/down rounding always.
  
      # Calculate the expected pattern:
      cmp_patterns = f16s_patterns[1:-1].copy()
  
      if shift == "down" and offset != "up":
          shift_pattern = -1
      elif shift == "up" and offset != "down":
          shift_pattern = 1
      else:
          # There cannot be a shift, either shift is None, so all rounding
          # will go back to original, or shift is reduced by offset too much.
          shift_pattern = 0
  
      # If rounding occurs, is it normal rounding or round to even?
      if offset is None:
          # Round to even occurs, modify only non-even, cast to allow + (-1)
          cmp_patterns[0::2].view(np.int16)[...] += shift_pattern
      else:
          cmp_patterns.view(np.int16)[...] += shift_pattern
  
      assert_equal(res_patterns, cmp_patterns)
  
imports: import platform
  import pytest
  import numpy
  from numpy import uint16, float16, float32, float64
  from numpy.testing import assert_, assert_equal, _OLD_PROMOTION, IS_WASM
label_desc: Use image node_id 5 for calling the TestHalf obj's underlying member method code with example usage: obj.test_half_conversion_rounding(float_t, shift, offset) without return types