3 simple questions about the usage and future of the excellent eigen library:
matrix[i][j]
, but only via matrix(i,j)
?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.
Multidimensional arrays are supported through the new Tensor module:
http://eigen.tuxfamily.org/dox-devel/unsupported/group__CXX11__Tensor__Module.html
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With