code: def cast_if_numpy_array(xp, array, chx_expected_dtype):
      """Casts NumPy result array to match the dtype of ChainerX's corresponding
      result.
  
      This function receives result arrays for both NumPy and ChainerX and only
      converts dtype of the NumPy array.
      """
      if xp is chainerx:
          assert isinstance(array, chainerx.ndarray)
          return array
  
      if xp is numpy:
          assert isinstance(array, (numpy.ndarray, numpy.generic))
          # Dtype conversion to allow comparing the correctnesses of the values.
          return array.astype(chx_expected_dtype, copy=False)
  
      assert False
  
imports: import itertools
  import numpy
  import chainerx
label_desc: Use image node_id 2 for calling a global function with example usage: cast_if_numpy_array(xp, array, chx_expected_dtype) and returns: array, array