Questions tagged [eigen]

Eigen is a C++ template library for linear algebra: matrices, vectors, and related algorithms.

Eigen is a C++ template library for linear algebra: matrices, numerical solvers, and related algorithms.

Despite its name, this tag should not be mistaken with the and ones.

Eigen covers a large set of features through an easy to use unified API. Here is quick and incomplete overview:

  • Dense algebra:
    • array/matrix manipulation
    • linear solvers and factorizations (Cholesky, LU, QR, SVD, EVD)
  • Sparse algebra:
    • compressed sparse representation
    • direct solvers and factorizations (Cholesky, LU, QR)
    • Krylov subspace methods (CG, BiCGSTAB, GMRES) with preconditioners (Jacobi, ILLT, ILUT)
  • Geometry:
    • space transformation and subspace primitives

Find more on Eigen's home page and its online documentation.

3438 questions
30
votes
2 answers

Installing Eigen on Mac OS X for XCode

A while back it was a nightmare for me trying to get Eigen up and running on my mac for XCode, but a friend managed to figure it out and shared the instructions with me. I don't want anyone to go through what I went through, so here's an…
Maria-Andersado
  • 777
  • 1
  • 9
  • 18
28
votes
3 answers

C++ Eigen initialize static matrix

Is it possible to initialize a static eigen matrix4d in a header file? I want to use it as a global variable. I'd like to do something along the lines of: static Eigen::Matrix4d foo = Eigen::Matrix4d(1, 2 ... 16); Or similar to vectors: static…
Matt Stokes
  • 4,618
  • 9
  • 33
  • 56
27
votes
4 answers

Apply function to all Eigen matrix element

I have an Eigen::MatrixXd and I would like to modify all its elements by applying a function component-wise. For example: MatrixXd m = ...; for each m[i][j]: m[i][j] = exp(m[i][j]); Is there a way to achieve this result?
Nick
  • 10,309
  • 21
  • 97
  • 201
26
votes
2 answers

Why is it faster to perform float by float matrix multiplication compared to int by int?

Having two int matrices A and B, with more than 1000 rows and 10K columns, I often need to convert them to float matrices to gain speedup (4x or more). I'm wondering why is this the case? I realize that there is a lot of optimization and…
NULL
  • 759
  • 9
  • 18
26
votes
2 answers

Constructing diagonal matrix in eigen

In eigen, we can create a matrix as Matrix3f m; m << 1, 2, 3, 4, 5, 6, 7, 8, 9; How can I create a diagonal matrix like the one below 3, 0, 0, 0, 8, 0, 0, 0, 6; I don't understand how Eigen handle diagonal matrix? Only the diagonal…
asdfkjasdfjk
  • 3,784
  • 18
  • 64
  • 104
24
votes
1 answer

Append column to matrix, using Eigen library

It's quite a simple task, but I was not able to find an answer to it: Using the Eigen library, suppose I have Matrix2Xd mat and Vector2d vec, where mat = 1 1 1 1 1 1 vec = 2 2 Now I need something like mat.addCol(vec) such that afterwards mat…
luator
  • 4,769
  • 3
  • 30
  • 51
23
votes
4 answers

How to work with Eigen in CUDA kernels

Eigen is a c++ linear algebra library http://eigen.tuxfamily.org. It's easy to work with basic data types, like basic float arrays, and just copy it to device memory and pass the pointer to cuda kernels. But Eigen matrix are complex type so how to…
Mickey Shine
  • 12,187
  • 25
  • 96
  • 148
23
votes
6 answers

Creating a rotation matrix with pitch, yaw, roll using Eigen

How do I create a rotation matrix using pitch, yaw, roll with Eigen library?
Caesar
  • 9,483
  • 8
  • 40
  • 66
23
votes
3 answers

Eigen efficient type for dense symmetric matrix

Does Eigen have efficient type for store dense, fixed-size, symmetric matrix? (hey, they are ubiquitous!) I.e. for N=9, it should store only (1+9)*9/2==45 elements and it has appropriate operations. For instance there should be efficient addition of…
qble
  • 1,256
  • 2
  • 12
  • 29
22
votes
3 answers

Boost::uBLAS vs Eigen

I am used to Eigen for almost all my mathematical linear algebra work. Recently, I have discovered that Boost also provides a C++ template class library that provides Basic Linear Algebra Library (Boost::uBLAS). This got me wondering if I can get…
Vtik
  • 3,073
  • 2
  • 23
  • 38
22
votes
3 answers

How could comma separated initialization such as in Eigen be possibly implemented in C++?

Here's a part of Eigen documentation: Matrix3f m; m << 1, 2, 3, 4, 5, 6, 7, 8, 9; std::cout << m; Output: 1 2 3 4 5 6 7 8 9 I couldn't understand how could all the comma separated values be captured by operator<< above. I did a tiny…
Michael
  • 5,775
  • 2
  • 34
  • 53
21
votes
1 answer

CMake Can't find Eigen3

I have copied FindEigen3.cmake into my source directory. I then added: set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}) to my CMakeLists.txt to tell CMake to use this .cmake file. Then in my CMakeLists.txt I…
David Doria
  • 9,873
  • 17
  • 85
  • 147
21
votes
1 answer

Cross-product matrix in Eigen

Is there a ready function or method in Eigen for the Hat operator? That is the operator, taking a vector as input and returning a matrix, which mimics a cross product with that vector. I know, that it can be easily written, but would like to avoid…
wl2776
  • 4,099
  • 4
  • 35
  • 77
21
votes
4 answers

Teach Google-Test how to print Eigen Matrix

Introduction I am writing tests on Eigen matrices using Google's testing framework Google-Mock, as already discussed in another question. With the following code I was able to add a custom Matcher to match Eigen matrices to a given…
Lemming
  • 4,085
  • 3
  • 23
  • 36
21
votes
2 answers

How does OpenCV make use of Eigen?

When compiling OpenCV from source, there's the CMake option WITH_EIGEN, which says "Include Eigen3 support". However, nowhere in the documentation (or with google, for that matter) I can find out what exactly this does and how to use it. I can…
Ela782
  • 5,041
  • 5
  • 53
  • 66