GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: bindings/python/crocoddyl/core/constraint-base.hpp Lines: 0 38 0.0 %
Date: 2024-02-13 11:12:33 Branches: 0 128 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)
39
      : ConstraintModelAbstract(state, nu, ng, nh),
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
      : ConstraintModelAbstract(state, ng, nh) {
47
    unone_ = NAN * MathBase::VectorXs::Ones(nu_);
48
  }
49
50
  void calc(const boost::shared_ptr<ConstraintDataAbstract>& data,
51
            const Eigen::Ref<const Eigen::VectorXd>& x,
52
            const Eigen::Ref<const Eigen::VectorXd>& u) {
53
    if (static_cast<std::size_t>(x.size()) != state_->get_nx()) {
54
      throw_pretty("Invalid argument: "
55
                   << "x has wrong dimension (it should be " +
56
                          std::to_string(state_->get_nx()) + ")");
57
    }
58
    if (static_cast<std::size_t>(u.size()) != nu_) {
59
      throw_pretty("Invalid argument: "
60
                   << "u has wrong dimension (it should be " +
61
                          std::to_string(nu_) + ")");
62
    }
63
    if (std::isnan(u.lpNorm<Eigen::Infinity>())) {
64
      return bp::call<void>(this->get_override("calc").ptr(), data,
65
                            (Eigen::VectorXd)x);
66
    } else {
67
      return bp::call<void>(this->get_override("calc").ptr(), data,
68
                            (Eigen::VectorXd)x, (Eigen::VectorXd)u);
69
    }
70
  }
71
72
  void calcDiff(const boost::shared_ptr<ConstraintDataAbstract>& data,
73
                const Eigen::Ref<const Eigen::VectorXd>& x,
74
                const Eigen::Ref<const Eigen::VectorXd>& u) {
75
    if (static_cast<std::size_t>(x.size()) != state_->get_nx()) {
76
      throw_pretty("Invalid argument: "
77
                   << "x has wrong dimension (it should be " +
78
                          std::to_string(state_->get_nx()) + ")");
79
    }
80
    if (static_cast<std::size_t>(u.size()) != nu_) {
81
      throw_pretty("Invalid argument: "
82
                   << "u has wrong dimension (it should be " +
83
                          std::to_string(nu_) + ")");
84
    }
85
    if (std::isnan(u.lpNorm<Eigen::Infinity>())) {
86
      return bp::call<void>(this->get_override("calcDiff").ptr(), data,
87
                            (Eigen::VectorXd)x);
88
    } else {
89
      return bp::call<void>(this->get_override("calcDiff").ptr(), data,
90
                            (Eigen::VectorXd)x, (Eigen::VectorXd)u);
91
    }
92
  }
93
94
  boost::shared_ptr<ConstraintDataAbstract> createData(
95
      DataCollectorAbstract* const data) {
96
    if (boost::python::override createData = this->get_override("createData")) {
97
      return bp::call<boost::shared_ptr<ConstraintDataAbstract> >(
98
          createData.ptr(), boost::ref(data));
99
    }
100
    return ConstraintModelAbstract::createData(data);
101
  }
102
103
  boost::shared_ptr<ConstraintDataAbstract> default_createData(
104
      DataCollectorAbstract* const data) {
105
    return this->ConstraintModelAbstract::createData(data);
106
  }
107
};
108
109
}  // namespace python
110
}  // namespace crocoddyl
111
112
#endif  // BINDINGS_PYTHON_CROCODDYL_CORE_CONSTRAINT_BASE_HPP_