[Rcpp-devel] round function not found?

Simon Zehnder szehnder at uni-bonn.de
Tue Mar 4 13:16:26 CET 2014


In some way, round does not work on a matrix. But you can use RcppArmadillo: 

src <- 'Rcpp::NumericMatrix M(m);
arma::mat armaM(M.begin(), M.nrow(), M.ncol(), true, true);
return Rcpp::wrap(arma::floor(armaM));’

cfunc <- cxxfunction(signature(m = "matrix"), body = src, plugin = "RcppArmadillo”)

m <- as.matrix(rnorm(9))

m
                   [,1]      	      [,2]              [,3]
[1,]  0.4452233  1.2581666 -1.5520510
[2,] -1.1982695  0.2641597 -0.4497563
[3,]  0.9316742 -0.2111520 -0.1184958

cfunc(m)
     	[,1] [,2] [,3]
[1,]    0    1   -2
[2,]   -2    0   -1
[3,]    0   -1   -1

Best

Simon


On 04 Mar 2014, at 12:57, Hideyoshi Maeda <hideyoshi.maeda at gmail.com> wrote:

> Does round work on a matrix?
> 
> 
> On Tue, Mar 4, 2014 at 11:53 AM, Ahmadou Dicko <dicko.ahmadou at gmail.com> wrote:
> Hi,
> 
> `round` is part of Rcpp sugar for a long time now (http://dirk.eddelbuettel.com/blog/2012/10/01/).
> The way you use round is wrong you need to supply two arguments ('x' and 'digits'), Rcpp::round just wrap Rf_fround 
>  (which is an alias for fround) in Rmath.h so you can check in this file the right signature.
> 
> 
> #include <Rcpp.h>
> using namespace Rcpp ;
> 
> // [[Rcpp::export]]
> NumericVector h1(int samp, int wind){
>     return round(runif(samp*3)* wind, 0);
> 
> }
> 
> 
> Hope this help
> 
> 
> 
> 
> 
> On Tue, Mar 4, 2014 at 11:30 AM, Hideyoshi Maeda <hideyoshi.maeda at gmail.com> wrote:
> Hi Rcpp devel list
> 
> I am trying to run the following code but for some reason it says that there is "no matching function for call to ‘round’"
> 
> #include <Rcpp.h>
> using namespace Rcpp;
> 
> // [[Rcpp::export]]
> Rcpp::IntegerVector h1(int samp, int wind){
>   return round(runif(samp*3)*wind);
> }
> 
> I thought round was part of Rcpp sugar? is it not?
> 
> thanks
> 
> 
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
> 
> 
> 
> -- 
> Ahmadou H. DICKO
> statistician economist (Ingénieur Statisticien Économiste)
> PhD candidate in Climate change economics
> Faculty of economics and managment - Cheikh Anta Diop University
> West African Science Service Center on Climate Change and Adaptated Land Use (WASCAL)
> Center for Development Research (ZEF) - University of Bonn 
> email : ahmadou.dicko at ucad.edu.sn
> twitter : @dickoah
> github : github/dickoa
> tel : +221 33 827 55 16
> portable: +221 77 123 81 69
> 
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel



More information about the Rcpp-devel mailing list