Eigen3 Cheatsheet
Cheatsheet就是你写代码时对某个库的参照表,这些接口无需记忆,只用边写边看即可:
//------------------ Eigen Cheatsheet ---------------
//@Hanss401
//@2018/3/15
#include <iostream>
#include <Eigen/Dense>
typedef Matrix<float,Dynamic,Dynamic> MatrixfX
//define Vector
Eigen::Matrix<Dtype,n,1> vec;
//define Matrix
Eigen::Matrix<Dtype,m,n> mat;
//Matrix times const
Eigen::Matrix::Constant(3,3,1.2)*5.0;
//Martrix dot
//add/subtract
mat3 = mat1 + mat2; mat3 += mat1;
mat3 = mat1 - mat2; mat3 -= mat1;
//scalar product
mat3 = mat1 * s1; mat3 *= s1; mat3 = s1 * mat1;
mat3 = mat1 / s1; mat3 /= s1;
//matrix/vector products *
col2 = mat1 * col1;
row2 = row1 * mat1; row1 *= mat1;
mat3 = mat1 * mat2; mat3 *= mat1;
//transposition adjoint *
mat1 = mat2.transpose(); mat1.transposeInPlace();
mat1 = mat2.adjoint(); mat1.adjointInPlace();
//dot product
//inner product *
scalar = vec1.dot(vec2);
scalar = col1.adjoint() * col2;
scalar = (col1.adjoint() * col2).value();
//outer product *
mat = col1 * col2.transpose();
//norm normalization *
scalar = vec1.norm(); scalar = vec1.squaredNorm()
vec2 = vec1.normalized(); vec1.normalize(); // inplace
//cross product *
#include <Eigen/Geometry>
vec3 = vec1.cross(vec2);