You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there! I ran into this problem, fixed it, and subsequently read that nimble functions don't handle negative indices, as in R. Indeed, in a function more complex than the reproduceable example below (a custom sampler), I received an error when indexing by x[-d] where d = length(x). Here's the specific error returned on compilation:
Error:
Error: NIMBLE compiler does not support reduction operations on scalar arguments.
This occurred for: sum(x_next[-(d)])
This was part of the call: totTime - sum(x_next[-(d)])
However, the function compiled successfully and happily returned a wrong result when using x[-c(i,d)] where i is a for loop index. I only caught this error because results did not match my sampler implemented in R, but I could see how it might go unnoticed or be difficult to debug in some cases. So I'm flagging this as a potential candidate for a stop-execution error trap that doesn't return a result, similar to the error message above.
Below is a simple case reproducing the error. I'm using nimble v1.3.0.
testNegIdx <- nimbleFunction( run = function(x = double(1)) { ans <- x[-c(1,4)] return(ans) returnType(double(1)) } )
Should return c(2, 3), and does. x <- 1:4
testNegIdx(x)
[1] 2 3
Test compiled version
`CtestNegIdx <- compileNimble(testNegIdx)
Indeed in both the x[-2] and x[-c(2,4)] cases we should error trap. Furthermore, it doesn't look to me that we mention this lack of functionality in the manual.
Let's consider putting a check for - in sizeIndexingBracket. It looks like we could simply check for - in code$args, e.g,
Hi there! I ran into this problem, fixed it, and subsequently read that nimble functions don't handle negative indices, as in R. Indeed, in a function more complex than the reproduceable example below (a custom sampler), I received an error when indexing by
x[-d]
whered = length(x)
. Here's the specific error returned on compilation:However, the function compiled successfully and happily returned a wrong result when using
x[-c(i,d)]
wherei
is afor
loop index. I only caught this error because results did not match my sampler implemented in R, but I could see how it might go unnoticed or be difficult to debug in some cases. So I'm flagging this as a potential candidate for a stop-execution error trap that doesn't return a result, similar to the error message above.Below is a simple case reproducing the error. I'm using nimble v1.3.0.
testNegIdx <- nimbleFunction(
run = function(x = double(1)) {
ans <- x[-c(1,4)]
return(ans)
returnType(double(1))
} )
Should return c(2, 3), and does.
x <- 1:4
Test compiled version
`CtestNegIdx <- compileNimble(testNegIdx)
Not c(2,3) and returns different values each time it's called.
The text was updated successfully, but these errors were encountered: