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

Eigen::Tensor, how to access matrix from Tensor

I have the following Eigen Tensor: Eigen::Tensor m(3,10,10); I want to access the 1st matrix. In numpy I would do it as such m(0,:,:) How would I do this in Eigen
raaj
  • 2,869
  • 4
  • 38
  • 58
5
votes
1 answer

Why does returning an element of a copied Matrix3d result in incorrect output when using Clang 3.9?

Compiling the following example with -O2 on Clang 3.9 results in the reproFunction returning garbage (1.9038e+185) when called in main: Code double reproFunction(const Eigen::Matrix3d& R_in) { const Eigen::Matrix3d R = R_in; Eigen::Matrix3d Q =…
5
votes
3 answers

Unclear return type for function taking eigen types as parameters

I'm trying to use the Eigen3 library in a scientific program but I'm struggling to make some simple functions and member functions. For example, I'm not certain what kind of return type should I choose for something like the following: template…
German Capuano
  • 5,183
  • 6
  • 23
  • 35
5
votes
1 answer

Add Matrix and DiagonalMatrix in Eigen3

I want to add elements to the diagonal of a Eigen::MatrixXd object with the Eigen3 library (version 3.3.2). Both for optimisation and being able to use constness, I want to do this by adding a diagonal matrix to the original, like this const…
andybuckley
  • 1,114
  • 2
  • 11
  • 24
5
votes
1 answer

Writing new Eigen expression

I am trying to write new Eigen expression following latest documentation https://eigen.tuxfamily.org/dox-devel/TopicNewExpressionType.html. Basically, what I want is part of reshape functionality that is still absent in Eigen. So chop_expr(Eigen…
5
votes
1 answer

Using Eigen types with STL containers and std::vector

It looks like using Eigen types with STL containers is very messy and requires special attention to alignment issues. My problem is that I'm planning to create complex class hierarchy with dozens of classes that might include one or more Eigen types…
Shital Shah
  • 63,284
  • 17
  • 238
  • 185
5
votes
0 answers

Eigen 3.3 compilation error with AVX enabled

I have cloned Eigen today (hg clone https://bitbucket.org/eigen/eigen/) to get Eigen 3.3. I fail to use the AVX extensions. When adding the flags -march=native or -mavx, I get the following output on VERBOSE=1 make check (my own thoughts below) [ …
FelEnd
  • 868
  • 8
  • 12
5
votes
2 answers

Replacing all negative elements with zero eigen3 c++

As said I want to replace all < 0 elements in a eigen3 matrix in C++ with zero in most efficient manner. I check that there are negative elements using: (result.array() < 0).any()
Saurabh7
  • 710
  • 1
  • 5
  • 18
5
votes
1 answer

Using Ref<> for generic Eigen matrices in a templated function

Here is a function I would like to write: template using Vec = Eigen::Matrix; template void foo(Eigen::Ref> p) { // fill p with things } void main() { Vec v(2); …
jbcolli2
  • 113
  • 1
  • 4
5
votes
1 answer

Eigen 2D cross product

Can Eigen do a 2D cross product? I was trying to replace this code: Eigen::Vector2f a, b; float result = a.x()*b.y() - b.x()*a.y(); With this: Eigen::Vector2f a, b; float result = a.cross(b); However, this gives me the following error: error…
Jan Rüegg
  • 9,587
  • 8
  • 63
  • 105
5
votes
2 answers

How to get rank of a matrix in Eigen library?

How to get rank of a matrix in eigen?
abdolahS
  • 663
  • 12
  • 35
5
votes
2 answers

Sparse eigenvalues using eigen3/sparse

Is there an distinct and effective way of finding eigenvalues and eigenvectors of a real, symmetrical, very large, let's say 10000x10000, sparse matrix in Eigen3? There is an eigenvalue solver for dense matrices but that doesn't make use of the…
Philipp
  • 159
  • 1
  • 9
5
votes
1 answer

How to read an eigen matrix from a file?

I know I can write an eigen matrix to a file like this: std::ofstream file("test.txt"); if (file.is_open()) { Eigen::Matrix m; m << 1, 2, 3, 4, 5; file << m; } Whats the easiest way to read it…
Jan Rüegg
  • 9,587
  • 8
  • 63
  • 105
5
votes
1 answer

Eigen: Efficient implementation of matrix from C++ array

Would it be possible to implement a class that receives a C-style pointer as a template argument and somehow resolves into a static Eigen matrix but using the memory provided? Say a declaration would look something like: EIGEN_ALIGN16 double…
Alejandro
  • 1,064
  • 1
  • 8
  • 22
5
votes
1 answer

How to convert from Eigen::Affine3f to Eigen::Matrix4f

I have two questions. Does the rigid transformation represented in Eigen::Affine3f and Eigen::Matrix4f will be the same ? How can we convert from Eigen::Affine3f to Eigen::Matrix4f and vice versa ? Thanks for your help!
Sai
  • 377
  • 2
  • 7
  • 18