Questions tagged [rcpparmadillo]

204 questions
10
votes
1 answer

RcppArmadillo's sample() is ambiguous after updating R

I commonly work with a short Rcpp function that takes as input a matrix where each row contains K probabilities that sum to 1. The function then randomly samples for each row an integer between 1 and K corresponding to the provided probabilities.…
yrx1702
  • 1,619
  • 15
  • 27
7
votes
1 answer

Using SuperLU sparse solver with RcppArmadillo

I am trying to use the SparseLU solver from armadillo (http://arma.sourceforge.net/docs.html#spsolve) through RcppArmadillo: #define ARMA_USE_SUPERLU // [Rcpp::depends(RcppArmadillo)] #include // [[Rcpp::export]] arma::vec…
F. Privé
  • 11,423
  • 2
  • 27
  • 78
5
votes
1 answer

Error installing packages using renv::restore()

I have a problem using renv. For a larger project we want to use renv to all have the same version of r and all our packages. Yet, as soon as a newer version of a package is available and we run renv::restore() we get an error like the following…
Lizzie
  • 97
  • 1
  • 8
5
votes
1 answer

Why does Rcpp function segfault only when called from R package but not when sourced directly via sourceCpp?

I have a C++ function that works in R when sourced independently using Rcpp, but when I include it in a compiled R package, I keep receiving the following error: error: arma::memory::acquire(): out of memory. In this post, I have provided the C++…
4
votes
1 answer

How to remove the warning: Rcpp/DataFrame.h:136:18: warning unused variable 'data'?

I created an R package using RcppArmadillo from my Mac, and then built and installed it by doing the following: Rcpp::compileAttributes() devtools::build() devtools::install() However, I received several same warnings as below: clang++ -std=gnu++11…
Olivia
  • 43
  • 3
4
votes
2 answers

Use numeric sequence as default agument in Rcpp (Armadillo) function

I need this for a bigger project but I think this minimal reprex explains it best. I have the following function in R: test <- function(x = 2^(1:9)) { x } test() #> [1] 2 4 8 16 32 64 128 256 512 This is working fine. However, I want…
BerriJ
  • 913
  • 7
  • 18
4
votes
1 answer

Get the same sample of integers from Rcpp as base R

Is it possible to get the same sample of integers from Rcpp as from base R's sample? I have tried using Rcpp::sample and Rcpp::RcppArmadillo::sample but they do not return the same values -- example code below. Additionally, the Quick Example…
user2957945
  • 2,353
  • 2
  • 21
  • 40
4
votes
1 answer

Problems with Parallel and Rcpp Armadillo: Possible variable corruption between cluster workers

I am having some problems with using Rcpp (and Rcpp Armadillo) with the parallel package, and I am getting incorrect results depending on the number of cores I use for computation. I have a function compute_indices which computes 3 set of indices…
Segun Ojo
  • 91
  • 7
4
votes
1 answer

Advanced constructor for non-contiguous matrices

In my implementations I work a lot with submatrices and blocks of matrices. I am wondering if there is a way in Armadillo that would allow me to extract a block of a larger matrix and use the same memory for this submatrix as for the block within…
hejseb
  • 2,064
  • 3
  • 18
  • 28
4
votes
1 answer

Efficiently computing sum of cross product for two 3D arrays in R

For two 3D arrays in R, for example, N <- 1000 x <- rnorm(N*3*3); dim(x) <- c(N,3,3) y <- rnorm(N*3*3); dim(y) <- c(N,3,3) I can do the following cross product by loop: gg <- 0 for (n in 1:dim(x)[1]){ gg <- gg + t(x[n,,]) %*% y[n,,] } My…
user7283235
  • 101
  • 5
3
votes
1 answer

How to use RCPP_ARMADILLO_RETURN_ANYVEC_AS_VECTOR in an R package?

How do I use RCPP_ARMADILLO_RETURN_ANYVEC_AS_VECTOR in an R package? File veccany_as_v_test.cpp: // [[Rcpp::depends(RcppArmadillo)]] #define RCPP_ARMADILLO_RETURN_ANYVEC_AS_VECTOR #include using namespace Rcpp; //…
Simon
  • 58
  • 5
3
votes
2 answers

How do I find the indices of elements in a vector which are also in another vector using RcppArmadillo?

I am stuck trying to find the indices of elements in a vector x whose elements are also in another vector vals using Rcpp Armadillo. Both x and vals are of type arma::uvec. In R, this would be straightforward: x <- c(1,1,1,4,2,4,4) vals <-…
Econ21
  • 33
  • 3
3
votes
3 answers

Is there an efficient way to obtain "pmax" other than using the R base function?

I would like to create a function using Rcpp that could outperform the pmax function from R base. I also tried to handle missing values inside of Rcpp function, and this might not be a good idea. All vector must have some missing values and they are…
3
votes
0 answers

Rcpp port of a linear algebra function in R

The following is an objective function for symmetrical non-negative matrix factorization that I'm trying to port into Rcpp: fit_H <- function(W,H, num.iter){ for(i in 1:num.iter){ H <- 0.5*(H*(1+(crossprod(W,H)/tcrossprod(H,crossprod(H))))) …
zdebruine
  • 3,687
  • 6
  • 31
  • 50
3
votes
0 answers

Rstudio no autocomplete with Rcpp Armadillo?

I have long used Rcpp with Rstudio, but recently I lost autocomplete and diagnostic functionality. I was able to trace the cause to RcppArmadillow. Here is the basic default c++ new file code with modifications. #include using namespace…
MichaelE
  • 763
  • 8
  • 22
1
2 3
13 14