mirror of
https://github.com/NGSolve/netgen.git
synced 2025-04-01 21:34:31 +05:00
use ngcore pybind list caster only for non-numpy types
we should Array<T> for all numpy dtypes T
This commit is contained in:
parent
775b97f6b3
commit
d3e0ae6fd7
@ -15,6 +15,24 @@
|
|||||||
#include "profiler.hpp"
|
#include "profiler.hpp"
|
||||||
namespace py = pybind11;
|
namespace py = pybind11;
|
||||||
|
|
||||||
|
namespace ngcore
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
template<typename T>
|
||||||
|
struct HasPyFormat
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
template<typename T2>
|
||||||
|
static auto check(T2*) -> std::enable_if_t<std::is_same_v<decltype(std::declval<py::format_descriptor<T2>>().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<>
|
// automatic conversion of python list to Array<>
|
||||||
namespace pybind11 {
|
namespace pybind11 {
|
||||||
@ -57,7 +75,8 @@ public:
|
|||||||
PYBIND11_TYPE_CASTER(Type, _("Array[") + value_conv::name + _("]"));
|
PYBIND11_TYPE_CASTER(Type, _("Array[") + value_conv::name + _("]"));
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Type> struct type_caster<ngcore::Array<Type>>
|
|
||||||
|
template <typename Type> struct type_caster<ngcore::Array<Type>, enable_if_t<!ngcore::detail::HasPyFormat<Type>::value>>
|
||||||
: ngcore_list_caster<ngcore::Array<Type>, Type> { };
|
: ngcore_list_caster<ngcore::Array<Type>, Type> { };
|
||||||
|
|
||||||
|
|
||||||
@ -151,20 +170,6 @@ namespace ngcore
|
|||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
template<typename T>
|
|
||||||
struct HasPyFormat
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
template<typename T2>
|
|
||||||
static auto check(T2*) -> std::enable_if_t<std::is_same_v<decltype(std::declval<py::format_descriptor<T2>>().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 <typename T, typename TIND=typename FlatArray<T>::index_type>
|
template <typename T, typename TIND=typename FlatArray<T>::index_type>
|
||||||
void ExportArray (py::module &m)
|
void ExportArray (py::module &m)
|
||||||
{
|
{
|
||||||
|
@ -18,6 +18,11 @@ PYBIND11_MODULE(pyngcore, m) // NOLINT
|
|||||||
ExportArray<unsigned>(m);
|
ExportArray<unsigned>(m);
|
||||||
ExportArray<size_t>(m);
|
ExportArray<size_t>(m);
|
||||||
ExportArray<double>(m);
|
ExportArray<double>(m);
|
||||||
|
ExportArray<float>(m);
|
||||||
|
ExportArray<signed short>(m);
|
||||||
|
ExportArray<signed char>(m);
|
||||||
|
ExportArray<unsigned short>(m);
|
||||||
|
ExportArray<unsigned char>(m);
|
||||||
|
|
||||||
ExportTable<int>(m);
|
ExportTable<int>(m);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user