From 749a76ae1693c720b4fedbcdd5a9a3c9080a4a2d Mon Sep 17 00:00:00 2001 From: Joseph Mirabel Date: Wed, 24 Oct 2018 19:54:04 +0200 Subject: [PATCH] Fix compatibility with Eigen 3.2.0 --- src/dintegrate-visitor.hh | 22 ++++++++++++++++++---- src/eigen_fix.hh | 28 ++++++++++++++++++++++++++++ src/jdifference-visitor.hh | 26 ++++++++++++++++++-------- 3 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 src/eigen_fix.hh diff --git a/src/dintegrate-visitor.hh b/src/dintegrate-visitor.hh index 003eabb..e496856 100644 --- a/src/dintegrate-visitor.hh +++ b/src/dintegrate-visitor.hh @@ -19,6 +19,8 @@ # include +# include <../src/eigen_fix.hh> + namespace hpp { namespace pinocchio { namespace liegroupType { @@ -30,8 +32,14 @@ namespace hpp { template void operator () (const LgT& lg) { typename LgT::JacobianMatrix_t JqInt (lg.nv(), lg.nv()); - lg.dIntegrate_dq (q_.vector().segment(configRow_, lg.nq()), v_.segment(row_, lg.nv()), JqInt); - Jq_.middleRows (row_, lg.nv()).applyOnTheLeft (JqInt); + lg.dIntegrate_dq ( + // q_.vector().segment(configRow_, lg.nq()), + _BLOCK_ACCESSOR_EIGEN(q_.vector(),segment,LgT::NQ, configRow_, lg.nq()), + // v_.segment(row_, lg.nv()), + _BLOCK_ACCESSOR_EIGEN(v_,segment,LgT::NV, row_, lg.nv()), + JqInt); + // Jq_.middleRows (row_, lg.nv()).applyOnTheLeft (JqInt); + _BLOCK_ACCESSOR_EIGEN(Jq_,middleRows,LgT::NV, row_, lg.nv()).applyOnTheLeft (JqInt); row_ += lg.nv(); configRow_ += lg.nq(); } @@ -57,8 +65,14 @@ namespace hpp { template void operator () (const LgT& lg) { typename LgT::JacobianMatrix_t JvInt (lg.nv(), lg.nv()); - lg.dIntegrate_dv (q_.vector().segment(configRow_, lg.nq()), v_.segment(row_, lg.nv()), JvInt); - Jv_.middleRows (row_, lg.nv()).applyOnTheLeft (JvInt); + lg.dIntegrate_dv ( + // q_.vector().segment(configRow_, lg.nq()), + _BLOCK_ACCESSOR_EIGEN(q_.vector(),segment,LgT::NQ, configRow_, lg.nq()), + // v_.segment(row_, lg.nv()), + _BLOCK_ACCESSOR_EIGEN(v_,segment,LgT::NV, row_, lg.nv()), + JvInt); + // Jv_.middleRows (row_, lg.nv()).applyOnTheLeft (JvInt); + _BLOCK_ACCESSOR_EIGEN(Jv_,middleRows,LgT::NV, row_, lg.nv()).applyOnTheLeft (JvInt); row_ += lg.nv(); configRow_ += lg.nq(); } diff --git a/src/eigen_fix.hh b/src/eigen_fix.hh new file mode 100644 index 0000000..5534a6d --- /dev/null +++ b/src/eigen_fix.hh @@ -0,0 +1,28 @@ +// Copyright (c) 2018, CNRS +// Authors: Joseph Mirabel (joseph.mirabel@laas.fr) +// +// This file is part of hpp-pinocchio. +// hpp-pinocchio is free software: you can redistribute it +// and/or modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation, either version +// 3 of the License, or (at your option) any later version. +// +// hpp-pinocchio is distributed in the hope that it will be +// useful, but WITHOUT ANY WARRANTY; without even the implied warranty +// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// hpp-pinocchio. If not, see . + +// Eigen 3.2.0 has no fixed size segment<>, moddleRows<>, middleCols<> with 2 +// arguments. This is not documented in recent eigen either. +// This was introduced in Eigen 3.2.1. See +// - http://eigen.tuxfamily.org/index.php?title=ChangeLog#Eigen_3.2.1 (bug 579) +// - http://eigen.tuxfamily.org/bz/show_bug.cgi?id=579 +#if EIGEN_VERSION_AT_LEAST(3,2,1) +# define _BLOCK_ACCESSOR_EIGEN(var,method,tplSize,arg,size) \ + var.method(arg,size) +#else +# define _BLOCK_ACCESSOR_EIGEN(var,method,tplSize,arg,size) \ + ((tplSize==Eigen::Dynamic) ? var.method(arg,size) : var.method(arg)) +#endif diff --git a/src/jdifference-visitor.hh b/src/jdifference-visitor.hh index 64f6f06..402ac97 100644 --- a/src/jdifference-visitor.hh +++ b/src/jdifference-visitor.hh @@ -19,6 +19,8 @@ # include +# include <../src/eigen_fix.hh> + namespace hpp { namespace pinocchio { namespace liegroupType { @@ -41,21 +43,27 @@ namespace hpp { typename LgT::JacobianMatrix_t J1int (lg.nv(), lg.nv()); lg.Jdifference ( - q0_.segment(iq_, lg.nq()), - q1_.segment(iq_, lg.nq()), + // q0_.segment(iq_, lg.nq()), + _BLOCK_ACCESSOR_EIGEN(q0_,segment,LgT::NQ, iq_, lg.nq()), + // q1_.segment(iq_, lg.nq()), + _BLOCK_ACCESSOR_EIGEN(q1_,segment,LgT::NQ, iq_, lg.nq()), J0int, J1int); if (J0_.size() > 0) { if (ApplyOnTheLeft) - J0_.middleRows (iv_, lg.nv()).applyOnTheLeft (J0int); + // J0_.middleRows (iv_, lg.nv()).applyOnTheLeft (J0int); + _BLOCK_ACCESSOR_EIGEN(J0_,middleRows,LgT::NV, iv_, lg.nv()).applyOnTheLeft (J0int); else - J0_.middleCols (iv_, lg.nv()).applyOnTheRight (J0int); + // J0_.middleCols (iv_, lg.nv()).applyOnTheRight (J0int); + _BLOCK_ACCESSOR_EIGEN(J0_,middleCols,LgT::NV, iv_, lg.nv()).applyOnTheRight (J0int); } if (J1_.size() > 0) { if (ApplyOnTheLeft) - J1_.middleRows (iv_, lg.nv()).applyOnTheLeft (J1int); + // J1_.middleRows (iv_, lg.nv()).applyOnTheLeft (J1int); + _BLOCK_ACCESSOR_EIGEN(J1_,middleRows,LgT::NV, iv_, lg.nv()).applyOnTheLeft (J1int); else - J1_.middleCols (iv_, lg.nv()).applyOnTheRight (J1int); + // J1_.middleCols (iv_, lg.nv()).applyOnTheRight (J1int); + _BLOCK_ACCESSOR_EIGEN(J1_,middleCols,LgT::NV, iv_, lg.nv()).applyOnTheRight (J1int); } iq_ += lg.nq(); iv_ += lg.nv(); @@ -66,9 +74,11 @@ namespace hpp { { if (J0_.size() > 0) { if (ApplyOnTheLeft) - J0_.middleRows (iv_, lg.nv()) *= -1; + // J0_.middleRows (iv_, lg.nv()) *= -1; + _BLOCK_ACCESSOR_EIGEN(J0_,middleRows,N, iv_, lg.nv()) *= -1; else - J0_.middleCols (iv_, lg.nv()) *= -1; + // J0_.middleCols (iv_, lg.nv()) *= -1; + _BLOCK_ACCESSOR_EIGEN(J0_,middleCols,N, iv_, lg.nv()) *= -1; } iq_ += lg.nq(); iv_ += lg.nv();