Coverage for install/scipp/core/cumulative.py: 42%
12 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-11-17 01:51 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-11-17 01:51 +0000
1# SPDX-License-Identifier: BSD-3-Clause
2# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
3# @author Simon Heybrock
5from typing import Literal
7from .._scipp import core as _cpp
8from ..typing import VariableLikeType
9from ._cpp_wrapper_util import call_func as _call_cpp_func
10from .concepts import transform_data
11from .cpp_classes import Variable
14def cumsum(
15 a: VariableLikeType,
16 dim: str | None = None,
17 mode: Literal['exclusive', 'inclusive'] = 'inclusive',
18) -> VariableLikeType:
19 """Return the cumulative sum along the specified dimension.
21 See :py:func:`scipp.sum` on how rounding errors for float32 inputs are handled.
23 Parameters
24 ----------
25 a: scipp.typing.VariableLike
26 Input data.
27 dim:
28 Optional dimension along which to calculate the sum. If not
29 given, the cumulative sum along all dimensions is calculated.
30 mode:
31 Include or exclude the ith element (along dim) in the sum.
32 Options are 'inclusive' and 'exclusive'. Defaults to 'inclusive'.
34 Returns
35 -------
36 : Same type as input
37 The cumulative sum of the input values.
38 """
40 def _cumsum(data: Variable) -> Variable:
41 if dim is None:
42 return _call_cpp_func(_cpp.cumsum, data, mode=mode) # type: ignore[return-value]
43 else:
44 return _call_cpp_func(_cpp.cumsum, data, dim, mode=mode) # type: ignore[return-value]
46 return transform_data(a, _cumsum)