24 template <
typename T2>
26 test_comparable(decltype(std::declval<const T2 &>() == std::declval<const T2 &>()) *);
27 template <
typename T2>
29 template <
typename T2>
30 static std::true_type
test_value(
typename T2::value_type *);
31 template <
typename T2>
33 template <
typename T2>
34 static std::true_type
test_pair(
typename T2::first_type *,
typename T2::second_type *);
35 template <
typename T2>
39 = std::is_same<std::true_type, decltype(test_comparable<T>(
nullptr))>
::value;
40 static constexpr
const bool is_pair 41 = std::is_same<std::true_type, decltype(test_pair<T>(
nullptr,
nullptr))>
::value;
43 = std::is_same<std::true_type, decltype(test_value<T>(
nullptr))>
::value;
48 template <
typename T,
typename SFINAE =
void>
73 template <
typename,
typename,
typename... Args>
75 template <
typename,
typename,
typename... Args>
77 template <
typename,
typename,
typename... Args>
79 template <
typename,
typename,
typename... Args>
82 template <
typename Vector,
typename Class_>
87 template <
typename Vector,
typename Class_>
89 using T =
typename Vector::value_type;
96 [](
const Vector &
v,
const T &
x) {
return std::count(v.begin(), v.end(),
x); },
98 "Return the number of times ``x`` appears in the list");
102 [](
Vector &v,
const T &x) {
103 auto p = std::find(v.begin(), v.end(),
x);
111 "Remove the first item from the list whose value is x. " 112 "It is an error if there is no such item.");
116 [](
const Vector &v,
const T &x) {
return std::find(v.begin(), v.end(),
x) != v.end(); },
118 "Return true the container contains ``x``");
124 template <
typename Vector,
typename Class_>
127 using T =
typename Vector::value_type;
128 using SizeType =
typename Vector::size_type;
129 using DiffType =
typename Vector::difference_type;
131 auto wrap_i = [](DiffType
i, SizeType
n) {
135 if (i < 0 || (SizeType) i >=
n) {
145 "Add an item to the end of the list");
148 auto v = std::unique_ptr<Vector>(
new Vector());
151 v->push_back(
h.cast<T>());
157 "clear", [](
Vector &v) { v.clear(); },
"Clear the contents");
161 [](
Vector &v,
const Vector &src) { v.insert(v.end(), src.begin(), src.end()); },
163 "Extend the list by appending all the items in the given list");
168 const size_t old_size = v.size();
172 v.push_back(
h.cast<T>());
174 }
catch (
const cast_error &) {
175 v.erase(v.begin() +
static_cast<typename Vector::difference_type
>(old_size),
179 }
catch (
const std::exception &) {
186 "Extend the list by appending all the items in the given list");
190 [](
Vector &v, DiffType i,
const T &
x) {
195 if (i < 0 || (SizeType) i > v.size()) {
198 v.insert(v.begin() +
i,
x);
202 "Insert an item at a given position.");
210 T
t = std::move(v.back());
214 "Remove and return the last item");
218 [wrap_i](
Vector &v, DiffType i) {
219 i = wrap_i(i, v.size());
220 T
t = std::move(v[(SizeType) i]);
221 v.erase(std::next(v.begin(),
i));
225 "Remove and return the item at index ``i``");
227 cl.def(
"__setitem__", [wrap_i](
Vector &v, DiffType i,
const T &
t) {
228 i = wrap_i(i, v.size());
236 size_t start = 0, stop = 0,
step = 0, slicelength = 0;
238 if (!slice.
compute(v.size(), &start, &stop, &
step, &slicelength)) {
243 seq->reserve((
size_t) slicelength);
245 for (
size_t i = 0; i < slicelength; ++
i) {
246 seq->push_back(v[start]);
252 "Retrieve list elements using a slice object");
256 [](
Vector &v,
const slice &slice,
const Vector &value) {
257 size_t start = 0, stop = 0,
step = 0, slicelength = 0;
258 if (!slice.
compute(v.size(), &start, &stop, &
step, &slicelength)) {
262 if (slicelength != value.size()) {
263 throw std::runtime_error(
264 "Left and right hand size of slice assignment have different sizes!");
267 for (
size_t i = 0; i < slicelength; ++
i) {
272 "Assign list elements using a slice object");
276 [wrap_i](
Vector &v, DiffType i) {
277 i = wrap_i(i, v.size());
278 v.erase(v.begin() +
i);
280 "Delete the list elements at index ``i``");
284 [](
Vector &v,
const slice &slice) {
285 size_t start = 0, stop = 0,
step = 0, slicelength = 0;
287 if (!slice.
compute(v.size(), &start, &stop, &
step, &slicelength)) {
291 if (step == 1 &&
false) {
292 v.erase(v.begin() + (DiffType) start, v.begin() + DiffType(start + slicelength));
294 for (
size_t i = 0; i < slicelength; ++
i) {
295 v.erase(v.begin() + DiffType(start));
300 "Delete list elements using a slice object");
305 template <
typename Vector>
308 typename Vector::value_type &>>;
311 template <
typename Vector,
typename Class_>
313 using T =
typename Vector::value_type;
314 using SizeType =
typename Vector::size_type;
315 using DiffType =
typename Vector::difference_type;
316 using ItType =
typename Vector::iterator;
318 auto wrap_i = [](DiffType
i, SizeType
n) {
322 if (i < 0 || (SizeType) i >=
n) {
330 [wrap_i](
Vector &
v, DiffType i) -> T & {
331 i = wrap_i(i, v.size());
332 return v[(SizeType) i];
340 return make_iterator<return_value_policy::reference_internal, ItType, ItType, T &>(
348 template <
typename Vector,
typename Class_>
350 using T =
typename Vector::value_type;
351 using SizeType =
typename Vector::size_type;
352 using DiffType =
typename Vector::difference_type;
353 using ItType =
typename Vector::iterator;
354 cl.def(
"__getitem__", [](
const Vector &
v, DiffType
i) -> T {
355 if (i < 0 && (i += v.size()) < 0) {
358 if ((SizeType) i >= v.size()) {
361 return v[(SizeType) i];
367 return make_iterator<return_value_policy::copy, ItType, ItType, T>(v.begin(), v.end());
373 template <
typename Vector,
typename Class_>
375 -> decltype(std::declval<std::ostream &>() << std::declval<typename Vector::value_type>(),
377 using size_type =
typename Vector::size_type;
382 std::ostringstream
s;
384 for (size_type
i = 0;
i < v.size(); ++
i) {
386 if (
i != v.size() - 1) {
393 "Return the canonical string representation of this list.");
399 template <
typename Vector,
typename =
void>
401 template <
typename Vector>
404 enable_if_t<
std::is_same<decltype(format_descriptor<typename Vector::value_type>::format(),
405 std::declval<Vector>().data()),
406 typename Vector::value_type *>
::value>> : std::true_type {};
411 template <
typename... Args>
413 return detail::any_of<std::is_same<Args, buffer_protocol>...>
::value;
420 template <
typename Vector,
typename Class_,
typename... Args>
422 using T =
typename Vector::value_type;
425 "There is not an appropriate format descriptor for this vector");
442 if (
info.ndim != 1 ||
info.strides[0] % static_cast<ssize_t>(
sizeof(T))) {
443 throw type_error(
"Only valid 1D buffers can be copied to a vector");
447 throw type_error(
"Format mismatch (Python: " +
info.format
451 T *
p =
static_cast<T *
>(
info.ptr);
458 vec.reserve((
size_t)
info.shape[0]);
468 template <
typename Vector,
typename Class_,
typename... Args>
471 template <
typename Vector,
typename Class_,
typename... Args>
474 cl, detail::any_of<std::is_same<Args, buffer_protocol>...>{});
482 template <
typename Vector,
typename holder_type = std::unique_ptr<Vector>,
typename... Args>
488 using vtype =
typename Vector::value_type;
490 bool local = !vtype_info || vtype_info->module_local;
492 Class_
cl(scope, name.c_str(), pybind11::module_local(local), std::forward<Args>(
args)...);
500 detail::vector_if_copy_constructible<Vector, Class_>(cl);
503 detail::vector_if_equal_operator<Vector, Class_>(cl);
506 detail::vector_if_insertion_operator<Vector, Class_>(cl,
name);
509 detail::vector_modifiers<Vector, Class_>(cl);
512 detail::vector_accessor<Vector, Class_>(cl);
516 [](
const Vector &
v) ->
bool {
return !v.empty(); },
517 "Check whether the list is nonempty");
527 "changes the number of elements stored");
530 [](Vector &v, SizeType
i) {
533 v.erase(v.begin() +
i);
534 },
"erases element at index ``i``");
536 cl.def(
"empty", &Vector::empty,
"checks whether the container is empty");
537 cl.def(
"size", &
Vector::size,
"returns the number of elements");
538 cl.def(
"push_back", (
void (Vector::*)(
const T&)) &Vector::push_back,
"adds an element to the end");
539 cl.def(
"pop_back", &Vector::pop_back,
"removes the last element");
541 cl.def(
"max_size", &Vector::max_size,
"returns the maximum possible number of elements");
542 cl.def(
"reserve", &Vector::reserve,
"reserves storage");
543 cl.def(
"capacity", &Vector::capacity,
"returns the number of elements that can be held in currently allocated storage");
544 cl.def(
"shrink_to_fit", &Vector::shrink_to_fit,
"reduces memory usage by freeing unused memory");
546 cl.def(
"clear", &Vector::clear,
"clears the contents");
549 cl.def(
"front", [](Vector &v) {
550 if (v.size())
return v.front();
551 else throw index_error();
552 },
"access the first element");
554 cl.def(
"back", [](Vector &v) {
555 if (v.size())
return v.back();
556 else throw index_error();
557 },
"access the last element ");
571 template <
typename,
typename,
typename... Args>
573 template <
typename,
typename,
typename... Args>
577 template <
typename Map,
typename Class_>
580 using KeyType =
typename Map::key_type;
581 using MappedType =
typename Map::mapped_type;
583 cl.def(
"__setitem__", [](Map &
m,
const KeyType &k,
const MappedType &
v) {
595 template <
typename Map,
typename Class_>
599 using KeyType =
typename Map::key_type;
600 using MappedType =
typename Map::mapped_type;
602 cl.def(
"__setitem__", [](Map &
m,
const KeyType &k,
const MappedType &
v) {
604 auto r = m.emplace(k, v);
614 template <
typename Map,
typename Class_>
616 -> decltype(std::declval<std::ostream &>() << std::declval<typename Map::key_type>()
617 << std::declval<typename Map::mapped_type>(),
623 std::ostringstream
s;
626 for (
auto const &kv : m) {
630 s << kv.first <<
": " << kv.second;
636 "Return the canonical string representation of this map.");
639 template <
typename Map>
644 template <
typename Map>
649 template <
typename Map>
656 template <
typename Map,
typename holder_type = std::unique_ptr<Map>,
typename... Args>
658 using KeyType =
typename Map::key_type;
659 using MappedType =
typename Map::mapped_type;
660 using KeysView = detail::keys_view<Map>;
661 using ValuesView = detail::values_view<Map>;
662 using ItemsView = detail::items_view<Map>;
669 bool local = !tinfo || tinfo->module_local;
672 local = !tinfo || tinfo->module_local;
675 Class_
cl(scope, name.c_str(), pybind11::module_local(local), std::forward<Args>(
args)...);
677 scope, (
"KeysView[" + name +
"]").
c_str(), pybind11::module_local(local));
679 scope, (
"ValuesView[" + name +
"]").
c_str(), pybind11::module_local(local));
681 scope, (
"ItemsView[" + name +
"]").
c_str(), pybind11::module_local(local));
686 detail::map_if_insertion_operator<Map, Class_>(cl,
name);
690 [](
const Map &
m) ->
bool {
return !m.empty(); },
691 "Check whether the map is nonempty");
701 [](Map &m) {
return KeysView{m}; },
707 [](Map &m) {
return ValuesView{m}; },
713 [](Map &m) {
return ItemsView{m}; },
719 [](Map &m,
const KeyType &k) -> MappedType & {
729 cl.def(
"__contains__", [](Map &m,
const KeyType &k) ->
bool {
737 cl.def(
"__contains__", [](Map &,
const object &) ->
bool {
return false; });
740 detail::map_assignment<Map, Class_>(cl);
742 cl.def(
"__delitem__", [](Map &m,
const KeyType &k) {
752 keys_view.
def(
"__len__", [](KeysView &
view) {
return view.map.size(); });
755 [](KeysView &view) {
return make_key_iterator(view.map.begin(), view.map.end()); },
758 keys_view.
def(
"__contains__", [](KeysView &view,
const KeyType &k) ->
bool {
759 auto it = view.map.find(k);
760 if (it == view.map.end()) {
766 keys_view.
def(
"__contains__", [](KeysView &,
const object &) ->
bool {
return false; });
768 values_view.
def(
"__len__", [](ValuesView &view) {
return view.map.size(); });
775 items_view.
def(
"__len__", [](ItemsView &view) {
return view.map.size(); });
778 [](ItemsView &view) {
return make_iterator(view.map.begin(), view.map.end()); },
PYBIND11_NOINLINE detail::type_info * get_type_info(PyTypeObject *type)
def step(data, isam, result, truth, currPoseIndex)
Annotation for parent scope.
static constexpr const bool is_element
Keep patient alive while nurse lives.
void vector_modifiers(const Args &...)
void vector_if_copy_constructible(const Args &...)
constexpr bool args_any_are_buffer()
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 y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set view
buffer_info request(bool writable=false) const
class_ & def(const char *name_, Func &&f, const Extra &...extra)
void vector_buffer(Class_ &cl)
void vector_if_equal_operator(const Args &...)
#define PYBIND11_NAMESPACE
const char * c_str(Args &&...args)
int EIGEN_BLAS_FUNC() swap(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
void vector_if_insertion_operator(const Args &...)
class_< Map, holder_type > bind_map(handle scope, const std::string &name, Args &&...args)
bool compute(size_t length, size_t *start, size_t *stop, size_t *step, size_t *slicelength) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArgReturnType arg() const
Array< int, Dynamic, 1 > v
Eigen::Triplet< double > T
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
void map_if_insertion_operator(const Args &...)
static constexpr const bool is_vector
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)
void map_assignment(const Args &...)
class_< Vector, holder_type > bind_vector(handle scope, std::string const &name, Args &&...args)
void vector_buffer_impl(Class_ &cl, std::true_type)
detail::initimpl::constructor< Args... > init()
Binds an existing constructor taking arguments Args...
static EIGEN_DEPRECATED const end_t end
std::string format(const std::string &str, const std::vector< std::string > &find, const std::vector< std::string > &replace)
static std::true_type test_comparable(decltype(std::declval< const T2 &>()==std::declval< const T2 &>()) *)
size_t len_hint(handle h)
void vector_accessor(enable_if_t<!vector_needs_copy< Vector >::value, Class_ > &cl)
iterator make_key_iterator(Iterator &&first, Sentinel &&last, Extra &&...extra)
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
iterator make_iterator(Iterator &&first, Sentinel &&last, Extra &&...extra)
Makes a python iterator from a first and past-the-end C++ InputIterator.
iterator make_value_iterator(Iterator &&first, Sentinel &&last, Extra &&...extra)
Annotation for function names.
Information record describing a Python buffer object.
static std::true_type test_value(typename T2::value_type *)
static constexpr const bool is_pair
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
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
static std::true_type test_pair(typename T2::first_type *, typename T2::second_type *)
#define PYBIND11_NAMESPACE_END(name)
#define PYBIND11_NAMESPACE_BEGIN(name)