code: def _check_finite(array, xp):
      """Check for NaNs or Infs."""
      msg = "array must not contain infs or NaNs"
      try:
          if not xp.all(xp.isfinite(array)):
              raise ValueError(msg)
      except TypeError:
          raise ValueError(msg)
  
imports: from __future__ import annotations
  import os
  import warnings
  import numpy
  from scipy._lib import array_api_compat
  from scipy._lib.array_api_compat import is_array_api_obj, size, numpy
label_desc: Use image node_id 2 for calling a global function with example usage: _check_finite(array, xp) without return types