armadillo

sample in Rcpp Armadillo

心不动则不痛 提交于 2021-01-27 21:30:25
问题 I am currently struggeling with the sample() command provided in RcppArmadillo . When I try to run the code below I get the error no matching function for call to sample and I already add the extra Rcpp:: namespace in front since this worked out well in another post. I also tried several other container classes, but I am always stuck with this error. Below is some code, which produces the error. Any help would be greatly appreciated :) #include <RcppArmadillo.h> // [[Rcpp::depends

Boost serializing armadillo matrices

喜欢而已 提交于 2020-05-16 20:55:07
问题 I'm trying to make sure serializing works for matrices i.e. Armadillo and I'm getting some errors. I made a simple example of a random matrix and am trying to save the content using boost in a binary file, then load it using boost: #include <iostream> #include <fstream> #include <boost/archive/tmpdir.hpp> #include <boost/archive/binary_oarchive.hpp> #include <boost/archive/binary_iarchive.hpp> #include <armadillo> int main() { arma::mat A = arma::randu<arma::mat>(4,5); std::ofstream

Windows上Armadillo如何使用OpenBLAS

二次信任 提交于 2020-05-06 03:42:55
以下来自于清华大学电机系刘一兵同学: 下载armadillo(下文简称arma),官网上的arma自带了lapack和blas的binary packages,所以,只需在工程中包含arma的include文件夹和lib即可,如果这时程序能够运行,说明config里面的设置是正确的,即可以使用lapack和blas以及openblas; 下载openblas的binary packages包,将openblas的的lib文件夹包含进工程的lib路径和include路径,linker/input设为libopenblas.lib(此时不需包含lapack和blas); 设为X64编译环境(可选,如果是Windows 64位,并且下载的是64位的OpenBLAS,就需要设置X64) 如果编译报错找不到libopenblas.dll,则将openblas包中的libopenblas.dll复制到当前工程的debug文件夹下的*.exe旁边即可; 如果编译通过了,但是运行时提示找不到libgfortran.dll,只需从网上下载mingw中该dll,然后放到c:windows/system32文件夹或者*.exe所在的文件夹下即可。 来源: oschina 链接: https://my.oschina.net/u/274748/blog/158728

Rcpp sugar commands in armadillo

倾然丶 夕夏残阳落幕 提交于 2020-01-30 08:59:04
问题 I'm trying to use ifelse() command of Rcpp sugar with arma::vec . The code fails with error 'ifelse' was not declared in this scope I could not find a solution. A simple example code (resulted with error) is below. #include <RcppArmadillo.h> // [[Rcpp::depends(RcppArmadillo)]] // [[Rcpp::export]] arma::vec f(arma::vec x, arma::vec y) { arma::vec res1 = Rcpp::ifelse(x < y, x, y); arma::vec res = trans(res1)*y; return res; } /*** R f(c(1,2,3),c(3,2,1)) */ 回答1: Using Armadillo's advanced

Code using RcppArmadillo compiles when running R from terminal but not rstudio-server

只愿长相守 提交于 2020-01-17 04:43:47
问题 I'm trying to get some c++ code to compile using sourceCpp and RcppArmadillo. I'm using R 3.3.3 on Ubuntu, Rcpp 0.12.10 and RcppArmadillo 0.7.800.2.0. The file, armatest.cpp, is totally stripped down. // [[Rcpp::depends(RcppArmadillo)]] #include <RcppArmadillo.h> using namespace arma; using namespace Rcpp; int one() { return 1; } When I attempt to compile this from within Rstudio server, I get the following compilation error: > Rcpp::sourceCpp("armatest.cpp", verbose = TRUE, rebuild=TRUE)

Bandits with Rcpp

南楼画角 提交于 2020-01-06 07:09:40
问题 This is a second attempt at correcting my earlier version that lives here. I am translating the epsilon-greedy algorithm for multiarmed bandits. A summary of the code is as follows. Basically, we have a set of arms, each of which pays out a reward with a pre-defined probability and our job is to show that by drawing at random from the arms while drawing the arm with the best reward intermittently eventually allows us to converge on to the best arm. The original algorithm can be found here.

QR decomposition in RcppArmadillo

给你一囗甜甜゛ 提交于 2020-01-04 04:06:26
问题 Really confused why the QR output using RcppArmadillo is different than QR output from R; Armadillo documentation doesnt give a clear answer either. Essentially when I give R a matrix Y that is n * q (say 1000 X 20 ) , I get back Q which is 1000 X 20 and R 20 X 1000. This is what I need. But when I use the QR solver in Armadillo, it throws me back Q 1000 X 1000 and R 1000 X 20. Can I call R's qr function instead? I need Q to have dimension n x q, not q x q. Code below is what I am using(its a

How to properly include Armadillo in CLion (without having false errors)?

无人久伴 提交于 2020-01-03 09:30:00
问题 When I use the header-only Armadillo C++ library in CLion, the IDE indicates (highlights) multiple (false) errors in the code, however the usage of Armadillo is valid and the code builds and runs without any errors. For example, in a very simple Armadillo test project, the IDE indicates 3 errors, as written in the comments: #include <iostream> #include "armadillo" using namespace std; using namespace arma; int main() { cout << "Armadillo version: " << arma_version::as_string() << endl; //

function pass by reference in RcppArmadillo

邮差的信 提交于 2019-12-30 07:29:10
问题 I have a function written in RcppArmadillo style and I want to use it for changing variables in the calling environment. I know it is not advisable to do things like this, but it's helpful in my case. Concretely, I'm trying this: #include <RcppArmadillo.h> #include <iostream> //[[Rcpp::export]] void myfun(double &x){ arma::mat X = arma::randu<arma::mat>(5,5); arma::mat Y = X.t()*X; arma::mat R1 = chol(Y); x = arma::det(R1); std::cout << "Inside myfun: x = " << x << std::endl; } /*** R x = 1.0

Parallelisation in Armadillo

久未见 提交于 2019-12-29 08:41:17
问题 The Armadillo C++ linear algebra library documentation states one of the reasons for developing the library in C++ to be "ease of parallelisation via OpenMP present in modern C++ compilers", but the Armadillo code does not use OpenMP. How can I gain the benefits of parallelisation with Armadillo? Is this achieved by using one of the high-speed LAPACK and BLAS replacements? My platform is Linux, Intel processor but I suspect there is a generic answer to this question. 回答1: Okay so it appears