C++中 eigen(一)建造向量

快速上手:
https://eigen.tuxfamily.org/dox/group__QuickRefPage.html

文档:
https://eigen.tuxfamily.org/dox/index.html

在这里插入图片描述
Constructors 建造 向量

Vectors 向量

例如,方便的 typedef Vector3f 是一个包含 3 个浮点数的(列)向量。 Eigen 定义如下:

typedef Matrix<float, 3, 1> Vector3f;

We also offer convenience typedefs for row-vectors, for example:
我们还为行向量提供方便的 typedef,int 整数 例如:

typedef Matrix<int, 1, 2> RowVector2i;

Of course, Eigen is not limited to matrices whose dimensions are known at compile time. The RowsAtCompileTime and ColsAtCompileTime template parameters can take the special value Dynamic which indicates that the size is unknown at compile time, so must be handled as a run-time variable. In Eigen terminology, such a size is referred to as a dynamic size; while a size that is known at compile time is called a fixed size. For example, the convenience typedef MatrixXd, meaning a matrix of doubles with dynamic size, is defined as follows:
当然,Eigen 不限于在编译时维度已知的矩阵。 RowsAtCompileTime 和 ColsAtCompileTime 模板参数可以采用特殊值 Dynamic ,该值表示编译时大小未知,因此必须作为运行时处理多变的。在 Eigen 术语中,这样的尺寸被称为动态尺寸;而在编译时已知的大小称为固定大小。例如,方便的 typedef MatrixXd ,表示具有动态大小的双精度矩阵,定义如下:

typedef Matrix<double, Dynamic, Dynamic> MatrixXd;
// typedef Matrix<双精度、动态、动态> MatrixXd;

And similarly, we define a self-explanatory typedef VectorXi as follows:
同样,我们定义一个不言自明的 typedef VectorXi 如下:

typedef Matrix<int, Dynamic, 1> VectorXi;

You can perfectly have e.g. a fixed number of rows with a dynamic number of columns, as in:
你可以完美地拥有例如固定数量的行和动态数量的列,如下所示:

Matrix<float, 3, Dynamic>
矩阵<浮点、3、动态>
Matrix3f a;
MatrixXf b;

a 是一个 3 x 3 矩阵,包含一个未初始化系数的普通 float[9] 数组、
b 是一个动态大小的矩阵,当前大小为 0 乘 0,其系数数组尚未分配。

MatrixXf a(10,15);
VectorXf b(30);

a 是一个 10x15 的动态矩阵,系数已分配但当前未初始化。
b 是一个动态大小为 30 的向量,系数已分配但当前未初始化。

Matrix3f a(3,3)

and is a no-operation. 无效操作

矩阵和向量也可以从系数列表初始化。在 C++11 之前,此功能仅限于小型固定大小列或最大大小为 4 的向量:

Vector2d a(5.0, 6.0);
Vector3d b(5.0, 6.0, 7.0);
Vector4d c(5.0, 6.0, 7.0, 8.0);

开启 c++11

Vector2i a(1, 2);                      // A column vector containing the elements {1, 2}
Matrix<int, 5, 1> b {1, 2, 3, 4, 5};   // A row-vector containing the elements {1, 2, 3, 4, 5}
Matrix<int, 1, 5> c = {1, 2, 3, 4, 5}; // A column vector containing the elements {1, 2, 3, 4, 5}

In the general case of matrices and vectors with either fixed or runtime sizes, coefficients have to be grouped by rows and passed as an initializer list of initializer list (details ):
在具有固定大小或运行时大小的矩阵和向量的一般情况下,系数必须按行分组并作为初始值设定项列表的初始值设定项列表传递(详细信息):):

MatrixXi a {      // construct a 2x2 matrix
      {1, 2},     // first row
      {3, 4}      // second row
};
Matrix<double, 2, 3> b {
      {2, 3, 4},
      {5, 6, 7},
};

For column or row vectors, implicit transposition is allowed. This means that a column vector can be initialized from a single row:
对于列向量或行向量,允许隐式转置。这意味着可以从单行初始化列向量:

VectorXd a {{1.5, 2.5, 3.5}};             // A column-vector with 3 coefficients
RowVectorXd b {{1.0, 2.0, 3.0, 4.0}};     // A row-vector with 4 coefficients
  • 20
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值