16 #include <unordered_map>
27 s <<
"El{" << v.
a <<
'}';
43 template <
class Container> Container *
one_to_n(
int n) {
44 auto v =
new Container();
45 for (
int i = 1;
i <= n;
i++)
52 for (
int i = 1;
i <= n;
i++)
58 auto m =
new NestMap();
59 for (
int i = 1;
i <= n;
i++)
60 for (
int j = 1; j <= n; j++)
61 (*
m)[
i].emplace(
int(j*10),
E_nc(100*j));
67 py::bind_vector<std::vector<unsigned int>>(
m,
"VectorInt", py::buffer_protocol());
70 py::class_<El>(
m,
"El")
71 .def(py::init<int>());
72 py::bind_vector<std::vector<El>>(
m,
"VectorEl");
73 py::bind_vector<std::vector<std::vector<El>>>(
m,
"VectorVectorEl");
76 py::bind_map<std::map<std::string, double>>(
m,
"MapStringDouble");
77 py::bind_map<std::unordered_map<std::string, double>>(
m,
"UnorderedMapStringDouble");
80 py::bind_map<std::map<std::string, double const>>(
m,
"MapStringDoubleConst");
81 py::bind_map<std::unordered_map<std::string, double const>>(
m,
"UnorderedMapStringDoubleConst");
83 py::class_<E_nc>(
m,
"ENC")
88 py::bind_vector<std::vector<E_nc>>(
m,
"VectorENC");
89 m.def(
"get_vnc", &
one_to_n<std::vector<E_nc>>);
90 py::bind_vector<std::deque<E_nc>>(
m,
"DequeENC");
91 m.def(
"get_dnc", &
one_to_n<std::deque<E_nc>>);
92 py::bind_map<std::map<int, E_nc>>(
m,
"MapENC");
93 m.def(
"get_mnc", &
times_ten<std::map<int, E_nc>>);
94 py::bind_map<std::unordered_map<int, E_nc>>(
m,
"UmapENC");
95 m.def(
"get_umnc", &
times_ten<std::unordered_map<int, E_nc>>);
97 py::bind_map<std::map<int, std::vector<E_nc>>>(
m,
"MapVecENC");
98 m.def(
"get_nvnc", [](
int n)
100 auto m =
new std::map<int, std::vector<E_nc>>();
101 for (
int i = 1;
i <= n;
i++)
102 for (
int j = 1; j <= n; j++)
103 (*
m)[
i].emplace_back(j);
106 py::bind_map<std::map<int, std::map<int, E_nc>>>(
m,
"MapMapENC");
107 m.def(
"get_nmnc", &
times_hundred<std::map<
int, std::map<int, E_nc>>>);
108 py::bind_map<std::unordered_map<int, std::unordered_map<int, E_nc>>>(
m,
"UmapUmapENC");
109 m.def(
"get_numnc", &
times_hundred<std::unordered_map<
int, std::unordered_map<int, E_nc>>>);
112 py::bind_vector<std::vector<unsigned char>>(
m,
"VectorUChar", py::buffer_protocol());
114 struct VUndeclStruct {
bool w; uint32_t
x;
double y;
bool z; };
115 m.def(
"create_undeclstruct", [
m] ()
mutable {
116 py::bind_vector<std::vector<VUndeclStruct>>(
m,
"VectorUndeclStruct", py::buffer_protocol());
120 try { py::module_::import(
"numpy"); }
121 catch (...) {
return; }
124 struct VStruct {
bool w; uint32_t
x;
double y;
bool z; };
126 py::class_<VStruct>(
m,
"VStruct").def_readwrite(
"x", &
VStruct::x);
127 py::bind_vector<std::vector<VStruct>>(
m,
"VectorStruct", py::buffer_protocol());
128 m.def(
"get_vectorstruct", [] {
return std::vector<VStruct> {{0, 5, 3.0, 1}, {1, 30, -1e4, 0}};});