How to use Eigen, the C++ template library for linear algebra?
Asked Answered
C

2

6

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

Conjunctive answered 15/7, 2010 at 15:23 Comment(6)
We can't help you if you don't post the particular errors you're getting.Citral
What are the compilation errors?Shewchuk
Did u check compiler support and dependency from your link?Rhyme
Sorry guys, I just edited the question now, please look at the question again. Thanks.Conjunctive
Why is this tagged as relating to C?Aekerly
Nathon, my apologies, will fix it.Conjunctive
C
11

The USING_PART_OF_NAMESPACE_EIGEN macro was removed in Eigen 3. Instead, simply use

using namespace Eigen;

Apparently, the tutorial is outdated.

Citral answered 15/7, 2010 at 15:32 Comment(1)
Yes, Thomas the tutorial was indeed outdated. Now it works well. Thanks for your quick reply saved a lot of time.Conjunctive
T
4

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.

#!/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/
If any thing change, please see mytinx

Tarragona answered 6/6, 2017 at 5:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.