-
Notifications
You must be signed in to change notification settings - Fork 26
NIMBLE compiler
A nimbleFunction without setup code has simpler compilation, so we cover that first. Such a nimbleFunction is internally called an RCfunction. Relevant source code is in RCfunction_core.R and RCfunction_compiler.R
An RCfunction is represented by an object of class nfMethodRC. (This name reflects that the same class is used for methods (the default run method and any others) of nimbleFunctions that do have setup code.) The function definition returned by a call to nimbleFunction without a setup argument will have a nfMethodRC object called nfMethodRCobject in its environment. For example:
> myRCfun <- nimbleFunction(
run = function(x = double(1)) {
return(sum(x))
returnType(double())
}
)
> ls(environment(test))
## [1] "nfMethodRCobject"When the nfMethodRC object is initialized, several steps happen:
- The argument list is extracted and processed a bit for future use.
- A set of immediately required keyword replacements are made. These are typically of the form "nimPrint" instead of "print", "nimDim" instead of "dim", etc. This avoids later ambiguity with R functions of the same name, generally whose behavior NIMBLE tries to mimc. Programmers who prefer to use "nimPrint", "nimDim" etc. directly in their code may do so.
- The returnType() declaration is extracted from the body of the run code.
If the RCfunction was created via a call to nimbleFunction, which calls the function called RCfunction, then the nfMethodRC method generateFunctionObject is used to return an R function as shown above. This will have default values from the NIMBLE argument type declarations inserted correctly as default values in the R function that is returned. Only scalar default values are allowed in nimbleFunctions that will be compiled.