GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: unittest/python/pybind11/cpp2pybind11.cpp Lines: 45 50 90.0 %
Date: 2022-07-05 08:28:44 Branches: 28 66 42.4 %

Line Branch Exec Source
1
#include <pinocchio/bindings/python/pybind11.hpp>
2
3
// This lines forces clang-format to keep the include split here
4
#include <pybind11/pybind11.h>
5
6
#include <boost/python.hpp>
7
8
#define SCALAR double
9
#define OPTIONS 0
10
#define JOINT_MODEL_COLLECTION ::pinocchio::JointCollectionDefaultTpl
11
#include <pinocchio/bindings/python/pybind11-all.hpp>
12
13
1
pinocchio::Model* make_model() {
14
1
  pinocchio::Model* model = new pinocchio::Model;
15
1
  std::cout << "make_model: " << reinterpret_cast<intptr_t>(model) << std::endl;
16
1
  return model;
17
}
18
19
1
pinocchio::Model& return_same_model_copy(pinocchio::Model& m) { return m; }
20
1
pinocchio::Model* return_same_model_nocopy(pinocchio::Model& m) { return &m; }
21
22
4
pinocchio::SE3 multiply_se3(pinocchio::SE3 const& a, pinocchio::SE3 const& b) {
23
4
  return a * b;
24
}
25
26
template <typename T>
27
10
intptr_t get_ptr(T& m) {
28
10
  std::cout << &m << '\n' << m << std::endl;
29
10
  return reinterpret_cast<intptr_t>(&m);
30
}
31
32
void test1(int i) { std::cout << "no conversion: " << ' ' << i << std::endl; }
33
1
void testModel1(pinocchio::Model& model) {
34
1
  std::cout << "testModel1: " << &model << std::endl;
35
1
  model.name = "testModel1: I modified the model name";
36
1
}
37
1
intptr_t testModel2(pinocchio::Model& model, int i) {
38
1
  std::cout << "testModel2: " << &model << ' ' << i << std::endl;
39
1
  model.name = "testModel2: I modified the model name";
40
1
  return reinterpret_cast<intptr_t>(&model);
41
}
42
1
intptr_t testModel3(pinocchio::Model const& model, int i) {
43
1
  std::cout << "testModel3: " << &model << ' ' << i << std::endl;
44
1
  return reinterpret_cast<intptr_t>(&model);
45
}
46
47
void testModel_manual(pybind11::object model) {
48
  testModel1(pinocchio::python::from<pinocchio::Model&>(model));
49
}
50
51
using pinocchio::python::make_pybind11_function;
52
53





4
PYBIND11_MODULE(cpp2pybind11, m) {
54
  using namespace pybind11::literals;  // For _a
55
56
2
  pybind11::module::import("pinocchio");
57
2
  m.def("testModel_manual", testModel_manual);
58
59
2
  m.def("test1", make_pybind11_function(&test1));
60
61
2
  m.def("make_model", make_pybind11_function(&make_model));
62
  m.def("return_same_model_broken", make_pybind11_function(&return_same_model_copy),
63
2
        pybind11::return_value_policy::reference);
64
  m.def("return_same_model", make_pybind11_function(&return_same_model_nocopy),
65
2
        pybind11::return_value_policy::reference);
66
67
2
  m.def("get_ptr", make_pybind11_function(&get_ptr<pinocchio::Model>));
68
2
  m.def("get_se3_ptr", make_pybind11_function(&get_ptr<pinocchio::SE3>));
69
70
2
  m.def("multiply_se3_1", make_pybind11_function(&multiply_se3), "a"_a, "b"_a);
71
2
  m.def("multiply_se3", make_pybind11_function(&multiply_se3), "a"_a,
72


4
        "b"_a = pinocchio::python::default_arg(pinocchio::SE3::Identity()));
73
2
  m.def("testModel1", make_pybind11_function(&testModel1));
74
2
  m.def("testModel2", make_pybind11_function(&testModel2));
75
2
  m.def("testModel3", make_pybind11_function(&testModel3));
76
77
2
  pybind11::module no_wrapper = m.def_submodule("no_wrapper");
78
2
  no_wrapper.def("multiply_se3", &multiply_se3, "a"_a,
79
2
                 "b"_a
80
                 // does not work = pinocchio::SE3::Identity()
81
2
                 );
82
2
  no_wrapper.def("testModel1", &testModel1);
83
2
  no_wrapper.def("testModel2", &testModel2);
84
2
  no_wrapper.def("testModel3", &testModel3);
85
2
}