Hello Rcpp developers,

The following simple code attempts to instantiate every sparse matrix in a
given R list of sparse matrices ("dgCMatrix"). The code compiles OK, but
crashes at runtime with a segmentation fault.

I followed the as<> approach outlined in
https://gallery.rcpp.org/articles/dynamic-dispatch-for-sparse-matrices/ ,
although in that post, we are not dealing with a list of sparse matrices,
but with just one sparse matrix.

Thank you, SK.

library(Rcpp)library(Matrix)

# -- The function in question --cppFunction(
  "arma::mat accessEntries(Rcpp::List x){
     for(int i=0; i<x.size(); i++){
     arma::sp_mat ar=Rcpp::as<arma::sp_mat>(x[i]); //similar to :
https://gallery.rcpp.org/articles/dynamic-dispatch-for-sparse-matrices/
     }
  }",
depends=c("RcppArmadillo", "Rcpp"),
plugins = "cpp11"
)

# -- Construct a list of sparse matrices and call the above function --
X <- as(cbind( c(1,2,3), c(3,4,5), c(5, 6, 7) ), "dgCMatrix")
spList <- list( X, X )accessEntries(spList)

# -- Output --
# *** caught segfault ***#address 0x0, cause 'unknown'

#Traceback:
# 1: .Call(<pointer: 0x10df0eba0>, x)
# 2: accessEntries(spList)
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to