Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fabian-s opened this issue Feb 7, 2024 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@fabian-s
Copy link
Contributor

fabian-s commented Feb 7, 2024

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.
@fabian-s fabian-s added the enhancement New feature or request label Feb 7, 2024
@fabian-s
Copy link
Contributor Author

fabian-s commented Feb 9, 2024

also this:

x[1:3, , matrix = FALSE] # or TRUE
tfd[3] on (0,1) based on 51 evaluations each
interpolation by tf_approx_linear 
1: (0.00,-0.30);(0.02,-0.25);(0.04,-0.14); ...

should be the same as x[1:3, tf_arg(x), matrix = ?] but it's not....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant