Re: [Rcpp-devel] Joining each row of CharacterMatrix to return a CharacterVector?

2012-12-10 Thread Romain Francois
Hello, We don't know your function f, so this is hard to say. Anyway, this below implements something similar to apply(.,1,paste0) in rcpp (current devl version): #include using namespace Rcpp ; // [[Rcpp::export]] CharacterVector pasteColumns(CharacterMatrix m){ String buffer ; in

Re: [Rcpp-devel] Joining each row of CharacterMatrix to return a CharacterVector?

2012-12-10 Thread hickey
Thanks very much, Dirk and Steve. Always slightly fear-inducing when someone starts their reply with "Ah, the joy of working with X" :) I'll have a go at implementing your suggestion on my two examples, Dirk. I think learning more about Rcpp will become my Christmas-holiday project. It's alr

Re: [Rcpp-devel] Joining each row of CharacterMatrix to return a CharacterVector?

2012-12-10 Thread Steve Lianoglou
Hi, On Mon, Dec 10, 2012 at 5:43 PM, wrote: > I preface this by stating that I'm very much a Rcpp beginner who is > comfortable in R but I've never before used C++. I'm working through the > Rcpp documentation but haven't been able to answer my question. > > I've written an Rcpp (v0.10.1) functi

Re: [Rcpp-devel] Joining each row of CharacterMatrix to return a CharacterVector?

2012-12-10 Thread Dirk Eddelbuettel
Hi Pete, On 11 December 2012 at 09:43, hic...@wehi.edu.au wrote: | I preface this by stating that I'm very much a Rcpp beginner who is comfortable | in R but I've never before used C++. I'm working through the Rcpp documentation | but haven't been able to answer my question. | | I've written a

[Rcpp-devel] Joining each row of CharacterMatrix to return a CharacterVector?

2012-12-10 Thread hickey
I preface this by stating that I'm very much a Rcpp beginner who is comfortable in R but I've never before used C++. I'm working through the Rcpp documentation but haven't been able to answer my question. I've written an Rcpp (v0.10.1) function f that takes as input a CharacterMatrix X. X has 2

Re: [Rcpp-devel] RcppArmadillo: passing matrix columns by reference

2012-12-10 Thread Ramon Diaz-Uriarte
On Mon, 10 Dec 2012 17:06:06 +0100,Romain Francois wrote: > the .col method gives you a subview_col : >arma_inline subview_col col(const uword col_num); >arma_inline const subview_col col(const uword col_num) const; > not an umat. > The name of the class implies that it is a "

Re: [Rcpp-devel] For a Matrix A, is A(i, j) or A[i, j] preferred as an accessor for an element

2012-12-10 Thread Dirk Eddelbuettel
On 10 December 2012 at 10:45, Douglas Bates wrote: | On Mon, Dec 10, 2012 at 10:38 AM, Romain Francois | wrote: | | Le 10/12/12 17:29, Douglas Bates a écrit : | | or does it matter? | | | A[i,j] is wrong, not valid C or C++ code. so there is only one choice. No, it's worse, I

Re: [Rcpp-devel] For a Matrix A, is A(i, j) or A[i, j] preferred as an accessor for an element

2012-12-10 Thread Romain Francois
Le 10/12/12 17:45, Douglas Bates a écrit : On Mon, Dec 10, 2012 at 10:38 AM, Romain Francois mailto:rom...@r-enthusiasts.com>> wrote: Le 10/12/12 17:29, Douglas Bates a écrit : or does it matter? A[i,j] is wrong, not valid C or C++ code. so there is only one choice. Indeed.

Re: [Rcpp-devel] For a Matrix A, is A(i, j) or A[i, j] preferred as an accessor for an element

2012-12-10 Thread Douglas Bates
On Mon, Dec 10, 2012 at 10:38 AM, Romain Francois wrote: > Le 10/12/12 17:29, Douglas Bates a écrit : > >> or does it matter? >> > > A[i,j] is wrong, not valid C or C++ code. so there is only one choice. > Indeed. Thanks. Somehow I managed to convince myself that I had used A[i,j] at some point

[Rcpp-devel] For a Matrix A, is A(i, j) or A[i, j] preferred as an accessor for an element

2012-12-10 Thread Douglas Bates
or does it matter? ___ 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: passing matrix columns by reference

2012-12-10 Thread Romain Francois
Le 10/12/12 17:06, Romain Francois a écrit : the .col method gives you a subview_col : arma_inline subview_col col(const uword col_num); arma_inline const subview_col col(const uword col_num) const; not an umat. The name of the class implies that it is a "view" class, so a way to l

Re: [Rcpp-devel] RcppArmadillo: passing matrix columns by reference

2012-12-10 Thread Romain Francois
the .col method gives you a subview_col : arma_inline subview_col col(const uword col_num); arma_inline const subview_col col(const uword col_num) const; not an umat. The name of the class implies that it is a "view" class, so a way to look a data from another class. hence, no data o

[Rcpp-devel] RcppArmadillo: passing matrix columns by reference

2012-12-10 Thread Ramon Diaz-Uriarte
Dear All, I am trying to pass columns from an Armadillo matrix to a function, but I'd like to pass just a reference to the column, not a copy of the column and I do not seem to be able to do it "elegantly". The code below (function f1) I think shows that passing X.col to a function creates a co

Re: [Rcpp-devel] RcppArmadillo: resize vs. insert_cols

2012-12-10 Thread Ramon Diaz-Uriarte
Hi Conrad, Thanks a lot. Understood; I'll stay away from premature optimization, then, and see if it is really needed. Best, R. On Mon, 10 Dec 2012 23:48:36 +1000,c s wrote: > Hi Ramon, > Option (b) would be more efficient, at the expense of slightly more code. > However, you can use opti

Re: [Rcpp-devel] RcppArmadillo: resize vs. insert_cols

2012-12-10 Thread c s
Hi Ramon, Option (b) would be more efficient, at the expense of slightly more code. However, you can use option (a) to quickly get something working. Once you test that your code works okay, you can always optimise it by selectively refactoring it into (b). If the code in question is not inside

Re: [Rcpp-devel] How to increase the coding efficiency

2012-12-10 Thread c s
Hi Honglang, I recommend looking into using the solve() function in Armadillo, instead of inv(). Using solve() will be considerably faster. More details here: http://arma.sourceforge.net/docs.html#solve On Thursday, December 6, 2012, Honglang Wang wrote: > The following is a full example altho

[Rcpp-devel] RcppArmadillo: resize vs. insert_cols

2012-12-10 Thread Ramon Diaz-Uriarte
Dear All, I am using RcppArmadillo, and I am creating matrices in the C++ code (i.e., these are not matrices passed from R). The sizes of these matrices might need to increase dynamically during run time, with elements being added at the end. What is the recommended way of doing this: a) Just i