Consider adding `default` property to altrep class
Closed this issue · 1 comments
EmilHvitfeldt commented
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 commented
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