Coverage for install/scipp/core/cumulative.py: 45%

11 statements  

« prev     ^ index     » next       coverage.py v7.4.0, created at 2024-04-28 01:28 +0000

1# SPDX-License-Identifier: BSD-3-Clause 

2# Copyright (c) 2023 Scipp contributors (https://github.com/scipp) 

3# @author Simon Heybrock 

4 

5from typing import Literal, Optional 

6 

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 

11 

12 

13def cumsum( 

14 a: VariableLikeType, 

15 dim: Optional[str] = None, 

16 mode: Literal['exclusive', 'inclusive'] = 'inclusive', 

17) -> VariableLikeType: 

18 """Return the cumulative sum along the specified dimension. 

19 

20 See :py:func:`scipp.sum` on how rounding errors for float32 inputs are handled. 

21 

22 Parameters 

23 ---------- 

24 a: scipp.typing.VariableLike 

25 Input data. 

26 dim: 

27 Optional dimension along which to calculate the sum. If not 

28 given, the cumulative sum along all dimensions is calculated. 

29 mode: 

30 Include or exclude the ith element (along dim) in the sum. 

31 Options are 'inclusive' and 'exclusive'. Defaults to 'inclusive'. 

32 

33 Returns 

34 ------- 

35 : Same type as input 

36 The cumulative sum of the input values. 

37 """ 

38 

39 def _cumsum(data): 

40 if dim is None: 

41 return _call_cpp_func(_cpp.cumsum, data, mode=mode) 

42 else: 

43 return _call_cpp_func(_cpp.cumsum, data, dim, mode=mode) 

44 

45 return transform_data(a, _cumsum)