Skip to content

Commit 09d9b45

Browse files
committed
Merge branch 'devel' of github.com:nimble-dev/nimble into devel
2 parents e9ca8e5 + 2e64b61 commit 09d9b45

4 files changed

Lines changed: 38 additions & 9 deletions

File tree

packages/nimble/R/genCpp_generateCpp.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ cppOutputNimDerivsPrependType <- function(code, symTab){
196196
for(i in seq_along(code$args)){
197197
iArg <- code$args[[i]]
198198
iName <- names(code$args)[i]
199-
if(iName == 'log' && (is.numeric(iArg) | is.logical(iArg))){
199+
if(isTRUE(iName == 'log' && (is.numeric(iArg) || is.logical(iArg)))) {
200200
logFixedString <- '_logFixed'
201201
argList[[length(argList) + 1]] <- nimGenerateCpp(iArg, symTab,
202202
asArg = TRUE)

packages/nimble/R/genCpp_sizeProcessing.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,9 @@ sizeConcatenate <- function(code, symTab, typeEnv) { ## This is two argument ver
577577
## overall strategy is to separate runs of scaalrs and non-scalars
578578
## also in C++ we don't take arbitrary arguments. Instead we chain together calls in groups of 4
579579
## e.g. c(a1, a2, a3, a4, a5) will become c( c(a1, a2, a3, a4), a5)
580+
581+
if(!length(code$args))
582+
stop("`c()` must have at least one argument")
580583

581584
## first puzzle is with nimC(scalar1, scalar2, vector1, scalar3)
582585
## we need to extract the runs of scalars like (scalar1, scalar2), so they can be packed up in an object together.
@@ -2719,6 +2722,12 @@ sizeIndexingBracket <- function(code, symTab, typeEnv) {
27192722
## This is deprecated:
27202723
if(code$args[[1]]$type == 'symbolNumericList') return(c(asserts, sizemvAccessBracket(code, symTab, typeEnv)))
27212724

2725+
minuses <- sapply(code$args, function(x) inherits(x, 'exprClass') &&
2726+
exists('name', x) && x$name == "-")
2727+
if(any(minuses))
2728+
if(any(sapply(code$args[minuses], function(x) length(x$args) == 1)))
2729+
stop("use of 'minus' indexing found in `", safeDeparse(code$expr), "` cannot be compiled")
2730+
27222731
## Iterate over arguments, lifting any logical indices into which()
27232732
## e.g. X[i, bool] becomes X[i, Interm1], with Interm1 <- which(bool) as an assert.
27242733
for(i in seq_along(code$args)) {

packages/nimble/R/parameterTransform.R

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ parameterTransform <- nimbleFunction(
245245
## argument values(model, nodes), return vector on unconstrained scale
246246
transformed <- nimNumeric(tLength)
247247
if(nNodes == 0) return(transformed)
248+
iNode <- 1L; i <- 1L; j <- 1L; dd <- 1L; pp <- 1L ## integer types
248249
for(iNode in 1:nNodes) {
249250
theseValues <- nodeValuesFromModel[transformData[iNode,NIND1]:transformData[iNode,NIND2]]
250251
thisType <- transformType[iNode]
@@ -263,14 +264,14 @@ parameterTransform <- nimbleFunction(
263264
## DT: there has to be a better way to do this procedure, below,
264265
## creating the vector of the log-Cholesky transformed values.
265266
theseTransformed <- nimNumeric(transformData[iNode,DATA2])
266-
tInd <- 1
267+
tInd <- 1L
267268
for(j in 1:dd) {
268269
for(i in 1:dd) {
269-
if(i==j) { theseTransformed[tInd] <- log(U[i,j]); tInd <- tInd+1 }
270-
if(i< j) { theseTransformed[tInd] <- U[i,j]; tInd <- tInd+1 } } }
270+
if(i==j) { theseTransformed[tInd] <- log(U[i,j]); tInd <- tInd+1L }
271+
if(i< j) { theseTransformed[tInd] <- U[i,j]; tInd <- tInd+1L } } }
271272
},
272273
{ ## 8: multivariate dirichlet
273-
dd <- transformData[iNode,DATA1] - 1
274+
dd <- transformData[iNode,DATA1] - 1L
274275
theseTransformed <- nimNumeric(dd)
275276
theseTransformed[1] <- logit( theseValues[1] )
276277
if(dd > 1) {
@@ -287,21 +288,21 @@ parameterTransform <- nimbleFunction(
287288
theseTransformed <- nimNumeric(pp)
288289
theseValuesMatrix <- nimArray(theseValues, dim = c(dd, dd)) # U in matrix form
289290
if(dd > 1) {
290-
cnt <- 1
291+
cnt <- 1L
291292
## Length of each column of U is 1.
292293
## We first produce the canonical partial correlations and then apply atanh()
293294
## to make the unconstrained parameters..
294295
for(j in 2:dd) {
295296
theseTransformed[cnt] <- atanh(theseValuesMatrix[1, j])
296-
cnt <- cnt + 1
297+
cnt <- cnt + 1L
297298
if(j > 2) {
298299
partialSum <- 1
299300
for(i in 2:(j-1)) {
300301
partialSum <- partialSum - theseValuesMatrix[i-1, j]^2
301302
## Transformed value is atanh of the proportion of the
302303
## remaining correlation (which is in 'partialSum').
303304
theseTransformed[cnt] <- atanh(theseValuesMatrix[i, j] / sqrt(partialSum))
304-
cnt <- cnt + 1
305+
cnt <- cnt + 1L
305306
}
306307
}
307308
}
@@ -470,6 +471,6 @@ parameterTransform <- nimbleFunction(
470471
return(lp)
471472
}
472473
),
473-
buildDerivs = list(inverseTransform = list(),
474+
buildDerivs = list(inverseTransform = list(), transform = list(),
474475
logDetJacobian = list(ignore = c('iNode','j','dd','ddm1','i')))
475476
)

packages/nimble/tests/testthat/test-user.R

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,25 @@ test_that("conflicted nimbleFunction names trapped", {
11101110

11111111
})
11121112

1113+
test_that("Error trap 'minus' indexing.", {
1114+
testMinusIdx <- nimbleFunction(
1115+
run = function(x = double(0)) {
1116+
ans <- x[-3]
1117+
return(ans)
1118+
returnType(double(1))
1119+
} )
1120+
expect_error(cf <- compileNimble(testMinusIdx), "use of 'minus' indexing")
1121+
1122+
testMinusIdx <- nimbleFunction(
1123+
run = function(x = double(2)) {
1124+
ans <- x[5, -c(1,4)]
1125+
return(ans)
1126+
returnType(double(1))
1127+
} )
1128+
expect_error(cf <- compileNimble(testMinusIdx), "use of 'minus' indexing")
1129+
})
1130+
1131+
11131132
nimbleOptions(allowNFobjInModel = currentOption)
11141133

11151134
nimbleOptions(verbose = nimbleVerboseSetting)

0 commit comments

Comments
 (0)