test_sequences_and_iterators.cpp
Go to the documentation of this file.
1 /*
2  tests/test_sequences_and_iterators.cpp -- supporting Pythons' sequence protocol, iterators,
3  etc.
4 
5  Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
6 
7  All rights reserved. Use of this source code is governed by a
8  BSD-style license that can be found in the LICENSE file.
9 */
10 
11 #include <pybind11/operators.h>
12 #include <pybind11/stl.h>
13 
14 #include "constructor_stats.h"
15 #include "pybind11_tests.h"
16 
17 #include <algorithm>
18 #include <utility>
19 #include <vector>
20 
21 #ifdef PYBIND11_HAS_OPTIONAL
22 # include <optional>
23 #endif // PYBIND11_HAS_OPTIONAL
24 
25 template <typename T>
27  const T *ptr_;
28 
29 public:
30  explicit NonZeroIterator(const T *ptr) : ptr_(ptr) {}
31 
32  // Make the iterator non-copyable and movable
33  NonZeroIterator(const NonZeroIterator &) = delete;
35  NonZeroIterator &operator=(const NonZeroIterator &) = delete;
36  NonZeroIterator &operator=(NonZeroIterator &&) noexcept = default;
37 
38  const T &operator*() const { return *ptr_; }
40  ++ptr_;
41  return *this;
42  }
43 };
44 
45 class NonZeroSentinel {};
46 
47 template <typename A, typename B>
48 bool operator==(const NonZeroIterator<std::pair<A, B>> &it, const NonZeroSentinel &) {
49  return !(*it).first || !(*it).second;
50 }
51 
52 /* Iterator where dereferencing returns prvalues instead of references. */
53 template <typename T>
55  const T *ptr_;
56 
57 public:
58  explicit NonRefIterator(const T *ptr) : ptr_(ptr) {}
59  T operator*() const { return T(*ptr_); }
61  ++ptr_;
62  return *this;
63  }
64  bool operator==(const NonRefIterator &other) const { return ptr_ == other.ptr_; }
65 };
66 
68 public:
69  explicit NonCopyableInt(int value) : value_(value) {}
70  NonCopyableInt(const NonCopyableInt &) = delete;
72  other.value_ = -1; // detect when an unwanted move occurs
73  }
74  NonCopyableInt &operator=(const NonCopyableInt &) = delete;
76  value_ = other.value_;
77  other.value_ = -1; // detect when an unwanted move occurs
78  return *this;
79  }
80  int get() const { return value_; }
81  void set(int value) { value_ = value; }
82  ~NonCopyableInt() = default;
83 
84 private:
85  int value_;
86 };
87 using NonCopyableIntPair = std::pair<NonCopyableInt, NonCopyableInt>;
88 
89 PYBIND11_MAKE_OPAQUE(std::vector<NonCopyableInt>);
90 PYBIND11_MAKE_OPAQUE(std::vector<NonCopyableIntPair>);
91 
92 template <typename PythonType>
93 py::list test_random_access_iterator(PythonType x) {
94  if (x.size() < 5) {
95  throw py::value_error("Please provide at least 5 elements for testing.");
96  }
97 
98  auto checks = py::list();
99  auto assert_equal = [&checks](py::handle a, py::handle b) {
100  auto result = PyObject_RichCompareBool(a.ptr(), b.ptr(), Py_EQ);
101  if (result == -1) {
102  throw py::error_already_set();
103  }
104  checks.append(result != 0);
105  };
106 
107  auto it = x.begin();
108  assert_equal(x[0], *it);
109  assert_equal(x[0], it[0]);
110  assert_equal(x[1], it[1]);
111 
112  assert_equal(x[1], *(++it));
113  assert_equal(x[1], *(it++));
114  assert_equal(x[2], *it);
115  assert_equal(x[3], *(it += 1));
116  assert_equal(x[2], *(--it));
117  assert_equal(x[2], *(it--));
118  assert_equal(x[1], *it);
119  assert_equal(x[0], *(it -= 1));
120 
121  assert_equal(it->attr("real"), x[0].attr("real"));
122  assert_equal((it + 1)->attr("real"), x[1].attr("real"));
123 
124  assert_equal(x[1], *(it + 1));
125  assert_equal(x[1], *(1 + it));
126  it += 3;
127  assert_equal(x[1], *(it - 2));
128 
129  checks.append(static_cast<std::size_t>(x.end() - x.begin()) == x.size());
130  checks.append((x.begin() + static_cast<std::ptrdiff_t>(x.size())) == x.end());
131  checks.append(x.begin() < x.end());
132 
133  return checks;
134 }
135 
136 TEST_SUBMODULE(sequences_and_iterators, m) {
137  // test_sliceable
138  class Sliceable {
139  public:
140  explicit Sliceable(int n) : size(n) {}
141  int start, stop, step;
142  int size;
143  };
144  py::class_<Sliceable>(m, "Sliceable")
145  .def(py::init<int>())
146  .def("__getitem__", [](const Sliceable &s, const py::slice &slice) {
147  py::ssize_t start = 0, stop = 0, step = 0, slicelength = 0;
148  if (!slice.compute(s.size, &start, &stop, &step, &slicelength)) {
149  throw py::error_already_set();
150  }
151  int istart = static_cast<int>(start);
152  int istop = static_cast<int>(stop);
153  int istep = static_cast<int>(step);
154  return std::make_tuple(istart, istop, istep);
155  });
156 
157  m.def("make_forward_slice_size_t", []() { return py::slice(0, -1, 1); });
158  m.def("make_reversed_slice_object",
159  []() { return py::slice(py::none(), py::none(), py::int_(-1)); });
160 #ifdef PYBIND11_HAS_OPTIONAL
161  m.attr("has_optional") = true;
162  m.def("make_reversed_slice_size_t_optional_verbose",
163  []() { return py::slice(std::nullopt, std::nullopt, -1); });
164  // Warning: The following spelling may still compile if optional<> is not present and give
165  // wrong answers. Please use with caution.
166  m.def("make_reversed_slice_size_t_optional", []() { return py::slice({}, {}, -1); });
167 #else
168  m.attr("has_optional") = false;
169 #endif
170 
171  // test_sequence
172  class Sequence {
173  public:
174  explicit Sequence(size_t size) : m_size(size) {
175  print_created(this, "of size", m_size);
176  // NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer)
177  m_data = new float[size];
178  memset(m_data, 0, sizeof(float) * size);
179  }
180  explicit Sequence(const std::vector<float> &value) : m_size(value.size()) {
181  print_created(this, "of size", m_size, "from std::vector");
182  // NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer)
183  m_data = new float[m_size];
184  memcpy(m_data, &value[0], sizeof(float) * m_size);
185  }
186  Sequence(const Sequence &s) : m_size(s.m_size) {
187  print_copy_created(this);
188  // NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer)
189  m_data = new float[m_size];
190  memcpy(m_data, s.m_data, sizeof(float) * m_size);
191  }
192  Sequence(Sequence &&s) noexcept : m_size(s.m_size), m_data(s.m_data) {
193  print_move_created(this);
194  s.m_size = 0;
195  s.m_data = nullptr;
196  }
197 
198  ~Sequence() {
199  print_destroyed(this);
200  delete[] m_data;
201  }
202 
203  Sequence &operator=(const Sequence &s) {
204  if (&s != this) {
205  delete[] m_data;
206  m_size = s.m_size;
207  m_data = new float[m_size];
208  memcpy(m_data, s.m_data, sizeof(float) * m_size);
209  }
210  print_copy_assigned(this);
211  return *this;
212  }
213 
214  Sequence &operator=(Sequence &&s) noexcept {
215  if (&s != this) {
216  delete[] m_data;
217  m_size = s.m_size;
218  m_data = s.m_data;
219  s.m_size = 0;
220  s.m_data = nullptr;
221  }
222  print_move_assigned(this);
223  return *this;
224  }
225 
226  bool operator==(const Sequence &s) const {
227  if (m_size != s.size()) {
228  return false;
229  }
230  for (size_t i = 0; i < m_size; ++i) {
231  if (m_data[i] != s[i]) {
232  return false;
233  }
234  }
235  return true;
236  }
237  bool operator!=(const Sequence &s) const { return !operator==(s); }
238 
239  float operator[](size_t index) const { return m_data[index]; }
240  float &operator[](size_t index) { return m_data[index]; }
241 
242  bool contains(float v) const {
243  for (size_t i = 0; i < m_size; ++i) {
244  if (v == m_data[i]) {
245  return true;
246  }
247  }
248  return false;
249  }
250 
251  Sequence reversed() const {
252  Sequence result(m_size);
253  for (size_t i = 0; i < m_size; ++i) {
254  result[m_size - i - 1] = m_data[i];
255  }
256  return result;
257  }
258 
259  size_t size() const { return m_size; }
260 
261  const float *begin() const { return m_data; }
262  const float *end() const { return m_data + m_size; }
263 
264  private:
265  size_t m_size;
266  float *m_data;
267  };
268  py::class_<Sequence>(m, "Sequence")
269  .def(py::init<size_t>())
270  .def(py::init<const std::vector<float> &>())
272  .def("__getitem__",
273  [](const Sequence &s, size_t i) {
274  if (i >= s.size()) {
275  throw py::index_error();
276  }
277  return s[i];
278  })
279  .def("__setitem__",
280  [](Sequence &s, size_t i, float v) {
281  if (i >= s.size()) {
282  throw py::index_error();
283  }
284  s[i] = v;
285  })
286  .def("__len__", &Sequence::size)
288  .def(
289  "__iter__",
290  [](const Sequence &s) { return py::make_iterator(s.begin(), s.end()); },
291  py::keep_alive<0, 1>() /* Essential: keep object alive while iterator exists */)
292  .def("__contains__", [](const Sequence &s, float v) { return s.contains(v); })
293  .def("__reversed__", [](const Sequence &s) -> Sequence { return s.reversed(); })
295  .def("__getitem__",
296  [](const Sequence &s, const py::slice &slice) -> Sequence * {
297  size_t start = 0, stop = 0, step = 0, slicelength = 0;
298  if (!slice.compute(s.size(), &start, &stop, &step, &slicelength)) {
299  throw py::error_already_set();
300  }
301  auto *seq = new Sequence(slicelength);
302  for (size_t i = 0; i < slicelength; ++i) {
303  (*seq)[i] = s[start];
304  start += step;
305  }
306  return seq;
307  })
308  .def("__setitem__",
309  [](Sequence &s, const py::slice &slice, const Sequence &value) {
310  size_t start = 0, stop = 0, step = 0, slicelength = 0;
311  if (!slice.compute(s.size(), &start, &stop, &step, &slicelength)) {
312  throw py::error_already_set();
313  }
314  if (slicelength != value.size()) {
315  throw std::runtime_error(
316  "Left and right hand size of slice assignment have different sizes!");
317  }
318  for (size_t i = 0; i < slicelength; ++i) {
319  s[start] = value[i];
320  start += step;
321  }
322  })
324  .def(py::self == py::self)
325  .def(py::self != py::self)
326  // Could also define py::self + py::self for concatenation, etc.
327  ;
328 
329  // test_map_iterator
330  // Interface of a map-like object that isn't (directly) an unordered_map, but provides some
331  // basic map-like functionality.
332  class StringMap {
333  public:
334  StringMap() = default;
335  explicit StringMap(std::unordered_map<std::string, std::string> init)
336  : map(std::move(init)) {}
337 
338  void set(const std::string &key, std::string val) { map[key] = std::move(val); }
339  std::string get(const std::string &key) const { return map.at(key); }
340  size_t size() const { return map.size(); }
341 
342  private:
343  std::unordered_map<std::string, std::string> map;
344 
345  public:
346  decltype(map.cbegin()) begin() const { return map.cbegin(); }
347  decltype(map.cend()) end() const { return map.cend(); }
348  };
349  py::class_<StringMap>(m, "StringMap")
350  .def(py::init<>())
351  .def(py::init<std::unordered_map<std::string, std::string>>())
352  .def("__getitem__",
353  [](const StringMap &map, const std::string &key) {
354  try {
355  return map.get(key);
356  } catch (const std::out_of_range &) {
357  throw py::key_error("key '" + key + "' does not exist");
358  }
359  })
360  .def("__setitem__", &StringMap::set)
361  .def("__len__", &StringMap::size)
362  .def(
363  "__iter__",
364  [](const StringMap &map) { return py::make_key_iterator(map.begin(), map.end()); },
365  py::keep_alive<0, 1>())
366  .def(
367  "items",
368  [](const StringMap &map) { return py::make_iterator(map.begin(), map.end()); },
369  py::keep_alive<0, 1>())
370  .def(
371  "values",
372  [](const StringMap &map) { return py::make_value_iterator(map.begin(), map.end()); },
373  py::keep_alive<0, 1>());
374 
375  // test_generalized_iterators
376  class IntPairs {
377  public:
378  explicit IntPairs(std::vector<std::pair<int, int>> data) : data_(std::move(data)) {}
379  const std::pair<int, int> *begin() const { return data_.data(); }
380  // .end() only required for py::make_iterator(self) overload
381  const std::pair<int, int> *end() const { return data_.data() + data_.size(); }
382 
383  private:
384  std::vector<std::pair<int, int>> data_;
385  };
386 
387  {
388  // #4383 : Make sure `py::make_*iterator` functions work with move-only iterators
389  using iterator_t = NonZeroIterator<std::pair<int, int>>;
390 
393  static_assert(!std::is_copy_assignable<iterator_t>::value, "");
395  }
396 
397  py::class_<IntPairs>(m, "IntPairs")
398  .def(py::init<std::vector<std::pair<int, int>>>())
399  .def(
400  "nonzero",
401  [](const IntPairs &s) {
402  return py::make_iterator(NonZeroIterator<std::pair<int, int>>(s.begin()),
403  NonZeroSentinel());
404  },
405  py::keep_alive<0, 1>())
406  .def(
407  "nonzero_keys",
408  [](const IntPairs &s) {
409  return py::make_key_iterator(NonZeroIterator<std::pair<int, int>>(s.begin()),
410  NonZeroSentinel());
411  },
412  py::keep_alive<0, 1>())
413  .def(
414  "nonzero_values",
415  [](const IntPairs &s) {
416  return py::make_value_iterator(NonZeroIterator<std::pair<int, int>>(s.begin()),
417  NonZeroSentinel());
418  },
419  py::keep_alive<0, 1>())
420 
421  // test iterator that returns values instead of references
422  .def(
423  "nonref",
424  [](const IntPairs &s) {
425  return py::make_iterator(NonRefIterator<std::pair<int, int>>(s.begin()),
426  NonRefIterator<std::pair<int, int>>(s.end()));
427  },
428  py::keep_alive<0, 1>())
429  .def(
430  "nonref_keys",
431  [](const IntPairs &s) {
432  return py::make_key_iterator(NonRefIterator<std::pair<int, int>>(s.begin()),
433  NonRefIterator<std::pair<int, int>>(s.end()));
434  },
435  py::keep_alive<0, 1>())
436  .def(
437  "nonref_values",
438  [](const IntPairs &s) {
439  return py::make_value_iterator(NonRefIterator<std::pair<int, int>>(s.begin()),
440  NonRefIterator<std::pair<int, int>>(s.end()));
441  },
442  py::keep_alive<0, 1>())
443 
444  // test single-argument make_iterator
445  .def(
446  "simple_iterator",
447  [](IntPairs &self) { return py::make_iterator(self); },
448  py::keep_alive<0, 1>())
449  .def(
450  "simple_keys",
451  [](IntPairs &self) { return py::make_key_iterator(self); },
452  py::keep_alive<0, 1>())
453  .def(
454  "simple_values",
455  [](IntPairs &self) { return py::make_value_iterator(self); },
456  py::keep_alive<0, 1>())
457 
458  // Test iterator with an Extra (doesn't do anything useful, so not used
459  // at runtime, but tests need to be able to compile with the correct
460  // overload. See PR #3293.
461  .def(
462  "_make_iterator_extras",
463  [](IntPairs &self) { return py::make_iterator(self, py::call_guard<int>()); },
464  py::keep_alive<0, 1>())
465  .def(
466  "_make_key_extras",
467  [](IntPairs &self) { return py::make_key_iterator(self, py::call_guard<int>()); },
468  py::keep_alive<0, 1>())
469  .def(
470  "_make_value_extras",
471  [](IntPairs &self) { return py::make_value_iterator(self, py::call_guard<int>()); },
472  py::keep_alive<0, 1>());
473 
474  // test_iterator_referencing
475  py::class_<NonCopyableInt>(m, "NonCopyableInt")
476  .def(py::init<int>())
477  .def("set", &NonCopyableInt::set)
478  .def("__int__", &NonCopyableInt::get);
479  py::class_<std::vector<NonCopyableInt>>(m, "VectorNonCopyableInt")
480  .def(py::init<>())
481  .def("append",
482  [](std::vector<NonCopyableInt> &vec, int value) { vec.emplace_back(value); })
483  .def("__iter__", [](std::vector<NonCopyableInt> &vec) {
484  return py::make_iterator(vec.begin(), vec.end());
485  });
486  py::class_<std::vector<NonCopyableIntPair>>(m, "VectorNonCopyableIntPair")
487  .def(py::init<>())
488  .def("append",
489  [](std::vector<NonCopyableIntPair> &vec, const std::pair<int, int> &value) {
490  vec.emplace_back(NonCopyableInt(value.first), NonCopyableInt(value.second));
491  })
492  .def("keys",
493  [](std::vector<NonCopyableIntPair> &vec) {
494  return py::make_key_iterator(vec.begin(), vec.end());
495  })
496  .def("values", [](std::vector<NonCopyableIntPair> &vec) {
497  return py::make_value_iterator(vec.begin(), vec.end());
498  });
499 
500 #if 0
501  // Obsolete: special data structure for exposing custom iterator types to python
502  // kept here for illustrative purposes because there might be some use cases which
503  // are not covered by the much simpler py::make_iterator
504 
505  struct PySequenceIterator {
506  PySequenceIterator(const Sequence &seq, py::object ref) : seq(seq), ref(ref) { }
507 
508  float next() {
509  if (index == seq.size())
510  throw py::stop_iteration();
511  return seq[index++];
512  }
513 
514  const Sequence &seq;
515  py::object ref; // keep a reference
516  size_t index = 0;
517  };
518 
519  py::class_<PySequenceIterator>(seq, "Iterator")
520  .def("__iter__", [](PySequenceIterator &it) -> PySequenceIterator& { return it; })
521  .def("__next__", &PySequenceIterator::next);
522 
523  On the actual Sequence object, the iterator would be constructed as follows:
524  .def("__iter__", [](py::object s) { return PySequenceIterator(s.cast<const Sequence &>(), s); })
525 #endif
526 
527  // test_python_iterator_in_cpp
528  m.def("object_to_list", [](const py::object &o) {
529  auto l = py::list();
530  for (auto item : o) {
531  l.append(item);
532  }
533  return l;
534  });
535 
536  m.def("iterator_to_list", [](py::iterator it) {
537  auto l = py::list();
538  while (it != py::iterator::sentinel()) {
539  l.append(*it);
540  ++it;
541  }
542  return l;
543  });
544 
545  // test_sequence_length: check that Python sequences can be converted to py::sequence.
546  m.def("sequence_length", [](const py::sequence &seq) { return seq.size(); });
547 
548  // Make sure that py::iterator works with std algorithms
549  m.def("count_none", [](const py::object &o) {
550  return std::count_if(o.begin(), o.end(), [](py::handle h) { return h.is_none(); });
551  });
552 
553  m.def("find_none", [](const py::object &o) {
554  auto it = std::find_if(o.begin(), o.end(), [](py::handle h) { return h.is_none(); });
555  return it->is_none();
556  });
557 
558  m.def("count_nonzeros", [](const py::dict &d) {
559  return std::count_if(d.begin(), d.end(), [](std::pair<py::handle, py::handle> p) {
560  return p.second.cast<int>() != 0;
561  });
562  });
563 
564  m.def("tuple_iterator", &test_random_access_iterator<py::tuple>);
565  m.def("list_iterator", &test_random_access_iterator<py::list>);
566  m.def("sequence_iterator", &test_random_access_iterator<py::sequence>);
567 
568  // test_iterator_passthrough
569  // #181: iterator passthrough did not compile
570  m.def("iterator_passthrough", [](py::iterator s) -> py::iterator {
571  return py::make_iterator(std::begin(s), std::end(s));
572  });
573 
574  // test_iterator_rvp
575  // #388: Can't make iterators via make_iterator() with different r/v policies
576  static std::vector<int> list = {1, 2, 3};
577  m.def("make_iterator_1",
578  []() { return py::make_iterator<py::return_value_policy::copy>(list); });
579  m.def("make_iterator_2",
580  []() { return py::make_iterator<py::return_value_policy::automatic>(list); });
581 
582  // test_iterator on c arrays
583  // #4100: ensure lvalue required as increment operand
584  class CArrayHolder {
585  public:
586  CArrayHolder(double x, double y, double z) {
587  values[0] = x;
588  values[1] = y;
589  values[2] = z;
590  };
591  double values[3];
592  };
593 
594  py::class_<CArrayHolder>(m, "CArrayHolder")
595  .def(py::init<double, double, double>())
596  .def(
597  "__iter__",
598  [](const CArrayHolder &v) { return py::make_iterator(v.values, v.values + 3); },
599  py::keep_alive<0, 1>());
600 }
make_value_iterator
typing::Iterator< ValueType > make_value_iterator(Iterator first, Sentinel last, Extra &&...extra)
Definition: pybind11.h:2543
NonZeroIterator
Definition: test_sequences_and_iterators.cpp:26
ssize_t
Py_ssize_t ssize_t
Definition: wrap/pybind11/include/pybind11/detail/common.h:489
NonZeroSentinel
Definition: test_sequences_and_iterators.cpp:45
s
RealScalar s
Definition: level1_cplx_impl.h:126
d
static const double d[K][N]
Definition: igam.h:11
NonCopyableInt
Definition: test_sequences_and_iterators.cpp:67
b
Scalar * b
Definition: benchVecAdd.cpp:17
NonRefIterator::NonRefIterator
NonRefIterator(const T *ptr)
Definition: test_sequences_and_iterators.cpp:58
operator==
bool operator==(const NonZeroIterator< std::pair< A, B >> &it, const NonZeroSentinel &)
Definition: test_sequences_and_iterators.cpp:48
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
stl.h
NonZeroIterator::operator++
NonZeroIterator & operator++()
Definition: test_sequences_and_iterators.cpp:39
NonZeroIterator::ptr_
const T * ptr_
Definition: test_sequences_and_iterators.cpp:27
T
Eigen::Triplet< double > T
Definition: Tutorial_sparse_example.cpp:6
iterator
Definition: pytypes.h:1460
h
const double h
Definition: testSimpleHelicopter.cpp:19
constructor_stats.h
result
Values result
Definition: OdometryOptimize.cpp:8
test_random_access_iterator
py::list test_random_access_iterator(PythonType x)
Definition: test_sequences_and_iterators.cpp:93
print_copy_created
void print_copy_created(T *inst, Values &&...values)
Definition: constructor_stats.h:282
size
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
n
int n
Definition: BiCGSTAB_simple.cpp:1
slice
Definition: pytypes.h:1909
NonRefIterator::ptr_
const T * ptr_
Definition: test_sequences_and_iterators.cpp:55
NonCopyableInt::operator=
NonCopyableInt & operator=(const NonCopyableInt &)=delete
data
int data[]
Definition: Map_placement_new.cpp:1
make_tuple
tuple make_tuple()
Definition: cast.h:1383
Eigen::internal::On
@ On
Definition: TensorForwardDeclarations.h:160
print_copy_assigned
void print_copy_assigned(T *inst, Values &&...values)
Definition: constructor_stats.h:294
gtsam::Sequence
std::map< double, double > Sequence
Our sequence representation is a map of {x: y} values where y = f(x)
Definition: FitBasis.h:36
l
static const Line3 l(Rot3(), 1, 1)
NonRefIterator::operator==
bool operator==(const NonRefIterator &other) const
Definition: test_sequences_and_iterators.cpp:64
slice::compute
bool compute(size_t length, size_t *start, size_t *stop, size_t *step, size_t *slicelength) const
Definition: pytypes.h:1928
NonCopyableInt::NonCopyableInt
NonCopyableInt(NonCopyableInt &&other) noexcept
Definition: test_sequences_and_iterators.cpp:71
gtsam::utils.visual_isam.step
def step(data, isam, result, truth, currPoseIndex, isamArgs=())
Definition: visual_isam.py:82
pybind_wrapper_test_script.z
z
Definition: pybind_wrapper_test_script.py:61
m
Matrix3f m
Definition: AngleAxis_mimic_euler.cpp:1
Eigen::Triplet< double >
NonCopyableInt::value_
int value_
Definition: test_sequences_and_iterators.cpp:85
init
detail::initimpl::constructor< Args... > init()
Binds an existing constructor taking arguments Args...
Definition: pybind11.h:2006
size_t
std::size_t size_t
Definition: wrap/pybind11/include/pybind11/detail/common.h:490
y
Scalar * y
Definition: level1_cplx_impl.h:124
NonZeroIterator::NonZeroIterator
NonZeroIterator(const T *ptr)
Definition: test_sequences_and_iterators.cpp:30
PYBIND11_MAKE_OPAQUE
PYBIND11_MAKE_OPAQUE(std::vector< NonCopyableInt >)
key
const gtsam::Symbol key('X', 0)
set
void set(Container &c, Position position, const Value &value)
Definition: stdlist_overload.cpp:37
operator!=
bool operator!=(UserVectorLike const &, UserVectorLike const &)
Definition: test_stl_binders.cpp:120
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
NonCopyableInt::NonCopyableInt
NonCopyableInt(int value)
Definition: test_sequences_and_iterators.cpp:69
print_move_created
void print_move_created(T *inst, Values &&...values)
Definition: constructor_stats.h:288
leaf::values
leaf::MyValues values
NonCopyableInt::get
int get() const
Definition: test_sequences_and_iterators.cpp:80
pybind11_tests.h
TEST_SUBMODULE
TEST_SUBMODULE(sequences_and_iterators, m)
Definition: test_sequences_and_iterators.cpp:136
print_destroyed
void print_destroyed(T *inst, Values &&...values)
Definition: constructor_stats.h:314
p
float * p
Definition: Tutorial_Map_using.cpp:9
ref
Reference counting helper.
Definition: object.h:67
v
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
self
static const self_t self
Definition: operators.h:72
gtsam::assert_equal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
NonCopyableInt::~NonCopyableInt
~NonCopyableInt()=default
print_move_assigned
void print_move_assigned(T *inst, Values &&...values)
Definition: constructor_stats.h:299
NonCopyableIntPair
std::pair< NonCopyableInt, NonCopyableInt > NonCopyableIntPair
Definition: test_sequences_and_iterators.cpp:87
NonRefIterator::operator*
T operator*() const
Definition: test_sequences_and_iterators.cpp:59
Eigen::placeholders::end
static const EIGEN_DEPRECATED end_t end
Definition: IndexedViewHelper.h:181
NonCopyableInt::operator=
NonCopyableInt & operator=(NonCopyableInt &&other) noexcept
Definition: test_sequences_and_iterators.cpp:75
gtsam.examples.DogLegOptimizerExample.default
default
Definition: DogLegOptimizerExample.py:111
make_key_iterator
typing::Iterator< KeyType > make_key_iterator(Iterator first, Sentinel last, Extra &&...extra)
Definition: pybind11.h:2525
init
Definition: TutorialInplaceLU.cpp:2
Eigen::seq
internal::enable_if<!(symbolic::is_symbolic< FirstType >::value||symbolic::is_symbolic< LastType >::value), ArithmeticSequence< typename internal::cleanup_index_type< FirstType >::type, Index > >::type seq(FirstType f, LastType l)
Definition: ArithmeticSequence.h:234
get
Container::iterator get(Container &c, Position position)
Definition: stdlist_overload.cpp:29
operators.h
NonCopyableInt::set
void set(int value)
Definition: test_sequences_and_iterators.cpp:81
test_callbacks.value
value
Definition: test_callbacks.py:160
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
print_created
void print_created(T *inst, Values &&...values)
Definition: constructor_stats.h:309
make_iterator
typing::Iterator< ValueType > make_iterator(Iterator first, Sentinel last, Extra &&...extra)
Makes a python iterator from a first and past-the-end C++ InputIterator.
Definition: pybind11.h:2507
NonRefIterator::operator++
NonRefIterator & operator++()
Definition: test_sequences_and_iterators.cpp:60
test_eigen.ref
ref
Definition: test_eigen.py:9
NonRefIterator
Definition: test_sequences_and_iterators.cpp:54


gtsam
Author(s):
autogenerated on Thu Jul 4 2024 03:06:03