#include "aare/Cluster.hpp" #include #include #include #include #include #include #include namespace py = pybind11; using pd_type = double; using namespace aare; #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" template void define_Cluster(py::module &m, const std::string &typestr) { auto class_name = fmt::format("Cluster{}", typestr); py::class_>( m, class_name.c_str(), py::buffer_protocol()) .def(py::init([](uint8_t x, uint8_t y, py::array_t data) { py::buffer_info buf_info = data.request(); Cluster cluster; cluster.x = x; cluster.y = y; auto r = data.template unchecked<1>(); // no bounds checks for (py::ssize_t i = 0; i < data.size(); ++i) { cluster.data[i] = r(i); } return cluster; })) // TODO! Review if to keep or not .def_property_readonly( "data", [](Cluster &c) -> py::array { return py::array(py::buffer_info( c.data.data(), sizeof(Type), py::format_descriptor::format(), // Type // format 2, // Number of dimensions {static_cast(ClusterSizeX), static_cast(ClusterSizeY)}, // Shape (flattened) {sizeof(Type) * ClusterSizeY, sizeof(Type)} // Stride (step size between elements) )); }) .def_readonly("x", &Cluster::x) .def_readonly("y", &Cluster::y); } template void reduce_to_3x3(py::module &m) { m.def( "reduce_to_3x3", [](const Cluster &cl) { return reduce_to_3x3(cl); }, py::return_value_policy::move, "Reduce cluster to 3x3 subcluster by taking the 3x3 subcluster with " "the highest photon energy."); } template void reduce_to_2x2(py::module &m) { m.def( "reduce_to_2x2", [](const Cluster &cl) { return reduce_to_2x2(cl); }, py::return_value_policy::move, "Reduce cluster to 2x2 subcluster by taking the 2x2 subcluster with " "the highest photon energy."); } #pragma GCC diagnostic pop