Re: [Rcpp-devel] Best Practice for Optimize Functions in RCPP

2014-12-23 Thread Gabor Grothendieck
On Tue, Dec 23, 2014 at 12:04 AM, Simon Riddell  wrote:
> Hello,
>
> I have been judiciously using RCPP for six months, and have had my numerous
> questions answered so far from previous threads. I have now run into an
> issue I cannot get a handle on:
>
> I have converted a fairly large (recursive) Kalman filter function from R to
> C++ using RCPP. This function is then called within the R optim() function,
> subject to constraints, which estimates a set of ~30 parameters.
>
> My issue occurs within the C++ Kalman Filter function, where, I use the
> optimize() function to calculate the yield to maturity rate of various
> bonds. I do this by calling back to the R environment to access the
> optimize() function. Below is the R Function I create to be used within the
> Kalman filter, and below this R function is my method for calling it within
> the C++ code. To complicate matters further, the R Function calls a C++
> Function. To clarify: The Kalman Filter C++ code calls an R function, and
> this R Function calls an additional separate C++ function. (Code included
> below)
>
> As I iterate the Kalman filter it runs perfectly for anywhere from 30
> minutes to six hours (and produces correct output when matched to the R
> code), but it inevitably crashes. From past reading I have done, Dirk has
> before mentioned that calling an R function many times within C++ is usually
> not a good idea. As a result I suspect this is my issue (the error codes
> vary, sometimes mentioning numerical errors, other times recursive errors,
> other times random RCPP error codes -- I can document and provide them if
> needed)
>
> My biggest impasse is I cannot figure out a way to complete this without
> calling the R optimize() function, and cannot find any RCPP optimize
> functions to use instead. Thank you for reading.
>

Try this code from R itself:

http://www.sourcecodebrowser.com/r-base-core-ra/1.1.1/fmin_8c_source.html
___
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] Returning an arma vec

2014-12-03 Thread Gabor Grothendieck
1. This returns a matrix rather than a vector:

--  start of file teste.cpp ---
#include 
// [[Rcpp::depends(RcppArmadillo)]]

using namespace arma;
using namespace Rcpp;

// [[Rcpp::export]]
NumericVector teste(const vec& x) {
vec v = x.subvec(1, 2); // x
return wrap(v); // x
}
/*** R
teste(1:4)
*/
--- end of file teste.cpp ---

Now run in R:

> sourceCpp("teste.cpp", rebuild = TRUE)

> teste(1:4)
 [,1]
[1,]2
[2,]3


2. If we replace the lines marked // x with

   return wrap(x.subvec(1, 2));

then it fails with a compiler error.

error: cannot convert 'const arma::subview_col' to 'SEXP' in
initialization


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] tracking volatile bug

2014-11-23 Thread Gabor Grothendieck
On Sun, Nov 23, 2014 at 2:07 PM, Sokol Serguei  wrote:
> Gabor Grothendieck has written at  Sat, 22 Nov 2014 19:17:27 -0500
>
>> On Sat, Nov 22, 2014 at 1:43 PM, Sokol Serguei
>> wrote:
>>>
>>> Let try to stick with regular rcpp code
>>> (file: matrix_norm.cpp):
>>>
>>> //[[Rcpp::depends(RcppArmadillo)]]
>>> #include 
>>> using namespace Rcpp;
>>> using namespace arma;
>>>
>>> // [[Rcpp::export]]
>>> double nmat(mat A) {
>>> Function Matrix_norm_r_=Environment("package:Matrix")["norm"];
>>> double res=as(Matrix_norm_r_(A, "1"));
>>> return res;
>>> }
>>>
>>> When called in R as:
>>>
>>> library(Rcpp)
>>> library(Matrix)
>>> sourceCpp("matrix_norm.cpp")
>>> gctorture(TRUE)
>>> nmat(as.matrix(pi))
>>>
>>> it gives an error:
>>> Erreur : 'getCharCE' doit être appelé sur un CHARSXP
>>> (my English translation: Error: 'getCharCE' must be called on CHARSXP)
>>>
>>> Something was irregular on my side here?
>>> Serguei.
>>
>> Try replacing the line that sets res with:
>>
>> double res=as(Matrix_norm_r_(NumericMatrix(wrap(A)),
>> CharacterVector::create("1")));
>>
>> Be sure to try it on a fresh session since errors from prior runs
>> could have messed up R.
>
> Yes, this version works too.
> The least change that leads to a working code that I have found (thanks to
> Martin) is
>
> double res=as(Matrix_norm_r_(A, CharacterVector("1")));
>
> but it is still unclear what is wrong with passing a plain string.
> In quickref, all examples pass just numbers without any prior conversion
> to NumericVector or IntegerVector. Strings are exception to this?

Not on my system.  That fails for me with the same error you got.

I am using

> packageVersion("Rcpp")
[1] ‘0.11.3’
> gctorture(FALSE)
> packageVersion("RcppArmadillo")
[1] ‘0.4.500.0’
> R.version.string
[1] "R version 3.1.2 RC (2014-10-25 r66870)"

Under Windows 8.1 with Rtools version 3.1.0..1942 (which uses g++ 4.6.3)

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Re: [Rcpp-devel] tracking volatile bug

2014-11-22 Thread Gabor Grothendieck
On Sat, Nov 22, 2014 at 1:43 PM, Sokol Serguei  wrote:
> Let try to stick with regular rcpp code
> (file: matrix_norm.cpp):
>
> //[[Rcpp::depends(RcppArmadillo)]]
> #include 
> using namespace Rcpp;
> using namespace arma;
>
> // [[Rcpp::export]]
> double nmat(mat A) {
>Function Matrix_norm_r_=Environment("package:Matrix")["norm"];
>double res=as(Matrix_norm_r_(A, "1"));
>return res;
> }
>
> When called in R as:
>
> library(Rcpp)
> library(Matrix)
> sourceCpp("matrix_norm.cpp")
> gctorture(TRUE)
> nmat(as.matrix(pi))
>
> it gives an error:
> Erreur : 'getCharCE' doit être appelé sur un CHARSXP
> (my English translation: Error: 'getCharCE' must be called on CHARSXP)
>
> Something was irregular on my side here?
> Serguei.

Try replacing the line that sets res with:

   double res=as(Matrix_norm_r_(NumericMatrix(wrap(A)),
CharacterVector::create("1")));

Be sure to try it on a fresh session since errors from prior runs
could have messed up R.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Re: [Rcpp-devel] Can't compile BOOST package via Rcpp on Windows7 OS

2014-11-11 Thread Gabor Grothendieck
On Tue, Nov 11, 2014 at 9:51 AM, דוד ארנבורג  wrote:
> Hi guys,
>
> So I've installed and loaded the BH package without any errors, then I tried
> to run this example but sourceCpp failed to compile it. I was wondering if
> there is a quick fix for this and I'm just making some very basic mistake
> here
>
> I saw this post lately and I'm not sure if this means that I just can't
> compile BH on windows or just can't build a package which depends on it
>
> As a side note, I was trying to add the quantile() function from BOOST to
> this SO answer in order to improve it for future readers as I didn't find
> any nice BOOST/Rcpp implementations online other than in Dirks Gallery
>
> Thanks,
> David
>
> ---
>
> sessionInfo()
> R version 3.1.1 (2014-07-10)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
>
> locale:
> [1] LC_COLLATE=Hebrew_Israel.1255  LC_CTYPE=Hebrew_Israel.1255
> LC_MONETARY=Hebrew_Israel.1255
> [4] LC_NUMERIC=C   LC_TIME=Hebrew_Israel.1255
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base
>
> other attached packages:
> [1] Rcpp_0.11.3 BH_1.54.0-4
>
> loaded via a namespace (and not attached):
> [1] tools_3.1.1
>
> ___
> 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

Calling the file test_boost.cpp this ran without errors for me:

library(Rcpp)
sourceCpp("test_boost.cpp")

and repeating the test runs shown at the link you mentioned gave the
same answers as there.  I am using Windows 8.1, the same Rcpp and BH
versions as you and

> R.version.string
[1] "R version 3.1.2 RC (2014-10-25 r66870)"

and this version of Rtools:

C:\Rtools>type VERSION.txt
Rtools version 3.1.0.1942





-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Re: [Rcpp-devel] inplace modification more affect other varibles

2014-10-22 Thread Gabor Grothendieck
On Tue, Oct 21, 2014 at 9:22 PM, 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.
>
> 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 
> 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
>

This is common among C++ software called by R that modifies R objects
in place. For example, below DT2 is modified:

> library(data.table)
...junk...
> DT <- data.table(a = 1:3)
> DT2 <- DT
> DT[, b:=a]
> DT2
   a b
1: 1 1
2: 2 2
3: 3 3
___
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 API Reference

2014-09-04 Thread Gabor Grothendieck
On Wed, Sep 3, 2014 at 11:03 PM, Yixuan Qiu  wrote:
> Dear all,
> I believe that everyone in this list has seen the benefit of using Rcpp to
> incorporate C++ code and develop R packages, but it's also the fact that
> currently there is rarely a complete reference which documents every detail
> of the classes and functions inside Rcpp.
> To make this situation a little bit better, recently I've created a project
> that aims to accomplish this long run target. A quick view of what it looks
> like is available at my site: http://statr.me/rcpp-note/
> Basically it's like the Doxygen documentation, but the content here was
> manually added rather than extracted from the Rcpp source code. For now I've
> finished some of the most commonly used classes in Rcpp, and do hope that
> more people are joining in, either by reviewing and correcting the existing
> documentation, or contributing your own knowledge.
> I wish this project would be helpful for those who want to use Rcpp in their
> code and packages, and be more powerful and complete with the help of you
> experts in this list. If you are also interested in, don't hesistate to go
> to the project repository (https://github.com/yixuan/Rcpp-note), reporting
> mistakes, contributing document or giving suggestions.
> Happy Rcpping!
>

This is great. Thanks.

Particularly like the small code examples and hope that additional
such examples can be added in the future.
___
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] Comparison of R and rcpp for backsolve

2014-06-27 Thread Gabor Grothendieck
On Fri, Jun 27, 2014 at 7:14 PM, Peter Rossi  wrote:
> Folks-
>
> In my package, bayesm, I use backsolve() to invert upper-triangular
> arrays.  I am in the process of converting my package to rccp-arma.
>
> I thought I would test the analogous operation in arma by declaring
> the matrix as upper-triangular and inverting using solve().
>
> To my surprise, pure R code was considerably faster than
> rcpp-armadillo for 50 x 50 and larger matrices.
>
> I attach an rmd and cpp files necessary to run this benchmark.
>
> I assume I'm doing something terribly wrong or naive in my use of
> rcpp-armadillo and would appreciate any thoughts on what causes these
> unexpected results.
>
> p
>
> Here are the results for those who do not want to compile the rmd file:
>
> 10 by 10 uppertriangular matrix;
>
> # 10 by 10
> set.seed(777)
> k <- 10
> m <- k + 10
> A <- matrix(rnorm(k*m), m, k)
> R <- chol(t(A)%*%A)
>
> rep <- 500
> microbenchmark(backsolve_R(rep, R),backsolve_rcpp(rep, R),times=10)
>
> ## Unit: microseconds
> ##exprmin lq median uqmax neval
> ## backsolve_R(rep, R) 3781.3 4002.4 4131.0 4958.8 6146.310
> ##  backsolve_rcpp(rep, R)  809.1  812.5  825.1  851.4  889.710
>
> 50 by 50 uppertriangular matrix
>
> # 50 by 50
> set.seed(777)
> k <- 50
> m <- k + 10
> A <- matrix(rnorm(k*m), m, k)
> R <- chol(t(A)%*%A)
>
> rep <- 500
> microbenchmark(backsolve_R(rep, R),backsolve_rcpp(rep, R),times=10)
>
> ## Unit: milliseconds
> ##expr   minlq medianuq   max neval
> ## backsolve_R(rep, R) 18.92 19.40  19.97 20.94 44.2210
> ##  backsolve_rcpp(rep, R) 36.67 36.88  37.13 37.28 37.4110
>
> 100 by 100 uppertriangular matrix
>
> # 100 by 100
> set.seed(777)
> k <- 100
> m <- k+10
> A <- matrix(rnorm(k*m), m, k)
> R <- chol(t(A)%*%A)
>
> rep <- 500
> microbenchmark(backsolve_R(rep, R),backsolve_rcpp(rep,R),times=10)
>
> ## Unit: milliseconds
> ##expr   minlq medianuq   max neval
> ## backsolve_R(rep, R) 101.5 102.4  103.2 104.4 126.810
> ##  backsolve_rcpp(rep, R) 251.6 251.8  251.8 252.0 254.010
>

Try eigen.  On my test run it took roughly half the time of R for rep=500.

> microbenchmark(backsolve_R(rep, R), backsolve_rcpp(rep, R), times=10)
Unit: milliseconds
   expr  min   lq   median   uq  max neval
backsolve_R(rep, R) 76.62980 85.39488 86.71858 88.01366 89.9251010
 backsolve_rcpp(rep, R) 41.51224 46.72658 47.10239 47.13911 47.3507710

See attachment for code.


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
// To run:  library(Rcpp); sourceCpp("backsolve_eigen_test.cpp")
//
// [[Rcpp::depends(RcppEigen)]]
#include 

using namespace Eigen;

// [[Rcpp::export]]
MatrixXd backsolve_rcpp(const int rep, const Map R) { 
  
  int k = R.rows();
  MatrixXd RI(k, k);
  MatrixXd I;
  I.setIdentity(k, k);
  
  for(int i=0; i().solve(I);
  }
  
  return RI;
}


/*** R

backsolve_R = function(rep, R) { # backsolve
  
  k = nrow(R)
  I = diag(k)
  
  for (i in 1:rep){
RI = backsolve(R, I)
  }
  
  return(RI)
}


library(microbenchmark)
set.seed(777)
k <- 50L
m <- k + 10L
A <- matrix(rnorm(k*m), m, k)
R <- chol(t(A)%*%A)

rep <- 500L
microbenchmark(backsolve_R(rep, R), backsolve_rcpp(rep, R), times=10)

all.equal(backsolve_R(1L, R), backsolve_rcpp(1L, 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

Re: [Rcpp-devel] Rcpp release candidate

2014-06-05 Thread Gabor Grothendieck
On Thu, Jun 5, 2014 at 11:01 AM, Romain François
 wrote:
> Watch out for this part:
>
> Le 5 juin 2014 à 15:05, Gabor Grothendieck  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.
>

OK. That explains it.  Good catch.
___
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

2014-06-05 Thread Gabor Grothendieck
On Thu, Jun 5, 2014 at 9:55 AM, Dirk Eddelbuettel  wrote:
>
> On 5 June 2014 at 09:05, Gabor Grothendieck wrote:
> | I am using  "R version 3.1.0 Patched (2014-05-09 r65562)" but its
> | working now so perhaps you changed more than described.
>
> We did not. I encourage you to learn about patch and diff, and/or commit logs
> which make it plain to see what changed.  That is what version control
> systems are for, and they are good at it.

All my R packages use svn, git or hg.   It may be that the latest
commit did not change anything for R 3.1.0 or later but the fact is
that the logs I posted clearly show that it failed before because the
-std option emitted was wrong for the latest Rtools on the first log
posted and now is correct so something has changed.

>
> It would also make your email-only contributions easier to use hence more
> likely to get adopted.
>
>
> On 5 June 2014 at 09:06, Gabor Grothendieck wrote:
> | Just to clarify the C++11 part is working now
>
> Very good. Thanks for catching that, and thanks for confirming.
>
> | but the choking on the vignette is still a problem.
>
> I will consider that your local problem as all this is working on CRAN and
> win-builder, and has for years.
>
>
> So unless I hear otherwise onwards with Rcpp 0.11.2 ...
>
> Dirk
>
> --
> http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] Rcpp release candidate

2014-06-05 Thread Gabor Grothendieck
Just to clarify the C++11 part is working now but the choking on the
vignette is still a problem.

On Thu, Jun 5, 2014 at 9:05 AM, Gabor Grothendieck
 wrote:
> I am using  "R version 3.1.0 Patched (2014-05-09 r65562)" but its
> working now so perhaps you changed more than described.
>
>> devtools::install_github("RcppCore/Rcpp", ref = "feature/windows-c++0x",
> +  build_vignette=FALSE)
> Installing github repo Rcpp/feature/windows-c++0x from RcppCore
> Downloading windows-c++0x.zip from
> https://github.com/RcppCore/Rcpp/archive/feature/windows-c++0x.zip
> Installing package from
> C:\Users\Gabor\AppData\Local\Temp\RtmpkNGNb7/windows-c++0x.zip
> Installing Rcpp
> "C:/PROGRA~1/R/R-3.1/bin/x64/R" --vanilla CMD INSTALL  \
>   
> "C:\Users\Gabor\AppData\Local\Temp\RtmpkNGNb7\devtools1d74220c82c\Rcpp-feature-windows-c-0x"
>  \
>   --library="C:/Users/Gabor/Documents/R/win-library/3.1" --install-tests
>
> * installing *source* package 'Rcpp' ...
> ** libs
>
> *** arch - i386
> g++ -m32 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG -I../inst/include/
>  -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall
> -mtune=core2 -c Date.cpp -o Date.o
> g++ -m32 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG -I../inst/include/
>  -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall
> -mtune=core2 -c Module.cpp -o Module.o
> g++ -m32 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG -I../inst/include/
>  -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall
> -mtune=core2 -c Rcpp_init.cpp -o Rcpp_init.o
> g++ -m32 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG -I../inst/include/
>  -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall
> -mtune=core2 -c api.cpp -o api.o
> g++ -m32 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG -I../inst/include/
>  -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall
> -mtune=core2 -c attributes.cpp -o attributes.o
> g++ -m32 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG -I../inst/include/
>  -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall
> -mtune=core2 -c barrier.cpp -o barrier.o
> g++ -m32 -shared -s -static-libgcc -o Rcpp.dll tmp.def Date.o Module.o
> Rcpp_init.o api.o attributes.o barrier.o
> -Ld:/RCompile/CRANpkg/extralibs64/local/lib/i386
> -Ld:/RCompile/CRANpkg/extralibs64/local/lib
> -LC:/PROGRA~1/R/R-3.1/bin/i386 -lR
> installing to C:/Users/Gabor/Documents/R/win-library/3.1/Rcpp/libs/i386
>
> *** arch - x64
> g++ -m64 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG -I../inst/include/
>  -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall
> -mtune=core2 -c Date.cpp -o Date.o
> g++ -m64 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG -I../inst/include/
>  -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall
> -mtune=core2 -c Module.cpp -o Module.o
> g++ -m64 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG -I../inst/include/
>  -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall
> -mtune=core2 -c Rcpp_init.cpp -o Rcpp_init.o
> g++ -m64 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG -I../inst/include/
>  -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall
> -mtune=core2 -c api.cpp -o api.o
> g++ -m64 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG -I../inst/include/
>  -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall
> -mtune=core2 -c attributes.cpp -o attributes.o
> g++ -m64 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG -I../inst/include/
>  -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall
> -mtune=core2 -c barrier.cpp -o barrier.o
> g++ -m64 -shared -s -static-libgcc -o Rcpp.dll tmp.def Date.o Module.o
> Rcpp_init.o api.o attributes.o barrier.o
> -Ld:/RCompile/CRANpkg/extralibs64/local/lib/x64
> -Ld:/RCompile/CRANpkg/extralibs64/local/lib
> -LC:/PROGRA~1/R/R-3.1/bin/x64 -lR
> 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
> ** 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 
> + #include 
> + using boost::irange;
> + // [[Rcpp::depends(BH)]]
> 

Re: [Rcpp-devel] Rcpp release candidate

2014-06-05 Thread Gabor Grothendieck
I am using  "R version 3.1.0 Patched (2014-05-09 r65562)" but its
working now so perhaps you changed more than described.

> devtools::install_github("RcppCore/Rcpp", ref = "feature/windows-c++0x",
+  build_vignette=FALSE)
Installing github repo Rcpp/feature/windows-c++0x from RcppCore
Downloading windows-c++0x.zip from
https://github.com/RcppCore/Rcpp/archive/feature/windows-c++0x.zip
Installing package from
C:\Users\Gabor\AppData\Local\Temp\RtmpkNGNb7/windows-c++0x.zip
Installing Rcpp
"C:/PROGRA~1/R/R-3.1/bin/x64/R" --vanilla CMD INSTALL  \
  
"C:\Users\Gabor\AppData\Local\Temp\RtmpkNGNb7\devtools1d74220c82c\Rcpp-feature-windows-c-0x"
 \
  --library="C:/Users/Gabor/Documents/R/win-library/3.1" --install-tests

* installing *source* package 'Rcpp' ...
** libs

*** arch - i386
g++ -m32 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG -I../inst/include/
 -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall
-mtune=core2 -c Date.cpp -o Date.o
g++ -m32 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG -I../inst/include/
 -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall
-mtune=core2 -c Module.cpp -o Module.o
g++ -m32 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG -I../inst/include/
 -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall
-mtune=core2 -c Rcpp_init.cpp -o Rcpp_init.o
g++ -m32 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG -I../inst/include/
 -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall
-mtune=core2 -c api.cpp -o api.o
g++ -m32 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG -I../inst/include/
 -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall
-mtune=core2 -c attributes.cpp -o attributes.o
g++ -m32 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG -I../inst/include/
 -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall
-mtune=core2 -c barrier.cpp -o barrier.o
g++ -m32 -shared -s -static-libgcc -o Rcpp.dll tmp.def Date.o Module.o
Rcpp_init.o api.o attributes.o barrier.o
-Ld:/RCompile/CRANpkg/extralibs64/local/lib/i386
-Ld:/RCompile/CRANpkg/extralibs64/local/lib
-LC:/PROGRA~1/R/R-3.1/bin/i386 -lR
installing to C:/Users/Gabor/Documents/R/win-library/3.1/Rcpp/libs/i386

*** arch - x64
g++ -m64 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG -I../inst/include/
 -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall
-mtune=core2 -c Date.cpp -o Date.o
g++ -m64 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG -I../inst/include/
 -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall
-mtune=core2 -c Module.cpp -o Module.o
g++ -m64 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG -I../inst/include/
 -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall
-mtune=core2 -c Rcpp_init.cpp -o Rcpp_init.o
g++ -m64 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG -I../inst/include/
 -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall
-mtune=core2 -c api.cpp -o api.o
g++ -m64 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG -I../inst/include/
 -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall
-mtune=core2 -c attributes.cpp -o attributes.o
g++ -m64 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG -I../inst/include/
 -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall
-mtune=core2 -c barrier.cpp -o barrier.o
g++ -m64 -shared -s -static-libgcc -o Rcpp.dll tmp.def Date.o Module.o
Rcpp_init.o api.o attributes.o barrier.o
-Ld:/RCompile/CRANpkg/extralibs64/local/lib/x64
-Ld:/RCompile/CRANpkg/extralibs64/local/lib
-LC:/PROGRA~1/R/R-3.1/bin/x64 -lR
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
** 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 
+ #include 
+ 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  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 plug

Re: [Rcpp-devel] Rcpp release candidate

2014-06-05 Thread Gabor Grothendieck
On Wed, Jun 4, 2014 at 11:21 PM, Dirk Eddelbuettel  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 
+ #include 
+
+ 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 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG
-I"C:/Users/Gabor/Documents/R/win-library/3.1/Rcpp/include"
-I"C:/Users/Gabor/Documents/R/win-library/3.1/BH/include"
-I"d:/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 

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`, 'sourceCpp_37333_useCpp11')

rm(`.sourceCpp_37333_DLLInfo`)

Building shared library


DIR: C:/Users/Gabor/AppData/Local/Temp/RtmpmUpJdX/sourcecpp_18a41e263c3c

C:/PROGRA~1/R/R-3.1/bin/x64/R CMD SHLIB -o "sourceCpp_77519.dll"
"file18a42f7f546e.cpp"
g++ -m64 -I"C:/PROGRA~1/R/R-3.1/include" -DNDEBUG
-I"C:/Users/Gabor/Documents/R/win-library/3.1/Rcpp/include"
-I"C:/Users/Gabor/Documents/R/win-library/3.1/BH/include"
-I"d:/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_77519.dll" WIN=64 TCLBIN=64
OBJECTS="file18a42f7f546e.o"' had status 2
Error in sourceCpp(code = code, verbose = TRUE) :
  Error 1 occurred building shared library.




-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] Rcpp release candidate

2014-06-05 Thread Gabor Grothendieck
On Wed, Jun 4, 2014 at 11:21 PM, Dirk Eddelbuettel  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.

I am getting latex errors when attempting to install it on Windows
8.1.  (If I add the build_vignettes=FALSE argument then it does build
although, of course, without the vignettes):

> devtools::install_github("RcppCore/Rcpp")
Installing github repo Rcpp/master from RcppCore
Downloading master.zip from https://github.com/RcppCore/Rcpp/archive/master.zip
Installing package from C:\Users\Gabor\AppData\Local\Temp\RtmpmUpJdX/master.zip
Installing Rcpp
"C:/PROGRA~1/R/R-3.1/bin/x64/R" --vanilla CMD build  \
  
"C:\Users\Gabor\AppData\Local\Temp\RtmpmUpJdX\devtools18a41727545c\Rcpp-master"
 \
  --no-manual --no-resave-data

* checking for file
'C:\Users\Gabor\AppData\Local\Temp\RtmpmUpJdX\devtools18a41727545c\Rcpp-master/DESCRIPTION'
... OK
* preparing 'Rcpp':
* checking DESCRIPTION meta-information ... OK
* cleaning src
* installing the package to process help pages
* creating vignettes ...Warning: running command
'"C:/PROGRA~1/R/R-3.1/bin/x64/Rscript" --vanilla --default-packages=
-e "tools::buildVignettes(dir = '.', tangle = TRUE)"' had status 1
 ERROR
Loading required package: inline
Loading required package: highlight

Attaching package: 'Rcpp'

The following object is masked from 'package:inline':

registerPlugin

Warning: running command
'"C:\PROGRA~2\MIKTEX~1.9\miktex\bin\texi2dvi.exe" --quiet --pdf
"Rcpp-FAQ.tex" --max-iterations=20 -I
"C:/PROGRA~1/R/R-3.1/share/texmf/tex/latex" -I
"C:/PROGRA~1/R/R-3.1/share/texmf/bibtex/bst"' had status 1
Error: running 'texi2dvi' on 'Rcpp-FAQ.tex' failed

LaTeX errors:
Rcpp-FAQ.tex:516: pdfTeX error (font expansion): auto expansion is only possibl
e with scalable fonts


Here is how much of TeX's memory you used:
Rcpp-FAQ.tex:516:  ==> Fatal error occurred, no output PDF file produced!
Execution halted
Error: Command failed (1)

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] Compile errors when including Rcpp 0.11.0

2014-05-10 Thread Gabor Grothendieck
Regarding the vignettes I got this error when running
github_install("RcppCore/Rcpp"):

LaTeX errors:
pp-FAQ.tex:516: pdfTeX error (font expansion): auto expansion is only possible
with scalable fonts

On Sat, May 10, 2014 at 4:41 PM, Kevin Ushey  wrote:
> The vignettes build fine for me. Can you provide more information
> (perhaps as a GitHub issue)?
>
> I'll take a look at InternalFunction. I think there was something
> similar reported earlier.
>
> Cheers,
> Kevin
>
> On Sat, May 10, 2014 at 12:44 PM, Gabor Grothendieck
>  wrote:
>> On Sat, Mar 1, 2014 at 2:36 PM, Dirk Eddelbuettel  wrote:
>>>
>>> On 1 March 2014 at 20:23, Jonathon Love wrote:
>>> | It didn't work, I get the same error.
>>> |
>>> | I installed from github using:
>>> |
>>> | install_github("RcppCore/Rcpp")
>>> |
>>> | this updated my Rcpp to version 0.11.0.2
>>> |
>>> | but the problem persists.
>>> |
>>> | Any further suggestions?
>>>
>>> Not really.  A minimal reproducible example would help.
>>>
>>> The corpus of now 180 packages at CRAN work across OS X, Windows and Linux;
>>> as do 19 BioC packages in the next release plus an unknowable number of
>>> private packages.
>>>
>>> But there can always be fresh bugs in unseen code. But to fix something, it
>>> helps tremendously to be able to reproduce it.
>>>
>>> Can you assist with a small example?
>>
>> As you never got a reproducible example, let me jump in to this old
>> thread as the error discussed, viz.
>>class Rcpp::InternalFunction_Impl' has no
>> member named 'update'
>> comes up with both the version of Rcpp on CRAN as well as the version
>> on github when running
>> this reproducible example:
>>
>> code <- '
>> #include 
>> using namespace Rcpp ;
>>
>> void callback(){
>> Rprintf( "hello from calback\n" ) ;
>> }
>>
>> // [[Rcpp::export]]
>> InternalFunction get_callback(){
>> return InternalFunction(&callback) ;
>> }
>> '
>> library(Rcpp)
>> sourceCpp(code = code, verbose = TRUE)
>>
>> This example is from Romain who posted it on SO here some time back
>> except I added a & before callback in the last line.
>> http://stackoverflow.com/questions/13904786/r-pointer-to-c-function/13910838#13910838
>>
>> I am on Windows 8.1 and am using  "R version 3.1.0 Patched (2014-05-08 
>> r65552)"
>>
>> (Note that the version of Rcpp on github fails when installing during
>> building the vignette so I built it without vignettes; however, the
>> problem occurs on the CRAN version too as mentioned.)
>> ___
>> 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



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] Compile errors when including Rcpp 0.11.0

2014-05-10 Thread Gabor Grothendieck
On Sat, Mar 1, 2014 at 2:36 PM, Dirk Eddelbuettel  wrote:
>
> On 1 March 2014 at 20:23, Jonathon Love wrote:
> | It didn't work, I get the same error.
> |
> | I installed from github using:
> |
> | install_github("RcppCore/Rcpp")
> |
> | this updated my Rcpp to version 0.11.0.2
> |
> | but the problem persists.
> |
> | Any further suggestions?
>
> Not really.  A minimal reproducible example would help.
>
> The corpus of now 180 packages at CRAN work across OS X, Windows and Linux;
> as do 19 BioC packages in the next release plus an unknowable number of
> private packages.
>
> But there can always be fresh bugs in unseen code. But to fix something, it
> helps tremendously to be able to reproduce it.
>
> Can you assist with a small example?

As you never got a reproducible example, let me jump in to this old
thread as the error discussed, viz.
   class Rcpp::InternalFunction_Impl' has no
member named 'update'
comes up with both the version of Rcpp on CRAN as well as the version
on github when running
this reproducible example:

code <- '
#include 
using namespace Rcpp ;

void callback(){
Rprintf( "hello from calback\n" ) ;
}

// [[Rcpp::export]]
InternalFunction get_callback(){
return InternalFunction(&callback) ;
}
'
library(Rcpp)
sourceCpp(code = code, verbose = TRUE)

This example is from Romain who posted it on SO here some time back
except I added a & before callback in the last line.
http://stackoverflow.com/questions/13904786/r-pointer-to-c-function/13910838#13910838

I am on Windows 8.1 and am using  "R version 3.1.0 Patched (2014-05-08 r65552)"

(Note that the version of Rcpp on github fails when installing during
building the vignette so I built it without vignettes; however, the
problem occurs on the CRAN version too as mentioned.)
___
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

2014-05-07 Thread Gabor Grothendieck
I did read it but his theory must be wrong since it failed as
described before Kevin's fix and worked afterwards.


On Wed, May 7, 2014 at 8:14 AM, Dirk Eddelbuettel  wrote:
>
> On 7 May 2014 at 06:47, Gabor Grothendieck wrote:
> | I am now getting latex errors when I try to install Rcpp from github
>
> We treat GitHub as a development repository, just like R-Forge before it.
>
> To us, it is not a means for general distribution (though we strive to keep
> the master branch sane at all times).  OTOH releases are rigorously tested on
> win-builder and other platforms. So if in doubt, use CRAN.
>
> That said, even GitHub gets continuous integration and builds on every
> commit. Things generally work for the OS X and Linux crowds (for several
> flavours of each). We do turn vignettes off on GitHub to save some processing
> time. Building vignettes requires highlight (the package) and a decent LaTeX.
>
> As nobody in Rcpp Core develops (primarily) on Windows, if something breaks
> you get to keep the pieces -- at least until you, or someone else, fixes it.
>
> Dirk
>
>
> | (see below) but it does now work (without the vignettes) if I use:
> |github_install("RcppCore/Rcpp", build_vignettes = FALSE)
> | so at least I can proceed without explicitly setting any environment
> | variables now.
> | Thanks.
> |
> | > R.version.string
> | [1] "R version 3.1.0 Patched (2014-05-03 r65519)"
> | >
> | > devtools::install_github("RcppCore/rcpp")
> | Installing github repo rcpp/master from RcppCore
> | Downloading master.zip from 
> https://github.com/RcppCore/rcpp/archive/master.zip
> |
> | 
> |
> | * creating vignettes ...Warning: running command
> | '"C:/PROGRA~1/R/R-3.1/bin/x64/Rscript" --vanilla --default-packages=
> | -e "tools::buildVignettes(dir = '.', tangle = TRUE)"' had status 1
> |  ERROR
> | Loading required package: inline
> | Loading required package: highlight
> |
> | Attaching package: 'Rcpp'
> |
> | The following object is masked from 'package:inline':
> |
> | registerPlugin
> |
> | Warning: running command
> | '"C:\PROGRA~2\MIKTEX~1.9\miktex\bin\texi2dvi.exe" --quiet --pdf
> | "Rcpp-FAQ.tex" --max-iterations=20 -I
> | "C:/PROGRA~1/R/R-3.1/share/texmf/tex/latex" -I
> | "C:/PROGRA~1/R/R-3.1/share/texmf/bibtex/bst"' had status 1
> | Error: running 'texi2dvi' on 'Rcpp-FAQ.tex' failed
> |
> | LaTeX errors:
> | cpp-FAQ.tex:516: pdfTeX error (font expansion): auto expansion is only 
> possible
> |  with scalable fonts
> |
> |
> | Here is how much of TeX's memory you used:
> | cpp-FAQ.tex:516:  ==> Fatal error occurred, no output PDF file produced!
> | Execution halted
> | Error: Command failed (1)
> |
> | On Wed, May 7, 2014 at 1:50 AM, Kevin Ushey  wrote:
> | > Hi Gabor,
> | >
> | > Looks like it was a bug on our end -- R-exts specifies that USE_CXX1X
> | > should be set to any value; we try to set it to nothing (ie, define it
> | > but leave it empty) but apparently that is not accepted.
> | >
> | > I just pushed a bug fix to GitHub and it works on my Windows VM; can
> | > you give it another shot?
> | >
> | > Thanks,
> | > Kevin
> | >
> | > On Tue, May 6, 2014 at 9:09 PM, Gabor Grothendieck
> | >  wrote:
> | >> On Windows with R 3.1 I installed the latest Rcpp from github and did
> | >> the following but the compliation gave an error which was was due to
> | >> the C++11 constructs.  If I rerun it but uncomment the Sys.setenv line
> | >> then it works. What do I do to get the cpp11 attribute to work?
> | >>
> | >> library(Rcpp)
> | >> # Sys.setenv("PKG_CXXFLAGS"="-std=c++0x")
> | >> cat('
> | >> // [[Rcpp::plugins("cpp11")]]
> | >> // [[Rcpp::export]]
> | >> int useCpp11() {
> | >> auto x = 10;
> | >> return x;
> | >> }
> | >> ', file = "testauto.cpp")
> | >> sourceCpp("testauto.cpp")
> | >>
> | >> On Wed, Apr 30, 2014 at 11:12 AM, Dirk Eddelbuettel  
> wrote:
> | >>>
> | >>> On 30 April 2014 at 10:05, Dirk Eddelbuettel wrote:
> | >>> |
> | >>> | On 30 April 2014 at 10:41, JJ Allaire wrote:
> | >>> | | I think that might be overkill (or something that we can do later 
> if users ask
> | >>> | | for it).
> | >>> |
> | >>> | It is a one-liner, and it just sits there to be used, like OpenMP 
> plugin.
> | >

Re: [Rcpp-devel] g++ flags

2014-05-07 Thread Gabor Grothendieck
I am now getting latex errors when I try to install Rcpp from github
(see below) but it does now work (without the vignettes) if I use:
   github_install("RcppCore/Rcpp", build_vignettes = FALSE)
so at least I can proceed without explicitly setting any environment
variables now.
Thanks.

> R.version.string
[1] "R version 3.1.0 Patched (2014-05-03 r65519)"
>
> devtools::install_github("RcppCore/rcpp")
Installing github repo rcpp/master from RcppCore
Downloading master.zip from https://github.com/RcppCore/rcpp/archive/master.zip



* creating vignettes ...Warning: running command
'"C:/PROGRA~1/R/R-3.1/bin/x64/Rscript" --vanilla --default-packages=
-e "tools::buildVignettes(dir = '.', tangle = TRUE)"' had status 1
 ERROR
Loading required package: inline
Loading required package: highlight

Attaching package: 'Rcpp'

The following object is masked from 'package:inline':

registerPlugin

Warning: running command
'"C:\PROGRA~2\MIKTEX~1.9\miktex\bin\texi2dvi.exe" --quiet --pdf
"Rcpp-FAQ.tex" --max-iterations=20 -I
"C:/PROGRA~1/R/R-3.1/share/texmf/tex/latex" -I
"C:/PROGRA~1/R/R-3.1/share/texmf/bibtex/bst"' had status 1
Error: running 'texi2dvi' on 'Rcpp-FAQ.tex' failed

LaTeX errors:
cpp-FAQ.tex:516: pdfTeX error (font expansion): auto expansion is only possible
 with scalable fonts


Here is how much of TeX's memory you used:
cpp-FAQ.tex:516:  ==> Fatal error occurred, no output PDF file produced!
Execution halted
Error: Command failed (1)

On Wed, May 7, 2014 at 1:50 AM, Kevin Ushey  wrote:
> Hi Gabor,
>
> Looks like it was a bug on our end -- R-exts specifies that USE_CXX1X
> should be set to any value; we try to set it to nothing (ie, define it
> but leave it empty) but apparently that is not accepted.
>
> I just pushed a bug fix to GitHub and it works on my Windows VM; can
> you give it another shot?
>
> Thanks,
> Kevin
>
> On Tue, May 6, 2014 at 9:09 PM, Gabor Grothendieck
>  wrote:
>> On Windows with R 3.1 I installed the latest Rcpp from github and did
>> the following but the compliation gave an error which was was due to
>> the C++11 constructs.  If I rerun it but uncomment the Sys.setenv line
>> then it works. What do I do to get the cpp11 attribute to work?
>>
>> library(Rcpp)
>> # Sys.setenv("PKG_CXXFLAGS"="-std=c++0x")
>> cat('
>> // [[Rcpp::plugins("cpp11")]]
>> // [[Rcpp::export]]
>> int useCpp11() {
>> auto x = 10;
>> return x;
>> }
>> ', file = "testauto.cpp")
>> sourceCpp("testauto.cpp")
>>
>> On Wed, Apr 30, 2014 at 11:12 AM, Dirk Eddelbuettel  wrote:
>>>
>>> On 30 April 2014 at 10:05, Dirk Eddelbuettel wrote:
>>> |
>>> | On 30 April 2014 at 10:41, JJ Allaire wrote:
>>> | | I think that might be overkill (or something that we can do later if 
>>> users ask
>>> | | for it).
>>> |
>>> | It is a one-liner, and it just sits there to be used, like OpenMP plugin.
>>> |
>>> | So in that sense it doesn't hurt, and it may yet help those for which 
>>> both R
>>> | < 3.1.0 and Windows are true.
>>>
>>> Actually, as Gabor points out, where 'R < 3.1.0' and 'g++ < 4.7' which may
>>> also be a bunch of servers running older RHEL or Ubuntu LTS.
>>>
>>> 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
>>
>>
>>
>> --
>> 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



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] g++ flags

2014-05-06 Thread Gabor Grothendieck
On Windows with R 3.1 I installed the latest Rcpp from github and did
the following but the compliation gave an error which was was due to
the C++11 constructs.  If I rerun it but uncomment the Sys.setenv line
then it works. What do I do to get the cpp11 attribute to work?

library(Rcpp)
# Sys.setenv("PKG_CXXFLAGS"="-std=c++0x")
cat('
// [[Rcpp::plugins("cpp11")]]
// [[Rcpp::export]]
int useCpp11() {
auto x = 10;
return x;
}
', file = "testauto.cpp")
sourceCpp("testauto.cpp")

On Wed, Apr 30, 2014 at 11:12 AM, Dirk Eddelbuettel  wrote:
>
> On 30 April 2014 at 10:05, Dirk Eddelbuettel wrote:
> |
> | On 30 April 2014 at 10:41, JJ Allaire wrote:
> | | I think that might be overkill (or something that we can do later if 
> users ask
> | | for it).
> |
> | It is a one-liner, and it just sits there to be used, like OpenMP plugin.
> |
> | So in that sense it doesn't hurt, and it may yet help those for which both R
> | < 3.1.0 and Windows are true.
>
> Actually, as Gabor points out, where 'R < 3.1.0' and 'g++ < 4.7' which may
> also be a bunch of servers running older RHEL or Ubuntu LTS.
>
> 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



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] g++ flags

2014-04-30 Thread Gabor Grothendieck
On Wed, Apr 30, 2014 at 10:40 AM, Dirk Eddelbuettel  wrote:
>
> On 30 April 2014 at 10:15, JJ Allaire wrote:
> | I think this PR addresses the issue:
> |
> | https://github.com/RcppCore/Rcpp/pull/143
>
> Very nice. We get the better behaviour of R 3.1.0 when it is available but do
> not enforce it.
>
> I may still add a new simple plugin to provide 'c++0x' for users on Windoze
> who do not have the newer R.  Or do you think that's overkill?

I think that would be worthwhile in addition to the proposed fix since
many people are waiting for the read.table problem in R 3.1 to be
fixed before upgrading to it.

Also this plugin is presumably applicable to all OSes, not just Windows.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] g++ flags

2014-04-30 Thread Gabor Grothendieck
On Wed, Apr 30, 2014 at 9:19 AM, Romain Francois
 wrote:
> The plugin as implemented now is not portable.

It would presumably have the same problem on any OS if used witih g++
4.6.3.  An OS-independent way to do this would be to examine the
version of g++ used and act accordingly:

> sub(".*\\D(\\d+[.]\\d+[.]\\d+).*", "\\1", system("g++ --version", intern = 
> TRUE)[1])
[1] "4.6.3"
___
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] (no subject)

2014-04-30 Thread Gabor Grothendieck
Thr cpp11 plugin as described in this article

http://gallery.rcpp.org/articles/first-steps-with-C++11/

gives an error regarding an unknown option when run on Windows with
the current version of Rtools (Rtools version 3.1.0.1942) and Rcpp
0.11.1:

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 and not -std-c++11.

See:
http://gcc.gnu.org/projects/cxx0x.html
http://gcc.gnu.org/gcc-4.6/cxx0x_status.html

If one removes the reference to the plugin in useAuto.cpp then to run
the example cited above this works:

Sys.setenv("PKG_CXXFLAGS"="-std=c++0x")
sourceCpp("useAuto.cpp")


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] Installation tutorial for Rcpp, C++11, and 64-bit Windows

2013-11-24 Thread Gabor Grothendieck
On Sun, Nov 24, 2013 at 12:38 AM, Brian Templeton  wrote:
> I ended up spending a bit of time trying to get Rcpp to work for C++11 
> standard code in Windows. (I already had code working on Linux with Rcpp, but 
> needed to get it to work with Windows as well.) I figured I'd write up what 
> worked and post it on Rcpp list in case someone else has similar problems:
>
> http://batempleton.wordpress.com/2013/11/22/installing-rcpp-using-c11-on-windows-x64/
>

I also have some Windows batch files that can help with this, the main
benefit being that no enviornment variables or registry keys need to
be set for R or for Rtools (although it will use them if set).  A
secondary benefit is that they do not require Admin privileges since
they make no permanent changes to your system.

R.bat is a single self contained Windows batch file that can start
R.exe or Rgui.exe .  It looks up the location of R and Rtools using
the registry or if not found looks in standard locations.  It also
scans Rtools to discover the appropriate path to its directories. It
works by temporarily setting the required environment variables
eliminating the need to set any such variables yourself.

Using it installation of R is as simple as installing R and Rtools
using the defaults (they both have automated installers so this is
simple) and then placing R.bat anywhere on your path.  Running is just
a matter of using (1) 'R.bat' in place of 'R.exe' and (2) 'R.bat gui'
in place of 'Rgui.exe'.

They are available by downloading these two files (the second is the
documentation):

   https://batchfiles.googlecode.com/svn/trunk/R.bat
   https://batchfiles.googlecode.com/svn/trunk/batchfiles.md

On some systems its heuristic won't work and in that case use:

   https://batchfiles.googlecode.com/svn/trunk/Rpathset.bat

which is a simple batch file that can be edited manually (so its not
as automatic as R.bat but due to its simplicity you may have fewer
problems).  It also eliminates the need to set any environment
variables or to make other changes in the registry and is also
documented in the above md file.

Some of these installation simplifications are alternately provided in
some form in Rcpp itself as well as in the devtools and installr
packages.  These packages allow one to do this from within R whereas
these batch files work from the Windows cmd line.

In addition to the cited documentation there is some info on these and
other batch files on the home page:

   http://batchfiles.googlecode.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] Forcing a shallow versus deep copy

2013-07-12 Thread Gabor Grothendieck
On Fri, Jul 12, 2013 at 1:42 AM, Dirk Eddelbuettel  wrote:
>
> On 11 July 2013 at 19:21, Gabor Grothendieck wrote:
> | 1. Just to be clear what we have been discussing here is not just how to
> | avoid copying but how to avoid copying while using as and wrap
> | or approaches that automatically generate as and wrap.  I was already
> | aware of how to avoid copying using Armadillo how to use Armadillo types
> | as arguments and return values to autogen as and wrap.  The problem is
> | not that but that these two things cannot be done at once - its either or.
>
> I must still be misunderstanding as this still reads to me as if you are
> suspecting that we somehow keep layers making extra copies.
>
> We're not. And I've known you long enough to know that you are not likely to
> suspect this either.  So what is it then?
>
> As Romain said, some of the choice have to do with the representation on both
> the R and C++ side -- for Rcpp itself we can be lightweight and efficient via
> proxy classes, but this does not mean we can do this for _any arbitrary C++
> class_ coming from another project. As eg Armadillo.  RcppArmadilo already
> does pretty well, and code review may make it better.  We do not know of any
> fat to cut, or we'd cut it ourselves.  We care about a few things, but
> performance is clearly among them.

I think Romain's proposal will clarify this.

>
> | 2. Regarding the quesiton of performance impact there are two situations
> | which should be distinguished:
> |
> | i. We call C++ from R and it does some processing and then returns and
> | we don't call it again. In that case its likely that copying or not won't
> | make a big difference or at least it won't if the actual C++ computation
> | time is large coimpared to the time spent in copying.
> |
> | ii. We factor out the inner loop of the code and only recode that in C++
> | and repeatedly call it many times.  In that case the copying is multiplied
> | by the number of iterations and might very well have a significant impact.
>
> In case ii) I'd try to use a different design and make it more like i): You
> generally do not want to call down from R to object code a bazillion times as
> there is always some overhead, and multiplying even something rather
> efficient by a veryBigNumber can make small times large in the aggregate.

Sure and sugar, rcpparmadillo and other facilities do make it easier to move
more functionality into C++; nevertheless, it can be the case that a relatively
small amount of R code repeatedly
invoked is responsible for the performance hit in a program and from
the viewpoint
of reducing complexity and increasing maintainability it can be
desirable to just
move that minimum portion to the C++ side minimizing the dual language aspect
of the code.  By making call overhead as fast
as one can while retaining any automatic Rcpp features then this
is facilitated.  If its not possible in general then if it were just possible
for Armadillo objects and selected other situations then this would
still be nice.

>
> Dirk
>
> |
> | On Thu, Jul 11, 2013 at 6:55 PM, Dirk Eddelbuettel  wrote:
> | >
> | > Everybody has this existing example in their copy of Armadillo.
> | >
> | > I am running it here from SVN rather than the installed directory, but 
> this
> | > should not make a difference. Machine is my not-overly-powerful thinkpad 
> used
> | > for traveling:
> | >
> | > edd@don:~/svn/rcpp/pkg/RcppArmadillo/inst/examples$ r fastLm.r
> | > Loading required package: methods
> | >
> | > Attaching package: ‘Rcpp’
> | >
> | > The following object is masked from ‘package:inline’:
> | >
> | > registerPlugin
> | >
> | >test replications relative elapsed user.self 
> sys.self
> | > 2 fLmTwoCasts(X, y) 50001.000   0.184 0.204
> 0.164
> | > 1  fLmOneCast(X, y) 50001.011   0.186 0.200
> 0.172
> | > 4   fastLmPureDotCall(X, y) 50001.141   0.210 0.236
> 0.184
> | > 3  fastLmPure(X, y) 50002.027   0.373 0.412
> 0.332
> | > 6  lm.fit(X, y) 50002.685   0.494 0.528
> 0.456
> | > 5 fastLm(frm, data = trees) 5000   36.380   6.694 7.332
> 6.028
> | > 7 lm(frm, data = trees) 5000   42.734   7.863 8.628
> 7.068
> | > edd@don:~/svn/rcpp/pkg/RcppArmadillo/inst/examples$
> | >
> | > What we are talking about here is the difference between 'fLmTwoCasts' and
> | > 'fLmOneCasts'.  If you use larger objects, the different with be larger.  
> But
> | > the relative diff

Re: [Rcpp-devel] Forcing a shallow versus deep copy

2013-07-11 Thread Gabor Grothendieck
1. Just to be clear what we have been discussing here is not just how to
avoid copying but how to avoid copying while using as and wrap
or approaches that automatically generate as and wrap.  I was already
aware of how to avoid copying using Armadillo how to use Armadillo types
as arguments and return values to autogen as and wrap.  The problem is
not that but that these two things cannot be done at once - its either or.

2. Regarding the quesiton of performance impact there are two situations
which should be distinguished:

i. We call C++ from R and it does some processing and then returns and
we don't call it again. In that case its likely that copying or not won't
make a big difference or at least it won't if the actual C++ computation
time is large coimpared to the time spent in copying.

ii. We factor out the inner loop of the code and only recode that in C++
and repeatedly call it many times.  In that case the copying is multiplied
by the number of iterations and might very well have a significant impact.

On Thu, Jul 11, 2013 at 6:55 PM, Dirk Eddelbuettel  wrote:
>
> Everybody has this existing example in their copy of Armadillo.
>
> I am running it here from SVN rather than the installed directory, but this
> should not make a difference. Machine is my not-overly-powerful thinkpad used
> for traveling:
>
> edd@don:~/svn/rcpp/pkg/RcppArmadillo/inst/examples$ r fastLm.r
> Loading required package: methods
>
> Attaching package: ‘Rcpp’
>
> The following object is masked from ‘package:inline’:
>
> registerPlugin
>
>test replications relative elapsed user.self sys.self
> 2 fLmTwoCasts(X, y) 50001.000   0.184 0.2040.164
> 1  fLmOneCast(X, y) 50001.011   0.186 0.2000.172
> 4   fastLmPureDotCall(X, y) 50001.141   0.210 0.2360.184
> 3  fastLmPure(X, y) 50002.027   0.373 0.4120.332
> 6  lm.fit(X, y) 50002.685   0.494 0.5280.456
> 5 fastLm(frm, data = trees) 5000   36.380   6.694 7.3326.028
> 7 lm(frm, data = trees) 5000   42.734   7.863 8.6287.068
> edd@don:~/svn/rcpp/pkg/RcppArmadillo/inst/examples$
>
> What we are talking about here is the difference between 'fLmTwoCasts' and
> 'fLmOneCasts'.  If you use larger objects, the different with be larger.  But
> the relative differences are tiny.
>
> It would be nice to make this more elegant, and I look forward to Romain's
> proposals, but methinks that we may well have bigger fish to fry.
>
> Dirk, still in Sydney
>
> --
> 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



--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] Forcing a shallow versus deep copy

2013-07-11 Thread Gabor Grothendieck
On Thu, Jul 11, 2013 at 8:56 AM, Changi Han  wrote:
> I entirely missed that thread ... sorry. I came across the above examples
> at:
>
> http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2013-April/005680.html
>
>
> On Thu, Jul 11, 2013 at 8:38 PM, Gabor Grothendieck
>  wrote:
>>
>> On Thu, Jul 11, 2013 at 8:32 AM, Changi Han 
>> wrote:
>> > Hello,
>> >
>> > I think I (superficially) understand the difference between:
>> >
>> > // [[Rcpp::export]]
>> > double sum1(Rcpp::NumericMatrix M) {
>> > arma::mat A(M.begin(), M.rows(), M.cols(), false);
>> > return sum(sum(A));
>> > }
>> >
>> >
>> > // [[Rcpp::export]]
>> > double sum2(arma::mat A) {
>> > return sum(sum(A));
>> > }
>> >
>> > Partly out of laziness, partly because sum2 is more elegant, and partly
>> > to
>> > avoid namespace pollution, I was wondering if there is a way to "force"
>> > a
>> > "shallow" copy in sum2.
>> >
>> > If not, then may I submit a low priority feature request. An attribute?
>> > Some
>> > thing like:
>> >
>> > // [[Rcpp::export]]
>> > double sum2(arma::mat A) {
>> > // [[ Rcpp::shallow ( A ) ]]
>> > return sum(sum(A));
>> > }
>> >
>> > Or (akin to C++11 generalized attributes)
>> >
>> > // [[Rcpp::export]] { [[ Rcpp::shallow ( A ) ]] }
>> > double sum2(arma::mat A) {
>> > return sum(sum(A));
>> > }
>> >
>> > An alternative is to have an argument in sourceCpp that takes a
>> > list/vector
>> > of objects that are to be shallow or deep copied.
>> >
>> > For example in sum1, if M is changed within the function before casting
>> > to
>> > the arma::mat, then might be cleaner to add M to a list/vector of
>> > objects to
>> > be deep copied rather than cloning M within sum1: leads to one fewer
>> > variable name.
>> >
>> > Just a thought. I can certainly live with the additional step. As
>> > always,
>> > thanks for all the Rcpp goodness.
>>
>> I had just made a similar suggestion in my post about half an hour ago.
>
>

It does suggest that many people are thinking along the same lines in
terms of new desirable features.

--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] Forcing a shallow versus deep copy

2013-07-11 Thread Gabor Grothendieck
On Thu, Jul 11, 2013 at 8:32 AM, Changi Han  wrote:
> Hello,
>
> I think I (superficially) understand the difference between:
>
> // [[Rcpp::export]]
> double sum1(Rcpp::NumericMatrix M) {
> arma::mat A(M.begin(), M.rows(), M.cols(), false);
> return sum(sum(A));
> }
>
>
> // [[Rcpp::export]]
> double sum2(arma::mat A) {
> return sum(sum(A));
> }
>
> Partly out of laziness, partly because sum2 is more elegant, and partly to
> avoid namespace pollution, I was wondering if there is a way to "force" a
> "shallow" copy in sum2.
>
> If not, then may I submit a low priority feature request. An attribute? Some
> thing like:
>
> // [[Rcpp::export]]
> double sum2(arma::mat A) {
> // [[ Rcpp::shallow ( A ) ]]
> return sum(sum(A));
> }
>
> Or (akin to C++11 generalized attributes)
>
> // [[Rcpp::export]] { [[ Rcpp::shallow ( A ) ]] }
> double sum2(arma::mat A) {
> return sum(sum(A));
> }
>
> An alternative is to have an argument in sourceCpp that takes a list/vector
> of objects that are to be shallow or deep copied.
>
> For example in sum1, if M is changed within the function before casting to
> the arma::mat, then might be cleaner to add M to a list/vector of objects to
> be deep copied rather than cloning M within sum1: leads to one fewer
> variable name.
>
> Just a thought. I can certainly live with the additional step. As always,
> thanks for all the Rcpp goodness.

I had just made a similar suggestion in my post about half an hour ago.
___
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] copying or not when convering to arma

2013-07-11 Thread Gabor Grothendieck
On Thu, Jul 11, 2013 at 3:50 AM, Dirk Eddelbuettel  wrote:
>
> On 10 July 2013 at 11:58, Gabor Grothendieck wrote:
> | Suppose we have this program where we have started and ended with SEXP
> | and written out the as and wrap conversions to make them explicit.
> |
> | How many times is the data copied?
> | Does as copy the underlying data?
> | Does wrap?
> | Is it copied elsewhere?
> | Which file in the source code would one look to determine this?
> | If it does copy the data is there some way to tell as and wrap to just
> | point to it to avoid copying?
> |
> | #include 
> | // [[Rcpp::depends(RcppArmadillo)]]
> | // [[Rcpp::export]]
> | SEXP test(SEXP v) {
> |arma::vec va = Rcpp::as(v);
> |SEXP vs = Rcpp::wrap(va);
> |return vs;
> | }
>
> You can reduce this to
>
> #include 
> // [[Rcpp::depends(RcppArmadillo)]]
> // [[Rcpp::export]]
> arma::vec gabortest(arma::vec v) {
>return v;
> }
>
> because as<> and wrap() can get called automagically given that
> RcppArmadillo provides them.
>
> You want to start with the few header files we add to Armadillo in
> RcppArmadillo (ie above the armadillo_bits/ directory which is verbatim
> Armadillo.
>
> In this case, a copy is made. How to avoid this has been discussed a dozen
> times here and is shown in FastLm.cpp as well.
>
> As for counts of objects:  I'd rather trust a good memory profiler than my
> word :)  But approximately, one each as we have to go from R/Rcpp to
> Armadillo (as use the easy way; for alternatives see above).  If you use just
> Rcpp no copies are being made.
>
> Cheers from Sydney,  Dirk
>
> | # run it from R
> | sourceCpp("test.cpp")
> | test(c(1.2, 1.3, 1.4))
> |
> |
> | --
> | 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
>
> --
> Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com

It might be nice if this were controllable by the user via something like:

// [[Rcpp::nocopy]]

or other syntax so that one could still use as and wrap (or approaches which
generate as and wrap automatically) while avoiding the copying.

--
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] copying or not when convering to arma

2013-07-10 Thread Gabor Grothendieck
Suppose we have this program where we have started and ended with SEXP
and written out the as and wrap conversions to make them explicit.

How many times is the data copied?
Does as copy the underlying data?
Does wrap?
Is it copied elsewhere?
Which file in the source code would one look to determine this?
If it does copy the data is there some way to tell as and wrap to just
point to it to avoid copying?

#include 
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::export]]
SEXP test(SEXP v) {
   arma::vec va = Rcpp::as(v);
   SEXP vs = Rcpp::wrap(va);
   return vs;
}


# run it from R
sourceCpp("test.cpp")
test(c(1.2, 1.3, 1.4))


--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] Regular Expressions

2013-03-05 Thread Gabor Grothendieck
On Mon, Mar 4, 2013 at 9:09 PM, Dirk Eddelbuettel  wrote:
>
> On 4 March 2013 at 20:18, Gabor Grothendieck wrote:
> | I had no luck with sourceCpp or inline on Windows but did manage to
> | use R CMD SHLIB to build a dll which loads into 32-bit R (it does not
> | currently load in 64-bit R - haven't yet figured out why) and seems to
> | run ok there.  To get it to work I did replace the first and last
> | statements in regexDemo with these two respectively so that all inputs
> | and outputs are SEXPs:
> |
> | extern "C" SEXP regexDemo(SEXP ss) {
> |std::vector s = Rcpp::as >(ss);
> |
> | return Rcpp::wrap(Rcpp::DataFrame::create(Rcpp::Named("input") = s,
> |Rcpp::Named("valid") = valid,
> |Rcpp::Named("machine") = machine,
> |Rcpp::Named("human") = human));
> |
> | This isn't quite as nice as what you had but at least it runs.
>
> Thanks for reporting back, and glad you get something to work. Going back to
> the metal can help.
>
> I won't be of much help for the Windows aspect.  The basic things all work,
> and from the 100+ CRAN packages now using Rcpp, many do involve libraries. If
> you _really_ wanted to squash this you could try to rebuild libboost_regex.a
> during the package build process (of a to be built package) to ensure that
> the same g++ gets used. That should help with 32/64 bit too.  But that is
> surely overkill.

I did rebuild boost from source as part of this since I also figured
that might be a problem.  On Windows there is a tool that is used  in
rebuilding the source (presumably similar to configure on UNIX) and I
rebuilt that tool from source too.  I may play around with all this a
bit more but it does take half an hour to build boost from source.
Its possible that some of the things I tried prior to rebuilding from
source would have worked had that they been tried with the rebuilt
version of boost.

Is it intended that BH will include boost libraries like Boost.Regex
which is not a header-only library?  Alternately if R made its own
regular expression libraries available to C++ programs there could be
an advantage in terms of consistency with R of the regular expressions
accepted.

Regarding packages, can you suggest which one(s) to look at?


--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] Regular Expressions

2013-03-04 Thread Gabor Grothendieck
On Fri, Mar 1, 2013 at 8:56 PM, Dirk Eddelbuettel  wrote:
>
> Gabor,
>
> Here is a quick variant of one of the Boost regexp examples, particularly
> http://www.boost.org/doc/libs/1_53_0/libs/regex/example/snippets/credit_card_example.cpp
>
> // cf 
> www.boost.org/doc/libs/1_53_0/libs/regex/example/snippets/credit_card_example.cpp
>
> #include 
>
> #include 
> #include 
>
> bool validate_card_format(const std::string& s) {
>static const boost::regex e("(\\d{4}[- ]){3}\\d{4}");
>return boost::regex_match(s, e);
> }
>
> const boost::regex e("\\A(\\d{3,4})[- ]?(\\d{4})[- ]?(\\d{4})[- 
> ]?(\\d{4})\\z");
> const std::string machine_format("\\1\\2\\3\\4");
> const std::string human_format("\\1-\\2-\\3-\\4");
>
> std::string machine_readable_card_number(const std::string& s) {
>return boost::regex_replace(s, e, machine_format, boost::match_default | 
> boost::format_sed);
> }
>
> std::string human_readable_card_number(const std::string& s) {
>return boost::regex_replace(s, e, human_format, boost::match_default | 
> boost::format_sed);
> }
>
> // [[Rcpp::export]]
> Rcpp::DataFrame regexDemo(std::vector s) {
> int n = s.size();
>
> std::vector valid(n);
> std::vector machine(n);
> std::vector human(n);
>
> for (int i=0; i valid[i]  = validate_card_format(s[i]);
> machine[i] = machine_readable_card_number(s[i]);
> human[i] = human_readable_card_number(s[i]);
> }
> return Rcpp::DataFrame::create(Rcpp::Named("input") = s,
>Rcpp::Named("valid") = valid,
>Rcpp::Named("machine") = machine,
>Rcpp::Named("human") = human);
> }
>
> which we can test with the same input as the example has:
>
>
> R> Rcpp::sourceCpp('/tmp/boostreex.cpp')
> R> s <- c("", "   ", "---", 
> "000---")
> R> regexDemo(s)
> input valid  machine   human
> 1 FALSE  ---
> 2      TRUE  ---
> 3 ---  TRUE  ---
> 4  000--- FALSE  000  000---
> R>
>
> On Linux, you generally don't have to do anything to get Boost headers as
> they end up in /usr/include (or /usr/local/include) so for me, this just
> builds.  For R on Windows, you are quite likely to get by with the
> CRAN-provided boost tarball and an additional -I$(BOOSTLIB) etc.
>

I had no luck with sourceCpp or inline on Windows but did manage to
use R CMD SHLIB to build a dll which loads into 32-bit R (it does not
currently load in 64-bit R - haven't yet figured out why) and seems to
run ok there.  To get it to work I did replace the first and last
statements in regexDemo with these two respectively so that all inputs
and outputs are SEXPs:

extern "C" SEXP regexDemo(SEXP ss) {
   std::vector s = Rcpp::as >(ss);

return Rcpp::wrap(Rcpp::DataFrame::create(Rcpp::Named("input") = s,
   Rcpp::Named("valid") = valid,
   Rcpp::Named("machine") = machine,
   Rcpp::Named("human") = human));

This isn't quite as nice as what you had but at least it runs.


--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] Regular Expressions

2013-03-02 Thread Gabor Grothendieck
On Sat, Mar 2, 2013 at 8:54 PM, Dirk Eddelbuettel  wrote:
>
> On 2 March 2013 at 20:39, Gabor Grothendieck wrote:
> | On Sat, Mar 2, 2013 at 7:05 PM, Dirk Eddelbuettel  wrote:
> | > Sorry that this is so frustrating, but this (IMNSHO) all just Windows...
> | >
> | > I would try two things:
> | >
> | >   a) forward slashes (no escaping needed)
> | >
> | >   b) use verbose=TRUE so that you see the R CMD ... invocation.
> | >
> | > Your initial boost test was key.  We know you have a working boost 
> library;
> | > we know Rcpp can create working code, now we just need to tie'em together.
> | >
> |
> | I had tried both these. It does not seem to be picking up the
> | PKG_LIBS.  There is no -l... or -L... on the g++ cmd line.
>
> There was also an issue with sourceCpp overwriting rather than extending
> PKG_LIBS.  I would suggest to for now ignore sourceCpp as a means of
> debugging.
>
> "All" we really need is one proper R CMD COMPILE step, and one R CMD SHLIB
> step.  You can do that by hand -- my old talks have the explicit steps, but I
> think you you know what do to do.
>
> You can also try just ~/.R/Makevars -- which is what I do when switcing from
> g++ to clang (setting CXX and CC), changing compiler options or warnings
> (PKG_CXXFLAGS), ... and so on.
>
> | Its also not clear precisely which boost distribution to use.  I had
> | tried http://nuwen.net/mingw.html (version 8.0) and also tried the
> | boost library from Cygwin.
>
> I have no idea. We need subsets of Boost for QuantLib, but as I recall that
> only covers the headers-only template use.  In any event if you must use
> something compatible with MinGw, as always, so Cygwin is probably a no-no.
>
> | If I use the MinGW from nuewn and run this from the Windows cnd line I
> | get no errors or warnings (note that ^ must be the last character on
> | the line to escape the newline):
> |
> | C:\MinGW\set_distro_paths.bat
> | g++ -DNDEBUG ^
> |  -L %userprofile%/Documents/R/win-library/2.15/Rcpp/lib/x64/libRcpp.a ^
> |  -lboost_regex ^
> |  -I"C:/PROGRA~1/R/R-2.15/include" ^
> |  -I%userprofile%/Documents/R/win-library/2.15/Rcpp/include ^
> |  -O2 -Wall -mtune=core2 -c credit.cpp -o credit.o
> |
> | If tyhat is ok then what would the next step be?
>
> That looks pretty good.  Use similar settings, make sure R sees them, and let
> R CMD ... do its magic.  Everything, be it via Makevars and Makevars.win, via
> inline's cxxfunction or Rcpp's sourceCpp just calls them anyway.
>

If I try this next after the above g++ line:

   R CMD SHLIB credit.o

then I get this:

C:/PROGRA~1/R/R-2.15/bin/x64/R.dll: file not recognized: File format
not recognized
collect2: ld returned 1 exit status

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] Regular Expressions

2013-03-02 Thread Gabor Grothendieck
On Sat, Mar 2, 2013 at 7:05 PM, Dirk Eddelbuettel  wrote:
>
> On 2 March 2013 at 18:47, Gabor Grothendieck wrote:
> | On Sat, Mar 2, 2013 at 10:17 AM, Dirk Eddelbuettel  wrote:
> | >
> | > On 1 March 2013 at 23:03, Gabor Grothendieck wrote:
> | > | On Fri, Mar 1, 2013 at 9:50 PM, Dirk Eddelbuettel  
> wrote:
> | > | >
> | > | > On 1 March 2013 at 21:24, Hadley Wickham wrote:
> | > | > | > | I searched BH for regex and found nothing so I don't think BH 
> includes
> | > | > | > | Boost.Regex.
> | > | > | >
> | > | > | > Could you register an issue ticket at the r-forge page for BH, 
> please?  There
> | > | > | > are other things missing too, of course, as we started pretty 
> with the needs
> | > | > | > of "just" bigmemory and RcppBDT.
> | > | > |
> | > | > | But Boost.Regex isn't header only?
> | > | >
> | > | > Yup. Found that out the hard way when I wrote it up as a piece for 
> the Rcpp
> | > | > Gallery. You do need to link.
> | > | >
> | > | > Piece now up at 
> http://gallery.rcpp.org/articles/boost-regular-expressions/
> | > | >
> | > |
> | > | I have downloaded boost such that I have this file:
> | > |
> | > | C:\MinGW\lib\libboost_regex.a
> | > |
> | > | How do I tell Rcpp to use it?
> | >
> | > Follow eg the Rcpp Gallery story and use
> | >
> | > Sys.setenv("PKG_LIBS"="C:\MinGW\lib\libboost_regex.a")
> | >
> | > as static library can be given "as is".  Else try
> | >
> | > Sys.setenv("PKG_LIBS"="-LC:\MinGW\lib\ -lboost_regex")
> | >
> | > which is the standard form.  That should work with the example I posted.
> | >
> | > If everthing else, try the documentation for Rcpp (Rcpp-package vignette 
> in
> | > particular) or Boost.
> | >
> |
> | Thanks. I doubled each backslash but unfortunately neither work.
> |
> | I am able to build the original credit_card_example from the boost
> | site independently of Rcpp, i.e. this builds and I can run the result:
> |
> |rem this works
> |C:\MinGW\set_distor_paths.bat
> |g++ credit_card_example.cpp -o credit_card_example.exe -lboost_regex
> |
> | and can also build C++ scripts not using boost; however,
> |
> | all of the following give:
> | credit.cpp:6:27: fatal error: boost/regex.hpp: No such file or directory
> |
> |library(Rcpp)
> |Sys.setenv("PKG_LIBS"="C:\\MinGW\\lib\\libboost_regex.a")
> |sourceCpp("credit.cpp", verbose = TRUE)
> |
> |library(Rcpp)
> |Sys.setenv("PKG_LIBS"="-LC:\\MinGW\\lib\\ -lboost_regex")
> |sourceCpp("credit.cpp", verbose = TRUE)
> |
> |library(Rcpp)
> |Sys.setenv("PKG_LIBS"="-lboost_regex")
> |sourceCpp("credit.cpp", verbose = TRUE)
> |
> | I also tried with Cygwin.  I have this file among others:
> | C:\cygwin\lib\libboost_regex-mt.dll.a
> |
> | and tried these but they give the same result:
> |
> |library(Rcpp)
> |Sys.setenv("PKG_LIBS"="C:\\cygwin\\lib\\libboost_regex-mt.dll.a")
> |sourceCpp("credit.cpp", verbose = TRUE)
> |
> |library(Rcpp)
> |Sys.setenv("PKG_LIBS"="-LC:\\cygwin\\lib\\ -lboost_regex")
> |sourceCpp("credit.cpp", verbose = TRUE)
> |
> | Changing backslash to forward slash does not change anything.
> |
> | Everything was done with the svn version of Rcpp:
> |
> | > packageVersion("Rcpp")
> | [1] '0.10.2.5'
>
> Sorry that this is so frustrating, but this (IMNSHO) all just Windows...
>
> I would try two things:
>
>   a) forward slashes (no escaping needed)
>
>   b) use verbose=TRUE so that you see the R CMD ... invocation.
>
> Your initial boost test was key.  We know you have a working boost library;
> we know Rcpp can create working code, now we just need to tie'em together.
>

I had tried both these. It does not seem to be picking up the
PKG_LIBS.  There is no -l... or -L... on the g++ cmd line.

Its also not clear precisely which boost distribution to use.  I had
tried http://nuwen.net/mingw.html (version 8.0) and also tried the
boost library from Cygwin.

If I use the MinGW from nuewn and run this from the Windows cnd line I
get no errors or warnings (note that ^ must be the last character on
the line to escape the newline):

C:\MinGW\set_distro_paths.bat
g++ -DNDEBUG ^
 -L %userprofile%/Documents/R/win-library/2.15/Rcpp/lib/x64/libRcpp.a ^
 -lboost_regex ^
 -I"C:/PROGRA~1/R/R-2.15/include" ^
 -I%userprofile%/Documents/R/win-library/2.15/Rcpp/include ^
 -O2 -Wall -mtune=core2 -c credit.cpp -o credit.o

If tyhat is ok then what would the next step be?

--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] Regular Expressions

2013-03-02 Thread Gabor Grothendieck
On Sat, Mar 2, 2013 at 10:17 AM, Dirk Eddelbuettel  wrote:
>
> On 1 March 2013 at 23:03, Gabor Grothendieck wrote:
> | On Fri, Mar 1, 2013 at 9:50 PM, Dirk Eddelbuettel  wrote:
> | >
> | > On 1 March 2013 at 21:24, Hadley Wickham wrote:
> | > | > | I searched BH for regex and found nothing so I don't think BH 
> includes
> | > | > | Boost.Regex.
> | > | >
> | > | > Could you register an issue ticket at the r-forge page for BH, 
> please?  There
> | > | > are other things missing too, of course, as we started pretty with 
> the needs
> | > | > of "just" bigmemory and RcppBDT.
> | > |
> | > | But Boost.Regex isn't header only?
> | >
> | > Yup. Found that out the hard way when I wrote it up as a piece for the 
> Rcpp
> | > Gallery. You do need to link.
> | >
> | > Piece now up at 
> http://gallery.rcpp.org/articles/boost-regular-expressions/
> | >
> |
> | I have downloaded boost such that I have this file:
> |
> | C:\MinGW\lib\libboost_regex.a
> |
> | How do I tell Rcpp to use it?
>
> Follow eg the Rcpp Gallery story and use
>
> Sys.setenv("PKG_LIBS"="C:\MinGW\lib\libboost_regex.a")
>
> as static library can be given "as is".  Else try
>
> Sys.setenv("PKG_LIBS"="-LC:\MinGW\lib\ -lboost_regex")
>
> which is the standard form.  That should work with the example I posted.
>
> If everthing else, try the documentation for Rcpp (Rcpp-package vignette in
> particular) or Boost.
>

Thanks. I doubled each backslash but unfortunately neither work.

I am able to build the original credit_card_example from the boost
site independently of Rcpp, i.e. this builds and I can run the result:

   rem this works
   C:\MinGW\set_distor_paths.bat
   g++ credit_card_example.cpp -o credit_card_example.exe -lboost_regex

and can also build C++ scripts not using boost; however,

all of the following give:
credit.cpp:6:27: fatal error: boost/regex.hpp: No such file or directory

   library(Rcpp)
   Sys.setenv("PKG_LIBS"="C:\\MinGW\\lib\\libboost_regex.a")
   sourceCpp("credit.cpp", verbose = TRUE)

   library(Rcpp)
   Sys.setenv("PKG_LIBS"="-LC:\\MinGW\\lib\\ -lboost_regex")
   sourceCpp("credit.cpp", verbose = TRUE)

   library(Rcpp)
   Sys.setenv("PKG_LIBS"="-lboost_regex")
   sourceCpp("credit.cpp", verbose = TRUE)

I also tried with Cygwin.  I have this file among others:
C:\cygwin\lib\libboost_regex-mt.dll.a

and tried these but they give the same result:

   library(Rcpp)
   Sys.setenv("PKG_LIBS"="C:\\cygwin\\lib\\libboost_regex-mt.dll.a")
   sourceCpp("credit.cpp", verbose = TRUE)

   library(Rcpp)
   Sys.setenv("PKG_LIBS"="-LC:\\cygwin\\lib\\ -lboost_regex")
   sourceCpp("credit.cpp", verbose = TRUE)

Changing backslash to forward slash does not change anything.

Everything was done with the svn version of Rcpp:

> packageVersion("Rcpp")
[1] '0.10.2.5'
___
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] Regular Expressions

2013-03-01 Thread Gabor Grothendieck
On Fri, Mar 1, 2013 at 9:50 PM, Dirk Eddelbuettel  wrote:
>
> On 1 March 2013 at 21:24, Hadley Wickham wrote:
> | > | I searched BH for regex and found nothing so I don't think BH includes
> | > | Boost.Regex.
> | >
> | > Could you register an issue ticket at the r-forge page for BH, please?  
> There
> | > are other things missing too, of course, as we started pretty with the 
> needs
> | > of "just" bigmemory and RcppBDT.
> |
> | But Boost.Regex isn't header only?
>
> Yup. Found that out the hard way when I wrote it up as a piece for the Rcpp
> Gallery. You do need to link.
>
> Piece now up at http://gallery.rcpp.org/articles/boost-regular-expressions/
>

I have downloaded boost such that I have this file:

C:\MinGW\lib\libboost_regex.a

How do I tell Rcpp to use it?


--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] Regular Expressions

2013-03-01 Thread Gabor Grothendieck
On Fri, Mar 1, 2013 at 7:55 PM, Dirk Eddelbuettel  wrote:
>
> On 1 March 2013 at 19:41, Gabor Grothendieck wrote:
> | Are there any packages that use Rcpp that use regular expressions?
>
> Great question. And not that I know of!
>
> Now that we have the BH package (for really easy access to Boost by using
> Boost headers via this CRAN package) I was thinking about a use case for
> Boost regex and file reading, but haven't had time to do anything about it.
>
> Other than Boost, we could possibly get access to the regexp libraries
> already linked into R.  What use case did you have in mind?
>

I searched BH for regex and found nothing so I don't think BH includes
Boost.Regex.  Ideally that would be accessible as well as the tre,
pcre (and Henry Spencer routines via Tcl) that R itself uses.

-- 
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] Regular Expressions

2013-03-01 Thread Gabor Grothendieck
Are there any packages that use Rcpp that use regular expressions?

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] Integrate xts_API for C with Rcpp

2013-01-11 Thread Gabor Grothendieck
On Fri, Jan 11, 2013 at 10:36 AM, Dirk Eddelbuettel  wrote:
>
> Howdy,
>
> Thanks for bringing questions to the list, much appreciated!
>
> On 11 January 2013 at 23:10, Wu Wush wrote:
> | Dear Dirk,
> |
> | I have seen your post in http://stackoverflow.com/questions/14274055/
> | how-to-use-c-api-of-xts-package-in-rcpp .
> |
> | What should we do to generalize the include flag settings?
>
> It's pretty early still here in Chicago and I'm at work so that has not seen
> full attention -- but I already pestered Jeff over IM on this.  I may just
> create a little RcppXts package that provides the inline plugin so that just
> via sourceCpp() becomes a breeze too.  Give me a few days.
>
> What we really need then is to lean on Jeff to export more of an API. And
> that is a bit of an issue as code is moving from xts to zoo etc pp at a
> glacial pace.  Gabor, Achim and he have been at this for years now.
>
> Not all wheels turn at Rcpp speed ;-)   [ That is *sure* to get Jeff's blood
> boiling to make maybe we will get an API ;-) ]
>
> Exactly what type of access / use did you have in mind from C / C++?
>

Just to be fair it should be pointed out that C/C++ is not the only
priority of the project.  Also there have been more user contributions
to the zoo project recently with Trevor Davis' ggplot2 interface to
zoo -- subsequently further enhanced by Achim and I.  This was an
important milestone achieved just a month ago as zoo finally has
interfaces to all three graphics systems (classic, lattice, ggplot2).
Additional contributions and unreleased code exist as well so
improvements continue..
___
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 advocacy question -- build environment

2012-12-09 Thread Gabor Grothendieck
On Tue, Nov 27, 2012 at 2:24 AM, Christian Gunning  wrote:
> Advice for introducing students to Rcpp:
>
> I'm TAing for a statistical programming class next semester, and I'm
> talking to the instructor about including Rcpp examples -- sourceCpp()
> makes this very easy to sell!
>
> The question is build environment for folks with windows machines.
> Personally, I think it's a worthwhile experience installing linux in a
> VM and gaining the experience of working with a *nix machine (as I've
> said before here).  Boot-from-usb is a similar option I've seen
> successfully used for quick-and-easy Rinside build environment.
> Personally, I'm confident in troubleshooting any problems that might
> arise in these environments.
>
> I have little experience with Rtools and I stopped following windows
> years ago, so I'm a little worried about helping other folks with
> build issues here.  Is it worth the trouble to push for a *nix build
> environment, or is configuring R + Rcpp + Windows X now smooth enough
> that I should relax and not worry?
>

Rgui.bat, R.bat and Rcmd.bat in the batchfiles distribution
automatically locate R, Rtools and temporarily set all environment
variables and modify your path appropriately each time you call R so
the whole process is just install R, install Rtools, place Rgui.bat,
R.bat and Rcmd.bat anywhere on your path (or some subset of them if
you don't use them all)  The Windows PATH command will give you a list
of the directories you can use for putting these batch files in.  You
won't need to set any environment variables, you won;t need to change
your PATH, you won't need to reboot, etc.  These do require that you
let the R and Rtools installers set the appropriate registry values
since they get their info from there although there are workarounds if
you want a portable install from a USB.

--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] A beginners guide to Rcpp

2012-11-30 Thread Gabor Grothendieck
On Fri, Nov 30, 2012 at 1:34 AM, Walter Mascarenhas
 wrote:
> listening to criticism is a good way to keep a balanced view of things.

Just to be clear I don't regard my comments as criticism of Rcpp. I
was commenting on the document for which comments had been solicited.
Rcpp is much more general than .C and is a completely different thing.
 Its really an amazing effort. I was only reacting to the statement
that the alternative to it is painful and just wanted to point out
that this was blurring the distinction between .C and actually having
to wrestle with SEXPs.   If the alternative is to work with SEXPs
directly then the alternative certainly is painful but if the
alternative is to use .C (and that may not be a feasible alternative
in some or many cases due to its restricted applicability) its not
painful at all.
___
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 beginners guide to Rcpp

2012-11-29 Thread Gabor Grothendieck
On Thu, Nov 29, 2012 at 10:37 AM, Hadley Wickham  wrote:
>> Nice document but it would be good to distinguish between the C
>> interfaces -- the .C interface may not be fully general; however, it
>> is adequate for a lot of numerical work such as writing the objective
>> function and gradient in optimization routines and is not painful at
>> all.
>
> I guess my argument would be that if you know Rcpp, you don't need to
> know the C interface. If you know the C interface, you're still better
> off learning Rcpp if you want to tackle anything more complicated.
>
> i.e. if you only have the time to learn one of Rcpp, .C, or .Call,
> you're better off learning Rcpp.
>  That's not to say .C or .Call are not useful to know, but they're
> probably not that useful to learn unless you already known how to
> program in C.  If you don't know how to program in C++, it's still
> worthwhile to learn Rcpp.

That is only the case if you don't know C or C++ .  Many people who
are using these interfaces already know C and in that case the  .C
interface is trivial (its just a simple interface) whereas Rcpp is a
new environment you have to learn to program in.

The trivial amount of time to learn .C for anyone who knows C is
hardly comparable to the effort to learn a new environment even if
that environment is a nice one.

--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] A beginners guide to Rcpp

2012-11-29 Thread Gabor Grothendieck
On Thu, Nov 29, 2012 at 8:34 AM, Hadley Wickham  wrote:
>> I've printed this out and will sit down with it sometime in the next week.
>> One (personal opinion) edit -- the following:
>>
>> " It is possible to write high performance code in C or Fortran. This
>> might produce faster code than C++ (but probably not), but it will
>> take you much much longer to write. Without Rcpp, you must sacrifice
>> many helpful wrappers and master the complex C internals of R
>> yourself. Rcpp is currently the best balance between speed and
>> convenience, and any other approach will be much more painful."
>>
>> should read more like:
>>
>> " It is possible but painful to write C or Fortran code for use by R.
>> Rcpp greatly simplifies this process without sacrificing speed or
>> low-level control."
>
> Thanks Christian.  I didn't really like those sentences either.  I've
> changed them to:
>
> It is _possible_ to write C or Fortran code for use in R, but it will
> be painful; Rcpp provides a clean, approachable API that lets you
> write high-performance code, insulated from R's arcane C API.
>

Nice document but it would be good to distinguish between the C
interfaces -- the .C interface may not be fully general; however, it
is adequate for a lot of numerical work such as writing the objective
function and gradient in optimization routines and is not painful at
all.

--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] RcppArmadillo -- crude benchmark of various mcmcvs rcppbugs

2012-04-27 Thread Gabor Grothendieck
On Fri, Apr 27, 2012 at 11:26 AM, Smith, Dale  wrote:
> As the MCMCpack and rcppbugs packages were built on Linux, I can't install 
> them on my Windows box. I'll have to get the sources and try to make them 
> when I have time.
>

On Windows my experience has been that WinBUGS runs faster than jags
so you might want to add that to your Windows benchmark.  (Top of my
head estimate is that WinBUGS is about twice as fast as jags.)

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] Checking for a promise

2010-12-30 Thread Gabor Grothendieck
On Wed, Dec 29, 2010 at 12:51 PM, Romain Francois
 wrote:
> Le 25/12/10 02:10, Gabor Grothendieck a écrit :
>>
>> How do I fix this so it works?  The code is intended to return TRUE or
>> FALSE according to whether the variable with name nm in environment
>> env is a promise or not.  In the example code below it returns FALSE
>> but I would like it to return TRUE.  Is the promise being forced
>> somewhere along the way?  Some other problem?
>>
>> library(Rcpp)
>> f<- cxxfunction(signature(env="environment", nm = "character"),
>>         body=' Environment e(env);
>>            std::string s = as(nm);
>>            return wrap(TYPEOF (e[s]) == PROMSXP); ',
>>         plugin="Rcpp")
>>
>> # create promise
>> delayedAssign("prom", 3)
>>
>> # want it to return TRUE but it returns FALSE
>> f(.GlobalEnv, "prom")
>
> Hello,
>
> Sorry for jumping late in this thread, xmas oblige.
>
> Environment::operator[] eventually calls Environment::get() which is
> implemented (in Environment.cpp) as follows:
>
>    SEXP Environment::get( const std::string& name) const {
>        SEXP res = Rf_findVarInFrame( m_sexp, Rf_install(name.c_str())  ) ;
>
>        if( res == R_UnboundValue ) return R_NilValue ;
>
>        /* We need to evaluate if it is a promise */
>        if( TYPEOF(res) == PROMSXP){
>                res = Rf_eval( res, m_sexp ) ;
>        }
>        return res ;
>    }
>
> So the promise is explicitely forced.
>
>
> We could augment the interface of Environment so that it adds something that
> would not force the promise. Perhaps adding ', bool force = false' to get
> and find.
>
> We could also add a ctor to Rcpp::Promise that would grab a promise from an
> environment, something like:
>
> Promise::Promise( const Environment& env, std::string& name){
>        SEXP res = Rf_findVarInFrame( m_sexp, Rf_install(name.c_str())  ) ;
>        if( TYPEOF(res) != PROMSXP){ be unhappy ; }
>        setSEXP( res ) ;
> }
>
> Promises is a beast I rarely use, so the interface is still in a "to be
> improved" state. Suggestions are much welcome, for example pseudo code
> chunks of the sort of things one would do with them.
>

Thanks. Note that in a subsequent post I did list the sorts of
operations that would be nice and also did provide some working code
-- that code was just intended to show how to check for promises
without forcing them and seemed to show that one must descend to a
lower level to do this.  (That code was not intended to address the
question of what is a desirable interface.)  R-Forge, hence the
rcpp-devel archives, seem to be down right now but you can find this
post here:

http://www.mail-archive.com/rcpp-devel@lists.r-forge.r-project.org/msg01287.html


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] Checking for a promise

2010-12-26 Thread Gabor Grothendieck
On Sun, Dec 26, 2010 at 1:55 PM, Dirk Eddelbuettel  wrote:
>
> On 26 December 2010 at 13:36, Gabor Grothendieck wrote:
> | On Sun, Dec 26, 2010 at 12:07 PM, Dirk Eddelbuettel  wrote:
> | >
> | > On 25 December 2010 at 17:22, Gabor Grothendieck wrote:
> | > | It seems that there are no facilities for this in Rcpp -- at least I
> | > | haven't found them.  It seems one has to go one level lower to do
> | >
> | > Patches are always welcome, particularly if they come with use cases
> | > motivating them ("Does it make things easier? Or faster? Or at least make
> | > them possible?")  as well as unit tests and documentation.
> | >
> | > | this.  The code below works.  It passes an environment and name and
> | > | returns the type code.  I think this sort of functionality was
> | > | intentionally left out of R itself and if one were just trying to
> | > | emulate R then I can understand it not being there but since Rcpp is
> | > | intended for performance it might be a good idea to give this sort of
> | > | access to promises without forcing the program to use the lower level
> | > | facilities.
> | >
> | > Well, why?  I do not use delayedAssign() all that much in R; I haven't 
> needed
> |
> | I did address this already in the paragraph you quote but in case it
> | wasn't clear its to make the code run faster.  Promises that are not
> | used never need be evaluated saving the time that such evaluation
> | would have otherwise taken.
>
> Why would I pass an expression I never expect to be evaluated?
>

Because you don't know ahead of time whether it will be used or not.
Here is an example that one can speed up by a factor of 500x by using
R instead of Rcpp. I guess you could say its .Call's fault but the
fact remains that R will be much faster than Rcpp whenever this comes
into play.

> library(Rcpp)
> library(inline)
> library(rbenchmark)
>
> f1 <- function(which, x, y) if (which == 1) x else y
> f2 <- cxxfunction(sig = c(which = "numeric", x = "SEXP", y = "SEXP"),
+ body = '
+ SEXP z;
+ int w = as(which);
+ if (w == 1) z = x; else z = y; return z;
+ ', plugin = "Rcpp")
>
> benchmark(replications = 1000,
+ R = f1(1, 10, rnorm(1)),
+ Rcpp = f2(1, 10, rnorm(1))
+ )
  test replications elapsed relative user.self sys.self user.child sys.child
1R 10000.011  0.010 NANA
2 Rcpp 10004.82  482  4.790 NANA


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] Checking for a promise

2010-12-26 Thread Gabor Grothendieck
On Sun, Dec 26, 2010 at 12:07 PM, Dirk Eddelbuettel  wrote:
>
> On 25 December 2010 at 17:22, Gabor Grothendieck wrote:
> | It seems that there are no facilities for this in Rcpp -- at least I
> | haven't found them.  It seems one has to go one level lower to do
>
> Patches are always welcome, particularly if they come with use cases
> motivating them ("Does it make things easier? Or faster? Or at least make
> them possible?")  as well as unit tests and documentation.
>
> | this.  The code below works.  It passes an environment and name and
> | returns the type code.  I think this sort of functionality was
> | intentionally left out of R itself and if one were just trying to
> | emulate R then I can understand it not being there but since Rcpp is
> | intended for performance it might be a good idea to give this sort of
> | access to promises without forcing the program to use the lower level
> | facilities.
>
> Well, why?  I do not use delayedAssign() all that much in R; I haven't needed

I did address this already in the paragraph you quote but in case it
wasn't clear its to make the code run faster.  Promises that are not
used never need be evaluated saving the time that such evaluation
would have otherwise taken.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] Checking for a promise

2010-12-25 Thread Gabor Grothendieck
On Sat, Dec 25, 2010 at 5:02 PM, Dominick Samperi  wrote:
>
>
> On Sat, Dec 25, 2010 at 4:08 PM, Gabor Grothendieck
>  wrote:
>>
>> On Sat, Dec 25, 2010 at 3:58 PM, Dominick Samperi 
>> wrote:
>> > Using .Call appears to force the promise:
>> >
>> > msg="old"
>> > delayedAssign("x",msg)
>> > msg="new"
>> > .Call('sexpType',x) # promise triggered here, returns 16
>> > msg="even newer" # will not change already fired promise
>> > .Call('sexpType',x) # returns 16
>> > y = x
>> > y # "new" (not "even newer")
>> >
>> > Here's sexpType:
>> >
>> > RcppExport SEXP sexpType(SEXP x_) {
>> >     return Rcpp::wrap(TYPEOF(x_));
>> > }
>> >
>> > The type returned is 16 here (STRSXP). If numbers were
>> > assigned to msg instead 14 would be returned (REALSXP).
>> >
>>
>> Note that the first attempt I posted tried to get around that by
>> passing the environment and the name of the variable in the
>> environment so that the object would not itself be passed yet it did
>> not work either.  Here is a slight variation:
>
> Yes, I tired your variant (just passing the environment) but it
> still doesn't work. Here is the explanation: Rcpp currently
> implements e[] (i.e., operator [] for Environment) via get(),
> and when the variable is a promise it evaluates, effectively
> forcing the promise. There is a Rcpp::Promise class, but it is
> probably work in progress because it is not exposed.
>
>>
>> > library(Rcpp)
>> > library(inline)
>> > f <- cxxfunction(signature(env="environment", nm = "character"),
>> +        body=' Environment e(env);
>> +           std::string s = as(nm);
>> +           return wrap(TYPEOF (e[s])); ',
>> +        plugin="Rcpp")
>> >
>> > # create promise
>> > delayedAssign("prom", 3)
>> >
>> > # want it to return 5 but it returns 14
>> > f(.GlobalEnv, "prom")
>> [1] 14

It seems that there are no facilities for this in Rcpp -- at least I
haven't found them.  It seems one has to go one level lower to do
this.  The code below works.  It passes an environment and name and
returns the type code.  I think this sort of functionality was
intentionally left out of R itself and if one were just trying to
emulate R then I can understand it not being there but since Rcpp is
intended for performance it might be a good idea to give this sort of
access to promises without forcing the program to use the lower level
facilities.

The main functions that would be nice would be:
- to determine if an object is a promise
- to extract, set and replace its components (i.e. the expression and
the environment).
- also the ability to copy a promise from one environment to another
without forcing it

library(Rcpp)
library(inline)
f <- cxxfunction(signature(env="environment", nm = "character"),
   body=' Environment e(env);
  std::string s = as(nm);
  SEXP res = Rf_findVarInFrame( e, Rf_install(s.c_str())  ) ;
  if( res == R_UnboundValue ) return R_NilValue ;
  return wrap(TYPEOF (res)); ',
   plugin="Rcpp")

# create promise
delayedAssign("prom", 3)

# returns 5 which is the code for a promise
f(.GlobalEnv, "prom")

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] Checking for a promise

2010-12-25 Thread Gabor Grothendieck
On Sat, Dec 25, 2010 at 3:58 PM, Dominick Samperi  wrote:
> Using .Call appears to force the promise:
>
> msg="old"
> delayedAssign("x",msg)
> msg="new"
> .Call('sexpType',x) # promise triggered here, returns 16
> msg="even newer" # will not change already fired promise
> .Call('sexpType',x) # returns 16
> y = x
> y # "new" (not "even newer")
>
> Here's sexpType:
>
> RcppExport SEXP sexpType(SEXP x_) {
>     return Rcpp::wrap(TYPEOF(x_));
> }
>
> The type returned is 16 here (STRSXP). If numbers were
> assigned to msg instead 14 would be returned (REALSXP).
>

Note that the first attempt I posted tried to get around that by
passing the environment and the name of the variable in the
environment so that the object would not itself be passed yet it did
not work either.  Here is a slight variation:

> library(Rcpp)
> library(inline)
> f <- cxxfunction(signature(env="environment", nm = "character"),
+body=' Environment e(env);
+   std::string s = as(nm);
+   return wrap(TYPEOF (e[s])); ',
+plugin="Rcpp")
>
> # create promise
> delayedAssign("prom", 3)
>
> # want it to return 5 but it returns 14
> f(.GlobalEnv, "prom")
[1] 14



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] Checking for a promise

2010-12-24 Thread Gabor Grothendieck
On Fri, Dec 24, 2010 at 8:10 PM, Gabor Grothendieck
 wrote:
> How do I fix this so it works?  The code is intended to return TRUE or
> FALSE according to whether the variable with name nm in environment
> env is a promise or not.  In the example code below it returns FALSE
> but I would like it to return TRUE.  Is the promise being forced
> somewhere along the way?  Some other problem?
>
> library(Rcpp)
> f <- cxxfunction(signature(env="environment", nm = "character"),
>        body=' Environment e(env);
>           std::string s = as(nm);
>           return wrap(TYPEOF (e[s]) == PROMSXP); ',
>        plugin="Rcpp")
>
> # create promise
> delayedAssign("prom", 3)
>
> # want it to return TRUE but it returns FALSE
> f(.GlobalEnv, "prom")

Or perhaps this is closer but it still does not work as intended:

library(Rcpp)
library(inline)
f <- cxxfunction(signature(s="SEXP"),
   body=' return wrap(TYPEOF(s));',
   plugin="Rcpp")

f(f) # 3
# note that promises are type 5 but we get:
delayedAssign("prom", 3)
f(prom) # 14


-- 
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] Checking for a promise

2010-12-24 Thread Gabor Grothendieck
How do I fix this so it works?  The code is intended to return TRUE or
FALSE according to whether the variable with name nm in environment
env is a promise or not.  In the example code below it returns FALSE
but I would like it to return TRUE.  Is the promise being forced
somewhere along the way?  Some other problem?

library(Rcpp)
f <- cxxfunction(signature(env="environment", nm = "character"),
body=' Environment e(env);
   std::string s = as(nm);
   return wrap(TYPEOF (e[s]) == PROMSXP); ',
plugin="Rcpp")

# create promise
delayedAssign("prom", 3)

# want it to return TRUE but it returns FALSE
f(.GlobalEnv, "prom")


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] sugar performance

2010-12-22 Thread Gabor Grothendieck
On Wed, Dec 22, 2010 at 6:33 AM,   wrote:
> Also, I'm trying to write the looping internally in order to get a better 
> comparison. With the attached file, I get:

The attachment does not seem to have made it through.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] Rcpp:integer class?

2010-12-21 Thread Gabor Grothendieck
On Tue, Dec 21, 2010 at 12:23 PM, Cedric Ginestet
 wrote:
> Dear Rcpp experts,
>
> I am trying to find a way a single integer to a function. See the code
> below. I am here obliged to translage v1 as an IntegerVector and then to
> select only its first argument. Is there a better way of doing this, where I
> don't have to declare an entire vector for such a task?
>
> ###
> src2 <- '
>   IntegerVector x1(v1);
>   IntegerMatrix xD(D);
>   IntegerVector Drow(xD.ncol());
>   for(int i=0; i return Drow;
> '
> rowExtraction <-
> cxxfunction(signature(D="matrix",v1="integer"),body=src2,plugin="Rcpp",verbose=TRUE)
> rowExtraction(D,1)
> 
>

Try this:

src2 <- '
  int x1 = as(v1);
  IntegerMatrix xD(D);
  IntegerVector Drow(xD.ncol());
  for(int i=0; ihttps://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


[Rcpp-devel] Got error when trying to run example in Intro vignette

2010-12-21 Thread Gabor Grothendieck
I tried copying the example in the intro vignette
   http://dirk.eddelbuettel.com/code/rcpp/Rcpp-introduction.pdf
and get the following error. What's wrong?

> library(inline)
> library(Rcpp)
> funIntro <- cxxfunction(signature(a = "numeric", b = "numeric"), body = '
+ RcppExport SEXP convolve3cpp(SEXP a, SEXP b) {
+ Rcpp::NumericVector xa(a);
+ Rcpp::NumericVector xb(b);
+ int n_xa = xa.size(), n_xb = xb.size();
+ int nab = n_xa + n_xb - 1;
+ Rcpp::NumericVector xab(nab);
+ for (int i = 0; i < n_xa; i++)
+ for (int j = 0; j < n_xb; j++)
+ xab[i + j] += xa[i] * xb[j];
+ return xab;
+ }', plugin="Rcpp")
file303dbfd.cpp: In function 'SEXPREC* file303dbfd(SEXPREC*, SEXPREC*)':
file303dbfd.cpp:31:1: error: expected unqualified-id before string constant
make: *** [file303dbfd.o] Error 1

ERROR(s) during compilation: source code errors or compiler
configuration errors!

Program source:
  1:
  2: // includes from the plugin
  3:
  4: #include 
  5:
  6:
  7: #ifndef BEGIN_RCPP
  8: #define BEGIN_RCPP
  9: #endif
 10:
 11: #ifndef END_RCPP
 12: #define END_RCPP
 13: #endif
 14:
 15: using namespace Rcpp;
 16:
 17:
 18: // user includes
 19:
 20:
 21: // declarations
 22: extern "C" {
 23: SEXP file303dbfd( SEXP a, SEXP b) ;
 24: }
 25:
 26: // definition
 27:
 28: SEXP file303dbfd( SEXP a, SEXP b ){
 29: BEGIN_RCPP
 30:
 31: RcppExport SEXP convolve3cpp(SEXP a, SEXP b) {
 32: Rcpp::NumericVector xa(a);
 33: Rcpp::NumericVector xb(b);
 34: int n_xa = xa.size(), n_xb = xb.size();
 35: int nab = n_xa + n_xb - 1;
 36: Rcpp::NumericVector xab(nab);
 37: for (int i = 0; i < n_xa; i++)
 38: for (int j = 0; j < n_xb; j++)
 39: xab[i + j] += xa[i] * xb[j];
 40: return xab;
 41: }
 42: END_RCPP
 43: }
 44:
 45:
Error in compileCode(f, code, language = language, verbose = verbose) :
  Compilation ERROR, function(s)/method(s) not created!
file303dbfd.cpp: In function 'SEXPREC* file303dbfd(SEXPREC*,
SEXPREC*)':
file303dbfd.cpp:31:1: error: expected unqualified-id before string constant
make: *** [file303dbfd.o] Error 1
In addition: Warning message:
running command 'C:\PROGRA~1\R\R-212~1.X/bin/i386/R CMD SHLIB
file303dbfd.cpp 2> file303dbfd.cpp.err.txt' had status 1
>


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] Rcpp speed

2010-12-21 Thread Gabor Grothendieck
On Tue, Dec 21, 2010 at 10:31 AM,   wrote:
> Hello,
>
> I think the most relevant aspect of the time difference is coercion:
>
>> x <- 1:10
>> typeof(x)
> [1] "integer"
>
> So, the constructor of NumericVector has to make a coercion, this is what 
> costs time. As the vector get bigger, the time to coerce them to numeric 
> vectors gets bigger.
>
> The differences are much less dramatic once you do one of these:
> - coerce x to a REALSXP before you get started
> - operate on INTSXP
>
>
> With this code:
>
>
> require(Rcpp)
> require(inline)
> code <- '
> NumericVector xx(x);
> NumericVector yy(y);
> NumericVector zz = xx + yy;
> return( zz );
> '
> testfun_Rcpp <- cxxfunction(signature(x="numeric", y="numeric"),
>    body = code, plugin="Rcpp")
> testfun_R  <- function(x,y) x+y
>
> x <- 1:3
> y <- 10 * x
> testfun_Rcpp(x, y)
>
> library(rbenchmark)
> x <- as.numeric(1:10)
> benchmark(replications = 1,
>    R = testfun_R(x,x),
>    Rcpp = testfun_Rcpp(x, x)
>    )
>
> x <- as.numeric(1:1000)
> benchmark(replications = 1,
>    R = testfun_R(x,x),
>    Rcpp = testfun_Rcpp(x, x)
> )
>
> x <- as.numeric(1:100)
> benchmark(replications = 1,
>    R = testfun_R(x,x),
>    Rcpp = testfun_Rcpp(x, x)
> )
>
>
> I get these results:
>
>  test replications elapsed relative user.self sys.self user.child sys.child
> 1    R        1   0.050     1.00     0.049    0.001          0         0
> 2 Rcpp        1   0.067     1.34     0.065    0.002          0         0
>  test replications elapsed relative user.self sys.self user.child sys.child
> 1    R        1   0.087 1.00     0.083    0.004          0         0
> 2 Rcpp        1   0.145 1.67     0.145    0.000          0         0
>  test replications elapsed relative user.self sys.self user.child sys.child
> 1    R        1  49.189 1.00    35.405   13.776          0         0
> 2 Rcpp        1 100.849 2.050235    87.029   13.814          0         0
>
>
> However, it is still true that the bigger x is, the bigger the ratio Rcpp / R 
> gets. Not sure why. Sounds like a nice xmas activity.
>
> It might be worth looping internally for the benchmark to dilute some of the 
> confusion factor that might be related to inline/rbenchmark.
>

Thanks. That and Dirk's last post do seem to explain a large part of
the difference.

I agree it would still be a good idea to try to understand why the
ratio increases even when we eliminate the coercion and if there is
anything that can be done about it.

I am sure my benchmark is a bit lame although it did bring out some
issues nevertheless.  It would be a good idea to generate some
benchmarks USING SUGAR to see what kind of speed ups can be achieved.
Since there is a degree of effort in getting into all this I sure
would like to see benchmarks that show it will likely pay off in
improved performance before spending too much time on this.

P.S. In Dirk's post we don't need the L's in the seq expressions since
m:n is integer anyways in those cases; however, in y <- 10 * x we do
need 10L.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] Rcpp speed

2010-12-21 Thread Gabor Grothendieck
On Tue, Dec 21, 2010 at 9:39 AM, Dirk Eddelbuettel  wrote:
>
> On 21 December 2010 at 09:15, Gabor Grothendieck wrote:
> | Can anyone explain these results?   Rcpp takes 30% more time than R
> | with 10 elements, the same time as R with 1000 elements and 7x as long
> | with a million elements.  I would have expected the ratio to be
> | highest for `10 elements since that would be dominated by the call
> | sequence but its the other way around and it seems to get relatively
> | less efficient as the size of the vector grows.
>
> Errr, these are _single expressions in the R parser_ !  So how could they be
> faster in Rcpp when we have to do the extra marshalling of objects on the
> heap, NA tests, exception handlings, etc pp ?  Did you seriously thing there
> could be a gain?
>
> If you have a real task, time that.
>
> Do you recall the issue started by Radford Neal about curly or straight
> paranthese?  When Christian Robert followed up and that whole thing became a
> little blogging storm, I wrote an ad-hoc post ... demonstrating an 80-fold
> speed increase with Rcpp.  That was in September, and be we may well have got
> faster since as a number of tweaks went into Rcpp.
>
> In any event, the aforementioned blog post is
>
> http://dirk.eddelbuettel.com/blog/2010/09/07#straight_curly_or_compiled
>
> Otherwise, thanks for being empirical and posting replicable code using
> inline and rbenchmark. That is the right idea. But I fear you started to
> measure the wrong question here.

My question was not why Rcpp was slower.
Also posted link does not use sugar.

My question was why the relative speed did not improve as the size
increased but instead got worse.  Does using sugar mean that it just
gets me back to the speed of R or worse?








-- 
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] Rcpp speed

2010-12-21 Thread Gabor Grothendieck
Can anyone explain these results?   Rcpp takes 30% more time than R
with 10 elements, the same time as R with 1000 elements and 7x as long
with a million elements.  I would have expected the ratio to be
highest for `10 elements since that would be dominated by the call
sequence but its the other way around and it seems to get relatively
less efficient as the size of the vector grows.

> require(inline)
> testfun <- cxxfunction(signature(x="numeric", y="numeric"),
+ body = '
+ NumericVector xx(x);
+ NumericVector yy(y);
+ NumericVector zz = xx + yy;
+ return( zz );
+ ', plugin="Rcpp")
> x <- 1:3
> y <- 10 * x
> testfun(x, y)
[1] 11 22 33
>
> library(rbenchmark)
> x <- 1:10
> benchmark(replications = 1, R = x + x, Rcpp = testfun(x, x))
  test replications elapsed relative user.self sys.self user.child sys.child
1R10.17 1.00  0.160 NANA
2 Rcpp10.22 1.294118  0.230 NANA
>
> x <- 1:1000
> benchmark(R = x + x, Rcpp = testfun(x, x))
  test replications elapsed relative user.self sys.self user.child sys.child
1R  1000.000  0.000 NANA
2 Rcpp  1000.011  0.010 NANA
>
> x <- 1:100
> benchmark(R = x + x, Rcpp = testfun(x, x))
  test replications elapsed relative user.self sys.self user.child sys.child
1R  1002.34 1.00  1.81 0.15 NANA
2 Rcpp  100   16.64 7.11 12.63 1.66 NANA


-- 
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] Packages using sugar

2010-12-20 Thread Gabor Grothendieck
Which R packages currently use sugar as described in:

http://dirk.eddelbuettel.com/code/rcpp/Rcpp-sugar.pdf


-- 
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