Eigen库

2023-05-16

MatrixXd表示任意size的矩阵,元素类型为double; VectorXd表示任意size的向量,元素类型为double.


//创建3*1的向量v,并赋值为1,2,3
VectorXd v(3);
v << 1, 2, 3;  

使用固定尺寸的Matrix,Vector相比于可变尺寸的Matrix,Vector,例如Matrix3d m代替MatrixXd m(3,3)有以下优点:

运行速度更快,编译期间可实现更严格的错误检查。

Eigen中,所有的矩阵,向量都是Matrix模板类的对象,向量只是矩阵的特例,行数或者列数为1.


//便捷定义
typedef Matrix<float, 4, 4> Matrix4f;
typedef Matrix<float, 3, 1> Vector3f;
typedef Matrix<int, 1, 2> RowVector2i;  
  typedef Matrix<double, Dynamic, Dynamic> MatrixXd;  //编译期未知尺寸

 Eigen中通过()获取其元素,起始索引为0。The operator[] is also overloaded for index-based access in vectors, but keep in mind that C++ doesn't allow operator[] to take more than one argument.

 transpose()计算矩阵的转置, transpose()不支持就地转置,使用transposeInPlace()来实现就地转置。

 Array

We adopt the convention that typedefs of the form ArrayNt stand for 1-dimensional arrays, where N and t are the size and the scalar type.For 2-dimensional arrays, we use typedefs of the form ArrayNNt. 

matrix和array之间可以相互进行转换,通过调用matrix的.array()函数将matrix转换为array表达式;通过调用array的.matrix()函数将array转换为matrix表达式。

Eigen中禁止一个表达式中混合使用matrix和array,但允许赋值运算符这样操作。

Eigen中为matrix提供了cwiseProduct()函数以实现逐元素相乘。

 Block Operation

matrix.row(i) 获取矩阵matrix的第i行,matrix.col(j)获取矩阵matrix的第j列。相比于使用block()性能更好。

Eigen also provides special methods for blocks that are flushed against one of the corners or sides of a matrix or array. For instance, .topLeftCorner() can be used to refer to a block in the top-left corner of a matrix.

 

squaredNorm() 计算2范数的平方,norm()计算2范数,lpNorm<p>()计算p范数,p设置为Infinity可计算无穷范数。

The following reductions operate on boolean values:

  • all() returns true if all of the coefficients in a given Matrix or Array evaluate to true .
  • any() returns true if at least one of the coefficients in a given Matrix or Array evaluates to true .
  • count() returns the number of coefficients in a given Matrix or Array that evaluate to true.

 Visitors

Visitors are useful when one wants to obtain the location of a coefficient inside a Matrix or Array. The simplest examples are maxCoeff(&x,&y) and minCoeff(&x,&y), which can be used to find the location of the greatest or smallest coefficient in a Matrix or Array.

The arguments passed to a visitor are pointers to the variables where the row and column position are to be stored. These variables should be of type Index 

 matrix.data()函数返回一个指向矩阵内存地址的指针。Eigen中矩阵默认以column-major存储元素值。

 

转载于:https://www.cnblogs.com/larry-xia/p/10666834.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Eigen库 的相关文章

  • 使用 std::vector 初始化 Eigen::vector

    我以前见过它 但我不记得如何有效地初始化Eigen Vector已知长度的std vector相同长度的 这是一个很好的例子 std vector
  • 将 C++ 特征矩阵传递给 Matlab mex 输出

    我怎样才能通过特征矩阵作为Matlab输出参数 我尝试过这个 EIGEN 如何从特征矩阵中取出和取出数据 MatrixXd resultEigen Eigen matrix with some result non NULL double
  • 如何使用OpenCV进行LU分解?

    cvInvert 方法采用标志 CV LU 进行 LU 分解以反转输入矩阵 但是有什么方法可以获得计算过程中形成的 L 和 U 矩阵吗 为 LU 分解编写一个新函数似乎毫无意义 因为 OpenCV 已经为其优化了代码 不幸的是 OpenCV
  • 按欧拉角输入旋转四元数

    我正在编写一段代码来控制 3D 空间中的机械臂 机械臂通过四元数处理旋转 但我希望用户通过改变偏航 俯仰和滚动来控制它 因为人类使用这些更明智 我编写了函数来获取用户想要在每个方向 滚动 俯仰 偏航 旋转手臂的量并输出新的四元数 我将 cu
  • Eigen 中三元运算符的类型错误

    我正在用 C 编写一个类来概括两个稀疏矩阵求解器 SparseLU 和 Sparse Cholesky 当我尝试使用三元运算符时 它说操作数类型不兼容 但如果我使用 If 语句 代码就会编译 错误 2 错误 操作数类型不兼容 const E
  • 在 MEX 函数中将特征复数矩阵返回到 MATLAB,无需额外复制

    这个问题演示如何使用映射对象将双精度矩阵返回到 MATLAB 以下适用于非复杂数据 double outputPtr plhs 0 mxCreateDoubleMatrix mwSize n mwSize m mxREAL outputPt
  • Eigen::Ref<> 作为成员变量

    我需要一个类有一个 Eigen Ref 变量作为静态成员 该变量将通过init静态方法 像这样的东西 class CostFunction public static Eigen Ref
  • 稠密对称矩阵的特征有效类型

    Does Eigen http eigen tuxfamily org index php title Main Page有存储密集 固定大小 对称矩阵的有效类型吗 嘿 它们无处不在 IE 对于 N 9 它应该只存储 1 9 9 2 45
  • Rcpp 相当于 rowsum [关闭]

    很难说出这里问的是什么 这个问题是含糊的 模糊的 不完整的 过于宽泛的或修辞性的 无法以目前的形式得到合理的回答 如需帮助澄清此问题以便重新打开 访问帮助中心 help reopen questions 我正在寻找 R 函数的快速替代方案r
  • eigen::select() 的奇怪行为

    在本征中 构造 R array lt s select P Q 当 P Q 之一或两者都是向量时有效 与R的长度相同 但只要两者 其中一些是标量 我收到编译错误 我的问题是 是的行为select在场 两个标量是特征警告我的一种方式 还有更有
  • 元素矩阵乘法:R 与 Rcpp(如何加速此代码?)

    我是新来的C 编程 使用Rcpp无缝集成到R 并且我希望得到一些有关如何加快某些计算速度的建议 考虑以下示例 testmat lt matrix 1 9 nrow 3 testvec lt 1 3 testmat testvec 1 2 3
  • 如何在使用 Eigen Library C++ 时删除特定行或列

    我正在为我的项目使用 Eigen 库 我正在搜索如何从特征中的给定矩阵中删除特定行或列 我没有成功 MatrixXd A X1 X2 X3 X4 Y1 Y2 Y3 Y4 Z1 Z2 Z3 Z4 A1 A2 A3 A4 MatrixXd At
  • 如何在 Eigen 中平移矩阵(4x4)?

    如何在 Eigen 中平移矩阵 4x4 identity matrix 4x4 type Eigen Matrix
  • C++ 对齐的未来:按值传递?

    阅读 Eigen 库文档 我注意到有些对象不能按值传递 http eigen tuxfamily org dox TopicPassingByValue html C 11 中是否有任何开发或计划开发可以安全地按值传递此类对象 另外 为什么
  • 如何访问 C++ Eigen 数组中的多个元素?

    我想检索特征数组中的某些元素并将它们作为向量返回 我使用以下代码 Eigen ArrayXXi test test resize 5 5 test setRandom Eigen Matrix
  • 如何确保特征等距保持等距?

    我目前正在调查Eigen Isometry3f 定义为typedef Transform
  • 为什么选择 Eigen 作为 TensorFlow? [关闭]

    Closed 此问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 TensorFlow白皮书提到使用了Eigen 是否有关于如何选择 Eigen 的公开解释 它们是在 T
  • 使用矢量化为 iPhone 编译 Eigen 库

    我正在努力为 iPhone 4 编译 Eigen 库 该库具有带有 armv7 指令集的 ARM 处理器 到目前为止 当我指定预处理器定义 EIGEN DONT VECTORIZE 时 一切正常 但由于一些性能问题 我想使用armv7优化的
  • Eigen 如何沿特定维度连接矩阵?

    我有两个特征矩阵 我想将它们连接起来 就像在 matlab 中一样cat 0 A B eigen 有等价物吗 Thanks 您可以使用逗号初始值设定项语法 水平方向 MatrixXd C A rows A cols B cols C lt
  • Eigen 库:在函数中返回矩阵块作为左值

    我试图将矩阵块作为函数的左值返回 假设我的函数如下所示 Block

随机推荐