nimble icon indicating copy to clipboard operation
nimble copied to clipboard

Compiled besselK() function acting on array arguments returns a vector

Open danielturek opened this issue 5 years ago • 4 comments

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

danielturek avatar Mar 01 '19 18:03 danielturek

GitHub makes it much too easy to accidentally "assign yourself" to an issue, by clicking the wrong button...

danielturek avatar Mar 01 '19 18:03 danielturek

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 avatar Mar 02 '19 23:03 paciorek

@paciorek These are questions for @perrydv

danielturek avatar Mar 03 '19 00:03 danielturek

Note: look at Cpp code for recycling vis-a-vis besselK recyclingl.

paciorek avatar Mar 06 '19 17:03 paciorek