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

Problem storing array of Eigen::Matrix objects

Tags: None
(comma "," separated)
mmoller
Registered Member
Posts
16
Karma
0
Dear all,

I try to store multiple Eigen::Matrix objects in an array, e.g.

Code: Select all
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> localMat[10];


and also

Code: Select all
std::array<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>, 10> localMat;


When I try to initialise the matrices by calling

localMat[0].setZero(4,4);
...


I receive the following error using valgrind (V 3.12.0)

==87413== Invalid free() / delete / delete[] / realloc()
==87413== at 0x100130A65: free (in /usr/local/homebrew/Cellar/valgrind/3.12.0/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==87413== by 0x100051654: Eigen::internal::aligned_free(void*) (Memory.h:177)
==87413== by 0x100051634: void Eigen::internal::conditional_aligned_free<true>(void*) (Memory.h:230)
==87413== by 0x10005175B: void Eigen::internal::conditional_aligned_delete_auto<double, true>(double*, unsigned long) (Memory.h:416)
==87413== by 0x100077264: Eigen::DenseStorage<double, -1, -1, -1, 0>::resize(int, int, int) (DenseStorage.h:401)
==87413== by 0x100077029: Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >::resize(int, int) (PlainObjectBase.h:287)
==87413== by 0x10007C074: Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >::setZero(int, int) (CwiseNullaryOp.h:535)

When I replace the array of matrices by

Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> localMat0;
Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> localMat1;
...


this error does not occur. Any help is appreciated.

Best,
Matthias
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
I cannot reproduce with:
Code: Select all
#include <iostream>
#include <array>
#include <Eigen/Dense>
using namespace Eigen;
using namespace std;

int main()
{
  //std::array<MatrixXd,10> A;
  MatrixXd A[10];

  for(int k=0;k<9;++k)
    cout << A[k].setZero(k,k);

  for(int k=0;k<9;++k)
    cout << A[k].size() << " ";
  cout << endl;
}

Please provide a self-contained example. You are likely doing something wrong in-between the declaration and its use.
mmoller
Registered Member
Posts
16
Karma
0
My apologise. The problem was not due to Eigen but due to a complicated (and thus wrong) recursive compile-time computation of the array size.


Bookmarks



Who is online

Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]