[Rcpp-devel] Problem with calling a function in RcppArmadillo to R

Kokia Z zkokia at 163.com
Fri Nov 18 12:08:10 CET 2016


I need to compute a kronecker product of two matrix, but the vector is out of the limit:


  Error in kronecker(X, as(Y, "TsparseMatrix"), FUN = FUN, make.dimnames = make.dimnames,  :
  Error in validityMethod(as(object, superClass)) :
  no support for long vectors:../include/Rinlinedfuns.h:137


   So I try to call a kronecker function, the corresponding file in the fn_kron.hpp file are:


1) In "R":
Rcpparma_hello_world <- function () {
.Call ( 'fn_kron_hpp_rcpparma_hello_world', PACKAGE = 'fn_kron.hpp')
}}


Rcpparma_outerproduct <- function (x) {
.Call ( 'fn_kron_hpp_rcpparma_outerproduct', PACKAGE = 'fn_kron.hpp', x)
}}


2) "src":
#Include <Rcpp.h>
Using namespace Rcpp;


// rcpparma_hello_world
Arma :: mat rcpparma_hello_world ();
RcppExport SEXP fn_kron_hpp_rcpparma_hello_world () {
BEGIN_RCPP
Rcpp :: RObject rcpp_result_gen;
Rcpp :: RNGScope rcpp_rngScope_gen;
Rcpp_result_gen = Rcpp :: wrap (rcpparma_hello_world ());
Return rcpp_result_gen;
END_RCPP
}}
// rcpparma_outerproduct
Arma :: mat rcpparma_outerproduct (const arma :: colvec & x);
RcppExport SEXP fn_kron_hpp_rcpparma_outerproduct (SEXP xSEXP) {
BEGIN_RCPP
Rcpp :: RObject rcpp_result_gen;
Rcpp :: RNGScope rcpp_rngScope_gen;
Rcpp :: traits :: input_parameter <const arma :: colvec &> :: type x (xSEXP);
Rcpp_result_gen = Rcpp :: wrap (rcpparma_outerproduct (x));
Return rcpp_result_gen;
END_RCPP
}}


3)"man" includes rcpparma_hello_world.Rd and fn_kron.hpp-package.Rd two documents.



# =================================================
So now the question is that I not know how to call the function in R ?
Library (RcppArmadillo)
Ws <- .Call ( 'fn_kron_hpp_rcpparma_outerproduct', PACKAGE = 'fn_kron.hpp', listw)


Note: I used the R kronecker function, the code is as follows:
I_T <- Diagonal (T)
Ws <- kronecker (I_T, listw)


And I do not understand what 'x' represents in . Call ( 'fn_kron_hpp_rcpparma_outerproduct', PACKAGE = 'fn_kron.hpp', x).


Thank you !
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20161118/72d561d7/attachment.html>


More information about the Rcpp-devel mailing list