eigen

Eigen::Ref for concatenating matrices

妖精的绣舞 提交于 2019-12-17 19:55:02
问题 If I want to concatenate two matrices A and B , I would do using Eigen::MatrixXd; const MatrixXd A(n, p); const MatrixXd B(n, q); MatrixXd X(n, p+q); X << A, B; Now if n , p , q are large, defining X in this way would mean creating copies of A and B . Is it possible to define X as an Eigen::Ref<MatrixXd> instead? Thanks. 回答1: No, Ref is not designed for that. We/You would need to define a new expression for that, that could be called Cat . If you only need to concatenate two matrices

Wrong results using auto with Eigen

巧了我就是萌 提交于 2019-12-17 16:57:13
问题 I got different results using auto and using Vector when summing two vectors. My code: #include "stdafx.h" #include <iostream> #include "D:\externals\eigen_3_1_2\include\Eigen\Geometry" typedef Eigen::Matrix<double, 3, 1> Vector3; void foo(const Vector3& Ha, volatile int j) { const auto resAuto = Ha + Vector3(0.,0.,j * 2.567); const Vector3 resVector3 = Ha + Vector3(0.,0.,j * 2.567); std::cout << "resAuto = " << resAuto <<std::endl; std::cout << "resVector3 = " << resVector3 <<std::endl; }

Eigen库介绍及使用入门

 ̄綄美尐妖づ 提交于 2019-12-16 12:10:47
Eigen是一个高层次的C ++库,有效支持线性代数,矩阵和矢量运算,数值分析及其相关的算法。Eigen是一个开源库,从3.1.1版本开始遵从MPL2许可。 为了将Matlab写的运动学程序转化为C++所编写的dll,需要用用到矩阵库Eigen,Eigen库是一个使用C++源码编写的矩阵库,基本上能满足计算中所需要用到的运算,下面介绍一些库的入门学习。 1.首先是关于固定大小矩阵,向量的定义,初始化 #include<iostream> #include<Eigen/Core> using namespace std; using namespace Eigen; //import most commen Eigen types int main(int, char *[]) { Matrix3fm3; //3X3单精度矩阵 m3<< 1, 2, 3, 4, 5, 6, 7, 8, 9; Matrix4fm4 = Matrix4f::Identity();//4X4单位矩阵(单精度) Vector4iv4(1, 2, 3, 4); //长度为4的整形向量 //输出结果 std::cout<< "m3\n" << m3 << "\nm4:\n" <<m4 << "\nv4:\n" << v4 << std::endl; getchar(); return0; } /*学习笔记*/ /

Eigen(7)-Geometry(几何转换)

寵の児 提交于 2019-12-16 09:53:16
官方地址传送 Space transformations 常用 1.旋转矩阵(3X3):Eigen::Matrix3d 2.旋转向量(3X1):Eigen::AngleAxisd 3.四元数(4X1):Eigen::Quaterniond 4.平移向量(3X1):Eigen::Vector3d 5.变换矩阵(4X4):Eigen::Isometry3d AngleAxis(angle, axis):绕该轴逆时针旋转angle(rad)。 变换矩阵 Eigen::Isometry3d T; T.matrix()才是变换矩阵,做运算时需加.matrix()后缀; T.pretranslate()以及T.prerotate()可以给平移部分和旋转矩阵赋值,但是若循环中使用,末尾不重置变换矩阵的话,这个设置量会累加,而不是覆盖。 四元数赋值:Eigen::Quaterniond Q; Q.x() = 3 「类似地 Q.y() = Q.z() = Q.w()」 1、 旋转矩阵(R),旋转向量(V)和四元数(Q)在Eigen中转换关系的总结: 2、旋转矩阵(R),旋转向量(V)和四元数(Q)分别通过自身初始化自己的方式: R通过自身初始化的方法: 使用旋转矩阵的函数来初始化旋转矩阵 Matrix3d R1=Matrix3d::Identity(); cout << “Rotation

Compiling Eigen library for iPhone with vectorisation

梦想的初衷 提交于 2019-12-14 03:49:01
问题 I am struggling with the compilation of Eigen library for iPhone 4 which has an ARM processor with armv7 instruction set. Everything works fine so far when I specify the preprocessor define EIGEN_DONT_VECTORIZE. But due to some performance issues I would like to use armv7 optimised code. Regardless which compiler I use LLVM-GCC 4.2 or LLVM CLang 2.0, I always run into compilation errors. I figured out (or better think so), that LLVM-GCC 4.2 is the only way to get access to these ARM-NEON

How do I in-place modify each element of a 1D Array?

余生颓废 提交于 2019-12-14 03:46:54
问题 I have a 1D eigen array ( Eigen::Array<double,Dynamic,Dynamic> ) of doubles, and I want to modify each element in the array in place . However, I'm not really sure how to do this. I'm considering this: Eigen::Array<double,Eigen::Dynamic,Eigen::Dynamic> arr1D; // ... // Threshold function: arr1D.unaryExpr([](double& elem) { elem = elem < 0.0 ? 0.0 : 1.0; } ); But this seems like a bit of a hack because the Eigen Reference examples only give examples of .unaryExpr where it is used with a

Eigen(6)-Linear algebra and decompositions(线性代数和分解)

孤人 提交于 2019-12-13 15:50:14
线性代数、分解 介绍如何求解线性系统,计算几种分解,比如LU,QR,SVD等。 基本线性求解 问题:假设有一个系统方程写成如下矩阵的形式 A x = b Ax=b A x = b 其中A,b是矩阵,b也可以是向量,当想要求解x时,可以选择多种分解方式,取决于矩阵A的形式以及考虑的速度和精度,下面是一个简单的例子 # include <iostream> # include <Eigen/Dense> using namespace std ; using namespace Eigen ; int main ( ) { Matrix3f A ; Vector3f b ; A << 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 10 ; b << 3 , 3 , 4 ; cout << "Here is the matrix A:\n" << A << endl ; cout << "Here is the vector b:\n" << b << endl ; Vector3f x = A . colPivHouseholderQr ( ) . solve ( b ) ; cout << "The solution is:\n" << x << endl ; } 解出的结果: Here is the matrix A: 1 2 3 4 5 6 7 8 10

How to copy Eigen matrix

≡放荡痞女 提交于 2019-12-13 15:01:25
问题 I have two Eigen::MatrixXd and they always have a single row. The input matrix is A and I want to copy this matrix into another matrix B , but the number of columns between the matrices can be different. Following is an example: A 0.5 And I need to create a B matrix of 1 rows and 4 columns, so that it will be: B 0.5 0.5 0.5 0.5 But if A is: A 1 0.5 Then B will be B 1 0.5 1 0.5 How can I do? 回答1: You can replicate a matrix by using the (wait for it) replicate function. The first parameter is

Eigen(5)-Reductions, visitors and broadcasting(规约、迭代和广播)

六月ゝ 毕业季﹏ 提交于 2019-12-13 12:10:05
规约、迭代、广播 规约 Eigen中规约是指对一个矩阵或数组操作并返回一个标量的函数,常用的是sum()方法,返回矩阵或数组的所有元素的和。 # include <iostream> # include <Eigen/Dense> using namespace std ; int main ( ) { Eigen :: Matrix2d mat ; mat << 1 , 2 , 3 , 4 ; cout << "Here is mat.sum(): " << mat . sum ( ) << endl ; cout << "Here is mat.prod(): " << mat . prod ( ) << endl ; cout << "Here is mat.mean(): " << mat . mean ( ) << endl ; cout << "Here is mat.minCoeff(): " << mat . minCoeff ( ) << endl ; cout << "Here is mat.maxCoeff(): " << mat . maxCoeff ( ) << endl ; cout << "Here is mat.trace(): " << mat . trace ( ) << endl ; } output Here is mat.sum(): 10

Eigen: how can I substitute matrix positive values with 1 and 0 otherwise?

吃可爱长大的小学妹 提交于 2019-12-13 07:06:22
问题 I want to write the following matlab code in Eigen (where K is pxp and W is pxb ): H = (K*W)>0; However the only thing that I came up so far is: H = ((K*W.array() > 0).select(1,0)); This code doesn't work as explained here, but replacing 0 with VectorXd::Constant(p,0) (as suggested in the link question) generates a runtime error: Eigen::internal::variable_if_dynamic<T, Value>::variable_if_dynamic(T) [with T = long int; int Value = 1]: Assertion `v == T(Value)' failed. How can I solve this?