Skip to content

Summary of core R features implemented Fall 2016

perrydv edited this page Feb 8, 2017 · 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 ':'

  • Check the case when from and to are both integers but by is not 1
  • Negative integer sequences (2:1) need to be implemented.

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:
  • logical() is flagged by checkDSL as a possible problem - FIXME
  • 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.
  • Check on LHS of 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

type-casting in vectorized arithmetic and linear algebra

  • e.g. for Y <- A + B, if A is an integer vector and B is a double vector, Eigen needs A cast to double. NIMBLE now does that.
  • Some cases still need testing.

return dim() as an integer vector

  • This works

Not yet implemented (short list of immediate priorities):

  • single indexing when dimensionality > 2. e.g. mymatrix[2]
  • 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