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

Add some sparse helpers - mean, sd, var, median #79

Merged
merged 7 commits into from
Oct 18, 2024
Merged

Conversation

EmilHvitfeldt
Copy link
Member

Ref: #49

They are currently written in R, but they beat the default implementation for common data sizes.

They also have early exits for completely sparse vectors

library(sparsevctrs)

x <- sparse_double(c(10, 50, 11), c(1, 50, 111), 1000)

bench::mark(
  dense = mean(x),
  sparse = sparse_mean(x)
)
#> # A tibble: 2 × 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 dense       35.47µs   35.8µs    27010.    23.3KB     2.70
#> 2 sparse       1.48µs    1.6µs   574807.    19.2KB    57.5

x <- sparse_double(c(10, 50, 11), c(1, 50, 111), 100000)

bench::mark(
  dense = mean(x),
  sparse = sparse_mean(x)
)
#> # A tibble: 2 × 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 dense        3.42ms   3.46ms      288.        0B        0
#> 2 sparse       1.44µs   1.56µs   579646.        0B        0

@EmilHvitfeldt EmilHvitfeldt merged commit 2726b8a into main Oct 18, 2024
11 checks passed
@EmilHvitfeldt EmilHvitfeldt deleted the sparse-helpers branch October 18, 2024 04:53
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

Successfully merging this pull request may close these issues.

1 participant