From d3e0ae6fd7ece928c090a64476593031cae77888 Mon Sep 17 00:00:00 2001 From: "mhochsteger@cerbsim.com" Date: Mon, 21 Feb 2022 11:18:17 +0100 Subject: [PATCH] use ngcore pybind list caster only for non-numpy types we should Array for all numpy dtypes T --- libsrc/core/python_ngcore.hpp | 35 ++++++++++++++++------------ libsrc/core/python_ngcore_export.cpp | 5 ++++ 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/libsrc/core/python_ngcore.hpp b/libsrc/core/python_ngcore.hpp index dc54b1e1..c4b04096 100644 --- a/libsrc/core/python_ngcore.hpp +++ b/libsrc/core/python_ngcore.hpp @@ -15,6 +15,24 @@ #include "profiler.hpp" namespace py = pybind11; +namespace ngcore +{ + namespace detail + { + template + struct HasPyFormat + { + private: + template + static auto check(T2*) -> std::enable_if_t>().format()), std::string>, std::true_type>; + static auto check(...) -> std::false_type; + public: + static constexpr bool value = decltype(check((T*) nullptr))::value; + }; + } // namespace detail +} // namespace ngcore + + //////////////////////////////////////////////////////////////////////////////// // automatic conversion of python list to Array<> namespace pybind11 { @@ -57,7 +75,8 @@ public: PYBIND11_TYPE_CASTER(Type, _("Array[") + value_conv::name + _("]")); }; -template struct type_caster> + +template struct type_caster, enable_if_t::value>> : ngcore_list_caster, Type> { }; @@ -151,20 +170,6 @@ namespace ngcore return arr; } - namespace detail - { - template - struct HasPyFormat - { - private: - template - static auto check(T2*) -> std::enable_if_t>().format()), std::string>, std::true_type>; - static auto check(...) -> std::false_type; - public: - static constexpr bool value = decltype(check((T*) nullptr))::value; - }; - } // namespace detail - template ::index_type> void ExportArray (py::module &m) { diff --git a/libsrc/core/python_ngcore_export.cpp b/libsrc/core/python_ngcore_export.cpp index b53c6f47..a6730f4d 100644 --- a/libsrc/core/python_ngcore_export.cpp +++ b/libsrc/core/python_ngcore_export.cpp @@ -18,6 +18,11 @@ PYBIND11_MODULE(pyngcore, m) // NOLINT ExportArray(m); ExportArray(m); ExportArray(m); + ExportArray(m); + ExportArray(m); + ExportArray(m); + ExportArray(m); + ExportArray(m); ExportTable(m);