Re: [Rcpp-devel] Rccp code with vector and matrix inputs and matrix output

2014-03-31 Thread Dirk Eddelbuettel
On 31 March 2014 at 10:51, Petre Caraiani wrote: | Am(ii,jj) = exp((jj+1)/(T-1)) ; [...] | and use  fun(a,b,A,T), I get a matrix of 1s. Is there something wrong with the | division in this Cpp code? | | I get the same thing when I write: Am(ii,jj) = exp((jj+1)/(T-1)*log(a[ii])) ; | bu

Re: [Rcpp-devel] Rccp code with vector and matrix inputs and matrix output

2014-03-31 Thread Petre Caraiani
Hello everybody, Thanks for your suggestions. I used the cppFunction as follows: #include using namespace Rcpp; // [[Rcpp::export]] NumericMatrix fun (NumericVector a, NumericVector b, NumericMatrix Am , int T ){ int nrow = Am.nrow(); int ncol = Am.ncol(); for (int ii = 0; ii <= nrow-1; ii++)

Re: [Rcpp-devel] Rccp code with vector and matrix inputs and matrix output

2014-03-28 Thread Hadley Wickham
I'd recommend: a) using cppFunction instead of the older cxxfunction b) creating an example that anyone can copy and paste out of their email client and into R. You are more likely to get helpful responses if you reduce the burden on the potential helpers as much as possible Hadley On Fri, Mar

Re: [Rcpp-devel] Rccp code with vector and matrix inputs and matrix output

2014-03-28 Thread Dirk Eddelbuettel
On 28 March 2014 at 13:51, Petre Caraiani wrote: | Thank you for your quick reply! | I corrected the issue mentioned by you, but I get the same error. | It must be a beginner's issue. | | The data is quite big, but this kind of output could be produced with any | random data, I guess. | | Namely

Re: [Rcpp-devel] Rccp code with vector and matrix inputs and matrix output

2014-03-28 Thread Petre Caraiani
Thank you for your quick reply! I corrected the issue mentioned by you, but I get the same error. It must be a beginner's issue. The data is quite big, but this kind of output could be produced with any random data, I guess. Namely, using the Rcpp, I get Am as: [,1] [,2] [,3] [,4] [,5] [,6

Re: [Rcpp-devel] Rccp code with vector and matrix inputs and matrix output

2014-03-28 Thread Gregor Kastner
Hi Petre, > The following code works well in R: > attach(dataqtr) Not for me, because my vanilla copy of R doesn't know about dataqtr. It's helpful to provide reproducible examples. > However I am not able to reproduce it using the following Rccp code: > > a<- dataqtr[,LTG] > b<- dataqtr[,mean

Re: [Rcpp-devel] Rccp code with vector and matrix inputs and matrix output

2014-03-28 Thread Dirk Eddelbuettel
On 28 March 2014 at 10:30, Petre Caraiani wrote: | Hello, | The following code works well in R: | attach(dataqtr) | | dataqtr <- data.table(dataqtr) | setkeyv(dataqtr,c("gvkey","qtr")) | | vec_growth <- data.frame(0,0,0,0,0,0,0,0,0,0,0,0,0) | vec_eps    <- data.frame(0,0,0,0,0,0,0,0,0,0,0,0,0) |