GCC Code Coverage Report


Directory: ./
File: include/pinocchio/bindings/python/utils/model-checker.hpp
Date: 2025-04-30 16:14:33
Exec Total Coverage
Lines: 11 11 100.0%
Branches: 11 20 55.0%

Line Branch Exec Source
1 //
2 // Copyright (c) 2025 INRIA
3 //
4
5 #ifndef __pinocchio_python_utils_model_checker_hpp__
6 #define __pinocchio_python_utils_model_checker_hpp__
7
8 #include <Python.h>
9 #include <string>
10
11 #include "pinocchio/algorithm/check-model.hpp"
12 #include "pinocchio/bindings/python/fwd.hpp"
13
14 namespace pinocchio
15 {
16 namespace python
17 {
18
19 // Checker Policy to make a safe version of python function, concerning joint mimic.
20 // This will throw a runtime error in case algorithm does not allow joint mimic in the model.
21 template<class Policy = boost::python::default_call_policies>
22 struct mimic_not_supported_function : Policy
23 {
24 5032 mimic_not_supported_function(size_t model_idx_)
25 : Policy()
26 5032 , model_idx(model_idx_)
27 {
28 5032 }
29
30 template<class ArgumentPackage>
31 262 bool precall(ArgumentPackage const & args) const
32 {
33 // Convert the object to a tuple
34
2/4
✓ Branch 1 taken 262 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 262 times.
✗ Branch 5 not taken.
262 boost::python::tuple py_args = boost::python::extract<boost::python::tuple>(args);
35
36
5/10
✓ Branch 1 taken 262 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 262 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 262 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 262 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 262 times.
✗ Branch 14 not taken.
524 context::Model m = boost::python::extract<context::Model>(py_args[model_idx]);
37
3/4
✓ Branch 1 taken 262 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 261 times.
262 if (!m.check(MimicChecker()))
38 {
39
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 PyErr_SetString(PyExc_RuntimeError, m_error_message.c_str());
40 1 return false;
41 }
42 else
43 261 return static_cast<const Policy *>(this)->precall(args);
44 262 }
45
46 protected:
47 static const std::string m_error_message;
48 // index of the pinocchio in the function arguments. Need it to avoid a loop
49 const size_t model_idx;
50 };
51
52 template<class Policy>
53 const std::string mimic_not_supported_function<Policy>::m_error_message =
54 "This algorithm does not support Joint Mimic type in the model.";
55 } // namespace python
56 } // namespace pinocchio
57 #endif // model_checker
58