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
20
votes
1 answer

Why was Eigen chosen for TensorFlow?

The TensorFlow white paper mentions that Eigen is used. Are there public explanations for how Eigen was chosen, and are they motivation for using Eigen in TensorFlow C++ op kernels?
Noah Smith
  • 351
  • 1
  • 3
  • 9
20
votes
3 answers

Using GDB with Eigen C++ library

I am using the Eigen C++ library downloadable from http://eigen.tuxfamily.org/. This is a C++ library for easier handling of Matrices and Arrays. I use g++ compiler and gdb for debugging. However, I found that I am unable to print the content of a…
Sooraj
  • 585
  • 1
  • 6
  • 12
20
votes
1 answer

How to convert sparse matrix to dense matrix in Eigen

Is there some easy and fast way to convert a sparse matrix to a dense matrix of doubles? Because my SparseMatrix is not sparse any more, but became dense after some matrix products. Another question I have: The Eigen library has excellent…
user2165656
  • 445
  • 1
  • 3
  • 11
20
votes
2 answers

The future of C++ alignment: passing by value?

Reading the Eigen library documentation, I noticed that some objects cannot be passed by value. Are there any developments in C++11 or planned developments that will make it safe to pass such objects by value? Also, why is there no problem with…
Neil G
  • 32,138
  • 39
  • 156
  • 257
19
votes
2 answers

How do you make a matrix out of vectors in eigen?

I have four column vectors. I need to append them to make a four by four matrix. Is there a constructor or something for that?
DanielLC
  • 5,801
  • 5
  • 18
  • 16
19
votes
5 answers

Large Matrix Inversion

I am looking at taking the inverse of a large matrix, common size of 1000 x 1000, but sometimes exceeds 100000 x 100000 (which is currently failing due to time and memory). I know that the normal sentiment is 'don't take the inverse, find some other…
18
votes
2 answers

Solving large linear systems with block sparse matrices

I want to solve Ax = b where A is a very large square positive definite symmetric block matrix and x and b are vectors. When I say large I mean for a nxn matrix an n as large as 300,000. Here is an example of a much smaller but representative…
Z boson
  • 32,619
  • 11
  • 123
  • 226
18
votes
3 answers

Best way to convert an Eigen Vector4 type to Vector3?

I want to extract the three first values of a Vector4 type in Eigen, into a Vector3 type. So far I am doing it in a for-loop. Is there a smarter way to do it?
Reed Richards
  • 4,178
  • 8
  • 41
  • 55
18
votes
1 answer

Eigen: convert Matrix3d rotation to Quaternion

I'm trying to convert a Matrix3d rotation to a Quaternion, but I got only weird compiler errors so far. The code I'm using is: Quaternion getQuaternionFromRotationMatrix(const Matrix3d& mat) { AngleAxisd aa; aa = mat; …
Esparver
  • 1,515
  • 1
  • 15
  • 28
18
votes
8 answers

Eigen library --> initialize matrix with data from file or existing std::vector content (c++)

My question is how to initialize an eigen Matrix, but NOT this way: matrix << 1,0,1,0, 1,0,1,0, 1,0,1,0, I have a Matrix that looks like the above one ( commas or no commas doesnt matter) stored in a txt file. I already wrote a…
dieHellste
  • 252
  • 1
  • 2
  • 11
18
votes
4 answers

How to use the Eigen unsupported levenberg marquardt implementation?

I'm trying to minimize a following sample function: F(x) = f[0]^2(x[0],...,x[n-1]) + ... + f[m-1]^2(x[0],...,x[n-1]) A normal way to minimize such a funct could be the Levenberg-Marquardt algorithm. I would like to perform this minimization in c++…
Deepfreeze
  • 1,755
  • 1
  • 13
  • 18
18
votes
2 answers

Eigen convert dense matrix to sparse one

How to convert an Eigen::Matrix to an Eigen::SparseMatrix ? I'm looking for a better way instead of iterate through the dense matrix
Alberto
  • 2,881
  • 7
  • 35
  • 66
18
votes
4 answers

How to integrate a library that uses expression templates?

I would like to use the Eigen matrix library as the linear algebra engine in my program. Eigen uses expression templates to implement lazy evaluation and to simplify loops and calculations. For example: #include int main() { int size…
Martin Drozdik
  • 12,742
  • 22
  • 81
  • 146
17
votes
2 answers

write matrix to file in eigen?

I am trying to learn C++ with the Eigen library. int main(){ MatrixXf m = MatrixXf::Random(30,3); cout << "Here is the matrix m:\n" << m << endl; cout << "m" << endl << colm(m) << endl; return 0; } How can I export m to a text file…
user189035
  • 5,589
  • 13
  • 52
  • 112
17
votes
4 answers

Breaking change in C++20 or regression in clang-trunk/gcc-trunk when overloading equality comparison with non-Boolean return value?

The following code compiles fine with clang-trunk in c++17 mode but breaks in c++2a (upcoming c++20) mode: // Meta struct describing the result of a comparison struct Meta {}; struct Foo { Meta operator==(const Foo&) { return Meta{}; } Meta…
chtz
  • 17,329
  • 4
  • 26
  • 56