armadillo

RcppArmadillo and C++ division issue

一笑奈何 提交于 2019-12-12 06:32:07
问题 A very simple question regarding RcppArmadillo. Trying to multiply a vector by a scalar, and getting different results depending on small changes in syntax. Any ideas? // [[Rcpp::depends("RcppArmadillo")]] // [[Rcpp::export]] arma::vec funtemp(arma::vec x) { // return(x/10); // this works // return((1/10)*x); // this does not work return(x*(1/10)); // this does not work } 回答1: Ahh, the good ol' integer vs. double division problem in C++. Before we begin, note that: arma::vec is by default a

Select Armadillo sub-matrix with non contiguous indices

爱⌒轻易说出口 提交于 2019-12-12 04:37:38
问题 I am passing a python code to C++ where I find python expressions like this: J11 = dS_dVa[array([pvpq]).T, pvpq].real Here, J11 and dS_dVa are Sparse matrices, and pvpq is an array of indices that can be in any growing order (ie. 1, 2, 5, 7, 9) Looking at the documentation here I have inferred the following: arma::Row<int> pvpq(calc->pqpv); arma::sp_mat J11 = arma::real(dS_dVa.submat(pvpq, pvpq)); where calc->pqpv is of type std::vector<int> . However the GCC compiler says: engine.h:2436:

issue with eigs_sym for obtaining eigenvalues with smallest magnitude

社会主义新天地 提交于 2019-12-12 04:11:22
问题 i'm trying to get a limited number of eigen-values with smallest magnitude of a squared symmetric matrix. To do this, i'm using first the example in the doc of Armadillo (http://arma.sourceforge.net/docs.html#eigs_sym) : sp_mat A = sprandu<sp_mat>(1000, 1000, 0.1); sp_mat B = A.t()*A; arma::vec eigval; mat eigvec; eigs_sym(eigval, eigvec, B, 10, "sm");//i add "sm" to get the eigen- //values of smallest magnitude cout<<eigval<<endl; Here i obtain an error saying the ddcomposition fails [failed

Infinite loop in random.tcc (GCC 6.1.0) (May be bug in Armadillo)

痞子三分冷 提交于 2019-12-12 02:19:19
问题 I found the C++ 11 random number generator in GCC 6.1.0 causes codes stuck in Mac OS X 10.11.5, a simple code snippet is as following: #include <iostream> #include <armadillo> using namespace std; using namespace arma; int main(int argc, char const* argv[]) { cout << "check 1" << endl; cout << arma_rng::randn<double>() << endl; cout << "check 2" << endl; return 0; } I debugged this code by using lldb , and locked the suspicious part in random.tcc file of libstdc++ : /** * Polar method due to

Eclipse CDT project with armadillo - CDT does not recognize 'arma' namespace

假如想象 提交于 2019-12-12 01:52:28
问题 I'm running on a CentOS 6.5 x64 OS and have used yum to install armadillo. I'm developing in Eclipse CDT I've included the armadillo header in the project properties >> C/C++ Build >> Settings >> GCC C++ Compiler >> Includes >> Include files. The entry is: "/usr/include/armadillo" The header file I am working on recognizes armadillo and the include statement isn't flagged for any errors or warnings. Below is the code: #include <armadillo> using namespace std; using namespace arma; // arma is

C++ armadillo sparse matrix type conversion

二次信任 提交于 2019-12-11 10:40:59
问题 I want to add two sparse armadillo matrices of arbitrary (different) type with operator+ , e.g. SpMat<double> M1(2,2); SpMat<cx_double> M2(2,2); // ..fill both matrices cout<<M1 + M2<<endl; Upon compiling, the compiler complains that operator+ is not defined for those types. When doing the same with DENSE matrices, armadillo automatically promotes the double matrix to a complex one, performs the addition and prints a complex result matrix. There is a corresponding template for this operator

Index A Matrix Using A Vector of Indices in Armadillo LIbrary

帅比萌擦擦* 提交于 2019-12-11 06:25:46
问题 I'm using the Armadillo Cpp code for matrix algebra. I have an Eigenvector matrix E that I want to sort by its eigenvalues in a vector d . mat E; vec d; eig_sym(d,E,Rxx); // Sort indices of eignen values / vectors // based on decreasing real part of eigen values. uvec order = sort_index(-d); // Extract top eigen vectors. E = E(span::all,order(1,nb_sources)); I couldn't find anything related to this kind of indexing in the documentation. Indexing using a vector is such a common requirement

Matlab's Accumarray equivalent in C++

允我心安 提交于 2019-12-11 05:48:47
问题 I found a solution for matlab's accumarray equivalent in c++ with armadillo here. Although the code works like it should in matlab, my problem is that is takes a lot of time. It takes approximately 2.2 seconds to run and i have to call this function around 360 times. Is there a way to optimize this code or anyother way to implement accumarray in c++ with armadillo/opencv/boost? I know python has a bitcount function with numpy which is fast and efficient but i cant find anything in c++. Thank

R packages with Rcpp and nloptr

醉酒当歌 提交于 2019-12-11 05:17:54
问题 I have been building an r-package that runs RcppParallel and calls nloptr from the cpp in parallel. Currently, the package will not build as it can't find the 'nloptrAPI.h' file. The build log outputs: * checking dependencies in R code ... NOTE Namespaces in Imports field not imported from: ‘RcppArmadillo’ ‘nloptr’ My question is if there is a simple fix for this. Or if I would have to rewrite the function to call 'nlopt' from the cpp version and add a 'makevars' file to the package. The src

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