<div dir="ltr">Hello, everyone. <div>I guess the probrem maybe occur because of sourceCpp(), so I have made another test. I make a simple package using RcppArmadillo.package.skeletion(). </div><div>But the same problem appear.</div>
<div>My code is on Github:</div><div><a href="https://github.com/ZhangYet/RcppTest">https://github.com/ZhangYet/RcppTest</a></div><div>Is there anything related to my compiler or OS? I use 64-bit CentOS and g++ 4.4.5</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Jan 18, 2014 at 2:01 AM, 张晔 <span dir="ltr"><<a href="mailto:zhangyet@gmail.com" target="_blank">zhangyet@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks, Dirk.<br>
I have upload my code to Github: <a href="https://github.com/ZhangYet/RcppTest/" target="_blank">https://github.com/ZhangYet/<u></u>RcppTest/</a><br>
And I made a mistake:<div class="im"><br>
<br>
| res1 <- mydcov(x,y)/sqrt(mydcov(x,x)*<u></u>mydcov(y,y))<br>
|<br>
| a <- mydcov(x,y)<br>
| b <- mydcov(x,x)<br>
| c <- mydcov(y,y)<br>
| res2 <- a/sqrt(b*c)<br>
|<br>
| and res2 is different from res1.(res2 is the right answer.)<br>
<br></div>
I checked my test result. res2 is not the right answer, but it's different from res.<br>
<br>
于 2014/1/17 21:36, Dirk Eddelbuettel 写道:<div class="HOEnZb"><div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 17 January 2014 at 20:51, 晔张 wrote:<br>
| Dear all,<br>
|<br>
| I have a strange question such that I can't conclude it in the title.<br>
| I have write an function:<br>
| //[[Rcpp::export]]<br>
| double mydcov(NumericVector x, NumericVector y)<br>
<br>
It would help us to see the function to have any guess at what may be wrong.<br>
  | This function is computing  ditance covariance. This function is OK. It give<br>
| the right answer.<br>
| I use this function to compute distance correltion.<br>
|<br>
| //[[Rcpp::export]]<br>
| double mydcor(NumericVector x, NumericVector y)<br>
| {<br>
|     return mydcov(x,y)/sqrt(mydcov(x,x)*<u></u>mydcov(y,y));<br>
| }<br>
|<br>
| Then, I compile the source code using sourceCpp.<br>
| And then mydcor(x,y) give a wrong answer.<br>
|<br>
| Here comes the strange part:<br>
| In R, I run code as follow<br>
|<br>
| res1 <- mydcov(x,y)/sqrt(mydcov(x,x)*<u></u>mydcov(y,y))<br>
|<br>
| a <- mydcov(x,y)<br>
| b <- mydcov(x,x)<br>
| c <- mydcov(y,y)<br>
| res2 <- a/sqrt(b*c)<br>
|<br>
| and res2 is different from res1.(res2 is the right answer.)<br>
|<br>
| And I have another test, rewriting the source code for mydcor():<br>
| version1:<br>
| //[[Rcpp::export]]<br>
| double mydcor(NumericVector x, NumericVector y)<br>
| {<br>
|     double a = mydcov(x,y)<br>
|     double b = mydcov(x,x);<br>
|     double c = mydcov(y,y);<br>
|     return (a/sqrt(b*c));<br>
| }<br>
|<br>
| version2:<br>
| //[[Rcpp::export]]<br>
| double mydcor(NumericVector x, NumericVector y)<br>
| {<br>
|     double a = mydcov(x,y)<br>
|     Rcout<<a<<"\n";<br>
|     double b = mydcov(x,x);<br>
|     Rcout<<b<<"\n";<br>
|     double c = mydcov(y,y);<br>
|     Rcout<<c<<"\n"<br>
|     return (a/sqrt(b*c));<br>
| }<br>
| This time, version2 make a right answer.<br>
| It's too weird. I havn't meet such situation before.<br>
<br>
I am not sure we are in a position to help you here.<br>
<br>
Regards, Dirk<br>
<br>
|<br>
| Happy Lunar New Year (the most important festival in China), and Thanks in<br>
| advance.<br>
|<br>
| Best regards<br>
| ZhangYet<br>
|<br>
| ------------------------------<u></u>------------------------------<u></u>----------<br>
| ______________________________<u></u>_________________<br>
| Rcpp-devel mailing list<br>
| <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">Rcpp-devel@lists.r-forge.r-<u></u>project.org</a><br>
| <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-<u></u>project.org/cgi-bin/mailman/<u></u>listinfo/rcpp-devel</a><br>
</blockquote>
<br>
</div></div></blockquote></div><br></div>