[Rcpp-devel] FW: Step-by-Step Plan to Code Writing and Testing withRcpp, RcppGSL or RcppArmadillo
savitsky at rand.org
Sat Dec 11 19:47:40 CET 2010
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
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
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.
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
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?
Thanks very much for your time, Terrance
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
| 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
which happen to work on Linux systems such as mine.
At a minimum, you will need something like
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,
| I'm hoping you may have some insight. My installation of GSL comes
| 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
| additional environment variables, GSL_INC and GSL_LIB with the
| appropriate path locations for the GSL include and library files.
| nothing seems to work. So I'd be very thankful if you have any ideas
| what I might next try.
As I alluded to yesterday, Cygwin != MinGW. You may have to rebuild the
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
elsewhere. In essence, you need to be to able to build a R package
GSL on Windows. Last we check (quite recently) that comprises a dozen
packages: copula, dynamo, gsl, gstat, magnets, mvabund, QRMlib,
RDieHarder, RHmm, segclust, surveillance, and topicmodels.
Some of these have other Depends: and you don't want that -- more work
for testing. Pick a simple one, and see if you can build it from
Lastly, if you just need linear algebra, RNGs, ... then Armadillo can
and RcppArmadillo gives it to you via Templates -- no libraries needed.
| -----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
| 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.
| | I have a do-over?
| | I am an inexperienced developer. So I'm looking
| | forward to using Rcpp to improve my productivity and output quality
| | 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
| 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
| 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
| | 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
| | is used?" - Does R CMD use the g++ compiler? Since my code is
| 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
| | my Rcpp C++ code (with wrappers around R SEXP objects) outside of R,
| Why? We do it all the time with Makefiles. See the examples/ mentioned
| | I'm looking for how to compile with debugging support in R. I
| | write C code and compile and run (via cygwin gcc in Windows) with
| Have you ever written any C/C++ code for R? Do you know Cygwin is not
| When I say 'Rtools' do you have a Pavlovian reflex to the
| site? You better do ... See 'Writing R Extensions' for starters.
| In a nutshell you need a set of compilers etc just for R. Luckily
| been setup.
| | It's not obvious to me how this process would work when writing Rcpp
| | 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
| | standalone C/C++ code not interfaced with R?
| Well personally speaking I use the same IDE on all platforms: Emacs.
| the Rcpp Core team, some of us work on OS X and some work on Linux.
| should not matter: R and R add-ons like Rcpp work on Windows, OS X and
| Use whichever platform you find easiest. Personally, I like Ubuntu
| Debian a lot.
| | Terrance Savitsky
| | On 8 December 2010 at 17:44, Savitsky, Terrance wrote:
| | | I?m having difficulty to find ?How-to? documentation; the papers
| | | presentations (including the RcppExamples package) are exciting,
| | focus on
| | | marketing use,
| | Nice way to start a dialogue with us by telling us we're idiots.
| | going.
| | | rather than providing instructions. I?d appreciate any help to
| | | get started to:
| | |
| | | 1. Code C++ using the Rcpp, RcppGSL and RcppArmadillo
| | 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
| | | 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
| | 'R CMD ...'
| | and/or Makefiles.
| | If you need netbeans, you get to figure out netbeans. Exiciting to
| | 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
| | | c. The matrix and vector classes, including views, Rcpp
| | implementation of
| | | the C library GSL employs new C++ capabilities and different
| | (e.g.
| | | extraction of pointers from matrix or vector view objects). Is
| | 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
| | 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++
| | Rcpp
| | | whenever we wish to input R data types such as matrix, vector and
| | (due to
| | | need to call .Call)?
| | Look at the definiton and decide for yourself. Using the define has
| | 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
| | 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)
| | 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
| | list
| | following Whit's question. Did you look at it?
| | | b. Is there any help on code debugging? (e.g. some
| | ?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
| | 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
| | and
| | | may contain confidential information. Any unauthorized review,
| | | disclosure or distribution is prohibited. If you are not the
| | | recipient, please contact the sender by reply email and destroy
| | copies
| | | of the original message.
| | |
| | |
| | | _______________________________________________
| | | Rcpp-devel mailing list
| | | Rcpp-devel at lists.r-forge.r-project.org
| | |
| | --
| | 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)
| 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
| of the original message.
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
More information about the Rcpp-devel