[Rcpp-devel] row iterators in RcppArmadillo

Dirk Eddelbuettel edd at debian.org
Wed Oct 12 23:36:54 CEST 2016


Hi Jon,

On 12 October 2016 at 14:20, Jonathan Fintzi wrote:
| Thanks for the quick response. In the broader project, the vector being copied
| from is an Rcpp::NumericVector that contatenates vectorized versions of a
| number of other objects that are integrated numerically using the boost odeint
| solvers. I couldn't quite get the numerical integrators to play nice with
| Armadillo objects, and in using std::copy I was trying to avoid converting the
| vector 'v' to an arma::vec since I would have to convert it back for further
| integration. Perhaps this was a mistake?

Yes -- the transformation in as essentially costless.  We have some
benchmarking that show that.

| Still, I don't quite understand why armadillo row pointers don't work which
| armadillo column pointers are fine.

Now you phrase your question as "arma-only" (which makes sense) but that
is not what your code does, is it?

I see that you are having an issue mixing things. So I suggest an easy
simplification. You are of course free to ignore that -- but you may then
have to provide another layer as the compiler so far appears to be unhappy.

Dirk
 
| Thanks,
| Jon
| 
| On Wed, Oct 12, 2016 at 2:10 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
| 
|    
|     On 12 October 2016 at 13:43, Jonathan Fintzi wrote:
|     | Hello,
|     |
|     | I am trying to use the std::copy() function to copy elements from an
|     | Rcpp::NumericVector into rows of armadillo matrices. A simplified version
|     of my
|     | code is as follows:
|     |
|     | cppFunction('void copyinto(Rcpp::NumericVector& v, arma::mat& d1,
|     arma::mat&
|     | d2) {
|     |         std::copy(v.begin(), v.begin() + 3, d1.begin_row(0));
|     |         std::copy(v.begin() + 3, v.end(), d2.begin_row(0));
|     | }', depends = "RcppArmadillo")
| 
|     You should not need to mix an _Rcpp_ vector with an _Armadillo_ matrix
|     using
|     std::copy.  Check the decent Armadillo docs -- all the subsetting and
|     slicing
|     can be done with Armadillo.  And that is what I would do.
| 
|     But maybe I didn't quite understand what you are really after.
| 
|     Dirk
|    
|     | v <- runif(6)
|     | d1 <- matrix(0.0, 3,3)
|     | d2 <- matrix(0.0, 3,3)
|     |
|     | copyinto(v, d1, d2)
|     |
|     | However, when I attempt to compile the code, I receive a list of
|     compilation
|     | errors including "no type named 'XXXXXX' in 'class arma::Mat<double>
|     | row_iterator", where XXXXXX is iterator_category, value_type,
|     difference_type,
|     | pointer, and reference.
|     |
|     | If I change the iterators to column iterators (e.g. d1.begin_col(0))
|     everything
|     | compiles and works just fine. I feel that I must be missing something
|     quite
|     | basic here, but in searching around I haven't been able to identify my
|     mistake.
|     |
|     | Thank you for your help!
|     | Jon
|     | _______________________________________________
|     | Rcpp-devel mailing list
|     | Rcpp-devel at lists.r-forge.r-project.org
|     | https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
|    
|     --
|     http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
| 
| 

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


More information about the Rcpp-devel mailing list