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 "docstring.h" 6 : #include "pybind11.h" 7 : 8 : #include "scipp/dataset/dataset.h" 9 : #include "scipp/dataset/histogram.h" 10 : 11 : using namespace scipp; 12 : using namespace scipp::variable; 13 : using namespace scipp::dataset; 14 : 15 : namespace py = pybind11; 16 : 17 6 : template <class T> void bind_histogram(py::module &m) { 18 6 : auto doc = Docstring() 19 12 : .description( 20 : "Histograms the input event data along the dimensions of " 21 : "the supplied Variable describing the bin edges.") 22 12 : .returns("Histogrammed data with units of counts.") 23 6 : .rtype<T>() 24 12 : .template param<T>("x", "Input data to be histogrammed.") 25 12 : .param("bins", "Bin edges.", "Variable"); 26 6 : m.def( 27 : "histogram", 28 249 : [](const T &x, const Variable &bins) { return histogram(x, bins); }, 29 0 : py::arg("x"), py::arg("bins"), py::call_guard<py::gil_scoped_release>(), 30 6 : doc.c_str()); 31 6 : } 32 : 33 3 : void init_histogram(py::module &m) { 34 3 : bind_histogram<DataArray>(m); 35 3 : bind_histogram<Dataset>(m); 36 3 : }