如何使用线性代数的C ++模板库Eigen?

时间:2010-07-15 15:23:33

标签: c++ matrix simd eigen

我有一个矩阵的图像处理算法,我有自己的矩阵运算代码(乘法,反...)。但我使用的处理器是ARM​​ Cortex-A8处理器,它有NEON协处理器进行矢量化,因为矩阵运算是SIMD操作的理想情况,我要求编译器(-mfpu = neon -mfloat-abi = softfp)生成NEON我的代码的说明,但编译器没有这样做,然后我也尝试为Matrix操作编写自己的NEON内在函数代码,但我发现很难这样做。

所以,我想到了使用Eigen库来承诺矩阵运算的矢量化。所以我立即下载了Eigen C ++库并尝试在他们的教程中使用它,但不幸的是,当我运行example programs时,我得到编译错误

那些有使用Eigen经验的人,任何例子都会有帮助吗?请帮我解决这个问题。

帮助!

由于


我有Eigen文件夹: / home / ubuntu / Documents / eigen 我在Eclipse的C ++项目的其他目录中设置了这个路径。然后我运行以下程序(示例) -

#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;
}

我得到的错误 -

构建配置调试项目Test_Eigen ****

全部

构建文件:../ main.cpp

调用: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”

“../的main.cpp”

../ main.cpp:6:错误:'int'之前的构造函数,析构函数或类型转换 make:*** [main.o]错误1

2 个答案:

答案 0 :(得分:10)

特征3中的USING_PART_OF_NAMESPACE_EIGEN宏为removed。只需使用

即可
using namespace Eigen;

显然,教程已经过时了。

答案 1 :(得分:1)

我正在使用Ubuntu 17.04,这对我来说很有用 第一:
我在eigen official site下载了egien3.3.3。在一个名为eigen的目录中提取,cd进入它 第二:
逐个运行命令或使它们成为一次运行的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

最后:
进行测试

#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;
}

注意:
要查找已安装的结果,请参阅/ usr / local / include / eigen3 /
如果有任何变化,请参阅mytinx