eigen

bool multiplication with exclusive-or, not or (with Eigen Matrix Library)

我是研究僧i 提交于 2019-12-12 11:34:17
问题 I'm trying to implement hamming error correcting codes, and to do this I need to take a bool Vector (the data) and multiply it with a bool Matrix(hamming generator matrix), performing XOR operations (instead of what looks like OR as Eigen's default bool behavior). An example of what I am doing is found in this simple tutorial: http://michael.dipperstein.com/hamming/ I don't necessarily have to use Eigen, so please feel free to suggest something other than Eigen if you have the solution. So

How to write a third-party library wrapper class around expression templates

百般思念 提交于 2019-12-12 10:39:49
问题 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 use either Eigen or Armadillo. We wish to build a wrapper around these packages for two reasons: 1. to expose our own API to the users rather than the third-party API; and 2. in case we

Comparing two matrices with eigen

自闭症网瘾萝莉.ら 提交于 2019-12-12 09:56:40
问题 Let's say I have two eigen matrices A and B, and I want to create a third matrix defined by C(i,j) = 5.0 if A(i,j) > B(i,j), 0 otherwise I guess it is possible to do it without an explicit for loop. But I am not very proficient with Eigen yet. What whould be the best approach? 回答1: Assuming A , B and C are MatrixXd you can do: C = (A.array()>B.Array()).cast<double>() * 5.0; 来源: https://stackoverflow.com/questions/22228332/comparing-two-matrices-with-eigen

Eigen Library - Pseudo-Inverse of Matrix (Matlab - pinv)

北城余情 提交于 2019-12-12 09:26:36
问题 I am trying to find the pseudo-inverse of a matrix using the Eigen Library. They have a class that does implement it, however I do not know how to put script the syntax. This is how it is shown on the website (https://eigen.tuxfamily.org/dox/classEigen_1_1CompleteOrthogonalDecomposition.html#ab2fd4c81aa1cd8bc917c7f135505cb7f): const Inverse Eigen::CompleteOrthogonalDecomposition< MatrixType >::pseudoInverse ( ) const 回答1: It's a method of the CompleteOrthogonalDecomposition class. So you have

Eigen: mask an array

亡梦爱人 提交于 2019-12-12 08:37:19
问题 Is it possible to mask an array in Eigen as in Matlab? Something like ArrayXd arrayA = ArrayXd::Random(10, 5); ArrayXi mask = ArrayXi::Zero(arrayA.rows(), arrayA.cols()); mask = arrayA > 5; ArrayXd arrayB = arrayA(mask) where arrayB is a row vector containing all and only the elements of arrayA>5 I could find similar requests but not any updated answer after 2011 ( https://forum.kde.org/viewtopic.php?f=74&t=98382 , https://forum.kde.org/viewtopic.php?f=74&t=98093 , https://forum.kde.org

C++ Eigen Sparse Matrix multiplication much slower than python scipy.sparse

南楼画角 提交于 2019-12-12 08:14:44
问题 Edit: The huge difference in performance is due to a bug in the test, when set up properly Eigen is 2 to 3 times faster. I noticed that sparse matrix multiplication using C++ Eigen library is much slower than using Python scipy.sparse library. I achieve in scipy.sparse in ~0.03 seconds what I achieve in Eigen in ~25 seconds. Maybe I doing something wrong in Eigen? Here Python code: from scipy import sparse from time import time import random as rn N_VALUES = 200000 N_ROWS = 400000 N_COLS =

Array of pointers to Eigen Matrices

拜拜、爱过 提交于 2019-12-12 08:12:16
问题 I am using MatrixXd matrices from Eigen on my code, and at a certain point I need a 3D one. Since Eigen does not have tridimensional matrix types, as it is optimized just for linear algebra, instead I am creating a pointer array of the MatrixXd type: Eigen::MatrixXd *CVM =new Eigen::MatrixXd[100]; for (int i = 0; i < 100; i++){ CVM[i]= Eigen::MatrixXd::Zero(5,5); } However, later on I need to acess the values on this array, and for that I am doing something like: for (int k = 0; k < 100; k++)

Map a Eigen Matrix to an C array

非 Y 不嫁゛ 提交于 2019-12-12 08:00:40
问题 I recently started to use the Eigen library. I got a question of mapping an Eigen matrix to a C/C++ array. An Eigen matrix is column majored by default. So if i use the following code to map a matrix to an C/C++ array, double a[10]; double *p = &a[0]; MatrixXd(2,5) m; for (int i=0; i<2;i++) for (int j=0; j<5;j++) m(i,j) = i+j; cout<<m<<endl; Eigen::Map<MatrixXd>(p,2,5) = m; for (int i=0; i<10; i++) cout<<a[i]<<" "; cout<<endl; The output is: 0 1 2 3 4 1 2 3 4 5 0 1 1 2 2 3 3 4 4 5 If I change

Copy select rows into new matrix

[亡魂溺海] 提交于 2019-12-12 07:44:39
问题 I want to copy the rows 0, 2 and 4 of my matrix A into B, in this order. Let A = [a0, a1, a2, a3, a4]^T , with a_i being row-vectors, then B should be: [a0, a2, a4]^T. The code below does what I want but I wonder whether there is a prettier solution (maybe using Eigen)? #include <iostream> #include <vector> #include <opencv/cv.h> int main(int argc, char **argv) { const int num_points = 5; const int vec_length = 3; cv::Mat A(num_points, vec_length, CV_32FC1); cv::RNG rng(0); // Fill A with

Different eigenvector and eigenvalues in Eigen and Matlab could generate errors?

妖精的绣舞 提交于 2019-12-12 05:48:20
问题 Like it's explained here and here the orde of the eigenvalues (and relative eigenvectors and their sign too) are library dependent and (according to the first linked question) it shouldn't be a problem. In addition, eigenvectors relative to almost-zero eigenvalues can be considered as garbage. So far so good. Now, consider the MATLAB code below that I want to rewrite in C++ using Eigen library: %supposing K is 3x3 matrix [V_K,D_K] = eig(K); d_k = diag(D_K); ind_k = find(d_k > 1e-8); d_k(ind_k