Questions tagged [eigen3]

Eigen is a C++ template library for linear algebra: matrices, vectors, numerical solvers, and related algorithms.

Eigen is a C++ template library for linear algebra: matrices, vectors, numerical solvers, and related algorithms. Homepage: http://eigen.tuxfamily.org

Please use eigen3 tag specifically for questions related to version 3 of the library.

1014 questions
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
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
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
16
votes
2 answers

How to get the number of rows and columns of an Eigen::MatrixXd?

I am trying to traverse Eigen::MatrixXd matrix. However, there does not seem to be a function that returns the columns size nor the row size. Does anybody have an idea on how to do this?
Tom Oconnor
  • 393
  • 2
  • 5
  • 14
16
votes
6 answers

How to extract a subvector (of an Eigen::Vector) from a vector of indices in Eigen?

Suppose I have Eigen::VectorXd x; //{1,2,3,4,5,6,7,8} and Eigen::VectorXd ind_vec; //{0,2,4,5} Is there a way an easy way to extract the ind_vec elements of x? Something like: x.extract(ind_vec) returning {1, 3, 5, 6}
user1526533
  • 441
  • 1
  • 5
  • 9
15
votes
1 answer

Why are initializer lists not available when changing the allocator of std::vector?

In my project I changed the used point type from Eigen::Vector2f to Eigen::Vector2d and ran into the alignment problem. Here is a simplified version of the code: #include #include int main() { std::vector
mic
  • 821
  • 6
  • 18
13
votes
2 answers

Unable to find Eigen3 with CMake

I am kind of desperate: For my studies I need to work with Eigen and CMake. I'm able to use Eigen if I copy the whole library in the directories where my compiler looks by default but as soon as I try to find it via find_package(Eigen3 REQUIRED) I…
Cryoris
  • 416
  • 1
  • 4
  • 12
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 efficiently extract real/imaginary parts of complex matrix in Eigen3 library?

I have some complex, dense vectors/matrices in the Eigen3 library, and I want to extract the real and imaginary parts into separate arrays. In Matlab, I could do something like cplxFoo = [1, 1i; -1i -1] re = real(cplxFoo) im = imag(cplxFoo) which…
Nicu Stiurca
  • 8,747
  • 8
  • 40
  • 48
11
votes
2 answers

Error while compiling eigen program: error: 'seq' is not a member of 'Eigen'

I am trying to index a matrix in indexes which follow an arithmetic sequence. According to the Eigen tutorial on the official website, I should use Eigen::seq(firstVal, lastVal, step) to generate this sequence. After calling this the error, as…
AldiT
  • 126
  • 1
  • 9
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
2 answers

Using Eigen::Map as function argument of type Eigen::MatrixXd

In short, the question is how to pass a Eigen::Map object to a function which expects a Eigen::MatrixXd object. Longer story: I have this C++ function declaration void npMatrix(const Eigen::MatrixXd &data, Eigen::MatrixXd…
ReedWood
  • 135
  • 1
  • 1
  • 9
10
votes
2 answers

How to fix 'non-type template argument is not a constant expression' in eigen3?

I am still new to the Eigen library and C++. I am testing some code and I do not get why this #include #include using namespace std; int main() { int a = 2; const int SIZE_ = a; Eigen::Matrix
Léo Buchenel
  • 101
  • 1
  • 3
10
votes
3 answers

Is Eigen slow at multiplying small matrices?

I wrote a function that multiplies Eigen matrices of dimension 10x10 together. Then I wrote a naive multiply function CustomMultiply which was surprisingly 2x faster than Eigen's implementation. I tried a couple of different compilation flags like…
Mark Liu
  • 109
  • 1
  • 6
10
votes
5 answers

How can I calculate inverse of sparse matrix in Eigen library

I have a question about Eigen library in C++. Actually, I want to calculate inverse matrix of sparse matrix. When I used Dense matrix in Eigen, I can use .inverse() operation to calculate inverse of dense matrix. But in Sparse matrix, I cannot…
kujungmul
  • 115
  • 1
  • 1
  • 7
1
2 3
67 68