This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Missing delete operator for Fixed size matrices?

Tags: eigen eigen eigen
(comma "," separated)
hijokpayne
Registered Member
Posts
25
Karma
0
I was trying out the new Boost 1.56 beta for serialization of Eigen Matices but it to compile complaining about missing matching delete ( void*, size_t ) operator
There is also the following note in the file /boost/archive/detail/iserializer.hpp(237) which says: (Github Link)

// if compilation fails here, the likely cause that the class
// T has a class specific new operator but no class specific
// delete operator which matches the following signature. Fix
// your program to have this. Note that adding operator delete
// with only one parameter doesn't seem correct to me since
// the standard(3.7.4.2) says "
// "If a class T has a member deallocation function named
// 'operator delete' with exactly one parameter, then that function
// is a usual (non-placement) deallocation function" which I take
// to mean that it will call the destructor of type T which we don't
// want to do here.

I suspect this is because of use of EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF.

Code to reproduce the error is as following:

Code: Select all
#include <Eigen/Core>
#include <fstream>
#include <boost/serialization/vector.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>

//Boost Serialization of Eigen Matrix
namespace boost {
  template<class Archive, typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
  inline void serialize(Archive & ar,
    Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& t,
    const unsigned int file_version) {
    size_t rows = t.rows(), cols = t.cols();
    ar & rows;
    ar & cols;
    if (rows * cols != t.size())
      t.resize(rows, cols);
    ar & boost::serialization::make_array(t.data(), t.size());
  }
}

//Simple helper for serialization to a file
template <typename T>
bool serialize(const T& data, const std::string& filename) {
  std::ofstream ofs(filename.c_str(), std::ios::out | std::ios::binary);
  if (!ofs.is_open())
    return false;
  { // use scope to ensure archive goes out of scope before stream
    boost::archive::binary_oarchive oa(ofs);
    oa << data;
  }
  ofs.close();
  return true;
}

//Simple helper for de-serialization from a file
template <typename T>
bool deSerialize(T& data, const std::string& filename) {
  std::ifstream ifs(filename.c_str(), std::ios::in | std::ios::binary);
  if (!ifs.is_open())
    return false;
  { // use scope to ensure archive goes out of scope before stream
    boost::archive::binary_iarchive ia(ifs);
    ia >> data;
  }
  ifs.close();
  return true;
}

int main(int argc, char *argv[]) {
  typedef Eigen::Vector3d VectorType;
  VectorType* vec = new VectorType(1, 2, 3);
  serialize(vec, "v4d.dat");
  std::cout << "v4d =\n" << *vec << std::endl;

  VectorType* vec_in;
  deSerialize(vec_in, "v4d.dat");
  std::cout << "v4d_in =\n" << *vec_in << std::endl;
  return 0;
}


The error in Visual studio 2013 says:

boost/archive/detail/iserializer.hpp(237): error C2665: 'Eigen::PlainObjectBase<Eigen::Matrix<double,3,1,0,3,1>>::operator delete' : none of the 3 overloads could convert all the argument types
2> c:\users\abhijit\codes\installs\eigen\eigen-install\include\eigen3\eigen\src/Core/PlainObjectBase.h(132): could be 'void Eigen::PlainObjectBase<Eigen::Matrix<double,3,1,0,3,1>>::operator delete(void *,const std::nothrow_t &) throw()'
2> c:\users\abhijit\codes\installs\eigen\eigen-install\include\eigen3\eigen\src/Core/PlainObjectBase.h(132): or 'void Eigen::PlainObjectBase<Eigen::Matrix<double,3,1,0,3,1>>::operator delete(void *,void *) throw()'
2> while trying to match the argument list '(VectorType *, size_t)'
2> C:\Boost\boost-1_56_0_b1\boost/archive/detail/iserializer.hpp(224) : while compiling class template member function 'void boost::archive::detail::heap_allocation<T>::has_new_operator::invoke_delete(T *)'

Is this is a bug on Eigen's part? Although the above works with previous versions of Boost.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Fixed:

https://bitbucket.org/eigen/eigen/commits/d336163ce058/
Changeset: d336163ce058
User: ggael
Date: 2014-07-30 09:32:35
Summary: add missing delete operator overloads


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]