eigen

Pointer vs Reference difference when passing Eigen objects as arguments

核能气质少年 提交于 2019-12-11 03:59:06
问题 If a have a function that takes a Eigen matrix as an argument, what would be the difference between: void foo(Eigen::MatrixXd& container){ for(i=0;i<container.rows();i++){ for(j=0;j<container.cols();j++){ container(i,j)=47; } } } and void foo(Eigen::MatrixXd* container){ for(i=0;i<container->rows();i++){ for(j=0;j<container->cols();j++){ container->coeffRef(i,j)=47; } } } In Eigen documentation, they only present the first method - does that mean that there are any advantages to that approach

How to “move” Eigen::VectorXd s

我们两清 提交于 2019-12-11 03:41:20
问题 A commenter in a recent post of mine told me I need to utilize c++11 move-semantics better to deal with a bottleneck in my code. Below is a simplified version of what needs to be fixed. #include <iostream> #include <Eigen/Dense> #include <vector> void makeCopy(std::vector<Eigen::VectorXd> &oldV){ int n = oldV.size(); std::vector<Eigen::VectorXd> mandatoryCopy; mandatoryCopy.resize(n); for(int i = 0; i < n; i++){ mandatoryCopy[i] = oldV[i]; } // swap the two oldV = mandatoryCopy; } int main

Eigen elements manipulation without loop

别来无恙 提交于 2019-12-11 03:35:28
问题 I want to check if the elements of my matrix are smaller than zero then I want to assign zero to them, in matlab it was done using this: ind = find(floatFrame < 0); floatFrame(ind) = 0; Is there any equivalent for Eigen matrices? 回答1: You can use the select function, which is similar to the ternary ?: operator in C. For your example: floatFrame = (floatFrame < 0).select(0, floatFrame) 来源: https://stackoverflow.com/questions/25766754/eigen-elements-manipulation-without-loop

C++: How to implement sparse matrices with very large indices?

强颜欢笑 提交于 2019-12-11 03:34:19
问题 I am trying to implement the dynamic programming presented in this article to solve the Shortest Hamiltonian Path problem. This solution requires storing values in a 2d array called DP of size n x 2^n where n is the number of nodes of the graph. My graph has more than 100 nodes, but it is very sparse, so most of the elements of the matrix DP is +infinity. Therefore I can store it using a sparse matrix library (and see zero elements as +infinity). For example, using Eigen: Eigen::SparseMatrix

Eigen & OpenMP : No parallelisation due to false sharing and thread overhead

心不动则不痛 提交于 2019-12-11 03:11:09
问题 System Specification: Intel Xeon E7-v3 Processor(4 sockets, 16 cores/sockets, 2 threads/core) Use of Eigen family and C++ Following is serial implementation of code snippet: Eigen::VectorXd get_Row(const int j, const int nColStart, const int nCols) { Eigen::VectorXd row(nCols); for (int k=0; k<nCols; ++k) { row(k) = get_Matrix_Entry(j,k+nColStart); } } double get_Matrix_Entry(int x , int y){ return exp(-(x-y)*(x-y)); } I need to parallelise the get_Row part as nCols can be as large as 10^6,

Precision loss when solving nonlinear equations with long integer parameters by mpreal.h

这一生的挚爱 提交于 2019-12-11 02:31:32
问题 I have a numerical computation problem which requires solving nonlinear equations (with long integers) in multiple precision. I tried an MPFR C++ wrapper from this link by Pavel: mpfr C++ wrapper by Pavel The wrapper can be downloaded here: mpfrc++-3.5.6.zip However, there is precision loss in the solution when handling very long integers (equations with small integers worked well). I tried three options as in the sample code below: to use the code immediately does not work with "constant

How to compute basis of nullspace with Eigen library?

元气小坏坏 提交于 2019-12-11 01:13:57
问题 How to compute basis of nullspace of a matrix with Eigen library? I tried to find explicit function name to compute null basis and also, as a workaround, to find method for computing rref of a matrix (as we're able to get null basis from rref). But I couldn't find any relevant functions names. I think there's must be solution for this, but I know not much about Eigen library and Eigen's code also very difficult to me to understand. Please suggest me the solution for this problem. 回答1: You can

eigen::vectorXf to MatriXf map

纵然是瞬间 提交于 2019-12-11 00:57:24
问题 In eigen c++, how do you map a vectorXf to a matrixXf (of appropriate dimensions) (there is good docs on how to do it for external objects so i know we can do: MatrixXf x_cen=Map<MatrixXf>(*x,*n,*p); but what if x is a VectorXf ? 回答1: You can use the .data() member function followed by Map: VectorXf vec(rows*cols); vec = ...; Map<MatrixXf> vec_view_as_a_matrix(vec.data(), rows, cols); Then you can use vec_view_as_a_matrix just like any Eigen objects, modifications to vec_view_as_a_matrix will

Mixing Scalar Types in Eigen

拈花ヽ惹草 提交于 2019-12-11 00:45:22
问题 #include <iostream> #include <Eigen/Core> namespace Eigen { // float op double -> double template <typename BinaryOp> struct ScalarBinaryOpTraits<float, double, BinaryOp> { enum { Defined = 1 }; typedef double ReturnType; }; // double op float -> double template <typename BinaryOp> struct ScalarBinaryOpTraits<double, float, BinaryOp> { enum { Defined = 1 }; typedef double ReturnType; }; } int main() { Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic> m1(2, 2); m1 << 1, 2, 3, 4; Eigen:

Thread-safe writing to Eigen::MatrixXd by row

ぐ巨炮叔叔 提交于 2019-12-10 22:46:43
问题 My question is very simple, and hopefully has a nice answer too: When I have a constructed Eigen::MatrixXd matrix, can I use multiple threads to populate rows in the matrix at the same time (if I can assure that no rows are being concurrently written), or must I create temporary row objects in each thread, and then copy (ugh...) them into the matrix as a reduce operation? 回答1: While it may be thread safe in terms of not writing to the same address from different threads, because Eigen: