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
14
votes
4 answers

Combining a linear algebra library with Boost::Units

I'm doing a good amount of scientific programming and made very good experiences with both Boost.Units, which provides compile-time dimensional analysis for quantities (i.e. tags quantities with units and thereby catches many errors with classical…
thiton
  • 35,651
  • 4
  • 70
  • 100
14
votes
2 answers

Multiplication of each matrix column by each vector element using Eigen C++ Library

I need to multiply each matrix column by each vector element using Eigen C++ library. I tried colwise without success. Sample data: Eigen::Matrix3Xf A(3,2); //3x2 A << 1 2, 2 2, 3 5; Eigen::Vector3f V = Eigen::Vector3f(2, 3); //Expected…
SergioABP
  • 335
  • 1
  • 3
  • 8
14
votes
2 answers

Speeding up the L1 distance between all pairs in a ground set

I have a matrix NxM (usually 10k X 10k elements) describing a ground set. Each line represents an object and each column an specific feature. For example, in the matrix f1 f2 f3 x1 0 4 -1 x2 1 0 5 x3 4 0 0 x4 0 1 0 the object x1 has…
an_drade
  • 664
  • 1
  • 5
  • 15
14
votes
3 answers

Compare Eigen matrices in Google Test or Google Mock

I was wondering if there is a good way to test two Eigen matrices for approximate equality using Google Test, or Google Mock. Take the following test-case as a simplified example: I am multiplying two complex valued matrices A, and B, and expect a…
Lemming
  • 4,085
  • 3
  • 23
  • 36
14
votes
3 answers

Eigen, how to access the underlying array of a MatrixBase

I need to access the array that contains the data of a MatrixBase Eigen matrix. The Eigen library has the data() method which returns a pointer to an array, however it is only accessible from a Matrix type. The MatrixBase doesn't have a similar…
XapaJIaMnu
  • 1,408
  • 3
  • 12
  • 28
14
votes
4 answers

Eigen Convert Matrix to Vector

In MATLAB, the line below converts a matrix to a vector. It flattens the matrix column by column into a vector. myvar(:) How do I do that with Eigen? The solution should work for any dimension of matrix. MatrixXd A(3,2); VectorXd B(6); A <<…
user3501255
  • 141
  • 1
  • 1
  • 4
14
votes
2 answers

Using Boost::odeint with Eigen::Matrix as state vector

I'm trying to utilize the ODE integration capabilities of Boost using the Matrix class from Eigen 3 as my state vector, but I'm running into problems deep into Boost that I don't understand how to address. A minimal example of what I'm trying to…
Tomas Aschan
  • 58,548
  • 56
  • 243
  • 402
14
votes
3 answers

sort eigen vectorXf in ascending order

I'm trying to sort an Eigen VectorXf x in ascending order. This sorts it in descending order: std::sort(x.data(),x.data()+x.size()); and this doesn't work: bool myfunction (int i,int j) { return (i
user189035
  • 5,589
  • 13
  • 52
  • 112
14
votes
7 answers

How to remove a certain row or column while using Eigen Library c++

I am using Eigen library for my project. I am searching how to remove a certain row or column from the given matrix in Eigen. I am not successful. MatrixXd A = X1 X2 X3 X4 Y1 Y2 Y3 Y4 Z1 Z2 Z3 Z4 A1 A2 A3…
wholock
  • 177
  • 1
  • 1
  • 8
14
votes
2 answers

find rowwise maxCoeff and Index of maxCoeff in Eigen

I want to find the maximum values and indices by row of a matrix. I based this on an example on the eigen website (example 7). #include #include using namespace std; using namespace Eigen; int main() { MatrixXf…
Florian Oswald
  • 5,054
  • 5
  • 30
  • 38
13
votes
2 answers

Difference between norm, normalize and normalized in eigen

Suppose I have a MatrixXcf called A. I want to replace elements of every column by normalized one relative to the corresponding column. I've written following code but it's not true! for (int i = 0; i < A.cols(); i++) A.col(i).real.array() =…
Saeid
  • 508
  • 1
  • 4
  • 20
13
votes
3 answers

eigen: Subtracting a scalar from a vector

I am having an error when using the Eigen library and all I am trying to do is subtract a scalar from an Eigen::VectorXf. So, my code is something as follows: #define VECTOR_TYPE Eigen::VectorXf #define MATRIX_TYPE Eigen::MatrixXf // myMat is of…
Luca
  • 10,458
  • 24
  • 107
  • 234
13
votes
3 answers

How to write a matrix matrix product that can compete with Eigen?

Below is the C++ implementation comparing the time taken by Eigen and For Loop to perform matrix-matrix products. The For loop has been optimised to minimise cache misses. The for loop is faster than Eigen initially but then eventually becomes…
Adhvaitha
  • 251
  • 2
  • 9
13
votes
4 answers

MatrixXf::Random always returning same matrices

I just played around with Eigen a bit and noticed that MatrixXf::Random(3,3) always returns the same matrices, first one is always this for example: 0.680375 0.59688 -0.329554 -0.211234 0.823295 0.536459 0.566198 -0.604897 -0.444451 Is that…
wlfbck
  • 554
  • 8
  • 22
12
votes
2 answers

Sparse matrix class with parameterizable "zero"

I am doing some computations on a sparse matrix of floats in the log domain, so the "empty" entries are actually -Inf (using -FLT_MAX). I'm using a custom sparse matrix class right now but I am eager to swap in an off-the-shelf replacement. This is…
David Alexander
  • 358
  • 1
  • 12