LCOV - code coverage report
Current view: top level - python - comparison.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 19 22 86.4 %
Date: 2024-04-28 01:25:40 Functions: 9 9 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/core/string.h"
       8             : #include "scipp/dataset/dataset.h"
       9             : #include "scipp/variable/comparison.h"
      10             : 
      11             : using namespace scipp;
      12             : using namespace scipp::variable;
      13             : using namespace scipp::dataset;
      14             : 
      15             : namespace py = pybind11;
      16             : 
      17           3 : template <class T> void bind_isclose(py::module &m) {
      18           3 :   m.def(
      19             :       "isclose",
      20         300 :       [](const T &x, const T &y, const T &rtol, const T &atol,
      21             :          const bool equal_nan) {
      22             :         return isclose(x, y, rtol, atol,
      23             :                        equal_nan ? NanComparisons::Equal
      24         300 :                                  : NanComparisons::NotEqual);
      25             :       },
      26           0 :       py::arg("x"), py::arg("y"), py::arg("rtol"), py::arg("atol"),
      27           0 :       py::arg("equal_nan"), py::call_guard<py::gil_scoped_release>());
      28           3 : }
      29             : 
      30           9 : template <typename T> void bind_identical(py::module &m) {
      31           9 :   m.def(
      32             :       "identical",
      33        5714 :       [](const T &x, const T &y, const bool equal_nan) {
      34        5714 :         if (equal_nan) {
      35          15 :           return equals_nan(x, y);
      36             :         }
      37        5699 :         return x == y;
      38             :       },
      39           0 :       py::arg("x"), py::arg("y"), py::arg("equal_nan"),
      40           9 :       py::call_guard<py::gil_scoped_release>());
      41           9 : }
      42             : 
      43           3 : void init_comparison(py::module &m) {
      44           3 :   bind_isclose<Variable>(m);
      45           3 :   bind_identical<Variable>(m);
      46           3 :   bind_identical<Dataset>(m);
      47           3 :   bind_identical<DataArray>(m);
      48           3 : }

Generated by: LCOV version 1.14