HI,

I cannot help with your bug. However...

Le 19/08/2021 à 04:17, Naeem Khoshnevis a écrit :

Dear all,


I wrote a function using Rcpp; it is a simple function; however, it significantly improves the performance.

Compared to what? The same algorithm with plenty for-loop re-written in R? Then sure, it will improve the performance.

But what your algorithm does can be expressed as one-liner in R:

      out=apply(abs(outer(a,b,"-"))*sc+cd, 2, which.min)

It should be also much more performant then R code with for-loop everywhere (though not so performant as C++ code).

Oh, and it will not require a whole package to do the job.

Best,
Serguei.

I realized that on some systems, the result of the function is different from others.


For example, on the following systems (on rhub), the results are identical and are correct:

  * Fedora Linux, R-devel, clang, gfortran (fedora-clang-devel)
  * macOS 10.13.6 High Sierra, R-release, brew (macos-highsierra-release)
  * Windows Server 2008 R2 SP1, R-devel, 32/64 bit (windows-x86_64-devel)

However, on the following systems (on rhub), the results are different:

  *  Ubuntu Linux 20.04.1 LTS, R-devel, GCC (ubuntu-gcc-devel)


Here is the error:


Running the tests in ‘tests/testthat.R’ failed.

   Last 13 lines of output:

 val[1] not equal to 4.

     1/1 mismatches

     [1] 2 - 4 == -2

     ── Failure (test-compute_closest_wgps_helper.R:12:3): compute_closest_wgps_helper works as expected. ──

 val[3] not equal to 3.

     1/1 mismatches

     [1] 1 - 3 == -2

     ── Failure (test-compute_closest_wgps_helper.R:13:3): compute_closest_wgps_helper works as expected. ──

 val[4] not equal to 1.

     1/1 mismatches

     [1] 2 - 1 == 1

     [ FAIL 3 | WARN 0 | SKIP 0 | PASS 69 ]


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).

I would be grateful if you could let me know your thoughts about this issue.


Here is the source code:

https://github.com/fasrc/CausalGPS/blob/97342ecc90fd20f2c7c4458a70aefe471b09510c/src/compute_closest_wgps_helper.cpp <https://github.com/fasrc/CausalGPS/blob/97342ecc90fd20f2c7c4458a70aefe471b09510c/src/compute_closest_wgps_helper.cpp>


Here is the related test:

https://github.com/fasrc/CausalGPS/blob/97342ecc90fd20f2c7c4458a70aefe471b09510c/tests/testthat/test-compute_closest_wgps_helper.R <https://github.com/fasrc/CausalGPS/blob/97342ecc90fd20f2c7c4458a70aefe471b09510c/tests/testthat/test-compute_closest_wgps_helper.R>



Best regards,

Naeem Khoshnevis


_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to