dimanche 26 mai 2019

c++ class with Eigen variable error during assignment

My brief code is as below, I have a "PoseHypo" class:

class PoseHypo
{
public:
  PoseHypo();
  PoseHypo(const Eigen::Matrix4f &pose);
  PoseHypo& operator = (const PoseHypo &other); 
  ~PoseHypo();

public:
  Eigen::Matrix4f _pose;
  int _id;

  EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
};

And now when I do following:

std::vector<PoseHypo> _pose_hypos;   // this is initialized somewhere before and I confirmed it is good 
std::sort(_pose_hypos.begin(),_pose_hypos.end(),HypoCompare()); // compare based on _id  

This gives segfault. Output of gdb is:

#0  0x000000000057ee2b in _mm256_load_ps (__P=0x584b070)
    at /usr/lib/gcc/x86_64-linux-gnu/5/include/avxintrin.h:848
#1  Eigen::internal::pload<float __vector(8)>(Eigen::internal::unpacket_traits<float __vector(8)>::type const*) (
    from=0x584b070) at /usr/include/eigen3/Eigen/src/Core/arch/AVX/PacketMath.h:206
#2  0x00000000005d6420 in Eigen::internal::ploadt<float __vector(8), 32>(Eigen::internal::unpacket_traits<float __vector(8)>::type const*) (from=0x584b070) at /usr/include/eigen3/Eigen/src/Core/GenericPacketMath.h:475
#3  Eigen::internal::evaluator<Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> > >::packet<32, float __vector(8)>(long, long) const (this=0x7fffffff9a80, row=0, col=0)
    at /usr/include/eigen3/Eigen/src/Core/CoreEvaluators.h:183
#4  0x00000000005d31d6 in Eigen::internal::generic_dense_assignment_kernel<Eigen::internal::evaluator<Eigen::Matrix<float, 4, 4, 0, 4, 4> >, Eigen::internal::evaluator<Eigen::Matrix<float, 4, 4, 0, 4, 4> >, Eigen::internal::assign_op<float>, 0>::assignPacket<16, 32, float __vector(8)>(long, long) (this=0x7fffffff9a90, row=0, col=0)
    at /usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:592
#5  0x00000000005d04a5 in Eigen::internal::generic_dense_assignment_kernel<Eigen::internal::evaluator<Eigen::Matrix<float, 4, 4, 0, 4, 4> >, Eigen::internal::evaluator<Eigen::Matrix<float, 4, 4, 0, 4, 4> >, Eigen::internal::assign_op<float>, 0>::assignPacketByOuterInner<16, 32, float __vector(8)>(long, long) (this=0x7fffffff9a90, outer=0, 
    inner=0) at /usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:606
#6  0x00000000005cc011 in Eigen::internal::copy_using_evaluator_innervec_CompleteUnrolling<Eigen::internal::generic_dense_assignment_kernel<Eigen::internal::evaluator<Eigen::Matrix<float, 4, 4, 0, 4, 4> >, Eigen::internal::evaluator<Eigen::Matrix<float, 4, 4, 0, 4, 4> >, Eigen::internal::assign_op<float>, 0>, 0, 16>::run (kernel=...)
    at /usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:244
#7  0x00000000005c4ce6 in Eigen::internal::dense_assignment_loop<Eigen::internal::generic_dense_assignment_kernel<Eigen::internal::evaluator<Eigen::Matrix<float, 4, 4, 0, 4, 4> >, Eigen::internal::evaluator<Eigen::Matrix<float, 4, 4, 0, 4, 4> >, Eigen::internal::assign_op<float>, 0>, 3, 2>::run (kernel=...)
    at /usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:403
#8  0x00000000005bf643 in Eigen::internal::call_dense_assignment_loop<Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::internal::assign_op<float> > (dst=..., src=..., func=...)
    at /usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:653
#9  0x00000000005b88c7 in Eigen::internal::Assignment<Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::internal::assign_op<float>, Eigen::internal::Dense2Dense, float>::run (dst=..., src=..., 
--Type <RET> for more, q to quit, c to continue without paging--
    func=...) at /usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:790
#10 0x00000000005afe95 in Eigen::internal::call_assignment_no_alias<Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::internal::assign_op<float> > (dst=..., src=..., func=...)
    at /usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:747
#11 0x00000000005b6f60 in Eigen::internal::call_assignment<Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::internal::assign_op<float> >(Eigen::Matrix<float, 4, 4, 0, 4, 4>&, Eigen::Matrix<float, 4, 4, 0, 4, 4> const&, Eigen::internal::assign_op<float> const&, Eigen::internal::enable_if<!Eigen::internal::evaluator_assume_aliasing<Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::internal::evaluator_traits<Eigen::Matrix<float, 4, 4, 0, 4, 4> >::Shape>::value, void*>::type) (dst=..., src=..., func=...)
    at /usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:712
#12 0x00000000005aeadc in Eigen::internal::call_assignment<Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 4, 0, 4, 4> > (dst=..., src=...) at /usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:693
#13 0x00000000005a327b in Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >::_set<Eigen::Matrix<float, 4, 4, 0, 4, 4> > (this=0x584b010, other=...) at /usr/include/eigen3/Eigen/src/Core/PlainObjectBase.h:682
#14 0x0000000000594305 in Eigen::Matrix<float, 4, 4, 0, 4, 4>::operator= (this=0x584b010, other=...)
    at /usr/include/eigen3/Eigen/src/Core/Matrix.h:208
#15 0x00007ffff774b08d in PoseHypo::operator= (this=0x584b010, other=...)
..........

There are some other prints after #15 and I can add them if necessary. My implementation for PoseHypo::operator= is:

PoseHypo& PoseHypo::operator = (const PoseHypo &other)
{
  _id=other._id;
  _pose=other._pose;
  return *this;
}

I have tried all kinds of keywords to Google but failed to find any clue. I think I have taken care of all the pitfalls Eigen website mentioned. Any help is greatly appreciated!!

Aucun commentaire:

Enregistrer un commentaire