1 #include "pybind11/pybind11.h"
2 #include "pybind11/stl_bind.h"
4 #define FORCE_IMPORT_ARRAY
9 #if defined(__GNUC__) && !defined(__clang__)
12 inline void complex_allocator()
14 std::allocator<int> ai;
15 std::allocator<double> ad;
21 namespace py = pybind11;
25 const std::string DARRAY_DICT_NAME =
"DArrayDict";
26 const std::string IARRAY_DICT_NAME =
"IArrayDict";
27 const std::string DSCALAR_DICT_NAME =
"DScalarDict";
28 const std::string ISCALAR_DICT_NAME =
"IScalarDict";
35 template <
class OS,
class M>
36 OS&
print_map(OS& os,
const std::string& name,
const M& m)
40 for(
const auto& kv: m)
46 os << kv.first <<
": " << kv.second;
58 using key_type =
typename map_type::key_type;
59 using mapped_type =
typename map_type::mapped_type;
64 [](map_type& m, key_type& k, mapped_type&
v)
66 m.insert_or_assign(std::move(k), std::move(
v));
73 std::ostringstream oss;
76 "Return the canonical representation of this map."
80 [](map_type& m) ->
bool
84 "Check wether the map is nonempty"
88 [](map_type& m,
const key_type& k) -> mapped_type&
102 cl.def(py::init<>());
110 cl.def(
"__setitem__",
113 ad.
m_iarray.insert_or_assign(std::move(k), std::move(a));
115 cl.def(
"__setitem__",
118 ad.
m_darray.insert_or_assign(std::move(k), std::move(a));
125 cl.def(
"__setitem__",
128 ad.
m_iscalar.insert_or_assign(std::move(k), std::move(i));
130 cl.def(
"__setitem__",
133 ad.
m_dscalar.insert_or_assign(std::move(k), std::move(d));
138 std::ostringstream oss;
139 oss << name <<
"{\n";
140 oss <<
" " <<
"m_darray: ";
142 oss <<
"\n " <<
"m_iarray: ";
144 oss <<
"\n " <<
"m_dscalar: ";
146 oss <<
"\n " <<
"m_iscalar: ";
162 using dpyarray_dict = pyarray_dict<std::string, double>;
163 using ipyarray_dict = pyarray_dict<std::string, int>;
164 using dscalar_dict = scalar_dict<std::string, double>;
165 using iscalar_dict = scalar_dict<std::string, int>;
167 py::class_<dpyarray_dict> dad(m, DARRAY_DICT_NAME.c_str());
170 py::class_<ipyarray_dict> iad(m, IARRAY_DICT_NAME.c_str());
173 py::class_<dscalar_dict> dsd(m, DSCALAR_DICT_NAME.c_str());
176 py::class_<iscalar_dict> isd(m, ISCALAR_DICT_NAME.c_str());
179 py::class_<arguments_dict> ad(m,
"ArgumentsDict");