I'm trying to create quite large matrices (to store point data) in an Eigen matrix in the following way void MyFunction(Eigen::MatrixBase<Derived1>& X) { // Create empty matrix Eigen::Matrix3Xf Q = Eigen::Matrix3Xf::Zero(3, X.cols()); Where X.cols is around 300,000. This is taking a LONG time when I'm stepping through the code in...

I am encountering an error where the values of protected members of a base class are changing values between when the parent class constructor is called and when the child constructor is called. A stripped down version of the code is as follows: Namespace A { class Parent { public:...

I have written a code using Eigen in c++ which returns some NaNs and the whole thing blows up. When I try to print out variables (with ofstream) and trace back to where the NaN originated, suddenly the NaNs don't appear and the calculation completes successfully. Does anybody have any...

I have an array of doubles, and I want to create a 4-by-4 matrix using the Eigen library. I also want to specify that the data is stored in row-major order. How can I do this? I have tried the following, but it does not compile: double data[16]; Eigen::Matrix4d M...

I have following code that shrinks an Eigen MatrixXd by removing the last line. Anyway, that seems to corrupt the matrix. Also valgrind is very upset on that code. What is the proper way to perform that task? #include <Eigen/Core> #include <iostream> int main() { Eigen::MatrixXd A(3, 4); for (int...

I am mapping a multi-channel OpenCV cv::Mat to a Eigen::Matrix. There are a couple ways I thought of to do it. Ignoring row- vs column-major for the sake of the example, the first is: Map<Matrix<double, Dynamic, Dynamic>, Stride<3,1>> R((double*)mat_cv.data); Map<Matrix<double, Dynamic, Dynamic>, Stride<3,1>> G((double*)mat_cv.data + 1); Map<Matrix<double, Dynamic, Dynamic>, Stride<3,1>>...

I am trying to create a wrapper in Cython for a library which uses Eigen::Matrix3d matrices. How can I set an individual element/coefficient of the Matrix3d object? I know, I can get the value with the coeff(row, col) method but could not find any function set_coeff(row, col, value) - or...

I'm using large matrices (100x100 to 3000x3000) to do some claculations (a lot of sums and up to 120 matrix-vector multiplications), I'm using the Eigen Library for my vectors and matrices. I was wondering how I could speed up my program. Should I keep using Eigen, use 1d arrays, use...

I have stored 85 Point Clouds on hdd. I want to open all the clouds and save them in a vector/array. How should I do this? What I tested with no success: define _CRT_SECURE_NO_WARNINGS #include <pcl/io/pcd_io.h> #include <pcl/point_types.h> #include <pcl/registration/icp.h> #include <pcl/visualization/pcl_visualizer.h> #include <pcl/common/transforms.h> #include <pcl/filters/voxel_grid.h> #include <pcl/filters/radius_outlier_removal.h> #include <Eigen/Geometry>...

I'm doing some large stochastic matrices (at least 1000x1000) calculation in C++, using the Eigen Library, my code consists of the following functions : Eigen::VectorXd grid(...); initializes (element by element) a sorted vector of log-normally distributed values, using the quicksort algorithm and the ran1 algorithm, let's say of size N,...

In MATLAB, you can create a binary matrix B by thresholding a matrix A as follows: B = A > threshold Where threshold is some value. In Eigen for C++, I have been able see similar results, but have faced an inability to assign the output. That is, given MatrixXd...

I am experimenting with doing bicubic interpolation of some gridded data using Eigen, and I can't figure out how to reshape the 16x1 column vector of coefficients into a 4x4 matrix. Ideally I would like to do something along the lines of https://bitbucket.org/eigen/eigen/pull-request/41/reshape/diff without any copying, but I can't make...

I have a float array Eigen::ArrayXf which I need to decimate (i.e. pick 1 out of f.i. 8 samples). Eigen::ArrayXf decimatedSignal = Eigen::Map<Eigen::ArrayXf, 0, Eigen::InnerStride<8> >(signal.data(), length, 1).eval(); which works, with a caveat: I need to know how long length is, and it can be specified too long, leading to...

In numpy, there are functions like nanmean() that treat quiet NaNs as missing data, i.e. sum only over finite elements and divide by the number of finite elements. This produces quite clean and readable code. Are there counterparts of such functions in Eigen? Currently I need to implement a masked...

Can someone explain to me why the results are different. Code in C++: MatrixXcd testTest; testTest.resize(3,3); testTest.real()(0,0) = 1; testTest.real()(0,1) = 2; testTest.real()(0,2) = 3; testTest.real()(1,0) = 1; testTest.real()(1,1) = 2; testTest.real()(1,2) = 3; testTest.real()(2,0) = 1; testTest.real()(2,1) = 2; testTest.real()(2,2) = 3; testTest.imag()(0,0) = 1; testTest.imag()(0,1) = 2; testTest.imag()(0,2)...

We are trying to implement a new C++ code in my research group to perform large numerical simulations (finite elements, finite difference methods, topology optimization, etc.) The software will be used by people from academia and industry alike. For the dense linear algebra piece of the software, we want to...

Do anyone have any idea how can I rewrite eig(A,B) from Matlab used to calculate generalized eigenvector/eigenvalues? I've been struggling with this problem lately. So far: Matlab definition of eig function I need: [V,D] = eig(A,B) produces a diagonal matrix D of generalized eigenvalues and a full matrix V whose...

I have a code with following structure : Eigen::MatrixXd function1(args) { #pragma omp parallel for for (args) //filling a matrix element-wise return matrix; } Eigen::MatrixXd function2(argument is function1 matrix) { #pragma omp parallel for for (args) //element-wise probabilities calculations on matrix from function1 return matrix; } Eigen::MatrixXd global_function(args) { Eigen::MatrixXd...

The following main file should pass a VectorXi to my class called Test which then has a method that does something with it (for demonstration it just prints the sum of all elements): #include <iostream> #include <eigen3/Eigen/Dense> #include "test.h" using namespace std; using namespace Eigen; int main(int argc, const char...

Eigen is a linear algebra library in C++. I have my data (double type) in a std::vector (DataVector in the code below) type array. I try to copy it row-wise using the following code which is still giving results column-wise. Map<MatrixXd, RowMajor> MyMatrix(DataVector.data(), M, N); Am I doing the correct...

I have code written in C++ that is using Eigen and I need to rewrite it in OpenCV. The problem is that I haven't used Eigen before and I can't find any more extensive examples to help me out. This is a code sample: int n; Eigen::VectorXd alpha; Eigen::MatrixXd L;...

I want to rewrite to C++ eig function from Matlab: [V,D] = eig(A,B) produces a diagonal matrix D of generalized eigenvalues and a full matrix V whose columns are the corresponding eigenvectors so that A*V = B*V*D. I get positive results for Matrix4d class: pair<Matrix4d, Vector4d> eig(const Matrix4d& A, const...

I am trying to perform right division in c++ on a vector/matrix as is done in matlab with the / operator. More specifically, I am using eigen and the code snippet where I try to do the division is the following: #include <Eigen/Dense> // Do stuff // ... Vector3d instance;...

I am using both OpenCV and Eigen to calculate SVD: Eigen: JacobiSVD<Matrix3f> svd(myM, ComputeFullU); OpenCV: cvSVD(&myM, &w, &u, 0, CV_SVD_MODIFY_A | CV_SVD_U_T); I am focused on the left singular vectors: Eigen result: 0.0341698 -0.064916 0.997306 0.950241 -0.307051 -0.0525437 0.309635 0.949476 0.051194 OpenCV result: [0.03417001163639093, -0.06491612525262211, 0.9973055233913801; -0.9502414121501213, 0.3070511298822651, 0.05254390804810754; -0.3096347347112595,...

I was trying to pass a function template F_1 that received a reference to an Eigen MatrixBase to another function template F_2 that would then, do something with it: //Function that will be argument to F_2 template<typename derived_matrix,typename derived_float> void F_1(const MatrixBase<derived_matrix>& x,derived_float t,MatrixBase<derived_matrix>& store){ store = 2*x; } template<typename...

Using the Eigen C++ library, I have a Matrix3f A, a Vector4f b, and a Vector4f c. I want to create a Matrix4f M out of these. I want the top 3-by-3 corner of M to be A, I want to final column of M to be b, and I...

I have a python-based face recognition script running several processes (threads?) all doing different things. I am attempting to use one of these to re-train the model once the training images have been changed/updated. I have tried sending the model through the python pipe function: pipe.send(model) I am not hit...

SparseMatrix<double> matA(rows, cols); SparseMatrix<double> ATA(rows, cols); ... ATA = (SparseMatrix<double>(matA.transpose()) * matA).pruned(); //.triangularView<Lower>(); If I want to store results to Dense matrix for ex. DATA = ..., it returns very strange error of pruned function. smaller question: If I use .triangularView<Lower>(); this store in the heap only n/2+n elements of...

SparseMatrix<int,RowMajor> sm(3,3),sm1; sm.insert(0,0)=1; sm.insert(1,1)=1; sm.insert(2,2)=1; sm.insert(1,2)=1; sm.insert(2,1)=1; SparseMatrix<int,RowMajor> I(3,3); I.insert(0,0)=1; I.insert(1,1)=1; I.insert(2,2)=1; cout<<"SM matrix \n"<<sm<<endl; sm1=sm-I; cout<<"SM1 Matrix"<<sm1<<endl; cout<<"the number of nonzeros\n"<<sm1.nonZeros()<<endl; Output SM matrix Nonzero entries: (1,0) (_,_) (1,1) (1,2) (1,1) (1,2) Outer pointers: 0 2 4 $ Inner non zeros: 1 2 2 $ 1 0 0 0...

I made this code to test performance of eigen additons versus plain old scalar additions. int x, y; cin >> x; cin >> y; typedef int theType; Array<theType, 8, 1> theArray; theArray << 0,0,0,0,0,0,0,0; StopWatch sw; sw.Start(); for(int k = 0; k < y*1000000; k++){ theArray << 0,0,0,0,0,0,0,0; for (int...

I have many expressions that look like auto result = vec3f.cwiseProduct( vec3ui ); where vec3f is from type Eigen::Matrix< float, 3, 1 > and vec3ui is from Eigen::Matrix< unsigned int, 3, 1 >. These doesn't seem to be allowed, at least the compiler complains about it. Hence I need to...

I'm searching for an equivalent of A=Spdiags(B,d,N,N)in C++. This function extracts the diagonals element of the matrix B by taking the columns of B and placing them along the diagonals specified by the vector d. N N are the size of the output matrix A. I've searched in Eigen, but...