- 浏览: 679461 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (181)
- Matlab (16)
- Java (26)
- autoHotkey (4)
- openCV (1)
- C++ (50)
- PDF-XChange Viewer (2)
- 学术 (11)
- javascript (4)
- linux (11)
- SWT (9)
- latex (7)
- GAE (2)
- windows (6)
- C# (3)
- PS (20)
- JNI (4)
- latex,批处理 (0)
- 批处理 (4)
- Android (5)
- 矩阵论 (1)
- SVM (1)
- 概率图模型 (0)
- Python (12)
- Eigen (5)
- 编程题 (1)
- MKL (1)
- 神经网络 (9)
- 最优化 (2)
- 摄影 (1)
- PPT (0)
- After Effects (3)
- CUDA (3)
- caffe (0)
- MXNet (2)
- svn (1)
- R (0)
- 虚拟机 (0)
- tensorflow (7)
- theano (1)
- Keras (1)
- vim (1)
- xgboost (1)
- spark (6)
- eclipse (2)
- word2vec (0)
- hadoop (1)
- dmlc (1)
- git (0)
最新评论
-
jeffersonz:
请问大神,这个插件记录下来的脚本为什么不能再Extendscr ...
PhotoShop - 记录PS的所有操作为JavaScript代码 -
cherishLC:
Andy__Zou 写道cherishLC 写道Andy__Z ...
Eigen的编译选项;MKL的使用 -
Andy__Zou:
cherishLC 写道Andy__Zou 写道cherish ...
Eigen的编译选项;MKL的使用 -
cherishLC:
Andy__Zou 写道cherishLC 写道Andy__Z ...
Eigen的编译选项;MKL的使用 -
Andy__Zou:
cherishLC 写道Andy__Zou 写道 您好,您的工 ...
Eigen的编译选项;MKL的使用
在使用Eigen编程时,到处是Curiously recurring template pattern,那么,我们如何知道一个矩阵中存的是double型变量还是float型的变量呢?
有人会说, MatrixXd中存的就是double型变量MatrixXf中存的是float型变量啊!
我是无耻的插队者:不了解Curiously recurring template pattern的可以看我之前的文章:http://cherishlc.iteye.com/blog/1994276
可是,如果一个泛型函数是如下定义的,我们如何知道X中存的是什么类型的变量呢?
先说一下这样写的好处:
但是,事物都有其两面性。。。
问题来了:如果再写函数的过程中,我们需要声明一个临时变量,与X中存储的元素类型相同,该如何声明?
答案很简单,Eigen在MatrixBase类(事实上是近乎所有类)中为我们定义了这些类型,
类型列表如下:
使用的时候,用如下语句可以声明一个变量s:
好了,最后来膜拜一下PlainObject的定义:
还有些简单的:
可能有些人还会有疑问,为何是internal::traits<Derived>::Scalar 而不是Derived::Scalar(事实上我们用的时候可以这么用,但是在写Eigen库的过程中不行)!!原因是在编写Eigen库的过程中,类型相互引用,会产生类型未定义的问题(大致如此,描述可能不准确),这样的问题,我们作为库的使用者是不会遇到的
摘录Eigen官方文档如下:
Matrix类官方文档:
http://eigen.tuxfamily.org/dox/classEigen_1_1Matrix.html
MatrixBase类官方文档:
http://eigen.tuxfamily.org/dox/classEigen_1_1MatrixBase.html#ac33495a0e3788e5951670c392b44d9ad
编写Eigen的泛型函数:
http://eigen.tuxfamily.org/dox/TopicFunctionTakingEigenTypes.html
关于internal::traits的,这篇对理解Eigen架构很有帮助:
http://eigen.tuxfamily.org/dox/TopicInsideEigenExample.html
有人会说, MatrixXd中存的就是double型变量MatrixXf中存的是float型变量啊!
我是无耻的插队者:不了解Curiously recurring template pattern的可以看我之前的文章:http://cherishlc.iteye.com/blog/1994276
可是,如果一个泛型函数是如下定义的,我们如何知道X中存的是什么类型的变量呢?
template <typename Derived> void cov(const MatrixBase<Derived>& X){}
先说一下这样写的好处:
- 1、通用性强,X既可以是MatrixXd类型的,也可以是MatrixXf类型的,甚至是矩阵的一个子块m1.block(0,0,10,10)的 或者表达式 m1+m2 (假设m1,m2为MatrixXd类型的)
- 2、速度快(表达式类型不用先进行运算,存为Matrix了)
但是,事物都有其两面性。。。
问题来了:如果再写函数的过程中,我们需要声明一个临时变量,与X中存储的元素类型相同,该如何声明?
答案很简单,Eigen在MatrixBase类(事实上是近乎所有类)中为我们定义了这些类型,
类型列表如下:
- Scalar: 矩阵中存储的类型
- Index: 矩阵下标的类型,貌似为unsigned int型的
- PlainObject: 表达式对应的矩阵类型, 比如m1+m2对应的PlainObject为 m1的类型,即decltype(m1)
使用的时候,用如下语句可以声明一个变量s:
typename Derived::Scalar s;
好了,最后来膜拜一下PlainObject的定义:
typedef Matrix<typename internal::traits<Derived>::Scalar, internal::traits<Derived>::RowsAtCompileTime, internal::traits<Derived>::ColsAtCompileTime, AutoAlign | (internal::traits<Derived>::Flags&RowMajorBit ? RowMajor : ColMajor), internal::traits<Derived>::MaxRowsAtCompileTime, internal::traits<Derived>::MaxColsAtCompileTime > PlainObject
还有些简单的:
typedef typename internal::traits<Derived>::Index Index; typedef typename internal::traits<Derived>::Scalar Scalar; typedef typename NumTraits<Scalar>::Real RealScalar;
可能有些人还会有疑问,为何是internal::traits<Derived>::Scalar 而不是Derived::Scalar(事实上我们用的时候可以这么用,但是在写Eigen库的过程中不行)!!原因是在编写Eigen库的过程中,类型相互引用,会产生类型未定义的问题(大致如此,描述可能不准确),这样的问题,我们作为库的使用者是不会遇到的
摘录Eigen官方文档如下:
引用
Let us now explain the internal::traits here. The internal::scalar_sum_op class takes one template parameter: the type of the numbers to handle. Here of course we want to pass the scalar type (a.k.a. numeric type) of VectorXf, which is float. How do we determine which is the scalar type of Derived ? Throughout Eigen, all matrix and expression types define a typedef Scalar which gives its scalar type. For example, VectorXf::Scalar is a typedef for float. So here, if life was easy, we could find the numeric type of Derived as just
typename Derived::Scalar
Unfortunately, we can't do that here, as the compiler would complain that the type Derived hasn't yet been defined. So we use a workaround: in src/Core/util/ForwardDeclarations.h, we declared (not defined!) all our subclasses, like Matrix, and we also declared the following class template:
template<typename T> struct internal::traits;
In src/Core/Matrix.h, right before the definition of class Matrix, we define a partial specialization of internal::traits for T=Matrix<any template parameters>. In this specialization of internal::traits, we define the Scalar typedef. So when we actually define Matrix, it is legal to refer to "typename internal::traits\<Matrix\>::Scalar".
typename Derived::Scalar
Unfortunately, we can't do that here, as the compiler would complain that the type Derived hasn't yet been defined. So we use a workaround: in src/Core/util/ForwardDeclarations.h, we declared (not defined!) all our subclasses, like Matrix, and we also declared the following class template:
template<typename T> struct internal::traits;
In src/Core/Matrix.h, right before the definition of class Matrix, we define a partial specialization of internal::traits for T=Matrix<any template parameters>. In this specialization of internal::traits, we define the Scalar typedef. So when we actually define Matrix, it is legal to refer to "typename internal::traits\<Matrix\>::Scalar".
Matrix类官方文档:
http://eigen.tuxfamily.org/dox/classEigen_1_1Matrix.html
MatrixBase类官方文档:
http://eigen.tuxfamily.org/dox/classEigen_1_1MatrixBase.html#ac33495a0e3788e5951670c392b44d9ad
编写Eigen的泛型函数:
http://eigen.tuxfamily.org/dox/TopicFunctionTakingEigenTypes.html
关于internal::traits的,这篇对理解Eigen架构很有帮助:
http://eigen.tuxfamily.org/dox/TopicInsideEigenExample.html
发表评论
-
C++函数中的静态变量
2019-07-19 11:22 762在C++中,可以在成员函数中使用静态变量,从而间接达到在hpp ... -
tensorflow 静态编译笔记 -- linux系统
2018-11-05 14:26 0注: 1、编译tensorflow静态库 很简单,参见: h ... -
gperftools笔记
2018-06-27 14:30 0export LD_LIBRARY_PATH=LD_LIBR ... -
dmlc分布式线性模型编译笔记
2018-06-06 10:37 21051、使用第三方修改后的wormhole工程 原始工程wor ... -
C++中读取控制台输出,并将文件指针FILE*转换为istream
2017-11-27 15:03 1707解决的问题: 1、通过执行系统的bash命令后,获取其输出( ... -
c++中使用boost库在共享内存中存储map
2017-11-09 11:37 5121boost库中的interprocess包可以在共享内存中创建 ... -
近似最近邻算法库FLANN
2017-04-25 18:45 0FLANN库是计算近似最近邻的库, 问题定义如下: 给定距离函 ... -
C++杂记-- 重定向std::cout等
2017-04-18 17:28 18881、屏蔽std::cout 参见:http://stackov ... -
CMake指定目标代码的平台(win32,x64)
2016-06-03 20:54 11534主要参考自:http://blog.c ... -
windows 10下安装GPU版MXNet
2016-06-03 21:28 8527上回说到编译CPU版的MXNet: http://cheris ... -
windows下安装CPU版mxnet
2016-05-23 23:14 17487MXnet (mix net)类似Caffe,Tensorfl ... -
Linux C++编译及 静态/动态 链接库 笔记
2015-12-20 19:49 59861、C++文件的编译 g++参 ... -
Linux (Ubuntu) 下 Eclipse C++ 环境配置
2015-12-08 21:49 19201、安装JDK 参见http://blog.csdn.net/ ... -
Photoshop插件开发-filter
2015-10-11 22:53 3310初学,,感觉PS插件的文档很烂,,教程也很少,,也就这么简单学 ... -
使Visual Assist X支持CUDA的.cu文件的代码提示
2015-07-17 00:05 2227现在安装CUDA很方便了,直接支持Visual Studio。 ... -
CUDA程序block和thread超出硬件允许值时的异常
2015-07-13 11:32 3681调用CUDA的核函数时指定block 和 thread大小,该 ... -
创建及使用DLL
2014-09-29 15:22 1194此篇仅作简要的记录,作为备忘。 更为详细的可以参考:http: ... -
matlab的mexFunction中使用std::cout(部分转载)
2014-09-27 15:37 2124在matlab、C++混合编程的时候,可能会用到之前的代码。代 ... -
Eigen库:那些年我们一起经历的bug
2014-09-24 18:39 17701、使用auto声明新变量 ... -
C++:无虚函数的类作为有虚函数类的父类时产生Expression:_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
2014-09-24 09:48 1899调程序时忘了为啥,写了一小段测试程序,再简单不过,结果跑出了E ...
相关推荐
实用矩阵库 eigen 强大且只需要头文件即可 实用矩阵库 eigen 强大且只需要头文件即可 实用矩阵库 eigen 强大且只需要头文件即可
近需要用 C++ 做一些数值计算,之前一直采用Matlab 混合编程的方式处理矩阵运算,非常麻烦,直到发现了 Eigen 库,简直相见恨晚,好用哭了。 Eigen 是一个基于C++模板的线性代数库,直接将库下载后放在项目目录下,...
矩阵库eigen 3,不用安装,简便易用
矩阵库Eigen,本人亲测在VS2010中运行良好,只需要在项目中包含文件的路径就可以正常使用了
可以源码级引用的开源矩阵运算库,适合于多种项目嵌入,使用方便
C++的矩阵库——EIGEN,通过这个矩阵库,可以很方便的使用matlab的矩阵计算
Eigen是一个高层次的C ++库,有效支持线性代数,矩阵和矢量运算,数值分析及其相关的算法。Eigen是一个开源库,从3.1.1版本开始遵从MPL2许可。
矩阵计算 Eigen3依赖库 (3.3.5 Release)。Eigen是一个高层次的C++库,有效支持线性代数,矩阵和矢量运算,数值分析及其相关的算法。该版本是在3.3.5版本中发布的,有效支持需要Eigen 3.2 or later的调用。
本文主要讲解利用Eigen库计算矩阵的特征值及特征向量并与Matlab计算结果进行比较。 C++Eigen库代码 #include #include <Eigen> #include <Eigen> using namespace Eigen; using namespace std; void Eig() { ...
4.5 特殊矩阵的定义 4.5.1 全0矩阵 4.5.2 全1矩阵 4.5.3 矩阵置0 4.5.4 矩阵置1 4.5.5 随机矩阵 4.5.6 置为单位阵(不一定是方阵) 4.5.7 矩阵填充 4.5.8 将向量转为对角阵 4.6 矩阵运算 4.6.1 矩阵相乘 4.6.2 矩阵...
eigen中文使用教程,csdn网页版的教程;eigen是矩阵运算函数库,简单易用。
c++代码,利用eigen矩阵库,求解线性方程组。 c++代码,利用eigen矩阵库,求解线性方程组。 c++代码,利用eigen矩阵库,求解线性方程组。 c++代码,利用eigen矩阵库,求解线性方程组。 c++代码,利用eigen矩阵库,...
Eigen适用范围广,支持包括固定大小、任意大小的所有矩阵操作,甚至是稀疏矩阵;...Eigen支持多种编译环境,开发人员对库中的实例在多种编译环境下经过测试,以保证其在不同编译环境下的可靠性和实用性。
Eigen数学函数库中文使用案例,包括矩阵的基本使用、线性代数运算、稀疏矩阵算法以及矩阵的几何算法。
C++矩阵处理库 Eigen是可以用来进行线性代数、矩阵、向量操作等运算的C++库,它里面包含了很多算法。它的License是MPL2。它支持多平台。
C++矩阵工具库,可以执行矩阵的加减乘除、矩阵的各种分解,矩阵的特征值和特征向量,速度适中
Eigen是一个高层次的C ++库,有效支持线性代数,矩阵和矢量运算,数值分析及其相关的算法。 直接静态调用即可。
非常强大的矩阵运算库,Eigen一个重要特点是没有什么依赖的库,本身仅有许多头文件组成,因此非常轻量而易于跨平台。
使用vs2017和cmake编译的Eigen3.3.9的库,32位64位通用