简体   繁体   English

特征库中的多维数组

[英]Multidimensional arrays in eigen library

3 simple questions about the usage and future of the excellent eigen library:关于优秀特征库的使用和未来的3个简单问题:

  1. Does it have a reason why the access to Matrices is not possible via matrix[i][j] , but only via matrix(i,j) ?是否有理由不能通过matrix[i][j]访问矩阵,而只能通过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] ?会有多维数组matrix[n][m]...[l]吗?

I really like the eigen library, it is fast and easy to use.我真的很喜欢 eigen 库,它快速且易于使用。 The only thing missing for me are really multidimensional arrays.我唯一缺少的是真正的多维数组。

Multidimensional arrays are supported through the new Tensor module:通过新的 Tensor 模块支持多维数组:

http://eigen.tuxfamily.org/dox-devel/unsupported/group__CXX11__Tensor__Module.html 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.我不能说eigen库,因为我从未使用过它,但我可以谈谈代码的设计。 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. eigen库的作者可能不想经历将向量定义为矩阵类基础的麻烦。

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;
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:定义 peren 运算符通常更容易,因为它也不依赖于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 Matrix class like this:允许我们像这样使用Matrix类:

Matrix matrix;
matrix(4, 3) = 9.2;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM