armadillo

RcppArmadillo “ReferenceInputParameter is not a template”

余生长醉 提交于 2019-12-11 04:04:26
问题 I am trying to build a user package that has been building fine on my colleague's windows box which has R 2.15.1 installed. My config is: R 2.15.3, RTools 3.0, Rcpp 0.10.4, RcppArmadillo 0.3.920.1, RStudio 0.97.551 This is the first compilation instance when I run "R CMD INSTALL mypackage". indfunForecast.cpp is one of the source files within the package. >g++ -m32 -I"D:/PROGRA~1/R/R-215~1.3/include" -DNDEBUG -I"D:/R/win-library/2.15/Rcpp/include" -I"D:/R/win-library/2.15/RcppArmadillo

push_back/append or appending a vector with a loop in C++ Armadillo

巧了我就是萌 提交于 2019-12-10 17:07:15
问题 I would like to create a vector (arma::uvec) of integers - I do not ex ante know the size of the vector. I could not find approptiate function in Armadillo documentation, but moreover I was not successfull with creating the vector by a loop. I think the issue is initializing the vector or in keeping track of its length. arma::uvec foo(arma::vec x){ arma::uvec vect; int nn=x.size(); vect(0)=1; int ind=0; for (int i=0; i<nn; i++){ if ((x(i)>0)){ ind=ind+1; vect(ind)=i; } } return vect; } The

Armadillo C++ linear algebra library : How to create vector of boolean

十年热恋 提交于 2019-12-10 16:08:25
问题 Recently I started using Armadillo C++ library. Given my C++ coding skills are not that great, I found this very friendly for linear algebra. I am also using that along with my matlab to speed things up for many of reconstruction algorithm. I do need to create a vector of boolean and I would prefer using this library rather than . However, I could not figure out how to do it. I tried using uvec; but, documentation seems to indicate that it can not be used with boolean. Any help would be

C++ Armadillo and OpenMp: Parallelization of summation of outer products - define reduction for Armadillo matrix

 ̄綄美尐妖づ 提交于 2019-12-09 23:37:23
问题 I am trying to parallelize a for loop using OpenMP which sums over Armadillo matrices. I have the following code: #include <armadillo> #include <omp.h> int main() { arma::mat A = arma::randu<arma::mat>(1000,700); arma::mat X = arma::zeros(700,700); arma::rowvec point = A.row(0); # pragma omp parallel for shared(A) reduction(+:X) for(unsigned int i = 0; i < A.n_rows; i++){ arma::rowvec diff = point - A.row(i); X += diff.t() * diff; // Adding the matrices to X here } } I am getting this error:

Rcpp equivalent for rowsum [closed]

时光怂恿深爱的人放手 提交于 2019-12-09 23:13:51
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I am looking for a fast alternative for the R function rowsum in C++ / Rcpp / Eigen or Armadillo. The purpose is to get the sum of elements in a vector a according to a grouping vector b . For example: > a [1] 2

Conversion between cv::Mat and arma::mat

旧时模样 提交于 2019-12-08 15:58:03
问题 I am using OpenCV and also want to add some of cool functions from mlpack, which is using Armadillo matrices. Is there an easy way to convet between cv::Mat and arms::mat? Thanks! 回答1: OpenCV's Mat has a pointer to its data. Armadillo has a constructor that is capable of reading from external data. It's easy to put them together. Remember that Armadillo stores in column-major order, whereas OpenCV uses row-major. I suppose you'll need to add another step for transformation, before or after.

Including Armadillo C++ library in a C++ project in Microsoft Visual Studio 2015

扶醉桌前 提交于 2019-12-08 11:15:26
问题 I'm trying to include the Armadillo C++ library, a linear algebra library, in a C++ project I'm working on, and I'm having a difficult time figuring out how to do so. I'm unfamiliar with how to add libraries to a project in general, so I've been searching for a resource that has step by step instructions, and the best one I could find didn't work for me (http://codeyarns.com/2013/11/15/how-to-use-armadillo-on-windows/). I followed all the instructions on the web page, and Visual Studio still

C++11 parallelization: bottleneck in Armadillo's set_seed_random()

纵饮孤独 提交于 2019-12-08 10:20:39
问题 In C++11, the use of arma_rng::set_seed_random() generates a bottleneck. I show a way to reproduce it. Consider this simple code: #include <armadillo> // Load Armadillo library. using namespace arma; int main() { bool jj = true; while ( jj == true ){ arma_rng::set_seed_random(); // Set the seed to generate random numbers. double rnd_number = randu<double>(); // Generate a random number. } } I compiled it with g++ -std=c++11 -Wall -g bayesian_estimation.cpp -o bayesian_estimation -O2

Armadillo equivalent of Matlab permute?

三世轮回 提交于 2019-12-08 07:39:02
问题 I have a arma::cube mycube(5,10,15); and I want to permute its dimensions, as one would do in matlab: mycube = ones(5,10,15); mycube = permute(mycube,[3 1 2]); size(mycube) % returns (15 5 10) Is there a way to do that? Would it be too inefficient? I actually want to do a 3D FFT, so I thought of permuting the first and third dimensions to be able to use arma::fft , and then permuting back. 回答1: Armadillo ibrary does not contain such a function, but you can implement a simplified version. For

Large SpMat object with RcppArmadillo

浪子不回头ぞ 提交于 2019-12-08 07:24:24
问题 I am trying to learn and use Rcpp and RcppArmadillo for the sparse linear algebra routines. Code below is adaptation of the example here: http://gallery.rcpp.org/articles/armadillo-sparse-matrix/ code <- ' S4 matx(x); IntegerVector Xd = matx.slot("Dim"); IntegerVector Xi = matx.slot("i"); IntegerVector Xp = matx.slot("p"); NumericVector Xx = matx.slot("x"); arma::sp_mat Xsp(Xd[0], Xd[1]); // create space for values, and copy arma::access::rw(Xsp.values) = arma::memory::acquire_chunked<double>