eigen

Removing zero columns or rows using eigen

老子叫甜甜 提交于 2019-12-10 19:15:11
问题 I was wondering if there is a more efficient way to remove columns or rows that are all zero elements. I am sure there is using the functions in the eigen library but I do not know how. Right now I am doing it like so, with the idea of the while loop being used in case there are multiple rows/columns that sum to zero I dont want to exceed range limits or pass any zero rows. void removeZeroRows() { int16_t index = 0; int16_t num_rows = rows(); while (index < num_rows) { double sum = row(index)

Zero-copy construction of an Eigen SparseMatrix

回眸只為那壹抹淺笑 提交于 2019-12-10 19:05:31
问题 I have the following problem: I have an Eigen::SparseMatrix I need to send over the network, and my network library only supports sending arrays of primitive types. I can retrieve the pointers to the backing arrays of my SparseMatrix by doing something like (here's the backing object's code): // Get pointers to the indices and values, send data over the network int num_items = sparse_matrix.nonZeros() auto values_ptr = sparse_matrix.data().valuePtr() auto index_ptr = sparse_matrix.data()

Eigen class to take mean of each row of matrix (compute Centroid of the column vectors)

天涯浪子 提交于 2019-12-10 17:53:28
问题 I am really new with C++ but here is what I am trying to do. I have a 4 by 3 matrix: 100 109.523 119.096 100 89.7169 76.256 100 96.0822 103.246 100 101.084 85.0639 I want to take calculate the mean of each row and store it in some vector. I am using the Eigen library. I cannot think of anything to do this efficiently. Here is my code thus far: MatrixXd SS(N,n+1); MatrixXd Z = generateGaussianNoise(N,n); for(int i = 0; i < N; i++){ SS(i,0) = S0; for(int j = 1; j <= n; j++){ SS(i,j) = SS(i,j-1)

Eigen: Divide each row by last row

只谈情不闲聊 提交于 2019-12-10 17:45:53
问题 I can't quite figure out the syntax for this when using Eigen's rowwise operations... I have an Eigen matrix, and I want to divide each row by the last row. So if we started with a matrix r = [ 0, 1 2, 3 4, 5 ] then after this transform, I want to have r = [ 0, .2 .5, .6 1, 1 ] Preferably the operation would happen in place, overwriting r . Furthermore, I will not be using the values in the last row, so it doesn't matter if the last row is actually 1's after the transform. Here are some

Eigen with -O3 warning: argument 1 value ‘X’ exceeds maximum object size Y

≡放荡痞女 提交于 2019-12-10 17:14:50
问题 What happens When I try to add an Eigen::Vector3f into an std::vector following the tutorial on Eigen website like this: #include <Eigen/Core> #include <Eigen/StdVector> #include <iostream> template <class EigenT> using EigenStdVector = std::vector<EigenT, Eigen::aligned_allocator<EigenT>>; int main() { EigenStdVector<Eigen::Vector3f> vec; vec.emplace_back(1.0f, 1.0f, 1.0f); std::cerr << vec.back().transpose() << std::endl; return 0; } I get the following warning: In file included from /usr

Set coefficients of an Eigen::Matrix according an arbitrary distribution

家住魔仙堡 提交于 2019-12-10 17:01:33
问题 Eigen::Matrix has a setRandom() method which will set all coefficients of the matrix to random values. However, is there a built in way to set all the matrix coefficients to random values while specifying the distribution to use. Is there a way to achieve something like the following: Eigen::Matrix3f myMatrix; std::tr1::mt19937 gen; std::tr1::uniform_int<int> dist(0,MT_MAX); myMatrix.setRandom(dist(gen)); 回答1: You can do what you want using Boost and unaryExpr. The function you pass to

Multidimensional arrays in eigen library

試著忘記壹切 提交于 2019-12-10 16:18:16
问题 3 simple questions about the usage and future of the excellent eigen library: Does it have a reason why the access to Matrices is not possible via matrix[i][j] , but only via matrix(i,j) ? Are there plans to implement such a syntax? Will there be an implementation of multidimensional arrays matrix[n][m]...[l] ? I really like the eigen library, it is fast and easy to use. The only thing missing for me are really multidimensional arrays. 回答1: I can't speak for the eigen library because I've

Extracting blocks/ROIs from Eigen::SparseMatrix without copying

时光总嘲笑我的痴心妄想 提交于 2019-12-10 16:18:05
问题 I wonder is there any good way to extract blocks/ROIs from Eigen::SparseMatrix? More precisely, what I want to extract is inner vectors . What I want to do is like: typedef Eigen::SparseMatrix<double,Eigen::RowMajor> SpMat; // Prepare some sparse matrix SpMat spmat; // Extract lines from it const SpMat& row_i = spmat.innerVector(i); const SpMat& row_j = spmat.innerVector(j); // Some calculation with row_i and row_j... As I tested, the data of row_i and row_j is copied (!!) from spmat .

Assigning a vector to a matrix column in Eigen

喜夏-厌秋 提交于 2019-12-10 15:38:24
问题 This question was asked in haste. The error in my original program, was not the typo in the code that is displayed here. The error was that in my program v was not getting populated due to some conditions. The more useful takeaway from this thread is the demonstration of copying a std::vector to all rows or columns of an Eigen Matrix, in the accepted answer. I want to copy vectors into the columns of a matrix, like the following: #include <Eigen/Dense> #include <vector> #include <iostream>

Extract a block from a sparse matrix as another sparse matric

老子叫甜甜 提交于 2019-12-10 14:59:24
问题 How to extract a block from a Eigen::SparseMatrix<double> . It seems there aren't the methods I used for the dense ones. ‘class Eigen::SparseMatrix<double>’ has no member named ‘topLeftCorner’ ‘class Eigen::SparseMatrix<double>’ has no member named ‘block’ There is a way to extract a block as a Eigen::SparseMatrix<double> ? 回答1: I made this function to extract blocks from a Eigen::SparseMatrix<double,ColMaior> typedef Triplet<double> Tri; SparseMatrix<double> sparseBlock(SparseMatrix<double