Line |
Branch |
Exec |
Source |
1 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
2 |
|
|
// BSD 3-Clause License |
3 |
|
|
// |
4 |
|
|
// Copyright (C) 2019-2025, LAAS-CNRS, University of Edinburgh, |
5 |
|
|
// Heriot-Watt University |
6 |
|
|
// Copyright note valid unless otherwise stated in individual files. |
7 |
|
|
// All rights reserved. |
8 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
9 |
|
|
|
10 |
|
|
#ifndef BINDINGS_PYTHON_CROCODDYL_CORE_ACTIVATION_BASE_HPP_ |
11 |
|
|
#define BINDINGS_PYTHON_CROCODDYL_CORE_ACTIVATION_BASE_HPP_ |
12 |
|
|
|
13 |
|
|
#include "crocoddyl/core/activation-base.hpp" |
14 |
|
|
#include "python/crocoddyl/core/core.hpp" |
15 |
|
|
|
16 |
|
|
namespace crocoddyl { |
17 |
|
|
namespace python { |
18 |
|
|
|
19 |
|
|
template <typename Scalar> |
20 |
|
|
class ActivationModelAbstractTpl_wrap |
21 |
|
|
: public ActivationModelAbstractTpl<Scalar>, |
22 |
|
|
public bp::wrapper<ActivationModelAbstractTpl<Scalar>> { |
23 |
|
|
public: |
24 |
|
|
EIGEN_MAKE_ALIGNED_OPERATOR_NEW |
25 |
|
✗ |
CROCODDYL_DERIVED_CAST(ActivationModelBase, ActivationModelAbstractTpl_wrap) |
26 |
|
|
|
27 |
|
|
typedef typename crocoddyl::ActivationModelAbstractTpl<Scalar> |
28 |
|
|
ActivationModel; |
29 |
|
|
typedef typename crocoddyl::ActivationDataAbstractTpl<Scalar> ActivationData; |
30 |
|
|
typedef typename ActivationModel::VectorXs VectorXs; |
31 |
|
|
using ActivationModel::nr_; |
32 |
|
|
|
33 |
|
✗ |
explicit ActivationModelAbstractTpl_wrap(const std::size_t nr) |
34 |
|
✗ |
: ActivationModel(nr), bp::wrapper<ActivationModel>() {} |
35 |
|
|
|
36 |
|
✗ |
void calc(const std::shared_ptr<ActivationData>& data, |
37 |
|
|
const Eigen::Ref<const VectorXs>& r) override { |
38 |
|
✗ |
if (static_cast<std::size_t>(r.size()) != nr_) { |
39 |
|
✗ |
throw_pretty( |
40 |
|
|
"Invalid argument: " << "r has wrong dimension (it should be " + |
41 |
|
|
std::to_string(nr_) + ")"); |
42 |
|
|
} |
43 |
|
✗ |
return bp::call<void>(this->get_override("calc").ptr(), data, (VectorXs)r); |
44 |
|
|
} |
45 |
|
|
|
46 |
|
✗ |
void calcDiff(const std::shared_ptr<ActivationData>& data, |
47 |
|
|
const Eigen::Ref<const VectorXs>& r) override { |
48 |
|
✗ |
if (static_cast<std::size_t>(r.size()) != nr_) { |
49 |
|
✗ |
throw_pretty( |
50 |
|
|
"Invalid argument: " << "r has wrong dimension (it should be " + |
51 |
|
|
std::to_string(nr_) + ")"); |
52 |
|
|
} |
53 |
|
✗ |
return bp::call<void>(this->get_override("calcDiff").ptr(), data, |
54 |
|
✗ |
(VectorXs)r); |
55 |
|
|
} |
56 |
|
|
|
57 |
|
✗ |
std::shared_ptr<ActivationData> createData() override { |
58 |
|
✗ |
enableMultithreading() = false; |
59 |
|
✗ |
if (boost::python::override createData = this->get_override("createData")) { |
60 |
|
✗ |
return bp::call<std::shared_ptr<ActivationData>>(createData.ptr()); |
61 |
|
|
} |
62 |
|
✗ |
return ActivationModel::createData(); |
63 |
|
|
} |
64 |
|
|
|
65 |
|
✗ |
std::shared_ptr<ActivationData> default_createData() { |
66 |
|
✗ |
return this->ActivationModel::createData(); |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
template <typename NewScalar> |
70 |
|
✗ |
ActivationModelAbstractTpl_wrap<NewScalar> cast() const { |
71 |
|
|
typedef ActivationModelAbstractTpl_wrap<NewScalar> ReturnType; |
72 |
|
✗ |
ReturnType ret(nr_); |
73 |
|
✗ |
return ret; |
74 |
|
|
} |
75 |
|
|
}; |
76 |
|
|
|
77 |
|
|
} // namespace python |
78 |
|
|
} // namespace crocoddyl |
79 |
|
|
|
80 |
|
|
#endif // BINDINGS_PYTHON_CROCODDYL_CORE_ACTIVATION_BASE_HPP_ |
81 |
|
|
|