eigen

Map two-dimensional array to Eigen::Matrix

眉间皱痕 提交于 2019-12-05 15:47:21
I can't figure out if and how it's possible to map a two-dimensional double array to an Eigen::Matrix. Is it possible to map an array double d[][] which I receive as double** p to an Eigen::Matrix? While one-dimensinal arrays work fine, I wasn't able to map p to Eigen::Map<Eigen::Matrix<double, n, n>> . Is that possible and how could it be done? The size n is not really constant, but I could accept a hard coded size. I tried several versions, but none worked. I thought the following should work (assume the size n would be 4). Eigen::Map<Eigen::Matrix<double, 4, 4>> p_OUTPUT(&p[0][0]); The code

Best way of solving sparse linear systems in C++ - GPU Possible?

╄→гoц情女王★ 提交于 2019-12-05 15:06:11
I am currently working on a project where we need to solve |Ax - b|^2 . In this case, A is a very sparse matrix and A'A has at most 5 nonzero elements in each row. We are working with images and the dimension of A'A is NxN where N is the number of pixels. In this case N = 76800 . We plan to go to RGB and then the dimension will be 3Nx3N . In matlab solving (A'A)\(A'b) takes about 0.15 s, using doubles. I have now done some experimenting with Eigens sparse solvers. I have tried: SimplicialLLT SimplicialLDLT SparseQR ConjugateGradient and some different orderings. The by far best so far is

How to write a makefile for a C++ project which uses Eigen, the C++ template library for linear algebra?

雨燕双飞 提交于 2019-12-05 12:49:51
I'm making use of Eigen library which promises vectorization of matrix operations. I don't know how to use the files given in Eigen and write a makefile. The source files which make use of Eigen include files as listed below, these are not even header files (They are just some text files)- <Eigen/Core> <Eigen/Dense> <Eigen/Eigen> and so on. On Eigen's webpage, it's mentioned that, in order to use its functions I don't have to build the project, then how can I include these files in my makefile to build my project. My example main.c file looks like this. Can anyone show me how to write a

c++ check for nested typedef of a template parameter to get its scalar base type

删除回忆录丶 提交于 2019-12-05 10:46:34
Consider the exponential smoother template class below. This class is for smoothing/filtering sequential data exponentially (see update method). Elemtype might be an vector and Floattype is usually a scalar. E.g. ExponentialSmoother<Eigen::Vector2f, float> x(0.1, Vector2f(0.5, 0.5)); In this example the second template parameter Floattype could be avoided because Eigen's Matrix class contains a nested typedef to get the scalar base type: Vector2f::Scalar It is also reasonable to instantiate both Elemtype and Floatype as floats to smooth one dimensional data. In this case the second template

include of any Eigen 3.3.1 files in fresh Visual Studio project won't compile

大兔子大兔子 提交于 2019-12-05 09:25:48
问题 I created a fresh C++ (empty) project in VS2015, and then placed the Eigen 3.3.1 source code in an 'inc' folder in solution dir, such that the path to Matrix.h, for example, is inc/Eigen/Core/ . I have set this inc/ path as an additional include directory, and have also tried with inc/Eigen/ as another include directory in case the files had issues including each other, but this changed nothing. In main.cpp, I have the following: #include "Eigen/Core/Matrix.h" int main() { return 0; } This

Why does std::less<Eigen::VectorXd> fail to compile?

这一生的挚爱 提交于 2019-12-05 04:15:19
I implemented a comparison operator operator< for Eigen::VectorXd , and sometimes, I need to pass a compare function to another of my function, I am tired of wrapping the operator< into [](const VectorXd& v1, const VectorXd& v2)->bool{return v1 < v2} , so I think the std::less class would be useful, as, to my understanding, it can generate the lambda function as long as operator< is defined. However, I found that std::less<VectorXd> didn't work for me, for example, the below code works fine: #include "Eigen/Dense" #include <iostream> #include <functional> using namespace std; using namespace

Coefficient-wise custom functions in Eigen

倖福魔咒の 提交于 2019-12-05 03:02:03
I have a do_magic method which takes a double and adds 42 to it. I'd like to apply this method to each coefficient of a Eigen::Matrix or Eigen::Array (that means, I wouldn't mind if it's only possible with one of both types). Is this possible? Like this: Eigen::MatrixXd m(2, 2); m << 1,2,1,2; m.applyCoefficientWise(do_magic); // m is now 43, 44, 43, 44 You can use unaryExpr , though this returns a new view onto the matrix, rather than allowing you to modify the elements in place. Copying the example out of the documentation: double ramp(double x) { if (x > 0) return x; else return 0; } int

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

℡╲_俬逩灬. 提交于 2019-12-05 02:07:33
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} Since the current answer was not satisfactory for me, I googled a bit and I found this tutorial in the Eigen documentation. #include <Eigen/Dense> #include <iostream> using namespace std; int main() { Eigen::ArrayXf v(6); v << 1, 2, 3, 4, 5, 6; cout << "v.head(3) =" << endl << v.head(3) << endl << endl; cout << "v.tail<3>() = " << endl << v.tail<3>() << endl << endl; v.segment(1

Using Eigen in a C Project

老子叫甜甜 提交于 2019-12-05 00:31:53
问题 I am working on a C project I got from the Internet, and I'm trying to add some functions to the project that involve linear algebra. In my previous works in C++, I usually rely on Eigen for linear algebra. Is there a way to use Eigen for a C project? If yes, what should I do to make that work? (Simply adding Eigen header files is not enough since for example the standard C++ files do not get included automatically) 回答1: Eigen is a library which heavily uses C++ features which are not present

Boost::uBLAS vs Eigen

无人久伴 提交于 2019-12-05 00:13:12
I am used to Eigen for almost all my mathematical linear algebra work. Recently, I have discovered that Boost also provides a C++ template class library that provides Basic Linear Algebra Library ( Boost::uBLAS ). This got me wondering if I can get all my work based only on boost as it is already a major library for my code. A closer look at both didn't really got me a clearer distinction between them: Boost::uBLAS : uBLAS provides templated C++ classes for dense, unit and sparse vectors, dense, identity, triangular, banded, symmetric, hermitian and sparse matrices. Views into vectors and