当前位置:网站首页>PCL eigen introduction and simple use
PCL eigen introduction and simple use
2022-07-02 10:57:00 【AICVer】
Eigen It can be used for Linear Algebra 、 matrix 、 Vector operation, etc C++ library .
Related code operations are as follows :
//#include "stdafx.h"// The original blog used this , But my computer can't find , So replace... With the following three lines .
#include <stdio.h>
#include "stdlib.h"
#include <tchar.h>
#include <iostream>
#include <Eigen/Dense>
// Ten 、eigen Use
using namespace std;
using namespace Eigen;
template <typename T>
static void matrix_mul_matrix(T* p1, int iRow1, int iCol1, T* p2, int iRow2, int iCol2, T* p3)
{
if (iRow1 != iRow2) return;
// Column priority
//Eigen::Map< Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> > map1(p1, iRow1, iCol1);
//Eigen::Map< Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> > map2(p2, iRow2, iCol2);
//Eigen::Map< Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> > map3(p3, iCol1, iCol2);
// Line first
Eigen::Map< Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> > map1(p1, iRow1, iCol1);
Eigen::Map< Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> > map2(p2, iRow2, iCol2);
Eigen::Map< Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> > map3(p3, iCol1, iCol2);
map3 = map1 * map2;
}
int main(int argc, char* argv[])
{
//1. Definition of matrix
cout << "1. Definition of matrix " << endl;
Eigen::MatrixXd m(2, 2);
Eigen::Vector3d vec3d;
Eigen::Vector4d vec4d(1.0, 2.0, 3.0, 4.0);
//2. Dynamic matrix 、 Static matrix
cout << "2. Dynamic matrix 、 Static matrix " << endl;
Eigen::MatrixXd matrixXd;
Eigen::Matrix3d matrix3d;
//3. Access to matrix elements
cout << "3. Access to matrix elements " << endl;
m(0, 0) = 1;
m(0, 1) = 2;
m(1, 0) = m(0, 0) + 3;
m(1, 1) = m(0, 0) * m(0, 1);
std::cout << m << std::endl << std::endl;
//4. Set the elements of the matrix
cout << "4. Set the elements of the matrix " << endl;
m << -1.5, 2.4,
6.7, 2.0;
std::cout << m << std::endl << std::endl;
int row = 4;
int col = 5;
Eigen::MatrixXf matrixXf(row, col);
matrixXf << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20;
std::cout << matrixXf << std::endl << std::endl;
matrixXf << Eigen::MatrixXf::Identity(row, col);//Identity Unit matrix means :Identity matrix
std::cout << matrixXf << std::endl << std::endl;
//5. Reset matrix size
cout << "5. Reset matrix size " << endl;
Eigen::MatrixXd matrixXd1(3, 3);
m = matrixXd1;
std::cout << m.rows() << " " << m.cols() << std::endl << std::endl;
//6. Matrix operations
cout << "6. Matrix operations " << endl;
m << 1, 2, 7,
3, 4, 8,
5, 6, 9;
std::cout << m << std::endl;
matrixXd1 = Eigen::Matrix3d::Random();
m += matrixXd1;
std::cout << m << std::endl << std::endl;
m *= 2;
std::cout << m << std::endl << std::endl;
std::cout << -m << std::endl << std::endl;
std::cout << m << std::endl << std::endl;
//7. Transpose matrix 、 Conjugate matrix 、 Adjoint matrix
cout << "7. Transpose matrix 、 Conjugate matrix 、 Adjoint matrix " << endl;
std::cout << m.transpose() << std::endl << std::endl;
std::cout << m.conjugate() << std::endl << std::endl;
std::cout << m.adjoint() << std::endl << std::endl;
std::cout << m << std::endl << std::endl;
m.transposeInPlace();
std::cout << m << std::endl << std::endl;
//8. matrix multiplication 、 Matrix vector multiplication
cout << "8. matrix multiplication 、 Matrix vector multiplication " << endl;
std::cout << m*m << std::endl << std::endl;
vec3d = Eigen::Vector3d(1, 2, 3);
std::cout << m * vec3d << std::endl << std::endl;
std::cout << vec3d.transpose()*m << std::endl << std::endl;
//9. Block operation of matrix
cout << "9. Block operation of matrix " << endl;
std::cout << m << std::endl << std::endl;
std::cout << m.block(1, 1, 2, 2) << std::endl << std::endl;
std::cout << m.block<1, 2>(0, 0) << std::endl << std::endl;
std::cout << m.col(1) << std::endl << std::endl;
std::cout << m.row(0) << std::endl << std::endl;
//10. Block operation of vector
cout << "10. Block operation of vector " << endl;
Eigen::ArrayXf arrayXf(10);
arrayXf << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;
std::cout << vec3d << std::endl << std::endl;
std::cout << arrayXf << std::endl << std::endl;
std::cout << arrayXf.head(5) << std::endl << std::endl;
std::cout << arrayXf.tail(4) * 2 << std::endl << std::endl;
//11. Solve the eigenvalues and eigenvectors of the matrix
cout << "11. Solve the eigenvalues and eigenvectors of the matrix " << endl;
Eigen::Matrix2f matrix2f;
matrix2f << 1, 2, 3, 4;
Eigen::SelfAdjointEigenSolver<Eigen::Matrix2f> eigenSolver(matrix2f);// Form is this form , In case of high-dimensional problems, replace them with high-dimensional ones matrix2f.
if (eigenSolver.info() == Eigen::Success) {
std::cout << eigenSolver.eigenvalues() << std::endl << std::endl;
std::cout << eigenSolver.eigenvectors() << std::endl << std::endl;
}
//12. class Map And the use of dynamic matrix
cout << "12. class Map And the use of dynamic matrix " << endl;
int array1[4] = {
1, 2, 3, 4 };
int array2[4] = {
5, 6, 7, 8 };
int array3[4] = {
0, 0, 0, 0 };
matrix_mul_matrix(array1, 2, 2, array2, 2, 2, array3);
for (int i = 0; i < 4; i++)
std::cout << array3[i] << std::endl;
return 0;
}
边栏推荐
- AppGallery Connect场景化开发实战—图片存储分享
- axis设备的rtsp setup头中的url不能带参
- Solutions to a series of problems in sqoop job creation
- What are the popular frameworks for swoole in 2022?
- Oracle notes
- C#中索引器
- 2022爱分析· 国央企数字化厂商全景报告
- AttributeError: type object ‘Image‘ has no attribute ‘fromarray‘
- 1287_FreeRTOS中prvTaskIsTaskSuspended()接口实现分析
- 软件产品管理系统有哪些?12个最佳产品管理工具盘点
猜你喜欢
随机推荐
Win11 arm系统配置.net core环境变量
MySQL数据库远程访问权限设置
Pywin32 opens the specified window
How to get the password of cpolar?
SUS系统可用性量表
【ARK UI】HarmonyOS ETS的启动页的实现
正则及常用公式
The nanny level tutorial of flutter environment configuration makes the doctor green to the end
UVM learning - object attribute of UVM phase
UWA报告使用小技巧,你get了吗?(第四弹)
【快应用】text组件里的文字很多,旁边的div样式会被拉伸如何解决
Stm32 et développement de moteurs (système supérieur)
13.信号量临界区保护
Mysql database remote access permission settings
一招快速实现自定义快应用titlebar
Shapiro Wilk normal analysis by SPSS
P1055 [NOIP2008 普及组] ISBN 号码
Flink calculates topn hot list in real time
[SUCTF2018]followme
高考的意义是什么








