eigen

Type error in ternary operator in Eigen

梦想的初衷 提交于 2019-12-11 10:37:19
问题 I'm doing a class in c++ to generalize two sparse matrix solvers (SparseLU and Sparse Cholesky). When I try to use the ternary operator it says that the operand types are incompatible, but if I use the If statement, the code compiles. Error 2 error: operand types are incompatible ("const Eigen::Solve < Eigen::SimplicialLDLT < Eigen::SparseMatrix < double, 0, int > , 1, Eigen::AMDOrdering < int > > , Eigen::Matrix < double, -1, 1, 0, -1, 1 > > " and "const Eigen::Solve < Eigen::SparseLU <

mingw windows can not find Eigen header file

我是研究僧i 提交于 2019-12-11 10:27:54
问题 I can't get Eigen starting to work. According to this link, I have to use g++ -I /path/to/eigen/ my_program.cpp -o my_program But this is not working for mingw So I look into mingw doc here. It seems that I should put Eigen folder into c:/mingw/include . So I did it, but still not working Here is the C++ source #include <iostream> #include <Eigen/Dense> using Eigen::MatrixXd; int main() { MatrixXd m(2,2); m(0,0) = 3; m(1,0) = 2.5; m(0,1) = -1; m(1,1) = m(1,0) + m(0,1); std::cout << m << std:

How do I do outer product of tensors in Eigen?

对着背影说爱祢 提交于 2019-12-11 09:46:50
问题 In eigen, one can do quite easily tensor contractions using: Tensor<double, 1> tensor1; Tensor<double, 2> tensor2; // fill with data so that // tensor1 is of dimensions [10] and tensor2 of dimensions [5,10] std::array<Eigen::IndexPair<int>, 1> product_dims1 = { IndexPair<int>(1, 0) }; auto tensor = tensor2.contract(tensor1, product_dims1); // now tensor is of dimensions [5] I am looking for a method that does the opposite of contraction, meaning it takes two tensors A and B, say of dimensions

Parallelization of Jacobi algorithm using eigen c++ using openmp

北战南征 提交于 2019-12-11 08:54:30
问题 I have implemented the Jacobi algorithm based on the routine described in the book Numerical Recipes but since I plan to work with very large matrices I am trying to parallelize it using openmp. void ROTATE(MatrixXd &a, int i, int j, int k, int l, double s, double tau) { double g,h; g=a(i,j); h=a(k,l); a(i,j)=g-s*(h+g*tau); a(k,l)=h+s*(g-h*tau); } void jacobi(int n, MatrixXd &a, MatrixXd &v, VectorXd &d ) { int j,iq,ip,i; double tresh,theta,tau,t,sm,s,h,g,c; VectorXd b(n); VectorXd z(n); v

DenseBase, auto, and binary operation says arrays have different shape

ぐ巨炮叔叔 提交于 2019-12-11 06:37:49
问题 I write a function that takes two DenseBase as arguments. The function uses .derived().array() to convert both Array and Matrix to Array . I got tired of writing derived for many times and use auto. But auto leads to strange error. Eigen complains that x2 and y2 don't have same shape. If I don't want to write .derived().array() for many times, what can I use? Eigen is from https://github.com/eigenteam/eigen-git-mirror.git #include <Eigen/Eigen> int main() { Eigen::ArrayXf x(3); Eigen::ArrayXf

Transform matrix of 3D positions with corresponding transformation matrix

╄→尐↘猪︶ㄣ 提交于 2019-12-11 05:48:34
问题 I have a matrix of 3D points ( positions ), in which every column represents a 3D point expressed in a local frame at a specific time instance. The transforms (row)vector contains the transformation matrix of the moving local frame at each time instance, i.e. the ith transformation matrix corresponds with the ith column of positions . I want to calculate the position in the global frame ( transformed ) by applying the transformation matrixes to their corresponding point. This can be done with

Rcpp Eigen Map Error with MatrixXf

余生颓废 提交于 2019-12-11 05:34:08
问题 Why does the following code not compile? library(Rcpp) cppFunction(' int rows(const NumericMatrix& X) { using Eigen::MatrixXf; typedef Eigen::Map<MatrixXf> MapMat; MapMat X1(as<MapMat>(X)); return X1.rows(); }', depends = "RcppEigen") It throws the following error: error: no matching function for call to 'Eigen::Map<Eigen::Matrix<float, -1, -1> >::Map(Rcpp::Vector<14, Rcpp::PreserveStorage>::iterator, int&, int&)' OUT get() {return OUT(vec.begin(), d_nrow, d_ncol );} The same code works fine

Why does the following fail with Eigen?

删除回忆录丶 提交于 2019-12-11 04:47:44
问题 I have the following piece of code, which I hoped would do outer product between tensor2 and tensor3 and then add the result to tensor, however I get a dimension mismatch issue: #include <Eigen/Core> #include <unsupported/Eigen/CXX11/Tensor> #include <iostream> using namespace Eigen; using namespace std; int main() { Eigen::Tensor<double, 2> tensor(1,9); Eigen::Tensor<double, 1> tensor2(1); Eigen::Tensor<double, 1> tensor3(9); tensor = tensor + tensor2 * tensor3; } The error is an assertion

Eigen Sparse LU solver return value

左心房为你撑大大i 提交于 2019-12-11 04:23:18
问题 I have a problem with the following piece of code, after some research I have singled out the problem in a separate line, but not sure now how to solve it. typedef double ComplexType; typedef std::complex<ComplexType> Complex; typedef Eigen::SparseMatrix<Complex, Eigen::ColMajor, long long> SparseMatrixT; typedef Eigen::SparseVector<Complex, Eigen::ColMajor, long long> SparseVectorC; typedef Eigen::SparseLU<SparseMatrixT, Eigen::COLAMDOrdering< long long>> SolverT; SparseVectorC Solve(const

How do I diagonalize a matrix quickly in C++?

笑着哭i 提交于 2019-12-11 04:09:34
问题 I don't know which library to choose (for windows): LAPACK++, Armadillo, IT++, Eigen, or maybe something else? All I need to do is to check if a big (about 10,000*10,000) matrix is diagonalizable, and if so, to get the diagonal and the invertible matrix such that D=(P^(-1))*A*P. This has to be done as fast as possible. I have no idea which library to use. Also, I'll be happy to know in general what are the pros and cons of each of these libraries. 回答1: This may be a rather vague answer, since