GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/core/constraint-base.hpp
Date: 2025-01-16 08:47:40
Exec Total Coverage
Lines: 0 37 0.0%
Branches: 0 130 0.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2020-2024, University of Edinburgh, Heriot-Watt University
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
7 ///////////////////////////////////////////////////////////////////////////////
8
9 #ifndef BINDINGS_PYTHON_CROCODDYL_CORE_CONSTRAINT_BASE_HPP_
10 #define BINDINGS_PYTHON_CROCODDYL_CORE_CONSTRAINT_BASE_HPP_
11
12 #include "crocoddyl/core/constraint-base.hpp"
13 #include "crocoddyl/core/utils/exception.hpp"
14 #include "python/crocoddyl/core/core.hpp"
15
16 namespace crocoddyl {
17 namespace python {
18
19 class ConstraintModelAbstract_wrap
20 : public ConstraintModelAbstract,
21 public bp::wrapper<ConstraintModelAbstract> {
22 public:
23 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
24 using ConstraintModelAbstract::nu_;
25 using ConstraintModelAbstract::unone_;
26
27 ConstraintModelAbstract_wrap(
28 boost::shared_ptr<StateAbstract> state,
29 boost::shared_ptr<ResidualModelAbstract> residual, const std::size_t ng,
30 const std::size_t nh)
31 : ConstraintModelAbstract(state, residual, ng, nh),
32 bp::wrapper<ConstraintModelAbstract>() {
33 unone_ = NAN * MathBase::VectorXs::Ones(nu_);
34 }
35
36 ConstraintModelAbstract_wrap(boost::shared_ptr<StateAbstract> state,
37 const std::size_t nu, const std::size_t ng,
38 const std::size_t nh, const bool T_const = true)
39 : ConstraintModelAbstract(state, nu, ng, nh, T_const),
40 bp::wrapper<ConstraintModelAbstract>() {
41 unone_ = NAN * MathBase::VectorXs::Ones(nu);
42 }
43
44 ConstraintModelAbstract_wrap(boost::shared_ptr<StateAbstract> state,
45 const std::size_t ng, const std::size_t nh,
46 const bool T_const = true)
47 : ConstraintModelAbstract(state, ng, nh, T_const) {
48 unone_ = NAN * MathBase::VectorXs::Ones(nu_);
49 }
50
51 void calc(const boost::shared_ptr<ConstraintDataAbstract>& data,
52 const Eigen::Ref<const Eigen::VectorXd>& x,
53 const Eigen::Ref<const Eigen::VectorXd>& u) {
54 if (static_cast<std::size_t>(x.size()) != state_->get_nx()) {
55 throw_pretty(
56 "Invalid argument: " << "x has wrong dimension (it should be " +
57 std::to_string(state_->get_nx()) + ")");
58 }
59 if (static_cast<std::size_t>(u.size()) != nu_) {
60 throw_pretty(
61 "Invalid argument: " << "u has wrong dimension (it should be " +
62 std::to_string(nu_) + ")");
63 }
64 if (std::isnan(u.lpNorm<Eigen::Infinity>())) {
65 return bp::call<void>(this->get_override("calc").ptr(), data,
66 (Eigen::VectorXd)x);
67 } else {
68 return bp::call<void>(this->get_override("calc").ptr(), data,
69 (Eigen::VectorXd)x, (Eigen::VectorXd)u);
70 }
71 }
72
73 void calcDiff(const boost::shared_ptr<ConstraintDataAbstract>& data,
74 const Eigen::Ref<const Eigen::VectorXd>& x,
75 const Eigen::Ref<const Eigen::VectorXd>& u) {
76 if (static_cast<std::size_t>(x.size()) != state_->get_nx()) {
77 throw_pretty(
78 "Invalid argument: " << "x has wrong dimension (it should be " +
79 std::to_string(state_->get_nx()) + ")");
80 }
81 if (static_cast<std::size_t>(u.size()) != nu_) {
82 throw_pretty(
83 "Invalid argument: " << "u has wrong dimension (it should be " +
84 std::to_string(nu_) + ")");
85 }
86 if (std::isnan(u.lpNorm<Eigen::Infinity>())) {
87 return bp::call<void>(this->get_override("calcDiff").ptr(), data,
88 (Eigen::VectorXd)x);
89 } else {
90 return bp::call<void>(this->get_override("calcDiff").ptr(), data,
91 (Eigen::VectorXd)x, (Eigen::VectorXd)u);
92 }
93 }
94
95 boost::shared_ptr<ConstraintDataAbstract> createData(
96 DataCollectorAbstract* const data) {
97 if (boost::python::override createData = this->get_override("createData")) {
98 return bp::call<boost::shared_ptr<ConstraintDataAbstract> >(
99 createData.ptr(), boost::ref(data));
100 }
101 return ConstraintModelAbstract::createData(data);
102 }
103
104 boost::shared_ptr<ConstraintDataAbstract> default_createData(
105 DataCollectorAbstract* const data) {
106 return this->ConstraintModelAbstract::createData(data);
107 }
108 };
109
110 } // namespace python
111 } // namespace crocoddyl
112
113 #endif // BINDINGS_PYTHON_CROCODDYL_CORE_CONSTRAINT_BASE_HPP_
114