eigen

int p is not a constant expression in lpNorm<p>

家住魔仙堡 提交于 2020-03-22 07:25:30
问题 I wrote this function template <typename T> double norm(const T & v, const int p) { return v.template lpNorm<p>(); } but it doesn't work and gives the error: error: 'p' is not a constant expression return v.template lpNorm<p>(); ^ I seem to think that the compiler expects p to be known at compile time whereas my p is dynamic. Possibly related: Why is this not a constant expression? Non-type template argument is not a constant expression How can I fix this? 回答1: You can partially do it with a

Eigen 3.3 Conjugate Gradient is slower when multi-threaded with GCC compiler optimization

♀尐吖头ヾ 提交于 2020-03-20 06:10:53
问题 I've been using the ConjugateGradient solver in Eigen 3.2 and decided to try upgrading to Eigen 3.3.3 with the hope of benefiting from the new multi-threading features. Sadly, the solver seems slower (~10%) when I enable -fopenmp with GCC 4.8.4. Looking at xosview, I see that all 8 cpus are being used, yet performance is slower... After some testing, I discovered that if I disable compiler optimization (use -O0 instead of -O3 ), then -fopenmp does speed up the solver by ~50%. Of course, it's

Eigen 3.3 Conjugate Gradient is slower when multi-threaded with GCC compiler optimization

青春壹個敷衍的年華 提交于 2020-03-20 06:10:38
问题 I've been using the ConjugateGradient solver in Eigen 3.2 and decided to try upgrading to Eigen 3.3.3 with the hope of benefiting from the new multi-threading features. Sadly, the solver seems slower (~10%) when I enable -fopenmp with GCC 4.8.4. Looking at xosview, I see that all 8 cpus are being used, yet performance is slower... After some testing, I discovered that if I disable compiler optimization (use -O0 instead of -O3 ), then -fopenmp does speed up the solver by ~50%. Of course, it's

How to access tensorflow::Tensor C++

大兔子大兔子 提交于 2020-03-18 09:26:51
问题 I am running Tensorflow using its C++ API. I have the following call that returns four tensors in finalOutput: std::string str1 = "detection_boxes"; std::string str2 = "detection_scores"; std::string str3 = "detection_classes"; std::string str4 = "num_detections"; std::vector<Tensor> finalOutput; status = session->Run({ {InputName, inputTensor} }, { str1, str2, str3, str4 }, {}, &finalOutput); std::cout << finalOutput[0].DebugString() << std::endl; The print statement outputs the following:

Eigen子矩阵操作

冷暖自知 提交于 2020-03-07 07:06:33
1 子矩阵操作简介 子矩阵操作又称块操作,在矩阵运算中,子矩阵的提取和操作应用也十分广泛。因此Eigen中也提供了相关操作的方法。提取的子矩阵在操作过程中既可以用作左值也可以用作右值。 2 块操作的一般使用方法 在Eigen中最基本的快操作运算是用 .block() 完成的。提取的子矩阵同样分为动态大小和固定大小。 块操作 构建动态大小子矩阵 提取块大小为(p,q),起始于(i,j) matrix.block(i,j,p,q) 同样需要注意的是在Eigen中,索引是从0开始。所有的操作方法都可以适用于Array.同样使用固定大小的操作方式在小型矩阵运算时更加的快,但要求在编译时就要知道矩阵的大小。 下面是一个使用示例: #include <iostream> #include "Eigen/Dense" using namespace std; using namespace Eigen; int main() { MatrixXf m(4,4); m<< 1,2,3,4, 5,6,7,8, 9,10,11,12, 13,14,15,16; cout<<"Block in the middle"<<endl; cout<<m.block<2,2>(1,1)<<endl<<endl; for(int i = 1;i <= 3;++i) { cout<<"Block of size "

Eigen矩阵基本运算

血红的双手。 提交于 2020-03-07 07:06:00
1 矩阵基本运算简介 Eigen重载了+,-,*运算符。同时提供了一些方法如dot(),cross()等。对于矩阵类的运算符重载只支持线性运算,比如matrix1*matrix2是矩阵相乘,当然必须要满足矩阵乘法规则。对于向量和标量的加法(vector+scalar)这里并不支持,关于非线性运算这里暂不介绍。 2 加减运算 矩阵加减运算中必须要保证左右矩阵的行列对应相等。此外更重要的一点是,矩阵的类型也必须一致,这里的矩阵运算 并不支持隐式的类型转换 。矩阵运算中重载的运算符有: 二元运算符+:a+b 二元运算符-:a-b 一元运算符-:-a 复合运算符+=:a+=b 复合运算符-=:a-=b 下面是使用示例: #include <iostream> #include "Eigen\Dense" using namespace Eigen; int main() { 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;

Ubuntu虚拟机下安装运行ORB-SLAM2

帅比萌擦擦* 提交于 2020-03-05 13:49:33
Ubuntu虚拟机下安装运行ORB-SLAM2 由于电脑的两个硬盘都存着数据,没法腾出来一个安装双系统,所以无奈只能在虚拟机上跑SLAM。这两天边看高博的《SLAM十四讲》,边熟悉Ubuntu,遇到了许多问题,但也磕磕绊绊配置运行上了ORB-SLAM2。在此记录下配置过程和出现的一些错误,仅供参考。 1.基本工具 在配置过程中需要cmake、gcc、g++和git工具,这是最基本的工具了,不安装后面要报错的。可以直接在桌面右击打开终端进行安装。git的安装需要一些额外的配置,比如生成SSH密钥,填写你的github账号等,网上有许多这里不再一一赘述。 sudo apt - get install cmake sudo apt - get install git sudo apt - get install gcc g ++ 2.安装Pangolin Pangolin是对OpenGL进行封装的轻量级的OpenGL输入/输出和视频显示的库。可以用于3D视觉和3D导航的视觉图,可以输入各种类型的视频、并且可以保留视频和输入数据用于debug。也就是说Pangolin是一个可视化用户界面。 首先要安装一些Pangolin所需要的依赖库: sudo apt - get install libglew - dev sudo apt - get install libboost - dev

Understanding solveInPlace operation in Eigen

僤鯓⒐⒋嵵緔 提交于 2020-03-05 02:16:06
问题 I was trying to explore the option of "solveInPlace()" function while using LLT in Eigen3.3.7 to speed up the matrix inverse computation in my application. I used the following code to test it. int main() { const int M=3; Eigen::Matrix<MyType,Eigen::Dynamic,Eigen::Dynamic> R = Eigen::Matrix<MyType,Eigen::Dynamic,Eigen::Dynamic>::Zero(M,M); // to make sure full rank for(int i=0; i<M*2; i++) { const Eigen::Matrix<MyType, Eigen::Dynamic,1> tmp = Eigen::Matrix<MyType,Eigen::Dynamic,1>::Random(M);

计算方法(三)矩阵分解1-正交分解(QR分解)

北战南征 提交于 2020-03-02 19:07:16
正交分解 矩阵的正交分解又称为QR分解,是将矩阵分解为一个正交矩阵Q和一个上三角矩阵的乘积的形式。 任意实数方阵A,都能被分解为 。这里的Q为正交单位阵,即 R是一个上三角矩阵。这种分解被称为QR分解。 QR分解也有若干种算法,常见的包括Gram–Schmidt、Householder和Givens算法。 QR分解是将矩阵分解为一个正交矩阵与上三角矩阵的乘积。用一张图可以形象地表示QR分解: 为啥我们需要正交分解呢? 实际运用过程中,QR分解经常被用来解线性最小二乘问题,这个问题我们后面讲述。 提到正交分解就不得不讨论(Householder transformation Householder变换)豪斯霍尔德变换和(Schmidt orthogonalization Schmidt正交化)施密特正交化 Schmidt正交化 定理1 设A是n阶实非奇异矩阵,则存在正交矩阵Q和实非奇异上三角矩阵R使A有QR分解;且除去相差一个对角元素的绝对值(模)全等于1的对角矩阵因子外,分解是唯一的. 定理2 设A是m×n实矩阵,且其n个列向量线性无关,则A有分解A=QR,其中Q是m×n实矩阵,且满足QHTQ=E,R是n阶实非奇异上三角矩阵该分解除去相差一个对角元素的绝对值(模)全等于1的对角矩阵因子外是唯一的.用Schmidt正交化分解方法对矩阵进行QR分解时,所论矩阵必须是列满秩矩阵。

c++在使用Eigen,编译找不到eigen3的报错解决方法(方法测试可行)

≡放荡痞女 提交于 2020-03-01 06:04:17
描述问题如下 造成的原因 安装的路径不对:在很多程序中include时经常使用#include <Eigen/Dense>而不是使用#include <eigen3/Eigen/Dense>所以要做下处理,否则一些程序在编译时会因找不到Eigen/Dense而报错 解决方法 上面指令将usr/local/include/eigen3文件夹中的Eigen文件递归地复制到上一层文件夹(直接放到/usr/local/include中,否则系统无法默认搜索到 -> 此时只能在CMakeLists.txt用include_libraries(绝对路径了)) 例如: 我使用apt-get安装默认路径为:/usr/include/eigen3/Eigen 需要将Eigen和eigen3并列在同一文件夹下 来源: CSDN 作者: Spider_man_ 链接: https://blog.csdn.net/chengmo123/article/details/104579679