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

apply not working on greta_array #514

Open
hrlai opened this issue Apr 19, 2022 · 3 comments
Open

apply not working on greta_array #514

hrlai opened this issue Apr 19, 2022 · 3 comments
Milestone

Comments

@hrlai
Copy link

hrlai commented Apr 19, 2022

Hi, I bumped into this weird problem today... hopefully there is a quick fix or I was just doing something wrong.

library(greta)
z <- normal(0, 1, dim = c(2, 3))
apply(z, 1, mean)    # doesn't work
rowMeans(z)          # works

Working on Ubuntu and greta_0.4.2.

@hrlai
Copy link
Author

hrlai commented Apr 19, 2022

Okay it just got weirder... because apply(z, 1, "mean") works...

@njtierney njtierney added this to the 0.5.0 milestone May 19, 2022
@njtierney
Copy link
Collaborator

That sounds spooky! Let me check this out.

@hrlai
Copy link
Author

hrlai commented Dec 18, 2022

Hi there, I'm looking into cumsum and encountered a similar issue to the earlier one, potentially also related to #504

Wanted to apply the cumsum function across rows of a greta_array, but got NAs instead... do you think these fall into the same category of things to improve?

library(greta)
#> 
#> Attaching package: 'greta'
#> The following objects are masked from 'package:stats':
#> 
#>     binomial, cov2cor, poisson
#> The following objects are masked from 'package:base':
#> 
#>     %*%, apply, backsolve, beta, chol2inv, colMeans, colSums, diag,
#>     eigen, forwardsolve, gamma, identity, rowMeans, rowSums, sweep,
#>     tapply

x <- normal(0, 10, dim = c(4, 5))
#> ℹ Initialising python and checking dependencies, this may take a moment.
#> ✔ Initialising python and checking dependencies ... done!
#> 

apply(x, 1, mean)   # doesn't work
#> Error in match.arg(FUN): 'arg' must be NULL or a character vector
apply(x, 1, "mean") # works
#> greta array (operation)
#> 
#>      [,1]
#> [1,]  ?  
#> [2,]  ?  
#> [3,]  ?  
#> [4,]  ?

apply(x, 2, sd)     # doesn't work
#> Error in match.arg(FUN): 'arg' must be NULL or a character vector
apply(x, 2, "sd")   # doesn't work too, but gives more informative error
#> Error in match.arg(FUN): 'arg' should be one of "sum", "max", "mean", "min", "prod", "cumsum", "cumprod"

apply(x, 2, cumsum)   # doesn't work
#> Error in match.arg(FUN): 'arg' must be NULL or a character vector
apply(x, 2, "cumsum") # supposed to work according to error message above, but doesn't
#> greta array (operation)
#> 
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,]   NA   NA   NA   NA   NA
#> [2,]   NA   NA   NA   NA   NA
#> [3,]   NA   NA   NA   NA   NA
#> [4,]   NA   NA   NA   NA   NA

Created on 2022-12-19 with reprex v2.0.2

@njtierney njtierney modified the milestones: 0.5.0, 0.6.0 Feb 8, 2023
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

No branches or pull requests

2 participants