[Rcpp-devel] row iterators in RcppArmadillo

Dirk Eddelbuettel edd at debian.org
Thu Oct 13 00:34:41 CEST 2016


On 12 October 2016 at 15:27, Sokol Serguei wrote:
| May be the problem is that you are trying to use std::copy for writing
| to non contiguous memory when you use a row pointer and the class writers
| were smart enough to prevent such situation.
| 
| The following code works as expected, may be it can do the job for you:
| 
| cppFunction('void copy2(arma::rowvec& v, arma::mat& d1, arma::mat& d2) {
|         d1.row(0)=v(arma::span(0,2));
|         d2.row(0)=v(arma::span(3,5));
| }', depends = "RcppArmadillo")
| 
| v <- runif(6)
| d1 <- matrix(0.0, 3,3)
| d2 <- matrix(0.0, 3,3)
| copy2(v, d1, d2)

Thanks for taking the time to create an example -- this os pretty much what I
was advocating too.

Dirk

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


More information about the Rcpp-devel mailing list