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
6
votes
3 answers

Removing zero rows from a Matrix (elegant way)

I have a matrix with some zero rows. I would like to remove the zero rows. The matrix is Nx3. What I've done is simple. I create std::vector in which every three elements represent a row then I convert it to Eigen::MatrixXd. Is there an elegant way…
CroCo
  • 5,531
  • 9
  • 56
  • 88
6
votes
2 answers

cannot convert from 'const Eigen::GeneralProduct' to 'double'

I keep getting this error every time I compute this line double k = b.transpose()*Z.inverse()*b; where Eigen::MatrixXd Z(3,3), b(3,1);. I've tried casting but no luck. Any suggestions?
CroCo
  • 5,531
  • 9
  • 56
  • 88
6
votes
1 answer

How to compile a C++ program using eigen without specifying the -I flag?

I have the following test program using eigen: #include #include using namespace std; using Eigen::MatrixXd; int main() { MatrixXd m(2, 2); m(0, 0) = 3; m(1, 0) = 2.5; m(0, 1) = -1; m(1, 1) = m(1, 0) + m(0, 1); …
Paul Baltescu
  • 2,095
  • 4
  • 25
  • 30
6
votes
2 answers

How to resize a Vector in Eigen3

I'm wrapping two Eigen3 vectors in a templated LineSegment class. You might use it like this: typedef LineSegment LineSegment2d; typedef LineSegment LineSegment3d; typedef LineSegment LineSegment3i; It contains a…
Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
5
votes
3 answers

eigen3 with libfmt >= 9.0

I used to be able to pass Eigen3 arrays/matrices to spdlog, which internally uses libfmt. Starting with libfmt 9.0.0, these types are no longer formatted by libfmt without further code. Custom types are supported in fmt by specializing…
eudoxos
  • 18,545
  • 10
  • 61
  • 110
5
votes
1 answer

efficiently updating inplace certain blocks of a large sparse matrix in Eigen?

Suppose that I have a large sparse matrix with the following pattern: the number of nonzeros per column and their locations are fixed only matrix block A and B will change and the rest of the matrix stays static; (blocks A and B themselves are…
wuyang3
  • 55
  • 7
5
votes
2 answers

Is std::ranges::size supposed to return an unsigned integer?

Here it is written that std::ranges::size should return an unsigned integer. However, when I use it on an Eigen vector (with Eigen 3.4) the following compiles: Eigen::VectorXd x; static_assert(std::same_as
fdev
  • 127
  • 12
5
votes
2 answers

Adding scalar to Eigen matrix (vector)

I just started using Eigen library and can't understand how to add a scalar value to all matrix's members? Let's suppose that I have a matrix: Eigen::Matrix3Xf mtx = Eigen::Matrix3Xf::Ones(3,4); mtx = mtx + 1; // main.cxx:104:13: error: invalid…
Kerim
  • 171
  • 3
  • 10
5
votes
1 answer

How can I debug memory alignment problems (AVX) when they don't reproduce in a minimal context?

I run into the following problem all the time recently: I have a large-ish codebase which uses Eigen and PCL (which also uses Eigen) I need to use the almost current Eigen master branch and can't use a stable release due to a dependency requiring…
oarfish
  • 4,116
  • 4
  • 37
  • 66
5
votes
2 answers

How do I ensure a consistent build environment across machines in for C++ in Visual Studio 2015?

I have some C++ code in visual studio 2015 that compiles and works fine on my machine, but not on my team mate's. We have the exact same code base, and the exact same versions of all the same libraries, but on his machine, Visual Studio fails to…
Hexx i.m
  • 91
  • 5
5
votes
1 answer

How to handle mixing of different libraries (eg. stl and eigen3) that use different types for indices (size_t, int, ...)

I have following problem. I have some code that uses Eigen3. Eigen3 uses int or long int for indices. At some points in the code I have to store values from the eigen-arrays in a std::vector. Here is some example: std::vector…
goaran
  • 353
  • 2
  • 11
5
votes
2 answers

Should the Eigen-unsupported modules be avoided?

The popular linear algebra library Eigen comes with a long list of so-called "unsupported" modules, for example modules for FFT, numerical differentiation or Euler angles. In the Eigen documentation, it is clearly stated: These modules are…
Mark G
  • 55
  • 7
5
votes
0 answers

Why is calculating each matrix column faster than using matrix product?

#include #include #include using namespace std; using namespace Eigen; void slow(const Matrix, 20, 1> &a, const Matrix &b, Matrix, 20, 2> &out) { …
tboerstad
  • 51
  • 4
5
votes
1 answer

Eigen: Return a reference to a block of a matrix with compile-time dimension checks

What I am asking is a generalization of this question. Specifically, I would like to make a C++ Eigen wrapper around a legacy C and Fortran library, which uses a 2D data-structure: [ x[0,0] ... x[0,w-1] ] [ u[0,0] ... u[0,w-1] ] [ …
bremen_matt
  • 6,902
  • 7
  • 42
  • 90
5
votes
1 answer

Eigen unsupported Tensor to Eigen matrix

I get a Eigen::Tensor after some operations on a Tensor with more dimensions. Is there an easy way to create a Eigen::MatrixXcf from this Tensor-object or do I have to copy the values manually?
user2329125