Directory: | ./ |
---|---|
File: | include/pinocchio/bindings/python/utils/std-aligned-vector.hpp |
Date: | 2024-08-27 18:20:05 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 20 | 20 | 100.0% |
Branches: | 21 | 42 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // | ||
2 | // Copyright (c) 2016-2024 CNRS INRIA | ||
3 | // | ||
4 | |||
5 | #ifndef __pinocchio_python_utils_std_aligned_vector_hpp__ | ||
6 | #define __pinocchio_python_utils_std_aligned_vector_hpp__ | ||
7 | |||
8 | #include <boost/python.hpp> | ||
9 | #include <string> | ||
10 | |||
11 | #include "pinocchio/container/aligned-vector.hpp" | ||
12 | |||
13 | #include "pinocchio/bindings/python/utils/pickle-vector.hpp" | ||
14 | #include "pinocchio/bindings/python/utils/std-vector.hpp" | ||
15 | |||
16 | namespace pinocchio | ||
17 | { | ||
18 | namespace python | ||
19 | { | ||
20 | |||
21 | /// | ||
22 | /// \brief Expose an container::aligned_vector from a type given as template argument. | ||
23 | /// | ||
24 | /// \tparam T Type to expose as container::aligned_vector<T>. | ||
25 | /// \tparam EnableFromPythonListConverter Enables the conversion from a Python list to a | ||
26 | /// container::aligned_vector<T>. | ||
27 | /// | ||
28 | /// \sa StdAlignedVectorPythonVisitor | ||
29 | /// | ||
30 | template<class T, bool NoProxy = false, bool EnableFromPythonListConverter = true> | ||
31 | struct StdAlignedVectorPythonVisitor | ||
32 | : public ::boost::python::vector_indexing_suite< | ||
33 | typename container::aligned_vector<T>, | ||
34 | NoProxy, | ||
35 | eigenpy::internal:: | ||
36 | contains_vector_derived_policies<typename container::aligned_vector<T>, NoProxy>> | ||
37 | , public eigenpy::StdContainerFromPythonList<container::aligned_vector<T>> | ||
38 | { | ||
39 | typedef container::aligned_vector<T> vector_type; | ||
40 | typedef eigenpy::StdContainerFromPythonList<vector_type, NoProxy> FromPythonListConverter; | ||
41 | typedef T value_type; | ||
42 | |||
43 | 300 | static void expose(const std::string & class_name, const std::string & doc_string = "") | |
44 | { | ||
45 |
1/2✓ Branch 1 taken 220 times.
✗ Branch 2 not taken.
|
300 | expose(class_name, doc_string, eigenpy::EmptyPythonVisitor()); |
46 | 300 | } | |
47 | |||
48 | template<typename VisitorDerived> | ||
49 | 120 | static void expose( | |
50 | const std::string & class_name, const boost::python::def_visitor<VisitorDerived> & visitor) | ||
51 | { | ||
52 |
2/4✓ Branch 2 taken 60 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 60 times.
✗ Branch 6 not taken.
|
120 | expose(class_name, "", visitor); |
53 | 120 | } | |
54 | |||
55 | template<typename VisitorDerived> | ||
56 | 420 | static void expose( | |
57 | const std::string & class_name, | ||
58 | const std::string & doc_string, | ||
59 | const boost::python::def_visitor<VisitorDerived> & visitor) | ||
60 | { | ||
61 | namespace bp = boost::python; | ||
62 |
1/2✓ Branch 1 taken 280 times.
✗ Branch 2 not taken.
|
420 | if (!eigenpy::register_symbolic_link_to_registered_type<vector_type>()) |
63 | { | ||
64 |
1/2✓ Branch 3 taken 280 times.
✗ Branch 4 not taken.
|
420 | bp::class_<vector_type> cl(class_name.c_str(), doc_string.c_str()); |
65 |
1/2✓ Branch 1 taken 280 times.
✗ Branch 2 not taken.
|
420 | cl.def(StdAlignedVectorPythonVisitor()) |
66 | |||
67 |
3/6✓ Branch 1 taken 280 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 280 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 280 times.
✗ Branch 8 not taken.
|
420 | .def(bp::init<size_t, const value_type &>( |
68 | bp::args("self", "size", "value"), | ||
69 | "Constructor from a given size and a given value.")) | ||
70 |
3/6✓ Branch 1 taken 280 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 280 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 280 times.
✗ Branch 8 not taken.
|
840 | .def(bp::init<const vector_type &>(bp::args("self", "other"), "Copy constructor")) |
71 | |||
72 |
1/2✓ Branch 1 taken 280 times.
✗ Branch 2 not taken.
|
420 | .def( |
73 | "tolist", &FromPythonListConverter::tolist, | ||
74 |
4/8✓ Branch 1 taken 280 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 280 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 280 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 280 times.
✗ Branch 11 not taken.
|
840 | (bp::arg("self"), bp::arg("deep_copy") = false), |
75 | "Returns the aligned_vector as a Python list.") | ||
76 |
1/2✓ Branch 1 taken 280 times.
✗ Branch 2 not taken.
|
420 | .def(visitor) |
77 | #ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION | ||
78 |
1/2✓ Branch 1 taken 280 times.
✗ Branch 2 not taken.
|
420 | .def_pickle(PickleVector<vector_type>()) |
79 | #endif | ||
80 |
1/2✓ Branch 1 taken 280 times.
✗ Branch 2 not taken.
|
420 | .def(eigenpy::CopyableVisitor<vector_type>()); |
81 | |||
82 | // Register conversion | ||
83 | if (EnableFromPythonListConverter) | ||
84 |
1/2✓ Branch 1 taken 280 times.
✗ Branch 2 not taken.
|
420 | FromPythonListConverter::register_converter(); |
85 | 420 | } | |
86 | 420 | } | |
87 | }; | ||
88 | } // namespace python | ||
89 | } // namespace pinocchio | ||
90 | |||
91 | #endif // ifndef __pinocchio_python_utils_std_aligned_vector_hpp__ | ||
92 |