code: def group_sum_and_cumsum(
      scores_mat: Tensor,
      end_group_idx: Tensor,
      group_idx: Union[Tensor, slice, None] = None,
  ) -> Tuple[Tensor, Union[Tensor, None]]:
      cumulative_scores = torch.cumsum(scores_mat, dim=1)
      ending_cumusums = cumulative_scores[:, end_group_idx]
      shifted_ending_cumusums = torch.cat(
          [
              torch.zeros(
                  size=(ending_cumusums.shape[0], 1),
                  dtype=ending_cumusums.dtype,
                  device=scores_mat.device,
              ),
              ending_cumusums[:, :-1],
          ],
          dim=1,
      )
      grouped_sums = ending_cumusums - shifted_ending_cumusums
  
      if group_idx is not None:
          grouped_cumsums = (
              cumulative_scores - shifted_ending_cumusums[:, group_idx]
          )
          return grouped_sums, grouped_cumsums
      return grouped_sums, None
  
file_path: kornia/kornia/feature/adalam/ransac.py
imports: from typing import Any, Dict, Tuple, Union
  import torch
  from kornia.core import Tensor
  from .utils import arange_sequence, batch_2x2_ellipse, batch_2x2_inv, draw_first_k_couples, piecewise_arange
label_desc: Use image node_id 2 for calling a global function with example usage: group_sum_and_cumsum(scores_mat, end_group_idx, group_idx) and returns: grouped_sums,  None, grouped_sums,  grouped_cumsums