test_numpy_array.cpp
Go to the documentation of this file.
1 /*
2  tests/test_numpy_array.cpp -- test core array functionality
3 
4  Copyright (c) 2016 Ivan Smirnov <i.s.smirnov@gmail.com>
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/numpy.h>
11 #include <pybind11/stl.h>
12 
13 #include "pybind11_tests.h"
14 
15 #include <cstdint>
16 #include <utility>
17 
18 // Size / dtype checks.
19 struct DtypeCheck {
22 };
23 
24 template <typename T>
26  py::module_ np = py::module_::import("numpy");
27  DtypeCheck check{};
28  check.numpy = np.attr("dtype")(np.attr(name));
29  check.pybind11 = py::dtype::of<T>();
30  return check;
31 }
32 
33 std::vector<DtypeCheck> get_concrete_dtype_checks() {
34  return {// Normalization
35  get_dtype_check<std::int8_t>("int8"),
36  get_dtype_check<std::uint8_t>("uint8"),
37  get_dtype_check<std::int16_t>("int16"),
38  get_dtype_check<std::uint16_t>("uint16"),
39  get_dtype_check<std::int32_t>("int32"),
40  get_dtype_check<std::uint32_t>("uint32"),
41  get_dtype_check<std::int64_t>("int64"),
42  get_dtype_check<std::uint64_t>("uint64")};
43 }
44 
46  std::string name{};
47  int size_cpp{};
48  int size_numpy{};
49  // For debugging.
51 };
52 
53 template <typename T>
56  check.name = py::type_id<T>();
57  check.size_cpp = sizeof(T);
58  check.dtype = py::dtype::of<T>();
59  check.size_numpy = check.dtype.attr("itemsize").template cast<int>();
60  return check;
61 }
62 
63 std::vector<DtypeSizeCheck> get_platform_dtype_size_checks() {
64  return {
65  get_dtype_size_check<short>(),
66  get_dtype_size_check<unsigned short>(),
67  get_dtype_size_check<int>(),
68  get_dtype_size_check<unsigned int>(),
69  get_dtype_size_check<long>(),
70  get_dtype_size_check<unsigned long>(),
71  get_dtype_size_check<long long>(),
72  get_dtype_size_check<unsigned long long>(),
73  };
74 }
75 
76 // Arrays.
77 using arr = py::array;
78 using arr_t = py::array_t<uint16_t, 0>;
80 
81 template <typename... Ix>
82 arr data(const arr &a, Ix... index) {
83  return arr(a.nbytes() - a.offset_at(index...), (const uint8_t *) a.data(index...));
84 }
85 
86 template <typename... Ix>
87 arr data_t(const arr_t &a, Ix... index) {
88  return arr(a.size() - a.index_at(index...), a.data(index...));
89 }
90 
91 template <typename... Ix>
92 arr &mutate_data(arr &a, Ix... index) {
93  auto *ptr = (uint8_t *) a.mutable_data(index...);
94  for (py::ssize_t i = 0; i < a.nbytes() - a.offset_at(index...); i++) {
95  ptr[i] = (uint8_t) (ptr[i] * 2);
96  }
97  return a;
98 }
99 
100 template <typename... Ix>
101 arr_t &mutate_data_t(arr_t &a, Ix... index) {
102  auto ptr = a.mutable_data(index...);
103  for (py::ssize_t i = 0; i < a.size() - a.index_at(index...); i++) {
104  ptr[i]++;
105  }
106  return a;
107 }
108 
109 template <typename... Ix>
110 py::ssize_t index_at(const arr &a, Ix... idx) {
111  return a.index_at(idx...);
112 }
113 template <typename... Ix>
114 py::ssize_t index_at_t(const arr_t &a, Ix... idx) {
115  return a.index_at(idx...);
116 }
117 template <typename... Ix>
118 py::ssize_t offset_at(const arr &a, Ix... idx) {
119  return a.offset_at(idx...);
120 }
121 template <typename... Ix>
122 py::ssize_t offset_at_t(const arr_t &a, Ix... idx) {
123  return a.offset_at(idx...);
124 }
125 template <typename... Ix>
126 py::ssize_t at_t(const arr_t &a, Ix... idx) {
127  return a.at(idx...);
128 }
129 template <typename... Ix>
130 arr_t &mutate_at_t(arr_t &a, Ix... idx) {
131  a.mutable_at(idx...)++;
132  return a;
133 }
134 
135 #define def_index_fn(name, type) \
136  sm.def(#name, [](type a) { return name(a); }); \
137  sm.def(#name, [](type a, int i) { return name(a, i); }); \
138  sm.def(#name, [](type a, int i, int j) { return name(a, i, j); }); \
139  sm.def(#name, [](type a, int i, int j, int k) { return name(a, i, j, k); });
140 
141 template <typename T, typename T2>
142 py::handle auxiliaries(T &&r, T2 &&r2) {
143  if (r.ndim() != 2) {
144  throw std::domain_error("error: ndim != 2");
145  }
146  py::list l;
147  l.append(*r.data(0, 0));
148  l.append(*r2.mutable_data(0, 0));
149  l.append(r.data(0, 1) == r2.mutable_data(0, 1));
150  l.append(r.ndim());
151  l.append(r.itemsize());
152  l.append(r.shape(0));
153  l.append(r.shape(1));
154  l.append(r.size());
155  l.append(r.nbytes());
156  return l.release();
157 }
158 
159 // note: declaration at local scope would create a dangling reference!
160 static int data_i = 42;
161 
162 TEST_SUBMODULE(numpy_array, sm) {
163  try {
164  py::module_::import("numpy");
165  } catch (const py::error_already_set &) {
166  return;
167  }
168 
169  // test_dtypes
170  py::class_<DtypeCheck>(sm, "DtypeCheck")
171  .def_readonly("numpy", &DtypeCheck::numpy)
172  .def_readonly("pybind11", &DtypeCheck::pybind11)
173  .def("__repr__", [](const DtypeCheck &self) {
174  return py::str("<DtypeCheck numpy={} pybind11={}>").format(self.numpy, self.pybind11);
175  });
176  sm.def("get_concrete_dtype_checks", &get_concrete_dtype_checks);
177 
178  py::class_<DtypeSizeCheck>(sm, "DtypeSizeCheck")
179  .def_readonly("name", &DtypeSizeCheck::name)
180  .def_readonly("size_cpp", &DtypeSizeCheck::size_cpp)
181  .def_readonly("size_numpy", &DtypeSizeCheck::size_numpy)
182  .def("__repr__", [](const DtypeSizeCheck &self) {
183  return py::str("<DtypeSizeCheck name='{}' size_cpp={} size_numpy={} dtype={}>")
184  .format(self.name, self.size_cpp, self.size_numpy, self.dtype);
185  });
186  sm.def("get_platform_dtype_size_checks", &get_platform_dtype_size_checks);
187 
188  // test_array_attributes
189  sm.def("ndim", [](const arr &a) { return a.ndim(); });
190  sm.def("shape", [](const arr &a) { return arr(a.ndim(), a.shape()); });
191  sm.def("shape", [](const arr &a, py::ssize_t dim) { return a.shape(dim); });
192  sm.def("strides", [](const arr &a) { return arr(a.ndim(), a.strides()); });
193  sm.def("strides", [](const arr &a, py::ssize_t dim) { return a.strides(dim); });
194  sm.def("writeable", [](const arr &a) { return a.writeable(); });
195  sm.def("size", [](const arr &a) { return a.size(); });
196  sm.def("itemsize", [](const arr &a) { return a.itemsize(); });
197  sm.def("nbytes", [](const arr &a) { return a.nbytes(); });
198  sm.def("owndata", [](const arr &a) { return a.owndata(); });
199 
200  // test_index_offset
201  def_index_fn(index_at, const arr &);
202  def_index_fn(index_at_t, const arr_t &);
203  def_index_fn(offset_at, const arr &);
204  def_index_fn(offset_at_t, const arr_t &);
205  // test_data
206  def_index_fn(data, const arr &);
207  def_index_fn(data_t, const arr_t &);
208  // test_mutate_data, test_mutate_readonly
211  def_index_fn(at_t, const arr_t &);
213 
214  // test_make_c_f_array
215  sm.def("make_f_array", [] { return py::array_t<float>({2, 2}, {4, 8}); });
216  sm.def("make_c_array", [] { return py::array_t<float>({2, 2}, {8, 4}); });
217 
218  // test_empty_shaped_array
219  sm.def("make_empty_shaped_array", [] { return py::array(py::dtype("f"), {}, {}); });
220  // test numpy scalars (empty shape, ndim==0)
221  sm.def("scalar_int", []() { return py::array(py::dtype("i"), {}, {}, &data_i); });
222 
223  // test_wrap
224  sm.def("wrap", [](const py::array &a) {
225  return py::array(a.dtype(),
226  {a.shape(), a.shape() + a.ndim()},
227  {a.strides(), a.strides() + a.ndim()},
228  a.data(),
229  a);
230  });
231 
232  // test_numpy_view
233  struct ArrayClass {
234  int data[2] = {1, 2};
235  ArrayClass() { py::print("ArrayClass()"); }
236  ~ArrayClass() { py::print("~ArrayClass()"); }
237  };
238  py::class_<ArrayClass>(sm, "ArrayClass")
239  .def(py::init<>())
240  .def("numpy_view", [](py::object &obj) {
241  py::print("ArrayClass::numpy_view()");
242  auto &a = obj.cast<ArrayClass &>();
243  return py::array_t<int>({2}, {4}, a.data, obj);
244  });
245 
246  // test_cast_numpy_int64_to_uint64
247  sm.def("function_taking_uint64", [](uint64_t) {});
248 
249  // test_isinstance
250  sm.def("isinstance_untyped", [](py::object yes, py::object no) {
251  return py::isinstance<py::array>(std::move(yes))
252  && !py::isinstance<py::array>(std::move(no));
253  });
254  sm.def("isinstance_typed", [](const py::object &o) {
255  return py::isinstance<py::array_t<double>>(o) && !py::isinstance<py::array_t<int>>(o);
256  });
257 
258  // test_constructors
259  sm.def("default_constructors", []() {
260  return py::dict("array"_a = py::array(),
261  "array_t<int32>"_a = py::array_t<std::int32_t>(),
262  "array_t<double>"_a = py::array_t<double>());
263  });
264  sm.def("converting_constructors", [](const py::object &o) {
265  return py::dict("array"_a = py::array(o),
266  "array_t<int32>"_a = py::array_t<std::int32_t>(o),
267  "array_t<double>"_a = py::array_t<double>(o));
268  });
269 
270  // test_overload_resolution
271  sm.def("overloaded", [](const py::array_t<double> &) { return "double"; });
272  sm.def("overloaded", [](const py::array_t<float> &) { return "float"; });
273  sm.def("overloaded", [](const py::array_t<int> &) { return "int"; });
274  sm.def("overloaded", [](const py::array_t<unsigned short> &) { return "unsigned short"; });
275  sm.def("overloaded", [](const py::array_t<long long> &) { return "long long"; });
276  sm.def("overloaded",
277  [](const py::array_t<std::complex<double>> &) { return "double complex"; });
278  sm.def("overloaded", [](const py::array_t<std::complex<float>> &) { return "float complex"; });
279 
280  sm.def("overloaded2",
281  [](const py::array_t<std::complex<double>> &) { return "double complex"; });
282  sm.def("overloaded2", [](const py::array_t<double> &) { return "double"; });
283  sm.def("overloaded2",
284  [](const py::array_t<std::complex<float>> &) { return "float complex"; });
285  sm.def("overloaded2", [](const py::array_t<float> &) { return "float"; });
286 
287  // [workaround(intel)] ICC 20/21 breaks with py::arg().stuff, using py::arg{}.stuff works.
288 
289  // Only accept the exact types:
290  sm.def("overloaded3", [](const py::array_t<int> &) { return "int"; }, py::arg{}.noconvert());
291  sm.def(
292  "overloaded3",
293  [](const py::array_t<double> &) { return "double"; },
294  py::arg{}.noconvert());
295 
296  // Make sure we don't do unsafe coercion (e.g. float to int) when not using forcecast, but
297  // rather that float gets converted via the safe (conversion to double) overload:
298  sm.def("overloaded4", [](const py::array_t<long long, 0> &) { return "long long"; });
299  sm.def("overloaded4", [](const py::array_t<double, 0> &) { return "double"; });
300 
301  // But we do allow conversion to int if forcecast is enabled (but only if no overload matches
302  // without conversion)
303  sm.def("overloaded5", [](const py::array_t<unsigned int> &) { return "unsigned int"; });
304  sm.def("overloaded5", [](const py::array_t<double> &) { return "double"; });
305 
306  // test_greedy_string_overload
307  // Issue 685: ndarray shouldn't go to std::string overload
308  sm.def("issue685", [](const std::string &) { return "string"; });
309  sm.def("issue685", [](const py::array &) { return "array"; });
310  sm.def("issue685", [](const py::object &) { return "other"; });
311 
312  // test_array_unchecked_fixed_dims
313  sm.def(
314  "proxy_add2",
315  [](py::array_t<double> a, double v) {
316  auto r = a.mutable_unchecked<2>();
317  for (py::ssize_t i = 0; i < r.shape(0); i++) {
318  for (py::ssize_t j = 0; j < r.shape(1); j++) {
319  r(i, j) += v;
320  }
321  }
322  },
323  py::arg{}.noconvert(),
324  py::arg());
325 
326  sm.def("proxy_init3", [](double start) {
327  py::array_t<double, py::array::c_style> a({3, 3, 3});
328  auto r = a.mutable_unchecked<3>();
329  for (py::ssize_t i = 0; i < r.shape(0); i++) {
330  for (py::ssize_t j = 0; j < r.shape(1); j++) {
331  for (py::ssize_t k = 0; k < r.shape(2); k++) {
332  r(i, j, k) = start++;
333  }
334  }
335  }
336  return a;
337  });
338  sm.def("proxy_init3F", [](double start) {
339  py::array_t<double, py::array::f_style> a({3, 3, 3});
340  auto r = a.mutable_unchecked<3>();
341  for (py::ssize_t k = 0; k < r.shape(2); k++) {
342  for (py::ssize_t j = 0; j < r.shape(1); j++) {
343  for (py::ssize_t i = 0; i < r.shape(0); i++) {
344  r(i, j, k) = start++;
345  }
346  }
347  }
348  return a;
349  });
350  sm.def("proxy_squared_L2_norm", [](const py::array_t<double> &a) {
351  auto r = a.unchecked<1>();
352  double sumsq = 0;
353  for (py::ssize_t i = 0; i < r.shape(0); i++) {
354  sumsq += r[i] * r(i); // Either notation works for a 1D array
355  }
356  return sumsq;
357  });
358 
359  sm.def("proxy_auxiliaries2", [](py::array_t<double> a) {
360  auto r = a.unchecked<2>();
361  auto r2 = a.mutable_unchecked<2>();
362  return auxiliaries(r, r2);
363  });
364 
365  sm.def("proxy_auxiliaries1_const_ref", [](py::array_t<double> a) {
366  const auto &r = a.unchecked<1>();
367  const auto &r2 = a.mutable_unchecked<1>();
368  return r(0) == r2(0) && r[0] == r2[0];
369  });
370 
371  sm.def("proxy_auxiliaries2_const_ref", [](py::array_t<double> a) {
372  const auto &r = a.unchecked<2>();
373  const auto &r2 = a.mutable_unchecked<2>();
374  return r(0, 0) == r2(0, 0);
375  });
376 
377  // test_array_unchecked_dyn_dims
378  // Same as the above, but without a compile-time dimensions specification:
379  sm.def(
380  "proxy_add2_dyn",
381  [](py::array_t<double> a, double v) {
382  auto r = a.mutable_unchecked();
383  if (r.ndim() != 2) {
384  throw std::domain_error("error: ndim != 2");
385  }
386  for (py::ssize_t i = 0; i < r.shape(0); i++) {
387  for (py::ssize_t j = 0; j < r.shape(1); j++) {
388  r(i, j) += v;
389  }
390  }
391  },
392  py::arg{}.noconvert(),
393  py::arg());
394  sm.def("proxy_init3_dyn", [](double start) {
395  py::array_t<double, py::array::c_style> a({3, 3, 3});
396  auto r = a.mutable_unchecked();
397  if (r.ndim() != 3) {
398  throw std::domain_error("error: ndim != 3");
399  }
400  for (py::ssize_t i = 0; i < r.shape(0); i++) {
401  for (py::ssize_t j = 0; j < r.shape(1); j++) {
402  for (py::ssize_t k = 0; k < r.shape(2); k++) {
403  r(i, j, k) = start++;
404  }
405  }
406  }
407  return a;
408  });
409  sm.def("proxy_auxiliaries2_dyn", [](py::array_t<double> a) {
410  return auxiliaries(a.unchecked(), a.mutable_unchecked());
411  });
412 
413  sm.def("array_auxiliaries2", [](py::array_t<double> a) { return auxiliaries(a, a); });
414 
415  // test_array_failures
416  // Issue #785: Uninformative "Unknown internal error" exception when constructing array from
417  // empty object:
418  sm.def("array_fail_test", []() { return py::array(py::object()); });
419  sm.def("array_t_fail_test", []() { return py::array_t<double>(py::object()); });
420  // Make sure the error from numpy is being passed through:
421  sm.def("array_fail_test_negative_size", []() {
422  int c = 0;
423  return py::array(-1, &c);
424  });
425 
426  // test_initializer_list
427  // Issue (unnumbered; reported in #788): regression: initializer lists can be ambiguous
428  sm.def("array_initializer_list1", []() { return py::array_t<float>(1); });
429  // { 1 } also works for the above, but clang warns about it
430  sm.def("array_initializer_list2", []() { return py::array_t<float>({1, 2}); });
431  sm.def("array_initializer_list3", []() { return py::array_t<float>({1, 2, 3}); });
432  sm.def("array_initializer_list4", []() { return py::array_t<float>({1, 2, 3, 4}); });
433 
434  // test_array_resize
435  // reshape array to 2D without changing size
436  sm.def("array_reshape2", [](py::array_t<double> a) {
437  const auto dim_sz = (py::ssize_t) std::sqrt(a.size());
438  if (dim_sz * dim_sz != a.size()) {
439  throw std::domain_error(
440  "array_reshape2: input array total size is not a squared integer");
441  }
442  a.resize({dim_sz, dim_sz});
443  });
444 
445  // resize to 3D array with each dimension = N
446  sm.def("array_resize3",
447  [](py::array_t<double> a, size_t N, bool refcheck) { a.resize({N, N, N}, refcheck); });
448 
449  // test_array_create_and_resize
450  // return 2D array with Nrows = Ncols = N
451  sm.def("create_and_resize", [](size_t N) {
452  py::array_t<double> a;
453  a.resize({N, N});
454  std::fill(a.mutable_data(), a.mutable_data() + a.size(), 42.);
455  return a;
456  });
457 
458  sm.def("array_view",
459  [](py::array_t<uint8_t> a, const std::string &dtype) { return a.view(dtype); });
460 
461  sm.def("reshape_initializer_list",
462  [](py::array_t<int> a, size_t N, size_t M, size_t O) { return a.reshape({N, M, O}); });
463  sm.def("reshape_tuple", [](py::array_t<int> a, const std::vector<int> &new_shape) {
464  return a.reshape(new_shape);
465  });
466 
467  sm.def("index_using_ellipsis",
468  [](const py::array &a) { return a[py::make_tuple(0, py::ellipsis(), 0)]; });
469 
470  // test_argument_conversions
471  sm.def("accept_double", [](const py::array_t<double, 0> &) {}, py::arg("a"));
472  sm.def(
473  "accept_double_forcecast",
474  [](const py::array_t<double, py::array::forcecast> &) {},
475  py::arg("a"));
476  sm.def(
477  "accept_double_c_style",
478  [](const py::array_t<double, py::array::c_style> &) {},
479  py::arg("a"));
480  sm.def(
481  "accept_double_c_style_forcecast",
482  [](const py::array_t<double, py::array::forcecast | py::array::c_style> &) {},
483  py::arg("a"));
484  sm.def(
485  "accept_double_f_style",
486  [](const py::array_t<double, py::array::f_style> &) {},
487  py::arg("a"));
488  sm.def(
489  "accept_double_f_style_forcecast",
490  [](const py::array_t<double, py::array::forcecast | py::array::f_style> &) {},
491  py::arg("a"));
492  sm.def("accept_double_noconvert", [](const py::array_t<double, 0> &) {}, "a"_a.noconvert());
493  sm.def(
494  "accept_double_forcecast_noconvert",
495  [](const py::array_t<double, py::array::forcecast> &) {},
496  "a"_a.noconvert());
497  sm.def(
498  "accept_double_c_style_noconvert",
499  [](const py::array_t<double, py::array::c_style> &) {},
500  "a"_a.noconvert());
501  sm.def(
502  "accept_double_c_style_forcecast_noconvert",
503  [](const py::array_t<double, py::array::forcecast | py::array::c_style> &) {},
504  "a"_a.noconvert());
505  sm.def(
506  "accept_double_f_style_noconvert",
507  [](const py::array_t<double, py::array::f_style> &) {},
508  "a"_a.noconvert());
509  sm.def(
510  "accept_double_f_style_forcecast_noconvert",
511  [](const py::array_t<double, py::array::forcecast | py::array::f_style> &) {},
512  "a"_a.noconvert());
513 
514  // Check that types returns correct npy format descriptor
515  sm.def("test_fmt_desc_float", [](const py::array_t<float> &) {});
516  sm.def("test_fmt_desc_double", [](const py::array_t<double> &) {});
517  sm.def("test_fmt_desc_const_float", [](const py::array_t<const float> &) {});
518  sm.def("test_fmt_desc_const_double", [](const py::array_t<const double> &) {});
519 
520  sm.def("round_trip_float", [](double d) { return d; });
521 
522  sm.def("pass_array_pyobject_ptr_return_sum_str_values",
523  [](const py::array_t<PyObject *> &objs) {
524  std::string sum_str_values;
525  for (const auto &obj : objs) {
526  sum_str_values += py::str(obj.attr("value"));
527  }
528  return sum_str_values;
529  });
530 
531  sm.def("pass_array_pyobject_ptr_return_as_list",
532  [](const py::array_t<PyObject *> &objs) -> py::list { return objs; });
533 
534  sm.def("return_array_pyobject_ptr_cpp_loop", [](const py::list &objs) {
535  py::size_t arr_size = py::len(objs);
536  py::array_t<PyObject *> arr_from_list(static_cast<py::ssize_t>(arr_size));
537  PyObject **data = arr_from_list.mutable_data();
538  for (py::size_t i = 0; i < arr_size; i++) {
539  assert(data[i] == nullptr);
540  data[i] = py::cast<PyObject *>(objs[i].attr("value"));
541  }
542  return arr_from_list;
543  });
544 
545  sm.def("return_array_pyobject_ptr_from_list",
546  [](const py::list &objs) -> py::array_t<PyObject *> { return objs; });
547 }
offset_at_t
py::ssize_t offset_at_t(const arr_t &a, Ix... idx)
Definition: test_numpy_array.cpp:122
Eigen::internal::print
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
Definition: NEON/PacketMath.h:3115
name
Annotation for function names.
Definition: attr.h:51
array
int array[24]
Definition: Map_general_stride.cpp:1
ssize_t
Py_ssize_t ssize_t
Definition: wrap/pybind11/include/pybind11/detail/common.h:489
d
static const double d[K][N]
Definition: igam.h:11
data
arr data(const arr &a, Ix... index)
Definition: test_numpy_array.cpp:82
r2
static const double r2
Definition: testSmartRangeFactor.cpp:32
c
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
DtypeCheck
Definition: test_numpy_array.cpp:19
test_eigen.np
np
Definition: test_eigen.py:5
DtypeSizeCheck::size_cpp
int size_cpp
Definition: test_numpy_array.cpp:47
data_t
arr data_t(const arr_t &a, Ix... index)
Definition: test_numpy_array.cpp:87
stl.h
TEST_SUBMODULE
TEST_SUBMODULE(numpy_array, sm)
Definition: test_numpy_array.cpp:162
index_at
py::ssize_t index_at(const arr &a, Ix... idx)
Definition: test_numpy_array.cpp:110
T
Eigen::Triplet< double > T
Definition: Tutorial_sparse_example.cpp:6
uint8_t
unsigned char uint8_t
Definition: ms_stdint.h:83
DtypeCheck::pybind11
py::dtype pybind11
Definition: test_numpy_array.cpp:21
DtypeSizeCheck::name
std::string name
Definition: test_numpy_array.cpp:46
arr_t
py::array_t< uint16_t, 0 > arr_t
Definition: test_numpy_array.cpp:78
dtype
Definition: numpy.h:636
isinstance
bool isinstance(handle obj)
Definition: pytypes.h:842
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
make_tuple
tuple make_tuple()
Definition: cast.h:1383
offset_at
py::ssize_t offset_at(const arr &a, Ix... idx)
Definition: test_numpy_array.cpp:118
get_concrete_dtype_checks
std::vector< DtypeCheck > get_concrete_dtype_checks()
Definition: test_numpy_array.cpp:33
DtypeSizeCheck
Definition: test_numpy_array.cpp:45
check
void check(bool b, bool ref)
Definition: fastmath.cpp:12
def_index_fn
#define def_index_fn(name, type)
Definition: test_numpy_array.cpp:135
l
static const Line3 l(Rot3(), 1, 1)
numpy.h
T2
static const Pose3 T2(Rot3::Rodrigues(0.3, 0.2, 0.1), P2)
Eigen::Triplet< double >
arg
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE ArgReturnType arg() const
Definition: ArrayCwiseUnaryOps.h:66
DtypeCheck::numpy
py::dtype numpy
Definition: test_numpy_array.cpp:20
DtypeSizeCheck::size_numpy
int size_numpy
Definition: test_numpy_array.cpp:48
size_t
std::size_t size_t
Definition: wrap/pybind11/include/pybind11/detail/common.h:490
gtsam::symbol_shorthand::O
Key O(std::uint64_t j)
Definition: inference/Symbol.h:162
at_t
py::ssize_t at_t(const arr_t &a, Ix... idx)
Definition: test_numpy_array.cpp:126
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
arr
py::array arr
Definition: test_numpy_array.cpp:77
pybind11_tests.h
test_eigen_tensor.dtype
dtype
Definition: test_eigen_tensor.py:26
mutate_at_t
arr_t & mutate_at_t(arr_t &a, Ix... idx)
Definition: test_numpy_array.cpp:130
get_dtype_check
DtypeCheck get_dtype_check(const char *name)
Definition: test_numpy_array.cpp:25
mutate_data_t
arr_t & mutate_data_t(arr_t &a, Ix... index)
Definition: test_numpy_array.cpp:101
v
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
data_i
static int data_i
Definition: test_numpy_array.cpp:160
pybind11
Definition: wrap/pybind11/pybind11/__init__.py:1
uint64_t
unsigned __int64 uint64_t
Definition: ms_stdint.h:95
len
size_t len(handle h)
Get the length of a Python object.
Definition: pytypes.h:2446
N
#define N
Definition: igam.h:9
mutate_data
arr & mutate_data(arr &a, Ix... index)
Definition: test_numpy_array.cpp:92
get_dtype_size_check
DtypeSizeCheck get_dtype_size_check()
Definition: test_numpy_array.cpp:54
index_at_t
py::ssize_t index_at_t(const arr_t &a, Ix... idx)
Definition: test_numpy_array.cpp:114
gtsam.examples.ShonanAveragingCLI.str
str
Definition: ShonanAveragingCLI.py:115
test_callbacks.value
value
Definition: test_callbacks.py:160
ceres::sqrt
Jet< T, N > sqrt(const Jet< T, N > &f)
Definition: jet.h:418
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
get_platform_dtype_size_checks
std::vector< DtypeSizeCheck > get_platform_dtype_size_checks()
Definition: test_numpy_array.cpp:63
auxiliaries
py::handle auxiliaries(T &&r, T2 &&r2)
Definition: test_numpy_array.cpp:142
M
Matrix< RealScalar, Dynamic, Dynamic > M
Definition: bench_gemm.cpp:51


gtsam
Author(s):
autogenerated on Wed Sep 25 2024 03:09:38