Re: [Rcpp-devel] Code review for xtensor R bindings
Hi, Instead of doing that: const int vtype = traits::r_sexptype_traits::rtype; SEXP shape_sxp = Rf_allocVector(vtype, shape.size()); Perhaps your rxarray object could hold an IntegerVector. Also not quite sure why you use the first line at all, which does not depend on T, so vtype is always going to be INTSXP. Also, you should avoid using std::cout in https://github.com/QuantStack/xtensor-r/blob/master/src/rcpp_hello_xtensor.cpp#L14 <https://github.com/QuantStack/xtensor-r/blob/master/src/rcpp_hello_xtensor.cpp#L14> You can use Rcpp::Rcout instead, or Rprintf. > And the memory is going to be freed again, at some point. And calling > Rcpp_ReleaseObject(m_sexp) would also clear the shape_sxp "attribute", right? The shape_sxp object you create here (and don’t protect) https://github.com/QuantStack/xtensor-r/blob/master/inst/include/xtensor-r/rxarray.hpp#L152 <https://github.com/QuantStack/xtensor-r/blob/master/inst/include/xtensor-r/rxarray.hpp#L152> Is probably duplicated here: https://github.com/QuantStack/xtensor-r/blob/master/inst/include/xtensor-r/rxarray.hpp#L160 <https://github.com/QuantStack/xtensor-r/blob/master/inst/include/xtensor-r/rxarray.hpp#L160> As part of allocArray’s business: https://github.com/wch/r-source/blob/d60c742aa8acc764874db87e3c748e27986e1134/src/main/array.c#L259 <https://github.com/wch/r-source/blob/d60c742aa8acc764874db87e3c748e27986e1134/src/main/array.c#L259> Romain > Le 7 juin 2017 à 03:01, Wolf Vollprecht <w.vollpre...@gmail.com> a écrit : > > Ok, I think I got the idea. > > In the R->xtensor bindings, we always work directly on memory allocated > through R (either passed in from R or allocated from C++ code). > > The review-relevant lines are really only ~10 lines: > https://github.com/QuantStack/xtensor-r/blob/master/inst/include/xtensor-r/rxarray.hpp#L145 > > <https://github.com/QuantStack/xtensor-r/blob/master/inst/include/xtensor-r/rxarray.hpp#L145> > > const int vtype = traits::r_sexptype_traits::rtype; > SEXP shape_sxp = Rf_allocVector(vtype, shape.size()); > > int* r_shape = INTEGER(shape_sxp); > // set shape values ... > m_sexp = Rf_allocArray(SXP, shape_sxp); > > So afterwards, the idea would be to make a call to > > Rcpp_PreserveObject(m_sexp); > > right? And if the destructor of the object is called (and the object is owned > from C++) we would just call > > Rcpp_ReleaseObject(m_sexp); > > And the memory is going to be freed again, at some point. And calling > Rcpp_ReleaseObject(m_sexp) would also clear the shape_sxp "attribute", right? > > Thanks for your reply! > > Wolf > > > 2017-06-06 16:27 GMT-07:00 Dirk Eddelbuettel <e...@debian.org > <mailto:e...@debian.org>>: > > On 6 June 2017 at 17:06, Dirk Eddelbuettel wrote: > | The general idea when working with R objects is that > | > | -- on the way in from R to the C++ functions we construct object such that > | the existing memory (from R) is used; one example is how RcppArmadillo > | uses the 'advanced' constructors of Armadillo allowing to operate > | without copies; hence R managed memory is used while C++ functions are > | called; in general this side of the conversion is the templates as<>() > | converters; > | > | -- on the way back we use the *alloc functions from the C-level API of R > to > | construct objects that use memory from R's pool, once we return these > | objects to R as SEXP they are indistinguishable to R from its own; > these > | are the wrap() functions (and I think we may make on occassion make > "one > | final copy" at his level, but I'd have to double-check). > > Actually, let me rephrase: "in most cases not involving native R types" do we > make one copy at the return. > > The general approach is iterator based, see internal/wrap.h. But there is a > lot of template magic... > > Dirk > > | I haven't had a chance to look at what Wes is doing with Apache Arrow, and > | what is happening with xtensor -- so thanks for getting the ball rolling. > | > | Dirk > | > | -- > | http://dirk.eddelbuettel.com <http://dirk.eddelbuettel.com/> | > @eddelbuettel | e...@debian.org <mailto:e...@debian.org> > | ___ > | Rcpp-devel mailing list > | Rcpp-devel@lists.r-forge.r-project.org > <mailto:Rcpp-devel@lists.r-forge.r-project.org> > | https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel > <https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel> > > -- > http://dirk.eddelbuettel.com <http://dirk.eddelbuettel.
Re: [Rcpp-devel] starter
This looks like a copy and paste mistake. I can definitely see this line on the slide 57: RMatrix output; Anyway, the example is there: http://gallery.rcpp.org/articles/parallel-matrix-transform/ <http://gallery.rcpp.org/articles/parallel-matrix-transform/> Romain > Le 31 mai 2017 à 12:42, f.k...@mailbox.org a écrit : > > Thanks Romain, > > this error is fine now, however, now I run into new… > I took the example code from this > <http://dirk.eddelbuettel.com/papers/rcpp_rfinance_may2015.pdf> presentation > of Dirk > > > > Rcpp::sourceCpp("src/par_example.cpp") > par_example.cpp:26:21: error: member initializer 'output' does not name a > non-static data member or base class > : input(input), output(output) {} > ^~ > par_example.cpp:31:5: error: use of undeclared identifier 'output' > output.begin() + begin, > ^ > 2 errors generated. > make: *** [par_example.o] Error 1 > > > Hope this is as easily solved as the before error. > > Cheers, Franz > > > > >> On 31 May 2017, at 12:26, Romain Francois <rom...@r-enthusiasts.com >> <mailto:rom...@r-enthusiasts.com>> wrote: >> >> You can add this somewhere on top of your cpp file >> >> // [[Rcpp::depends(RcppParallel)]] >> >> Romain >> >>> Le 31 mai 2017 à 12:22, f.k...@mailbox.org <mailto:f.k...@mailbox.org> a >>> écrit : >>> >>> Hi all, >>> >>> I am very new to Rcpp and I wrote a function which I now want to >>> parallelize. >>> The function is working fine, and is much faster than in R, however, it >>> really is slow for bigger datasets. >>> >>> Since the function is running I don’t need to explain what it does, >>> however, it is has >>> 3 nested for loops. It loops through columns and within each column if >>> loops through the rows and in a third loop produces pair comparisons… >>> >>> So the parallelisation should parallelize the column loop. >>> >>> I found the RcppParallel package and for the beginning wanted to run on of >>> the example to understand the >>> workflow first. However, I already have issues running the code below: >>> >>> following is sourced with: Rcpp::sourceCpp("src/par_example.cpp") >>> However, I get the error: >>> >>> par_example.cpp:6:10: fatal error: 'RcppParallel.h' file not found >>> #include >>> ^ >>> 1 error generated. >>> make: *** [par_example.o] Error 1 >>> >>> I would much appreciate if someone could give me a start with this! >>> >>> Cheers, >>> Franz >>> >>> >>> >>> #include >>> >>> using namespace Rcpp; >>> #include >>> #include >>> #include >>> >>> // [[Rcpp::export]] >>> NumericMatrix matrixSqrt(NumericMatrix orig) { >>> // allocate the matrix we will return >>> NumericMatrix mat(orig.nrow(), orig.ncol()); >>> // transform it >>> std::transform(orig.begin(), orig.end(), mat.begin(), ::sqrt); >>> // return the new matrix >>> return mat; >>> } >>> >>> >>> using namespace RcppParallel; >>> struct SquareRoot : public Worker { >>> const RMatrix input; >>> // source matrix RMatrix output; // destination matrix >>> // initialize with source and destination >>> SquareRoot(const NumericMatrix input, NumericMatrix output) >>> : input(input), output(output) {} >>> // take the square root of the range of elements requested >>> void operator()(std::size_t begin, std::size_t end) { >>> std::transform(input.begin() + begin, >>> input.begin() + end, >>> output.begin() + begin, >>> ::sqrt); >>> } >>> }; >>> >>> // [[Rcpp::export]] >>> NumericMatrix parallelMatrixSqrt(NumericMatrix x) { >>> // allocate the output matrix >>> NumericMatrix output(x.nrow(), x.ncol()); >>> // SquareRoot functor (pass input and output matrixes) >>> SquareRoot squareRoot(x, output); >>> // call parallelFor to do the work >>> parallelFor(0, x.length(), squareRoot); >>> // return the output matrix >>> return output; } >>> >>> >>> >>> ___ >>> Rcpp-devel mailing list >>> Rcpp-devel@lists.r-forge.r-project.org >>> <mailto:Rcpp-devel@lists.r-forge.r-project.org> >>> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel >>> <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] starter
You can add this somewhere on top of your cpp file // [[Rcpp::depends(RcppParallel)]] Romain > Le 31 mai 2017 à 12:22, f.k...@mailbox.org a écrit : > > Hi all, > > I am very new to Rcpp and I wrote a function which I now want to parallelize. > The function is working fine, and is much faster than in R, however, it > really is slow for bigger datasets. > > Since the function is running I don’t need to explain what it does, however, > it is has > 3 nested for loops. It loops through columns and within each column if loops > through the rows and in a third loop produces pair comparisons… > > So the parallelisation should parallelize the column loop. > > I found the RcppParallel package and for the beginning wanted to run on of > the example to understand the > workflow first. However, I already have issues running the code below: > > following is sourced with: Rcpp::sourceCpp("src/par_example.cpp") > However, I get the error: > > par_example.cpp:6:10: fatal error: 'RcppParallel.h' file not found > #include > ^ > 1 error generated. > make: *** [par_example.o] Error 1 > > I would much appreciate if someone could give me a start with this! > > Cheers, > Franz > > > > #include > > using namespace Rcpp; > #include > #include > #include > > // [[Rcpp::export]] > NumericMatrix matrixSqrt(NumericMatrix orig) { > // allocate the matrix we will return > NumericMatrix mat(orig.nrow(), orig.ncol()); > // transform it > std::transform(orig.begin(), orig.end(), mat.begin(), ::sqrt); > // return the new matrix > return mat; > } > > > using namespace RcppParallel; > struct SquareRoot : public Worker { > const RMatrix input; > // source matrix RMatrix output; // destination matrix > // initialize with source and destination > SquareRoot(const NumericMatrix input, NumericMatrix output) > : input(input), output(output) {} > // take the square root of the range of elements requested > void operator()(std::size_t begin, std::size_t end) { > std::transform(input.begin() + begin, > input.begin() + end, > output.begin() + begin, > ::sqrt); > } > }; > > // [[Rcpp::export]] > NumericMatrix parallelMatrixSqrt(NumericMatrix x) { > // allocate the output matrix > NumericMatrix output(x.nrow(), x.ncol()); > // SquareRoot functor (pass input and output matrixes) > SquareRoot squareRoot(x, output); > // call parallelFor to do the work > parallelFor(0, x.length(), squareRoot); > // return the output matrix > return output; } > > > > ___ > 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] Rcpp sugar for double?
Hello, Functions in sugar only apply to vectors. For a single value, you’d have to use the dnorm function in the R:: namespace: // [[Rcpp::export]] double test6(double x){ double y = R::dnorm(x,5.0,2.0,true); return y; } > test6(3) [1] -2.112086 > dnorm(3, mean = 5, sd = 2, log = TRUE) [1] -2.112086 Romain > Le 22 févr. 2017 à 15:58, Eridk Poliruyt <ep19...@gmail.com> a écrit : > > Hi, I just tried to calculate the density of a normal variable using dnorm. I > found that if the input is of type NumericVector, then it was fine. But if > the input is of type double, it yielded error in compilation. For example: > > // [[Rcpp::export]] > NumericVector test5(NumericVector x) > { > NumericVector y = dnorm(x,5.0,2.0,true); > return(y); > } > > and > > // [[Rcpp::export]] > double test6(double x) > { > double y = dnorm(x,5.0,2.0,true); > return(y); > } > > May I ask why and how can I calculate this density (and call other common > functions like dbeta, dt, beta, gamma, lbeta, lgamma, etc...) on double input? > > Many thanks, > Eridk > ___ > 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] Rcpp Timer
It made more sense to track times since an origin, esp when you might use several timers in case you use multiple threads. > Le 30 déc. 2016 à 13:37, Dirk Eddelbuettel <e...@debian.org> a écrit : > > > On 29 December 2016 at 11:25, Jonathan Christensen wrote: > | Hi Kaspar and Dirk, > | > | It is indeed cumulative. Previously (presumably when that gallery page was > | written) it was not cumulative, but Romain Francois changed the behavior of > the > | step() function several years ago, in this commit: > https://github.com/RcppCore/ > | Rcpp/commit/e295b2b178de55291e63705966368404bb0ce5e1. > > Nice catch. > > | There is no indication or reasoning about changing the behavior, so it may > be > | that making it cumulative was unintentional. > > Let's presume it was intentional to the author of the change -- but as you > rightly point out, it did of course change and reverse previous behaviour. > > We could easily add a toggle to the constructor to get an either/or behaviour. > > 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 ___ 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] Rcpp ISNAN slower than C ISNAN?
I’d be interesting to see what this more C++idomatic version would perform nanCount = std::count_if( x.begin(), x.end(), ISNAN ) ; Because despite all the inlining efforts that has been put in the implementation of NumericVector, its operator[] might not perform as well as using [] on a double*. Romain > Le 13 déc. 2016 à 12:38, Johannes Kruisselbrink <johan...@kruisselbrink.eu> a > écrit : > > Here is a further reduced example (see below). Now it is a function to count > NaNs in a vector, and it shows the same behaviour. Code is also available at > https://github.com/jwkruisselbrink/rcpp-timings/tree/master/minimal. > > Regarding your question: > | Why not drop data and codes and use sData1(i,k) - sData2(j,k) > > Well, I wanted to rule out that Rcpp sugar was causing the slowdown. If it > isn't we'll put it back in after having a fix for this issue. > > /=== call.c ===/ > > #include > #include > > SEXP CountNans(SEXP sX, SEXP sLength) { > int i, n = *INTEGER(sLength); > int *nanCount; > double *x = REAL(sX); > > SEXP output = PROTECT(allocVector(INTSXP, 1)); > nanCount = INTEGER(output); > *nanCount = 0; > for (i = 0; i < n; i++) { >if (ISNAN(x[i])) { > *nanCount += 1; >} > } > UNPROTECT(1); > return output; > } > > /=== rcpp.cpp ===/ > > #include > #include > using namespace Rcpp; > > // [[Rcpp::export]] > int CountNans(NumericVector x) { > int n = x.length(); > int nanCount = 0; > for (int i = 0; i < n; i++) { >if (ISNAN(x[i])) { > nanCount++; >} > } > return nanCount; > } > > /=== R code ===/ > > library(Rcpp) > library(microbenchmark) > library(ggplot2) > > sourceCpp('rcpp.cpp') > > if (is.loaded(paste("call", .Platform$dynlib.ext, sep=""))) { > dyn.unload(paste("call", .Platform$dynlib.ext, sep="")) > } > system(paste("R CMD SHLIB call.c", sep="")) > dyn.load(paste("call", .Platform$dynlib.ext, sep="")) > > n <- as.integer(10) > x <- rnorm(n) > mb <- microbenchmark( > rcpp <- CountNans(x), > call <- .Call("CountNans", x, n), > times = 1 > ) > > autoplot(mb) > > > ___ > 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] Specify Rcpp header location in Makevars
You need LinkingTo: Rcpp As per the current documentation. Romain Envoyé de mon iPhone Le 29 juil. 2015 à 17:19, jsmith5...@yahoo.com jsmith5...@yahoo.com a écrit : Hi, Is there a way to automatically specify the location of the Rcpp include directory (for Rcpp.h) in Makevars? In my Makevars, I use the following compile command: %.o: %.cpp $(cpp_sources) $(CXX) $(PKG_CXXFLAGS) $ I also specified Imports: Rcpp in DESCRIPTION, but it does not appear to automatically add the right flags to the compile command. I am looking for something that could work similarly to Rscript -e Rcpp:::LdFlags(), which used to export the Rcpp library flags. Any ideas are greatly appreciated! Thanks! Lutz ___ 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] When calling same Rcpp function several times different results are returned
Or just use a std::vectordouble for sg. That should do it. Romain Envoyé de mon iPhone Le 14 juil. 2015 à 13:21, JJ Allaire jj.alla...@gmail.com a écrit : The examples in the RcppParallel documentation assume that access to vectors and matrixes are *aligned* (i.e. fall into neat buckets whereby reading and writing doesn't overlap between worker instances). Your example appears to access arbitrary elements of sg (depending on what's passed in gi) which probably creates overlapping reads/writes. You should also study the documentation for join carefully. There's nothing incorrect about RcppParallel's behavior here, rather you need to think more carefully about the access patterns of your data and how they might conflict. You may need to introduce locking to overcome the conflicts, which in turn could kill the performance benefit you gain from parallelism. No easy answers here :-\ On Tue, Jul 14, 2015 at 7:15 AM, Danas Zuokas danas.zuo...@gmail.com wrote: Yes it is the same question on SO and I did consider RHertel's comments. But this problem (sums by group id) is not parallelFor it is parallelReduce: I split vector, calculate sums and then aggregate those sums. Please correct me if I am wrong. 2015-07-14 13:54 GMT+03:00 Dirk Eddelbuettel e...@debian.org: On 14 July 2015 at 09:25, Danas Zuokas wrote: | I have written parallel implementation of sums in groups using RcppParallel. Isn't this the same question as http://stackoverflow.com/questions/31318419/when-calling-same-rcpp-function-several-times-different-results-are-returned You got some excellent comments there by SO user 'RHertel'. Did you consider those? Dirk | // [[Rcpp::depends(RcppParallel)]] | #include Rcpp.h | #include RcppParallel.h | using namespace Rcpp; | using namespace RcppParallel; | | struct SumsG: public Worker | { | const RVectordouble v; | const RVectorint gi; | | RVectordouble sg; | | SumsG(const NumericVector v, const IntegerVector gi, NumericVector sg): v(v), gi(gi), sg(sg) {} | SumsG(const SumsG p, Split): v(p.v), gi(p.gi), sg(p.sg) {} | | void operator()(std::size_t begin, std::size_t end) { | for (std::size_t i = begin; i end; i++) { | sg[gi[i]] += v[i]; | } | } | | void join(const SumsG p) { | for(std::size_t i = 0; i sg.length(); i++) { | sg[i] += p.sg[i]; | } | } | }; | | // [[Rcpp::export]] | List sumsingroups(NumericVector v, IntegerVector gi, int ni) { | NumericVector sg(ni); | SumsG p(v, gi, sg); | parallelReduce(0, v.length(), p); | | return List::create(_[sg] = p.sg); | } | | It compiles using Rcpp::sourceCpp. Now when I call it from R sumsingroups(1:10, | rep(0:1, each = 5), 2) several times I get the right answer (15 40) and then | something different (usually some multiplicative of the right answer). Running | | | res - sumsingroups(1:10, rep(0:1, each = 5), 2) | for(i in 1:1000) { | tmp - sumsingroups(1:10, rep(0:1, each = 5), 2) | if(res[[1]][1] != tmp[[1]][1]) break | Sys.sleep(0.1) | } | | breaks at random iteration returning | | $sg | [1] 60 160 | | or | | $sg | [1] 30 80 | | I am new to Rcpp and RcppParallel and do not know what could cause such | behavior. | | Things that did not help: | | 1. Added for (std::size_t i = 0; i sg.length(); i++) sg[i] = 0; to both of | constructors. | 2. Changed names so that they are different in Worker definition and in | function implementation. | | ___ | 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 ___ 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] RcppParallel on Solaris
Le 13 avr. 2015 à 14:03, JJ Allaire jj.alla...@gmail.com a écrit : That's excellent I just updated the branch to reflect this change and also successfully ran the tests on the Solaris config that you provided me access to. I'll have to take a closer look at the warnings. One other issue that needs to be resolved prior to the next submission to CRAN revolves around pedantic warnings on Debian testing that prohibit long long (used by both TinyThread and TBB). The easy workaround is SystemRequirements: C++11 however this will mean that package won't compile on pre-Mavericks Macs (~30% of all Macs) nor RedHat/CentOS systems. Perhaps I can modify TinyThread and TBB to no longer use long long but I'll need to do this very carefully. FWIW tbb with C++11, in particular lambdas is awesome On Sun, Apr 12, 2015 at 10:30 PM, Gábor Csárdi csardi.ga...@gmail.com wrote: Hi JJ all, I had some time, had an idea, and made it to work. The problem was that TBB was not compiled with the same flags as R and the rest of the R package, so just had to find what is the difference that is incompatible. It is simple, you need to compile TBB with -library=stlport4 So if you change line 34 in SunOS.suncc.inc to CPLUS = CC -library=stlport4 then it compiles and installs fine. What's even better, the tests run fine, too. They spit out a lot of compiler warnings, but they all pass. Best, Gabor On Wed, Apr 8, 2015 at 11:38 AM, Gábor Csárdi csardi.ga...@gmail.com wrote: Ok, the server seems to work. JJ, I'll send you a private email. If anyone wants access, please email me in private. Remember that this is just a mac mini, so it might not be super fast. It seems fast enough for a single user, though. Gabor On Tue, Apr 7, 2015 at 7:17 PM, Gábor Csárdi csardi.ga...@gmail.com wrote: On Tue, Apr 7, 2015 at 6:50 PM, Jeroen Ooms jeroeno...@gmail.com wrote: [...] So that's why I thought they probably use GCC for packages that don't work with Solaris Studio. I see. That would indeed make sense. G. ___ 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] On Developing Header Packages
I would definitely second that. This eliminates a whole class of hard to deal with issues. Even Rcpp IMO should really just be header only. Romain Envoyé de mon iPhone Le 7 avr. 2015 à 20:51, JJ Allaire jj.alla...@gmail.com a écrit : I think that header-only packages (where possible) are definitely preferable within the R package ecosystem because it allows you to sidestep a lot of build configuration and runtime linking complexity. The rub is that some libraries simply can't be made header-only, especially if they make use of static data. I was able to convert the TinyThread library to header-only by simply prefacing all function/method definitions with the inline keyword. However that was a pretty small library so I'm not sure you'd have the same easy time of it with a larger library like clBLAS. On Tue, Apr 7, 2015 at 2:37 PM, Charles Determan cdeterma...@gmail.com wrote: This is probably the best place I can think of to ask this question if perhaps not completely on topic. Some quick context: I am exploring GPGPU computing and with my 'open-source' mindset I quickly gravitated to using OpenCL. Thankfully, many wonderful programmers have already begun creating libraries to make this language better and faster. One such library is the clBLAS library which essentially implements BLAS routines for OpenCL enabled devices. Naturally, I would like to use this library but I don't like the idea of telling users to install a dependency outside of R and would rather have them install another package. Therefore, I have it in my head to create a header package for the clBLAS library to be used by anyone exploring OpenCL programming within R. This leads me to my two general questions that I hope others can comment. 1. What are developers thoughts regarding the 'packaging' of various C++ header libraries? I know this has be very successfully done with the 'BH' package but is this considered an exception or an example? 2. If it is encouraged to create such header packages are there any guidelines or standards that should be followed? Is there an expected structure? I can look at the 'BH' package and go from there but it would be nice if the R(cpp) community had some collective opinion about this. Regards, Charles ___ 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 ___ 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] RInside vs Statconndcom
RInside is not really about performance. it’s just a way to easily embed R in a C++ application. Le 4 avr. 2015 à 19:54, Jodi Jhouranda Siregar 11.6...@stis.ac.id a écrit : I'm on my project developing user interface for r. I dicided to use rinside. And i want to know which is better in term of peformance, RInside or statconndcom ? For the reason why using RInside is better than statconndcom. Thanks. ___ 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] assert() for Rcpp?
Envoyé de mon iPhone Le 18 févr. 2015 à 17:31, JJ Allaire jj.alla...@gmail.com a écrit : We *can* call Rf_error from C++ code, but when we do it bypasses all C++ destructors on the stack, so we don't do it so as not leak memory and otherwise have deterministic behavior around construction/destruction. You'll notice in Dirk's example that there are no C++ objects on the stack when he calls Rf_error. This would still bypass the dror for the RNGscope object automatically added by Rcpp::export right ? The core idea in Rcpp is to use exceptions to get high enough in the stack that there are no more destructors. On Wed, Feb 18, 2015 at 9:08 AM, Sparapani, Rodney rspar...@mcw.edu wrote: On Tue, 2015-02-17 at 17:53 -0700, JJ Allaire wrote: One piece of immediate feedback on your initial implementation: you can't call Rf_error from C++ code (as it will bypass C++ destructors on the stack). Rather, you should throw Rcpp::exception. Hi JJ: Ok, this puzzles me. We can't call Rf_error from C++ code, but we can call it from within the exception handler, right? It would seem so since Dirk has written a nice gallery post that does it that way... http://gallery.rcpp.org/articles/intro-to-exceptions Just my $0.02, but I would stick to exceptions and avoid assert in C++. Rodney ___ 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 ___ 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] String encoding (UTF-8 conversion)
That is similar to a path i've followed in Rcpp11/Rcpp14. What's really missing in R is api access to strings, e.g testing for equality of two CHARSXP, comparing them, ... This causes all sorts of problems with dplyr. Romain Le 16 déc. 2014 à 06:00, Jeroen Ooms jeroen.o...@stat.ucla.edu a écrit : On Thu, Dec 11, 2014 at 12:24 PM, Jeroen Ooms jeroen.o...@stat.ucla.edu wrote: I'm interfacing a c++ library which assumes strings are UTF-8. However strings from R can have various encodings. It's not clear to me how I need to account for that in Rcpp. Follow-up on this: from what I have found, there is currently no string type that is unambiguous across platforms and locales (other than the actual STRSXP). If the native locale uses UTF8 than all is fine, but we can not assume that in R. Here is a little script that illustrates the various combinations I tried and the results on Windows: https://gist.github.com/jeroenooms/9edf97f873f17a4ce5d3. Assuming that each of these cases are intended behavior, perhaps we could introduce an additional string type e.g. Rcpp::UTF8String. The mapping from STRSXP to Rcpp::UTF8String would use translateCharUTF8(STRING_ELT(x, 0)) and the mapping Rcpp::UTF8String back to STRSXP would use SET_STRING_ELT(out, 0, mkCharCE(olds, CE_UTF8)). That would allow for defining c++ functions operating on UTF8 strings which will work as expected across platforms and locales. ___ 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] Rcpp Parallel and Rcpp Armadillo
Some pointers. When you use an arma::mat passed by value in an Rcpp::export, this means copying all of the data of the underlying R object into armadillo. I’d suggest you use a reference to const to avoid that, i.e. mat contrib1(const mat X1) { … } Then in pQnorm, you do: NumericMatrix x_q = Rcpp::asRcpp::NumericMatrix(wrap(xx_q)); That is yet again, copying all of the data from the arma::mat into an Rcpp matrix. You then return a arma::mat, which data is copied implicitly as the return of contrib1. I’d suggest you do all this without armadillo, which you don’t really use except for inducing a lot of extra copies of data. To anwser your last question, R uses a garbage collector, so the memory is not automatically reclaimed as soon as it is no longer needed. Hope this helps. Romain Le 10 déc. 2014 à 15:01, Maxime To maxime...@outlook.fr a écrit : Hi, I changed the function as indicated by Dirk and I modify the functions and the program does work now. However, I am still puzzled by the memory use of the program. when I run a loop of my function in R as in the code below, it seems that the program does not free the memory used in the previous iterations... which is annoying when I need to optimize on my final object. So I was wondering whether it was a question of declaration of object in my code? -- sourceCpp(Rcpp/test.cpp) # qwe = matrix(runif(1), nrow = 100) a = contrib1(qwe) b = qnorm(qwe) a - b for (i in 1:2) a = contrib1(qwe) -- // test.cpp #include RcppArmadillo.h #include cmath #include algorithm #include RcppParallel.h #include boost/math/distributions/inverse_gaussian.hpp using namespace Rcpp; using namespace arma; using namespace std; using namespace RcppParallel; // [[Rcpp::depends(RcppArmadillo, RcppParallel, BH)]] double qnorm_f(const double x_q) { boost::math::normal s; return boost::math::quantile(s, x_q); }; struct Qnorm : public Worker { // source matrix const RMatrixdouble input_q; // destination matrix RMatrixdouble output_q; // initialize with source and destination Qnorm(const NumericMatrix input_q, NumericMatrix output_q) : input_q(input_q), output_q(output_q) {} // take the Pnorm of the range of elements requested void operator()(std::size_t begin, std::size_t end) { std::transform(input_q.begin() + begin, input_q.begin() + end, output_q.begin() + begin, ::qnorm_f); } }; mat pQnorm(mat xx_q) { NumericMatrix x_q = Rcpp::asRcpp::NumericMatrix(wrap(xx_q)); // allocate the output matrix const NumericMatrix output_q(x_q.nrow(), x_q.ncol()); // Pnorm functor (pass input and output matrices) Qnorm qnorm_temp(x_q, output_q); // call parallelFor to do the work parallelFor(0, x_q.length(), qnorm_temp); // return the output matrix mat outmat_q(output_q.begin(), output_q.nrow(),output_q.ncol()); return outmat_q; } // [[Rcpp::export]] mat contrib1(mat X1) { mat test= pQnorm(X1); mat results = test; return results; } -- Date: Tue, 9 Dec 2014 09:07:10 -0600 To: q...@umail.iu.edu mailto:q...@umail.iu.edu CC: maxime...@outlook.fr mailto:maxime...@outlook.fr; rcpp-devel@lists.r-forge.r-project.org mailto:rcpp-devel@lists.r-forge.r-project.org Subject: Re: [Rcpp-devel] Rcpp Parallel and Rcpp Armadillo From: e...@debian.org mailto:e...@debian.org On 9 December 2014 at 09:46, Qiang Kou wrote: | What do you mean by doesn't work ? Compiling error or the result is not | right? | | I just tried the code, and it seems the code can compile and work. I am generally very careful about calling back to anything related to R from functions to be parallelized. So for inline double f(double x) { return ::Rf_pnorm5(x, 0.0, 1.0, 1, 0); } I think going with an equivalent pnorm() function from Boost / Bh may be better. But I am shooting from my hip here as I have not had time to look at this, having been out way too late at a nice concert :) 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 ___ 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] Rcpp and ExternalPtr
You are looking for XPtr. https://github.com/RcppCore/Rcpp/blob/master/inst/include/Rcpp/XPtr.h It is a template class whose first parameter is the class of the raw pointer you are dealing with, let’s call it T. You can create an external pointer using something like : XPtrT xp( new T(...) ) ; This registers the default finalizer (which calls delete) to be executed when R garbage collects the R object. So you can send xp back to the R side. Then you can grab it back on the C++ side, e.g. as a parameter to a function: // [[Rcpp::export]] void foo( XPtrT xp ){ // here you can treat xp as a raw pointer, e.g. do xp-foo( ... ) ; } You can also set the finalizer yourself with a bit more work if you wanted to do something different than the default, e.g. void my_finalizer( T* obj ){ // whatever you need to do } typedef XPtrT, PreserveStorage, my_finalizer Bar ; If you deal with a pointer that you don’t own, i.e. you don’t handle its finalization for some reason, you can set the second parameter of the XPtr constructor from https://github.com/RcppCore/Rcpp/blob/master/inst/include/Rcpp/XPtr.h#L84 XPtrT xp( raw_ptr, false ) ; Romain Le 5 déc. 2014 à 08:45, Jeroen Ooms jeroen.o...@stat.ucla.edu a écrit : Does Rcpp provide some elegant way to let the R user manage persistent c++ objects that have no R type (e.g. internal handles or sessions of some sort)? In C, I would use R_MakeExternalPtr to create a ptr SEXP that the user can pass from one R function to another. This also makes it easy to add a finalizer with R_RegisterCFinalizerEx so that the garbage collector will automatically clean up the session/handle whenever user deletes the R object. Most Rcpp examples I have seen use function arguments with standard data types that are automatically mapped to R types. Does Rcpp have any special mechanics for managing external objects (pointers) from R which do not map to a SEXP type? Or do I have to fall back on Rinternals for this? ___ 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
Something like this: template typename T inline wrap( const arma::subview_coldouble x ){ return wrap( arma::MatT( x ) ) ; } (untested) This would still wrap it as a matrix though as this is what subview_col conceptually gives. The only downside is that this is somewhat inefficient as it would have to allocate memory for a arma::mat first and then copy that across to an Rcpp::Matrix … Romain Le 3 déc. 2014 à 22:41, Martyn Plummer plumm...@iarc.fr a écrit : 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_coldouble' 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
Re: [Rcpp-devel] Returning an arma vec
Envoyé de mon iPhone Le 3 déc. 2014 à 17:59, Gabor Grothendieck ggrothendi...@gmail.com a écrit : 1. This returns a matrix rather than a vector: -- start of file teste.cpp --- #include RcppArmadillo.h // [[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_coldouble' 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] Const correctness of NumericVector iterators
And now sent a pull request. Not sure this will be merged in with the new commandment that « Thou shalt not break abi ». See: https://github.com/RcppCore/Rcpp/pull/211 Romain Le 29 nov. 2014 à 13:52, Romain François rom...@r-enthusiasts.com a écrit : Promoted this to an issue on github. https://github.com/RcppCore/Rcpp/issues/209 Should not be very hard to fix, but this is indeed a bug. The code should not compile if Rcpp respected const correctness. Le 26 nov. 2014 à 14:20, Martyn Plummer plumm...@iarc.fr a écrit : This is related to David Shih's thread about modifying input arguments but I think it needs its own thread. I found a problem when I tried porting some Rcpp code to run outside of Rcpp by providing my own NumericVector implementation based on STL vectors. In Rcpp it is possible to obtain a non-constant iterator for a constant vector, whereas STL does not allow this. In particular, it is possible to modify a const NumericVector. The compiler allows this because the actual contents of the NumericVector are in auxiliary memory. But this breaks the abstraction of the NumericVector class. An example is given below. The sumsquares function calculates the sum of squares of a vector. Internally, it calls the workhorse function, which is declared to take a constant reference as an argument. So it looks safe to pass the input vector to workhorse without copying. However the implementation of workhorse does in fact alter the vector. ### BEGIN SS.cc #include Rcpp.h using Rcpp::NumericVector; static double workhorse(NumericVector const v); // [[Rcpp::export]] double sumsquares(NumericVector v) { //Since workhorse takes a constant reference we think we do not need //to copy v... return workhorse(v); } double workhorse(NumericVector const v) { double y = 0; for (NumericVector::iterator i = v.begin(); i != v.end(); ++i) { double x = *i; //... but this function does alter its argument x *= x; y += x; } return y; } ### END SS.cc In R we have library(Rcpp) sourceCpp(SS.cc) x - c(1,2,3) sumsquares(x) [1] 14 x #is modified [1] 1 4 9 Martyn --- 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 ___ 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] Const correctness of NumericVector iterators
Promoted this to an issue on github. https://github.com/RcppCore/Rcpp/issues/209 Should not be very hard to fix, but this is indeed a bug. The code should not compile if Rcpp respected const correctness. Le 26 nov. 2014 à 14:20, Martyn Plummer plumm...@iarc.fr a écrit : This is related to David Shih's thread about modifying input arguments but I think it needs its own thread. I found a problem when I tried porting some Rcpp code to run outside of Rcpp by providing my own NumericVector implementation based on STL vectors. In Rcpp it is possible to obtain a non-constant iterator for a constant vector, whereas STL does not allow this. In particular, it is possible to modify a const NumericVector. The compiler allows this because the actual contents of the NumericVector are in auxiliary memory. But this breaks the abstraction of the NumericVector class. An example is given below. The sumsquares function calculates the sum of squares of a vector. Internally, it calls the workhorse function, which is declared to take a constant reference as an argument. So it looks safe to pass the input vector to workhorse without copying. However the implementation of workhorse does in fact alter the vector. ### BEGIN SS.cc #include Rcpp.h using Rcpp::NumericVector; static double workhorse(NumericVector const v); // [[Rcpp::export]] double sumsquares(NumericVector v) { //Since workhorse takes a constant reference we think we do not need //to copy v... return workhorse(v); } double workhorse(NumericVector const v) { double y = 0; for (NumericVector::iterator i = v.begin(); i != v.end(); ++i) { double x = *i; //... but this function does alter its argument x *= x; y += x; } return y; } ### END SS.cc In R we have library(Rcpp) sourceCpp(SS.cc) x - c(1,2,3) sumsquares(x) [1] 14 x #is modified [1] 1 4 9 Martyn --- 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 ___ 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] Const correctness of NumericVector iterators
This is probably related to this: template int RTYPE struct r_vector_const_iterator { typedef typename storage_typeRTYPE::type* type ; }; There should be a const there somewhere. FWIW, more modern implementations of R/C++ are more safe on that issue: $ Rcpp11Script /tmp/martyn.cpp file33e7a74d9ba.cpp:18:33: error: cannot initialize a variable of type 'NumericVector::iterator' (aka 'double *') with an rvalue of type 'const_iterator' (aka 'const double *') for (NumericVector::iterator i = v.begin(); i != v.end(); ++i) { ^ ~ 1 error generated. make: *** [file33e7a74d9ba.o] Error 1 Error in dyn.load(basename(dynlib)) : unable to load shared object '/private/var/folders/k8/gmp11jks4hl_nwcnk82fbr8mgn/T/RtmpKvVUpq/file33e7a74d9ba.so': dlopen(/private/var/folders/k8/gmp11jks4hl_nwcnk82fbr8mgn/T/RtmpKvVUpq/file33e7a74d9ba.so, 6): image not found Calls: sourceCpp - Anonymous - dyn.load In addition: Warning message: running command '/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB 'file33e7a74d9ba.cpp'' had status 1 Execution halted If I change NumericVector::iterator to auto, I then get: $ Rcpp11Script /tmp/martyn.cpp file34f617c08b2.cpp:19:16: error: binding of reference to type 'double' to a value of type 'const double' drops qualifiers double x = *i; ^ ~~ 1 error generated. make: *** [file34f617c08b2.o] Error 1 Error in dyn.load(basename(dynlib)) : unable to load shared object '/private/var/folders/k8/gmp11jks4hl_nwcnk82fbr8mgn/T/Rtmp74ZJLp/file34f617c08b2.so': dlopen(/private/var/folders/k8/gmp11jks4hl_nwcnk82fbr8mgn/T/Rtmp74ZJLp/file34f617c08b2.so, 6): image not found Calls: sourceCpp - Anonymous - dyn.load In addition: Warning message: running command '/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB 'file34f617c08b2.cpp'' had status 1 Execution halted Hard compiler error/GOOD THING. Le 26 nov. 2014 à 14:20, Martyn Plummer plumm...@iarc.fr a écrit : This is related to David Shih's thread about modifying input arguments but I think it needs its own thread. I found a problem when I tried porting some Rcpp code to run outside of Rcpp by providing my own NumericVector implementation based on STL vectors. In Rcpp it is possible to obtain a non-constant iterator for a constant vector, whereas STL does not allow this. In particular, it is possible to modify a const NumericVector. The compiler allows this because the actual contents of the NumericVector are in auxiliary memory. But this breaks the abstraction of the NumericVector class. An example is given below. The sumsquares function calculates the sum of squares of a vector. Internally, it calls the workhorse function, which is declared to take a constant reference as an argument. So it looks safe to pass the input vector to workhorse without copying. However the implementation of workhorse does in fact alter the vector. ### BEGIN SS.cc #include Rcpp.h using Rcpp::NumericVector; static double workhorse(NumericVector const v); // [[Rcpp::export]] double sumsquares(NumericVector v) { //Since workhorse takes a constant reference we think we do not need //to copy v... return workhorse(v); } double workhorse(NumericVector const v) { double y = 0; for (NumericVector::iterator i = v.begin(); i != v.end(); ++i) { double x = *i; //... but this function does alter its argument x *= x; y += x; } return y; } ### END SS.cc In R we have library(Rcpp) sourceCpp(SS.cc) x - c(1,2,3) sumsquares(x) [1] 14 x #is modified [1] 1 4 9 Martyn --- 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 ___ 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] Indexing vector with x(i) and x[i] gives remarkable difference in computing time
Le 27 nov. 2014 à 13:22, Søren Højsgaard sor...@math.aau.dk a écrit : Dear all, By accident I noticed that indexing with x(i) and x[i] gives remarkable difference in computing time. For example: library(Rcpp) cppFunction(' IntegerVector insert1 (int n){ IntegerVector z(n); for (int i=0; in; ++i) z(i) = i; // NOTICE: using () return z; }') cppFunction(' IntegerVector insert2 (int n){ IntegerVector z(n); for (int i=0; in; ++i) z[i] = i; // NOTICE: using [] return z; }') Both functions work: n - 10; insert1(n); insert2(n) [1] 0 1 2 3 4 5 6 7 8 9 [1] 0 1 2 3 4 5 6 7 8 9 But notice this difference in computing time: n - 5 microbenchmark::microbenchmark( insert1(n), insert2(n) ) Unit: microseconds expr min lq mean median uq max neval cld insert1(n) 391.154 406.5500 416.9694 407.5005 421.1855 731.752 100 b insert2(n) 149.771 156.8045 189.9401 157.3745 163.0760 1204.635 100 a So using z(i) is more than twice as slow as using z[i]. This prompts me to ask: 1) Why is that? bounds checking. operator()(int i) checks that is i is between 0 and the length of the vector. 2) In the vignettes it is always [i] that are used for vectors. But why is it that (i,j) is then used for matrices. Wouldn't it be preferable if one could use both [] and () for indexing in both cases (and with the same speed) - or are there deeper reasons for this? No such thing as a operator[](int, int) in C++ so we had to use () Best regards Søren ___ 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] sugar: x+y and y+x gives different results when there are NA's in y
This has nothing to do with NA. It's just about the size difference. sugar does not make attempt at recycling. Your responsibility. Romain Le 22 nov. 2014 à 11:48, Søren Højsgaard sor...@math.aau.dk a écrit : Dear all, Came across this: #include Rcpp.h using namespace Rcpp; //[[Rcpp::export]] List sumxy(NumericVector x, NumericVector y){ NumericVector xy = x+y; NumericVector yx = y+x; return List::create(xy, yx); } /*** R x - c(1,3,5,7) y - c(NA,2,4,6,8) x+y y+x sumxy(x, y) */ x - c(1,3,5,7) y - c(NA,2,4,6,8) x+y [1] NA 5 9 13 9 y+x [1] NA 5 9 13 9 sumxy(x, y) [[1]] [1] NA 5 9 13 [[2]] [1] NA 5 9 13 8 Is this intentional? Apologies if this has been documented anywhere; was unable to find it. Regards Søren ___ 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] sugar: x+y and y+x gives different results when there are NA's in y
You get UB if the first is bigger than the second. Envoyé de mon iPhone Le 22 nov. 2014 à 14:30, Søren Højsgaard sor...@math.aau.dk a écrit : OK; thanks! Shall I read this such as the behaviour is undefined? Søren |-Original Message- |From: Romain Francois [mailto:rom...@r-enthusiasts.com] |Sent: 22. november 2014 13:25 |To: Søren Højsgaard |Cc: rcpp-devel@lists.r-forge.r-project.org |Subject: Re: [Rcpp-devel] sugar: x+y and y+x gives different results when |there are NA's in y | |This has nothing to do with NA. It's just about the size difference. |sugar does not make attempt at recycling. Your responsibility. | |Romain | | Le 22 nov. 2014 à 11:48, Søren Højsgaard sor...@math.aau.dk a écrit : | | Dear all, | Came across this: | | #include Rcpp.h | using namespace Rcpp; | | //[[Rcpp::export]] | List sumxy(NumericVector x, NumericVector y){ NumericVector xy = | x+y; NumericVector yx = y+x; return List::create(xy, yx); } | | /*** R | x - c(1,3,5,7) | y - c(NA,2,4,6,8) | x+y | y+x | sumxy(x, y) | */ | | x - c(1,3,5,7) | y - c(NA,2,4,6,8) | x+y | [1] NA 5 9 13 9 | y+x | [1] NA 5 9 13 9 | sumxy(x, y) | [[1]] | [1] NA 5 9 13 | [[2]] | [1] NA 5 9 13 8 | | Is this intentional? Apologies if this has been documented anywhere; |was unable to find it. | | Regards | Søren | | | ___ | Rcpp-devel mailing list | Rcpp-devel@lists.r-forge.r-project.org | https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-deve | l ___ 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] Bug in loadRcppClass/loadModule?
sourceCpp knows how to deal with modules, i.e.: inc - ' #include Rcpp.h using namespace Rcpp; double norm( double x, double y ) { return sqrt( x*x + y*y ); } RCPP_MODULE(mod) { function( norm, norm ); }' sourceCpp( code = inc ) giving: norm( 3, 3 ) [1] 4.242641 Romain Le 19 nov. 2014 à 05:49, Aaron Polhamus aaronpolha...@gmail.com a écrit : Dear list, In the process of writing a comprehensive unit testing application for Rcpp I may have come across a bug in the code. It seems to me that the following block should execute just fine, exporting the C++ class norm to the global environment: require(inline) require(Rcpp) inc - ' using namespace Rcpp; double norm( double x, double y ) { return sqrt( x*x + y*y ); } RCPP_MODULE(mod) { function( norm, norm ); }' fx - cxxfunction(signature(), plugin=Rcpp, include=inc) mod - Module(mod, getDynLib(fx)) loadRcppClass('norm', 'norm', mod) What happens, though, is that the following error is returned: Error in as.environment(pos) : no item called moduleName on the search list Digging in to loadRcppClass, I find that the function fails at the line: mod - loadModule(module, NULL, env = where, loadNow = TRUE) Entering loadModule, the function fails here, at the get statement: loadM - as.environment(module) module - get(loadM, moduleName) Isn't this backward? get syntax is: get(x, pos = -1, envir = as.environment(pos), mode = any, inherits = TRUE) Where x is the object sought in the specified environment. In this case, the function is failing because it can't find moduleName in the environment's search list, but the reason for this seems to be that the current statement is search for an environment within a character string, rather than a character string representing a named object within an environment. Is this in need of a patch, or am I missing something obvious? Cheers, Aaron ___ 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] tracking volatile bug
Le 18 nov. 2014 à 14:42, Serguei Sokol serguei.so...@gmail.com a écrit : Hi everybody, I am facing a volatile bug which appears and disappears in identical calls on identical data. My RcppArmadilla code is expm_cpp() (it is obtained by rex2arma tool which I have presented before, cf. attached file). It is compared and benchmarked vs its R counterpart expm.higham() (also attached). Both are computing matrix exponential by a same particular method. The results are identical for R and Rcpp on small and medium sized matrices nxn n=10:100 but on large matrices (n 800) various error messages can interrupt (or not) a normal run of expm_cpp(). Sometimes message says (in French) type 'char' indisponible dans 'eval', I suppose in English it must be unimplemented type 'char' in 'eval' I have seen (thanks to Google) a similar error message in the following snippet: /* call this R command: source(FileName) */ int errorOccurred; SEXP e = lang2(install(source), mkString(FileName)); /* mkChar instead of mkString would lead to this runtime error: * Error in source(FileName) : unimplemented type 'char' in 'eval' */ R_tryEval(e, R_GlobalEnv, errorOccurred); e is not protected here. Does the problem go away if you protect it: SEXP e = PROTECT( lang2(install(source), mkString(FileName))) ; Or more R/C++ idiomatically, which is both nicer and safer. Language e( source, FileName ) ; Romain which suggests that somewhere in Rcpp or RcppArmadillo there is a mkChar() call instead of mkString(). Other times, error message can say something like argument type[1]='x' must be one of 'M','1','O','I','F' or 'E' or argument type[1]='character' must be a one-letter character string This latter message is somewhat volatile per se. The part of message just after type[1]= can be 'character' (as above) or 'method' or 'ANY' etc. That kind of problem usually is related to premature GC. I have found these messages in the Matrix package https://r-forge.r-project.org/scm/viewvc.php/pkg/Matrix/src/Mutils.c?view=markuproot=matrixpathrev=2614 function char La_norm_type(const char *typstr) Seemingly, the argument *typstr is getting corrupted somewhere on the road. It is useless to say that debugging is of no help here. If run in a debugger, the program stops normally with or without error messages cited above. I have also tried to low the level of gcc optimization both in compiling R and the Rcpp code but it didn't help. Anybody has an experience in tracking down similar cases? This example can be run as: library(expm) library(Rcpp) source(expm_cpp.R) source(expm.higham.R) n=1000 As=matrix(rnorm(n*n), n) stopifnot(diff(range(expm.higham(As, balancing=TRUE)-expm_cpp(As, balancing=TRUE))) 1.e-14) The last command may be run several times before an error shows up. Cheers, Serguei. expm_cpp.Rexpm.higham.R___ 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] inplace modification more affect other varibles
a and b are the same object: a - seq(1, 0.1, -0.1) b - a pryr::address( a ) [1] 0x7f9504534948 pryr::address( b ) [1] 0x7f9504534948 So clone is what you need here. Implementing copy on write for that kind of example is possible, but would require a lot of additional code, i.e. the iterator would need to handle the write operation. An undesirable side effect of this is that such iterators would be quite less performant, right now Rcpp is close to the metal and uses direct pointers as iterators when it makes sense. A price that everyone would have to pay. no go. Instead, the responsibility is given to the user to clone explicitly when changes will be made to the underlying object. Romain Le 22 oct. 2014 à 04:13, Chenliang Xu luckyr...@gmail.com a écrit : Hi Dirk, Thanks for your quick answer. I don't think Rcpp::clone is what I was looking for. I know `stl_sort_inplace(a)` modify the value of `a`, but it surprise me to see it modify `b`. And it may modify some other variables c, d, e, f..., and it's hard to know which variables point to the same place. On Tue, Oct 21, 2014 at 8:31 PM, Dirk Eddelbuettel e...@debian.org mailto:e...@debian.org wrote: On 21 October 2014 at 20:22, Chenliang Xu wrote: | Hello, | | With the following inplace sorting example, I understand the value of `a` is | sorted inplace, but it's strange to see the value of `b` is also modified. This | can cause some hard to detect bug, since the cpp function may modify a variable | defined in other scope. Very well known issue -- maybe do a search for 'Rcpp::clone' ... In a nutshell, SEXP objects are passed by a __pointer__ and changes do therefore persist. If you want distinct copies, use Rcpp::clone(). Dirk | It seems that rcpp doesn't respect the named field, which is adopted by R to | implement copy-on-modify. I don's see an easy fix on C++ side, since the called | cpp function has no information about variable binding in R. A possible fix is | adding a function `inplace` to R, which ensure the returned variable has named | filed = 0 so is safe to modify inplace. Then, we have to call the function as | `stl_sort_inplace(inplace(a))`, which seems odd but is also informative. It | shows clearly that we are breaking the pass-by-value rule in R. | | ```cpp | #include Rcpp.h | using namespace Rcpp; | | // [[Rcpp::export]] | void stl_sort_inplace(NumericVector x) { | std::sort(x.begin(), x.end()); | } | | ``` | | ```r | a - seq(1, 0.1, -0.1) | b - a | # [1] 1.0 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 | | stl_sort_inplace(a) | | a | # [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 | | b | # [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 | | a - seq(1, 0.1, -0.1) | pure_function - function (x) { | y - x | stl_sort_inplace(y) | print(y) | } | pure_function(a) | a | # [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 | | ``` | | ___ | Rcpp-devel mailing list | Rcpp-devel@lists.r-forge.r-project.org mailto:Rcpp-devel@lists.r-forge.r-project.org | https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel -- http://dirk.eddelbuettel.com http://dirk.eddelbuettel.com/ | @eddelbuettel | e...@debian.org mailto: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 ___ 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] inplace modification more affect other varibles
Pretty much. But sometimes that's what you want, and Rcpp does not get in the way. You just have to know the rules of the game. BTW, same rules apply when you use .Call C/R API, you are in charge of making the copy when it's needed. Romain Le 22 oct. 2014 à 17:53, Chenliang Xu luckyr...@gmail.com a écrit : Thanks a lot! Does that mean we should never modify an argument passed from R to cpp? On Wed, Oct 22, 2014 at 8:24 AM, Romain Francois rom...@r-enthusiasts.com mailto:rom...@r-enthusiasts.com wrote: a and b are the same object: a - seq(1, 0.1, -0.1) b - a pryr::address( a ) [1] 0x7f9504534948 pryr::address( b ) [1] 0x7f9504534948 So clone is what you need here. Implementing copy on write for that kind of example is possible, but would require a lot of additional code, i.e. the iterator would need to handle the write operation. An undesirable side effect of this is that such iterators would be quite less performant, right now Rcpp is close to the metal and uses direct pointers as iterators when it makes sense. A price that everyone would have to pay. no go. Instead, the responsibility is given to the user to clone explicitly when changes will be made to the underlying object. Romain Le 22 oct. 2014 à 04:13, Chenliang Xu luckyr...@gmail.com mailto:luckyr...@gmail.com a écrit : Hi Dirk, Thanks for your quick answer. I don't think Rcpp::clone is what I was looking for. I know `stl_sort_inplace(a)` modify the value of `a`, but it surprise me to see it modify `b`. And it may modify some other variables c, d, e, f..., and it's hard to know which variables point to the same place. On Tue, Oct 21, 2014 at 8:31 PM, Dirk Eddelbuettel e...@debian.org mailto:e...@debian.org wrote: On 21 October 2014 at 20:22, Chenliang Xu wrote: | Hello, | | With the following inplace sorting example, I understand the value of `a` is | sorted inplace, but it's strange to see the value of `b` is also modified. This | can cause some hard to detect bug, since the cpp function may modify a variable | defined in other scope. Very well known issue -- maybe do a search for 'Rcpp::clone' ... In a nutshell, SEXP objects are passed by a __pointer__ and changes do therefore persist. If you want distinct copies, use Rcpp::clone(). Dirk | It seems that rcpp doesn't respect the named field, which is adopted by R to | implement copy-on-modify. I don's see an easy fix on C++ side, since the called | cpp function has no information about variable binding in R. A possible fix is | adding a function `inplace` to R, which ensure the returned variable has named | filed = 0 so is safe to modify inplace. Then, we have to call the function as | `stl_sort_inplace(inplace(a))`, which seems odd but is also informative. It | shows clearly that we are breaking the pass-by-value rule in R. | | ```cpp | #include Rcpp.h | using namespace Rcpp; | | // [[Rcpp::export]] | void stl_sort_inplace(NumericVector x) { | std::sort(x.begin(), x.end()); | } | | ``` | | ```r | a - seq(1, 0.1, -0.1) | b - a | # [1] 1.0 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 | | stl_sort_inplace(a) | | a | # [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 | | b | # [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 | | a - seq(1, 0.1, -0.1) | pure_function - function (x) { | y - x | stl_sort_inplace(y) | print(y) | } | pure_function(a) | a | # [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 | | ``` | | ___ | Rcpp-devel mailing list | Rcpp-devel@lists.r-forge.r-project.org mailto:Rcpp-devel@lists.r-forge.r-project.org | https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel -- http://dirk.eddelbuettel.com http://dirk.eddelbuettel.com/ | @eddelbuettel | e...@debian.org mailto:e...@debian.org ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org mailto:Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel 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 ___ 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] convert to unsigned char* variable
Le 20 oct. 2014 à 21:54, Dirk Eddelbuettel e...@debian.org a écrit : Hi Gustaf, On 20 October 2014 at 15:17, Gustaf Granath wrote: | Im trying to use some C++ functions in R. However, these functions are | build around unsigned char* variables (1D array). I have for example a | large matrix in R that represents black (e.g. 1-bit image, 0 and 1s). I | cant find a solution to convert a character vector into unsigned char* | within Rcpp. Im new to Rcpp and C++ so I might have missed something Rcpp builds a bridge between R and C++, and supports (in C++) the types that R supports. Eg you won't find 'float' but only 'double' as that is what R does. Here you will get character vectors easily. If they must be unsigned char, you will probably have to cast them at the C++ level. | obvious here. Please direct me to resources on this topic (google did | not help much). | | A start: | | SEXP test(SEXP cM){ |CharacterVector Vc(cM); |int n = Vr.size(); |RawVector x(n); //is this the same as unsigned char* ? No, RawVector is for R 'raw' types -- see help(raw) in R, Guess what raw is !!! demangle( RawVector::stored_type ) [1] unsigned char Dirk | //I tried to fill it with char*(Mr) but I | didnt succeed | } | | Thanks, | | Gustaf | | -- | Gustaf Granath (PhD) | Post doc | McMaster University | School of Geography Earth Sciences | | ___ | 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 ___ 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] convert to unsigned char* variable
Hi, that's not going to fly. A CharacterVector holds strings of arbitrary lengths, well technically it holds other R objects (SEXP) that hold pointers to strings. A RawVector holds unsigned char. Can you add some meat to your example, e.g. what you'd expect to go in, etc ... Romain Le 20 oct. 2014 à 21:17, Gustaf Granath gustaf.gran...@gmail.com a écrit : Hi Im trying to use some C++ functions in R. However, these functions are build around unsigned char* variables (1D array). I have for example a large matrix in R that represents black (e.g. 1-bit image, 0 and 1s). I cant find a solution to convert a character vector into unsigned char* within Rcpp. Im new to Rcpp and C++ so I might have missed something obvious here. Please direct me to resources on this topic (google did not help much). A start: SEXP test(SEXP cM){ CharacterVector Vc(cM); int n = Vr.size(); RawVector x(n); //is this the same as unsigned char* ? //I tried to fill it with char*(Mr) but I didnt succeed } Thanks, Gustaf -- Gustaf Granath (PhD) Post doc McMaster University School of Geography Earth Sciences ___ 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] Grid Search in RcppParallel
Envoyé de mon iPhone Le 5 oct. 2014 à 07:51, Jeffrey Wong jeff.ct.w...@gmail.com a écrit : I am trying to use RcppParallel to do a fast grid search. The idea is to construct a matrix using R's expand.grid, then for each row of that matrix, x, call f(x). For simplicity the function f will always return a double. Since Rcpp can call an R function I was hoping RcppParallel would allow me to use a parallelFor to process the rows of the grid quickly. However, it keeps crashing R, and I am wondering if this is because an R function cannot be passed to RcppParallel? You definitely cannot call an R function concurrently. require(Rcpp) require(RcppParallel) grid = as.matrix(expand.grid(a = 1:5, b = 1:5)) foo = function(pars) {pars[1]^2 + pars[2]^2} RcppParallelGridSearch(grid, foo) in .cpp file #include Rcpp.h using namespace Rcpp; // [[Rcpp::depends(RcppParallel)]] #include RcppParallel.h using namespace RcppParallel; struct GridSearch : public Worker { // source matrix const RMatrixdouble grid; const Function f; // destination vector RVectordouble output; // initialize with source and destination GridSearch(const NumericMatrix grid, const Function f, NumericVector output) : grid(grid), f(f), output(output) {} // take the square root of the range of elements requested void operator()(std::size_t begin, std::size_t end) { for (std::size_t i = begin; i end; i++) { RMatrixdouble::Row parameters = grid.row(i); output[i] = asdouble(f(parameters)); } } }; // [[Rcpp::export]] NumericVector RcppParallelGridSearch(NumericMatrix grid, Function f) { // allocate the output matrix NumericVector output(grid.nrow()); // SquareRoot functor (pass input and output matrixes) GridSearch gridSearch(grid, f, output); // call parallelFor to do the work parallelFor(0, grid.nrow(), gridSearch); // return the output matrix return output; } -- Jeffrey Wong My portfolio: http://jeffreycwong.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] statement about rcpp11 ?
If you want to have a private conversation with Dirk, just email him directly: e...@debian.org Now since this is all in the open, let me participate to this. Le 29 sept. 2014 à 22:42, Jonathon Love j...@thon.cc a écrit : -BEGIN PGP SIGNED MESSAGE- Hash: SHA512 hey dirk, i was wondering if you could let us know your thoughts about Rcpp11. i've found it a little bit confusing, because at first i thought people were just talking about Rcpp (which happens to be at version 0.11). I also found it confusing that Rcpp's version became 0.11.* I guess we had it coming after 0.10.* since apparently for some reason it is trapped in the 0.* land forever then i thought it was a newer version of Rcpp, but of course it isn't. then i thought it was a version of Rcpp for use with C++11 (because presumably Rcpp doesn't support C++11... but of course it does). Yes you can use C++11 with Rcpp, and for that matter you can even use C++11 without Rcpp. You can do arcane .Call stuff on the outside and have C++11 code inside. Now Rcpp11 is a complete redesign, focusing on C++11, it means that it actively uses C++11, as opposed to let you use it. It has also allowed us to step back from mistakes that were made along the way when developing Rcpp such as (this is just one example) complexity of too many undocumented constructors for *Vector classes. Doing this is impossible with Rcpp which has to carry the weight of dependency. so the name alone appears to have been chosen to maximise confusion Not at all. Rcpp11 stands for R and C++11. From my point of view, the confusion comes from the versioning of Rcpp. Perhaps Rcpp will hit version 0.14.* when I start working on Rcpp14 soon. How convenient would that be. but i was wondering what you thought about it technically. do you see it replacing ol' Rcpp, and new projects should make an effort to use it instead? do you see Rcpp being retired as a result? what is the future of repp? They will coexist, are maintained by two different persons who have different goals. And that's fine. Right now CRAN makes it difficult to depend on Rcpp11, but we have implemented a workaround, so the next version of Rcpp11 (to be released when the next R is released) will be CRAN proof. Just use whatever version is best for your needs. I'm spending a great deal of energy and time (although perhaps not lately) on developing Rcpp11, but I still use Rcpp for projects for which it makes sense, e.g. dplyr uses Rcpp. perhaps these might make good FAQ entries. with thanks jonathon ___ 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] Pass an Rcpp module object to a method belonging to another module from R?
This is once again something with which the RCPP_EXPOSED_CLASS macro can help with. Try adding RCPP_EXPOSED_CLASS(A) before you declare class A and simply use this signature for the method. void DoSomethingWithInstanceOfA(const A ) Also, you can have both of these classes in the same module you know; RCPP_MODULE(LemonCurry) { using namespace Rcpp; class_A( A ) .constructor(); class_B( B ) .constructor() .method(DoSomethingWithInstanceOfA, B::DoSomethingWithInstanceOfA); } Romain. PS: Having to resort to that sort of macros is one of the reason that made me remove modules from Rcpp11, which will be replaced by something that will be nicer to use later. Le 10 sept. 2014 à 02:56, Grant Brown grant.brow...@gmail.com a écrit : Hi folks, I'm building several Rcpp modules which specify parts of a complicated statistical model, and want to pass them to a main module for use. Is there an easy way to do this? Below is a simplified example, with question marks where I'm not sure what to do. I've tried accepting a pointer to A, playing with using XPtrs, and a bunch of things which made far less sense, but so far no luck. Any suggestions or links to sections of the docs I should revisit would be appreciated. Thanks, -Grant ## file: A.cpp class A { public: A(); ~A(); }; class B { public: B(); void DoSomethingWithInstanceOfA(???); ~B(); }; A::A() { // Do stuff } B::B() { // Do stuff } B::DoSomethingWithInstanceOfA(???) { // Do stuff } RCPP_MODULE(mod_A) { using namespace Rcpp; class_A( A ) .constructor(); } RCPP_MODULE(mod_B) { using namespace Rcpp; class_B( B ) .constructor() .method(DoSomethingWithInstanceOfA, B::DoSomethingWithInstanceOfA); } ### End pseduo c++ code ___ 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] Pass an Rcpp module object to a method belonging to another module from R?
Le 10 sept. 2014 à 14:22, Gregory Jefferis jeffe...@mrc-lmb.cam.ac.uk a écrit : Gregory Jefferis On 10 Sep 2014, at 10:39, Romain Francois rom...@r-enthusiasts.com wrote: RCPP_EXPOSED_CLASS(A) before you declare class A and simply use this signature for the method. void DoSomethingWithInstanceOfA(const A ) I used this approach happily in the nabor package (on github) but the only caveat is that from R you need to call with something like: A$method(B$.CppObject) You can get some interesting crashes if you pass the R reference class (i.e. B) directly as the argument. I guess it might be better to have a derived R class that looks after extracting the .CppObject field. Best, Greg. That looks like a bug. Please submit it here: https://github.com/RcppCore/Rcpp/issues ___ 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] RcppModules with templated class
Le 1 sept. 2014 à 11:48, Dr Gregory Jefferis jeffe...@mrc-lmb.cam.ac.uk a écrit : Hello, I have a more or less complete Rcpp(Eigen) dependent package that exposes a pair of C++ classes to R using RcppModules;the C++ classes (which implement k nearest neighbour search trees) differ only in their scalar storage type (float vs double) and are called WKNND and WKNNF. For future flexibility/maintenance I would have like to convert the C++ classes to templated code. Is it possible to use RcppModules to expose template classes? I know that Rcpp in general can be used with template classes, but the RcppModules manual does not seem to mention this. I have tried to implement this by simple translation of my existing code to a single WKNN class and then defining types for WKNND and WKNNF (i.e. double and float). However this falls over with errors/notes indicating that the automatic wrap/conversion of Eigen types is failing to pick up the typedef. Error: In file included from WKNND.cpp:1: In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include/Rcpp.h:27: In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include/RcppCommon.h:169: In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include/Rcpp/as.h:25: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include/Rcpp/internal/Exporter.h:31:28: error: no matching constructor for initialization of 'WKNNdouble' Exporter( SEXP x ) : t(x){} ^ ~ and notes like: ./WKNN.h:14:8: note: candidate constructor (the implicit copy constructor) not viable: cannot convert argument of incomplete type 'SEXP' (aka 'SEXPREC *') to 'const WKNNdouble' struct WKNN { ^ ./WKNN.h:16:3: note: candidate constructor not viable: cannot convert argument of incomplete type 'SEXP' (aka 'SEXPREC *') to 'const Eigen::MapEigen::Matrixdouble, Dynamic, Dynamic ' WKNN(const Eigen::MapEigen::MatrixT, Dynamic, Dynamic data, bool buildtree=true); ^ So is there a way round this? Do I have to write an explicit wrap function? Do I have to give up on using RcppModules altogether? Any advice or pointers to a package already doing this would be much appreciated. And of course big thanks to Dirk, Romain and Douglas et al for these great packages. Best wishes, Greg. PS Code on this branch: https://github.com/jefferis/nabor/tree/feature/template-WKNN with these 2 commits making the changes: https://github.com/jefferis/nabor/commit/fa85ddae5187f1e93801d7ec36d1d78923384cc6 https://github.com/jefferis/nabor/commit/9ff93e63023b2f6d9c7ddad54fb7d1f503685b86 Hi, This looks related to what RCPP_EXPOSED_CLASS does, perhaps because your class comes from a template, you could try RCPP_EXPOSED_CLASS_NODECL instead. The only difference is that it does not add the class forward declaration, so you'd have to have it after you have defined or declared your class. Romain ___ 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] (Very) rare segfault
Le 20 août 2014 à 20:57, Gregor Kastner gregor.kast...@wu.ac.at a écrit : JJ Yes, RNGScope isn't safe by itself. You can use it via attributes (and we JJ make sure to use it correctly) or you could use this pattern e.g. if you JJ are planning to return a NumericVector: JJ JJ NumericVector vec(20); // or whatever size, the important thing is JJ allocating the return SEXP before RNGScope JJ JJ RNGScope rngScope; JJ JJ // do your thing JJ JJ JJ return vec; JJ, care to explain this ? I don't follow. OK thanks. That's definitely worth knowing. Might be a cause for trouble for others too, especially since misuse (i.e. other ordering) doesn't seem to show any effects in many cases. DE RNGScope is not for for seed setting, it is for RNG 'state sanity'. See DE Section 6.3 of 'Writing R Extensions' -- worst case you can just call DE GetRNGstate() and PutRNGstate() by hand. Though we never had to DE recommend that yet. Yep, sorry for the misuse of language. And I do understand going back to GetRNGstate() and PutRNGstate() is a bit old school; but I can definitely confirm that it seems to be safer than resorting do the constructor/destuctor magic. Compiler/Destructor is not magic. It is determinism. That's like feature #1 of C++. And BTW it is definitely safer than any manual handling. ___ 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] (Very) rare segfault
Le 21 août 2014 à 11:47, Gregor Kastner gregor.kast...@wu.ac.at a écrit : On Thu, 21 Aug 2014 11:34:23 +0200 Romain Francois rom...@r-enthusiasts.com wrote: GK Yep, sorry for the misuse of language. And I do understand going back to GK GetRNGstate() and PutRNGstate() is a bit old school; but I can definitely GK confirm that it seems to be safer than resorting do the GK constructor/destuctor magic. Compiler/Destructor is not magic. It is determinism. That's like feature #1 of C++. agreed: s/magic/automagic/g And BTW it is definitely safer than any manual handling. I cannot say that in the current case, as relying on the destructor does seem to create problems (in rare cases, making it even worse!) if objects which are to be returned are instantiated after the RNGScope object. Conditional on the fact the I understood JJ correctly, that is. Then it's a bug in how constructor or destructor is implemented in this class, probably with the counter. Or something invalidates the very assumptions of C++ here. Perhaps raw R api is called and the destructor is not called because of some long jump or something. Without a repex anyway, it is hard to diagnose what's happening. You're probably onto somthing, but going directly to the destructor are not safe, I'll just use C function calls is a dangerous route, soon you'll start using SEXP as you won't trust ctors/dtors of Rcpp objects do the right thing. Manual handling works perfectly. Best, /g ___ 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] (Very) rare segfault
That makes sense. No real reason not to use attributes anyway :) Le 21 août 2014 à 15:54, JJ Allaire j...@rstudio.com a écrit : Yes, the link posted by Matteo is what provoked us to make the change in Rcpp Attributes to dance around the constructor/destructor issues. Net: If you are using attributes then this isn't a concern, if you are not then you need the return value SEXP on the stack prior to RNGScope. On Thursday, August 21, 2014, Romain Francois rom...@r-enthusiasts.com wrote: Ah interesting. PutRNGstate does indeed allocate so might trigger GC. https://github.com/wch/r-source/blob/fbf5cdf29d923395b537a9893f46af1aa75e38f3/src/main/RNG.c#L437 That's a whole new Pandora's box right there. Le 21 août 2014 à 12:10, Matteo Fasiolo matteo.fasi...@gmail.com a écrit : Hi Romain and Gregor, maybe I am misunderstanding everything, but hasn't this problem been explained and solved here: http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2013-May/005838.html Best, Matteo On Thu, Aug 21, 2014 at 10:58 AM, Romain Francois rom...@r-enthusiasts.com wrote: Le 21 août 2014 à 11:47, Gregor Kastner gregor.kast...@wu.ac.at a écrit : On Thu, 21 Aug 2014 11:34:23 +0200 Romain Francois rom...@r-enthusiasts.com wrote: GK Yep, sorry for the misuse of language. And I do understand going back to GK GetRNGstate() and PutRNGstate() is a bit old school; but I can definitely GK confirm that it seems to be safer than resorting do the GK constructor/destuctor magic. Compiler/Destructor is not magic. It is determinism. That's like feature #1 of C++. agreed: s/magic/automagic/g And BTW it is definitely safer than any manual handling. I cannot say that in the current case, as relying on the destructor does seem to create problems (in rare cases, making it even worse!) if objects which are to be returned are instantiated after the RNGScope object. Conditional on the fact the I understood JJ correctly, that is. Then it's a bug in how constructor or destructor is implemented in this class, probably with the counter. Or something invalidates the very assumptions of C++ here. Perhaps raw R api is called and the destructor is not called because of some long jump or something. Without a repex anyway, it is hard to diagnose what's happening. You're probably onto somthing, but going directly to the destructor are not safe, I'll just use C function calls is a dangerous route, soon you'll start using SEXP as you won't trust ctors/dtors of Rcpp objects do the right thing. Manual handling works perfectly. Best, /g ___ 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] Template and non-template arguments in RCPP_RETURN_VECTOR
Hi, I guess RCPP_RETURN_VECTOR could be easily extended to support variadic number of arguments, using either variadic templates or variadic macros. https://github.com/RcppCore/Rcpp/blob/3ef9e662d89ebcfe71734675071568302bf10104/inst/include/Rcpp/macros/dispatch.h#L44 RCPP_RETURN_VECTOR is not that used as it looks kind of ugly and forces on you dispatch on all the SEXP types and sometimes you just want say INTSXP and REALSXP ... Romain Le 20 août 2014 à 14:30, Sven E. Templer sven.temp...@gmail.com a écrit : To create a templated function one can use the macro RCPP_RETURN_VECTOR, e.g: sourceCpp(code=' #include Rcpp.h template typename T T index_template ( T X ) { Rcpp::IntegerVector I(1, 0); return X[I]; } // [[Rcpp::export]] SEXP index ( SEXP X ) { RCPP_RETURN_VECTOR(index_template, X); } ') index(letters) index(c(pi,2,1)) Using a templated and a non-templated argument does not(?) allow use of the macro, e.g.: sourceCpp(code=' #include Rcpp.h template typename T T index2_template ( T X, Rcpp::IntegerVector I ) { return X[I]; } // [[Rcpp::export]] SEXP index2 ( SEXP X, Rcpp::IntegerVector I ) { switch(TYPEOF(X)) { case STRSXP: return index2_template(Rcpp::VectorSTRSXP(X), I); break; case REALSXP: return index2_template(Rcpp::VectorREALSXP(X), I); break; case INTSXP: return index2_template(Rcpp::VectorINTSXP(X), I); break; default: Rf_error(Unsupported type.); } } ') index2(c(pi,2,1),2) index2(letters,2) Is there an easier way that I am missing, than to use switch/TYPEOF ...? Like RCPP_RETURN_VECTOR2(index_template, X, I). Thank you for any hint, Sven. ___ 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] (Very) rare segfault
This would be typical gc problems. Could be anywhere. Even if you run it through gdb, the problem will incubate for some time before showing symptoms. We’ve been lucky sometimes to fix some of these by accident, but it is otherwise pretty hard. Romain Le 20 août 2014 à 19:38, Gregor Kastner gregor.kast...@wu.ac.at a écrit : Dear all, during a large simulation study on around 300 cores, I have just noticed strange behavior of my package depending on Rcpp. Strange in the sense that on very rare occasions (around 1 in 10 function calls through .Call), a NumericMatrix object created at C level and returned back to R as part of a list isn't available there, causing a memory not mapped segfault when trying to access it from R. The issue is not deterministically reproducible and, as mentioned, very rare. This makes narrowing down the bug a pain. I do know however that this problem does not appear in Rcpp 0.10.5 but does appear in Rcpp 0.11.0. Maybe there is anyone out there who has experienced something similar or otherwise has a hunch where I should dig further. Thanks a ton in advance, Gregor ___ 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] Typecasting bug in Rcpp::List (generic_name_proxy) when using clang
This is likely to be a bug in Rcpp, don't go bother clang about it:) Perhaps you can try to remove the bool cast and run the test suite. If everything works, then it either means that there are no tests for the particular case or that the overload is useless. You probably have to consider what happens with : list[a] = false ; bool a = list[a] ; i.e. does it work when the overload is removed, etc ... Also, it will be more useful if the example was not using RInside, as this has nothing to do with RInside really. You can easily demonstrate the problem with a cppFunction or a sourceCpp without having to go through RInside. I'd recommend to go here for bug submission: https://github.com/RcppCore/Rcpp/issues Romain Le 29 juil. 2014 à 10:36, Christian Authmann authm...@mathematik.uni-marburg.de a écrit : Hi, the following testcase exposes a difference in gcc and clang snip #include Rcpp.h #include RInside.h int main(int argc, char *argv[]) { // We need some kind of R environment to create a List. RInside R; Rcpp::List list; list[a] = 42; int a_auto = list[a]; int a_cast = Rcpp::asint(list[a]); std::cout list[\a\]= a_auto std::endl; std::cout Rcpp::asint(list[\a\]) = a_cast std::endl; } snip Results: gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) list[a]= 42 Rcpp::asint(list[a]) = 42 Ubuntu clang version 3.5-1ubuntu1 (trunk) (based on LLVM 3.5) list[a]= 1 Rcpp::asint(list[a]) = 42 list[a] returns a Rcpp::internal::generic_name_proxy19, which has the following typecasting operators: (rcpp/vector/proxy.h) snip template typename T operator T() const { #if RCPP_DEBUG_LEVEL 0 SEXP res = get() ; RCPP_DEBUG_1( generic_name_proxy::get() = %p , res ) ; return ::Rcpp::asT( res ) ; #else return ::Rcpp::asT( get() ) ; #endif } operator bool() const{ return ::Rcpp::asbool(get()); } snip A few sprinkled printf's reveal that clang will call the bool typecast, while gcc calls the template as intended. Now that I know, I can easily work around it by using Rcpp::as where needed (and I'm posting here so maybe others can find the information), but maybe it should be fixed. ;) I don't know all the intricacies of the C++ standard. Is this a bug in clang? Or is clang free to use any conversion operator it likes, and Rcpp is at fault for relying on implementation details of gcc? If the former, I'll create a reduced testcase and file a bug with clang. If the latter, I noticed that removing the bool typecast altogether will cause clang to correctly return 42. Unless there is a good reason for its existence (say, to suppress logging for bool casts), we could just remove it. Grep'ping all the includes suggest that this is the only class with redundant typecast operators. Ciao, Christian -- Christian Authmann Philipps-Universität Marburg Fachbereich Mathematik und Informatik AG Datenbanksysteme Hans-Meerwein-Straße D-35032 Marburg ___ 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] Typecasting bug in Rcpp::List (generic_name_proxy) when using clang
Thanks. Hopefully someone will pick it up or at least create an issue by proxy for you. Romain Le 29 juil. 2014 à 12:17, Christian Authmann authm...@mathematik.uni-marburg.de a écrit : I've removed the bool cast from last week's git, reinstalled the package, ran the test suite with --allTests, recompiled my own codes, everything seems to work. If the bool cast is missing, the code should just fall back to the templated operator T(), with T=bool. Unless RCPP_DEBUG_LEVEL is enabled, those are identical. RUNIT TEST PROTOCOL -- Tue Jul 29 13:20:29 2014 *** Number of test functions: 439 Number of errors: 0 Number of failures: 0 Sorry, due to a restrictive firewall on my dev computer, I cannot access github from it. A mail will have to suffice for now. Ciao, Christian On 29.07.2014 10:44, Romain Francois wrote: This is likely to be a bug in Rcpp, don't go bother clang about it:) Perhaps you can try to remove the bool cast and run the test suite. If everything works, then it either means that there are no tests for the particular case or that the overload is useless. You probably have to consider what happens with : list[a] = false ; bool a = list[a] ; i.e. does it work when the overload is removed, etc ... Also, it will be more useful if the example was not using RInside, as this has nothing to do with RInside really. You can easily demonstrate the problem with a cppFunction or a sourceCpp without having to go through RInside. I'd recommend to go here for bug submission: https://github.com/RcppCore/Rcpp/issues Romain Le 29 juil. 2014 à 10:36, Christian Authmann authm...@mathematik.uni-marburg.de a écrit : Hi, the following testcase exposes a difference in gcc and clang snip #include Rcpp.h #include RInside.h int main(int argc, char *argv[]) { // We need some kind of R environment to create a List. RInside R; Rcpp::List list; list[a] = 42; int a_auto = list[a]; int a_cast = Rcpp::asint(list[a]); std::cout list[\a\]= a_auto std::endl; std::cout Rcpp::asint(list[\a\]) = a_cast std::endl; } snip Results: gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) list[a]= 42 Rcpp::asint(list[a]) = 42 Ubuntu clang version 3.5-1ubuntu1 (trunk) (based on LLVM 3.5) list[a]= 1 Rcpp::asint(list[a]) = 42 list[a] returns a Rcpp::internal::generic_name_proxy19, which has the following typecasting operators: (rcpp/vector/proxy.h) snip template typename T operator T() const { #if RCPP_DEBUG_LEVEL 0 SEXP res = get() ; RCPP_DEBUG_1( generic_name_proxy::get() = %p , res ) ; return ::Rcpp::asT( res ) ; #else return ::Rcpp::asT( get() ) ; #endif } operator bool() const{ return ::Rcpp::asbool(get()); } snip A few sprinkled printf's reveal that clang will call the bool typecast, while gcc calls the template as intended. Now that I know, I can easily work around it by using Rcpp::as where needed (and I'm posting here so maybe others can find the information), but maybe it should be fixed. ;) I don't know all the intricacies of the C++ standard. Is this a bug in clang? Or is clang free to use any conversion operator it likes, and Rcpp is at fault for relying on implementation details of gcc? If the former, I'll create a reduced testcase and file a bug with clang. If the latter, I noticed that removing the bool typecast altogether will cause clang to correctly return 42. Unless there is a good reason for its existence (say, to suppress logging for bool casts), we could just remove it. Grep'ping all the includes suggest that this is the only class with redundant typecast operators. Ciao, Christian -- Christian Authmann Philipps-Universität Marburg Fachbereich Mathematik und Informatik AG Datenbanksysteme Hans-Meerwein-Straße D-35032 Marburg ___ 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] Typecasting bug in Rcpp::List (generic_name_proxy) when using clang
Sent a PR. Everything was pretty well explained in the original email. Le 29 juil. 2014 à 13:51, Dirk Eddelbuettel e...@debian.org a écrit : On 29 July 2014 at 12:17, Christian Authmann wrote: | Sorry, due to a restrictive firewall on my dev computer, I cannot access | github from it. A mail will have to suffice for now. Can you email me a proper patch, created the usual way via diff -u, or git diff ? Thanks, Dirk ___ 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] Faster lookup: Named Rcpp::List or std::map?
Lookup in Rcpp::List is linear on something that is quite cheap (comparing pointers, because strings in R are cached). Lookup in std::map is logarithmic on whatever it means to compare the keys (so in your case comparing strings). on top of that, copying the data across is linear in the best case scenario (when the data is already sorted) or N log(N) otherwise. See: http://www.cplusplus.com/reference/map/map/map/ Best is to try both and see which is best for your case. Don't make this just one dimensional and consider things like maintainability of your code, ... Romain Le 23 juil. 2014 à 15:30, Asis Hallab asis.hal...@gmail.com a écrit : Dear Rcpp-Experts, trying to optimize my algorithm I face the question wether a lookup by a string key like e.g. myRcppList( my_entry ) is as fast as the lookup in std::maps? That said, would you recommend converting myRcppList to a std::map before searching it? Thank you for your help in advance! Cheers! ___ 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] Raise a condition
Le 18 juin 2014 à 23:54, Tim Keitt tke...@utexas.edu a écrit : I'd like to raise a condition other than error or warning. Is that possible using the Rcpp api? I assume this can be done via R internals, but I'd prefer not to call error() directly (or is that the recommendation?). THK Definitely not. Rf_error should really only be called from C code. If you call it from C++, there is a great chance you'll lose determinism as destructors for your c++ objects are very likely not to be called. Most of the time, it will just mean you'll never release some objects to the garbage collector, but it could also get you leaks or other nice stuff depending on what your destructors were supposed to do and did not get a chance to do. I'm not sure Rcpp has a way to raise an R condition apart from calling stop, which usually is good enough. Otherwise, you can borrow from Rcpp11 and adapt some code from https://github.com/Rcpp11/Rcpp11/blob/450aade7338c16c34618ad0916003e8ca4fb58a6/inst/include/Rcpp/Condition.h Romain___ 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] Raise a condition
Le 19 juin 2014 à 00:15, Tim Keitt tke...@utexas.edu a écrit : On Wed, Jun 18, 2014 at 5:07 PM, Romain Francois rom...@r-enthusiasts.com wrote: Le 18 juin 2014 à 23:54, Tim Keitt tke...@utexas.edu a écrit : I'd like to raise a condition other than error or warning. Is that possible using the Rcpp api? I assume this can be done via R internals, but I'd prefer not to call error() directly (or is that the recommendation?). THK Definitely not. Rf_error should really only be called from C code. If you call it from C++, there is a great chance you'll lose determinism as destructors for your c++ objects are very likely not to be called. Most of the time, it will just mean you'll never release some objects to the garbage collector, but it could also get you leaks or other nice stuff depending on what your destructors were supposed to do and did not get a chance to do. That was my understanding. Just wanted to be sure it was still the case. I'm not sure Rcpp has a way to raise an R condition apart from calling stop, which usually is good enough. Otherwise, you can borrow from Rcpp11 and adapt some code from https://github.com/Rcpp11/Rcpp11/blob/450aade7338c16c34618ad0916003e8ca4fb58a6/inst/include/Rcpp/Condition.h Ah. I see. Eval stop in the global env with the condition as the argument. Clever. It is more of a hack due to lack of proper api from R. If you do this, make sure you don't have any c++ object in scope. Essentially that means you would evaluate `stop( condition )` in a top level catch block. ___ 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] Raise a condition
Le 19 juin 2014 à 00:30, Tim Keitt tke...@utexas.edu a écrit : On Wed, Jun 18, 2014 at 5:22 PM, Romain Francois rom...@r-enthusiasts.com wrote: Le 19 juin 2014 à 00:15, Tim Keitt tke...@utexas.edu a écrit : On Wed, Jun 18, 2014 at 5:07 PM, Romain Francois rom...@r-enthusiasts.com wrote: Le 18 juin 2014 à 23:54, Tim Keitt tke...@utexas.edu a écrit : I'd like to raise a condition other than error or warning. Is that possible using the Rcpp api? I assume this can be done via R internals, but I'd prefer not to call error() directly (or is that the recommendation?). THK Definitely not. Rf_error should really only be called from C code. If you call it from C++, there is a great chance you'll lose determinism as destructors for your c++ objects are very likely not to be called. Most of the time, it will just mean you'll never release some objects to the garbage collector, but it could also get you leaks or other nice stuff depending on what your destructors were supposed to do and did not get a chance to do. That was my understanding. Just wanted to be sure it was still the case. I'm not sure Rcpp has a way to raise an R condition apart from calling stop, which usually is good enough. Otherwise, you can borrow from Rcpp11 and adapt some code from https://github.com/Rcpp11/Rcpp11/blob/450aade7338c16c34618ad0916003e8ca4fb58a6/inst/include/Rcpp/Condition.h Ah. I see. Eval stop in the global env with the condition as the argument. Clever. It is more of a hack due to lack of proper api from R. If you do this, make sure you don't have any c++ object in scope. Essentially that means you would evaluate `stop( condition )` in a top level catch block. Rcpp objects are I assume ok however. Depends what you mean by ok. If you mean objects like NumericVector, ... their destructor is responsible for calling R_ReleaseObject, i.e. let go of the protection that was set by their constructor. If the destructor is not called because R error handling does a long jump, you will get objects forever protected. So things will seemingly work, until you exhaust the memory. I will try signalCondition and see what happens. THK ___ 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] Raise a condition
Le 19 juin 2014 à 01:02, Tim Keitt tke...@utexas.edu a écrit : On Wed, Jun 18, 2014 at 5:37 PM, Romain Francois rom...@r-enthusiasts.com wrote: Le 19 juin 2014 à 00:30, Tim Keitt tke...@utexas.edu a écrit : On Wed, Jun 18, 2014 at 5:22 PM, Romain Francois rom...@r-enthusiasts.com wrote: Le 19 juin 2014 à 00:15, Tim Keitt tke...@utexas.edu a écrit : On Wed, Jun 18, 2014 at 5:07 PM, Romain Francois rom...@r-enthusiasts.com wrote: Le 18 juin 2014 à 23:54, Tim Keitt tke...@utexas.edu a écrit : I'd like to raise a condition other than error or warning. Is that possible using the Rcpp api? I assume this can be done via R internals, but I'd prefer not to call error() directly (or is that the recommendation?). THK Definitely not. Rf_error should really only be called from C code. If you call it from C++, there is a great chance you'll lose determinism as destructors for your c++ objects are very likely not to be called. Most of the time, it will just mean you'll never release some objects to the garbage collector, but it could also get you leaks or other nice stuff depending on what your destructors were supposed to do and did not get a chance to do. That was my understanding. Just wanted to be sure it was still the case. I'm not sure Rcpp has a way to raise an R condition apart from calling stop, which usually is good enough. Otherwise, you can borrow from Rcpp11 and adapt some code from https://github.com/Rcpp11/Rcpp11/blob/450aade7338c16c34618ad0916003e8ca4fb58a6/inst/include/Rcpp/Condition.h Ah. I see. Eval stop in the global env with the condition as the argument. Clever. It is more of a hack due to lack of proper api from R. If you do this, make sure you don't have any c++ object in scope. Essentially that means you would evaluate `stop( condition )` in a top level catch block. Rcpp objects are I assume ok however. Depends what you mean by ok. If you mean objects like NumericVector, ... their destructor is responsible for calling R_ReleaseObject, i.e. let go of the protection that was set by their constructor. If the destructor is not called because R error handling does a long jump, you will get objects forever protected. So things will seemingly work, until you exhaust the memory. I will try signalCondition and see what happens. THK I can't get signalCondition to do anything. What exactly did you try ? Did you catch the condition at the R level, with withCallingHandlers or something. Just because you don't see something does not mean nothing happens. This works although I've not tested it for leaks. Easy enough to test for forgotten destructors. #include Rcpp.h using namespace Rcpp; void raise_condition(const std::string msg, const std::string type) { List cond; cond[message] = msg; cond[call] = R_NilValue; cond.attr(class) = CharacterVector::create(type, condition); Function stopper(stop); stopper(cond); } class A { public: A(){ Rprintf( A::A()\n ) ; } ~A(){ Rprintf( A::~A()\n ) ; } } ; // [[Rcpp::export]] void test(){ A a ; raise_condition( foo, bar) ; } /*** R test() */ which gives me: test() A::A() Error: foo So the destructor for A is never called. Not a big deal here, it was not doing anything. But might be more problematic elsewhere. void raise_condition(const std::string msg, const std::string type) { List cond; cond[message] = msg; cond[call] = R_NilValue; cond.attr(class) = CharacterVector::create(type, condition); Function stopper(stop); stopper(cond); } THK -- http://www.keittlab.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] Raise a condition
Le 19 juin 2014 à 03:05, Dirk Eddelbuettel e...@debian.org a écrit : On 18 June 2014 at 19:40, Tim Keitt wrote: | | | | On Wed, Jun 18, 2014 at 6:26 PM, Dirk Eddelbuettel e...@debian.org wrote: | | | Tim, | | Step back for a second and recognise that everything happens via | |SEXP .Call(SEXP a, SEXP b, ...) | | where R calls your C++ routine asynchronously. | | You can do tricks _within the subroutine that is called_ which is | essentially | what happens via the automatically-added try/catch block we have in C++. | And | Rcpp::stop() is just a shortcut for using those. | | | Can I throw a condition (meaning an object inheriting class condition) or am | I limited to strings? If I throw a condition, will it be raised as such? See eg Section 2.7 titled Exception Handling in my Springer book on Rcpp. This is standard stuff, and we discussed the basics in the 2011 JSS paper. You can throw anything that is subclassed from std::exception, and catch it appropriately. The default mechanism is to take the exception text and pass it to R -- because, once again, passing a string is all we can do. _Your_ code could course provide more complex things and keep them, and tickle (by error codes) retrieval via other functions. But again, the interface we are given by R is fixed. You can only be creative within the confines of that interface. Would be relatively easy to add an overload to stop https://github.com/RcppCore/Rcpp/blob/master/inst/include/Rcpp/exceptions.h#L195 so that it handles other things besides strings. The confines of the R interface is not the problem here. ___ 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] Using spatstat in Rcpp
Hello, You seem to be confusing R namespaces and C++ namespaces and assuming you can call an R function as if it belonged to a C++ namespace. R functions and c++ functions are different things. You can do something like: // get the spatstat environment Environment spatstat( package:spatstat ) ; // get the discpartarea function from that env Function discpartarea = spatstat[discpartarea]; Then you can call discpartarea. Romain Le 11 juin 2014 à 19:01, mohammad ghorbani ghorbani...@yahoo.com a écrit : Hi there, I would like to call discpartarea() and as.owin() functions of spatstat from Rcpp. In a simple example consider the following C++ code in which I'm trying to access the above functions: #include Rcpp.h using namespace Rcpp; // [[Rcpp::export]] NumericVector IndepSelfCortCpp( NumericMatrix obsu) { NumericMatrix obsxy = obsu( _ , Range(1,2) ) ; NumericVector xyW= NumericVector::create(0,56,0,38); double rslt = 0; rslt= spatstat::discpartarea(obsxy, 0.1, spatstat::as.owin(xyW)); return (rslt); } /* ** R obsu - matrix(c(0.5, 1.5, 4, 12, 1,2,3,4,2,3,5,7), ncol=3) IndepSelfCortCpp(obsu) */ When I source the file in Rstudio with sourceCpp(), I get the error: 'spatstat' has not been declard I was wondering, a direct call a function of an R package like spatstat is possible from Rcpp. If yes, Could anyone help me on debugging the code? Best Regards, Mohammad Ghorbani ___ 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] Speed up of the data.frame creation in DataFrame.h
Le 7 juin 2014 à 03:27, Dmitry Nesterov dmitry.neste...@gmail.com a écrit : Hello, Here I report the slowness in creation of Rcpp DataFrame objects and proposed change to speed it up. For system information, here is output from sessionInfo(): R version 3.1.0 (2014-04-10) Platform: x86_64-apple-darwin13.1.0 (64-bit) ... other attached packages: [1] microbenchmark_1.3-0 Rcpp_0.11.1 I am using Rcpp package to port my old functions written with R's C interface to a more convenient style of Rcpp. While writing code that creates data.frame’s, I noticed that the Rcpp-based code was running quite a bit slower (using microbenchmark package) than my old implementation. The difference was approximately 40(!) times slower for data frame 50x2 (row x col) I have narrowed the speed difference down to the following call: return Rcpp::DataFrame::create(Rcpp::Named(“xdata”)=x, Rcpp::Named(“ydata”)=y); Where x and y are Rcpp::NumericVector objects. By debugging through the code and Rcpp, I noticed that during the creation Rcpp uses “as.data.frame” conversion on the vector list that contained x, y vectors and their names “xdata” and “ydata”, while this step was not necessary in my previous code using C interface. Well, how then do you guarantee that the data frame is not corrupt ? Consider this code: #include Rcpp.h using namespace Rcpp ; // [[Rcpp::export]] DataFrame test(){ NumericVector x = NumericVector::create( 1, 2, 3, 4 ) ; NumericVector y = NumericVector::create( 1, 2 ) ; return DataFrame::create(_[x] = x, _[y] = y ) ; } The benefit of calling as.data.frame is that it would handle recycling y correctly. Just setting the class attribute to data.frame by brute force would make a corrupt data frame. Perhaps you can get your suggestion approved on the basis of being consistent with other ways to get corrupt data frames in Rcpp. https://github.com/RcppCore/Rcpp/issues/144 The basic idea is valid, but this would need more work and understanding of the conceptual requirements of a data frame. Romain In Rcpp/DataFrame.h:87 static DataFrame_Impl from_list( Parent obj ){ This in turn calls on line 104: return DataFrame_Impl(obj) ; and which ultimately calls on line 78: void set__(SEXP x){ if( ::Rf_inherits( x, data.frame )){ Parent::set__( x ) ; } else{ SEXP y = internal::convert_using_rfunction( x, as.data.frame ) ; Parent::set__( y ) ; } } Since the DataFrame::create() function has not set a class attribute to “data.frame” by far, the conversion “as.data.frame” takes place and slows down the creation of the final object. I propose to make change on line 103 to set class attribute to “data.frame”, so no further conversion will take place: if( use_default_strings_as_factors ) { Rf_setAttrib(obj, R_ClassSymbol, Rf_mkString(data.frame)); return DataFrame_Impl(obj) ; } I tested it and it brought the speed of execution of the function to about the same as it was before with plain C API. Please let me know if it makes sense or maybe I should use DataFrame::create() function differently. Best, Dmitry ___ 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] Speed up of the data.frame creation in DataFrame.h
Hello, I was merely pointing out the problem. People who maintain and contribute to Rcpp will tell you what they expect. I am no longer one of them. So I don’t really care either way, unless it starts adding a bug that will cause issues for software I’m involved with that still has to depend on Rcpp for reasons out of my control. On a general note, I’d argue that it makes sense to submit the pull request anyway as it creates a special place where you can discuss the proposal, and it triggers continuous testing, so that travis will tell you if you break something. Romain Le 7 juin 2014 à 14:35, Dmitry Nesterov dmitry.neste...@gmail.com a écrit : Hello Romain, maybe then another function, like force_create() could be available? Or some checks for equal number of elements in each vector. One of the main Rcpp advantages to the user is its flexibility and speed, compared to the plain R code. I am not sure at this point what solution would be the best, but having fast methods in Rcpp would be really great. Should I wait then before submitting the pull request? Dmitry On Jun 7, 2014, at 7:21 AM, Romain François rom...@r-enthusiasts.com wrote: Le 7 juin 2014 à 03:27, Dmitry Nesterov dmitry.neste...@gmail.com a écrit : Hello, Here I report the slowness in creation of Rcpp DataFrame objects and proposed change to speed it up. For system information, here is output from sessionInfo(): R version 3.1.0 (2014-04-10) Platform: x86_64-apple-darwin13.1.0 (64-bit) ... other attached packages: [1] microbenchmark_1.3-0 Rcpp_0.11.1 I am using Rcpp package to port my old functions written with R's C interface to a more convenient style of Rcpp. While writing code that creates data.frame’s, I noticed that the Rcpp-based code was running quite a bit slower (using microbenchmark package) than my old implementation. The difference was approximately 40(!) times slower for data frame 50x2 (row x col) I have narrowed the speed difference down to the following call: return Rcpp::DataFrame::create(Rcpp::Named(“xdata”)=x, Rcpp::Named(“ydata”)=y); Where x and y are Rcpp::NumericVector objects. By debugging through the code and Rcpp, I noticed that during the creation Rcpp uses “as.data.frame” conversion on the vector list that contained x, y vectors and their names “xdata” and “ydata”, while this step was not necessary in my previous code using C interface. Well, how then do you guarantee that the data frame is not corrupt ? Consider this code: #include Rcpp.h using namespace Rcpp ; // [[Rcpp::export]] DataFrame test(){ NumericVector x = NumericVector::create( 1, 2, 3, 4 ) ; NumericVector y = NumericVector::create( 1, 2 ) ; return DataFrame::create(_[x] = x, _[y] = y ) ; } The benefit of calling as.data.frame is that it would handle recycling y correctly. Just setting the class attribute to data.frame by brute force would make a corrupt data frame. Perhaps you can get your suggestion approved on the basis of being consistent with other ways to get corrupt data frames in Rcpp. https://github.com/RcppCore/Rcpp/issues/144 The basic idea is valid, but this would need more work and understanding of the conceptual requirements of a data frame. Romain In Rcpp/DataFrame.h:87 static DataFrame_Impl from_list( Parent obj ){ This in turn calls on line 104: return DataFrame_Impl(obj) ; and which ultimately calls on line 78: void set__(SEXP x){ if( ::Rf_inherits( x, data.frame )){ Parent::set__( x ) ; } else{ SEXP y = internal::convert_using_rfunction( x, as.data.frame ) ; Parent::set__( y ) ; } } Since the DataFrame::create() function has not set a class attribute to “data.frame” by far, the conversion “as.data.frame” takes place and slows down the creation of the final object. I propose to make change on line 103 to set class attribute to “data.frame”, so no further conversion will take place: if( use_default_strings_as_factors ) { Rf_setAttrib(obj, R_ClassSymbol, Rf_mkString(data.frame)); return DataFrame_Impl(obj) ; } I tested it and it brought the speed of execution of the function to about the same as it was before with plain C API. Please let me know if it makes sense or maybe I should use DataFrame::create() function differently. Best, Dmitry ___ 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] table, rev and missing names
Hello, You pretty much have to do this manually. rev is part of Rcpp sugar. Defined here: https://github.com/RcppCore/Rcpp/blob/master/inst/include/Rcpp/sugar/functions/rev.h It does not preserve names. That’s by design. It would have been very difficult to do it automatically, i.e. what happens here: rev( x * y ), etc … it is hard to decide which names to propagate, harder to try to follow R rules about it, and even harder to implement. So if you want names, you have to handle them yourself. Romain Le 6 juin 2014 à 12:58, Sven E. Templer sven.temp...@gmail.com a écrit : Hi, consider this code: require(Rcpp) require(inline) t - cxxfunction(sig=c(xx=character), plugin=Rcpp, body=' CharacterVector x(xx); IntegerVector t = table(x); return t;') r - cxxfunction(sig=c(xx=character), plugin=Rcpp, body=' CharacterVector x(xx); IntegerVector t = table(x); IntegerVector r = rev(t); return r;') o - cxxfunction(sig=c(xx=character), plugin=Rcpp, body=' CharacterVector x(xx); IntegerVector t = table(x); CharacterVector n = t.names(); IntegerVector r = rev(t); r.names() = rev(n); return r;') t(c('a','a','b',NA)) r(c('a','a','b',NA)) o(c('a','a','b',NA)) Reversed vectors loose their name ( t() vs r() ) and have to be copied and reversed 'manually' ( as in o() ). Is rev() a function declared by Rcpp, if so can names be reserved while reverting or is there any other easier solution than in o() ? Thank you! Sven ___ 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] Rcpp release candidate
Watch out for this part: Le 5 juin 2014 à 15:05, Gabor Grothendieck ggrothendi...@gmail.com a écrit : installing to C:/Users/Gabor/Documents/R/win-library/3.1/Rcpp/libs/x64 Warning in file.copy(files, dest, overwrite = TRUE) : problem copying .\Rcpp.dll to C:\Users\Gabor\Documents\R\win-library\3.1\Rcpp\libs\x64\Rcpp.dll: Permission denied I guess you tried to install from github while Rcpp was already loaded in your R session, so it has not really been installed. Romain ** R ** inst ** tests ** preparing package for lazy loading ** help *** installing help indices ** building package indices ** installing vignettes ** testing if installed package can be loaded *** arch - i386 *** arch - x64 * DONE (Rcpp) code - ' + // [[Rcpp::plugins(cpp11)]] + #include Rcpp.h + #include boost/range/irange.hpp + using boost::irange; + // [[Rcpp::depends(BH)]] + // [[Rcpp::export]] + int useCpp11() { + auto sum(0); + for(const auto i : irange(0,4)) { sum += i; } + return sum; + } + ' library(Rcpp) sourceCpp(code = code, rebuild = TRUE) useCpp11() [1] 6 R.version.string [1] R version 3.1.0 Patched (2014-05-09 r65562) On Thu, Jun 5, 2014 at 4:21 AM, JJ Allaire jj.alla...@gmail.com wrote: I couldn't reproduce this on Windows 7 with R 3.1 (which should have been using USE_CXX1X=yes under the hood resulting in -std=c++0x passed to gcc). However, I have this change which should make the cpp11 plugin automatically pass -std=c++0x when on R = 3.0: https://github.com/RcppCore/Rcpp/pull/148 Does that work for you? You can install with: devtools::install_github(RcppCore/Rcpp, ref = feature/windows-c++0x) On Thu, Jun 5, 2014 at 3:36 AM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Wed, Jun 4, 2014 at 11:21 PM, Dirk Eddelbuettel e...@debian.org wrote: Rcpp 0.11.2 should be ready. If anybody wants to jump in and do last minute testing, please do so now. I ran two complete tests against CRAN last weekend, the results are summarized as usual in the GitHub repo at https://github.com/RcppCore/rcpp-logs Of 215 CRAN packages, all but 18 passed. Of those 18 a number where due to package sirt not building because ... I use FC='ccache gfortran' which is not gfortran so its configure failed. Grrr. I would pass next time. Anyway, 195 packages passed just fine, so we should be good. But if there is something anyone of you would like to test, now would be a good time as I may upload the current version to CRAN in the next few days unless I hear objections. There seems to be a problem using Rcpp::plugins(cpp11) on Windows 8.1. It gives the error: cc1plus.exe: error: unrecognized command line option '-std=c++11' I am using Rtools 3.1.0.1942 (which is the latest version) and for that it needs -std=c++0x or -std=gnu++0x If I remove the plugins line and instead issue this line first then it all works (except as per prior email I built Rcpp without vignettes to get around that problem): Sys.setenv(PKG_CXXFLAGS=-std=c++0x) # for gcc 4.6.3 code - ' + // [[Rcpp::plugins(cpp11)]] + + #include Rcpp.h + #include boost/range/irange.hpp + + using boost::irange; + + // [[Rcpp::depends(BH)]] + + // [[Rcpp::export]] + int useCpp11() { + auto sum(0); + for(const auto i : irange(0,4)) { sum += i; } + return sum; + } + ' library(Rcpp) sourceCpp(code = code) g++ -m64 -IC:/PROGRA~1/R/R-3.1/include -DNDEBUG -IC:/Users/Gabor/Documents/R/win-library/3.1/Rcpp/include -IC:/Users/Gabor/Documents/R/win-library/3.1/BH/include -Id:/RCompile/CRANpkg/extralibs64/local/include -std=c++11-O2 -Wall -mtune=core2 -c file18a42f7f546e.cpp -o file18a42f7f546e.o cc1plus.exe: error: unrecognized command line option '-std=c++11' make: *** [file18a42f7f546e.o] Error 1 Warning message: running command 'make -f C:/PROGRA~1/R/R-3.1/etc/x64/Makeconf -f C:/PROGRA~1/R/R-3.1/share/make/winshlib.mk SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB=sourceCpp_83768.dll WIN=64 TCLBIN=64 OBJECTS=file18a42f7f546e.o' had status 2 Error in sourceCpp(code = code) : Error 1 occurred building shared library. useCpp11() Error: could not find function useCpp11 sourceCpp(code = code, verbose = TRUE) Generated extern C functions #include Rcpp.h RcppExport SEXP sourceCpp_37333_useCpp11() { BEGIN_RCPP SEXP __sexp_result; { Rcpp::RNGScope __rngScope; int __result = useCpp11(); PROTECT(__sexp_result = Rcpp::wrap(__result)); } UNPROTECT(1); return __sexp_result; END_RCPP } Generated R functions --- `.sourceCpp_37333_DLLInfo` - dyn.load('C:/Users/Gabor/AppData/Local/Temp/RtmpmUpJdX/sourcecpp_18a41e263c3c/sourceCpp_77519.dll') useCpp11 - Rcpp:::sourceCppFunction(function() {}, FALSE, `.sourceCpp_37333_DLLInfo
Re: [Rcpp-devel] Error during wrapup
This looks like a protection issue. For whomever this makes sense to: From the code that wraps such object, i would investigate the call to setAttrib. Perhaps we are supposed to get the result of it and protect it. So i would tend to use an Armor instead of a Shield. Romain Le 28 mai 2014 à 16:02, John Mous john.mo...@gmail.com a écrit : Hmm, unfortunately the GitHub version failed also. The attributes on the failed object are a little different though, here's what they look like: Browse[1] str(results) atomic [1:4] 1 1 2270 0 - attr(*, )= symbol sim - attr(*, value)= promise to NULL On Tue, May 27, 2014 at 6:10 PM, John Mous john.mo...@gmail.com wrote: Hi Kevin, Thanks. I will give the GitHub version a try -- the error usually manifests only after running for about a day or so, so it may take a while to do that. Unfortunately I am having trouble creating a small reproducible example -- a function with just the assignments as written in my previous e-mail works fine when executed thousands of times in a loop. The full code is not that long (~165 lines), but is also non-trivial. It's odd that something else is causing things to fail with the end result being that only the field *names*, which are hardcoded, and not the values, not coming through properly. Since you said you suspect the problem may be fixed, can you give me a hint of what you think it may be related to? This might help me isolate the piece of offending code. On Tue, May 27, 2014 at 5:46 PM, Kevin Ushey kevinus...@gmail.com wrote: Hi John, I think we may have tackled this in some of the latest fixes with the version of Rcpp on GitHub. Can you try installing that version and trying again? Ie, try install.packages(devtools); devtools::install_github(RcppCore/Rcpp) then try running your code again. Alternatively, please supply a small reproducible example that we can try to run ourselves. You may be able to tease this error out reproducibly if you run it with gctorture(TRUE) on. Thanks, Kevin On Tue, May 27, 2014 at 2:42 PM, John Mous john.mo...@gmail.com wrote: Hello, I am passing back a very simple std::mapstd::string, int from Rcpp as follows: std::mapstd::string, int result; result[X1] = X1; result[X2] = X2; result[X3] = X3; result[X4] = X4; return wrap(result); The keys are hardcoded as shown, and the values X1-X4 are ints. Almost always everything works fine, however, very intermittently, a vector is returned on the R side _without_ named fields. For example: Browse[1] results [1] 1 2 863 0 Error during wrapup: 'getCharCE' must be called on a CHARSXP Browse[1] str(results) atomic [1:4] 1 2 863 0 - attr(*, )= symbol X1 - attr(*, )= language `[[-`(`*tmp*`, sim, value = 1L) results[[X1]] works, but results[[X1]] does not, and X2-X4 can be retrieved only by index. However, again, most runs are successful: Browse[1] results X1 X2 X3 X4 11 32540 Browse[1] str(results) Named int [1:4] 1 1 3254 0 - attr(*, names)= chr [1:4] X1 X2 X3 X4 I am using R 3.1.0 and Rcpp 0.11.1. Does the message Error during wrapup: 'getCharCE' must be called on a CHARSXP within this context hint anything to anyone familiar with Rcpp's internals? I realize it's almost impossible to diagnose with the given information -- is there a way to get Rcpp to display more debugging information? Thank you. ___ 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 ___ 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] Error during wrapup
(now with some links): Le 28 mai 2014 à 16:31, John Mous john.mo...@gmail.com a écrit : The object really is just built as part of the return statement. i.e. the lines from my prior e-mail exist as-is in the full code, Sure. What happens is that Rcpp::export generates something that calls wrap( std::mapstd::string,int ). there's just more that actually builds the variables X1-X4 beforehand. It should not be relevant. So I'm not sure where to debug from the client side. I'm a C/C++ developer, but have no experience with Rcpp internals or the general interface between R and C. I can insert some debug statements on the Rcpp side if you can guide me to where wrap is defined. well wrap is defined here: https://github.com/RcppCore/Rcpp/blob/master/inst/include/Rcpp/internal/wrap_end.h#L28 It then performs a series of dispatch, that eventually lead to something that handles std::mapstd::string,int: https://github.com/RcppCore/Rcpp/blob/master/inst/include/Rcpp/internal/wrap.h#L255 template typename InputIterator, typename T inline SEXP range_wrap_dispatch___impl__cast( InputIterator first, InputIterator last, ::Rcpp::traits::false_type ){ size_t size = std::distance( first, last ) ; const int RTYPE = ::Rcpp::traits::r_sexptype_traitstypename T::second_type::rtype ; ShieldSEXP x( Rf_allocVector( RTYPE, size ) ); ShieldSEXP names( Rf_allocVector( STRSXP, size ) ) ; typedef typename ::Rcpp::traits::storage_typeRTYPE::type CTYPE ; CTYPE* start = r_vector_startRTYPE(x) ; size_t i =0; std::string buf ; for( ; isize; i++, ++first){ start[i] = (*first).second ; buf = (*first).first ; SET_STRING_ELT( names, i, Rf_mkChar(buf.c_str()) ) ; } ::Rf_setAttrib( x, R_NamesSymbol, names ) ; return wrap_extra_stepsT( x ) ; } what I suspect to be the problem is this line: ::Rf_setAttrib( x, R_NamesSymbol, names ) ; What Romain says makes sense to me, despite my lack of expertise in this area.. the really intermittent nature of the problem and the fact that I can't recreate it in a small / fast running example suggests that perhaps this manifests when R happens to garbage collect at an unfortunate time (if I understood correctly). Thanks again. Something like that. as hadley hinted, please try this under gc torture, or preferably through a debugger. On Wed, May 28, 2014 at 10:12 AM, Dirk Eddelbuettel e...@debian.org wrote: On 28 May 2014 at 10:02, John Mous wrote: | Hmm, unfortunately the GitHub version failed also. Darn. | The attributes on the failed | object are a little different though, here's what they look like: | | Browse[1] str(results) | atomic [1:4] 1 1 2270 0 | - attr(*, )= symbol sim | - attr(*, value)= promise to NULL I am not sure what we can do without a reproducible example. :-/ The code just got a review / refreshment over the last few months. You best bet may the slow and tedious insertion of debug statements to see when / if the object changes. Dirk -- Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.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] Error during wrapup
Le 29 mai 2014 à 00:35, John Mous john.mo...@gmail.com a écrit : No luck with gctorture on yet, but I haven't run it for very long. It slowed things down to a complete crawl, but maybe in the long run it can recreate the problem faster than running the original code (about 12 hours, the previous estimate of a day was too high), so this may still be worthwhile. On a whim I did try changing the two instances of Shield to Armor this morning (I was able to locate the code in wrap.h by digging around before I saw your e-mail) and ran the original full code without gctorture on, and the problem still persists. Would not be enough, you'd also have to do: x = ::Rf_setAttrib( x, R_NamesSymbol, names ) ; so that the result of setAttrib gets protected even if it is a new SEXP, which AFAIU can happen with setAttrib. But I'm not sure this is the problem. Romain On Wed, May 28, 2014 at 3:44 PM, Romain Francois rom...@r-enthusiasts.com wrote: (now with some links): Le 28 mai 2014 à 16:31, John Mous john.mo...@gmail.com a écrit : The object really is just built as part of the return statement. i.e. the lines from my prior e-mail exist as-is in the full code, Sure. What happens is that Rcpp::export generates something that calls wrap( std::mapstd::string,int ). there's just more that actually builds the variables X1-X4 beforehand. It should not be relevant. So I'm not sure where to debug from the client side. I'm a C/C++ developer, but have no experience with Rcpp internals or the general interface between R and C. I can insert some debug statements on the Rcpp side if you can guide me to where wrap is defined. well wrap is defined here: https://github.com/RcppCore/Rcpp/blob/master/inst/include/Rcpp/internal/wrap_end.h#L28 It then performs a series of dispatch, that eventually lead to something that handles std::mapstd::string,int: https://github.com/RcppCore/Rcpp/blob/master/inst/include/Rcpp/internal/wrap.h#L255 template typename InputIterator, typename T inline SEXP range_wrap_dispatch___impl__cast( InputIterator first, InputIterator last, ::Rcpp::traits::false_type ){ size_t size = std::distance( first, last ) ; const int RTYPE = ::Rcpp::traits::r_sexptype_traitstypename T::second_type::rtype ; ShieldSEXP x( Rf_allocVector( RTYPE, size ) ); ShieldSEXP names( Rf_allocVector( STRSXP, size ) ) ; typedef typename ::Rcpp::traits::storage_typeRTYPE::type CTYPE ; CTYPE* start = r_vector_startRTYPE(x) ; size_t i =0; std::string buf ; for( ; isize; i++, ++first){ start[i] = (*first).second ; buf = (*first).first ; SET_STRING_ELT( names, i, Rf_mkChar(buf.c_str()) ) ; } ::Rf_setAttrib( x, R_NamesSymbol, names ) ; return wrap_extra_stepsT( x ) ; } what I suspect to be the problem is this line: ::Rf_setAttrib( x, R_NamesSymbol, names ) ; What Romain says makes sense to me, despite my lack of expertise in this area.. the really intermittent nature of the problem and the fact that I can't recreate it in a small / fast running example suggests that perhaps this manifests when R happens to garbage collect at an unfortunate time (if I understood correctly). Thanks again. Something like that. as hadley hinted, please try this under gc torture, or preferably through a debugger. On Wed, May 28, 2014 at 10:12 AM, Dirk Eddelbuettel e...@debian.org wrote: On 28 May 2014 at 10:02, John Mous wrote: | Hmm, unfortunately the GitHub version failed also. Darn. | The attributes on the failed | object are a little different though, here's what they look like: | | Browse[1] str(results) | atomic [1:4] 1 1 2270 0 | - attr(*, )= symbol sim | - attr(*, value)= promise to NULL I am not sure what we can do without a reproducible example. :-/ The code just got a review / refreshment over the last few months. You best bet may the slow and tedious insertion of debug statements to see when / if the object changes. Dirk -- Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.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] Converting std::cout to Rcpp::Rcout automatically
Hi, I used to redirect std::cout to Rcpp::Rcout back when I still had Rcout in Rcpp11. e.g. https://github.com/Rcpp11/Rcpp11/blob/22cc410ea87a2668e547acf6510d07ca812dfca8/src/Rcpp11_init.cpp Which was basically leveraging std::cout.rdbuf. A variant of http://stackoverflow.com/questions/10150468/how-to-redirect-cin-and-cout-to-files And then just using std::cout; Of course then you get CRAN complaining. Romain Hi, dear all, I am using Rcpp to integrate an available C++ library with R. Since the std::cout and std::cerr are not permitted when uploading to CRAN, I have to modify files manually. It will be somewhat laborious if the library Does anyone have any idea how can I do that automatically? Thank you! Best, KK -- Qiang Kou q...@umail.iu.edu School of Informatics and Computing, Indiana University ___ 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] Not able to convert from Rcpp::NumericVector to Teuchos::ArrayRCPsize_t
Hello, From what I understand of ArrayRCP, having read the documentation for a few minutes. (http://trilinos.sandia.gov/packages/docs/r9.0/packages/teuchos/doc/html/classTeuchos_1_1ArrayRCP.html) This looks like a vector and therefore it is likely that the default ExporterT will not be useful as it tries to use the constructor taking a SEXP : template typename T class Exporter{ public: Exporter( SEXP x ) : t(x){} inline T get(){ return t ; } private: T t ; } ; you can use a RangeExporter instead which looks more compatible to what ArrayRCP looks like: template typename T class RangeExporter { public: typedef typename T::value_type r_export_type ; RangeExporter( SEXP x ) : object(x){} ~RangeExporter(){} T get(){ T vec( ::Rf_length(object) ); ::Rcpp::internal::export_range( object, vec.begin() ) ; return vec ; } private: SEXP object ; } ; You can probably do this by having something like this early enough (after RcppCommon.h but before Rcpp.h). namespace Rcpp { namespace traits { template typename T class Exporter Teuchos::ArrayRCPT : public RangeExporter Teuchos::ArrayRCPT { public: Exporter( SEXP x) : RangeExporter Teuchos::ArrayRCPT (x){} } } } Romain Le 23 mai 2014 à 00:42, Chaomei Lo chaome...@gmail.com a écrit : Sorry to confuse you, Dirk, I had my previous message title wrong. Here below was the message with the correct title and content. I have created R packages using Makevars and it works pretty good for me. I am able to convert from a Rcpp::NumericVector to std::vector as in below. NumericVector col_cts = buildMatrix(Xr); vectorlong unsigned int col_counts = Rcpp::asvectorlong unsigned int(col_cts); Now I am having a problem with an application involves the Trilinos library. Here below I am trying to convert a Rcpp::NumericVector to Teuchos::ArrayRCPsize_t in the following line, it gave me errors as shown below in red. Would you please help me with this ? Teuchos::ArrayRCPsize_t col_counts=Rcpp::asTeuchos::ArrayRCPsize_t(col_cts); Thanks a lot. In file included from /share/apps/R/3.0.2/lib64/R/library/Rcpp/include/Rcpp/as.h:25:0, from /share/apps/R/3.0.2/lib64/R/library/Rcpp/include/RcppCommon.h:169, from /share/apps/R/3.0.2/lib64/R/library/Rcpp/include/Rcpp.h:27, from buildMatrix.cpp:4: /share/apps/R/3.0.2/lib64/R/library/Rcpp/include/Rcpp/internal/Exporter.h: In constructor 'Rcpp::traits::ExporterT::Exporter(SEXP) [with T = Teuchos::Array RCPlong unsigned int, SEXP = SEXPREC*]': /share/apps/R/3.0.2/lib64/R/library/Rcpp/include/Rcpp/as.h:79:51: instantiated from 'T Rcpp::internal::as(SEXP, Rcpp::traits::r_type_generic_tag) [with T = Teuchos::ArrayRCPlong unsigned int, SEXP = SEXPREC*]' /share/apps/R/3.0.2/lib64/R/library/Rcpp/include/Rcpp/as.h:144:84: instantiated from 'T Rcpp::as(SEXP) [with T = Teuchos::ArrayRCPlong unsigned int, SEXP = SEXPREC*]' buildMatrix.cpp:84:87: instantiated from here /share/apps/R/3.0.2/lib64/R/library/Rcpp/include/Rcpp/internal/Exporter.h:31:31: error: invalid conversion from 'SEXP' to 'long int' [-fpermissive] /people/d3j508/trilinos-11.6.1/trilinos-11.6.1_Install/include/Teuchos_ArrayRCP.hpp:129:1: error: initializing argument 1 of 'Teuchos::ArrayRCPT::ArrayRC P(Teuchos::ArrayRCPT::size_type, const T) [with T = long unsigned int, Teuchos::ArrayRCPT::size_type = long int]' [-fpermissive] make: *** [buildMatrix.o] Error 1 ERROR: compilation failed for package 'Tpkg' ___ 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] bigmatrix and segmentation fault due to 'memory not mapped'
Le 15 mai 2014 à 09:03, Stefano Calza steca...@gmail.com a écrit : Hi everybody, I am trying to use big.matrix from Rcpp basically to write some (integer) data to a matrix. I keep getting segmentation fault due to 'memory not mapped'. Debugging with gdb I found out that the critical point is MatrixAccessorint ma(*pBigMat); The function is declared as something like (I just followed the Gallery Rcpp example): RcppExport SEXP myFun(SEXP X, SEXP Y, SEXP Z, SEXP XX, XPtrBigMatrix pBigMat) Basically it cannot get to the correct pointer. The really weird thing is that this error happens ONLY using the function built within a package .Call('myFun',X,Y,Z,XX,bigMat@address,package='myPackage') BUT if I use the very same code, changing just the declaration // [Rcpp::export] IntegerVector myFun(SEXP X, SEXP Y, SEXP Z, SEXP XX, XPtrBigMatrix pBigMat) and then sourceCpp('mycode.cpp') and myFun(X,Y,Z,XX,bigMat@address) it works fine! So what am I doing wrong here? Is the pointer reset somehow? But why only when using .Call version? Thanks Stefano If you use a raw .Call, all your parameters have to be SEXP. If you want to use other parameter types, such as XPtrBigMatrix, you need to use attributes (i.e. sourceCpp or compileAttributes) so that it generates .Call compatible function for you. Romain ___ 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] Questions on extending Rcpp wrap and as with templates
Le 6 mai 2014 à 08:45, Florian Burkart florian.burk...@gmail.com a écrit : Hi everyone (and Dirk), Second attempt on corrected email list. I have been trying to extend Rcpp with my own wrap and as templates. Two issues: 1) I need to explicitly call wrap. Is that expected? So for example I wrote this specialization: This is not a specialization, just another overload. You need to write a specialization, as in: namespace Rcpp{ template SEXP wrapstd::vector TimedOptDouble (std::vectorTimedOptDouble const entries) { … } } template SEXP Rcpp::wrap(std::vectorTimedOptDouble const entries) { std::vectordouble sec_times; std::vectordouble doubles; for(auto const entry : entries) { sec_times.push_back(entry.GetTime().Seconds()); TimedOptDouble::OptDouble opt_double(entry.GetOptDouble()); if(opt_double) doubles.push_back(*opt_double); else doubles.push_back(R_NaReal); } return List::create( Named( Time ) = sec_times, Named( Value ) = doubles); } First of all, this returns what I believe to be a Rcpp::List object, which seems to be converted implicitly to a SEXP. This is the typical behaviour I know. Unfortunately, when making use of this template, it doesn't work implicitly, but I need to explicitly call it. So for example SEXP GetSunPositions(SEXP a) { std::vectorTimedOptDouble sun_positions; ... return wrap(sun_positions); } works, where as return sun_positions; as last line doesn't. Am I doing something wrong here? I did do the declaration before including Rcpp.h. This should work if you return a std::vector TimedOptDouble from your function, as in: std::vector TimedOptDouble GetSunPositions(SEXP a) { … } 2) How to make as work for own types in containers The other way around, one can return a std::vectordouble implicitly, but how do I return std::vectorMyType? I tried to define template MyType as(SEXP); But that didn't help, e.g. I had to write my own template std::vectorMyType as(SEXP); This is the easiest way. A more general way would need you to express how to handle containers of MyType, but that requires defining some traits classes etc … not sure it is worth the effort. But again, you’d need to actually write a specialization: template std::vectorMyType as std::vectorMyType (SEXP); Romain Thanks for help Florian ___ 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] How to create list of list without known structure
Le 6 mai 2014 à 09:35, Florian Burkart florian.burk...@gmail.com a écrit : Hi, I have been creating lists of lists with return Rcpp::List::create(Rcpp::Named(vec) = someVector, Rcpp::Named(lst) = someList, Rcpp::Named(vec2) = someOtherVector); or to follow Romain: using namespace Rcpp ; return List::create( _[vec] = someVector, _[lst] = someList, _[vec2] = someOtherVector ) ; But how do I convert the following into a list of lists? std::vectorstd::string m_column_headers; std::vectorstd::vectorOptDouble m_vectors_of_values; You probably just need to know about .names() =, i.e. something like this should do: List values = wrap(m_vectors_of_values) ; values.names() = m_column_headers ; FWIW, in Rcpp11, you could use structure, e.g. : List values = structure( m_vectors_of_values, _[names] = m_column_headers ) ; Romain ___ 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] g++ flags
That looks alright to me. But apparently dirk has another way to do it that does not depend on R 3.1.0, whatever works. Romain Le 30 avr. 2014 à 16:15, JJ Allaire jj.alla...@gmail.com a écrit : Romain, I think this PR addresses the issue: https://github.com/RcppCore/Rcpp/pull/143 I've tested and it seems to work as intended. Is this fix you were conceiving of or is there something more we should be doing? J.J. On Wed, Apr 30, 2014 at 9:19 AM, Romain Francois rom...@r-enthusiasts.com wrote: The plugin as implemented now is not portable. The easiest way to make it portable would be to define the USE_CXX1X environment variable, which R knows how to interpret. This way R would do what makes sense, i.e. use -std=c++0x on windows (for which rtools is limited to gcc 4.6.3 now) and -std=c++11 when it makes sense. Romain Le 30 avr. 2014 à 15:10, Darren Cook dar...@dcook.org a écrit : The problem seems to be that Rcpp uses -std=c++11; however, g++ 4.6.3, which is what comes with the latest version of Rtools on Windows, uses -std=c++0x or -std=gnu++0x ... In g++ 4.8.1 those two are deprecated in favour of -std=c++11 and -std=gnu++11 respectively; however they are still available. Darren ___ 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] Parallel random numbers using Rcpp and OpenMP
Hi, If you can assume c++11, you might bot need openmp, as you can just use standard support for threads, etc ... Although the compiler suite used on windows (if you care about that) does not support c++11 threads. This might be available later. Romain Le 28 avr. 2014 à 12:51, Matteo Fasiolo matteo.fasi...@gmail.com a écrit : Hi all, many thanks for your detailed replies, I see that there are many options out there. As a first step I think I will try out the C++11 option that Matt suggested, as it seems relatively simple. In particular I might do something like: #pragma omp parallel { std::mt19937_64 engine( static_castuint64_t(seeds[omp_get_thread_num()] ) ); std::uniform_real_distributiondouble zeroToOne(0.0, 1.0); #pragma omp for for (int i = 0; i 1000; i++) { double a = zeroToOne(engine); } } were seeds is a NumericVector coming from R. That's probably not ideal, but it might give reasonable and reproducible results. Thanks, Matteo On Mon, Apr 28, 2014 at 9:39 AM, Matt D. mat...@gmail.com wrote: On 4/28/2014 01:30, Matteo Fasiolo wrote: [...] As I understand, doing things such as: NumericMatrix out(n, d); #pragma omp for schedule(static) for(int kk = 0; kk d; kk++) out( _, kk) = rnorm(n); is not going to work, because rnorm() is not thread safe (in fact this code crashed R). On the other hand R level parallelism using clusterApply, mclapply etc appears to be too slow to be of any use for this purpose. Is anybody aware of any package providing a parallel C++ rng which my package might link to? Your first choice can be to go with the C++ Standard Library -- header random -- (importantly) using one object per thread: http://stackoverflow.com/questions/8813592/c11-thread-safety-of-random-number-generators See: http://en.cppreference.com/w/cpp/numeric/random http://isocpp.org/blog/2013/03/n3551-random-number-generation Since you're using OpenMP, you can get the distinct thread ID by using the `omp_get_thread_num` function: http://stackoverflow.com/questions/15918758/how-to-make-each-thread-use-its-own-rng-in-c11 Note that if you're doing large scale parallel statistics (say, Monte Carlo) you may also want a PRNG with statistical properties which don't deteriorate (e.g., no spurious correlation, let alone overlapping) for very large samples; preferably, also one that doesn't maintain any kind of global state (so-called stateless) is going to be easier to use, too (nothing to synchronize/lock across threads). A relatively recent work that's particularly relevant is Random123: https://www.deshawresearch.com/resources_random123.html http://www.thesalmons.org/john/random123/ MIT-licensed C++ version is available here: http://www.sitmo.com/article/parallel-random-number-generator-in-c/ With a simple example: http://www.sitmo.com/article/multi-threaded-random-number-generation-in-c11/ // The author is currently working on getting it into Boost.Random; discussion: http://www.wilmott.com/messageview.cfm?catid=44threadid=95882STARTPAGE=2#710955 HTH, Best, Matt ___ 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 ___ 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] Rcpp11 3.1.0 is on CRAN
Hello, (may contains traces of personal opinions) My motivation for starting Rcpp11 were: - Assuming C++11, which is nicer to use and teach. Rcpp still wants to be compatible with older standard, which essentially means that even if I write something new using C++11, I still have to figure out how to write the same thing in C++98. - modernize the code base. This meant let go of a few features so that we have what we keep better. This is incompatible with Rcpp’s maintainership policy. Last time I asked to remove a feature from Rcpp, I was told that it would take a year of deprecation. In Rcpp11, because I’m in charge I can decide to break stuff to make something better. Rcpp has been a great project to work on for me. I’ve learned a lot of C++, and I think I owe most of my C++ knowledge from involvement I have with Rcpp. But as far as I’m concerned, the string requirements take all the fun away. Working on Rcpp11 has brought fun back. I can innovate. There will always be some conceptual compatibility between Rcpp and Rcpp11. For example both have the NumericVector class to handle numeric vectors. However in that particular example, the implementation of NumericVector in Rcpp is too complicated, you have gazillion of constructors, etc ... hard to maintain, hard to document, hard to teach. Now that Rcpp11 can be used on current versions of OSX, recent enough linux, windows and even solaris (if you use gcc), what I would suggest is that you try it and come back with questions (not on this list though, please use the google group that is not strictly restricted to Rcpp questions). What might help you deciding is that in Rcpp11, we did not retain some features such as modules and date/time related classes. If your code uses these, then you should probably either stick with Rcpp or start motivating me for adding something along the lines in Rcpp11. There is still a need for something like modules, but not with this implementation. Now, as Dirk says, you can use C++11 with Rcpp. Just as much as you can use C++11 with vanilla .Call/.C. Personally I think the future of R and C++ is with Rcpp11. This is where I’ll focus my time. Romain Le 17 avr. 2014 à 08:24, Søren Højsgaard sor...@math.aau.dk a écrit : Dear all, My understanding is that Rcpp11 will employ features of c++11 (which is very nice) but other than that it is not clear to me how Rcpp and Rcpp11 relate to each other? Can I start to use Rcpp11 with my existing Rcpp-based packages or is Rcpp and Rcpp11 branching off in different directions? Cheers Søren -Original Message- From: rcpp-devel-boun...@lists.r-forge.r-project.org [mailto:rcpp-devel-boun...@lists.r-forge.r-project.org] On Behalf Of Romain Francois Sent: 11. april 2014 15:26 To: rcpp-devel@lists.r-forge.r-project.org Subject: [Rcpp-devel] Rcpp11 3.1.0 is on CRAN Hello, I'll keep it short here. Rcpp11 3.1.0 was released on CRAN today. An announcement email has been sent to both r-packages and the new R and C++ mailing list. https://groups.google.com/forum/#!forum/r-and-cpp Best Regards, Romain ___ 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] Rcpp11 3.1.0 is on CRAN
Le 17 avr. 2014 à 09:42, Hao Ye h...@ucsd.edu a écrit : Hi Romain, Thanks for the explanation -- I was curious about the difference between Rcpp and Rcpp11, as well. What might help you deciding is that in Rcpp11, we did not retain some features such as modules and date/time related classes. If your code uses these, then you should probably either stick with Rcpp or start motivating me for adding something along the lines in Rcpp11. There is still a need for something like modules, but not with this implementation. Does this mean that there will be some other mechanism for exposing c++ classes to R? Maybe in some way that supports inheritence? ;) Yes. Problems with Rcpp modules are: - the way you express things is limited by C++ grammar. It was fun and challenging to write it. But experience of teaching modules shows that the concepts are somewhat hard to grasp. - it is very demanding in terms of resources In the future, I’d like to look into code generation (a la attributes) as a mean of exposing classes. So we need something expressive enough. My current blue sky line of thinking about this is that I’d like to have some sort of intermediate language between R and C++. John has done something similar with the exposeClass in Rcpp. https://github.com/RcppCore/Rcpp/blob/master/R/exposeClass.R It goes in the right direction, but this time you are limited by R’s grammar. This has been on my radar for some time, but I think having a class system that is nice to use in R requires some grammatical changes. It is unlikely that I will have the leverage to change R’s grammar, but what I can work on is an intermediate language that generates R code. In any case, Rcpp11 still has the external pointer class template, so we can « write modules by hand ». Romain ___ 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] Rcpp11 3.1.0 is on CRAN
Hello, I’ll keep it short here. Rcpp11 3.1.0 was released on CRAN today. An announcement email has been sent to both r-packages and the new R and C++ mailing list. https://groups.google.com/forum/#!forum/r-and-cpp Best Regards, Romain ___ 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] Distribution of Rcpp codebase
Le 8 avr. 2014 à 10:12, Xavier Robin xav...@cbs.dtu.dk a écrit : My 2 cents... On 07/04/14 10:12, Romain François wrote: It would also mean many copies of the same code base. To which I’m thinking: so what. No, it will mean many copies of /many different and mostly outdated/ code bases. Still: so what ;) You can count on me to forget to git pull next time I update my package. And as long as your package keeps working, this is not so much of an issue. You are then in control of which version of the codebase is used. If you want a new version of the codebase, you can get it, and the challenge for me is to make it easy enough for you to get and deploy it into your package, if you don’t that’s fine. Now consider the alternative. You have no idea of which version of the codebase is used with your package. You have no idea if the version used at runtime is the same as the version that was used when the package was compiled. When a new Rcpp package is released, you definitely have to recompile yours, and need to ask your users to recompile your package against this version. I prefer when I’m in control. What about something like the BH package that contains the boost headers? I'm using it in a project I'm working on, and just use a LinkingTo declaration with something in Makevars. That works fine because BH is truly header only. Rcpp is not. The change in Rcpp 0.11.0 was a big step forward, but it is a job half done. Functions in the .h files of Rcpp constantly poke into the Rcpp.so. Any binary change in Rcpp creates hard problem to fix. Currently the usual advice is to ask to recompile, etc ... It is really easy to make such a binary change. Of course ideally it would be in a build-depends type of declaration so it isn't pulled during binary installs. Xavier ___ 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] Generic R and C++ discussion
Hello, I have created a new mailing list (as a google group) for general discussions about R and C++. https://groups.google.com/forum/#!forum/r-and-cpp Shame that it had to come to this, but apparently Rcpp-devel is only for discussing the Dirk approved implementation of Rcpp. Personally, I will keep watching Rcpp-devel, and I hope I can still contribute interesting answers here, but I will use the google group for broad discussions. Romain ___ 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] Distribution of Rcpp codebase
Le 8 avr. 2014 à 10:51, Rainer M Krug rai...@krugs.de a écrit : Martyn Plummer plumm...@iarc.fr writes: And another 2 cents from me. A package is the basic unit of functionality in R. Whatever functionality you are providing, I think a package is the best way to deliver it. There is a well developed framework for versioning, dependency resolution, testing, and distribution. If you choose some other mechanism, then I suspect that any developer problems you eliminate will just return as system administration problems. I thought I could keep out of this... rcpp... is so much the core of many packages, that the mechanism of packages really shows its shortcomings, namely the versioning. A different aspect was discussed on the r-devel list some time ago concerning snapshots of CRAN to provide reproducibility. The part which makes rcpp outstanding from other packages, is that it is used mainly during compilation and not that much during running - that is if I understand the header only concept correctly. Well with the current Rcpp, you still need the runtime for any of the functions that are registered here: https://github.com/RcppCore/Rcpp/blob/master/src/Rcpp_init.cpp#L85 That’s what I meant earlier when I mentioned job half done. The intention of the change in 0.11.0 was to move away from runtime, but we did not go far enough. In contrast, as far as I know, all other packages provide run-time features as well as compile time - and this is what the packages were designed for - and I might say they work quite well. I agree. I can see Romain's point (oparticularly the more fine grained control of the developer), but I also understand that Dirk will keep rcpp as a package. Sure. My question is: would it be possible to combine these two, i.e. have one package, which contains different versions, and to use one command to switch between these? So one would have one package, which will switch between different versions? I see your point, but I would not want to do that. I can definitely foresee a whole new class of issues with this scenario. I don't know if this would be possible or a suitable solution? The other would obviously be to have different versions of rcpp on CRAN, similar to ggplot or oxygen. I can see this working. But there could be Rcpp_0_12_0, Rcpp_0_12_1, etc .. as different packages so that developers who want to update their package would need to change the version on which they depend. Not sure CRAN would be impressed if I start releasing a new package for each version. Cheers, Rainer Martyn On Tue, 2014-04-08 at 10:12 +0200, Xavier Robin wrote: My 2 cents... On 07/04/14 10:12, Romain François wrote: It would also mean many copies of the same code base. To which I’m thinking: so what. No, it will mean many copies of /many different and mostly outdated/ code bases. You can count on me to forget to git pull next time I update my package. What about something like the BH package that contains the boost headers? I'm using it in a project I'm working on, and just use a LinkingTo declaration with something in Makevars. Of course ideally it would be in a build-depends type of declaration so it isn't pulled during binary installs. Xavier ___ 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 -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Stellenbosch University South Africa Tel : +33 - (0)9 53 10 27 44 Cell: +33 - (0)6 85 62 59 98 Fax : +33 - (0)9 58 10 27 44 Fax (D):+49 - (0)3 21 21 25 22 44 email: rai...@krugs.de Skype: RMkrug PGP: 0x0F52F982 ___ 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] Distribution of Rcpp codebase
Le 8 avr. 2014 à 11:47, Rainer M Krug rai...@krugs.de a écrit : Romain François rom...@r-enthusiasts.com writes: Le 8 avr. 2014 à 10:51, Rainer M Krug rai...@krugs.de a écrit : Martyn Plummer plumm...@iarc.fr writes: And another 2 cents from me. A package is the basic unit of functionality in R. Whatever functionality you are providing, I think a package is the best way to deliver it. There is a well developed framework for versioning, dependency resolution, testing, and distribution. If you choose some other mechanism, then I suspect that any developer problems you eliminate will just return as system administration problems. I thought I could keep out of this... rcpp... is so much the core of many packages, that the mechanism of packages really shows its shortcomings, namely the versioning. A different aspect was discussed on the r-devel list some time ago concerning snapshots of CRAN to provide reproducibility. The part which makes rcpp outstanding from other packages, is that it is used mainly during compilation and not that much during running - that is if I understand the header only concept correctly. Well with the current Rcpp, you still need the runtime for any of the functions that are registered here: https://github.com/RcppCore/Rcpp/blob/master/src/Rcpp_init.cpp#L85 That’s what I meant earlier when I mentioned job half done. The intention of the change in 0.11.0 was to move away from runtime, but we did not go far enough. I must admit, I am not to familiar with rcpp to comment on these functions, but would it be possible to split Rcpp into headers-only, i.e. only for compiling and developing, and Rcpp-runtime for runtime? Because I really think it might make sense to have additional function at runtime? They are really too tightly coupled for that. I’ve been through making Rcpp11 truly header only and it was really hard. It was worth every second of it, but still hard. Doing it for Rcpp is impossible, at least with Dirk’s maintainer requirements. In contrast, as far as I know, all other packages provide run-time features as well as compile time - and this is what the packages were designed for - and I might say they work quite well. I agree. I can see Romain's point (oparticularly the more fine grained control of the developer), but I also understand that Dirk will keep rcpp as a package. Sure. My question is: would it be possible to combine these two, i.e. have one package, which contains different versions, and to use one command to switch between these? So one would have one package, which will switch between different versions? I see your point, but I would not want to do that. I can definitely foresee a whole new class of issues with this scenario. I don't know if this would be possible or a suitable solution? The other would obviously be to have different versions of rcpp on CRAN, similar to ggplot or oxygen. I can see this working. But there could be Rcpp_0_12_0, Rcpp_0_12_1, etc .. as different packages so that developers who want to update their package would need to change the version on which they depend. Well - I would stick with the usual system, that would mean Rcpp_0_12, Rcpp_0_13, ... and no further fine grained. Same difference. I think this would be kind of confusing, but at least it would be allowed as « Rcpp » is not the same name as « Rcpp_0_12 ». As a side note, I plan to version Rcpp11 according to the version of R, so the first release of Rcpp11 will be version 3.1.0, ... Not sure CRAN would be impressed if I start releasing a new package for each version. Agreed. Cheers, Rainer Martyn On Tue, 2014-04-08 at 10:12 +0200, Xavier Robin wrote: My 2 cents... On 07/04/14 10:12, Romain François wrote: It would also mean many copies of the same code base. To which I’m thinking: so what. No, it will mean many copies of /many different and mostly outdated/ code bases. You can count on me to forget to git pull next time I update my package. What about something like the BH package that contains the boost headers? I'm using it in a project I'm working on, and just use a LinkingTo declaration with something in Makevars. Of course ideally it would be in a build-depends type of declaration so it isn't pulled during binary installs. Xavier ___ 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 -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Stellenbosch University South Africa Tel : +33
Re: [Rcpp-devel] Generic R and C++ discussion
Le 8 avr. 2014 à 13:28, stat quant mail.statqu...@gmail.com a écrit : Hi, Will that be ok to ask Rcpp questions to on this list too? Definitely. Anything R and C++ related. On 8 Apr 2014 09:56, Romain François rom...@r-enthusiasts.com wrote: Hello, I have created a new mailing list (as a google group) for general discussions about R and C++. https://groups.google.com/forum/#!forum/r-and-cpp Shame that it had to come to this, but apparently Rcpp-devel is only for discussing the Dirk approved implementation of Rcpp. Personally, I will keep watching Rcpp-devel, and I hope I can still contribute interesting answers here, but I will use the google group for broad discussions. Romain ___ 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] Error in Module
Hello, Just sourceCpp the .cpp file and use the functions verbatim: sourceCpp( /tmp/mod.cpp ) bar(2L) [1] 4 If you really want to use the module as an object, you have to pick it up from the right spot: yada - Module(yada, where = tail(getLoadedDLLs(), 1)[[1]] ) yada$hello() [1] hello Romain Le 8 avr. 2014 à 09:00, Brötje David d.broe...@tu-braunschweig.de a écrit : Hello, I want to expose a C++ class to R through Rcpp. For that I want to try out a few examples from the note Exposing C++ functions and classes with Rcpp modules and the book Seamless R and C++ Integration with Rpp. But I can't manage to get them work. It ends up with an error. So this is what I'm doing. First I create a cpp file with the c++ code from the example. The full content of the cpp file is below. #include Rcpp.h using namespace Rcpp; std::string hello() { return hello; } int bar( int x) { return x*2; } double foo( int x, double y) { return x*y; } void bla( ) { Rprintf( hello\\n ); } void bla1( int x) { Rprintf( hello (x = %d)\\n, x ); } void bla2( int x, double y) { Rprintf( hello (x = %d, y = %5.2f)\\n, x, y ); } RCPP_MODULE(yada) { using namespace Rcpp; function( hello , hello ); function( bar , bar ); function( foo , foo ); function( bla , bla ); function( bla1 , bla1 ); function( bla2 , bla2 ); } Then I run this command: PKG_CXXFLAGS=`Rscript -e 'Rcpp:::CxxFlags()'` PKG_LIBS=`Rscript -e 'Rcpp:::LdFlags()'` R CMD SHLIB test.cpp Afterwards I start R and run these commands in R: require(Rcpp) yada - Module(yada) yada$bar( 2L ) yada$foo( 2L, 10.0 ) yada$hello() yada$bla() yada$bla1( 2L) yada$bla2( 2L, 5.0 ) And it ends up with this error: Error in Module(module, mustStart = TRUE) : Failed to initialize module pointer: Error in FUN(_rcpp_module_boot_yada[[1L]], ...): no such symbol _rcpp_module_boot_yada in package .GlobalEnv This happens all the time with modules. Did I overlook something or what am I doing wrong? David ___ 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] Distribution of Rcpp codebase
Le 7 avr. 2014 à 15:13, Gábor Csárdi csardi.ga...@gmail.com a écrit : On Mon, Apr 7, 2014 at 4:12 AM, Romain François rom...@r-enthusiasts.com wrote: [...] However, in terms of wins: - package developers would know for sure which version of the codebase is used with their package. Once they have done testing, they don’t have to be hostage of api breakage and things like « please recompile your package, etc … » - developers of Rcpp* are less trapped by the compatibility issues, hands are set free to innovate. The only small downsides I see here is that (1) users potentially have to do more work to include Rcpp* in their packages (although you can just write an R function to include/update their Rcpp* versions); and that (2) source packages will be somewhat bigger. The difference is that if they don’t want a new version, they can stick with the version they have in their package. So when they want newer Rcpp, they can have it, but they are not forced to do anything when the Rcpp* team wants to update the codebase. About 1). We just need to find a good way to propagate newer Rcpp* into a repo. Maybe through git subtree, git sub modules or something. We can come up with some tools. About 2). So What ;) Btw. you are essentially simulating versioned package dependencies this way. :) Yep. The next thing to consider is that Rcpp is not just Rcpp, there are really nice extensions like RcppArmadillo, etc ... perhaps we could setup some tools (e.g. RcppJam) to combine several header only libraries into the end package, instead of what we do now, which is have some headers in Rcpp, some in RcppArmadillo, some in RcppGSL, … with every risk of one being outdated or out of sync with the other. Exactly. IMHO this could work well and take the pressure of both Rcpp* developers and users. Gabor ___ 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] No no no -- Distribution of Rcpp codebase
Le 7 avr. 2014 à 15:34, Dirk Eddelbuettel e...@debian.org a écrit : Romain, Gabor, Would you considerr taking this discussion elsewhere? This is a broad discussion that might be relevant to anyone doing R and C++ work. So no. Or at least make it very clear that you are talking about the Rcpp11, which as AFAICT has not left Github. Rcpp11 needs R 3.1.0, so of course it is not on CRAN yet. But this discussion is not about the Rcpp11 package, it is not about the Rcpp package. It is about exchanging ideas about what would be beneficial to the community of people using R and C++. The way the Rcpp codebase is currently distributed might have been the best model for years, but I’m not convinced it is the best solution nowadays, so I wanted to discuss, and this list is the best venue, whether you like it or not. As for Rcpp11, I am indeed going to release it as an R package, but I will also definitely consider alternatives such as snapshotting the distribution as part of the client package. I think there are advantages to doing that. But don’t worry, I will definitely not do anything to change the Rcpp package. You are doing a fine job of keeping it alive. Rcpp was created as a CRAN package. It remains a CRAN package. It fits squarely into the dependency mechanism of CRAN. It has proven useful, and stable. As a consequence it is as of today used by almost 200 CRAN packages and almost 20 BioC package. Please do not confuse our users by implying that any of this is about to change. You are more than welcome to experiment with new approaches, new implementation, new distributions, ... but *please* make sure you continue to do so under a new name too. or what ? This list is about Rcpp. The CRAN package. In mt view, this list is about R and C++, broadly. At least it was the intention when I created it many years ago. There are plenty of threads in this list that are not stricly related to Rcpp. The world of R and C++ is bigger than Rcpp. Romain ___ 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] Distribution of Rcpp codebase
Le 7 avr. 2014 à 19:20, Gábor Csárdi csardi.ga...@gmail.com a écrit : On Mon, Apr 7, 2014 at 9:20 AM, Romain François rom...@r-enthusiasts.com wrote: [...] The only small downsides I see here is that (1) users potentially have to do more work to include Rcpp* in their packages (although you can just write an R function to include/update their Rcpp* versions); and that (2) source packages will be somewhat bigger. The difference is that if they don’t want a new version, they can stick with the version they have in their package. So when they want newer Rcpp, they can have it, but they are not forced to do anything when the Rcpp* team wants to update the codebase. About 1). We just need to find a good way to propagate newer Rcpp* into a repo. Maybe through git subtree, git sub modules or something. We can come up with some tools. Oh, I see, you mean installing Rcpp* dependent packages from git(hub) directly. I imagine some people would want to put the headers into their tree, as ordinary files. Having the files into the client package is what I meant. This way, the developer of the package is in control of what version is used. The challenge is how to make it easy. Others might want to have it as submodules. For the latter to work, I imagine you would need to set up some special repo structure. I think git subtree gives something close to what I mean. But obviously someone could just copy the files manually, it would just be a matter of copying the inst/include directory. Btw. I obviously don't have to tell you, but I want to point it out that this snapshotting is already possible today. I can just take the Rcpp* headers and put them in my package, and then I don't have to worry about future changes. This is assuming the package is header-only. With compiled code it is trickier, because of the name clashes. Good luck doing that with current Rcpp. Many functions are compiled into the shared library shipped with the package. It is not linking as it used to do it, which is the big win of 0.11.0, but there is still a library. Many of these functions go through the namespace of the Rcpp package, etc … so you could snapshot Rcpp, but it would definitely not be easy at all. So I think, the question is whether to support this with some infrastructure, e.g. to update the embedded headers, have them as a git submodule, etc. About 2). So What ;) Agreed. CRAN-core might be fussy about it, though, if source packages get much bigger because of this. Or might be not. This is a drop of water in the ocean of CRAN packages. I think the benefit would outweigh this quite easily. In any case, not gonna happen, at least not with Rcpp. Romain ___ 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] Distribution of Rcpp codebase
Thanks to have interest in this discussion. Le 7 avr. 2014 à 20:30, Kevin Ushey kevinus...@gmail.com a écrit : Here's some thoughts, from the perspective of a package developer who might want to use Rcpp11. One option is to have the Rcpp11 distribution live as a git repository within the `inst/include` directory of a developer's package. A package developer could clone the repository (or have it track the inst/include subdirectory of Rcpp11 -- not sure if that's possible), and at their leisure pull the current version, pull a certain tag / release, and so on.). Maybe there's something that needs to be in .Rbuildignore to ensure the .git repository doesn't get added into the built package on R CMD build. Some R functions, e.g. useRcpp11(), could be written that, when run in the package directory, clones a repository in inst/include/Rcpp, and also updates pertinent licensing information (this package uses Rcpp11, which is licensing under so-and-so...). Essentially they would be nice wrappers to git. Maybe package these as part of an Rcpp11 CRAN / GitHub release. I think git subtree is the right tool. I'm not sure how well a mechanism like this would work for syncing across the other Rcpp libraries, e.g. RcppArmadillo, though. As long as these other are header only, that would be pretty easy. We’d have to diverge them as well as they carry various fastLm, etc ... which really don’t belong there (before the Rcpp police gets involves : I know they will stay). One should expect that packages depending on Rcpp11 will still want to be submitted to CRAN, and one potential problem (I know we could say 'not our problem', but we should be good citizens) is that, if R-Core decides to make an R API change that causes these packages to fail R CMD check, it will be more painful for them to accept maintenance releases from all these packages. There are guarantees on R api changes. I don’t see this as an issue. Finally -- we might consider moving this discussion to a new mailing list, since I think Rcpp and Rcpp11 are divergent enough that we should consider Rcpp-devel for Rcpp-the-package-specific discussion, and a different mailing list for Rcpp11 development. Thoughts, Romain? I though this mailing list was about discussing R and C++, but apparently I was wrong. Fair enough if this is just Rcpp related. Perhaps I’ll leave the mailing list as I’m not that interested in Rcpp anymore. Rcpp11 has its own github issues, this I think is enough for now, but sure maybe a new mailing list would be good. On Mon, Apr 7, 2014 at 10:20 AM, Gábor Csárdi csardi.ga...@gmail.com wrote: On Mon, Apr 7, 2014 at 9:20 AM, Romain François rom...@r-enthusiasts.com wrote: [...] The only small downsides I see here is that (1) users potentially have to do more work to include Rcpp* in their packages (although you can just write an R function to include/update their Rcpp* versions); and that (2) source packages will be somewhat bigger. The difference is that if they don't want a new version, they can stick with the version they have in their package. So when they want newer Rcpp, they can have it, but they are not forced to do anything when the Rcpp* team wants to update the codebase. About 1). We just need to find a good way to propagate newer Rcpp* into a repo. Maybe through git subtree, git sub modules or something. We can come up with some tools. Oh, I see, you mean installing Rcpp* dependent packages from git(hub) directly. I imagine some people would want to put the headers into their tree, as ordinary files. Others might want to have it as submodules. For the latter to work, I imagine you would need to set up some special repo structure. Btw. I obviously don't have to tell you, but I want to point it out that this snapshotting is already possible today. I can just take the Rcpp* headers and put them in my package, and then I don't have to worry about future changes. This is assuming the package is header-only. With compiled code it is trickier, because of the name clashes. So I think, the question is whether to support this with some infrastructure, e.g. to update the embedded headers, have them as a git submodule, etc. About 2). So What ;) Agreed. CRAN-core might be fussy about it, though, if source packages get much bigger because of this. Or might be not. Gabor [...] ___ 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] Missing libRcpp.a and libRcpp.so
As of Rcpp 0.11.0, those no longer exist. You need to rebuild your packages from source against this Rcpp. See http://r.789695.n4.nabble.com/R-pkgs-Rcpp-0-11-0-td4684675.html Romain Le 25 mars 2014 à 10:24, Florian Burkart florian.burk...@gmail.com a écrit : Hi, This is probably quite straight forward but can't find the answer. I just installed Rcpp through R on a new Ubuntu install - however, /usr/local/lib/R/site-library/Rcpp is missing the lib directory which I have on my old machine. It contains libRcpp.a and libRcpp.so, which I link against (and now can't). How do I build those? Thanks, Florian ___ 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] Yet another instance of function 'dataptr' not provided ...
You need to import something, anything from Rcpp’s namespace. Sent you a pull request. Le 25 mars 2014 à 20:17, Douglas Bates ba...@stat.wisc.edu a écrit : I must have been away from writing R/Rcpp code for too long. I started off trying to reproduce a calculation that is, literally, a one-liner in Julia. See http://nbviewer.ipython.org/gist/dmbates/9746197 Now admittedly the calculation of the sums of the n choose k possible subsets of size k from a vector or length n is aided by the fact that there is a combinations iterator in Julia. Nonetheless it is pretty amazing that this can be written as combsums(v::Vector, k) = [sum(c) for c in combinations(v,k)] using this iterator and a comprehension. I tried to write the combinations iterator in C++ but eventually tied myself in knots so I decided to back off and write a function that does the equivalent of the R function sample() and use that to generate a random sample from the distribution of sums. I have the C++ code working using Rcpp attributes but now I must generate a package. I have to be missing something obvious because my attempt at http://github.com/dmbates/randomizationTest produces the dread function 'dataptr' not provided ... message when I try to invoke the R function randomsums. Which of the many vignettes or manuals should I start reading? (I can't believe I have spent two days going through innumerable contortions to try to achieve the effect of a one-liner.) ___ 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] Making objects in the C++ side persistent
Creating a package does not give you persistence of external pointers across sessions. Le 20 mars 2014 à 19:52, Dirk Eddelbuettel e...@debian.org a écrit : On 20 March 2014 at 12:40, Jiqiang Guo wrote: | RStan doesn't do anything to persist any c++ object. What's done is to save | the binary file created using package inline in an R object so it can be reused | without recompiling c++ code. So what is in cxxfunplus might not be related. Thanks for the clarification. My recommendation is usually to just create a package. We know that works. Dirk -- Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.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] Rcpp syntactic sugar equivalent for R's optimize() function
Le 28 févr. 2014 à 11:52, Gregor Kastner gregor.kast...@wu.ac.at a écrit : Hi Hideyoshi, Is there a way I can just call that function in Rcpp rather than having to install new libraries or create my own? (I presume that there is probably a “C_do_fmin.c” file somewhere that I can use?) This questions has been discussed in this list about a month ago: http://r.789695.n4.nabble.com/Linking-to-native-routines-in-other-packages-tt4683969.html#none As Dirk said, this is not the same thing. The level of complexity of calling an internal function of the stats package is quite high. I’d suggest : - reimplement clean c++ code as Dirk says - call the R function optimize form C++. Chances are the overhead of doing that is minimal and anecdotic compared to calling the objective function. - use something else as Dale says. I am now using the approach that Romain suggested in this thread. Be sure to include PKG_CPPFLAGS+=-I../inst/include/ As it has been reported to me by Brian Ripley, += is a gnu-ism so it is not portable. Also, you should not have the last `/` So: PKG_CPPFLAGS = -I../inst/include in the Makevars and Makevars.win files. AFAIK know this mechanism is not automated (yet), see http://r.789695.n4.nabble.com/LinkingTo-self-tt4684613.html Best, Gregor ___ 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] Rcpp module support
Rcpp11 is an alternative implementation of Rcpp indeed. It does not mean discussing it is not suitable to this mailing list. Rcpp11 will be released closely after R 3.1.0, whenever this happens to be. It contains major improvements over Rcpp, will be completely header only (no src/ directory at all) and will depend and leverage C++11 greatly. Le 27 févr. 2014 à 03:33, Dirk Eddelbuettel e...@debian.org a écrit : On 26 February 2014 at 21:25, KNAG, RALPH H (RALPH H) wrote: | I just saw a tweet that said that support for Rcpp modules will be dropped in | ?Release 11?. | When will this occur? This mailing list is about Rcpp -- whereas the tweet you refer to (if it was the same one I saw) was about Rcpp11, which is a different project. Dirk ___ 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] Avoiding having to write .h files
Hi, Then just put fun1 and fun2 in the same file. This is yet again less work than having two files. Romain Le 25 févr. 2014 à 12:45, Søren Højsgaard sor...@math.aau.dk a écrit : Only because it is extra work... Anyway, I hope this Rcpp::interfaces(r,cpp)-feature gets up and running again :) Søren -Original Message- From: Romain François [mailto:rom...@r-enthusiasts.com] Sent: 25. februar 2014 12:39 To: Søren Højsgaard Cc: rcpp-devel@lists.r-forge.r-project.org (rcpp-de...@r-forge.wu-wien.ac.at) Subject: Re: [Rcpp-devel] Avoiding having to write .h files Hello, Why do you want to avoid writing headers. I guess you could use extern For example, in foo1.cpp : double fun1(){ return 2.0 ; } In foo2.cpp ; extern double fun1() ; double fun2(){ return fun1() + 2; } Romain Le 25 févr. 2014 à 12:28, Søren Højsgaard sor...@math.aau.dk a écrit : Dear all, If in a package I have foo1.cpp with function fun1 and foo2.cpp with fun2 (which uses fun1 from foo1.cpp) then I must write foo1.h and include in foo2.cpp. Right? Is there another approach so that I do not have to write these header files? Using Rcpp::interfaces(r,cpp) should take care of that (according to the Rcpp-attributes vignette, at least that is my understanding) but I have seen on the list that there is a bug in this feature with the current Rcpp version (and also with the devel version on github). Cheers Søren ___ 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] Default empty values for vector and matrices
Le 17 févr. 2014 à 12:17, Alessandro Mammana mamm...@molgen.mpg.de a écrit : Dear all, I am trying to write an Rcpp function that accepts optionally a vector, but I cannot figure out what default value I should give to it. First I tried the following: // [[Rcpp::export]] int nilVec(NumericVector v = R_NilValue){ int sum = 0; for (int i = 0; i v.length(); ++i){ sum += v[i]; } return sum; } but when trying: nilVec() I get the error Not compatible with REALSXP, which is maybe not very consistent with the fact that in R you can do as.numeric(NULL) and it gives you a vector of length 0. R’s behavior is incoherent. NULL is not a numeric vector. Then I tried: // [[Rcpp::export]] int nilVec(NumericVector v = NumericVector()){ int sum = 0; for (int i = 0; i v.length(); ++i){ sum += v[i]; } return sum; } but it doesn't compile. That’s the attribute parser not making sense of it. It does compile, but the default is not propagated to R. I found the following discussion: http://comments.gmane.org/gmane.comp.lang.r.rcpp/5922 where I discovered that for whatever reason the following compiles and works: // [[Rcpp::export]] int nilVec(NumericVector v = NumericVector::create(0)){ int sum = 0; for (int i = 0; i v.length(); ++i){ sum += v[i]; } return sum; } Well. It might appear as something that works. It is in fact a bug. NumericVector::create(0) is supposed to create a vector of length 1 with the value of the first element set to 0. not numeric vector of length zero as it is currently the case. bug. https://github.com/RcppCore/Rcpp/issues/117 But the funny thing is that this does not work: // [[Rcpp::export]] int nilMat(NumericMatrix v = NumericMatrix::create(0)){ int sum = 0; for (int i = 0; i v.length(); ++i){ sum += v[i]; } return sum; } Matrix::create is nonsense as it does not create a matrix. check : m - evalCpp( NumericMatrix::create(0) ) str(m) num 0 so creates a vector, not a matrix. Besides, what do you actually expect. What dimensions would this matrix have ? So how should I do for matrices? I would also be happy with the solution of defining somewhere an empty vector or an empty matrix and assigning it as default argument, but the following does not work: My suggestion would be to handle this on the R side. The attribute parser is not a fully capable C++ parser, stick to defaults for only very simple things, like int or double or strings. For anything else, you’re better of with dealing with the parameter logic on the R side. NumericVector empty(0); // [[Rcpp::export]] int nilVec(NumericVector v = empty){ int sum = 0; for (int i = 0; i v.length(); ++i){ sum += v[i]; } return sum; } Suggestions? I would be super happy if in the future the special value R_NilValue could be converted to an empty vector, it would make things very easy and coherent with R's behaviour. Thx in advance, Ale -- Alessandro Mammana, PhD Student Max Planck Institute for Molecular Genetics Ihnestraße 63-73 D-14195 Berlin, Germany ___ 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] Deriving type information
In addition to what Kevin said, perhaps you are looking for macros from this file: https://github.com/RcppCore/Rcpp/blob/master/inst/include/Rcpp/macros/dispatch.h Le 14 févr. 2014 à 00:34, Søren Højsgaard sor...@math.aau.dk a écrit : Dear all, Function foo_num below takes a numeric vector and returns a list with the first element of the vector. (Not very interesting function). I want to create a templated version of this in function do_foo below, but whether a should be a double, an integer, or a string depends on the RTYPE. My question is (and it is embarrasing to ask because I believe Romain has already answered it; just can't find the answer) how to derive the what type a should have once we know RTYPE?? My second question is: Isn't there an easier general way to write the dispatch function (I have in mind situations where the templated function takes *more* than one argument!)? I have in mind something like: int type = TYPEOF(XX_) ; return do_footype ( XX_ ) ; but that fails because INTSXP, REALSXP etc seems to be defined as const's (thats my reading of the compiler message). What goes into template parameters is compile time constant. And the type of an R object is dynamic, there is no way to know before runtime, so the compiler can not do this for you. Thanks Søren #include Rcpp.h using namespace Rcpp; //[[Rcpp::export]] List foo_num(NumericVector x){ double a=x[0]; return List::create( a ); } template int RTYPE List do_foo( VectorRTYPE x ){ double a=x[0]; // WHAT TO DO HERE??? return List::create( a ); } SEXP foo_any( SEXP XX_){ int type = TYPEOF(XX_) ; switch( type ){ case INTSXP : return do_fooINTSXP ( XX_ ) ; case REALSXP : return do_fooREALSXP( XX_ ) ; case STRSXP : return do_fooSTRSXP ( XX_ ) ; } return R_NilValue ; } ___ 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] Segfault, is it because of iterators/pointers?
Le 12 févr. 2014 à 13:36, Alessandro Mammana mamm...@molgen.mpg.de a écrit : Ah wait, my bad (as always T.T), I found a much simpler explanation: colset - sample(3e7-nr, 1e7) storage.mode(colset) [1] integer storage.mode(colset-1) [1] double So when I was unwrapping colset I allocated new memory in Rcpp to convert from double to integer, which was no longer valid when I went out of scope. I think it is a bit dangerous that you never know if you are allocating memory or just wrapping R objects when parsing arguments in Rcpp. Is there a way of ensuring that NOTHING gets copied when parsing arguments? Can you throw an exception if the type you try to cast to is not the one you expect? You might imagine that with large datasets this is important. Silent coercion was added by design. Rcpp does not give you a « strict » mode. One thing you can do is something like this: #include Rcpp.h using namespace Rcpp ; template typename T class Strict : public T { public: Strict( SEXP x ) { if( TYPEOF(x) != T::r_type::value ) stop( not compatible ) ; T::Storage::set__(x) ; } } ; // [[Rcpp::export]] int foo( StrictNumericVector v ){ return v.size() ; } You’d get e.g. foo(rnorm(10)) [1] 10 foo(1:10) Error in eval(expr, envir, enclos) : not compatible Calls: sourceCpp ... source - withVisible - eval - eval - foo - Anonymous Execution halted Sorry for bothering and thanks again, Ale On Wed, Feb 12, 2014 at 1:10 PM, Dirk Eddelbuettel e...@debian.org wrote: On 12 February 2014 at 11:47, Alessandro Mammana wrote: | Ok I was able to find the code causing the bug. So it looks like the Thanks for the added detail. | pointers you get from an Rcpp::Vector using .begin() become invalid | after that the Rcpp::Vector goes out of scope (and this makes sense), | what I do not understand is that this Rcpp::Vector was allocated in R | and should still be living during the execution of the Rcpp call | (that's why I wasn't expecting the pointer to be invalid). | | This is the exact code (the one above is probably fine): | @@ in CPP @@i | | struct GapMat { | int* ptr; | int* colset; | int nrow; | int ncol; | | | inline int* colptr(int col){ | return ptr + colset[col]; | } | | GapMat(){} | | GapMat(int* _ptr, int* _colset, int _nrow, int _ncol): | ptr(_ptr), colset(_colset), nrow(_nrow), ncol(_ncol){} | }; | | | GapMat getGapMat(Rcpp::List gapmat){ | IntegerVector vec = gapmat[vec]; | IntegerVector pos = gapmat[colset]; | int nrow = gapmat[nrow]; | | return GapMat(vec.begin(), pos.begin(), nrow, pos.length()); | } | | // [[Rcpp::export]] | IntegerVector colSumsGapMat(Rcpp::List gapmat){ | | GapMat mat = getGapMat(gapmat); | IntegerVector res(mat.ncol); | | for (int i = 0; i mat.ncol; ++i){ | for (int j = 0; j mat.nrow; ++j){ | res[i] += mat.colptr(i)[j]; | } | } | | return res; | } | | @@ in R (with gdb debugger as suggested by Dirk) @@i | library(Rcpp) | sourceCpp(scratchpad.cpp) | | vec - rnbinom(3e7, mu=0.1, size=1); storage.mode(vec) - integer | nr - 80 | | colset - sample(3e7-nr, 1e7) | foo - vec[colset] #this is only to trigger some obscure garbage | collection mechanisms... | | for (i in 1:10){ | colset - sample(3e7-nr, 1e7) | gapmat - list(vec=vec, nrow=nr, colset=colset-1) | cs - colSumsGapMat(gapmat) | print(sum(cs)) | } | | [1] 8000 | [1] 8000 | [1] 80016890 | [1] 80008144 | [1] 80016022 | [1] 80021609 | | Program received signal SIGSEGV, Segmentation fault. | 0x718a5455 in GapMat::colptr (this=0x7fffc120, col=0) at | scratchpad.cpp:295 | 295return ptr + colset[col]; | | @@@ | | Why did it happen? What should I do to make sure that my pointers | remain valid? My goal is to convert safely some vectors or matrices | that exist in R to some pointers, how can I do that? Not sure. It looks fine at first instance. But then it's early in the morning and I had very little coffee yet... Maybe the fact that you tickle the gc() via vec[colset] has something to do with it, maybe it has not. Maybe I would try the decomposition of the List object inside the colSumsGapMat() function to keep it simpler. Or if you _really_ want an external object to iterate over, memcpy it out. With really large object, you may be stressing parts of the code that have not been stressed the same way. If it breaks, you do get to keep both pieces. Dirk -- Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com -- Alessandro Mammana, PhD Student Max Planck Institute for Molecular Genetics Ihnestraße 63-73 D-14195 Berlin, Germany ___ Rcpp-devel mailing list
Re: [Rcpp-devel] calling and R function from rcpp and evaluation
Hi Antonio, This is about how R evaluation works. Might not just be what you think it is. When you use Rcpp and therefore .Call things are evaluated fairly early, at least earlier than what would happen with R, etc … you can reproduce what R does by using promises. For example this work in Rcpp11: // [[Rcpp::export]] RawVector rcpp_serialize(Dots dots){ Function serialize(serialize) ; return serialize( dots.promise(0), R_NilValue ) ; } Dots has not been implemented in Rcpp, but would not be too hard to port: https://github.com/romainfrancois/Rcpp11/blob/master/inst/include/Rcpp/Dots.h But it would also need to fix Rcpp’s handling of recursive promises (i.e. promise of a promise of a promise). Alternatively, for a solution based on Rcpp, you can look in dplyr. The .data_dots function has most of the R-level logic https://github.com/hadley/dplyr/blob/master/R/manip-df.r And the C++ logic is mostly in DataDots.h https://github.com/hadley/dplyr/blob/master/inst/include/tools/DataDots.h Romain Le 6 févr. 2014 à 02:07, Antonio Piccolboni anto...@piccolboni.info a écrit : Hi, I was wondering why I can serialize a call such as in serialize(call(ripley), NULL) [1] 58 0a 00 00 00 02 00 03 00 02 00 02 03 00 00 00 00 06 00 00 00 01 00 04 00 09 00 00 00 06 72 69 70 6c 65 79 00 00 00 fe but if I try from C++ the call gets evaluated library(Rcpp) rcpp.serialize = cppFunction(code=RObject my_serialize(RObject x){Function r_serialize(\serialize\); return r_serialize(x, R_NilValue);}) rcpp.serialize(10) [1] 58 0a 00 00 00 02 00 03 00 02 00 02 03 00 00 00 00 0e 00 00 00 01 40 24 00 00 00 00 00 00 # easy things work rcpp.serialize(call(ripley)) Error: could not find function ripley # wants to evaluate it unserialize(rcpp.serialize(call(sqrt, 2))) [1] 1.414214 # How is one to serialize the call itself rcpp.serialize(list(call(ripley))) [1] 58 0a 00 00 00 02 00 03 00 02 00 02 03 00 00 00 00 13 00 00 00 01 00 00 00 06 00 00 00 01 00 04 00 09 00 00 00 06 72 69 70 6c 65 79 00 00 00 fe #wrapping in a list is enough to stop evaluation eval(call(ripley)) Error in eval(expr, envir, enclos) : could not find function ripley eval(list(call(ripley))) [[1]] ripley() #OK that's consistent Could anyone enlighten me on the evaluation mechanism? Not saying it's broken, but certainly my expectations were off. Thanks Antonio ___ 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] Package built with Rcpp fails to install
The problem is likely to be that it was assumed that List derives from RObject. It used to, it does not anymore. Classes from the api now use a policy based design. See andrei alexandrescu's modern c++ book for the why and the how of policy based design. . Envoyé de mon iPhone Le 3 févr. 2014 à 20:01, Kevin Ushey kevinus...@gmail.com a écrit : Hi Tal, I get the same error with the new CRAN Rcpp, 0.11.0. I'll try to take a look later. -Kevin On Mon, Feb 3, 2014 at 10:32 AM, Tal Galili tal.gal...@gmail.com wrote: Dear Rcpp people, I am trying to get a new package to CRAN called {dendextendRcpp}. Here is the repos: https://github.com/talgalili/dendextendRcpp (note that this package relies on the {dendextend} which has just been released to CRAN today :) ) The package loads fine for me (on R-devel, with Windows 7), however Kurt Hornik (CRAN maintainer) could not get the package to load on Linux. Following is the error massage that he got. Any input (either here or on the git repo) will be most appreciated. With regards, Tal (p.s: I suspect this might be because I use .hpp files in src. Should I use something else?) * installing *source* package 'dendextendRcpp' ... ** libs clang++ -std=c++11 -I/home/Hornik/tmp/R-d-clang/include -DNDEBUG -I/usr/local/include -I/home/Hornik/lib/R/Library/3.1/x86_64-linux-gnu/Rcpp/include -fpic -g -O3 -Wall -Wno-unused -pedantic -c RcppExports.cpp -o RcppExports.o clang++ -std=c++11 -I/home/Hornik/tmp/R-d-clang/include -DNDEBUG -I/usr/local/include -I/home/Hornik/lib/R/Library/3.1/x86_64-linux-gnu/Rcpp/include -fpic -g -O3 -Wall -Wno-unused -pedantic -c cut_lower.cpp -o cut_lower.o cut_lower.cpp:35:7: error: no matching function for call to 'get_height' if(get_height(tree) = height) { ^~ ./get_branches_heights.hpp:29:8: note: candidate function not viable: no known conversion from 'List' (aka 'Vector19') to 'RObject' (aka 'RObject_ImplPreserveStorage') for 1st argument double get_height(RObject x); ^ cut_lower.cpp:36:13: error: no matching member function for call to 'push_back' lower.push_back(tree); ~~^ /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/stl_vector.h:901:7: note: candidate function not viable: no known conversion from 'List' (aka 'Vector19') to 'const value_type' (aka 'const Rcpp::RObject_ImplPreserveStorage') for 1st argument push_back(const value_type __x) ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/stl_vector.h:919:7: note: candidate function not viable: no known conversion from 'List' (aka 'Vector19') to 'value_type' (aka 'Rcpp::RObject_ImplPreserveStorage') for 1st argument push_back(value_type __x) ^ cut_lower.cpp:84:7: error: no matching function for call to 'is_leaf' if(is_leaf( tree )) { ^~~ ./is_functions.hpp:35:6: note: candidate function not viable: no known conversion from 'List' (aka 'Vector19') to 'RObject' (aka 'RObject_ImplPreserveStorage') for 1st argument bool is_leaf(RObject x); ^ 3 errors generated. make: *** [cut_lower.o] Error 1 clang++ -std=c++11 -I/home/Hornik/tmp/R-d-clang/include -DNDEBUG -I/usr/local/include -I/home/Hornik/lib/R/Library/3.1/x86_64-linux-gnu/Rcpp/include -fpic -g -O3 -Wall -Wno-unused -pedantic -c cut_lower.cpp -o cut_lower.o cut_lower.cpp:35:7: error: no matching function for call to 'get_height' if(get_height(tree) = height) { ^~ ./get_branches_heights.hpp:29:8: note: candidate function not viable: no known conversion from 'List' (aka 'Vector19') to 'RObject' (aka 'RObject_ImplPreserveStorage') for 1st argument double get_height(RObject x); ^ cut_lower.cpp:36:13: error: no matching member function for call to 'push_back' lower.push_back(tree); ~~^ /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/stl_vector.h:901:7: note: candidate function not viable: no known conversion from 'List' (aka 'Vector19') to 'const value_type' (aka 'const Rcpp::RObject_ImplPreserveStorage') for 1st argument push_back(const value_type __x) ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/stl_vector.h:919:7: note: candidate function not viable: no known conversion from 'List' (aka 'Vector19') to 'value_type' (aka 'Rcpp::RObject_ImplPreserveStorage') for 1st argument push_back(value_type __x) ^ cut_lower.cpp:84:7: error: no matching function for call to 'is_leaf' if(is_leaf( tree )) { ^~~ ./is_functions.hpp:35:6: note: candidate function not viable: no known conversion from 'List' (aka 'Vector19') to 'RObject' (aka 'RObject_ImplPreserveStorage') for 1st argument bool is_leaf(RObject x); ^ 3 errors generated. make: *** [cut_lower.o] Error 1 ERROR: compilation failed for package 'dendextendRcpp' * removing
Re: [Rcpp-devel] Package built with Rcpp fails to install
Le 3 févr. 2014 à 20:35, Tal Galili tal.gal...@gmail.com a écrit : Dear all, Dirk - I have now re-checked, and the package loads fine on my machine, and it is completely synced with github. The only files in my gitignore are: .Rproj.user .Rhistory .RData src/*.o src/*.so src/*.dll So I suspect that the versions are indeed the same. Kevin - thanks. Romain - I am glad you have an idea for what the problem might be. However, I am not sure I understand how to proceed in fixing it. Since the package is very minimalistic, any specific examples on what can be improved would be of great help. My message was more or less aimee at kevin who volunteered to help you. I juqt wanted to give him some context. I'm sure kevin will be able to make sense of why i said. Otherwise i'll have a look, but not this week. Cheers, Romain Thanks everyone, Tal Contact Details:--- Contact me: tal.gal...@gmail.com | Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Mon, Feb 3, 2014 at 9:12 PM, Romain Francois rom...@r-enthusiasts.com wrote: The problem is likely to be that it was assumed that List derives from RObject. It used to, it does not anymore. Classes from the api now use a policy based design. See andrei alexandrescu's modern c++ book for the why and the how of policy based design. . Envoyé de mon iPhone Le 3 févr. 2014 à 20:01, Kevin Ushey kevinus...@gmail.com a écrit : Hi Tal, I get the same error with the new CRAN Rcpp, 0.11.0. I'll try to take a look later. -Kevin On Mon, Feb 3, 2014 at 10:32 AM, Tal Galili tal.gal...@gmail.com wrote: Dear Rcpp people, I am trying to get a new package to CRAN called {dendextendRcpp}. Here is the repos: https://github.com/talgalili/dendextendRcpp (note that this package relies on the {dendextend} which has just been released to CRAN today :) ) The package loads fine for me (on R-devel, with Windows 7), however Kurt Hornik (CRAN maintainer) could not get the package to load on Linux. Following is the error massage that he got. Any input (either here or on the git repo) will be most appreciated. With regards, Tal (p.s: I suspect this might be because I use .hpp files in src. Should I use something else?) * installing *source* package 'dendextendRcpp' ... ** libs clang++ -std=c++11 -I/home/Hornik/tmp/R-d-clang/include -DNDEBUG -I/usr/local/include -I/home/Hornik/lib/R/Library/3.1/x86_64-linux-gnu/Rcpp/include -fpic -g -O3 -Wall -Wno-unused -pedantic -c RcppExports.cpp -o RcppExports.o clang++ -std=c++11 -I/home/Hornik/tmp/R-d-clang/include -DNDEBUG -I/usr/local/include -I/home/Hornik/lib/R/Library/3.1/x86_64-linux-gnu/Rcpp/include -fpic -g -O3 -Wall -Wno-unused -pedantic -c cut_lower.cpp -o cut_lower.o cut_lower.cpp:35:7: error: no matching function for call to 'get_height' if(get_height(tree) = height) { ^~ ./get_branches_heights.hpp:29:8: note: candidate function not viable: no known conversion from 'List' (aka 'Vector19') to 'RObject' (aka 'RObject_ImplPreserveStorage') for 1st argument double get_height(RObject x); ^ cut_lower.cpp:36:13: error: no matching member function for call to 'push_back' lower.push_back(tree); ~~^ /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/stl_vector.h:901:7: note: candidate function not viable: no known conversion from 'List' (aka 'Vector19') to 'const value_type' (aka 'const Rcpp::RObject_ImplPreserveStorage') for 1st argument push_back(const value_type __x) ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/stl_vector.h:919:7: note: candidate function not viable: no known conversion from 'List' (aka 'Vector19') to 'value_type' (aka 'Rcpp::RObject_ImplPreserveStorage') for 1st argument push_back(value_type __x) ^ cut_lower.cpp:84:7: error: no matching function for call to 'is_leaf' if(is_leaf( tree )) { ^~~ ./is_functions.hpp:35:6: note: candidate function not viable: no known conversion from 'List' (aka 'Vector19') to 'RObject' (aka 'RObject_ImplPreserveStorage') for 1st argument bool is_leaf(RObject x); ^ 3 errors generated. make: *** [cut_lower.o] Error 1 clang++ -std=c++11 -I/home/Hornik/tmp/R-d-clang/include -DNDEBUG -I/usr/local/include -I/home/Hornik/lib/R/Library/3.1/x86_64-linux-gnu/Rcpp/include -fpic -g -O3 -Wall -Wno-unused -pedantic -c cut_lower.cpp -o cut_lower.o cut_lower.cpp:35:7: error: no matching function for call to 'get_height' if(get_height(tree) = height
Re: [Rcpp-devel] Wierd compilation error
The attributes parser does not know how to handle the static keyword. Works for me without it. You get the line number of the generated file. Use verbose = TRUE to have a better clue at what is wrong. Romain Le 29 janv. 2014 à 12:24, Alessandro Mammana mamm...@molgen.mpg.de a écrit : Hi all, I was experimenting with templates and Rcpp and trying to compile this code: // [[Rcpp::export]] static void readVector(VectorINTSXP v){ traits::storage_typeINTSXP::type i = v[0]; Rcout i std::endl; } I got this error: scratchpad.cpp: In function 'SEXPREC* sourceCpp_3062_readVector(SEXP)': scratchpad.cpp:337:21: error: variable or field '__result' declared void scratchpad.cpp:338:9: error: '__result' was not declared in this scope make: *** [scratchpad.o] Error 1 Also, the line numbers don't make any sense, because the file scratchpad.cpp is only 250 lines long... Do you know what could be wrong? Thanks in advance! Ale -- Alessandro Mammana, PhD Student Max Planck Institute for Molecular Genetics Ihnestraße 63-73 D-14195 Berlin, Germany ___ 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] Rcpp version of c( )
Hi, There is currently nothing like that. It is quite hard to generalize. You might like std::merge, e.g. template typename Vec Vec do_conc_(Vec x, Vec y){ Vec out=no_init(x.size()+y.size()); std::merge( x.begin(), x.end(), y.begin(), y.end(), out.begin() ) ; return out; } We could want to generalize this to arbitrary sugar expressions, so that we could do e.g. conc( x+x, y+y ) ; without having to materialize x+x and y+y into their own memory ... Perhaps it would look like this: template int RTYPE, typename T1, typename T2 VectorRTYPE concat( const T1 t1, const T2 t2 ){ // use static_assert to make sure T1 and T2 are sugar expressions int n = t1.size() + t2.size() ; VectorRTYPE out = no_init(n) ; std::merge( t1.begin(), t1.end(), t2.begin(), t2.end(), out.begin() ) ; return out ; } Then as Kevin hints (and has opened an issue in https://github.com/romainfrancois/Rcpp11/issues/92) we can want to go further and want something with multiple inputs. Interesting idea, I guess lots of work to generalize it. Romain Le 21 janv. 2014 à 23:02, Søren Højsgaard sor...@math.aau.dk a écrit : Dear all, I have made the following primitive concatenate function, because I couldn't find one in Rcpp: template const int RTYPE VectorRTYPE do_conc_(VectorRTYPE x, VectorRTYPE y){ int nx=x.size(), n=x.size()+y.size(),i,j; VectorRTYPE out=no_init(n); for (i=0; inx; ++i){ out[ i ] = x[ i ];} for (j=i, i=0; jn; ++j, ++i){ out[ j ] = y[i] ;} return out; } // [[Rcpp::export]] SEXP conc( SEXP XX_, SEXP YY_){ int type = TYPEOF(XX_) ; switch( type ){ case INTSXP : return do_conc_INTSXP ( XX_, YY_ ) ; case REALSXP : return do_conc_REALSXP( XX_, YY_ ) ; case STRSXP : return do_conc_STRSXP ( XX_, YY_ ) ; case VECSXP : return do_conc_VECSXP ( XX_, YY_ ) ; } return R_NilValue ; } As you can see it assumes that the two inputs XX_ and YY_ are of the same type, and it fails to copy names to the output. If I have missed any such functionality in Rcpp then I would be happy to know... Cheers Søren ___ 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] Rcpp version of c( )
Le 22 janv. 2014 à 01:10, Kevin Ushey kevinus...@gmail.com a écrit : Hi Søren, I like the idea. Currently there is nothing like that in Rcpp. It could be made more flexible if we: 1. Accept a generic set of vectors that could be appropriately casted as needed, 2. Cast these vectors to the appropriate type if necessary, 3. Fill an output vector with the elements of these vectors. Of course, we would like to be able to accept primitives as well so that e.g. c(x, 1, y) works so something a bit more designed would be nice. there is also the problem of names, e.g. c(x, foo = 1, y). This is a big part of the problem with ::create As a first approximation, perhaps we could ignore names. There should be a flexible way to implement this using variadic templates, so that e.g. template typename T, typename... Args T c( Args... args ) { ...do the concatenation… } I’ll discuss more on the issue you opened or if you create a branch for the feature in Rcpp11. I guess the R type must play a role, so I’d imagine an interface more like this : template int RTYPE, typename... Args VectorRTYPE c( Args... args ) { static_assert( all types in Args are compatible with RTYPE ) - find the final length - allocate a vector of that length - recursively iterate through args } Once you understand them, variadic templates are quite fun to work with. On a related note, I’ve added a structure function recently to Rcpp11. Of course, this requires C++11 so it might not fit until R 3.1.0 is out with its C++11 support, but it could be a natural fit in Rcpp11. Adding the generic version in Rcpp would require code bloat unfortunately. This might be fun to produce with C++11, but a massive pain with C++98. Romain -Kevin On Tue, Jan 21, 2014 at 2:02 PM, Søren Højsgaard sor...@math.aau.dk wrote: Dear all, I have made the following primitive concatenate function, because I couldn't find one in Rcpp: template const int RTYPE VectorRTYPE do_conc_(VectorRTYPE x, VectorRTYPE y){ int nx=x.size(), n=x.size()+y.size(),i,j; VectorRTYPE out=no_init(n); for (i=0; inx; ++i){ out[ i ] = x[ i ];} for (j=i, i=0; jn; ++j, ++i){ out[ j ] = y[i] ;} return out; } // [[Rcpp::export]] SEXP conc( SEXP XX_, SEXP YY_){ int type = TYPEOF(XX_) ; switch( type ){ case INTSXP : return do_conc_INTSXP ( XX_, YY_ ) ; case REALSXP : return do_conc_REALSXP( XX_, YY_ ) ; case STRSXP : return do_conc_STRSXP ( XX_, YY_ ) ; case VECSXP : return do_conc_VECSXP ( XX_, YY_ ) ; } return R_NilValue ; } As you can see it assumes that the two inputs XX_ and YY_ are of the same type, and it fails to copy names to the output. If I have missed any such functionality in Rcpp then I would be happy to know... Cheers Søren ___ 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 ___ 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] Rcpp version of c( )
Hi, There is a preliminary version of this in Rcpp11. For example: #include Rcpp.h using namespace Rcpp ; // [[Rcpp::export]] NumericVector test(){ NumericVector x(10) ; NumericVector y(30) ; return NumericVector::concat(x, 2.0, y, 1.0) ; } So it handles (or at least it should): - compatible primitive (i.e. double in the case of NumericVector) - arbitrary compatible sugar expression It is at least for now a static member function of the Vector class. Maybe it can be made a free function. This is about 90 lines of C++11 code. Romain Le 22 janv. 2014 à 01:37, Søren Højsgaard sor...@math.aau.dk a écrit : Hi Kevin, Thanks for your reply. I was only introduced to C++11 last week (my fault!); it seems that everybodys life becomes much easier once R-packages can be made with that... I think many Rcpp-friends would welcome a version of c( ). One view is of course that it should be as general as R's c( )-function. A more pragmatic view is a version of c() that could concatenate (a) two lists and (b) two vectors (where each can be integers, doubles, characters and complex, independently of each other). I guess that would satisfy 90+% of the needs for a c( ) function in an Rcpp setting... Best regards Søren -Original Message- From: Kevin Ushey [mailto:kevinus...@gmail.com] Sent: 22. januar 2014 01:10 To: Søren Højsgaard Cc: rcpp-devel@lists.r-forge.r-project.org (rcpp-de...@r-forge.wu-wien.ac.at) Subject: Re: [Rcpp-devel] Rcpp version of c( ) Hi Søren, I like the idea. Currently there is nothing like that in Rcpp. It could be made more flexible if we: 1. Accept a generic set of vectors that could be appropriately casted as needed, 2. Cast these vectors to the appropriate type if necessary, 3. Fill an output vector with the elements of these vectors. Of course, we would like to be able to accept primitives as well so that e.g. c(x, 1, y) works so something a bit more designed would be nice. There should be a flexible way to implement this using variadic templates, so that e.g. template typename T, typename... Args T c( Args... args ) { ...do the concatenation... } Of course, this requires C++11 so it might not fit until R 3.1.0 is out with its C++11 support, but it could be a natural fit in Rcpp11. Adding the generic version in Rcpp would require code bloat unfortunately. -Kevin On Tue, Jan 21, 2014 at 2:02 PM, Søren Højsgaard sor...@math.aau.dk wrote: Dear all, I have made the following primitive concatenate function, because I couldn't find one in Rcpp: template const int RTYPE VectorRTYPE do_conc_(VectorRTYPE x, VectorRTYPE y){ int nx=x.size(), n=x.size()+y.size(),i,j; VectorRTYPE out=no_init(n); for (i=0; inx; ++i){ out[ i ] = x[ i ];} for (j=i, i=0; jn; ++j, ++i){ out[ j ] = y[i] ;} return out; } // [[Rcpp::export]] SEXP conc( SEXP XX_, SEXP YY_){ int type = TYPEOF(XX_) ; switch( type ){ case INTSXP : return do_conc_INTSXP ( XX_, YY_ ) ; case REALSXP : return do_conc_REALSXP( XX_, YY_ ) ; case STRSXP : return do_conc_STRSXP ( XX_, YY_ ) ; case VECSXP : return do_conc_VECSXP ( XX_, YY_ ) ; } return R_NilValue ; } As you can see it assumes that the two inputs XX_ and YY_ are of the same type, and it fails to copy names to the output. If I have missed any such functionality in Rcpp then I would be happy to know... Cheers Søren ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-deve l ___ 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] A strange question while using Rcpp
Hello, This stands out double U; for(int i=0; in; i++){ for(int j=0; jn; j++){ U = U + A_kl(i,j) * B_kl(i,j)/n/n ; } } U = sqrt(U); U is not initialized. so all bets are on. Anything can happen. Same holds for aa and bb. Also, in terms of how you use attributes, you can at your advantage replace things like this: //[[Rcpp::export]] double mydcov(SEXP X, SEXP Y) { NumericVector x = asNumericVector(X); NumericVector y = asNumericVector(Y); … } by things like this: //[[Rcpp::export]] double mydcov(NumericVector x, NumericVector y){ … } Romain Le 19 janv. 2014 à 14:09, 晔张 zhang...@gmail.com a écrit : Hello, everyone. I guess the probrem maybe occur because of sourceCpp(), so I have made another test. I make a simple package using RcppArmadillo.package.skeletion(). But the same problem appear. My code is on Github: https://github.com/ZhangYet/RcppTest Is there anything related to my compiler or OS? I use 64-bit CentOS and g++ 4.4.5 On Sat, Jan 18, 2014 at 2:01 AM, 张晔 zhang...@gmail.com wrote: Thanks, Dirk. I have upload my code to Github: https://github.com/ZhangYet/RcppTest/ And I made a mistake: | res1 - mydcov(x,y)/sqrt(mydcov(x,x)*mydcov(y,y)) | | a - mydcov(x,y) | b - mydcov(x,x) | c - mydcov(y,y) | res2 - a/sqrt(b*c) | | and res2 is different from res1.(res2 is the right answer.) I checked my test result. res2 is not the right answer, but it's different from res. 于 2014/1/17 21:36, Dirk Eddelbuettel 写道: On 17 January 2014 at 20:51, 晔张 wrote: | Dear all, | | I have a strange question such that I can't conclude it in the title. | I have write an function: | //[[Rcpp::export]] | double mydcov(NumericVector x, NumericVector y) It would help us to see the function to have any guess at what may be wrong. | This function is computing ditance covariance. This function is OK. It give | the right answer. | I use this function to compute distance correltion. | | //[[Rcpp::export]] | double mydcor(NumericVector x, NumericVector y) | { | return mydcov(x,y)/sqrt(mydcov(x,x)*mydcov(y,y)); | } | | Then, I compile the source code using sourceCpp. | And then mydcor(x,y) give a wrong answer. | | Here comes the strange part: | In R, I run code as follow | | res1 - mydcov(x,y)/sqrt(mydcov(x,x)*mydcov(y,y)) | | a - mydcov(x,y) | b - mydcov(x,x) | c - mydcov(y,y) | res2 - a/sqrt(b*c) | | and res2 is different from res1.(res2 is the right answer.) | | And I have another test, rewriting the source code for mydcor(): | version1: | //[[Rcpp::export]] | double mydcor(NumericVector x, NumericVector y) | { | double a = mydcov(x,y) | double b = mydcov(x,x); | double c = mydcov(y,y); | return (a/sqrt(b*c)); | } | | version2: | //[[Rcpp::export]] | double mydcor(NumericVector x, NumericVector y) | { | double a = mydcov(x,y) | Rcouta\n; | double b = mydcov(x,x); | Rcoutb\n; | double c = mydcov(y,y); | Rcoutc\n | return (a/sqrt(b*c)); | } | This time, version2 make a right answer. | It's too weird. I havn't meet such situation before. I am not sure we are in a position to help you here. Regards, Dirk | | Happy Lunar New Year (the most important festival in China), and Thanks in | advance. | | Best regards | ZhangYet | | -- | ___ | 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 ___ 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] Bug: compileAttributes incorrectly handles Rcpp::export-ed functions with multiple arguments
Le 18 janv. 2014 à 06:10, Davor Cubranic cubra...@stat.ubc.ca a écrit : Running compileAttributes with “verbose = TRUE” was very informative: $ Rscript -e 'Rcpp::compileAttributes(., TRUE)' Exports from /Users/davor/projects/Davor/myPackage/src/rcpp_hello_world.cpp: List rcpp_hello_world(NumericVector foo) Exports from /Users/davor/projects/Davor/myPackage/src/rcpp_hello_world.cpp~: List rcpp_hello_world() Answer: compileAttributes interprets Emacs backup files with extension “.cpp~” as source files. (My fault for not zipping up the actual source directory but the product of R CMD build.) Probable source of the error is in compileAttributes (Attributes.R:355): cppFiles - list.files(srcDir, pattern = glob2rx(*.c*”)) Hi, This has bitten me too in various training I gave about Rcp. I guess [.]c(c|pp)$ would make a better pattern. WRE says (if you read between the lines) that c++ files are .cpp or .cc So this is a bug. Romain You need a better way to identify C++ sources. R-exts manual says R’s make rules use .cc and .cpp for C++. (This is supposed to be recorded in R_HOME/etcR_ARCH/Makeconf, so it could potentially be processed dynamically, although I doubt that’s really necessary.) Davor On Jan 17, 2014, at 4:18 PM, Dirk Eddelbuettel e...@debian.org wrote: On 17 January 2014 at 15:32, Davor Cubranic wrote: | On 2014-01-17, at 2:55 PM, Dirk Eddelbuettel wrote: | | You had two mistakes here: | | i) after you alter an interface to be used by Rcpp Attributes, you must |re-run the compileAttributes() function to update the files. See the |vignette for details. | | What do you mean by this? Like I said, I changed the .cpp file and re-run | compileAttributes. What I uploaded is the result afterwards. The equivalent of $ cd myPackage; R -e 'Rcpp::compileAttributes(.)' For once, I launched R and typed it by hand. |(And if you use RStudio, this is done automagically) | | So it is by devtools, on one of the functions I regularly use in my workflow, perhaps test. If it wasn't, it would be such a pain. | | ii) Your C++ function did not work as the 'List z = ...' parameter |shadowed an already declared parameter from the function interface. |Renaming to zz or z2 works, of course. | | I fixed it and rerun compileAttributes. Still the same problem. New version of the package is attached. See here, based on your previous file. edd@max:/tmp/davor/myPackage$ cat src/rcpp_hello_world.cpp #include Rcpp.h using namespace Rcpp; // [[Rcpp::export]] List rcpp_hello_world(NumericVector z) { CharacterVector x = CharacterVector::create( foo, bar ) ; NumericVector y = NumericVector::create( 0.0, 1.0 ) ; List z2 = List::create( x, y ) ; return z2 ; } edd@max:/tmp/davor/myPackage$ R CMD check . * using log directory ‘/tmp/davor/myPackage/..Rcheck’ * using R version 3.0.2 (2013-09-25) * using platform: x86_64-pc-linux-gnu (64-bit) * using session charset: UTF-8 * checking for file ‘./DESCRIPTION’ ... OK * checking extension type ... Package * this is package ‘myPackage’ version ‘1.0’ * checking package namespace information ... OK * checking package dependencies ... OK * checking if this is a source package ... OK * checking if there is a namespace ... OK * checking for executable files ... OK * checking for hidden files and directories ... NOTE Found the following hidden files and directories: ..Rcheck These were most likely included in error. See section ‘Package structure’ in the ‘Writing R Extensions’ manual. * checking for portable file names ... OK * checking for sufficient/correct file permissions ... OK * checking whether package ‘myPackage’ can be installed ... WARNING Found the following significant warnings: Warning: /tmp/davor/myPackage/man/myPackage-package.Rd:31: All text must be in a section Warning: /tmp/davor/myPackage/man/myPackage-package.Rd:32: All text must be in a section See ‘/tmp/davor/myPackage/..Rcheck/00install.out’ for details. * checking installed package size ... OK * checking package directory ... OK * checking DESCRIPTION meta-information ... WARNING Non-standard license specification: What Licence is it under ? Standardizable: FALSE * checking top-level files ... OK * checking for left-over files ... OK * checking index information ... OK * checking package subdirectories ... WARNING Found the following directory with the name of a check directory: ./..Rcheck Most likely, these were included erroneously. * checking R files for non-ASCII characters ... OK * checking R files for syntax errors ... OK * checking whether the package can be loaded ... OK * checking whether the package can be loaded with stated dependencies ... OK * checking whether the package can be unloaded cleanly ... OK * checking whether the namespace can be loaded with stated
Re: [Rcpp-devel] vector RawVector to RawMatrix [like do.call(rbind, mylist)]
Hi, If you wrap your std::vectorRawVector you get a list of raw vectors, and this does not do deep copies of the RawVector. If you want a RawMatrix, you have to make copies as all the matrix data is contiguous in memory. Perhaps you can change things around, first create the matrix and then fill it instead of creating a vector of RawVector. Romain Le 10 janv. 2014 à 10:51, Sven E. Templer sven.temp...@gmail.com a écrit : Hello, reading a matrix from a file and transforming it to raw format, I get a std::vector Rcpp::RawVector , how can I wrap it to Rcpp::RawMatrix. Right now I use Rcpp::List::create(vector RawVector ) and use do.call(rbind, mylist) in R (does this do a copy to the memory?). Is there a way to wrap it in C++? Thank you for your help, Sven. ___ 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] Question about modules
Hello, You can use .factory instead of .constructor in that case. Romain Le 9 janv. 2014 à 03:16, Tim Keitt tke...@utexas.edu a écrit : I did a little experiment with RCPP_MODULE trying to wrap a class from another library. The class in question has a protected default constructor and uses a non-member factory function for instantiation. In short I did not get it to work. I am assuming that if you do not include a .constuctor statement, then the class does not get wrapped in the module. Is that correct? THK -- http://www.keittlab.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 ___ 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] Question about modules
Hi, The module docs is probably the one in the worst shape. I think the current recommendation is to have this in one of your .R files: loadModule( yourmodule, TRUE ) which triggers a load action for when the package is loaded. Romain Le 9 janv. 2014 à 17:45, Tim Keitt tke...@utexas.edu a écrit : OK. Not quite as automatic as I thought. Its now loading the class using 'loadRcppModules' in '.onLoad'. Still a little lost. I'll have to re-read the modules docs. Not sure how to use the class. The factory did not get exposed. Do I have to expose it separately eg using attributes? THK On Thu, Jan 9, 2014 at 10:20 AM, Tim Keitt tke...@utexas.edu wrote: Thanks. That at least compiles. (If anyone is curious, through trial-and-error it appears .factory is not a template and takes a single argument, the factory function pointer.) However I am not seeing any of my functions exported to the package. How would the factory be called from R? I sort of understood that exporting in packages was automatic. Do I have to manually create the module in R? THK On Thu, Jan 9, 2014 at 4:40 AM, Romain Francois rom...@r-enthusiasts.com wrote: Hello, You can use .factory instead of .constructor in that case. Romain Le 9 janv. 2014 à 03:16, Tim Keitt tke...@utexas.edu a écrit : I did a little experiment with RCPP_MODULE trying to wrap a class from another library. The class in question has a protected default constructor and uses a non-member factory function for instantiation. In short I did not get it to work. I am assuming that if you do not include a .constuctor statement, then the class does not get wrapped in the module. Is that correct? THK -- http://www.keittlab.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 -- http://www.keittlab.org/ -- http://www.keittlab.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] Question about modules
not really. the std::is_enum trait in C++11 is going to help, but not that much. Romain Le 9 janv. 2014 à 19:02, Tim Keitt tke...@utexas.edu a écrit : Thanks. Got it working. Looks very promising. Any progress/work-arounds for enums? I have a ton to deal with. THK On Thu, Jan 9, 2014 at 11:31 AM, Romain Francois rom...@r-enthusiasts.com wrote: Hi, The module docs is probably the one in the worst shape. I think the current recommendation is to have this in one of your .R files: loadModule( yourmodule, TRUE ) which triggers a load action for when the package is loaded. Romain Le 9 janv. 2014 à 17:45, Tim Keitt tke...@utexas.edu a écrit : OK. Not quite as automatic as I thought. Its now loading the class using 'loadRcppModules' in '.onLoad'. Still a little lost. I'll have to re-read the modules docs. Not sure how to use the class. The factory did not get exposed. Do I have to expose it separately eg using attributes? THK On Thu, Jan 9, 2014 at 10:20 AM, Tim Keitt tke...@utexas.edu wrote: Thanks. That at least compiles. (If anyone is curious, through trial-and-error it appears .factory is not a template and takes a single argument, the factory function pointer.) However I am not seeing any of my functions exported to the package. How would the factory be called from R? I sort of understood that exporting in packages was automatic. Do I have to manually create the module in R? THK On Thu, Jan 9, 2014 at 4:40 AM, Romain Francois rom...@r-enthusiasts.com wrote: Hello, You can use .factory instead of .constructor in that case. Romain Le 9 janv. 2014 à 03:16, Tim Keitt tke...@utexas.edu a écrit : I did a little experiment with RCPP_MODULE trying to wrap a class from another library. The class in question has a protected default constructor and uses a non-member factory function for instantiation. In short I did not get it to work. I am assuming that if you do not include a .constuctor statement, then the class does not get wrapped in the module. Is that correct? THK -- http://www.keittlab.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 -- http://www.keittlab.org/ -- http://www.keittlab.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 -- http://www.keittlab.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] Problems wrapping stl::vectorint
Hello, wrap is for converting an object of arbitrary class to an R object. It deduces what to do based on the class of what you pass it. So you usually don’t specify the template parameter. So you’d usually just write : return wrap(a); If you wanted to be explicit, then you would use: return wrap std::vectorint ( a ) ; wrap returns a « SEXP » (any R object) which can be used by an IntegerVector constructor. So you can do: IntegerVector x( wrap(a) ) ; or even: IntegerVector = asIntegerVector( wrap(a) ) ; Romain Le 3 janv. 2014 à 17:18, Alessandro Mammana mamm...@molgen.mpg.de a écrit : Dear all, thank you again for this fantastic library. Sorry for the very stupid question, I looked before posting, but I couldn't find anything. I am encountering a problem when I try to do something very basic: I am trying to wrap a std::vectorint to an IntegerVector: In the file scratchpad.cpp: // [[Rcpp::export]] IntegerVector test(){ std::vectorint a; a.push_back(1);a.push_back(2);a.push_back(3); return wrapIntegerVector(a); } when doing: sourceCpp(scratchpad.cpp) I get the error: scratchpad.cpp: In function 'Rcpp::IntegerVector test()': scratchpad.cpp:181:30: error: no matching function for call to 'wrap(std::vectorint)' scratchpad.cpp:181:30: note: candidates are: In file included from /package/mariux64/R/R-3.0.2/lib/R/library/Rcpp/include/RcppCommon.h:120:0, from /package/mariux64/R/R-3.0.2/lib/R/library/Rcpp/include/Rcpp.h:27, from scratchpad.cpp:2: /package/mariux64/R/R-3.0.2/lib/R/library/Rcpp/include/Rcpp/internal/wrap.h:924:13: note: templateclass T SEXPREC* Rcpp::wrap(const T) /package/mariux64/R/R-3.0.2/lib/R/library/Rcpp/include/Rcpp/internal/wrap.h:924:13: note: template argument deduction/substitution failed: scratchpad.cpp:181:30: note: cannot convert 'a' (type 'std::vectorint') to type 'const Rcpp::Vector13' In file included from /package/mariux64/R/R-3.0.2/lib/R/library/Rcpp/include/RcppCommon.h:120:0, from /package/mariux64/R/R-3.0.2/lib/R/library/Rcpp/include/Rcpp.h:27, from scratchpad.cpp:2: /package/mariux64/R/R-3.0.2/lib/R/library/Rcpp/include/Rcpp/internal/wrap.h:965:13: note: templateclass InputIterator SEXPREC* Rcpp::wrap(InputIterator, InputIterator) /package/mariux64/R/R-3.0.2/lib/R/library/Rcpp/include/Rcpp/internal/wrap.h:965:13: note: template argument deduction/substitution failed: scratchpad.cpp:181:30: note: cannot convert 'a' (type 'std::vectorint') to type 'Rcpp::Vector13' scratchpad.cpp:183:1: warning: control reaches end of non-void function [-Wreturn-type] make: *** [scratchpad.o] Error 1 g++ -I/package/mariux64/R/R-3.0.2/lib/R/include -DNDEBUG -I/usr/local/include -I/package/mariux64/R/R-3.0.2/lib/R/library/Rcpp/include-fpic -g -O3 -Wall -pedantic -c scratchpad.cpp -o scratchpad.o Error in sourceCpp(scratchpad.cpp) : Error 1 occurred building shared library. I must definitely be doing something very stupid. But what? thanks in advance! Ale -- Alessandro Mammana, PhD Student Max Planck Institute for Molecular Genetics Ihnestraße 63-73 D-14195 Berlin, Germany ___ 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] exporting void test(void) function
Hello, This is fixed in Rcpp implementations I maintain: Rcpp11 and Rcpp98 and tested for in Rcpp-test. https://github.com/romainfrancois/Rcpp11/blob/master/src/attributes.cpp#L1195 https://github.com/romainfrancois/Rcpp98/blob/master/src/attributes.cpp#L1228 Trivial to port the fix to Rcpp. Romain Le 31 déc. 2013 à 05:15, Tim Keitt tke...@gmail.com a écrit : Apologies if this is the wrong list for user questions -- happy to be redirected -- I did not see it immediately. Am I correct in noting that // [[Rcpp::export]] void test(void) { // do something } does not generate any code in RcppExports.R? Thanks. -- Timothy H. Keitt http://www.keittlab.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 ___ 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