本征库中的多维数组 [英] Multidimensional arrays in eigen library

查看:91
本文介绍了本征库中的多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于优秀特征库的用法和未来的三个简单问题:

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


  1. 是否有理由可以访问矩阵?通过 matrix [i] [j] 不可能,但只能通过 matrix(i,j)

  2. 是否有计划实现这种语法?

  3. 是否将实现多维数组 matrix [n] [m]的实现。 .. [l]

  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.

推荐答案

我不能说 eigen 库,因为我从未使用过它,但是我可以讲代码的设计。为了使用 [] [] 表示法,这通常意味着矩阵是基于底层向量构建的,这些向量也使 [] 过载。 code>运算符。

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.

eigen 库的作者可能不想经历将向量定义为向量的麻烦。矩阵类的基础。

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.

采用以下示例。

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

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

允许我们使用 Matrix 类,

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

在这里定义peren运算符通常比较容易,因为它不依赖于a的实现 Vector 类:

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;
};

允许我们使用 Matrix 类,

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

这篇关于本征库中的多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆