Skip to content

Fix compilation error with min/max under certain circumstances#1557

Merged
paciorek merged 4 commits into
develfrom
partial-fix-1533
Jul 10, 2025
Merged

Fix compilation error with min/max under certain circumstances#1557
paciorek merged 4 commits into
develfrom
partial-fix-1533

Conversation

@paciorek
Copy link
Copy Markdown
Contributor

In the following case, we have an untrapped error (see issue #1533):

code <- nimbleCode({
    x <- max(0,y-z)
})
m <- nimbleModel(code,inits=list(z=-1,y=5), buildDerivs=TRUE)
cm <- compileNimble(m)

It occurs with if(iName == 'log' && (is.numeric(iArg) | is.logical(iArg))) in cppOutputNimDerivsPrependType. When the condition after && is TRUE, this errors if iName is NULL. If condition after && is FALSE (e.g., if the model code is x <- max(w,y), then execution continues.

I've wrapped the check in isTRUE as a rudimentary fix.

(Side note: max(a,b) is converted to pairmax behind the scenes, and I think this is why cppOutputNimDerivsPrependType, but I haven't fully grasped the details.)

@paciorek
Copy link
Copy Markdown
Contributor Author

paciorek commented Jul 8, 2025

Also, just noticing we need to convert | to || to be consistent with R's handling of scalar versus vector boolean arithmetic (and I think R is getting more strict about this in some recent or future version).

@paciorek paciorek merged commit 5174f37 into devel Jul 10, 2025
0 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant