<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body smarttemplateinserted="true" text="#000000" bgcolor="#FFFFFF">
    <div id="smartTemplate4-quoteHeader">Hi Jonathan,<br>
      <br>
      Jonathan Fintzi has written at  Wed, 12 Oct 2016 13:43:20 -0700</div>
    <blockquote
cite="mid:CAJxst-PONjo66S7H16ViPmewD3USOLiZ6Y0BNhsSPxs=KM-Q4A@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>
          <div>
            <div>
              <div>
                <div>Hello,<br>
                  <br>
                </div>
                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:<br>
                <br>
                cppFunction('void copyinto(Rcpp::NumericVector& v,
                arma::mat& d1, arma::mat& d2) {<br>
                        std::copy(v.begin(), v.begin() + 3,
                d1.begin_row(0));<br>
                        std::copy(v.begin() + 3, v.end(),
                d2.begin_row(0));<br>
                }', depends = "RcppArmadillo")<br>
                <br>
              </div>
              <div>v <- runif(6)<br>
              </div>
              <div>d1 <- matrix(0.0, 3,3)<br>
              </div>
              <div>d2 <- matrix(0.0, 3,3)<br>
                <br>
              </div>
              <div>copyinto(v, d1, d2)<br>
              </div>
              <div><br>
              </div>
              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. <br>
              <br>
            </div>
            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. <br>
          </div>
        </div>
      </div>
    </blockquote>
    May be the problem is that you are trying to use std::copy for
    writing<br>
    to non contiguous memory when you use a row pointer and the class
    writers<br>
    were smart enough to prevent such situation.<br>
    <br>
    The following code works as expected, may be it can do the job for
    you:<br>
    <br>
    cppFunction('void copy2(arma::rowvec& v, arma::mat& d1,
    arma::mat& d2) {<br>
            d1.row(0)=v(arma::span(0,2));<br>
            d2.row(0)=v(arma::span(3,5));<br>
    }', depends = "RcppArmadillo")<br>
    <br>
    v <- runif(6)<br>
    d1 <- matrix(0.0, 3,3)<br>
    d2 <- matrix(0.0, 3,3)<br>
    copy2(v, d1, d2)<br>
    <br>
    <blockquote
cite="mid:CAJxst-PONjo66S7H16ViPmewD3USOLiZ6Y0BNhsSPxs=KM-Q4A@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>
          <div><br>
          </div>
          Thank you for your help!<br>
        </div>
        Jon<br>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Rcpp-devel mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a>
<a class="moz-txt-link-freetext" href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a></pre>
    </blockquote>
    <p><br>
    </p>
    <br>
    <br>
    <div id="smartTemplate4-template">
      <p> </p>
    </div>
  </body>
</html>