code: def stable_cumsum(arr, axis=None, rtol=1e-05, atol=1e-08):
      """Use high precision for cumsum and check that final value matches sum.
  
      Warns if the final cumulative sum does not match the sum (up to the chosen
      tolerance).
  
      Parameters
      ----------
      arr : array-like
          To be cumulatively summed as flat.
      axis : int, default=None
          Axis along which the cumulative sum is computed.
          The default (None) is to compute the cumsum over the flattened array.
      rtol : float, default=1e-05
          Relative tolerance, see ``np.allclose``.
      atol : float, default=1e-08
          Absolute tolerance, see ``np.allclose``.
  
      Returns
      -------
      out : ndarray
          Array with the cumulative sums along the chosen axis.
      """
      out = np.cumsum(arr, axis=axis, dtype=np.float64)
      expected = np.sum(arr, axis=axis, dtype=np.float64)
      if not np.allclose(
          out.take(-1, axis=axis),
          expected,
          rtol=rtol,
          atol=atol,
          equal_nan=True,
      ):
          warnings.warn(
              (
                  "cumsum was found to be unstable: "
                  "its last element does not correspond to sum"
              ),
              RuntimeWarning,
          )
      return out
  
imports: import warnings
  from functools import partial
  from numbers import Integral
  import numpy
  from scipy import linalg, sparse
  from ..utils import deprecated
  from ..utils._param_validation import Interval, StrOptions, validate_params
  from .None import check_random_state
  from ._array_api import _is_numpy_namespace, device, get_namespace
  from .sparsefuncs_fast import csr_row_norms
  from .validation import check_array
label_desc: Use image node_id 18 for calling a global function with example usage: stable_cumsum(arr, axis, rtol, atol) and returns: out