code: def finite_range(
      arr: npt.ArrayLike,
      check_nan: bool = False,
  ) -> tuple[Scalar, Scalar, bool] | tuple[Scalar, Scalar]:
      """Get range (min, max) or range and flag (min, max, has_nan) from `arr`
  
      Parameters
      ----------
      arr : array-like
      check_nan : {False, True}, optional
          Whether to return third output, a bool signaling whether there are NaN
          values in `arr`
  
      Returns
      -------
      mn : scalar
         minimum of values in (flattened) array
      mx : scalar
         maximum of values in (flattened) array
      has_nan : bool
         Returned if `check_nan` is True. `has_nan` is True if there are one or
         more NaN values in `arr`
  
      Examples
      --------
      >>> a = np.array([[-1, 0, 1],[np.inf, np.nan, -np.inf]])
      >>> finite_range(a)
      (-1.0, 1.0)
      >>> a = np.array([[-1, 0, 1],[np.inf, np.nan, -np.inf]])
      >>> finite_range(a, check_nan=True)
      (-1.0, 1.0, True)
      >>> a = np.array([[np.nan],[np.nan]])
      >>> finite_range(a) == (np.inf, -np.inf)
      True
      >>> a = np.array([[-3, 0, 1],[2,-1,4]], dtype=int)
      >>> finite_range(a)
      (-3, 4)
      >>> a = np.array([[1, 0, 1],[2,3,4]], dtype=np.uint)
      >>> finite_range(a)
      (0, 4)
      >>> a = a + 1j
      >>> finite_range(a)
      (1j, (4+1j))
      >>> a = np.zeros((2,), dtype=[('f1', 'i2')])
      >>> finite_range(a)
      Traceback (most recent call last):
         ...
      TypeError: Can only handle numeric types
      """
      arr = np.asarray(arr)
      if arr.size == 0:
          if check_nan:
              return (np.inf, -np.inf, False)
          return (np.inf, -np.inf)
      # Resort array to slowest->fastest memory change indices
      stride_order = np.argsort(arr.strides)[::-1]
      sarr = arr.transpose(stride_order)
      kind = sarr.dtype.kind
      if kind in "iu":
          if check_nan:
              return np.min(sarr), np.max(sarr), False
          return np.min(sarr), np.max(sarr)
      if kind not in "cf":
          raise TypeError("Can only handle numeric types")
      # Deal with 1D arrays in loop below
      sarr = np.atleast_2d(sarr)
      # Loop to avoid big temporary arrays
      has_nan = False
      n_slices = sarr.shape[0]
      maxes = np.zeros(n_slices, dtype=sarr.dtype) - np.inf
      mins = np.zeros(n_slices, dtype=sarr.dtype) + np.inf
      for s in range(n_slices):
          this_slice = sarr[s]  # view
          if not has_nan:
              maxes[s] = np.max(this_slice)
              # May have a non-nan non-inf max before we trip on min. If so,
              # record so we don't recalculate
              max_good = False
              if np.isnan(maxes[s]):
                  has_nan = True
              elif maxes[s] != np.inf:
                  max_good = True
                  mins[s] = np.min(this_slice)
                  if mins[s] != -np.inf:
                      # Only case where we escape the default np.isfinite
                      # algorithm
                      continue
          tmp = this_slice[np.isfinite(this_slice)]
          if tmp.size == 0:  # No finite values
              # Reset max, min in case set in tests above
              maxes[s] = -np.inf
              mins[s] = np.inf
              continue
          if not max_good:
              maxes[s] = np.max(tmp)
          mins[s] = np.min(tmp)
      if check_nan:
          return np.nanmin(mins), np.nanmax(maxes), has_nan
      return np.nanmin(mins), np.nanmax(maxes)
  
imports: from __future__ import annotations
  import io
  import sys
  import typing
  import warnings
  from functools import reduce
  from operator import getitem, mul
  from os.path import exists, splitext
  import numpy
  from ._compression import COMPRESSED_FILE_LIKES
  from .casting import OK_FLOATS, shared_range
  from .externals.oset import OrderedSet
label_desc: Use image node_id 19 for calling a global function with example usage: finite_range(arr, check_nan) and returns: np,  np, np,  unknown, np,  np, np,  np,  has_nan, np,  unknown,  False, np,  np,  False