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
12
votes
2 answers

Converting an Armadillo Matrix to an Eigen MatriXd and vice versa

How can I convert from an Armadillo Matrix to an Eigen MatrixXd and vice versa? I have nu as an arma::vec of size N, z as arma::mat of dimension N x 3. I want to compute a matrix P such as the entry P_ij is Pij=exp(nu(i) + nu(j) +…
Ari.stat
  • 463
  • 4
  • 13
12
votes
1 answer

Inverse of a matrix using eigen

I have learnt how to find inverse of a matrix using Eigen. But when I'm finding inverse of an array that is a output of function I got an error request for member ‘inverse’ in ‘x’, which is of non-class type ‘double**’ Please help me out, in…
AGN
  • 223
  • 1
  • 2
  • 7
12
votes
3 answers

Eigen & GCC 5 : class std::binder2nd is deprecated

I just restarted working on a project which has been on hold for a few months. Last time I compiled it it was working just fine, without any error nor warning. Yet when I tried to compile it earlier today I got this warning attention :…
Amxx
  • 3,020
  • 2
  • 24
  • 45
12
votes
4 answers

Foreach loops over Eigen matrices?

Is it possible to use the foreach syntax of C++11 with Eigen matrices? For instance, if I wanted to compute the sum of a matrix (I know there's a builtin function for this, I just wanted a simple example) I'd like to do something like Matrix2d a; a…
David Pfau
  • 793
  • 9
  • 23
12
votes
1 answer

Eigen3: coefficient-wise multiplication in place

How can you perform a element-wise multiplication in place using Eigen3? Does a = a.cwiseProduct(b); run in place? Or is a.array() *= b.array(); the better solution in terms of style and performance?
PhilLab
  • 4,777
  • 1
  • 25
  • 77
12
votes
1 answer

How to check if Eigen Matrix is column major or row major?

I need to use the underlying arrays of several eigen matrices that could be RowMajor or ColumnMajor. Is there any way to check which of the formats is used? (besides comparing the first column, with the first n elements of the row/column) I found…
XapaJIaMnu
  • 1,408
  • 3
  • 12
  • 28
12
votes
2 answers

Eigen: mask an array

Is it possible to mask an array in Eigen as in Matlab? Something like ArrayXd arrayA = ArrayXd::Random(10, 5); ArrayXi mask = ArrayXi::Zero(arrayA.rows(), arrayA.cols()); mask = arrayA > 5; ArrayXd arrayB = arrayA(mask) where arrayB is a row…
lib
  • 2,918
  • 3
  • 27
  • 53
11
votes
3 answers

Using OpenMP and Eigen causes infinite loop/deadlock

I'm solving a much larger problem and have run into a bug when I try to use OpenMP to parallelize some loops. I've reproduced the problem with some simpler code below that mimics my own code. The problem is that when I run the program, it will…
user1144371
  • 221
  • 2
  • 7
11
votes
0 answers

Why does Eigen make inconsistent default assumptions about aliasing?

As a newcomer to Eigen there is something I am battling to come to terms with. With matrix multiplication Eigen creates a temporary by default to avoid aliasing issues: matA = matA * matA; // works fine (Eigen creates a temporary before…
Museful
  • 6,711
  • 5
  • 42
  • 68
11
votes
1 answer

Why does overloading operator<< to print Eigen class member result in a segfault?

For the following struct struct TestClass { TestClass() : mat(Eigen::Matrix3i::Zero()) {} Eigen::Matrix3i mat; }; I would like to have an overloaded operator<< to print the mat member to std::cout. I tried std::ostream& operator<<(std::ostream&…
red
  • 195
  • 1
  • 10
11
votes
1 answer

Why is Eigens mean() method so much faster than sum()?

This is a rather theoretical question, but I'm quite interested in it and would be glad if someone has some expert knowledge on this which he or she is willing to share. I have a matrix of floats with 2000 rows and 600 cols and want to subtract the…
Callidior
  • 2,899
  • 2
  • 18
  • 28
11
votes
2 answers

Roll pitch and yaw from Rotation matrix with Eigen Library

I need to extract the roll pitch yaw angles from a rotation matrix and I want to be sure that what I do is correct. Eigen::Matrix< simFloat, 3, 1> rpy = orientation.toRotationMatrix().eulerAngles(0,1,2); const double r = ((double)rpy(0)); …
desmond13
  • 2,913
  • 3
  • 29
  • 46
11
votes
3 answers

Initialize a constant eigen matrix in a header file

This is a question that can be answered by non-Eigen user... I want to use the Eigen API to initialize a constant matrix in a header file, but Eigen seems not providing a constructor to achieve this, and following is what I tried: // tried the…
Hailiang Zhang
  • 17,604
  • 23
  • 71
  • 117
11
votes
3 answers

Eigen combine rotation and translation into one matrix

I have a rotation matrix rot (Eigen::Matrix3d) and a translation vector transl (Eigen::Vector3d) and I want them both together in a 4x4 transformation matrix. I just for the life of me can't figure out how to do this in Eigen. I think Affine can be…
DaedalusAlpha
  • 1,610
  • 4
  • 20
  • 33
11
votes
1 answer

Overriding system defaults for C++ compilation flags from R

I'm using RcppEigen to write some C++ functions for my R code, and I'd like to optimize their compilation as much as possible. When I've used Eigen in the past, I've gotten a significant boost from -O3 and -fopenmp. Following Dirk's advice, I edited…
stackoverflax
  • 1,077
  • 3
  • 11
  • 25