Skip to content

Commit

Permalink
core: Avoid a GCC explicit template instantiation and symbol visibili…
Browse files Browse the repository at this point in the history
…ty bug
  • Loading branch information
jorisv committed Nov 5, 2024
1 parent 0eaf355 commit e9fb11f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 33 deletions.
46 changes: 13 additions & 33 deletions include/pinocchio/algorithm/contact-cholesky.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace pinocchio
///
template<typename _Scalar, int _Options>
struct PINOCCHIO_UNSUPPORTED_MESSAGE("The API will change towards more flexibility")
PINOCCHIO_DLLAPI ContactCholeskyDecompositionTpl
ContactCholeskyDecompositionTpl
{
EIGEN_MAKE_ALIGNED_OPERATOR_NEW

Expand Down Expand Up @@ -104,9 +104,7 @@ namespace pinocchio
///
/// \brief Default constructor
///
ContactCholeskyDecompositionTpl()
{
}
ContactCholeskyDecompositionTpl() = default;

///
/// \brief Constructor from a model.
Expand Down Expand Up @@ -463,35 +461,10 @@ namespace pinocchio
///@}

template<typename S1, int O1>
bool operator==(const ContactCholeskyDecompositionTpl<S1, O1> & other) const
{
bool is_same = true;

if (nv != other.nv || num_contacts != other.num_contacts)
return false;

if (
D.size() != other.D.size() || Dinv.size() != other.Dinv.size() || U.rows() != other.U.rows()
|| U.cols() != other.U.cols())
return false;

is_same &= (D == other.D);
is_same &= (Dinv == other.Dinv);
is_same &= (U == other.U);

is_same &= (parents_fromRow == other.parents_fromRow);
is_same &= (nv_subtree_fromRow == other.nv_subtree_fromRow);
is_same &= (last_child == other.last_child);
// is_same &= (rowise_sparsity_pattern == other.rowise_sparsity_pattern);

return is_same;
}
bool operator==(const ContactCholeskyDecompositionTpl<S1, O1> & other) const;

template<typename S1, int O1>
bool operator!=(const ContactCholeskyDecompositionTpl<S1, O1> & other) const
{
return !(*this == other);
}
bool operator!=(const ContactCholeskyDecompositionTpl<S1, O1> & other) const;
PINOCCHIO_COMPILER_DIAGNOSTIC_POP

protected:
Expand Down Expand Up @@ -702,10 +675,17 @@ namespace pinocchio

} // namespace pinocchio

#include "pinocchio/algorithm/contact-cholesky.hxx"

// Because of a GCC bug we should NEVER define a function that use ContactCholeskyDecompositionTpl
// before doing the explicit template instantiation.
// If we don't take care, GCC will not accept any visibility attribute when declaring the
// explicit template instantiation of the ContactCholeskyDecompositionTpl class.
// The warning message will look like this: type attributes ignored after type is already defined
// [-Wattributes] A minimal code example is added on the PR
// (https://github.com/stack-of-tasks/pinocchio/pull/2469)
#if PINOCCHIO_ENABLE_TEMPLATE_INSTANTIATION
#include "pinocchio/algorithm/contact-cholesky.txx"
#endif // PINOCCHIO_ENABLE_TEMPLATE_INSTANTIATION

#include "pinocchio/algorithm/contact-cholesky.hxx"

#endif // ifndef __pinocchio_algorithm_contact_cholesky_hpp__
35 changes: 35 additions & 0 deletions include/pinocchio/algorithm/contact-cholesky.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,41 @@ namespace pinocchio
return res;
}

template<typename Scalar, int Options>
template<typename S1, int O1>
bool ContactCholeskyDecompositionTpl<Scalar, Options>::operator==(
const ContactCholeskyDecompositionTpl<S1, O1> & other) const
{
bool is_same = true;

if (nv != other.nv || num_contacts != other.num_contacts)
return false;

if (
D.size() != other.D.size() || Dinv.size() != other.Dinv.size() || U.rows() != other.U.rows()
|| U.cols() != other.U.cols())
return false;

is_same &= (D == other.D);
is_same &= (Dinv == other.Dinv);
is_same &= (U == other.U);

is_same &= (parents_fromRow == other.parents_fromRow);
is_same &= (nv_subtree_fromRow == other.nv_subtree_fromRow);
is_same &= (last_child == other.last_child);
// is_same &= (rowise_sparsity_pattern == other.rowise_sparsity_pattern);

return is_same;
}

template<typename Scalar, int Options>
template<typename S1, int O1>
bool ContactCholeskyDecompositionTpl<Scalar, Options>::operator!=(
const ContactCholeskyDecompositionTpl<S1, O1> & other) const
{
return !(*this == other);
}

namespace details
{

Expand Down

0 comments on commit e9fb11f

Please sign in to comment.