Skip to content

Summary of core R features implemented Fall 2016

perrydv edited this page Dec 7, 2016 · 13 revisions

This page is a summary of implementation of some core R features into NIMBLE, allowing automatic compilation to C++.

c()

  • This works, including:
    • flattening of objects with dimension > 2
    • promotion of types with double > integer > logical in priority. e.g. c(TRUE, 1.2) returns a double vector (1, 1.2)

rep()

  • This works, including
    • scalar times, scalar each, scalar length.out
    • vector times

seq() and ':'

  • This works with the following exception:
    • if arguments from, by and length.out are given, rep() does not work. This will be fixed.

which()

  • This works.
  • arr.ind argument does not work (nor does useNames)

initialization of matrix() with a non-scalar

  • This works. array() can still be initialized only with a scalar.

creating non-scalar logical objects

  • This works. At the moment:
  • the "not" operator ("!") does not work.
  • we need to look into & vs && and | vs ||. These will be fixed.

indexing by arbitrary index vectors and logical vectors

  • This works for vectors and matrices.
  • Negative indices (to indicate all elements except the negative values) do not work.
  • drop cannot be a variable. It must TRUE or FALSE, known at compile-time.
  • For objects with dimension > 2, NIMBLE still only supports sequential integer indexing specified using ":"
  • In R, if an index vector contains a "0", the result will not include a value corresponding to that index. In NIMBLE, a "0" is not allowed in an index vector.
  • Does not work on LHS of "r" dist calls, getParam, or values

diag()

  • This works in all three usages:
    • diag(vector) returns a matrix.
    • diag(matrix) returns a vector.
    • diag(scalar) returns an identity matrix of size scalar x scalar.

vectorized distribution functions

  • All distribution functions ("d", "p", "q", and "r" functions) now support R's recycling rule. This means the size of the return object will be the maximum size of the arguments, and other arguments will be re-used in order as much as needed.
  • An important difference: In R, the dimension of the return object is the dimension of the largest argument. In NIMBLE, the number of dimensions of the return object must be determined at compile-time, so it is always a vector or a scalar.
  • rt_nonstandard needs attention

Not yet implemented (short list of immediate priorities):

  • Return of a vector from dim(X). Right now only dim(X)[i] works, i.e. immediately pulling out a needed scalar.
  • Type casting in vectorized arithmetic. Right now Y <- A + B, if A is an integer vector and B is a double vector will not work.
  • rbind, cbind, append
  • for(i in X) where X can be arbitrary. Right now X can only be sequential integers specified by ':'
  • component-wise arithmetic in > 2 dimensions

Clone this wiki locally