如何使用 Eigen,C++线性代数的模板库?
我有一个由矩阵组成的图像处理算法,我有自己的矩阵运算代码(乘法、逆...)。但我使用的处理器是ARM Cortex-A8处理器,它有用于矢量化的NEON协处理器,因为矩阵运算是SIMD运算的理想情况,我要求编译器(-mfpu=neon -mfloat-abi=softfp)生成NEON我的代码的说明,但编译器无法这样做,然后我还尝试为矩阵运算编写自己的 NEON 内在函数代码,但我发现很难这样做。
因此,我想到利用 Eigen 库,它承诺矩阵运算的矢量化。因此,我立即下载了 Eigen C++ 库,并尝试按照他们的教程中给出的方式使用它,但不幸的是,当我运行他们的 示例程序。
任何有使用 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
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.
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.
Anyone out there who has experience using Eigen, any examples will be really helpful? 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. 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 ****
make all
Building file: ../main.cpp
Invoking: Sourcery G++ C++ Compiler
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: error: expected constructor, destructor, or type conversion before 'int'
make: *** [main.o] Error 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
USING_PART_OF_NAMESPACE_EIGEN
宏已在 Eigen 3 中删除相反,只需使用显然,该教程已经过时了。
The
USING_PART_OF_NAMESPACE_EIGEN
macro was removed in Eigen 3. Instead, simply useApparently, the tutorial is outdated.
我正在使用 Ubuntu 17.04,这对我来说很有效
第一:
我在 eigen 官方网站下载了egien3.3.3。解压到一个名为 eigen 的目录中,cd 进入其中。
第二:
一条一条地运行下面的命令或者将它们做成xxx.sh文件一次运行。
最后:
进行测试
注意:
要查找安装的结果,请参阅 /usr/local/include/eigen3/
如果有任何变化,请参阅 mytinx
I am using the Ubuntu 17.04, and this is work for me
First:
I download the egien3.3.3 at eigen official site. Extracted in a directory called eigen, cd into it.
Second:
run the command bellow one by one or make them a xxx.sh file to run at a time.
Finally:
make a test
Note:
To find your installed results, please see /usr/local/include/eigen3/
If any thing change, please see mytinx