From 828db1b92fbf70e7eb70d16dd7574211e4902d2d Mon Sep 17 00:00:00 2001 From: "bechir.braham@psi.ch" Date: Fri, 19 Jul 2024 18:34:35 +0200 Subject: [PATCH] reach deadend again? --- CMakeLists.txt | 6 -- aare-environment.yml | 2 +- src/core/include/aare/core/Cluster.hpp | 2 +- src/python/cpp/core.hpp | 88 ++++++++++++++++++++++---- 4 files changed, 77 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 85d971a6..26ef2f75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,6 @@ option(AARE_FETCH_PYBIND11 "Use FetchContent to download pybind11" ON) option(AARE_FETCH_CATCH "Use FetchContent to download catch2" ON) option(AARE_FETCH_JSON "Use FetchContent to download nlohmann::json" ON) option(AARE_FETCH_ZMQ "Use FetchContent to download libzmq" ON) -option(AARE_FETCH_SIMDJSON "Use FetchContent to download simdjson" ON) option(ENABLE_DRAFTS "Enable zmq drafts (depends on gnutls or nss)" OFF) @@ -45,7 +44,6 @@ if(AARE_SYSTEM_LIBRARIES) set(AARE_FETCH_CATCH OFF CACHE BOOL "Disabled FetchContent for catch2" FORCE) set(AARE_FETCH_JSON OFF CACHE BOOL "Disabled FetchContent for nlohmann::json" FORCE) set(AARE_FETCH_ZMQ OFF CACHE BOOL "Disabled FetchContent for libzmq" FORCE) - set(AARE_FETCH_SIMDJSON OFF CACHE BOOL "Disabled FetchContent for simdjson" FORCE) endif() @@ -101,7 +99,6 @@ endif() add_library(aare_compiler_flags INTERFACE) target_compile_features(aare_compiler_flags INTERFACE cxx_std_17) -if(AARE_FETCH_SIMDJSON) FetchContent_Declare( simdjson GIT_REPOSITORY https://github.com/simdjson/simdjson.git @@ -114,9 +111,6 @@ set_target_properties(simdjson PROPERTIES POSITION_INDEPENDENT_CODE ON) # hide simdjson warnings by making the includes system includes get_target_property(_inc simdjson INTERFACE_INCLUDE_DIRECTORIES) target_include_directories(simdjson SYSTEM INTERFACE ${_inc}) -else() -find_package(simdjson 3.8.0 REQUIRED) -endif() ################# # MSVC specific # diff --git a/aare-environment.yml b/aare-environment.yml index 430d1615..3a8bb01a 100644 --- a/aare-environment.yml +++ b/aare-environment.yml @@ -9,4 +9,4 @@ dependencies: - catch2==3.6.0 - zeromq==4.3.5 - simdjson==3.8.0 - # - gxx==14 avaialable for linux and windows but not for mac + # - gxx==14.1.0 diff --git a/src/core/include/aare/core/Cluster.hpp b/src/core/include/aare/core/Cluster.hpp index e94bbdd4..981b90c3 100644 --- a/src/core/include/aare/core/Cluster.hpp +++ b/src/core/include/aare/core/Cluster.hpp @@ -138,7 +138,7 @@ template struct ClusterData std::array array; ClusterData() : x(0), y(0), array({}) {} - ClusterData(int16_t x_, int16_t y_, std::array array_) + ClusterData(int16_t x_, int16_t y_, std::array array_) : x(x_), y(y_), array(array_) {} void set(std::byte *data_) { std::memcpy(&x, data_, sizeof(x)); diff --git a/src/python/cpp/core.hpp b/src/python/cpp/core.hpp index 1a8d20ca..c2fef62b 100644 --- a/src/python/cpp/core.hpp +++ b/src/python/cpp/core.hpp @@ -1,4 +1,8 @@ +#include "aare/core/Cluster.hpp" +#include "aare/core/Frame.hpp" +#include "aare/core/Transforms.hpp" +#include "aare/core/defs.hpp" #include #include #include @@ -7,17 +11,69 @@ #include #include -#include "aare/core/Frame.hpp" -#include "aare/core/Transforms.hpp" -#include "aare/core/Cluster.hpp" -#include "aare/core/defs.hpp" +template void define_clusterData_bindings(py::module &m) { + std::string class_name = + "ClusterData_" + Dtype(typeid(T)).to_string() + "_" + std::to_string(N); + py::class_>(m, class_name.c_str()) + .def(py::init<>()) + .def(py::init>()) + .def_readwrite("x", &ClusterData::x) + .def_readwrite("y", &ClusterData::y) + .def_readwrite("array", &ClusterData::array) + .def_static("get_fields", &ClusterData::get_fields) + .def("__repr__", &ClusterData::to_string); +} +template void LOOP_DEFINE_CLUSTERDATA_BINDINGS(py::module &m) { + define_clusterData_bindings(m); + define_clusterData_bindings(m); + define_clusterData_bindings(m); + define_clusterData_bindings(m); + define_clusterData_bindings(m); + define_clusterData_bindings(m); + define_clusterData_bindings(m); + define_clusterData_bindings(m); + define_clusterData_bindings(m); + define_clusterData_bindings(m); + LOOP_DEFINE_CLUSTERDATA_BINDINGS(m); +} +template <> void LOOP_DEFINE_CLUSTERDATA_BINDINGS<0>(py::module &m) {} +void define_cluster_bindings(py::module &m) { + py::class_(m, "Field") + .def(py::init<>()) + .def(py::init()) + .def_readwrite("label", &Field::label) + .def_readwrite("dtype", &Field::dtype) + .def_readwrite("is_array", &Field::is_array) + .def_readwrite("array_size", &Field::array_size) + .def("to_json", &Field::to_json) + .def("from_json", &Field::from_json); + + py::class_(m, "ClusterHeader") + .def(py::init<>()) + .def(py::init()) + .def("__repr__", &ClusterHeader::to_string) + .def_static("get_fields", &ClusterHeader::get_fields) + .def_readwrite("frame_number", &ClusterHeader::frame_number) + .def_readwrite("n_clusters", &ClusterHeader::n_clusters); + + py::class_(m, "ClusterDataVlen") + .def(py::init<>()) + .def(py::init, std::vector, std::vector>()) + .def_readwrite("x", &ClusterDataVlen::x) + .def_readwrite("y", &ClusterDataVlen::y) + .def_readwrite("energy", &ClusterDataVlen::energy) + .def_static("get_fields", &ClusterDataVlen::get_fields) + .def("__repr__", &ClusterDataVlen::to_string); + + LOOP_DEFINE_CLUSTERDATA_BINDINGS<50>(m); +} template void define_to_frame(py::module &m) { m.def("to_frame", [](py::array_t &np_array) { py::buffer_info info = np_array.request(); if (info.format != py::format_descriptor::format()) - throw std::runtime_error( - "Incompatible format: different formats! (Are you sure the arrays are of the same type?)"); + throw std::runtime_error("Incompatible format: different formats! (Are you sure the " + "arrays are of the same type?)"); if (info.ndim != 2) throw std::runtime_error("Incompatible dimension: expected a 2D array!"); @@ -54,8 +110,9 @@ void define_core_bindings(py::module &m) { .def_readwrite("col", &xy::col) .def("__eq__", &xy::operator==) .def("__ne__", &xy::operator!=) - .def("__repr__", - [](const xy &a) { return ""; }); + .def("__repr__", [](const xy &a) { + return ""; + }); py::enum_(m, "DetectorType") .value("Jungfrau", DetectorType::Jungfrau) @@ -130,8 +187,8 @@ void define_core_bindings(py::module &m) { [](py::array_t &np_array) { py::buffer_info info = np_array.request(); if (info.format != Dtype(Dtype::UINT64).numpy_descr()) - throw std::runtime_error( - "Incompatible format: different formats! (Are you sure the arrays are of the same type?)"); + throw std::runtime_error("Incompatible format: different formats! (Are you " + "sure the arrays are of the same type?)"); if (info.ndim != 2) throw std::runtime_error("Incompatible dimension: expected a 2D array!"); @@ -142,9 +199,14 @@ void define_core_bindings(py::module &m) { return Transforms::reorder(a); }) .def_static("flip_horizental", &Transforms::flip_horizental) - .def("add", [](Transforms &self, std::function transformation) { self.add(transformation); }) - .def("add", [](Transforms &self, - std::vector> transformations) { self.add(transformations); }) + .def("add", + [](Transforms &self, std::function transformation) { + self.add(transformation); + }) + .def("add", + [](Transforms &self, std::vector> transformations) { + self.add(transformations); + }) .def("__call__", &Transforms::apply); define_to_frame(m);