<div dir="ltr"><div><div><div>Hi Sokol,<br><br></div>Yes, that explains it. I ended up implementing the solution that you and Dirk identified, which is to simply convert the vector 'v' to an armadillo vector for the purpose of copying from it. <br></div><div><br></div>Thanks for the help!<br></div>Jon<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 12, 2016 at 3:27 PM, Sokol Serguei <span dir="ltr"><<a href="mailto:serguei.sokol@gmail.com" target="_blank">serguei.sokol@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div text="#000000" bgcolor="#FFFFFF">
    <div id="m_8669928549158982453smartTemplate4-quoteHeader">Hi Jonathan,<br>
      <br>
      Jonathan Fintzi has written at  Wed, 12 Oct 2016 13:43:20 -0700</div><span class="">
    <blockquote 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"<wbr>,
              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></span>
    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));<span class=""><br>
    }', depends = "RcppArmadillo")<br>
    <br>
    v <- runif(6)<br>
    d1 <- matrix(0.0, 3,3)<br>
    d2 <- matrix(0.0, 3,3)<br></span>
    copy2(v, d1, d2)<br>
    <br>
    <blockquote type="cite"><span class="">
      <div dir="ltr">
        <div>
          <div><br>
          </div>
          Thank you for your help!<br>
        </div>
        Jon<br>
      </div>
      <br>
      <fieldset class="m_8669928549158982453mimeAttachmentHeader"></fieldset>
      <br>
      </span><span class=""><pre>______________________________<wbr>_________________
Rcpp-devel mailing list
<a class="m_8669928549158982453moz-txt-link-abbreviated" href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">Rcpp-devel@lists.r-forge.r-<wbr>project.org</a>
<a class="m_8669928549158982453moz-txt-link-freetext" href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-<wbr>project.org/cgi-bin/mailman/<wbr>listinfo/rcpp-devel</a></pre>
    </span></blockquote>
    <p><br>
    </p>
    <br>
    <br>
    <div id="m_8669928549158982453smartTemplate4-template">
      <p> </p>
    </div>
  </div>

<br>______________________________<wbr>_________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-<wbr>project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" rel="noreferrer" target="_blank">https://lists.r-forge.r-<wbr>project.org/cgi-bin/mailman/<wbr>listinfo/rcpp-devel</a><br></blockquote></div><br></div>