nimble
nimble copied to clipboard
Compiled besselK() function acting on array arguments returns a vector
The title says it all.
besselK()
function works as expected for scalar and vector arguments, in both uncompiled and compiled execution.
However, when passed array arguments:
- Uncompiled execution returns an array (same as in regular R)
- Compiled execution returns a vector
Reproducible example:
library(nimble)
Rnf <- nimbleFunction(
run = function(A = double(2), B = double(2)) {
returnType(double(1))
return(besselK(A, B))
}
)
Cnf <- compileNimble(Rnf)
A <- array(1, c(2,4))
B <- array(1:8, c(2,4))
besselK(A, B)
## [,1] [,2] [,3] [,4]
## [1,] 0.6019072 7.101263 360.9606 44207.02
## [2,] 1.6248389 44.232416 3653.8383 622552.12
Rnf(A, B)
## [,1] [,2] [,3] [,4]
## [1,] 0.6019072 7.101263 360.9606 44207.02
## [2,] 1.6248389 44.232416 3653.8383 622552.12
Cnf(A, B)
## [1] 0.6019072 1.6248389 7.1012628 44.2324158 360.9605896
## [6] 3653.8383119 44207.0203319 622552.1229587
array(Cnf(A, B), c(2,4))
## [,1] [,2] [,3] [,4]
## [1,] 0.6019072 7.101263 360.9606 44207.02
## [2,] 1.6248389 44.232416 3653.8383 622552.12
GitHub makes it much too easy to accidentally "assign yourself" to an issue, by clicking the wrong button...
I'm wondering how other functions that we allow in the DSL do with arrays as input... is this specific to how I created besselK?
@paciorek These are questions for @perrydv
Note: look at Cpp code for recycling vis-a-vis besselK recyclingl.