cppyabm  1.0.17
An agent-based library to integrate C++ and Python
test_numpy_dtypes.cpp
Go to the documentation of this file.
1 /*
2  tests/test_numpy_dtypes.cpp -- Structured and compound NumPy dtypes
3 
4  Copyright (c) 2016 Ivan Smirnov
5 
6  All rights reserved. Use of this source code is governed by a
7  BSD-style license that can be found in the LICENSE file.
8 */
9 
10 #include "pybind11_tests.h"
11 #include <pybind11/numpy.h>
12 
13 #ifdef __GNUC__
14 #define PYBIND11_PACKED(cls) cls __attribute__((__packed__))
15 #else
16 #define PYBIND11_PACKED(cls) __pragma(pack(push, 1)) cls __pragma(pack(pop))
17 #endif
18 
19 namespace py = pybind11;
20 
21 struct SimpleStruct {
22  bool bool_;
23  uint32_t uint_;
24  float float_;
25  long double ldbl_;
26 };
27 
28 std::ostream& operator<<(std::ostream& os, const SimpleStruct& v) {
29  return os << "s:" << v.bool_ << "," << v.uint_ << "," << v.float_ << "," << v.ldbl_;
30 }
31 
33  bool bool_;
34  float float_;
35  uint32_t uint_;
36  long double ldbl_;
37 };
38 
39 PYBIND11_PACKED(struct PackedStruct {
40  bool bool_;
41  uint32_t uint_;
42  float float_;
43  long double ldbl_;
44 });
45 
46 std::ostream& operator<<(std::ostream& os, const PackedStruct& v) {
47  return os << "p:" << v.bool_ << "," << v.uint_ << "," << v.float_ << "," << v.ldbl_;
48 }
49 
50 PYBIND11_PACKED(struct NestedStruct {
51  SimpleStruct a;
52  PackedStruct b;
53 });
54 
55 std::ostream& operator<<(std::ostream& os, const NestedStruct& v) {
56  return os << "n:a=" << v.a << ";b=" << v.b;
57 }
58 
59 struct PartialStruct {
60  bool bool_;
61  uint32_t uint_;
62  float float_;
63  uint64_t dummy2;
64  long double ldbl_;
65 };
66 
68  uint64_t dummy1;
70  uint64_t dummy2;
71 };
72 
73 struct UnboundStruct { };
74 
75 struct StringStruct {
76  char a[3];
77  std::array<char, 3> b;
78 };
79 
80 struct ComplexStruct {
81  std::complex<float> cflt;
82  std::complex<double> cdbl;
83 };
84 
85 std::ostream& operator<<(std::ostream& os, const ComplexStruct& v) {
86  return os << "c:" << v.cflt << "," << v.cdbl;
87 }
88 
89 struct ArrayStruct {
90  char a[3][4];
91  int32_t b[2];
92  std::array<uint8_t, 3> c;
93  std::array<float, 2> d[4];
94 };
95 
96 PYBIND11_PACKED(struct StructWithUglyNames {
97  int8_t __x__;
98  uint64_t __y__;
99 });
100 
101 enum class E1 : int64_t { A = -1, B = 1 };
102 enum E2 : uint8_t { X = 1, Y = 2 };
103 
104 PYBIND11_PACKED(struct EnumStruct {
105  E1 e1;
106  E2 e2;
107 });
108 
109 std::ostream& operator<<(std::ostream& os, const StringStruct& v) {
110  os << "a='";
111  for (size_t i = 0; i < 3 && v.a[i]; i++) os << v.a[i];
112  os << "',b='";
113  for (size_t i = 0; i < 3 && v.b[i]; i++) os << v.b[i];
114  return os << "'";
115 }
116 
117 std::ostream& operator<<(std::ostream& os, const ArrayStruct& v) {
118  os << "a={";
119  for (int i = 0; i < 3; i++) {
120  if (i > 0)
121  os << ',';
122  os << '{';
123  for (int j = 0; j < 3; j++)
124  os << v.a[i][j] << ',';
125  os << v.a[i][3] << '}';
126  }
127  os << "},b={" << v.b[0] << ',' << v.b[1];
128  os << "},c={" << int(v.c[0]) << ',' << int(v.c[1]) << ',' << int(v.c[2]);
129  os << "},d={";
130  for (int i = 0; i < 4; i++) {
131  if (i > 0)
132  os << ',';
133  os << '{' << v.d[i][0] << ',' << v.d[i][1] << '}';
134  }
135  return os << '}';
136 }
137 
138 std::ostream& operator<<(std::ostream& os, const EnumStruct& v) {
139  return os << "e1=" << (v.e1 == E1::A ? "A" : "B") << ",e2=" << (v.e2 == E2::X ? "X" : "Y");
140 }
141 
142 template <typename T>
143 py::array mkarray_via_buffer(size_t n) {
144  return py::array(py::buffer_info(nullptr, sizeof(T),
145  py::format_descriptor<T>::format(),
146  1, { n }, { sizeof(T) }));
147 }
148 
149 #define SET_TEST_VALS(s, i) do { \
150  s.bool_ = (i) % 2 != 0; \
151  s.uint_ = (uint32_t) (i); \
152  s.float_ = (float) (i) * 1.5f; \
153  s.ldbl_ = (long double) (i) * -2.5L; } while (0)
154 
155 template <typename S>
156 py::array_t<S, 0> create_recarray(size_t n) {
157  auto arr = mkarray_via_buffer<S>(n);
158  auto req = arr.request();
159  auto ptr = static_cast<S*>(req.ptr);
160  for (size_t i = 0; i < n; i++) {
161  SET_TEST_VALS(ptr[i], i);
162  }
163  return arr;
164 }
165 
166 template <typename S>
167 py::list print_recarray(py::array_t<S, 0> arr) {
168  const auto req = arr.request();
169  const auto ptr = static_cast<S*>(req.ptr);
170  auto l = py::list();
171  for (py::ssize_t i = 0; i < req.size; i++) {
172  std::stringstream ss;
173  ss << ptr[i];
174  l.append(py::str(ss.str()));
175  }
176  return l;
177 }
178 
179 py::array_t<int32_t, 0> test_array_ctors(int i) {
180  using arr_t = py::array_t<int32_t, 0>;
181 
182  std::vector<int32_t> data { 1, 2, 3, 4, 5, 6 };
183  std::vector<py::ssize_t> shape { 3, 2 };
184  std::vector<py::ssize_t> strides { 8, 4 };
185 
186  auto ptr = data.data();
187  auto vptr = (void *) ptr;
188  auto dtype = py::dtype("int32");
189 
190  py::buffer_info buf_ndim1(vptr, 4, "i", 6);
191  py::buffer_info buf_ndim1_null(nullptr, 4, "i", 6);
192  py::buffer_info buf_ndim2(vptr, 4, "i", 2, shape, strides);
193  py::buffer_info buf_ndim2_null(nullptr, 4, "i", 2, shape, strides);
194 
195  auto fill = [](py::array arr) {
196  auto req = arr.request();
197  for (int i = 0; i < 6; i++) ((int32_t *) req.ptr)[i] = i + 1;
198  return arr;
199  };
200 
201  switch (i) {
202  // shape: (3, 2)
203  case 10: return arr_t(shape, strides, ptr);
204  case 11: return py::array(shape, strides, ptr);
205  case 12: return py::array(dtype, shape, strides, vptr);
206  case 13: return arr_t(shape, ptr);
207  case 14: return py::array(shape, ptr);
208  case 15: return py::array(dtype, shape, vptr);
209  case 16: return arr_t(buf_ndim2);
210  case 17: return py::array(buf_ndim2);
211  // shape: (3, 2) - post-fill
212  case 20: return fill(arr_t(shape, strides));
213  case 21: return py::array(shape, strides, ptr); // can't have nullptr due to templated ctor
214  case 22: return fill(py::array(dtype, shape, strides));
215  case 23: return fill(arr_t(shape));
216  case 24: return py::array(shape, ptr); // can't have nullptr due to templated ctor
217  case 25: return fill(py::array(dtype, shape));
218  case 26: return fill(arr_t(buf_ndim2_null));
219  case 27: return fill(py::array(buf_ndim2_null));
220  // shape: (6, )
221  case 30: return arr_t(6, ptr);
222  case 31: return py::array(6, ptr);
223  case 32: return py::array(dtype, 6, vptr);
224  case 33: return arr_t(buf_ndim1);
225  case 34: return py::array(buf_ndim1);
226  // shape: (6, )
227  case 40: return fill(arr_t(6));
228  case 41: return py::array(6, ptr); // can't have nullptr due to templated ctor
229  case 42: return fill(py::array(dtype, 6));
230  case 43: return fill(arr_t(buf_ndim1_null));
231  case 44: return fill(py::array(buf_ndim1_null));
232  }
233  return arr_t();
234 }
235 
236 py::list test_dtype_ctors() {
237  py::list list;
238  list.append(py::dtype("int32"));
239  list.append(py::dtype(std::string("float64")));
240  list.append(py::dtype::from_args(py::str("bool")));
241  py::list names, offsets, formats;
242  py::dict dict;
243  names.append(py::str("a")); names.append(py::str("b")); dict["names"] = names;
244  offsets.append(py::int_(1)); offsets.append(py::int_(10)); dict["offsets"] = offsets;
245  formats.append(py::dtype("int32")); formats.append(py::dtype("float64")); dict["formats"] = formats;
246  dict["itemsize"] = py::int_(20);
247  list.append(py::dtype::from_args(dict));
248  list.append(py::dtype(names, formats, offsets, 20));
249  list.append(py::dtype(py::buffer_info((void *) 0, sizeof(unsigned int), "I", 1)));
250  list.append(py::dtype(py::buffer_info((void *) 0, 0, "T{i:a:f:b:}", 1)));
251  return list;
252 }
253 
254 struct A {};
255 struct B {};
256 
257 TEST_SUBMODULE(numpy_dtypes, m) {
258  try { py::module_::import("numpy"); }
259  catch (...) { return; }
260 
261  // typeinfo may be registered before the dtype descriptor for scalar casts to work...
262  py::class_<SimpleStruct>(m, "SimpleStruct")
263  // Explicit construct to ensure zero-valued initialization.
264  .def(py::init([]() { return SimpleStruct(); }))
265  .def_readwrite("bool_", &SimpleStruct::bool_)
266  .def_readwrite("uint_", &SimpleStruct::uint_)
267  .def_readwrite("float_", &SimpleStruct::float_)
268  .def_readwrite("ldbl_", &SimpleStruct::ldbl_)
269  .def("astuple", [](const SimpleStruct& self) {
270  return py::make_tuple(self.bool_, self.uint_, self.float_, self.ldbl_);
271  })
272  .def_static("fromtuple", [](const py::tuple tup) {
273  if (py::len(tup) != 4) {
274  throw py::cast_error("Invalid size");
275  }
276  return SimpleStruct{
277  tup[0].cast<bool>(),
278  tup[1].cast<uint32_t>(),
279  tup[2].cast<float>(),
280  tup[3].cast<long double>()};
281  });
282 
285  PYBIND11_NUMPY_DTYPE(PackedStruct, bool_, uint_, float_, ldbl_);
286  PYBIND11_NUMPY_DTYPE(NestedStruct, a, b);
290  PYBIND11_NUMPY_DTYPE(ArrayStruct, a, b, c, d);
291  PYBIND11_NUMPY_DTYPE(EnumStruct, e1, e2);
292  PYBIND11_NUMPY_DTYPE(ComplexStruct, cflt, cdbl);
293 
294  // ... or after
295  py::class_<PackedStruct>(m, "PackedStruct");
296 
297  PYBIND11_NUMPY_DTYPE_EX(StructWithUglyNames, __x__, "x", __y__, "y");
298 
299  // If uncommented, this should produce a static_assert failure telling the user that the struct
300  // is not a POD type
301 // struct NotPOD { std::string v; NotPOD() : v("hi") {}; };
302 // PYBIND11_NUMPY_DTYPE(NotPOD, v);
303 
304  // Check that dtypes can be registered programmatically, both from
305  // initializer lists of field descriptors and from other containers.
306  py::detail::npy_format_descriptor<A>::register_dtype(
307  {}
308  );
309  py::detail::npy_format_descriptor<B>::register_dtype(
310  std::vector<py::detail::field_descriptor>{}
311  );
312 
313  // test_recarray, test_scalar_conversion
314  m.def("create_rec_simple", &create_recarray<SimpleStruct>);
315  m.def("create_rec_packed", &create_recarray<PackedStruct>);
316  m.def("create_rec_nested", [](size_t n) { // test_signature
317  py::array_t<NestedStruct, 0> arr = mkarray_via_buffer<NestedStruct>(n);
318  auto req = arr.request();
319  auto ptr = static_cast<NestedStruct*>(req.ptr);
320  for (size_t i = 0; i < n; i++) {
321  SET_TEST_VALS(ptr[i].a, i);
322  SET_TEST_VALS(ptr[i].b, i + 1);
323  }
324  return arr;
325  });
326  m.def("create_rec_partial", &create_recarray<PartialStruct>);
327  m.def("create_rec_partial_nested", [](size_t n) {
328  py::array_t<PartialNestedStruct, 0> arr = mkarray_via_buffer<PartialNestedStruct>(n);
329  auto req = arr.request();
330  auto ptr = static_cast<PartialNestedStruct*>(req.ptr);
331  for (size_t i = 0; i < n; i++) {
332  SET_TEST_VALS(ptr[i].a, i);
333  }
334  return arr;
335  });
336  m.def("print_rec_simple", &print_recarray<SimpleStruct>);
337  m.def("print_rec_packed", &print_recarray<PackedStruct>);
338  m.def("print_rec_nested", &print_recarray<NestedStruct>);
339 
340  // test_format_descriptors
341  m.def("get_format_unbound", []() { return py::format_descriptor<UnboundStruct>::format(); });
342  m.def("print_format_descriptors", []() {
343  py::list l;
344  for (const auto &fmt : {
345  py::format_descriptor<SimpleStruct>::format(),
346  py::format_descriptor<PackedStruct>::format(),
347  py::format_descriptor<NestedStruct>::format(),
348  py::format_descriptor<PartialStruct>::format(),
349  py::format_descriptor<PartialNestedStruct>::format(),
350  py::format_descriptor<StringStruct>::format(),
351  py::format_descriptor<ArrayStruct>::format(),
352  py::format_descriptor<EnumStruct>::format(),
353  py::format_descriptor<ComplexStruct>::format()
354  }) {
355  l.append(py::cast(fmt));
356  }
357  return l;
358  });
359 
360  // test_dtype
361  m.def("print_dtypes", []() {
362  py::list l;
363  for (const py::handle &d : {
364  py::dtype::of<SimpleStruct>(),
365  py::dtype::of<PackedStruct>(),
366  py::dtype::of<NestedStruct>(),
367  py::dtype::of<PartialStruct>(),
368  py::dtype::of<PartialNestedStruct>(),
369  py::dtype::of<StringStruct>(),
370  py::dtype::of<ArrayStruct>(),
371  py::dtype::of<EnumStruct>(),
372  py::dtype::of<StructWithUglyNames>(),
373  py::dtype::of<ComplexStruct>()
374  })
375  l.append(py::str(d));
376  return l;
377  });
378  m.def("test_dtype_ctors", &test_dtype_ctors);
379  m.def("test_dtype_methods", []() {
380  py::list list;
381  auto dt1 = py::dtype::of<int32_t>();
382  auto dt2 = py::dtype::of<SimpleStruct>();
383  list.append(dt1); list.append(dt2);
384  list.append(py::bool_(dt1.has_fields())); list.append(py::bool_(dt2.has_fields()));
385  list.append(py::int_(dt1.itemsize())); list.append(py::int_(dt2.itemsize()));
386  return list;
387  });
388  struct TrailingPaddingStruct {
389  int32_t a;
390  char b;
391  };
392  PYBIND11_NUMPY_DTYPE(TrailingPaddingStruct, a, b);
393  m.def("trailing_padding_dtype", []() { return py::dtype::of<TrailingPaddingStruct>(); });
394 
395  // test_string_array
396  m.def("create_string_array", [](bool non_empty) {
397  py::array_t<StringStruct, 0> arr = mkarray_via_buffer<StringStruct>(non_empty ? 4 : 0);
398  if (non_empty) {
399  auto req = arr.request();
400  auto ptr = static_cast<StringStruct*>(req.ptr);
401  for (py::ssize_t i = 0; i < req.size * req.itemsize; i++)
402  static_cast<char*>(req.ptr)[i] = 0;
403  ptr[1].a[0] = 'a'; ptr[1].b[0] = 'a';
404  ptr[2].a[0] = 'a'; ptr[2].b[0] = 'a';
405  ptr[3].a[0] = 'a'; ptr[3].b[0] = 'a';
406 
407  ptr[2].a[1] = 'b'; ptr[2].b[1] = 'b';
408  ptr[3].a[1] = 'b'; ptr[3].b[1] = 'b';
409 
410  ptr[3].a[2] = 'c'; ptr[3].b[2] = 'c';
411  }
412  return arr;
413  });
414  m.def("print_string_array", &print_recarray<StringStruct>);
415 
416  // test_array_array
417  m.def("create_array_array", [](size_t n) {
418  py::array_t<ArrayStruct, 0> arr = mkarray_via_buffer<ArrayStruct>(n);
419  auto ptr = (ArrayStruct *) arr.mutable_data();
420  for (size_t i = 0; i < n; i++) {
421  for (size_t j = 0; j < 3; j++)
422  for (size_t k = 0; k < 4; k++)
423  ptr[i].a[j][k] = char('A' + (i * 100 + j * 10 + k) % 26);
424  for (size_t j = 0; j < 2; j++)
425  ptr[i].b[j] = int32_t(i * 1000 + j);
426  for (size_t j = 0; j < 3; j++)
427  ptr[i].c[j] = uint8_t(i * 10 + j);
428  for (size_t j = 0; j < 4; j++)
429  for (size_t k = 0; k < 2; k++)
430  ptr[i].d[j][k] = float(i) * 100.0f + float(j) * 10.0f + float(k);
431  }
432  return arr;
433  });
434  m.def("print_array_array", &print_recarray<ArrayStruct>);
435 
436  // test_enum_array
437  m.def("create_enum_array", [](size_t n) {
438  py::array_t<EnumStruct, 0> arr = mkarray_via_buffer<EnumStruct>(n);
439  auto ptr = (EnumStruct *) arr.mutable_data();
440  for (size_t i = 0; i < n; i++) {
441  ptr[i].e1 = static_cast<E1>(-1 + ((int) i % 2) * 2);
442  ptr[i].e2 = static_cast<E2>(1 + (i % 2));
443  }
444  return arr;
445  });
446  m.def("print_enum_array", &print_recarray<EnumStruct>);
447 
448  // test_complex_array
449  m.def("create_complex_array", [](size_t n) {
450  py::array_t<ComplexStruct, 0> arr = mkarray_via_buffer<ComplexStruct>(n);
451  auto ptr = (ComplexStruct *) arr.mutable_data();
452  for (size_t i = 0; i < n; i++) {
453  ptr[i].cflt.real(float(i));
454  ptr[i].cflt.imag(float(i) + 0.25f);
455  ptr[i].cdbl.real(double(i) + 0.5);
456  ptr[i].cdbl.imag(double(i) + 0.75);
457  }
458  return arr;
459  });
460  m.def("print_complex_array", &print_recarray<ComplexStruct>);
461 
462  // test_array_constructors
463  m.def("test_array_ctors", &test_array_ctors);
464 
465  // test_compare_buffer_info
466  struct CompareStruct {
467  bool x;
468  uint32_t y;
469  float z;
470  };
471  PYBIND11_NUMPY_DTYPE(CompareStruct, x, y, z);
472  m.def("compare_buffer_info", []() {
473  py::list list;
474  list.append(py::bool_(py::detail::compare_buffer_info<float>::compare(py::buffer_info(nullptr, sizeof(float), "f", 1))));
475  list.append(py::bool_(py::detail::compare_buffer_info<unsigned>::compare(py::buffer_info(nullptr, sizeof(int), "I", 1))));
476  list.append(py::bool_(py::detail::compare_buffer_info<long>::compare(py::buffer_info(nullptr, sizeof(long), "l", 1))));
477  list.append(py::bool_(py::detail::compare_buffer_info<long>::compare(py::buffer_info(nullptr, sizeof(long), sizeof(long) == sizeof(int) ? "i" : "q", 1))));
478  list.append(py::bool_(py::detail::compare_buffer_info<CompareStruct>::compare(py::buffer_info(nullptr, sizeof(CompareStruct), "T{?:x:3xI:y:f:z:}", 1))));
479  return list;
480  });
481  m.def("buffer_to_dtype", [](py::buffer& buf) { return py::dtype(buf.request()); });
482 
483  // test_scalar_conversion
484  auto f_simple = [](SimpleStruct s) { return s.uint_ * 10; };
485  m.def("f_simple", f_simple);
486  m.def("f_packed", [](PackedStruct s) { return s.uint_ * 10; });
487  m.def("f_nested", [](NestedStruct s) { return s.a.uint_ * 10; });
488 
489  // test_vectorize
490  m.def("f_simple_vectorized", py::vectorize(f_simple));
491  auto f_simple_pass_thru = [](SimpleStruct s) { return s; };
492  m.def("f_simple_pass_thru_vectorized", py::vectorize(f_simple_pass_thru));
493 
494  // test_register_dtype
495  m.def("register_dtype", []() { PYBIND11_NUMPY_DTYPE(SimpleStruct, bool_, uint_, float_, ldbl_); });
496 
497  // test_str_leak
498  m.def("dtype_wrapper", [](py::object d) { return py::dtype::from_args(std::move(d)); });
499 }
ComplexStruct::cflt
std::complex< float > cflt
Definition: test_numpy_dtypes.cpp:81
StringStruct
Definition: test_numpy_dtypes.cpp:75
UnboundStruct
Definition: test_numpy_dtypes.cpp:73
test_multiple_inheritance.i
i
Definition: test_multiple_inheritance.py:22
test_array_ctors
py::array_t< int32_t, 0 > test_array_ctors(int i)
Definition: test_numpy_dtypes.cpp:179
cast
T cast(const handle &handle)
Definition: cast.h:1769
operator<<
std::ostream & operator<<(std::ostream &os, const SimpleStruct &v)
Definition: test_numpy_dtypes.cpp:28
test_builtin_casters.x
x
Definition: test_builtin_casters.py:467
X
@ X
Definition: test_numpy_dtypes.cpp:102
data
arr data(const arr &a, Ix... index)
Definition: test_numpy_array.cpp:82
list
Definition: pytypes.h:1345
SimpleStructReordered::bool_
bool bool_
Definition: test_numpy_dtypes.cpp:33
SimpleStructReordered::uint_
uint32_t uint_
Definition: test_numpy_dtypes.cpp:35
SimpleStructReordered::float_
float float_
Definition: test_numpy_dtypes.cpp:34
E2
E2
Definition: test_numpy_dtypes.cpp:102
vectorize
detail::vectorize_helper< Return(*)(Args...), Return, Args... > vectorize(Return(*f)(Args ...))
Definition: numpy.h:1664
SimpleStruct
Definition: test_numpy_dtypes.cpp:21
PartialNestedStruct::dummy2
uint64_t dummy2
Definition: test_numpy_dtypes.cpp:70
ArrayStruct::a
char a[3][4]
Definition: test_numpy_dtypes.cpp:90
StringStruct::b
std::array< char, 3 > b
Definition: test_numpy_dtypes.cpp:77
PartialStruct::uint_
uint32_t uint_
Definition: test_numpy_dtypes.cpp:61
SimpleStructReordered
Definition: test_numpy_dtypes.cpp:32
bool_
Definition: pytypes.h:1087
PartialStruct::float_
float float_
Definition: test_numpy_dtypes.cpp:62
ComplexStruct
Definition: test_numpy_dtypes.cpp:80
arr_t
py::array_t< uint16_t, 0 > arr_t
Definition: test_numpy_array.cpp:79
ArrayStruct::b
int32_t b[2]
Definition: test_numpy_dtypes.cpp:91
SET_TEST_VALS
#define SET_TEST_VALS(s, i)
Definition: test_numpy_dtypes.cpp:149
SimpleStruct::bool_
bool bool_
Definition: test_numpy_dtypes.cpp:22
dict
Definition: pytypes.h:1299
PartialStruct::bool_
bool bool_
Definition: test_numpy_dtypes.cpp:60
dtype
Definition: numpy.h:462
make_tuple
tuple make_tuple()
Definition: cast.h:1866
PYBIND11_NUMPY_DTYPE
#define PYBIND11_NUMPY_DTYPE(Type,...)
Definition: numpy.h:1245
create_recarray
py::array_t< S, 0 > create_recarray(size_t n)
Definition: test_numpy_dtypes.cpp:156
PartialNestedStruct::dummy1
uint64_t dummy1
Definition: test_numpy_dtypes.cpp:68
PartialStruct::ldbl_
long double ldbl_
Definition: test_numpy_dtypes.cpp:64
numpy.h
test_dtype_ctors
py::list test_dtype_ctors()
Definition: test_numpy_dtypes.cpp:236
ssize_t
Py_ssize_t ssize_t
Definition: common.h:353
init
detail::initimpl::constructor< Args... > init()
Binds an existing constructor taking arguments Args...
Definition: pybind11.h:1587
A
Definition: test_numpy_dtypes.cpp:254
PYBIND11_PACKED
#define PYBIND11_PACKED(cls)
Definition: test_numpy_dtypes.cpp:16
ComplexStruct::cdbl
std::complex< double > cdbl
Definition: test_numpy_dtypes.cpp:82
Y
@ Y
Definition: test_numpy_dtypes.cpp:102
SimpleStruct::uint_
uint32_t uint_
Definition: test_numpy_dtypes.cpp:23
move
detail::enable_if_t<!detail::move_never< T >::value, T > move(object &&obj)
Definition: cast.h:1798
TEST_SUBMODULE
TEST_SUBMODULE(numpy_dtypes, m)
Definition: test_numpy_dtypes.cpp:257
arr
py::array arr
Definition: test_numpy_array.cpp:78
list::append
void append(T &&val) const
Definition: pytypes.h:1357
ArrayStruct::d
std::array< float, 2 > d[4]
Definition: test_numpy_dtypes.cpp:93
print_recarray
py::list print_recarray(py::array_t< S, 0 > arr)
Definition: test_numpy_dtypes.cpp:167
StringStruct::a
char a[3]
Definition: test_numpy_dtypes.cpp:76
mkarray_via_buffer
py::array mkarray_via_buffer(size_t n)
Definition: test_numpy_dtypes.cpp:143
PartialStruct::dummy2
uint64_t dummy2
Definition: test_numpy_dtypes.cpp:63
pybind11_tests.h
float_
Definition: pytypes.h:1159
PYBIND11_NUMPY_DTYPE_EX
#define PYBIND11_NUMPY_DTYPE_EX(Type,...)
Definition: numpy.h:1267
ArrayStruct::c
std::array< uint8_t, 3 > c
Definition: test_numpy_dtypes.cpp:92
pybind11
Definition: __init__.py:1
B
Definition: test_numpy_dtypes.cpp:255
PartialNestedStruct
Definition: test_numpy_dtypes.cpp:67
SimpleStruct::ldbl_
long double ldbl_
Definition: test_numpy_dtypes.cpp:25
len
size_t len(handle h)
Get the length of a Python object.
Definition: pytypes.h:1560
ArrayStruct
Definition: test_numpy_dtypes.cpp:89
SimpleStructReordered::ldbl_
long double ldbl_
Definition: test_numpy_dtypes.cpp:36
test_async.m
m
Definition: test_async.py:5
PartialStruct
Definition: test_numpy_dtypes.cpp:59
E1
E1
Definition: test_numpy_dtypes.cpp:101
SimpleStruct::float_
float float_
Definition: test_numpy_dtypes.cpp:24
PartialNestedStruct::a
PartialStruct a
Definition: test_numpy_dtypes.cpp:69