<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  </head>
  <body text="#000000" bgcolor="#ffffff">
    Dear Rcpp experts, <br>
    <br>
    I have started to use the uBlas library, and I am trying to ensure
    that I can pass from uBlas vectors to Rcpp vectors relatively
    easily. So far, I have tried the following templated function: <br>
    <br>
///////////////////////////////////////////////////////////////////////<br>
    using namespace Rcpp; <br>
    using namespace boost::numeric::ublas; <br>
    <br>
    template &lt;class T1, class T2&gt; <br>
    T1 ublas2rcpp(T2&amp; uVec){<br>
    &nbsp;&nbsp;&nbsp; T1 rcppVec; <br>
    &nbsp;&nbsp;&nbsp; for(int i=0; i&lt;uVec.size(); ++i) rcppVec.push_back(uVec(i));
    <br>
    return rcppVec; <br>
    }//ublas2rcpp.<br>
    &nbsp;<br>
    ////////<br>
    SEXP foo(vector&lt;int&gt; &amp;y){<br>
    &nbsp; ...<br>
    &nbsp; IntegerVector rcppY=ublas2rcpp&lt;IntegerVector,vector&lt;int&gt;
    &gt;(y); <br>
    &nbsp; ....<br>
    return rcppY; <br>
    }<br>
///////////////////////////////////////////////////////////////////////<br>
    <br>
    I have got two questions: <br>
    a. This templated function doesn't work. It compiles fine, but hangs
    when I try to run it in R. What do you think is faulty in the codes
    above? <br>
    b. Is there a better way to wrap uBlas vectors into Rcpp ones? Is
    that something that you are planning to implement (or have already
    implemented) within the Rcpp suite?<br>
    <br>
    Thank you very much for your help, <br>
    <br>
    <div class="moz-signature">-- <br>
      <div class="moz-signature"><font face="Times" size="3">
          Cedric Ginestet, PhD <br>
          Centre for Neuroimaging Sciences (L3.04) <br>
          NIHR Biomedical Research Centre <br>
          Department of Neuroimaging <br>
          Institute of Psychiatry, Box P089 <br>
          King's College London <br>
          De Crespigny Park<br>
          London <br>
          SE5 8AF <br>
          <a class="moz-txt-link-freetext" href="http://arxiv.org/find/q-bio/1/au:+Ginestet_C/0/1/0/all/0/1">http://arxiv.org/find/q-bio/1/au:+Ginestet_C/0/1/0/all/0/1</a><br>
        </font>
      </div>
    </div>
  </body>
</html>