Multidimensional arrays in a native library
3 simple questions about the use and future of an excellent native library:
- Does he have a reason why matrix access is not possible through
matrix[i][j]
, but only throughmatrix(i,j)
? - Are there any plans to implement such a syntax?
- Will there be an implementation of multidimensional arrays
matrix[n][m]...[l]
?
I really like my own library, it is simple and easy to use. The only thing I am missing is multidimensional arrays.
source to share
I can't speak for the library eigen
because I've never used it, but I can speak for the design of the code. To use the notation [][]
, this usually means that the matrix is built on base vectors, which also overloaded the operator []
.
Perhaps the author of the library eigen
did not want to solve the problem of defining vectors as the basis of matrix classes.
Let's 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 class Matrix
like this:
Matrix matrix;
matrix[0][0] = 1.2;
Where the definition of the peren operator is usually simpler because it is also independent of the class implementation Vector
:
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 class Matrix
like this:
Matrix matrix;
matrix(4, 3) = 9.2;
source to share
Multidimensional arrays are supported through the new Tensor module:
http://eigen.tuxfamily.org/dox-devel/unsupported/group__CXX11__Tensor__Module.html
source to share