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.
  
      Parameters
      ----------
      arr : array-like
          To be cumulatively summed as flat
      axis : int, optional
          Axis along which the cumulative sum is computed.
          The default (None) is to compute the cumsum over the flattened array.
      rtol : float
          Relative tolerance, see ``np.allclose``
      atol : float
          Absolute tolerance, see ``np.allclose``
      """
      out = np.cumsum(arr, axis=axis, dtype=np.float64)
      expected = np.sum(arr, axis=axis, dtype=np.float64)
      if not np.all(
          np.isclose(
              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 inspect
  import operator
  import os
  import warnings
  from contextlib import contextmanager
  from io import StringIO
  from math import log
  from pprint import pprint
  import numpy
label_desc: Use image node_id 15 for calling a global function with example usage: stable_cumsum(arr, axis, rtol, atol) and returns: out