Thanks to visit codestin.com
Credit goes to github.com

Skip to content

brackets [,] don't interpret array-valued arguments as expected #58

@fabian-s

Description

@fabian-s

default expected behavior for arrays (i.e., array-args to [ return a vector of entries in the array) does not carry over to tf-vectors:

library(tf)

x <- tf_rgp(5, arg = 1:5)

# to extract function values at specific args for each function, we need:
as.matrix(x)[cbind(1:5, 1:5)]
#> [1] -0.3721783  0.6235588  1.3563847 -1.4085395  1.1629906
# .. and more complicated code to match arg-values to array-column-indices in general...

# default behavior for arrays does not carry over to tf-vectors:

x[cbind(1:5, 1:5)] # treats array arg as a vector :(
#> tfd[10] on (1,5) based on 5 evaluations each
#> interpolation by tf_approx_linear 
#> [1]: (1, -0.4);(2, -1.0);(3,  0.8); ...
#> [2]: (1, -0.8);(2,  0.6);(3,  0.3); ...
#> [3]: (1,  1.9);(2,  0.6);(3,  1.4); ...
#> [4]: (1, -2.5);(2, -1.0);(3, -0.6); ...
#> [5]: (1,-0.07);(2, 0.91);(3,-0.63); ...
#> [6]: (1, -0.4);(2, -1.0);(3,  0.8); ...
#> [7]: (1, -0.8);(2,  0.6);(3,  0.3); ...
#> [8]: (1,  1.9);(2,  0.6);(3,  1.4); ...
#> [9]: (1, -2.5);(2, -1.0);(3, -0.6); ...
#> [10]: (1,-0.07);(2, 0.91);(3,-0.63); ...


x <- tf_rgp(5)
x[cbind(1:5, runif(5))] # fails because i-arg does not check for array-type :(
#> Error in `[.tf`(x, cbind(1:5, runif(5))): Assertion on 'i' failed: Must be of type 'integerish', but element 6 is not close to an integer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions