[Rcpp-devel] Returning an arma vec
1. This returns a matrix rather than a vector: -- start of file teste.cpp --- #include // [[Rcpp::depends(RcppArmadillo)]] using namespace arma; using namespace Rcpp; // [[Rcpp::export]] NumericVector teste(const vec& x) { vec v = x.subvec(1, 2); // x return wrap(v); // x } /*** R teste(1:4) */ --- end of file teste.cpp --- Now run in R: > sourceCpp("teste.cpp", rebuild = TRUE) > teste(1:4) [,1] [1,]2 [2,]3 2. If we replace the lines marked // x with return wrap(x.subvec(1, 2)); then it fails with a compiler error. error: cannot convert 'const arma::subview_col' to 'SEXP' in initialization -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com ___ 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
Re: [Rcpp-devel] Returning an arma vec
This is known, documented / has been discussed before, and hard to change now given that 100 CRAN packages depend on RcppArmadillo and its existing interface. You could write your own converter to SEXP and use that. Dirk On 3 December 2014 at 11:59, Gabor Grothendieck wrote: | 1. This returns a matrix rather than a vector: | | -- start of file teste.cpp --- | #include | // [[Rcpp::depends(RcppArmadillo)]] | | using namespace arma; | using namespace Rcpp; | | // [[Rcpp::export]] | NumericVector teste(const vec& x) { | vec v = x.subvec(1, 2); // x | return wrap(v); // x | } | /*** R | teste(1:4) | */ | --- end of file teste.cpp --- | | Now run in R: | | > sourceCpp("teste.cpp", rebuild = TRUE) | | > teste(1:4) | [,1] | [1,]2 | [2,]3 | | | 2. If we replace the lines marked // x with | |return wrap(x.subvec(1, 2)); | | then it fails with a compiler error. | | error: cannot convert 'const arma::subview_col' to 'SEXP' in | initialization | | | -- | Statistics & Software Consulting | GKX Group, GKX Associates Inc. | tel: 1-877-GKX-GROUP | email: ggrothendieck at gmail.com | ___ | 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 -- http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org ___ 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
Re: [Rcpp-devel] Returning an arma vec
Envoyé de mon iPhone > Le 3 déc. 2014 à 17:59, Gabor Grothendieck a écrit : > > 1. This returns a matrix rather than a vector: > > -- start of file teste.cpp --- > #include > // [[Rcpp::depends(RcppArmadillo)]] > > using namespace arma; > using namespace Rcpp; > > // [[Rcpp::export]] > NumericVector teste(const vec& x) { > vec v = x.subvec(1, 2); // x > return wrap(v); // x > } > /*** R > teste(1:4) > */ > --- end of file teste.cpp --- > > Now run in R: > >> sourceCpp("teste.cpp", rebuild = TRUE) > >> teste(1:4) > [,1] > [1,]2 > [2,]3 > > > 2. If we replace the lines marked // x with > > return wrap(x.subvec(1, 2)); > > then it fails with a compiler error. > > error: cannot convert 'const arma::subview_col' to 'SEXP' in > initialization This should be easy/trivial to fix for someone with the right skills. Romain > > -- > Statistics & Software Consulting > GKX Group, GKX Associates Inc. > tel: 1-877-GKX-GROUP > email: ggrothendieck at gmail.com > ___ > 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 ___ 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
Re: [Rcpp-devel] Returning an arma vec
On 3 December 2014 at 11:14, Dirk Eddelbuettel wrote: | | This is known, documented / has been discussed before, and hard to change now | given that 100 CRAN packages depend on RcppArmadillo and its existing interface. | | You could write your own converter to SEXP and use that. That said, I am no big fan either of the current behaviour you singled out. Maybe we could plan for a change, add a loud warning in X months and then phase out the current behaviour in Y months with Y >= 2 * X. So if someone wants to propose a plan, I am sure a few of us would review it.. Dirk -- http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org ___ 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
Re: [Rcpp-devel] Returning an arma vec
On 3 December 2014 at 18:30, Romain Francois wrote: | > 2. If we replace the lines marked // x with | > | > return wrap(x.subvec(1, 2)); | > | > then it fails with a compiler error. | > | > error: cannot convert 'const arma::subview_col' to 'SEXP' in | > initialization | | This should be easy/trivial to fix for someone with the right skills. Sure. Maybe Gabor wants to give it a try. Dirk -- http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org ___ 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
Re: [Rcpp-devel] Returning an arma vec
You just need to put a new template specialization of "wrap" for the subview_col class in RcppArmadilloWrap.h based on the existing one for the subview class. And throw in one for subview_row for good measure. Martyn From: rcpp-devel-boun...@lists.r-forge.r-project.org [rcpp-devel-boun...@lists.r-forge.r-project.org] on behalf of Dirk Eddelbuettel [e...@debian.org] Sent: 03 December 2014 19:25 To: Romain Francois Cc: rcpp-devel@lists.r-forge.r-project.org Subject: Re: [Rcpp-devel] Returning an arma vec On 3 December 2014 at 18:30, Romain Francois wrote: | > 2. If we replace the lines marked // x with | > | > return wrap(x.subvec(1, 2)); | > | > then it fails with a compiler error. | > | > error: cannot convert 'const arma::subview_col' to 'SEXP' in | > initialization | | This should be easy/trivial to fix for someone with the right skills. Sure. Maybe Gabor wants to give it a try. Dirk -- http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org ___ 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 --- This message and its attachments are strictly confidential. If you are not the intended recipient of this message, please immediately notify the sender and delete it. Since its integrity cannot be guaranteed, its content cannot involve the sender's responsibility. Any misuse, any disclosure or publication of its content, either whole or partial, is prohibited, exception made of formally approved use --- ___ 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