code: def _check_scalar(actual, desired, xp):
      # Shape check alone is sufficient unless desired.shape == (). Also,
      # only NumPy distinguishes between scalars and arrays.
      if desired.shape != () or not is_numpy(xp):
          return
      # We want to follow the conventions of the `xp` library. Libraries like
      # NumPy, for which `np.asarray(0)[()]` returns a scalar, tend to return
      # a scalar even when a 0D array might be more appropriate:
      # import numpy as np
      # np.mean([1, 2, 3])  # scalar, not 0d array
      # np.asarray(0)*2  # scalar, not 0d array
      # np.sin(np.asarray(0))  # scalar, not 0d array
      # Libraries like CuPy, for which `cp.asarray(0)[()]` returns a 0D array,
      # tend to return a 0D array in scenarios like those above.
      # Therefore, regardless of whether the developer provides a scalar or 0D
      # array for `desired`, we would typically want the type of `actual` to be
      # the type of `desired[()]`. If the developer wants to override this
      # behavior, they can set `check_shape=False`.
      desired = desired[()]
      _msg = f"Types do not match:\n Actual: {type(actual)}\n Desired: {type(desired)}"
      assert (
          xp.isscalar(actual)
          and xp.isscalar(desired)
          or (not xp.isscalar(actual) and not xp.isscalar(desired))
      ), _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 12 for calling a global function with example usage: _check_scalar(actual, desired, xp) without return types