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

Eigen boolean array slicing

In MATLAB it is common to slice out values that satisfy some condition from a matrix/array (called logical indexing). vec = [1 2 3 4 5]; condition = vec > 3; vec(condition) = 3; How do I do this in Eigen? So far I have: Eigen::Matrix
ejang
  • 3,982
  • 8
  • 44
  • 70
10
votes
2 answers

Installing the Eigen library in Visual C++ 2010

How can I install the Eigen library in Visual C++ 2010? I downloaded the library from eigen.tuxfamily But I do not know how can install it on my Visual C++. I want to run a program I downloaded and it has the following: #include using…
crystalclear
  • 129
  • 1
  • 3
  • 11
10
votes
2 answers

Eigen MatrixXd push back in c++

Eigen is a well known matrix Library in c++. I am having trouble finding an in built function to simply push an item on to the end of a matrix. Currently I know that it can be done like this: Eigen::MatrixXd matrix(10, 3); long int count = 0; long…
Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175
10
votes
1 answer

Calculate Cholesky Decomposition using Eigen

I'm trying to calculate the Cholesky factor of a matrix in C++ (for a given matrix P find L such that LL^T=P). My objective is NOT to solve a linear system P*x=b, as such matrix decompositions are often used for, but to actually obtain the matrix…
Clark
  • 890
  • 8
  • 20
9
votes
2 answers

Using Eigen Library with OpenCV 2.3.1

I have trouble in using Eigen3 Library along with OpenCV application in C++. I have installed Eigen3 library on my Ubuntu using the following command: sudo apt-get install libeigen3-dev I am able to compile and use sample Eigen3 applications…
garak
  • 4,713
  • 9
  • 39
  • 56
9
votes
0 answers

std::sort with struct containing Eigen datatype causes segfault

I have the following issue when compiling in release mode using MSVC 19.31.31106.2 (and C++17, as far as I understand the eigen page, alignment should be not an issue anymore) that I get a segfault from within of std::sort. The official Eigen 3.4…
Anima
  • 339
  • 2
  • 16
9
votes
3 answers

Function that accepts both Eigen Dense and Sparse Matrices

I'm working on adding Sparse matrix support to an open source math library and would like to not have duplicated functions for both Dense and Sparse matrix types. The below example shows an add function. A working example with two functions, then…
Steve Bronder
  • 926
  • 11
  • 17
9
votes
3 answers

How to build a simple C++ demo using Eigen with Bazel?

How can I use Eigen within a C++ project that is built using Bazel (version 0.25.2)? I like to fetch the Eigen dependency using http_archive or git_repository. I've tried the following: main.cpp #include #include using…
Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
9
votes
1 answer

Use the Eigen library with cppyy

I've been successfully using cppyy for automatic python bindings for a C++ project I'm working on. I recently included the Eigen library, but I'm having trouble using this together with cppyy. Does anyone have any experience doing this, or know how…
Bendik
  • 1,097
  • 1
  • 8
  • 27
9
votes
2 answers

Performance: Matlab vs C++ Matrix vector multiplication

Preamble Some time ago I asked a question about performance of Matlab vs Python (Performance: Matlab vs Python). I was surprised that Matlab is faster than Python, especially in meshgrid. In the discussion of that question, it was pointed to me that…
Fahd Siddiqui
  • 273
  • 3
  • 9
9
votes
2 answers

Typedef in traits vs typedef in class

I'm looking through the Eigen source code for educational purposes. I've noticed that for each concrete class template X in the hierarchy, there is an internal::traits defined. A typical example can be found in Matrix.h: namespace internal…
Moos Hueting
  • 650
  • 4
  • 14
9
votes
2 answers

clang-format for Eigen matrix initialization

To inialize for example Eigen::Matrix3i we can use syntax: Eigen::Matrix3i T; T << 1, 0, 0, 0, 2, 0, 0, 0, 3; However, when using clang-format (3.6 in my case) with Google style this nice initialization turns into: Eigen::Matrix3i T; T <<…
niosus
  • 738
  • 8
  • 22
9
votes
1 answer

Assigning a vector to a matrix column in Eigen

This question was asked in haste. The error in my original program, was not the typo in the code that is displayed here. The error was that in my program v was not getting populated due to some conditions. The more useful takeaway from this thread…
Hari
  • 1,561
  • 4
  • 17
  • 26
9
votes
4 answers

Eigen matrix library filling a matrix with random float values in a given range

The setRandom function in the Eigen matrix library fills a given matrix with random numbers in the range [-1,1]. How can I extend this to generate numbers within any given range? I require floating point numbers and I am okay with pseudo-randomness.…
pincir
  • 345
  • 1
  • 3
  • 7
9
votes
3 answers

Eigen - Check if matrix is Positive (Semi-)Definite

I'm implementing a spectral clustering algorithm and I have to ensure that a matrix (laplacian) is positive semi-definite. A check if the matrix is positive definite (PD) is enough, since the "semi-" part can be seen in the eigenvalues. The matrix…
dim_tz
  • 1,451
  • 5
  • 20
  • 37