[Rcpp-devel] FW: Step-by-Step Plan to Code Writing and Testing withRcpp, RcppGSL or RcppArmadillo

Dirk Eddelbuettel edd at debian.org
Sat Dec 11 20:23:37 CET 2010


On 11 December 2010 at 10:47, Savitsky, Terrance wrote:
| Hi Dirk,  Thx for your patient coaching.  It seems the lighter approach
| in use of the RcppArmadillo templates is best for me to avoid the need
| to link to a library.  
| 
| That said, I'd appreciate your comments on:
| 
| 1. I compiled the RcppArmadillo version of lm from the script posting of
| June 9 from your blog using inline, just as you lay out.  This script
| uses RcppArmadillo (not Armadillo) and employs iterators.  This same

(There is also a variant of this inside the RcppArmadillo package.)

| script is used with your benchmark study included in the May, 2010
| presentation, "Seamless R and C++ Integration".   This is a wind-up to
| towards saying that a single iteration of this RcppArmadillo version
| took a little over 4 seconds for dim(X) = (10000,9) on my machine, a
| result suggesting I'm bypassing BLAS and LAPACK.  Yet, I assume that
| RcppArmadillo employs BLAS and LAPACK from Rcpp (that is mentioned in

Yes, because R does (or at least should do it most cases, it all depends on
your installation).

| the package building instructions for RcppArmadillo).  I ran the R lm
| function (under which I have replaced the standard R BLAS with Atlas)
| and it runs in 0.08 seconds on the same data.  (It bears mentioning that
| both functions produce the same results).  I'm running Windows XP (with
| Nehalem quad core processor) with version 0.2.10 of RcppArmadillo.  I'd
| appreciate your insight into what I've done wrong.

No, I do not have any insights.  We have posted numerous reproducible
benchmarks over the months, I suggest you look at those.  What you report
above smells fishy -- the four seconds probably involves starting of R or
loading a library or what have you.  
 
| 2. Vinh Nguyen posts a June 10 entry on Rcpp-devel where he notes his
| employment of inline to compile and link his RcppArmadillo based code.
| In that discussion, you point out to him that you have already
| recommended to build a package skeleton instead of using inline.  I've

Maybe. We now have very good inline support for RcppArmadillo. Maybe we
didn't have comparable support for it then.

| built a package using RcppArmadillo.package.skelton() as described in
| the November 26, 2010 document for v 0.2.10.  Basic question: how does
| this help me to build my RcppArmadillo-based C++ code?  Do you recommend
| to just use the R CMD SHLIB for building instead of inline for code
| debugging?  Then once the files are debugged, we would install the
| package to achieve the build? 

I am not entirely sure what your question is.

  - You can test / prototype code for Rcpp and RcppArmdillo using inline.

  - You can use the code generated from inline to boostrap you own package
    skeleton.

  - You can write your own package from scratch using what we documented.

It's up to you -- use whatever works best for you. 

Good luck,  Dirk
 
| Thanks very much for your time, Terrance 
| 
| -----Original Message-----
| From: Dirk Eddelbuettel [mailto:edd at debian.org] 
| Sent: Thursday, December 09, 2010 8:36 PM
| To: Savitsky, Terrance
| Cc: Dirk Eddelbuettel; rcpp-devel at r-forge.wu-wien.ac.at
| Subject: RE: [Rcpp-devel] Step-by-Step Plan to Code Writing and Testing
| withRcpp, RcppGSL or RcppArmadillo
| 
| 
| On 9 December 2010 at 19:48, Savitsky, Terrance wrote:
| | Hi again,  Thanks for your very helpful suggestions; you're right - I
| | need to just concentrate on Rcpp.  To that end, I followed the process
| | in the appendix of the R extensions manual, including your point point
| | to seek out and install Rtools from Murdoch-Sutherland.  I then tried
| a
| | simple inline example without any library reference it built and
| | executed fine.
| 
| Good -- it is an important milestone to be able to run of some of these.
| 
| |  When I attempted to compile the inline example that
| | includes the GSL library, it wasn't able to find any GSL header file
| | locations to make the build.  In particular, I received the following
| | error message:
| | 
| | fatal error: gsl/gsl_rng.h: No such file or directory
| 
| Yes -- these are old and less polished examples. In particular, note the
| lines
| 
|                       cppargs="-I/usr/include",
|                       libargs="-lgsl -lgslcblas")
| 
| which happen to work on Linux systems such as mine.  
| 
| At a minimum, you will need something like
| 
|                       cppargs="-IC:/gsl/include",
|                       libargs="-LC:/gsl/lib -lgsl -lgslcblas")
| 
| but also read on.
|  
| | When running firstExample() from RccpInlineWithLibsExamples.r.   Since
| | I'm able to build, link, execute with Rcpp when not using the GSL
| | library, I know this problem may not be appropriate for this forum,
| but
| | I'm hoping you may have some insight.  My installation of GSL comes
| via
| | cygwin and I've added the appropriate links (to C:\cygwin\bin and
| | C:\cygwin\usr) in the PATH environment variable, as well as creating
| two
| | additional environment variables, GSL_INC and GSL_LIB with the
| | appropriate path locations for the GSL include and library files.
| Yet,
| | nothing seems to work.  So I'd be very thankful if you have any ideas
| on
| | what I might next try.
| 
| As I alluded to yesterday, Cygwin != MinGW.  You may have to rebuild the
| GSL
| just to use it with MinGW and R.  That's how it is on Windows...
| 
| That problem is however not Rcpp-specific, so it might be best to seek
| help
| elsewhere.  In essence, you need to be to able to build a R package
| using the
| GSL on Windows.  Last we check (quite recently) that comprises a dozen
| packages: copula, dynamo, gsl, gstat, magnets, mvabund, QRMlib,
| RBrownie,
| RDieHarder, RHmm, segclust, surveillance, and topicmodels.  
| 
| Some of these have other Depends: and you don't want that -- more work
| just
| for testing.  Pick a simple one, and see if you can build it from
| source.
| 
| Lastly, if you just need linear algebra, RNGs, ... then Armadillo can
| help
| and RcppArmadillo gives it to you via Templates -- no libraries needed.
| 
| Dirk
| 
| 
| | 
| | -----Original Message-----
| | From: Dirk Eddelbuettel [mailto:edd at debian.org] 
| | Sent: Wednesday, December 08, 2010 8:42 PM
| | To: Savitsky, Terrance
| | Cc: Dirk Eddelbuettel; rcpp-devel at r-forge.wu-wien.ac.at
| | Subject: RE: [Rcpp-devel] Step-by-Step Plan to Code Writing and
| Testing
| | withRcpp, RcppGSL or RcppArmadillo
| | 
| | 
| | On 8 December 2010 at 20:05, Savitsky, Terrance wrote:
| | | Hello Dirk,  I sincerely apologize for how I started the dialogue.
| | May
| | | I have a do-over? 
| | 
| | Sure.
| | 
| | | I am an inexperienced developer.  So I'm looking
| | | forward to using Rcpp to improve my productivity and output quality
| | with
| | | writing C++ for R implementation.   I will re-read the documents and
| | | presentations you've publicly posted.
| | | 
| | | My interest in examples is focused towards imitation before
| | innovation.
| | 
| | We actually think along the same lines. What you dismissed earlier as
| | "marketing" is, seen from another angle, a fairly large set of working
| | examples. So let's focus on those.
| | 
| | For now, forget RcppArmadillo, RcppGSL, ... and concentrate on just
| | Rcpp.
| | There are numerous examples in the package itself -- see the examples/
| | subdirectory.  Let's get those to work first.
| | 
| | | I'll seek out archived examples for this, which will hopefully focus
| | my
| | | start-up efforts.  I do, however, have a couple of f/u questions:
| | | 
| | | To your point, "How could there not be debugging support with gdb if
| | g++
| | | is used?"  - Does R CMD use the g++ compiler?  Since my code is
| quite
| | 
| | Yes. It is essentially the only C++ compiler R uses by default. 
| | 
| | | long, I just want to find a way to efficiently debug.  I can't
| compile
| | | my Rcpp C++ code (with wrappers around R SEXP objects) outside of R,
| | so
| | 
| | Why? We do it all the time with Makefiles. See the examples/ mentioned
| | above.
| | 
| | | I'm looking for how to compile with debugging support in R.  I
| | typically
| | | write C code and compile and run (via cygwin gcc in Windows) with
| gdb.
| | 
| | Have you ever written any C/C++ code for R?  Do you know Cygwin is not
| | supported?
| | 
| | When I say 'Rtools' do you have a Pavlovian reflex to the
| | Murdock-Sutherland
| | site?  You better do ...  See 'Writing R Extensions' for starters.
| | 
| | In a nutshell you need a set of compilers etc just for R. Luckily
| these
| | have
| | been setup.
| | 
| | | It's not obvious to me how this process would work when writing Rcpp
| | C++
| | | code for compilation and implementation in R.
| | | 
| | | What IDE do Windows users typically choose for their Rcpp C++ code
| | | writing?  Is it any different from the IDE they would use for
| non-Rcpp
| | | standalone C/C++ code not interfaced with R?  
| | 
| | Well personally speaking I use the same IDE on all platforms: Emacs.
| | Within
| | the Rcpp Core team, some of us work on OS X and some work on Linux.
| But
| | it
| | should not matter: R and R add-ons like Rcpp work on Windows, OS X and
| | Linux.
| | Use whichever platform you find easiest.  Personally, I like Ubuntu
| and
| | Debian a lot.
| | 
| | Dirk
| |  
| |  
| | | 
| | | Terrance Savitsky
| | | 
| | | 
| | | 
| | | On 8 December 2010 at 17:44, Savitsky, Terrance wrote:
| | | | I?m having difficulty to find ?How-to? documentation;  the papers
| | and
| | | | presentations (including the RcppExamples package) are exciting,
| but
| | | focus on
| | | | marketing use, 
| | | 
| | | Nice way to start a dialogue with us by telling us we're idiots.
| Keep
| | | going.
| | | 
| | | | rather than providing instructions.   I?d appreciate any help to
| | | | get started to:
| | | |
| | | | 1.       Code C++ using the Rcpp, RcppGSL and RcppArmadillo
| | libraries.
| | | 
| | | 
| | | I don't know how many example we posted on blogs, this list and in
| | | presentations. Exactly which did not work?
| | | 
| | | 	
| | |  
| | | | a.       May I link my IDE (netbeans) to the lib.a files and use
| the
| | | | appropriate .h files for composing C++ code for compilation in R? 
| | | 
| | | Don't know, don't care.  Ex-ant this is for __R__ where the command
| is
| | | 'R CMD ...'
| | | and/or Makefiles.
| | | 
| | | If you need netbeans, you get to figure out netbeans. Exiciting to
| be
| | | trailblazer, eh?
| | | 
| | | | b.      Do RcppGSL and RcppArmadillo contain the Rcpp classes or
| | | should the
| | | | header files from both be included (e.g. #include Rcpp.h, #include
| | | | RcppArmadillo.h)
| | | 
| | | Have you looked at the examples. They work, and they provide the
| | anwwer.
| | |  
| | | | c.       The matrix and vector classes, including views, Rcpp
| | | implementation of
| | | | the C library GSL employs new C++ capabilities and different
| syntax
| | | (e.g.
| | | | extraction of pointers from matrix or vector view objects).  Is
| | there
| | | detailed
| | | | documentation with examples for these class implementations.  The
| | | differences
| | | | from GSL disable using that documentation.
| | | 
| | | I have no idea what you are trying to say here. You are mixing two
| | core
| | | APIs
| | | (Views in Rcpp only exist in the classic API) and two 'glued-on'
| | | libraries
| | | one of which is C --- so there are bound to differences.
| | | 
| | | | d.      Should RcppExport be used in place of ?extern C? in C++
| | under
| | | Rcpp
| | | | whenever we wish to input R data types such as matrix, vector and
| | list
| | | (due to
| | | | need to call .Call)?
| | | 
| | | Look at the definiton and decide for yourself. Using the define has
| | the
| | | advantage that should we ever change it ...
| | | 
| | | | 2.       Compile and debug code using Inline or other preferred
| | | alternatives.
| | | | 
| | | | a.       The illustrations in presentations seem to copy and paste
| | the
| | | entire
| | | | code from C++ in single quotes with an assignment to a variable
| | | subsequently
| | | | used with inline in R.  My code (a Bayesian MCMC implementation)
| | will
| | | be on the
| | | | order of 600 lines long with about 10 input variables.  Is there a
| | | better way
| | | | to use inline?
| | | 
| | | Up to you. Inline is for experimentation. We had a MCMC example on
| the
| | | list
| | | following Whit's question. Did you look at it?
| | | 
| | | | b.      Is there any help on code debugging?  (e.g. some
| equivalent
| | of
| | | ?gdb?).
| | | 
| | | How could there not be debugging support with gdb if g++ is used?
| | |  
| | | | 3.       Writing a package.
| | | 
| | | Seen the Vignette?
| | |  
| | | | a.       What is the ?LinkingTo? declaration ? what purpose does
| it
| | | serve and
| | | | where is it used? 
| | | | 
| | | | b.      Same for Makevars and Makevars.win?
| | | 
| | | See 'Writing R Extensions' 
| | | 
| | | Dirk
| | | 
| | | 
| | | | Thanks, Terrance Savitsky
| | | | 
| | | |  
| | | | 
| | | | 
| | | |
| | |
| |
| ________________________________________________________________________
| | | __
| | | | 
| | | | This email message is for the sole use of the intended
| recipient(s)
| | | and
| | | | may contain confidential information. Any unauthorized review,
| use,
| | | | disclosure or distribution is prohibited. If you are not the
| | intended
| | | | recipient, please contact the sender by reply email and destroy
| all
| | | copies
| | | | of the original message.
| | | | 
| | | |
| | ----------------------------------------------------------------------
| | | | _______________________________________________
| | | | Rcpp-devel mailing list
| | | | Rcpp-devel at lists.r-forge.r-project.org
| | | |
| | |
| |
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
| | | 
| | | -- 
| | | Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
| | 
| | -- 
| | Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
| | 
| |
| ________________________________________________________________________
| __
| | 
| | This email message is for the sole use of the intended recipient(s)
| and
| | may contain confidential information. Any unauthorized review, use,
| | disclosure or distribution is prohibited. If you are not the intended
| | recipient, please contact the sender by reply email and destroy all
| copies
| | of the original message.
| | 
| 
| -- 
| Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list