<div dir="ltr">Hi,<div><br></div><div>I think you can/should use std::complex, see for example the types used in</div><div><br></div><div><a href="https://github.com/baptiste/rcppfaddeeva/blob/master/src/callFaddeeva.cpp">https://github.com/baptiste/rcppfaddeeva/blob/master/src/callFaddeeva.cpp</a> </div><div><br></div><div>In general I prefer to work with RcppArmadillo for numerical (including complex) computations, its syntax closely follows R and Matlab. See for instance </div><div><br></div><div><a href="https://github.com/baptiste/cda/blob/master/src/cda.cpp">https://github.com/baptiste/cda/blob/master/src/cda.cpp</a></div><div><a href="https://github.com/baptiste/planar/blob/master/src/fresnel.cpp">https://github.com/baptiste/planar/blob/master/src/fresnel.cpp</a><br></div><div><br></div><div>for some examples.</div><div><br></div><div>HTH,</div><div><br></div><div>baptiste</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 22 February 2017 at 04:46, Martin S Ridout <span dir="ltr"><<a href="mailto:M.S.Ridout@kent.ac.uk" target="_blank">M.S.Ridout@kent.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div dir="ltr" style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif">
<p></p>
<div>Apologies if this is a naive  question - I'm a beginner with Rcpp.  I did see some earlier discussion on similar topic, but I don't think it answered my questions. </div>
<div><br>
</div>
<div>I am trying (on Windows) to speed up a function currently written in R. This works very well for real-valued arguments of the function. But it needs to work for complex arguments as well. Here is a stripped down (but still non-working) example of what I
 am trying to do <br>
</div>
<div><br>
</div>
<div>cppFunction('</div>
<div>  ComplexVector test(ComplexVector s, ComplexVector lambda) {</div>
<div><br>
</div>
<div>    int n = s.size();<br>
</div>
<div>    int m = lambda.size();</div>
<div>    ComplexVector out(n);<br>
</div>
<div><br>
</div>
<div>    for (int i=0; i < n; ++i) {<br>
</div>
<div>      for (int j=0; j < m; ++j) {<br>
</div>
<div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px">
         out[i] = out[i] - log(s[i] + 1/lambda[j]) / 2; </div>
<div><span style="font-size:12pt">      }</span><br>
</div>
</div>
<div>    }<br>
</div>
<div>    return out;</div>
<div>  }<br>
</div>
<div>')</div>
<div><br>
</div>
<div><span style="font-size:12pt">I have (at least) 2 problems</span><br>
</div>
<div><br>
</div>
<div>i) Are the logarithm and exponential functions implemented for complex arguments? If not is there a work-around?<br>
</div>
<div><br>
</div>
<div>ii) What is the best way to specify constants like 1 and 2  as complex constants? This must be easy, but everything I tried so far gives an error (except passing them into the function via an extra ComplexVector argument, but there must be a better way). </div>
<div><br>
</div>
<div>Many thanks for any help,</div>
<div>Martin Ridout<br>
</div>
<p><br>
</p>
</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>