LCOV - code coverage report
Current view: top level - python - cumulative.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 17 19 89.5 %
Date: 2024-11-24 01:48:31 Functions: 5 5 100.0 %

          Line data    Source code
       1             : // SPDX-License-Identifier: BSD-3-Clause
       2             : // Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
       3             : /// @file
       4             : /// @author Simon Heybrock
       5             : #include "pybind11.h"
       6             : 
       7             : #include "scipp/variable/cumulative.h"
       8             : 
       9             : using namespace scipp;
      10             : using namespace scipp::variable;
      11             : 
      12             : namespace py = pybind11;
      13             : 
      14        3292 : auto cumsum_mode(const std::string &mode) {
      15        3292 :   if (mode == "inclusive")
      16        3290 :     return CumSumMode::Inclusive;
      17           2 :   if (mode == "exclusive")
      18           2 :     return CumSumMode::Exclusive;
      19           0 :   throw std::runtime_error("mode must be either 'exclusive' or 'inclusive'");
      20             : }
      21             : 
      22           3 : template <class T> void bind_cumsum(py::module &m) {
      23           3 :   m.def(
      24             :       "cumsum",
      25        3290 :       [](const T &a, const std::string &mode) {
      26        3290 :         return cumsum(a, cumsum_mode(mode));
      27             :       },
      28           6 :       py::arg("a"), py::arg("mode") = "inclusive",
      29           0 :       py::call_guard<py::gil_scoped_release>());
      30           3 :   m.def(
      31             :       "cumsum",
      32           2 :       [](const T &a, const std::string &dim, const std::string &mode) {
      33           2 :         return cumsum(a, Dim{dim}, cumsum_mode(mode));
      34             :       },
      35           6 :       py::arg("a"), py::arg("dim"), py::arg("mode") = "inclusive",
      36           3 :       py::call_guard<py::gil_scoped_release>());
      37           3 : }
      38             : 
      39           3 : void init_cumulative(py::module &m) { bind_cumsum<Variable>(m); }

Generated by: LCOV version 1.14