[英]How to use Eigen, the C++ template library for linear algebra?
I have an image processing algorithm which makes of matrices, I have my own matrix operation codes (Multiplication, Inverse...) with me. 我有一个矩阵的图像处理算法,我有自己的矩阵运算代码(乘法,逆...)。 But the processor I use is ARM Cortex-A8 processor, which has NEON co-processor for vectorization, as matrix operations are ideal cases for SIMD operations, I asked the compiler (-mfpu=neon -mfloat-abi=softfp) to generate NEON instructions for my code, but the compiler fails to do so and then I also attempted to write my own NEON intrinsics code for the Matrix operations, but I found it very hard to do so.
但我使用的处理器是ARM Cortex-A8处理器,它有NEON协处理器进行矢量化,因为矩阵运算是SIMD操作的理想情况,我要求编译器(-mfpu = neon -mfloat-abi = softfp)生成NEON我的代码的说明,但编译器没有这样做,然后我也尝试为Matrix操作编写自己的NEON内在函数代码,但我发现很难这样做。
So, I thought of making use of Eigen library which promises vectorization of matrix operations. 因此,我想到利用特征库来承诺矩阵运算的矢量化。 So I promptly downloaded the Eigen C++ library and tried using it as given in their tutorials but, unfortunately I get compilation errors when I run their example programs .
所以我立即下载了Eigen C ++库,并尝试在他们的教程中使用它,但不幸的是,当我运行他们的示例程序时,我得到了编译错误 。
Anyone out there who has experience using Eigen, any examples will be really helpful? 那些有使用Eigen经验的人,任何例子都会非常有用吗? Kindly help me how to go about it.
请帮助我如何去做。
Help! 救命!
Thanks 谢谢
I have the Eigen folder at: /home/ubuntu/Documents/eigen I set this path in my Eclipse's C++ project's additional directories. 我有Eigen文件夹: / home / ubuntu / Documents / eigen我在Eclipse的C ++项目的其他目录中设置了这个路径。 Then I run the following program (Example)-
然后我运行以下程序(示例) -
#include <Eigen/Core>
// import most common Eigen types
USING_PART_OF_NAMESPACE_EIGEN
int main(int, char *[])
{
Matrix3f m3;
m3 << 1, 2, 3, 4, 5, 6, 7, 8, 9;
Matrix4f m4 = Matrix4f::Identity();
Vector4i v4(1, 2, 3, 4);
std::cout << "m3\n" << m3 << "\nm4:\n"
<< m4 << "\nv4:\n" << v4 << std::endl;
}
Errors I get - 我得到的错误 -
Build of configuration Debug for project Test_Eigen **** 构建配置Debug for Project Test_Eigen ****
make all 做所有
Building file: ../main.cpp 构建文件:../ main.cpp
Invoking: Sourcery G++ C++ Compiler 调用:Sourcery G ++ C ++编译器
arm-none-linux-gnueabi-g++ -I/home/ubuntu/Documents/eigen -O0 -g3 -Wall -c -fmessage-length=0 -fcommon -MMD -MP -MF"main.d" -MT"main.d" -mcpu=cortex-a8 -marm -o"main.o" arm-none-linux-gnueabi-g ++ -I / home / ubuntu / Documents / eigen -O0 -g3 -Wall -c -fmessage-length = 0 -fcommon -MMD -MP -MF“main.d”-MT“main .d“-mcpu = cortex-a8 -marm -o”main.o“
"../main.cpp" “../main.cpp”
../main.cpp:6: error: expected constructor, destructor, or type conversion before 'int' make: *** [main.o] Error 1 ../main.cpp:6:错误:'int'make之前的构造函数,析构函数或类型转换:*** [main.o]错误1
I am using the Ubuntu 17.04, and this is work for me 我正在使用Ubuntu 17.04,这对我有用
First: 第一:
I download the egien3.3.3 at eigen official site . 我在eigen官方网站下载了egien3.3.3。 Extracted in a directory called eigen, cd into it.
在名为eigen的目录中提取,cd进入它。
Second: 第二:
run the command bellow one by one or make them a xxx.sh file to run at a time. 逐个运行命令,或者将它们作为xxx.sh文件一次运行。
#!/bin/bash
#eigen3 install
#from: http://eigen.tuxfamily.org/index.php?title=Main_Page
#download the package like eigen-eigen-67e894c6cd8f.tar.gz
mkdir build
cd build
cmake -DEIGEN_TEST_NO_OPENGL=1 ..
make
sudo make install
Finally: 最后:
make a test 做一个测试
#include <eigen3/Eigen/Core>
#include <iostream>
// import most common Eigen types
//USING_PART_OF_NAMESPACE_EIGEN
using namespace Eigen;
using namespace std;
int main(int, char *[])
{
Matrix3f m3;
m3 << 1, 2, 3, 4, 5, 6, 7, 8, 9;
Matrix4f m4 = Matrix4f::Identity();
Vector4i v4(1, 2, 3, 4);
cout << "m3\n" << m3 << "\nm4:\n"
<< m4 << "\nv4:\n" << v4 << endl;
}
Note: 注意:
To find your installed results, please see /usr/local/include/eigen3/ 要查找已安装的结果,请参阅/ usr / local / include / eigen3 /
If any thing change, please see mytinx 如果有任何变化,请参阅mytinx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.