<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <div class="moz-cite-prefix">HI,</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">I cannot help with your bug. However...</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">Le 19/08/2021 à 04:17, Naeem Khoshnevis
      a écrit :<br>
    </div>
    <blockquote type="cite"
cite="mid:CAKOOZvMwbLkVbF7YKNmiSu9rXW28my-yXVRF_JHfaru4i3FLXA@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">Dear
            all, </span></p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><br>
        </p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">I wrote
            a function using Rcpp; it is a simple function; however, it
            significantly improves the performance.</span></p>
      </div>
    </blockquote>
    <p>Compared to what? The same algorithm with plenty for-loop
      re-written in R? Then sure, it will improve the performance.</p>
    <p>But what your algorithm does can be expressed as one-liner in R:</p>
    <p>      out=apply(abs(outer(a,b,"-"))*sc+cd, 2, which.min)</p>
    <p>It should be also much more performant then R code with for-loop
      everywhere (though not so performant as C++ code).<br>
    </p>
    <p>Oh, and it will not require a whole package to do the job.</p>
    <p>Best,<br>
      Serguei.<br>
    </p>
    <blockquote type="cite"
cite="mid:CAKOOZvMwbLkVbF7YKNmiSu9rXW28my-yXVRF_JHfaru4i3FLXA@mail.gmail.com">
      <div dir="ltr">
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt"> I
            realized that on some systems, the result of the function is
            different from others. </span></p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><br>
        </p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">For
            example, on the following systems (on rhub), the results are
            identical and are correct:</span></p>
        <ul
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt">
          <li
style="background:transparent;margin-top:0pt;margin-bottom:0pt;list-style-type:disc"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">Fedora
              Linux, R-devel, clang, gfortran (fedora-clang-devel)  </span></li>
          <li
style="background:transparent;margin-top:0pt;margin-bottom:0pt;list-style-type:disc"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">macOS
              10.13.6 High Sierra, R-release, brew
              (macos-highsierra-release)</span></li>
          <li
style="background:transparent;margin-top:0pt;margin-bottom:0pt;list-style-type:disc"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">Windows
              Server 2008 R2 SP1, R-devel, 32/64 bit
              (windows-x86_64-devel)</span></li>
        </ul>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">However,
            on the following systems (on rhub), the results are
            different:</span></p>
        <ul
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt">
          <li
style="background:transparent;margin-top:0pt;margin-bottom:0pt;list-style-type:disc"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt"> Ubuntu
              Linux 20.04.1 LTS, R-devel, GCC (ubuntu-gcc-devel)</span></li>
        </ul>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><br>
        </p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">Here is
            the error:</span></p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><br>
        </p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">Running
            the tests in ‘tests/testthat.R’ failed.</span></p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">   Last
            13 lines of output:</span></p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">   
             val[1] not equal to 4.</span></p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">     1/1
            mismatches</span></p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">     [1]
            2 - 4 == -2</span></p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">     ──
            Failure (test-compute_closest_wgps_helper.R:12:3):
            compute_closest_wgps_helper works as expected. ──</span></p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">   
             val[3] not equal to 3.</span></p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">     1/1
            mismatches</span></p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">     [1]
            1 - 3 == -2</span></p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">     ──
            Failure (test-compute_closest_wgps_helper.R:13:3):
            compute_closest_wgps_helper works as expected. ──</span></p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">   
             val[4] not equal to 1.</span></p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">     1/1
            mismatches</span></p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">     [1]
            2 - 1 == 1</span></p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">     </span></p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">     [
            FAIL 3 | WARN 0 | SKIP 0 | PASS 69 ]</span></p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><br>
        </p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">As much
            as I can check the code, it looks correct. But I am not sure
            what else I can check. Some package users claimed that
            different R versions provide different results; however, I
            checked it on r-base=3.6, 4.0, 4.1 and received the same
            correct results (macOS 11.2). </span></p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">I would
            be grateful if you could let me know your thoughts about
            this issue.</span></p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><br>
        </p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">Here is
            the source code:</span></p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt"><a
href="https://github.com/fasrc/CausalGPS/blob/97342ecc90fd20f2c7c4458a70aefe471b09510c/src/compute_closest_wgps_helper.cpp"
              moz-do-not-send="true">https://github.com/fasrc/CausalGPS/blob/97342ecc90fd20f2c7c4458a70aefe471b09510c/src/compute_closest_wgps_helper.cpp</a></span></p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><br>
        </p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">Here is
            the related test:</span></p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt"><a
href="https://github.com/fasrc/CausalGPS/blob/97342ecc90fd20f2c7c4458a70aefe471b09510c/tests/testthat/test-compute_closest_wgps_helper.R"
              moz-do-not-send="true">https://github.com/fasrc/CausalGPS/blob/97342ecc90fd20f2c7c4458a70aefe471b09510c/tests/testthat/test-compute_closest_wgps_helper.R</a></span></p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><br>
        </p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><br>
        </p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">Best
            regards,</span></p>
        <p
style="color:rgb(14,16,26);background:transparent;margin-top:0pt;margin-bottom:0pt"><span
style="background:transparent;margin-top:0pt;margin-bottom:0pt">Naeem
            Khoshnevis</span></p>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-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>
  </body>
</html>