GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/core/costs/residual.cpp
Date: 2025-01-16 08:47:40
Exec Total Coverage
Lines: 25 27 92.6%
Branches: 20 40 50.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2021-2023, University of Edinburgh, Heriot-Watt University
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
7 ///////////////////////////////////////////////////////////////////////////////
8
9 #include "crocoddyl/core/costs/residual.hpp"
10
11 #include "python/crocoddyl/core/core.hpp"
12 #include "python/crocoddyl/utils/copyable.hpp"
13
14 namespace crocoddyl {
15 namespace python {
16
17 10 void exposeCostResidual() {
18 10 bp::register_ptr_to_python<boost::shared_ptr<CostModelResidual> >();
19
20
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<CostModelResidual, bp::bases<CostModelAbstract> >(
21 "CostModelResidual",
22 "This cost function uses a residual vector with a Gauss-Newton "
23 "assumption to define a cost term.",
24
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::init<boost::shared_ptr<StateAbstract>,
25 boost::shared_ptr<ActivationModelAbstract>,
26 boost::shared_ptr<ResidualModelAbstract> >(
27 20 bp::args("self", "state", "activation", "residual"),
28 "Initialize the residual cost model.\n\n"
29 ":param state: state description\n"
30 ":param activation: activation model\n"
31 ":param residual: residual model"))
32
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
10 .def(bp::init<boost::shared_ptr<StateAbstract>,
33 boost::shared_ptr<ResidualModelAbstract> >(
34
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "state", "residual"),
35 "Initialize the residual cost model.\n\n"
36 ":param state: state description\n"
37 ":param residual: residual model"))
38 .def<void (CostModelResidual::*)(
39 const boost::shared_ptr<CostDataAbstract>&,
40 const Eigen::Ref<const Eigen::VectorXd>&,
41 20 const Eigen::Ref<const Eigen::VectorXd>&)>(
42
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 "calc", &CostModelResidual::calc, bp::args("self", "data", "x", "u"),
43 "Compute the residual cost.\n\n"
44 ":param data: cost residual data\n"
45 ":param x: state point (dim. state.nx)\n"
46 ":param u: control input (dim. nu)")
47 .def<void (CostModelResidual::*)(
48 const boost::shared_ptr<CostDataAbstract>&,
49
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 const Eigen::Ref<const Eigen::VectorXd>&)>(
50
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 "calc", &CostModelAbstract::calc, bp::args("self", "data", "x"),
51 "Compute the residual cost based on state only.\n\n"
52 "It updates the total cost based on the state only.\n"
53 "This function is used in the terminal nodes of an optimal control "
54 "problem.\n"
55 ":param data: cost data\n"
56 ":param x: state point (dim. state.nx)")
57 .def<void (CostModelResidual::*)(
58 const boost::shared_ptr<CostDataAbstract>&,
59 const Eigen::Ref<const Eigen::VectorXd>&,
60
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 const Eigen::Ref<const Eigen::VectorXd>&)>(
61 "calcDiff", &CostModelResidual::calcDiff,
62
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x", "u"),
63 "Compute the derivatives of the residual cost.\n\n"
64 "It assumes that calc has been run first.\n"
65 ":param data: cost residual data\n"
66 ":param x: state point (dim. state.nx)\n"
67 ":param u: control input (dim. nu)")
68 .def<void (CostModelResidual::*)(
69 const boost::shared_ptr<CostDataAbstract>&,
70
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 const Eigen::Ref<const Eigen::VectorXd>&)>(
71 "calcDiff", &CostModelAbstract::calcDiff,
72
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x"),
73 "Compute the derivatives of the residual cost with respect to the "
74 "state only.\n\n"
75 "It updates the Jacobian and Hessian of the cost function based on "
76 "the state only.\n"
77 "This function is used in the terminal nodes of an optimal control "
78 "problem.\n"
79 ":param data: cost residual data\n"
80 ":param x: state point (dim. state.nx)")
81
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
20 .def("createData", &CostModelResidual::createData,
82 bp::with_custodian_and_ward_postcall<0, 2>(),
83
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data"),
84 "Create the residual cost data.\n\n"
85 "Each cost model has its own data that needs to be allocated. This "
86 "function\n"
87 "returns the allocated data for a predefined cost.\n"
88 ":param data: shared data\n"
89 ":return cost data.")
90
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(CopyableVisitor<CostModelResidual>());
91
92 10 bp::register_ptr_to_python<boost::shared_ptr<CostDataResidual> >();
93
94
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<CostDataResidual, bp::bases<CostDataAbstract> >(
95 "CostDataResidual", "Data for residual cost.\n\n",
96
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::init<CostModelResidual*, DataCollectorAbstract*>(
97 10 bp::args("self", "model", "data"),
98 "Create residual cost data.\n\n"
99 ":param model: residual cost model\n"
100 ":param data: shared data")[bp::with_custodian_and_ward<
101
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 1, 2, bp::with_custodian_and_ward<1, 3> >()])
102
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(CopyableVisitor<CostDataResidual>());
103 10 }
104
105 } // namespace python
106 } // namespace crocoddyl
107