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

Consider adding default property to altrep class #10

Closed
EmilHvitfeldt opened this issue Apr 19, 2024 · 1 comment · Fixed by #40
Closed

Consider adding default property to altrep class #10

EmilHvitfeldt opened this issue Apr 19, 2024 · 1 comment · Fixed by #40
Labels
feature a feature request or enhancement

Comments

@EmilHvitfeldt
Copy link
Member

right now there is a implicit assumption that non-specified values are zero. This doesn't have to be true, and we could include default as a value to data1 and use. With this we can have x + 1 retain its sparsity which is currently not the case.

library(sparsevctrs)

x <- new_sparse_real(c(1, 5, 10), c(1, 5, 10), 10)

x
#>  [1]  1  0  0  0  5  0  0  0  0 10

altrepr::is_altrep(x)
#> [1] TRUE

x + 1
#>  [1]  2  1  1  1  6  1  1  1  1 11

altrepr::is_altrep(x + 1)
#> [1] FALSE

We could also take variables that mostly take 100 as a value to become sparse with default 100

@EmilHvitfeldt EmilHvitfeldt added the feature a feature request or enhancement label Apr 19, 2024
@EmilHvitfeldt
Copy link
Member Author

To make this easier, I'm going to make it so all the coerce_ functions stop if the sparse vectors doesn't have default value 0

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

Successfully merging a pull request may close this issue.

1 participant