Re: [Rcpp-devel] RcppArmadillo inv() depends on Lapack, zgetri_ not available on CRAN / R-forge?
Thank you for the explanations below. On 5 June 2011 10:40, Dirk Eddelbuettel e...@debian.org wrote: On 5 June 2011 at 10:12, baptiste auguie wrote: | Hi Dirk and all, | | On 4 June 2011 12:04, Dirk Eddelbuettel e...@debian.org wrote: | | Baptiste, | | On 4 June 2011 at 11:45, baptiste auguie wrote: | | Dear list, | | | | My package cda, which I was hoping to release on CRAN, fails to | | compile on R-forge with error, | | | | ** testing if installed package can be loaded | | Error in dyn.load(file, DLLpath = DLLpath, ...) : | | unable to load shared object '/tmp/RtmpbztUMm/Rinst1829c04c/cda/libs/cda.so': | | /tmp/RtmpbztUMm/Rinst1829c04c/cda/libs/cda.so: undefined symbol: zgetri_ | | | | It builds fine on my local machines (Mac OS 10.5, 10.6). | | | | From an older discussion on this list | | http://www.mail-archive.com/rcpp-devel@lists.r-forge.r-project.org/msg00678.html | | the issue seems to be that Armadillo's inv() relies on a function that | | is not provided by R, only by LAPACK. I have just replaced inv() by | | pinv() and solve() in my code; merely to see what happens, but chances | | are they also require a full LAPACK. | | Indeed, the error on R-forge is now with zgels_, required to solve | linear systems. It seems one cannot solve Armadillo linear systems | without LAPACK in the current situation. Yes. Doug, Romain and myself should address that, or at least make it clear what feature of the full Armadillo are lacking in RcppArmadillo. | Sometime relatively early in the RcppArmadillo development process, Doug | convinced Romain and myself to go for a pure template solution with Armadillo | as all / most things found during the configure (or in this case, cmake) | stage can be assumed 'found' given that we have around us by design. So no | testing, no local library and full reliance and what R gives us. | | That was a brilliant idea, and has freed us from having to rely on building | and shipping a library, having to tell users how to set PKG_LIBS etc pp and I | firmly believe that this helped tremendously in getting RcppArmadillo more | widely used. So I would not want to revert this. | | It sounds like a good choice, I agree. Yet solving a linear system is | quite a crucial task in linear algebra; it would be nice if we could | come up with a tutorial recipe for dummies like me. | | | In any event, it seems that you need more LAPACK than R has for you. That is | likely to be a dicey situation as you per se do not know whether R was built | and linked with its own (subset) copy of LAPACK, or whether it uses system | LAPACK libraries (as e.g. the Debian / Ubuntu systems do). So you may be in | a spot bother and I not sure what I can recommend --- other than trying your | luck at some short configure snippets that will run at package build time to | determine whether the system you want to build cda on it 'rich' enough to | support it. I can help you off list with some configure snippets as some of | my packages have configure code; adding a test for zgetri should be feasible. | | | Does anybody have any experience | | dealing with such issues w.r.t releasing a package on R-forge / CRAN? | | Is there any chance they would consider installing LAPACK on those | | servers, or is there no point in asking such things? | | I don't think it is a matter of fixing the R-Forge server. I think it is a | matter of making your package installable on the largest number of user | systems. Also try win-builder.r-project.org to see how it fares on that | platform. Unsurprisingly, it fails, with the same complaint as R-forge. | | I was under the impression that R-forge or CRAN, if it had LAPACK | installed, could produce binaries for the relevant platforms, and | users would not have to build the package themselves and would not be | required of having LAPACK on their machine. That's probably a | misconception, isn't it? If and only statically linked binaries or libraries where produced, which is generally not the case. Many OSs (Linux incl) ship source only and otherwise link dynamically, others (Windoze) use dynamic linking and OS X is for all I know somewhere in the middle (as you can get prebuild packages with dynamic linking or build from source). I see; so basically the user will always need to have a full LAPACK installed. Here's one question then, if R-core didn't consider necessary to include those particular functions from LAPACK, presumably that means that R defines its own routines to solve linear systems and invert matrices. Is there any possibility to use those routines with Armadillo? | Sorry for being dense, I don't know anything about linking R to | external dependencies. It can be done; there are many examples -- for example every package using the GSL. I just checked how RcppGSL does it, and well, this configure
Re: [Rcpp-devel] Create an instance of a reference class for a C++ class exported as a module from within C++?
At the moment the only way i see is to make an R call to new and construct the object this way... Many of the methods for this class return other members of this class. Can I create a new instance of the reference class in R from within the module? I'm sure it is possible, I'm just wondering if there is an easy way to do this without duplicating large chunks of the code in Rcpp/src/Module.cpp. Can i somehow clone the SEXP representing the current instance then swap the external pointer to the C++ object? I played with this a little more, and the following works fine. Nothing striking here. The part I don't understand is, can you employ the SEXP returned by spawn() as an instance of Bar, or are you then stuck with the R interface to Bar? -Christian ## in R Rcpp.package.skeleton('testmod', module=T) //in testmod/src/rcpp_module.cpp #include Rcpp.h using namespace Rcpp; class Bar { public: Bar() {} void set(int state_) { this-state = state_; } int get() { return state; } SEXP spawn() { Environment meth(package:methods); Function Rnew = meth[new]; Function Rget(get); SEXP NewObj( Rnew(Rget(Bar)) ); return NewObj; } private: int state; }; ## in R require(testmod) bb = new(Bar); bb$set(3) cc = bb$spawn(); cc$set(4) bb$get(); cc$get() -- A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal – Panama! ___ 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] [Rd] Interfacing a C++ class
Le 04/06/11 16:31, soeren.vo...@uzh.ch a écrit : Hello Apologies for cross-posting, the discussion should (if) go to R-devel, but I also want to reach the rcpp-devel people. My C++ class FOO is a module available through Rcpp, and it works fine and is -- so far -- bug free. With trying to further develop my R package, I thought it was a good idea to interface my C++ workhorse FOO with an S4 class Foo. After some long and not always insightful trip through S4 classes and methods, I am not sure if I am on the right way of thinking and designing. Since there is no local assistance available, could you help to make things clearer? Just a brief outline: FOO is the C++ object, and Foo should be the S4 class. If the user creates an object, say bar, from class Foo, the creation process automatically makes a new FOO object relating to bar in that a unique name of the FOO instance is stored in a slot of bar. All the user then has to do is modify bar by simple assignments. The getters and setters ($, [) are set up and work. Each modification goes in hand with assigning new values to bar as well as updating the FOO object through available setters from FOO. So far, this way has brought me to about 100 lines, but now I read about ReferenceClasses and was wondering, if there is a much easier way of achieving my goals. Moreover, I was not sure any longer if my goals make sense or if a more advanced programmer would do it totally different (and could share some structural thinking on their approach). The idea behind my way of doing was based upon several considerations. First, a classical R object would not confuse users, as I assume users of my package to be rather non-skilled (and not willing to change that). Second, I want to create a properly programmed package for distribution on CRAN and publication, eventually. Third, I want to save objects across sessions. So if a user restores a session, a simple command, say, restore(), would do the trick to build all the related C++ objects again. However, I admit that I still have not figured out how to automatically clean up the workspace correctly before leaving a session, wanted or unwanted, that is, clean up memory before leaving home. Fourth, pure arithmetic check is done in C++, however, semantic check *should* be left to R, and the validity and class routines seem to be perfect for this. Fifth, some work should be done in R, such as the passing of data frames or samples from distributions. I hope to get some structured ideas and hints how to start and/or proceed. Thank you in advance, Sören Hello, A C++ class that is exposed through an Rcpp module is already a reference class, and so you can add methods, etc ... Consider this example : require(inline) require(Rcpp) fx - cxxfunction( , '', includes = ' class FOO{ public: FOO( double x_, double y_): x(x_), y(y_){} double x ; double y ; void move( double dx, double dy){ x += dx ; y += dy ; } } ; RCPP_MODULE(mod){ class_FOO(FOO ) .constructordouble,double() .field( x, FOO::x ) .field( y, FOO::y ) .method( move, FOO::move ) ; } ', plugin = Rcpp ) mod - Module( mod, getDynLib(fx),mustStart = TRUE ) # grab the exposed C++ class FOO - mod$FOO # add R methods FOO$methods( bla = function() x+y, reset = function() { x - 0.0 y - 0.0 } ) # create an instance f - new( FOO, 2.0, 3.0 ) # call an R method f$reset() # call a C++ method f$move( 2.0, 2.0 ) # call an R method f$bla() Hope this helps. Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr http://romain-francois.com |- http://bit.ly/hdKhCy : Rcpp article in JSS |- http://bit.ly/elZJRJ : Montpellier Comedie Club - Avril 2011 `- http://bit.ly/fhqbRC : Rcpp workshop in Chicago on April 28th ___ 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] Constructor for templated Rcpp::Matrix class from Rcpp::Dimension fails
Le 02/06/11 12:10, rom...@r-enthusiasts.com a écrit : Thanks. Making init protected instead of private in Vector.h solved it for me. I cant commit the fix from the eurostar. Romain Done in rev 3046. Le 1 juin 2011 à 21:36, Douglas Batesba...@stat.wisc.edu a écrit : I am developing classes for sparse matrices with an Rcpp interface that includes Rcpp::Dimension dim() const {return Rcpp::Dimension(nr(), nc());} Rcpp::NumericMatrix asmatrix() const; The implementation of the asmatrix method begins with Rcpp::NumericMatrix ans(dim()); which is a public constructor for the Rcpp::Matrix template but this fails stating In file included from /home/bates/R/x86_64-unknown-linux-gnu-library/2.14/Rcpp/include/Rcpp/Vector.h:58:0, from /home/bates/R/x86_64-unknown-linux-gnu-library/2.14/Rcpp/include/Rcpp.h:42, from RcppSparse.h:1, from Module.cpp:1: /home/bates/R/x86_64-unknown-linux-gnu-library/2.14/Rcpp/include/Rcpp/vector/Vector.h: In constructor ‘Rcpp::MatrixRTYPE::Matrix(const Rcpp::Dimension) [with int RTYPE = 14]’: RcppSparse.h:110:31: instantiated from here /home/bates/R/x86_64-unknown-linux-gnu-library/2.14/Rcpp/include/Rcpp/vector/Vector.h:640:7: error: ‘void Rcpp::VectorRTYPE::init() [with int RTYPE = 14]’ is private /home/bates/R/x86_64-unknown-linux-gnu-library/2.14/Rcpp/include/Rcpp/vector/Matrix.h:49:3: error: within this context make: *** [Module.o] Error 1 I can program around this problem by generating the Rcpp::NumericMatrix from the number of rows and number of columns but I would class the behavior of the constructor mentioned earlier as at least an infelicity (to use Bill Venables' term). ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr http://romain-francois.com |- http://bit.ly/kaSV6U : Stand up set at Up The Creek |- http://bit.ly/hdKhCy : Rcpp article in JSS `- http://bit.ly/elZJRJ : Montpellier Comedie Club - Avril 2011 ___ 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] Wrapping uBlas Matrices into Rcpp Matrices
Le 02/06/11 14:43, Cedric Ginestet a écrit : Hi again, I have tried to do the same for Matrices. Here my naive attempt: template typename T Rcpp::Matrix Rcpp::traits::r_sexptype_traitsT::rtype ublas2rcpp( const matrixT x ){ return Rcpp::Matrix Rcpp::traits::r_sexptype_traitsT::rtype ( x.begin(), x.end() ); } // Obviously that doesn't work, and I get the following error message: templatedFunction.h:63:5: error: ‘const class boost::numeric::ublas::matrixint’ has no member named ‘begin’ templatedFunction.h:63:5: error: ‘const class boost::numeric::ublas::matrixint’ has no member named ‘end’ I suppose that I either need to 'vectorized' the matrices or to run through both set of row and column indices. What is the best way to do so? Best wishes, Cedric Again untested, but you might like this constructor from Rcpp::Matrix: template typename Iterator Matrix( const int nrows_, const int ncols, Iterator start ) : VECTOR( start, start + (nrows_*ncols) ), nrows(nrows_) { VECTOR::attr( dim ) = Dimension( nrows, ncols ) ; } So you'd use it something like this: template typename T Rcpp::Matrix Rcpp::traits::r_sexptype_traitsT::rtype ublas2rcpp( const matrixT x ){ return Rcpp::Matrix Rcpp::traits::r_sexptype_traitsT::rtype ( x.size1(), x.size2(), x.begin1() ); } This is untested by guessing what would do the functions found in the documentation of uBlas: http://www.boost.org/doc/libs/1_42_0/libs/numeric/ublas/doc/matrix.htm Romain On 01/06/11 14:14, Romain Francois wrote: Le 01/06/11 14:28, Cedric Ginestet a écrit : Dear Romain, Thank you very much for your help. I tried what you suggested by including the following templated function in templatedFunction.h, as follows: template typename T Rcpp::Vector Rcpp::traits::r_sexptype_traitsT::rtype ublas2rcpp( const vectorT x ){ return Rcpp::Vector r_sexptype_traitsT::rtype ( x.begin(), x.end() ) ; } In addition, I have tested the function using in subgraph.cpp: Rcpp::Vectorint xY = ublas2rcpp(Y); And I got the following error messages: templatedFunction.h: In function ‘Rcpp::VectorRcpp::traits::r_sexptype_traitsT::rtype ublas2rcpp(const boost::numeric::ublas::vectorT)’: templatedFunction.h:50:26: error: ‘r_sexptype_traits’ was not declared in this scope templatedFunction.h:50:45: error: template argument 1 is invalid subgraph.cpp: In function ‘SEXPREC* cxx_Mask2Graph(SEXPREC*, SEXPREC*, SEXPREC*, SEXPREC*)’: subgraph.cpp:32:19: error: type/value mismatch at argument 1 in template parameter list for ‘templateint RTYPE class Rcpp::Vector’ subgraph.cpp:32:19: error: expected a constant of type ‘int’, got ‘int’ subgraph.cpp:32:24: error: invalid type in declaration before ‘=’ token subgraph.cpp:32:38: error: invalid conversion from ‘SEXPREC*’ to ‘int’ subgraph.cpp:34:8: error: invalid conversion from ‘int’ to ‘SEXPREC*’ ... Sure. This was a typo/thinko: go with something like this : template typename T Rcpp::Vector Rcpp::traits::r_sexptype_traitsT::rtype ublas2rcpp( const vectorT x ){ return Rcpp::Vector Rcpp::traits::r_sexptype_traitsT::rtype ( x.begin(), x.end() ) ; } and Rcpp::Vectorint makes no sense, you probably want IntegerVector, or (the same class): Rcpp::Vector r_sexptype_traitsint::rtype Rcpp::Vector is templated by the SEXP type. Also, as an aside, I was wondering what I should use instead of push_back for Rcpp Vectors. Do I necessarily have to specify the size of the vector before I assign its elements to specific values? That is much better yes. ublas probably gives a way to access the size of the vector. Thanks a lot, Cedric On 01/06/11 11:44, Romain Francois wrote: Hi, I've not used uBlas, but what you are trying to do is quite similar to what we do in RcppArmadillo. You can probably manage to guess the output type from the input type, so you only have to parameterise your template on the input type. something like (untested) : template typename T Rcpp::Vector Rcpp::traits::r_sexptype_traitsT::rtype ublas2rcpp( const vectorT x ){ return Rcpp::Vector r_sexptype_traitsT::rtype ( x.begin(), x.end() ) ; } This way you don't have to specify template parameter when you call ublas2rcpp because the compiler is smart enough. Nicer than this would be to implement wrap and as for ublas vectors, the way to go is documented in the Rcpp-extended vignettes, with examples implementations in RcppArmadillo and RcppGSL. As a side note, you don't want to use push_back on Rcpp types, because it creates a new vector each time, so this is HUGE memory waste. Now, this could get much smarter as ublas has vector expressions, similar to armadillo, so I suppose someone could write something like RcppUBlas with nice goodies. This is not me, at least not now ;-) Romain Le 01/06/11 12:24, Cedric Ginestet a écrit : Dear Rcpp
Re: [Rcpp-devel] namespace error
Le 04/06/11 14:53, soeren.vo...@uzh.ch a écrit : On 02.06.2011, at 22:51, Laurent Gatto wrote: On 2 June 2011 20:39,soeren.vo...@uzh.ch wrote: On 02.06.2011, at 18:50, Dirk Eddelbuettel wrote: On 2 June 2011 at 18:37, soeren.vo...@uzh.ch wrote: When R CMD CHECKing the package, I repeatedly get the error: | | Error: .onLoad failed in loadNamespace() for 'GUTS', details: | call: value[[3L]](cond) | error: failed to load module mod_guts from package GUTS | Execution halted | A namespace must be able to be loaded with just the base namespace | loaded: otherwise if the namespace gets loaded by a saved object, the | session will be unable to start. You have good chances to get rid of it using the latest svn version of Rccp: Thanks for the advice. Unfortunately, it doesn't work. I've downloaded and installed the latest version, made an Rcpp.package.skeleton(Foo, module=TRUE), and run R CMD CHECK Foo, resulting on a slightly different but still persistent warning: ** checking whether the name space can be loaded with stated dependencies ... WARNING Error: .onLoad failed in loadNamespace() for 'Foo', details: call: value[[3L]](cond) error: failed to load module yada from package Foo could not find function getClass Execution halted A namespace must be able to be loaded with just the base namespace loaded: otherwise if the namespace gets loaded by a saved object, the session will be unable to start. Probably some imports need to be declared in the NAMESPACE file. However, the package works and I think a solution is not urgent. *S* Do you get this warning if you add this line in the NAMESPACE file of the generated package: import(methods) Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr http://romain-francois.com |- http://bit.ly/kaSV6U : Stand up set at Up The Creek |- http://bit.ly/hdKhCy : Rcpp article in JSS `- http://bit.ly/elZJRJ : Montpellier Comedie Club - Avril 2011 ___ 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 inv() depends on Lapack, zgetri_ not available on CRAN / R-forge?
On 6 June 2011 at 09:56, baptiste auguie wrote: | | I don't think it is a matter of fixing the R-Forge server. I think it is a | | matter of making your package installable on the largest number of user | | systems. Also try win-builder.r-project.org to see how it fares on that | | platform. | | Unsurprisingly, it fails, with the same complaint as R-forge. Yup. | | I was under the impression that R-forge or CRAN, if it had LAPACK | | installed, could produce binaries for the relevant platforms, and | | users would not have to build the package themselves and would not be | | required of having LAPACK on their machine. That's probably a | | misconception, isn't it? | | If and only statically linked binaries or libraries where produced, which is | generally not the case. Many OSs (Linux incl) ship source only and otherwise | link dynamically, others (Windoze) use dynamic linking and OS X is for all I | know somewhere in the middle (as you can get prebuild packages with dynamic | linking or build from source). | | I see; so basically the user will always need to have a full LAPACK | installed. Here's one question then, if R-core didn't consider | necessary to include those particular functions from LAPACK, | presumably that means that R defines its own routines to solve linear | systems and invert matrices. Is there any possibility to use those | routines with Armadillo? I think that *is* generally what we do. We would have at specifics for the functions you are after. | It can be done; there are many examples -- for example every package using | the GSL. | | I just checked how RcppGSL does it, and well, this configure magic is | way above my head. I know it looks scary but you it is reasonably well understood and there are tons of examples. I can help you off-line. Also, read configure.in / configure.ac and not the configure which is autogenerated from it, large and generally unreadable. Dirk -- Gauss once played himself in a zero-sum game and won $50. -- #11 at http://www.gaussfacts.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] namespace error
On 06.06.2011, at 14:03, Romain Francois wrote: Le 04/06/11 14:53, soeren.vo...@uzh.ch a écrit : On 02.06.2011, at 22:51, Laurent Gatto wrote: On 2 June 2011 20:39,soeren.vo...@uzh.ch wrote: On 02.06.2011, at 18:50, Dirk Eddelbuettel wrote: On 2 June 2011 at 18:37, soeren.vo...@uzh.ch wrote: When R CMD CHECKing the package, I repeatedly get the error: | | Error: .onLoad failed in loadNamespace() for 'GUTS', details: | call: value[[3L]](cond) | error: failed to load module mod_guts from package GUTS | Execution halted | A namespace must be able to be loaded with just the base namespace | loaded: otherwise if the namespace gets loaded by a saved object, the | session will be unable to start. You have good chances to get rid of it using the latest svn version of Rccp: Thanks for the advice. Unfortunately, it doesn't work. I've downloaded and installed the latest version, made an Rcpp.package.skeleton(Foo, module=TRUE), and run R CMD CHECK Foo, resulting on a slightly different but still persistent warning: ** checking whether the name space can be loaded with stated dependencies ... WARNING Error: .onLoad failed in loadNamespace() for 'Foo', details: call: value[[3L]](cond) error: failed to load module yada from package Foo could not find function getClass Execution halted A namespace must be able to be loaded with just the base namespace loaded: otherwise if the namespace gets loaded by a saved object, the session will be unable to start. Probably some imports need to be declared in the NAMESPACE file. However, the package works and I think a solution is not urgent. *S* Do you get this warning if you add this line in the NAMESPACE file of the generated package: import(methods) In R: R: library(Rcpp) R: Rcpp.package.skeleton(Foo, module=TRUE) Then edit file NAMESPACE to useDynLib(Foo) exportPattern(^[[:alpha:]]+) import(Rcpp) import(methods) Then back on Terminal: R CMD CHECK Foo ... reveals: Error: .onLoad failed in loadNamespace() for 'Foo', details: call: value[[3L]](cond) error: failed to load module yada from package Foo could not find function getClass Execution halted R: sessionInfo() R version 2.13.0 (2011-04-13) Platform: i386-apple-darwin9.8.0/i386 (32-bit) locale: [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] Rcpp_0.9.4.2 loaded via a namespace (and not attached): [1] tools_2.13.0 ___ 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] Create an instance of a reference class for a C++ class exported as a module from within C++?
Le 06/06/11 06:09, Christian Gunning a écrit : At the moment the only way i see is to make an R call to new and construct the object this way... Many of the methods for this class return other members of this class. Can I create a new instance of the reference class in R from within the module? I'm sure it is possible, I'm just wondering if there is an easy way to do this without duplicating large chunks of the code in Rcpp/src/Module.cpp. Can i somehow clone the SEXP representing the current instance then swap the external pointer to the C++ object? I played with this a little more, and the following works fine. Nothing striking here. The part I don't understand is, can you employ the SEXP returned by spawn() as an instance of Bar, or are you then stuck with the R interface to Bar? -Christian ## in R Rcpp.package.skeleton('testmod', module=T) //in testmod/src/rcpp_module.cpp #includeRcpp.h using namespace Rcpp; class Bar { public: Bar() {} void set(int state_) { this-state = state_; } int get() { return state; } SEXP spawn() { Environment meth(package:methods); Function Rnew = meth[new]; Function Rget(get); SEXP NewObj( Rnew(Rget(Bar)) ); return NewObj; } private: int state; }; ## in R require(testmod) bb = new(Bar); bb$set(3) cc = bb$spawn(); cc$set(4) bb$get(); cc$get() I'm playing with this now. More later ... Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr http://romain-francois.com |- http://bit.ly/kaSV6U : Stand up set at Up The Creek |- http://bit.ly/hdKhCy : Rcpp article in JSS `- http://bit.ly/elZJRJ : Montpellier Comedie Club - Avril 2011 ___ 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] [ANN] RcppArmadillo 0.2.22
Armadillo 1.99.4 is out with fixes for small matrices, and this has been wrapped into RcppArmadillo 0.2.22 which is now on CRAN. Please test this and see if it addresses the issues with the prior pre-releases of Armadillo 2.0.0. The NEWS entry is below. Cheers, Dirk 0.2.22 2011-06-06 o Upgraded to Armadillo release 1.99.3 v2.0 beta 3 * fixes for handling of tiny matrices -- Gauss once played himself in a zero-sum game and won $50. -- #11 at http://www.gaussfacts.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] as cube
Hi, I would like to do something like this: src.cube - arma::cube a = asarma::cube(aR); return wrap(a); fx - cxxfunction(signature(aR=array), src.cube, plugin=RcppArmadillo) fx(array(1:27, c(3,3,3))) But it fails. Can someone suggest a good alternative? I tried to create the cube on the C++ side and use .fill() to fill it with a NumericVector, but this did not work either. Thanks, Richard ___ 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] trans() changed in latest RcppArmadillo
Hi Baptise Terrance, I've fixed several issues in Armadillo and released an updated version (1.99.4). Dirk has wrapped it up in RcppArmadillo 0.2.22, which should be hitting the mirrors soon. Could you try your code again and let me know if you encounter any problems ? With regards, Conrad On 1 June 2011 05:58, baptiste auguie baptiste.aug...@googlemail.com wrote: Thanks so much, Conrad! Best regards, Baptiste On 31 May 2011 23:37, Conrad Sand wrote: I've found the cause of the issue (involves handling of small matrices). The fix is easy (and already done in the SVN repo), but I currently don't have the time to roll out another release. I'll aim to release a fix on the weekend, which will also give me time to double-check if there is a problem in inv(). In the meantime I recommend sticking to the previous version of Armadillo and RcppArmadillo. btw, for dot products I recommend using the dot() and cdot() functions -- they're generally faster than going through the multiplication operator. ___ 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] [ANN] RcppArmadillo 0.2.22
On 6 June 2011 at 08:35, Dirk Eddelbuettel wrote: | | Armadillo 1.99.4 is out with fixes for small matrices, and this has been | wrapped into RcppArmadillo 0.2.22 which is now on CRAN. Please test this and | see if it addresses the issues with the prior pre-releases of Armadillo 2.0.0. | | The NEWS entry is below. | | Cheers, Dirk | | 0.2.22 2011-06-06 | | o Upgraded to Armadillo release 1.99.3 v2.0 beta 3 As Conrad just noticed: this needs 's/3/4/g'. Sorry. Dirk | * fixes for handling of tiny matrices | | | -- | Gauss once played himself in a zero-sum game and won $50. | -- #11 at http://www.gaussfacts.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 -- Gauss once played himself in a zero-sum game and won $50. -- #11 at http://www.gaussfacts.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] as cube
Richard, I usually use a list for this (see below). If anybody has a simpler way, I would love to learn about it... Sanjog src.cube = ' Rcpp::List aL(aL_); int nr = Rcpp::asint(nr_); int nc = Rcpp::asint(nc_); int ns = Rcpp::asint(ns_); arma::cube a(nr,nc,ns); for(int i=0; ins; i++) { a.slice(i) = Rcpp::asarma::mat(aL(i)); } return Rcpp::wrap(a); ' fx = cxxfunction(signature(aL_=list, nr_=integer, nc_=integer, ns_=integer),body = src.cube, plugin=RcppArmadillo) aR = array(1:27,c(3,3,3)) aL = NULL; for(i in 1:3) aL[[i]] = aR[,,i] fx(aL,3,3,3) Sanjog Misra Associate Professor of Marketing and Applied Statistics Area Coordinator, Applied Statistics Simon School of Business University of Rochester Rochester, NY 14627 P: 585.275.8920 F: 585.273.1140 From: rcpp-devel-boun...@r-forge.wu-wien.ac.at [mailto:rcpp-devel-boun...@r-forge.wu-wien.ac.at] On Behalf Of Richard Chandler Sent: Monday, June 06, 2011 11:13 AM To: rcpp-devel Subject: [Rcpp-devel] as cube Hi, I would like to do something like this: src.cube - arma::cube a = asarma::cube(aR); return wrap(a); fx - cxxfunction(signature(aR=array), src.cube, plugin=RcppArmadillo) fx(array(1:27, c(3,3,3))) But it fails. Can someone suggest a good alternative? I tried to create the cube on the C++ side and use .fill() to fill it with a NumericVector, but this did not work either. Thanks, Richard ___ 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