[Rcpp-devel] iterator for sparse Matrix

Dirk Eddelbuettel edd at debian.org
Thu Jan 23 02:13:20 CET 2014


Saurabh,

On 22 January 2014 at 18:04, Saurabh B wrote:
| I am running into many issues. Here they are ranked in order of importance) -
| 1) When I run this (incorrect) program -
| stochDescCpp(param = rep(0,3), x = X, y = Y, maxit = 100)
| 
| I get -
| Error in .Primitive(".Call")(<pointer: 0x0000000069d42560>, param, x,  : 
|   negative length vectors are not allowed
| 
| All the inputs are valid and work fine with the R version. So I don't know
| where this is coming from? I put a bunch of couts and I know that it is
| happening inside the for loop but don't know why. In general, what is the best
| way to debug code written this way? I am using RStudio.
| 
| 2) I don't know how to transpose the matrix in rCpp. I read that I could that
| using rCppArmadillo, but then I don't know how to convert from NumericMatrix to
| arma matrix. I don't want to copy as this operation will happen 1000x of times,
| so this has to be fast.
| 
| 3) I don't know how to randomly shuffle the rows. I tried RcppArmadillo::
| sample but haven't gotten the output to work. E.g. do I access elements as x
| (rowOrd[curIdx],_)?
| 
| 4) (minor issue) How do I add the bias unit? In other words, add a new column
| to the input matrix filled with all 1s. Do I have to create a new matrix, copy
| it column by column? this is not a dealbreaker since I can do this in R before
| I send in the inputs.
| 
| Sorry if my questions are too basic and don't seem well researched. I am trying
| to go for a practical example. 

You are trying too much at once. Attack each issue separately. Some of what
you are after is basic, and there are plenty of examples for RcppArmadillo
out there -- not to mention over 50 CRAN packages using it.  It will help you
to study some of those.

Dirk

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list