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
71
votes
7 answers

Convert Eigen Matrix to C array

The Eigen library can map existing memory into Eigen matrices. float array[3]; Map(array, 3).fill(10); int data[4] = 1, 2, 3, 4; Matrix2i mat2x2(data); MatrixXi mat2x2 = Map(data); MatrixXi mat2x2 = Map(data, 2, 2); My…
lil
  • 2,527
  • 4
  • 22
  • 15
65
votes
5 answers

Initialise Eigen::vector with std::vector

I have seen it done before but I cannot remember how to efficiently initialize an Eigen::Vector of known length with a std::vector of the same length. Here is a good example: std::vector v1 = {1.0, 2.0, 3.0}; Eigen::Vector3d v2; // Do I put…
Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175
59
votes
3 answers

Why don't C++ compilers do better constant folding?

I'm investigating ways to speed up a large section of C++ code, which has automatic derivatives for computing jacobians. This involves doing some amount of work in the actual residuals, but the majority of the work (based on profiled execution time)…
52
votes
3 answers

Eigen how to concatenate matrix along a specific dimension?

I have two eigen matrices and I would like to concatenate them, like in matlab cat(0, A, B) Is there anything equivalent in eigen? Thanks.
Ran
  • 4,117
  • 4
  • 44
  • 70
51
votes
6 answers

How can the C++ Eigen library perform better than specialized vendor libraries?

I was looking over the performance benchmarks: http://eigen.tuxfamily.org/index.php?title=Benchmark I could not help but notice that eigen appears to consistently outperform all the specialized vendor libraries. The questions is: how is it…
Anycorn
  • 50,217
  • 42
  • 167
  • 261
45
votes
3 answers

typecasting Eigen::VectorXd to std::vector

Their are many links to go the other way round but I am unable to find to get a std::vector from a Eigen::Matrix or Eigen::VectorXd in my specific case.
Manish
  • 668
  • 1
  • 6
  • 13
45
votes
1 answer

Correct usage of the Eigen::Ref<> class

Eigen has introduced the Ref<> class to write functions with Eigen objects as parameters without the use unnecessary temporaries, when writing template functions is not wanted. One can read about this here. When searching the internet further, I…
Nikolaus Ammann
  • 507
  • 1
  • 4
  • 12
40
votes
5 answers

OpenCV CV::Mat and Eigen::Matrix

Is there a reversible way to convert an OpenCV cv::Mat object to an Eigen::Matrix? e.g., Some way of doing: cv::Mat cvMat; Eigen::Matrix eigMat; camera->retrieve(cvMat); // magic to convert cvMat to eigMat // work on eigMat // convert eigMat back…
Yeraze
  • 3,269
  • 4
  • 28
  • 42
38
votes
1 answer

Access a column of a matrix as a vector in Eigen

How can I access a single vector from a matrix? For example: Is there a way to extract a vector using something like A(i) for a matrix Eigen::MatrixXf A(10,10) that returns an Eigen::VectorXf A(10)?
R.J.
  • 1,413
  • 2
  • 13
  • 18
38
votes
4 answers

Eigen: Coding style's effect on performance

From what I've read about Eigen (here), it seems that operator=() acts as a "barrier" of sorts for lazy evaluation -- e.g. it causes Eigen to stop returning expression templates and actually perform the (optimized) computation, storing the result…
jeremytrimble
  • 1,814
  • 1
  • 18
  • 22
38
votes
4 answers

How to check the version number of Eigen C++ template library?

I added several different versions of Eigen to default including directory of Visual C++. But I got collapse problem when using LDLT (Cholesky decomposition) for some of the testing numerical examples. So I want to determine which version is…
LCFactorization
  • 1,652
  • 1
  • 25
  • 35
38
votes
13 answers

Find package Eigen3 for CMake

CMake cannot find my Eigen3 package. I set an environment variable called EIGEN3_INCLUDE_DIR pointing to the path where FindEigen3.cmake is. Then in the CMakelists.txt I wrote: find_package( Eigen3 REQUIRED ) include_directories( EIGEN3_INCLUDE_DIR…
Jav_Rock
  • 22,059
  • 20
  • 123
  • 164
37
votes
2 answers

Member function in Eigen math library for vector magnitude

I have been trying to find a method that computes the magnitude of a vector in Eigen and I was not able to. Can somebody provide me with the function name of just if it doesn't exist? I can create a global method that does the job but I prefer not…
Alex
  • 373
  • 1
  • 3
  • 4
31
votes
1 answer

Error mixing types with Eigen matrices

There was no quick find answer that I could see on stack for this problem so I thought I would add one. Say I have the following example code from the c++ Eigen Library: Eigen::Matrix4d m1; Eigen::Matrix4f m2; m1 << 1, 2, 3, 4 ... 16 m2 = m1;…
Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175
31
votes
1 answer

Most efficient way to solve a system of linear equations

I have an (n x n) symmetric matrix A and a (n x 1) vector B. Basically, I just need to solve Ax = b for x. The issue is that A is going to potentially be massive. So I'm looking for the most efficient algorithm for solving linear equations in…
aesir
  • 565
  • 2
  • 13
  • 23
1
2 3
99 100