dirkschumacher / armacmp

🚀 Automatically compile linear algebra R code to C++ with Armadillo

Home Page:https://dirkschumacher.github.io/armacmp/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support <<-

dirkschumacher opened this issue · comments

Not sure if I should introduce <<-. Currently the semantic of <- is slightly different to R as it can also be used to assign values to variables that have been defined in an upper environment.

Avoid doing anything with global assignment. Allow the translation to fail in this case. This is asking for a world of hurt.

If you look at the recursive implementation of the julia qsort benchmark, the <<- operator is actually needed to run it correctly in R. In armacmp the usual assignment operators works.

But for now I will leave the issue open, but won't implement it.

qsort_r = function(a) {
  qsort_kernel = function(lo, hi) {
    i = lo
    j = hi
    while (i < hi) {
      pivot = a[floor((lo+hi)/2)]
      while (i <= j) {
        while (a[i] < pivot) i = i + 1
        while (a[j] > pivot) j = j - 1
        if (i <= j) {
          t = a[i]
          a[i] <<- a[j]
          a[j] <<- t
          i = i + 1;
          j = j - 1;
        }
      }
      if (lo < j) qsort_kernel(lo, j)
      lo = i
      j = hi
    }
  }
  qsort_kernel(1, length(a))
  return(a)
}