eigen

eigen 3.3 SparseMatrix<bool> operations

…衆ロ難τιáo~ 提交于 2019-12-25 08:13:25
问题 I would like to perform operations using Eigen::SparseMatrix<bool> without having to loop the matrices myself. This used to be possible in Eigen 3.2 but that code no longer compiles in version 3.3. For instance, the following code worked fine in 3.2: Eigen::SparseMatrix<bool> a(3,3), b(3,3), c(3,3); a = b + c; Is there an easy/short way of doing "and" and "or" operations in Eigen 3.3 without writing loops? 回答1: To be consistent with c++ standard behavior, adding boolean matrices now returns

how to map a Eigen::Matrix to std::vector<Eigen::vector>?

谁说胖子不能爱 提交于 2019-12-25 03:25:06
问题 E.g., if I have an Eigen::MatrixXd of size 10 columns and 3 rows, how can I alias that to a std::vector of 10 elements of Eigen::Vector3d ? when I say alias I mean using the same memory block without copying. I know that I can do the reversed mapping by something like: std::vector<Vector3d> v(10); ... Map<Matrix<double,3,Dynamic> > m(v.data().data(), 3, 10); but reversely, if I have an Eigen::Matrix, I tried to convert it to a vector of Eigen::vector but the following code line failed

Very slow filling of sparse matrix and no memory gain in Eigen

夙愿已清 提交于 2019-12-25 02:59:52
问题 I am trying to implement an example that is given in the Eigen tutorial as pseudocode. As far as I understand, it illustrates the recommended method for filling a sparse matrix, provided that the number of non zero entries per column is known. The pseudocode is found under the Header " Filling a sparse Matrix "and is written as follows: 1: SparseMatrix<double> mat(rows,cols); // default is column major 2: mat.reserve(VectorXi::Constant(cols,6)); 3: for each i,j such that v_ij != 0 4: mat

How to convert a vtkDoubleArray to an Eigen::matrix

ぐ巨炮叔叔 提交于 2019-12-25 02:32:13
问题 I've found the Eigen::Map class for converting a raw array to an Eigen class (and some useful snippets here https://stackoverflow.com/a/12007784/1136458 ) Is there any Eigen or vtk class to convert a vtk array to an Eigen class (and back)? What I am trying right now is: convert vtkDoubleArray to std::vector of std::vector (as in How to get the the values of a vtkDoubleArray in a std::vector ) using map to have a matrixxd Eigen::MatrixXd eig_arr; eig_arr = Eigen::Map<Eigen::MatrixXd> (cpp

Possible to get type of Eigen::MatrixBase<T> &

落爺英雄遲暮 提交于 2019-12-25 02:11:38
问题 having a Eigen::MatrixBase & data, are there any way to get if it is a float or double matrix? I need to create an new complex matrix of the same size and type as the MatrixBase. If it is MatrixXf then i need to create MatrixXcf, and if MatrixXd i need MatrixXcD.? template <typename A> int dowork(const Eigen::MatrixBase<A>& data) 回答1: That's pretty simple, just use the A::RealScalar typedef to build your complex type: template <typename A> int dowork(const Eigen::MatrixBase<A>& data) {

Passing Eigen::Map<ArrayXd> to a function expecting ArrayXd&

喜夏-厌秋 提交于 2019-12-25 02:03:26
问题 Some of my Eigen C++ methods need to be callable from plain C++, therefore I want to provide overloaded functions that accept c arrays and map them to ArrayXd using Eigen::Map. The code I currently have looks like this: bool Dmp::executeStep(double* position, double* velocity, double* acceleration, const int len) { Map<ArrayXd> posMap(position, len); Map<ArrayXd> velMap(velocity, len); Map<ArrayXd> accMap(acceleration, len); return executeStep(posMap, velMap, accMap); } bool Dmp::executeStep

Should Eigen dense matrix * dense vector multiplication be 7 times slower than GSL?

给你一囗甜甜゛ 提交于 2019-12-24 13:37:36
问题 The answer to this question of mine made me expect that (for matrices with 1/4 of non-vanishing entries) in Eigen the product Dense Matrix * Dense Vector should outperform Sparse Matrix*Dense Vector. Not only do I see the opposite, but also both are outperformed by GSL by a factor of 7 and 4 respectively. Am I using Eigen incorrectly? Am I timing carelessly? I am very startled. My compile options read: ludi@ludi-M17xR4:~/Desktop/tests$ g++ -o eigenfill.x eigenfill.cc -L/usr/local/lib -lgsl

How to calculate the transpose of external, row major matrix in eigen

人走茶凉 提交于 2019-12-24 08:38:33
问题 Having an external, row-major matrix A(m x n), and having already created the external, row-major matrix B(n x m) for the result, for getting the transpose I do: Map<MatrixXd,RowMajor> (B,n,m) = Map<MatrixXd,RowMajor> (A,m,n).transpose() where A and B point to the data buffers. This works fine in the default case of col-major matrices, but for row-major matrices the result is correct only for m == n, for m <> n the numbers are skewed up. Am I misinterpreting how to map row-major external data

How can I solve linear equation AX=b for sparse matrix

拈花ヽ惹草 提交于 2019-12-24 08:00:47
问题 I have sparse matrix A(120,000*120,000) and a vector b(120,000) and I would like to solve the linear system AX=b using Eigen library. I tried to follow the documentation but I always have an error. I also tried change the matrix to dense and solve the system Eigen::MatrixXd H(N,N); HH =Eigen:: MatrixXd(A); Eigen::ColPivHouseholderQR<Eigen::MatrixXd> dec(H); Eigen::VectorXd RR = dec.solve(b); but I got a memory error. Please help me find the way to solve this problem. 回答1: For sparse systems,

How do I convert R data types into an Eigen::Matrix<double,dim,1> in this situation?

狂风中的少年 提交于 2019-12-24 07:38:18
问题 Why is this reporting error: no matching function for call to ‘as<Eigen::Matrix<double, 400, 1, 0, 400, 1> >(int)’ and cannot convert ‘3’ (type ‘int’) to type ‘SEXP {aka SEXPREC*}’ ? There appears to be a similar problem here. In a previous question, I asked about registering plugins so that I could use a c++ template library from within R . Continuing on with that example, I still cannot get this small example to work. The plugin issue has been figured out, but now Rcpp::as won't allow me to