eigen库使用_eigen3

eigen库使用_eigen3Eigen库的安装1.VisualStudio2017安装eigen库1.1下载eigen库1.2配置1.3运行测试1.VisualStudio2017安装eigen库1.1下载eigen库eigen官网下载地址找到自己需要的版本下载,我下载的是3.3.9,箭头指向的zip。解压缩得到文件eigen-3.3.9,放到自己想放置的路径下(后面会引用此处的路径)。1.2配置在VS2017中新建一个空项目,取名为“eigen_demo”。输入以下测试

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

1. Visual Studio 2017 安装 eigen 库

1.1 下载 eigen 库

eigen官网下载地址
在这里插入图片描述

找到自己需要的版本下载,我下载的是3.3.9,箭头指向的 zip。
解压缩得到文件eigen-3.3.9,放到自己想放置的路径下(后面会引用此处的路径)。

1.2 配置

在VS 2017中新建一个空项目,取名为“eigen_demo”。输入以下测试代码(官方测试代码):

#include <iostream>
#include <Eigen/Dense>
using namespace Eigen;
using namespace std;

int main()
{ 
   
#pragma region Addition and subtraction
	Matrix2d a;
	a << 1, 2,
		3, 4;
	MatrixXd b(2, 2);
	b << 2, 3,
		1, 4;
	std::cout << "a + b =\n" << a + b << std::endl;
	std::cout << "a - b =\n" << a - b << std::endl;
	std::cout << "Doing a += b;" << std::endl;
	a += b;
	std::cout << "Now a =\n" << a << std::endl;
	Vector3d v(1, 2, 3);
	Vector3d w(1, 0, 0);
	std::cout << "-v + w - v =\n" << -v + w - v << std::endl;
#pragma endregion

#pragma region Scalar multiplication and division
	// Matrix2d a; //duplicate definition
	a << 1, 2,
		3, 4;
	// Vector3d v(1, 2, 3); //duplicate definition
	std::cout << "a * 2.5 =\n" << a * 2.5 << std::endl;
	std::cout << "0.1 * v =\n" << 0.1 * v << std::endl;
	std::cout << "Doing v *= 2;" << std::endl;
	v *= 2;
	std::cout << "Now v =\n" << v << std::endl;
#pragma endregion

#pragma region Transposition and conjugation
	MatrixXcf a_matrix = MatrixXcf::Random(2, 2);
	cout << "Here is the matrix a_matrix\n" << a_matrix << endl;
	cout << "Here is the matrix a_matrix^T\n" << a_matrix.transpose() << endl;
	cout << "Here is the conjugate of a_matrix\n" << a_matrix.conjugate() << endl;
	cout << "Here is the matrix a_matrix^*\n" << a_matrix.adjoint() << endl;

	//This is the so-called aliasing issue
	Matrix2i a_matrix2;
	a_matrix2 << 1, 2, 3, 4;
	cout << "Here is the matrix a_matrix2:\n" << a_matrix2 << endl;
	// a_matrix2 = a_matrix2.transpose(); // !!! do NOT do this !!!
	cout << "and the result of the aliasing effect:\n" << a_matrix2 << endl;
#pragma endregion

#pragma region Matrix-matrix and matrix-vector multiplication
	Matrix2d mat;
	mat << 1, 2,
		3, 4;
	Vector2d u_1(-1, 1), v_1(2, 0);
	std::cout << "Here is mat*mat:\n" << mat * mat << std::endl;
	std::cout << "Here is mat*u_1:\n" << mat * u_1 << std::endl;
	std::cout << "Here is u_1^T*mat:\n" << u_1.transpose()*mat << std::endl;
	std::cout << "Here is u_1^T*v:\n" << u_1.transpose()*v_1 << std::endl;
	std::cout << "Here is u_1*v_1^T:\n" << u_1 * v_1.transpose() << std::endl;
	std::cout << "Let's multiply mat by itself" << std::endl;
	mat = mat * mat;
	std::cout << "Now mat is mat:\n" << mat << std::endl;
#pragma endregion 

#pragma region Dot product and cross product
	Vector3d v_2(1, 2, 3);
	Vector3d w_2(0, 1, 2);
	cout << "Dot product: " << v_2.dot(w_2) << endl;
	double dp = v_2.adjoint()*w_2; // automatic conversion of the inner product to a scalar
	cout << "Dot product via a matrix product: " << dp << endl;
	cout << "Cross product:\n" << v_2.cross(w_2) << endl;
#pragma endregion

#pragma region Basic arithmetic reduction operations
	Eigen::Matrix2d mat_3;
	mat_3 << 1, 2,
		3, 4;
	cout << "Here is mat_3.sum(): " << mat_3.sum() << endl;
	cout << "Here is mat_3.prod(): " << mat_3.prod() << endl;
	cout << "Here is mat_3.mean(): " << mat_3.mean() << endl;
	cout << "Here is mat_3.minCoeff(): " << mat_3.minCoeff() << endl;
	cout << "Here is mat_3.maxCoeff(): " << mat_3.maxCoeff() << endl;
	cout << "Here is mat_3.trace(): " << mat_3.trace() << endl;

	Matrix3f m = Matrix3f::Random();
	std::ptrdiff_t i, j;
	float minOfM = m.minCoeff(&i, &j);
	cout << "Here is the matrix m:\n" << m << endl;
	cout << "Its minimum coefficient (" << minOfM
		<< ") is at position (" << i << "," << j << ")\n\n";
	RowVector4i v_4 = RowVector4i::Random();
	int maxOfV = v_4.maxCoeff(&i);
	cout << "Here is the vector v_4: " << v_4 << endl;
	cout << "Its maximum coefficient (" << maxOfV
		<< ") is at position " << i << endl;
#pragma endregion

	/**************This is the end of example codes in Eigen3 online document. **********************/
	system("pause");
}

此时项目默认为“DEBUG”模式,活动平台为“x64″。
在这里插入图片描述
如果后面更改了模式或平台,均要重新执行全部以下步骤。

鼠标右击项目 -> 选择属性 -> C/C++ -> 常规 -> 附加包含目录,将解压后的库文件夹所在路径:“ \Eigen 库\eigen-3.3.9 ”添加进去,点击确定。
在这里插入图片描述

再次打开此页面,链接器 -> 常规 -> 附加库目录,将路径“\Eigen 库\eigen-3.3.9”再次添加,点击确定。
在这里插入图片描述

1.3 运行测试

运行程序,看到正确运行的输出,Eigen库链接成功!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/180246.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • batch内负采样

    batch内负采样一般在计算softmax交叉熵时,需要用tf.nn.log_uniform_candidate_sampler多itemid做随机负采样。但是在类似dssm这种双塔模型中,item侧特征除了itemid外,还有其他meta特征,此时负样本对itemid做负采样后,还需要取相应负样本的meta特征。可是在tf训练数据中并不方便建立itemid与各类meta特征的映射表。为了解决dssm类模型的负采样问题,可以取一个batch内其他用户的正样本做为本用户的负样本,以解决负采样meta特征问题。好了,废话少说,

    2022年6月23日
    65
  • 静态方法只能通过类名进行调用_java非静态方法可以调用静态方法吗

    静态方法只能通过类名进行调用_java非静态方法可以调用静态方法吗静态方法调用的三种方式:1、newxx().静态();//使用对象调用,不推荐2、xx.静态();//类名调用,正规调用方法,推荐3、静态();//本类的静态方法在本类调用,直接调用欢迎各位在评论区留言探讨…

    2025年7月9日
    3
  • QQ空间钓鱼源码_QQ空间视频提取值源码

    QQ空间钓鱼源码_QQ空间视频提取值源码IgotthiswebsitefrommypalwhosharedwithmeconcerningthiswebpageandatthemomentthistimeIamvisitingthiswebsiteandreadingveryinformativearticlesorreviewshere.回复thejjreport.com…

    2022年8月24日
    9
  • 直和和直积_什么是直积举个例子

    直和和直积_什么是直积举个例子今天又在文章中看到直和和直积的概念,顺手baidu了一下,粘贴下来,其实以前矩阵论有讲过的。。。还是到用的时候印象最深。![在这里插入图片描述](https://img-blog.csdnimg.cn/20200609171605249.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80ODA5NDczMg==,size_…

    2025年6月14日
    2
  • Sublime Text3 如何安装、删除及更新插件

    Sublime Text3 如何安装、删除及更新插件1、打开SublimeText3,按Ctrl+`(和qq输入法快捷切换冲突,可以修改qq的输入法切换热键)2、复制粘黏以下代码添加至命令行,然后回车(功能:安装插件的工具,有了它,以后安装其他插件更方便)importurllib.request,os;pf=’PackageControl.sublime-package’;ipp=sublime.inst…

    2022年7月11日
    21
  • 毕业论文管理系统_本科毕业论文网

    毕业论文管理系统_本科毕业论文网毕业论文管理系统1.首先是个简约的登录页面,登录页面分为三个角色,分别是学生,老师和管理员系统的登录界面2.接下来是用户模块,分别为两个模块教师和学生的,管理员可以进行教师和学生添加和修改。3.系部管理4.文件管理,学生上传的论文,管理员和教师都可以进行下载和查看5.学生模块,学生选题,教师发布的题目学生可以进行选择。学生也可以自己申请题目6.学生申请课题7.论文初稿,学生上传论文初稿,等指导老师通过后才能进行最后的终稿8.学生上传论文,指导老师可以提建议,学生可以查看指导老师的建议9.

    2025年6月28日
    5

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号