Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/nimble/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Collate:
genCpp_buildIntermediates.R
genCpp_processSpecificCalls.R
genCpp_sizeProcessing.R
genCpp_toEigenize.R
genCpp_insertAssertions.R
genCpp_maps.R
genCpp_liftMaps.R
Expand Down
5 changes: 5 additions & 0 deletions packages/nimble/R/RCfunction_compile.R
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,15 @@ RCfunProcessing <- setRefClass('RCfunProcessing',
browser()
}

if(nimbleOptions('experimentalNewSizeProcessing')) {
exprClasses_setToEigenize(compileInfo$nimExpr, compileInfo$newLocalSymTab, compileInfo$typeEnv)
}

tryResult <- try(exprClasses_insertAssertions(compileInfo$nimExpr))
if(inherits(tryResult, 'try-error')) {
stop(paste('There is some problem at the insertAdditions processing step for this code:\n', paste(deparse(compileInfo$origRcode), collapse = '\n'), collapse = '\n'), call. = FALSE)
}

if(debug) {
print('compileInfo$nimExpr$show(showAssertions = TRUE)')
compileInfo$nimExpr$show(showAssertions = TRUE)
Expand Down
54 changes: 41 additions & 13 deletions packages/nimble/R/all_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,48 @@

double <- function(ndim, dims) {}

labelFunctionCreator <- function(lead, start = 1) {
nextIndex <- start
force(lead)
labelGenerator <- function(reset = FALSE, count = 1, envName = "") {
if(reset) {
nextIndex <<- 1
return(invisible(NULL))
## Sequential label generation system:
## labelFunctionMetaCreator returns a function that returns a function.
## labelFunctionMetaCreator is only called once, immediately below, to create labelFunctionCreator
## The outer layer allows allLabelFunctionCreators to be in the closure of every function returned
## by labelFunctionCreator. Each of those functions is registered as an element of allLableFunctionCreators.
##
## This scheme allows the function resetLabelFunctionCreators below to work simply,
## resetting the count to 1 for all of the label generators.
##
## The motivation for resetLabelFunctionCreators is for testing: If we want to check
## that two pathways to code generation (one existing, one experimental) create identical
## code, it is helpful to have identical generated labels. Resetting all label generators
## supports this goal.
labelFunctionMetaCreator <- function() {
allLabelFunctionCreators <- list()

creatorFun <- function(lead, start = 1) {
nextIndex <- start
force(lead)
labelGenerator <- function(reset = FALSE, count = 1, envName = "") {
if(reset) {
nextIndex <<- 1
return(invisible(NULL))
}
lead <- paste(lead, envName , sep = '_')
ans <- paste0(lead, nextIndex - 1 + (1:count))
nextIndex <<- nextIndex + count
ans
}
allLabelFunctionCreators[[ length(allLabelFunctionCreators) + 1 ]] <<- labelGenerator
labelGenerator
}
creatorFun
}

labelFunctionCreator <- labelFunctionMetaCreator()

resetLabelFunctionCreators <- function() {
allLabelFunctionCreators <- environment(labelFunctionCreator)$allLabelFunctionCreators
for(i in allLabelFunctionCreators) {
i(reset = TRUE)
}
lead <- paste(lead, envName , sep = '_')
ans <- paste0(lead, nextIndex - 1 + (1:count))
nextIndex <<- nextIndex + count
ans
}
labelGenerator
}

nimbleUniqueID <- labelFunctionCreator("UID")
Expand Down
1 change: 0 additions & 1 deletion packages/nimble/R/cppDefs_RCfunction.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ RCfunctionDef <- setRefClass('RCfunctionDef',

if(is.character(SEXPinterfaceCname) && is.null(dll) && eval) {
warning("creating a .Call() expression with no DLL information")
browser()
}

# avoid R CMD check problem with registration
Expand Down
13 changes: 7 additions & 6 deletions packages/nimble/R/genCpp_exprClass.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ exprClass <- setRefClass('exprClass',
sizeExprs = 'ANY', #'list', ## a list of size expressions (using R parse trees for each non-numeric expression
type = 'ANY', #'character', ## type label
args = 'ANY', #'list', ## list of exprClass objects for the arguments
eigMatrix = 'ANY', #'logical', ## vs. Array. Only used for Eigenized expressions
toEigenize = 'ANY', #'character', ##'yes', 'no', or 'maybe'
caller = 'ANY', ## exprClass object for the call to which this is an argument (if any)
callerArgID = 'ANY', #'numeric', ## index in the calling object's args list for this object.
assertions = 'ANY', #'list'
cppADCode = 'ANY' #'logical ## is expr in code generated for cppad?
eigMatrix = 'ANY', #'logical', ## vs. Array. Only used for Eigenized expressions
toEigenize = 'ANY', #'character', ##'yes', 'no', or 'maybe'
caller = 'ANY', # exprClass object for the call to which this is an argument (if any)
callerArgID = 'ANY', #'numeric', ## index in the calling object's args list for this object.
assertions = 'ANY', #'list'
cppADCode = 'ANY', #'logical' ## is expr in code generated for cppad?
aux = 'ANY' # anything needed for specific operators
),
methods = list(
initialize = function(...) {sizeExprs <<- list(); args <<- list();toEigenize <<- 'unknown';assertions <<- list(); eigMatrix <<- logical(); cppADCode <<- FALSE; callSuper(...)},
Expand Down
2 changes: 1 addition & 1 deletion packages/nimble/R/genCpp_insertAssertions.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ exprClasses_insertAssertions <- function(code) {
if(length(code$args[[i]]$assertions) > 0) {
toInsert <- lapply(code$args[[i]]$assertions, function(x) if(inherits(x, 'exprClass')) x else RparseTree2ExprClasses(x))
before <- unlist(lapply(toInsert, function(x) {if(x$name == 'after') FALSE else TRUE}))

if(nimbleOptions('experimentalNewSizeProcessing')) code$args[[i]]$assertions <- list() ## Clear assertions field so it can be used by later compiler stages
newExpr <- newBracketExpr(args = c(lapply(toInsert[before], ## assertions will be inserted recursively IF they are in {}
function(z) {exprClasses_insertAssertions(z); z}),
code$args[i],
Expand Down
Loading