Skip to content

Commit 1521fb3

Browse files
authored
Merge pull request stack-of-tasks#2659 from jorisv/topic/fix-algo-custom-scalar
Fix custom scalar support
2 parents 9ea33e6 + 8b4c065 commit 1521fb3

File tree

11 files changed

+17
-52
lines changed

11 files changed

+17
-52
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
88

99
### Fixed
1010
- Fix getters for models and data in `VisualizerPythonVisitor` ([#2647](https://github.com/stack-of-tasks/pinocchio/pull/2647))
11+
- Fix `pinocchio::cholesky::Mv` build with `CppAd` scalar ([#2659](https://github.com/stack-of-tasks/pinocchio/pull/2659))
12+
- Fix `pinocchio::contactABA` build with `casadi` scalar ([#2659](https://github.com/stack-of-tasks/pinocchio/pull/2659))
13+
14+
### Added
15+
- Add explicit template instantiation for constraint algorithms for `casadi`, `CppAD` and `CppADCodeGen` scalar ([#2659](https://github.com/stack-of-tasks/pinocchio/pull/2659))
16+
- Add `casadi` bindings for `pinocchio.initConstraintDynamics` and `pinocchio.constraintDynamics` ([#2659](https://github.com/stack-of-tasks/pinocchio/pull/2659))
17+
1118

1219
## [3.5.0] - 2025-04-02
1320

bindings/python/algorithm/expose-constrained-dynamics.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ namespace pinocchio
2525
typedef PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR(context::RigidConstraintData)
2626
RigidConstraintDataVector;
2727

28-
#ifndef PINOCCHIO_PYTHON_SKIP_ALGORITHM_CONSTRAINED_DYNAMICS
29-
3028
static const context::VectorXs constraintDynamics_proxy(
3129
const context::Model & model,
3230
context::Data & data,
@@ -53,8 +51,6 @@ namespace pinocchio
5351
return constraintDynamics(model, data, q, v, tau, contact_models, contact_datas);
5452
}
5553

56-
#endif // PINOCCHIO_PYTHON_SKIP_ALGORITHM_CONSTRAINED_DYNAMICS
57-
5854
void exposeConstraintDynamics()
5955
{
6056
using namespace Eigen;
@@ -77,7 +73,6 @@ namespace pinocchio
7773

7874
StdVectorPythonVisitor<RigidConstraintDataVector>::expose("StdVec_RigidConstraintData");
7975

80-
#ifndef PINOCCHIO_PYTHON_SKIP_ALGORITHM_CONSTRAINED_DYNAMICS
8176
ContactCholeskyDecompositionPythonVisitor<context::ContactCholeskyDecomposition>::expose();
8277

8378
bp::def(
@@ -112,8 +107,6 @@ namespace pinocchio
112107
"This function returns joint acceleration of the system. The contact forces are "
113108
"stored in the list data.contact_forces.",
114109
mimic_not_supported_function<>(0));
115-
116-
#endif // PINOCCHIO_PYTHON_SKIP_ALGORITHM_CONSTRAINED_DYNAMICS
117110
}
118111
} // namespace python
119112
} // namespace pinocchio

include/pinocchio/algorithm/cholesky.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ namespace pinocchio
363363

364364
for (int k = model.nv - 1; k >= 0; --k)
365365
{
366-
vout_[k] = M.row(k).segment(k, nvt[(size_t)k]) * vin.segment(k, nvt[(size_t)k]);
366+
vout_[k] = M.row(k).segment(k, nvt[(size_t)k]).dot(vin.segment(k, nvt[(size_t)k]));
367367
vout_.segment(k + 1, nvt[(size_t)k] - 1) +=
368368
M.row(k).segment(k + 1, nvt[(size_t)k] - 1).transpose() * vin[k];
369369
}

include/pinocchio/algorithm/constrained-dynamics.hxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "pinocchio/algorithm/contact-cholesky.hxx"
1414
#include "pinocchio/algorithm/crba.hpp"
1515
#include "pinocchio/algorithm/cholesky.hpp"
16+
#include "pinocchio/math/fwd.hpp"
1617
#include <limits>
1718

1819
namespace pinocchio
@@ -888,16 +889,15 @@ namespace pinocchio
888889
cdata.contact_acceleration_deviation.linear() +=
889890
contact1_velocity.angular().cross(contact1_velocity.linear());
890891

891-
using std::max;
892892
if (cmodel.type == CONTACT_3D)
893893
{
894-
primal_infeasibility = max<Scalar>(
894+
primal_infeasibility = math::max<Scalar>(
895895
primal_infeasibility,
896896
cdata.contact_acceleration_deviation.linear().template lpNorm<Eigen::Infinity>());
897897
}
898898
else
899899
{
900-
primal_infeasibility = max<Scalar>(
900+
primal_infeasibility = math::max<Scalar>(
901901
primal_infeasibility,
902902
cdata.contact_acceleration_deviation.toVector().template lpNorm<Eigen::Infinity>());
903903
}

include/pinocchio/algorithm/contact-cholesky.txx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,6 @@ namespace pinocchio
101101
ContactCholeskyDecompositionTpl<context::Scalar, context::Options>::inverse<context::MatrixXs>(
102102
const Eigen::MatrixBase<context::MatrixXs> &) const;
103103

104-
extern template PINOCCHIO_EXPLICIT_INSTANTIATION_DECLARATION_DLLAPI bool
105-
ContactCholeskyDecompositionTpl<context::Scalar, context::Options>::
106-
operator== <context::Scalar, context::Options>(
107-
const ContactCholeskyDecompositionTpl<context::Scalar, context::Options> &) const;
108-
109-
extern template PINOCCHIO_EXPLICIT_INSTANTIATION_DECLARATION_DLLAPI bool
110-
ContactCholeskyDecompositionTpl<context::Scalar, context::Options>::
111-
operator!= <context::Scalar, context::Options>(
112-
const ContactCholeskyDecompositionTpl<context::Scalar, context::Options> &) const;
113-
114104
PINOCCHIO_COMPILER_DIAGNOSTIC_POP
115105

116106
} // namespace pinocchio

include/pinocchio/bindings/python/algorithm/contact-cholesky.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,11 @@ namespace pinocchio
188188
"Returns the Constraint Cholesky decomposition associated to this "
189189
"DelassusCholeskyExpression.",
190190
bp::return_internal_reference<>())
191-
192191
.def(DelassusOperatorBasePythonVisitor<DelassusCholeskyExpression>());
193192
}
194193

195194
{
195+
#ifndef PINOCCHIO_PYTHON_SKIP_CASADI_UNSUPPORTED
196196
typedef DelassusOperatorDenseTpl<context::Scalar, context::Options> DelassusOperatorDense;
197197
bp::class_<DelassusOperatorDense>(
198198
"DelassusOperatorDense", "Delassus Cholesky dense operator from a dense matrix.",
@@ -201,9 +201,11 @@ namespace pinocchio
201201
bp::args("self", "matrix"), "Build from a given dense matrix"))
202202

203203
.def(DelassusOperatorBasePythonVisitor<DelassusOperatorDense>());
204+
#endif // PINOCCHIO_PYTHON_SKIP_CASADI_UNSUPPORTED
204205
}
205206

206207
{
208+
#ifndef PINOCCHIO_PYTHON_SKIP_CASADI_UNSUPPORTED
207209
typedef DelassusOperatorSparseTpl<context::Scalar, context::Options>
208210
DelassusOperatorSparse;
209211
bp::class_<DelassusOperatorSparse, boost::noncopyable>(
@@ -213,6 +215,7 @@ namespace pinocchio
213215
bp::args("self", "matrix"), "Build from a given sparse matrix"))
214216

215217
.def(DelassusOperatorBasePythonVisitor<DelassusOperatorSparse>());
218+
#endif // PINOCCHIO_PYTHON_SKIP_CASADI_UNSUPPORTED
216219
}
217220
#ifdef PINOCCHIO_WITH_ACCELERATE_SUPPORT
218221
{

include/pinocchio/context/casadi.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
#ifndef __pinocchio_context_casadi_hpp__
66
#define __pinocchio_context_casadi_hpp__
77

8-
#define PINOCCHIO_SKIP_ALGORITHM_CONSTRAINED_DYNAMICS_DERIVATIVES
9-
#define PINOCCHIO_SKIP_ALGORITHM_CONSTRAINED_DYNAMICS
10-
#define PINOCCHIO_SKIP_ALGORITHM_CONTACT_DYNAMICS
11-
#define PINOCCHIO_SKIP_ALGORITHM_CONTACT_CHOLESKY
12-
#define PINOCCHIO_SKIP_ALGORITHM_CONTACT_JACOBIAN
13-
#define PINOCCHIO_SKIP_ALGORITHM_CHOLESKY
148
#define PINOCCHIO_SKIP_ALGORITHM_MODEL
159
#define PINOCCHIO_SKIP_ALGORITHM_GEOMETRY
1610
#define PINOCCHIO_SKIP_MULTIBODY_SAMPLE_MODELS

include/pinocchio/context/cppad.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@
77

88
#include <cppad/cppad.hpp>
99

10-
#define PINOCCHIO_SKIP_ALGORITHM_CONSTRAINED_DYNAMICS_DERIVATIVES
11-
#define PINOCCHIO_SKIP_ALGORITHM_CONSTRAINED_DYNAMICS
12-
#define PINOCCHIO_SKIP_ALGORITHM_CONTACT_DYNAMICS
13-
#define PINOCCHIO_SKIP_ALGORITHM_CONTACT_CHOLESKY
14-
#define PINOCCHIO_SKIP_ALGORITHM_CONTACT_JACOBIAN
15-
#define PINOCCHIO_SKIP_ALGORITHM_CHOLESKY
1610
#define PINOCCHIO_SKIP_ALGORITHM_MODEL
1711
#define PINOCCHIO_SKIP_ALGORITHM_GEOMETRY
1812
#define PINOCCHIO_SKIP_MULTIBODY_SAMPLE_MODELS

include/pinocchio/context/cppadcg.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@
88
#include <cppad/cg/support/cppadcg_eigen.hpp>
99
#include <cppad/cppad.hpp>
1010

11-
#define PINOCCHIO_SKIP_ALGORITHM_CONSTRAINED_DYNAMICS_DERIVATIVES
12-
#define PINOCCHIO_SKIP_ALGORITHM_CONSTRAINED_DYNAMICS
13-
#define PINOCCHIO_SKIP_ALGORITHM_CONTACT_DYNAMICS
14-
#define PINOCCHIO_SKIP_ALGORITHM_CONTACT_CHOLESKY
15-
#define PINOCCHIO_SKIP_ALGORITHM_CONTACT_JACOBIAN
16-
#define PINOCCHIO_SKIP_ALGORITHM_CHOLESKY
1711
#define PINOCCHIO_SKIP_ALGORITHM_MODEL
1812
#define PINOCCHIO_SKIP_ALGORITHM_GEOMETRY
1913
#define PINOCCHIO_SKIP_MULTIBODY_SAMPLE_MODELS

include/pinocchio/math/eigenvalues.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace pinocchio
3535
void run(const MatrixLike & mat)
3636
{
3737
PINOCCHIO_CHECK_INPUT_ARGUMENT(max_it >= 1);
38-
PINOCCHIO_CHECK_INPUT_ARGUMENT(rel_tol > Scalar(0));
38+
PINOCCHIO_CHECK_INPUT_ARGUMENT((check_expression_if_real<Scalar, true>(rel_tol > 0)));
3939
Scalar eigenvalue_est = principal_eigen_vector.norm();
4040

4141
for (it = 0; it < max_it; ++it)
@@ -68,7 +68,7 @@ namespace pinocchio
6868
void lowest(const MatrixLike & mat, const bool compute_largest = true)
6969
{
7070
PINOCCHIO_CHECK_INPUT_ARGUMENT(max_it >= 1);
71-
PINOCCHIO_CHECK_INPUT_ARGUMENT(rel_tol > Scalar(0));
71+
PINOCCHIO_CHECK_INPUT_ARGUMENT((check_expression_if_real<Scalar, true>(rel_tol > 0)));
7272

7373
if (compute_largest)
7474
run(mat);

0 commit comments

Comments
 (0)