code: def cumsum(
      F, x: Tensor, exclusive: bool = False, reverse: bool = False
  ) -> Tensor:
      r"""
      Find cumulative sum on the last axis by multiplying with lower triangular
      ones-matrix:
  
      .. math::
  
         \operatorname{cumsum}(x) =
         \begin{cases}
           \operatorname{ltr\_ones} \times x
             & \text{for cumulative sum}\\
           x \times \operatorname{ltr\_ones}
             & \text{for cumulative sum in the reverse order}
         \end{cases}
  
      Also supports `exclusive` flag to start the cumsum with zero.
      For example, if :math:`x = [a, b, c]`, we have
  
      .. math::
  
         \operatorname{cumsum}(x) =
         \begin{cases}
           [a, a + b, a + b + c]
             & \text{if }\mathit{reverse = False, exclusive = False}\\
           [0, a, a + b]
             & \text{if }\mathit{reverse = False, exclusive = True}\\
           [a + b + c, b + c, c]
             & \text{if }\mathit{reverse = True, exclusive = False}\\
           [b + c, c, 0]
             & \text{if }\mathit{reverse = True, exclusive = True}\\
         \end{cases}
  
      Parameters
      ----------
      F
          The function space to use.
      x
          A tensor with shape :math:`(..., n)`.
      exclusive
          If `True`, the cumulative sum starts with zero.
      reverse
          If `True`, the cumulative sum is performed in the opposite direction.
  
      Returns
      -------
      Tensor:
          A modified tensor with identical shape and cumulative sums in the last
          axis.
      """
  
      # Create a new axis (for matrix multiplication) either at last location or
      # last-but-one location (for reverse mode)
      exp_dim = -2 if reverse else -1
      # (..., 1, n) if reverse is True and (..., n, 1) otherwise
      x = x.expand_dims(axis=exp_dim)
  
      # Ones_matrix (..., n, n)
      ones_matrix = F.linalg_gemm2(
          F.ones_like(x),
          F.ones_like(x),
          transpose_a=reverse,
          transpose_b=not reverse,
      )
      cumulative_sum = F.linalg_trmm(ones_matrix, x, rightside=reverse)
  
      if exclusive:
          cumulative_sum = cumulative_sum - x
  
      return cumulative_sum.squeeze(axis=exp_dim)
  
imports: import inspect
  import tempfile
  from pathlib import Path
  from typing import List, Optional, Tuple, cast, Type
  import mxnet
  from mxnet.gluon.block import _flatten
  from gluonts.core.serde import dump_json, load_json
  from gluonts.mx import Tensor
label_desc: Use image node_id 9 for calling a global function with example usage: cumsum(F, x, exclusive, reverse) and returns: cumulative_sum