Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multidimensional arrays in eigen library

3 simple questions about the usage and future of the excellent eigen library:

  1. Does it have a reason why the access to Matrices is not possible via matrix[i][j], but only via matrix(i,j)?
  2. Are there plans to implement such a syntax?
  3. Will there be an implementation of multidimensional arrays matrix[n][m]...[l]?

I really like the eigen library, it is fast and easy to use. The only thing missing for me are really multidimensional arrays.

like image 789
DaPhil Avatar asked Feb 10 '23 19:02

DaPhil


2 Answers

Multidimensional arrays are supported through the new Tensor module:

http://eigen.tuxfamily.org/dox-devel/unsupported/group__CXX11__Tensor__Module.html

like image 196
user2658323 Avatar answered Feb 12 '23 22:02

user2658323


I can't speak for the eigen library because I've never used it, but I can speak to the design of the code. In order to use the [][] notation, that typically means that the matrix is built upon underlying vectors that have also overloaded the [] operator.

It's possible the author of the eigen library did not want to go through the trouble of defining vectors to be the basis of the matrix classes.

Take the following example.

class Matrix {
   Vector& operator[](std::size_t ind);
};

class Vector {
   double& operator[](std::size_t ind);
};

Allows us to use the Matrix class like this:

Matrix matrix;
matrix[0][0] = 1.2;

Where as defining the peren operator is typically easier because it doesn't also rely on the implementation of a Vector class:

class Matrix {
    double& operator()(std::size_t i, std::size_t j);
    const double& operator()(std::size_t i, std::size_t j) const;
};

Allows us to use the Matrix class like this:

Matrix matrix;
matrix(4, 3) = 9.2;
like image 36
Tyler Jandreau Avatar answered Feb 13 '23 00:02

Tyler Jandreau