Re: [Rcpp-devel] Integer matrices in Rcpp and Armadillo

2013-06-09 Thread Simon Zehnder
Hi Dirk, thank you very much for this suggestion. I will time several approaches when I have finished the logic of my algorithm. Best Simon On Jun 8, 2013, at 10:23 PM, Dirk Eddelbuettel wrote: > > Simon, > > You (in my eyes needlessly) complicate matters further with the S4 wrapping. >

Re: [Rcpp-devel] Integer matrices in Rcpp and Armadillo

2013-06-09 Thread Simon Zehnder
Dear Dirk, Kevin and Romain, this has been a very interesting discussion to me and made the things clear. Thank you very much for your contributions! Best Simon On Jun 8, 2013, at 10:19 PM, Dirk Eddelbuettel wrote: > > On 8 June 2013 at 12:48, Kevin Ushey wrote: > | I'm pretty the sure the

Re: [Rcpp-devel] Integer matrices in Rcpp and Armadillo

2013-06-08 Thread Dirk Eddelbuettel
Simon, You (in my eyes needlessly) complicate matters further with the S4 wrapping. The base case is simple, shown/used in src/fastLm.cpp right in the middle of RcppArmadillo and discussed a million times: extern "C" SEXP fastLm(SEXP Xs, SEXP ys) { try { Rcpp::NumericVector yr(ys);

Re: [Rcpp-devel] Integer matrices in Rcpp and Armadillo

2013-06-08 Thread Dirk Eddelbuettel
On 8 June 2013 at 12:48, Kevin Ushey wrote: | I'm pretty the sure the Rcpp / RcppArmadillo way is to reuse memory whenever | the types match between the as'ed containers, and copy if type coercion makes | sense. Ie, an R integer vector --> an Rcpp IntegerVector would reuse the same | memory, while

Re: [Rcpp-devel] Integer matrices in Rcpp and Armadillo

2013-06-08 Thread Kevin Ushey
I'm pretty the sure the Rcpp / RcppArmadillo way is to reuse memory whenever the types match between the as'ed containers, and copy if type coercion makes sense. Ie, an R integer vector --> an Rcpp IntegerVector would reuse the same memory, while an R integer vector --> an Rcpp NumericVector would

Re: [Rcpp-devel] Integer matrices in Rcpp and Armadillo

2013-06-08 Thread Simon Zehnder
Hi Romain, I considered the implicit use of Rcpp::as<>() inside of the arma::mat() constructor. My target was to reuse memory and try to use a very simple setting, i.e. (at least in my opinion) not too much lines of code. You answered to my question "On the other side I then assume, that the

Re: [Rcpp-devel] Integer matrices in Rcpp and Armadillo

2013-06-07 Thread Romain Francois
Le 07/06/13 16:07, Simon Zehnder a écrit : Hi Romain, thanks for this precise answer. So the suggested methods below will work without making a copy of the object. yes What is about the implicit call of Rcpp::as<>() inside arma::mat()? It is a very convenient way to create an arma object r

Re: [Rcpp-devel] Integer matrices in Rcpp and Armadillo

2013-06-07 Thread Simon Zehnder
Hi Romain, thanks for this precise answer. So the suggested methods below will work without making a copy of the object. What is about the implicit call of Rcpp::as<>() inside arma::mat()? It is a very convenient way to create an arma object reusing memory and it seems to work just fine. Be

Re: [Rcpp-devel] Integer matrices in Rcpp and Armadillo

2013-06-07 Thread Romain Francois
Le 07/06/13 15:14, Simon Zehnder a écrit : Hi Romain, hi Dirk, sorry for posting here again, but I found something in some way connected to this discussion - and pretty interesting concerning the Rcpp::as<>() function: 1. I create a class containing a list: setClass("myclass", representation(

Re: [Rcpp-devel] Integer matrices in Rcpp and Armadillo

2013-06-07 Thread Simon Zehnder
Hi Romain, hi Dirk, sorry for posting here again, but I found something in some way connected to this discussion - and pretty interesting concerning the Rcpp::as<>() function: 1. I create a class containing a list: setClass("myclass", representation(par = "list")) l <- list(lambda = array(0, d

Re: [Rcpp-devel] Integer matrices in Rcpp and Armadillo

2013-06-07 Thread Simon Zehnder
Thank you Romain! All clear now! Best Simon On Jun 7, 2013, at 1:13 PM, Romain Francois wrote: > Le 07/06/13 13:09, Simon Zehnder a écrit : >> HI Dirk, hi Romain, >> >> allright, this is now clear to me, if I want to reuse memory, the allocated >> memory from R (so implicitly in C) must o

Re: [Rcpp-devel] Integer matrices in Rcpp and Armadillo

2013-06-07 Thread Romain Francois
Le 07/06/13 13:09, Simon Zehnder a écrit : HI Dirk, hi Romain, allright, this is now clear to me, if I want to reuse memory, the allocated memory from R (so implicitly in C) must of course have the same type - otherwise the memory has a different size. so far, this is obvious. On the other

Re: [Rcpp-devel] Integer matrices in Rcpp and Armadillo

2013-06-07 Thread Simon Zehnder
HI Dirk, hi Romain, allright, this is now clear to me, if I want to reuse memory, the allocated memory from R (so implicitly in C) must of course have the same type - otherwise the memory has a different size. On the other side I then assume, that the Rcpp:as() function makes a cast and there

Re: [Rcpp-devel] Integer matrices in Rcpp and Armadillo

2013-06-06 Thread Dirk Eddelbuettel
On 6 June 2013 at 13:17, Dirk Eddelbuettel wrote: | | On 6 June 2013 at 19:05, Simon Zehnder wrote: | | sorry I had overseen this message from you. Okay, so the explicit cast to SEXP together with the assignment operator makes the deal. But it still includes the reuse of memory right, i.e. the

Re: [Rcpp-devel] Integer matrices in Rcpp and Armadillo

2013-06-06 Thread Dirk Eddelbuettel
On 6 June 2013 at 19:05, Simon Zehnder wrote: | sorry I had overseen this message from you. Okay, so the explicit cast to SEXP together with the assignment operator makes the deal. But it still includes the reuse of memory right, i.e. the '=' does not call the copy constructor? But how could

Re: [Rcpp-devel] Integer matrices in Rcpp and Armadillo

2013-06-06 Thread Romain Francois
Le 06/06/13 19:05, Simon Zehnder a écrit : Hi Romain, sorry I had overseen this message from you. Okay, so the explicit cast to SEXP together with the assignment operator makes the deal. But it still includes the reuse of memory right, i.e. the '=' does not call the copy constructor? Yep. No

Re: [Rcpp-devel] Integer matrices in Rcpp and Armadillo

2013-06-06 Thread Simon Zehnder
Hi Romain, sorry I had overseen this message from you. Okay, so the explicit cast to SEXP together with the assignment operator makes the deal. But it still includes the reuse of memory right, i.e. the '=' does not call the copy constructor? Further, this only solves the ambiguity for the conv

Re: [Rcpp-devel] Integer matrices in Rcpp and Armadillo

2013-06-06 Thread Simon Zehnder
Hi Romain, oh thanks! I haven't recognized this one, even though I use armadillo now for more than a half year ;) best Simon On Jun 6, 2013, at 6:48 PM, Romain Francois wrote: > Le 06/06/13 18:38, Simon Zehnder a écrit : >> Hi Dirk, >> >> thanks for the fast reply. It seems, that using in

Re: [Rcpp-devel] Integer matrices in Rcpp and Armadillo

2013-06-06 Thread Dirk Eddelbuettel
Hi Simon, On 6 June 2013 at 18:38, Simon Zehnder wrote: | thanks for the fast reply. It seems, that using ints is the only possibility here. I understand though, that the arma::umat has type 'unsigned int', hasn't it? So in this case I wouldn't be able to use umat, but rather mat, right? Yes,

Re: [Rcpp-devel] Integer matrices in Rcpp and Armadillo

2013-06-06 Thread Romain Francois
Le 06/06/13 18:38, Simon Zehnder a écrit : Hi Dirk, thanks for the fast reply. It seems, that using ints is the only possibility here. I understand though, that the arma::umat has type 'unsigned int', hasn't it? So in this case I wouldn't be able to use umat, but rather mat, right? Which is

Re: [Rcpp-devel] Integer matrices in Rcpp and Armadillo

2013-06-06 Thread Simon Zehnder
Hi Dirk, thanks for the fast reply. It seems, that using ints is the only possibility here. I understand though, that the arma::umat has type 'unsigned int', hasn't it? So in this case I wouldn't be able to use umat, but rather mat, right? Best Simon On Jun 6, 2013, at 6:32 PM, Dirk Eddelbue

Re: [Rcpp-devel] Integer matrices in Rcpp and Armadillo

2013-06-06 Thread Romain Francois
Le 06/06/13 18:03, Simon Zehnder a écrit : Hi Rcpp:Users, and Rcpp::Devels, I encountered the following problem when working today/yesterday on my project: 1. In R create an S4-object with the following slot: setClass("myclass", representation(S = "array")) mclass <- new("myclass", S = array(

Re: [Rcpp-devel] Integer matrices in Rcpp and Armadillo

2013-06-06 Thread Dirk Eddelbuettel
On 6 June 2013 at 18:03, Simon Zehnder wrote: | What I need is an arma::umat in C++ and if possible in addition an integer array in R. Is this possible? R itself has no unsigned integers (just as it has no [signed or unsigned] short or long integeger). You should be able to write wrappers thou

[Rcpp-devel] Integer matrices in Rcpp and Armadillo

2013-06-06 Thread Simon Zehnder
Hi Rcpp:Users, and Rcpp::Devels, I encountered the following problem when working today/yesterday on my project: 1. In R create an S4-object with the following slot: setClass("myclass", representation(S = "array")) mclass <- new("myclass", S = array(0, dim = c(100, 10))) 2. In C++ compile a fu