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

fix bug in altrep_sparse_real_Dataptr() #24

Closed
EmilHvitfeldt opened this issue May 1, 2024 · 3 comments
Closed

fix bug in altrep_sparse_real_Dataptr() #24

EmilHvitfeldt opened this issue May 1, 2024 · 3 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@EmilHvitfeldt
Copy link
Member

The following code should not throw an error, as setting attributes shouldn't force materialization

aaa <- 1:1000000000000

# No materialization 
attributes(aaa) <- list(h = 3)

# Forced materialization
aaa[]
#> Error: vector memory exhausted (limit reached?)
library(sparsevctrs)
  
options("sparsevctrs.verbose_materialize" = TRUE)
  
aaa <- new_sparse_real(1, 5, 10)

attributes(aaa) <- list(h = 3)
#> sparsevctrs: Sparse vector materialized
@EmilHvitfeldt EmilHvitfeldt added the bug an unexpected problem or unintended behavior label May 1, 2024
@EmilHvitfeldt
Copy link
Member Author

per https://svn.r-project.org/R/branches/ALTREP/ALTREP.html#some_guidelines,

A common practice in C code in the base R implementation is to duplicate an object and modify the copy in place. ALTREP classes need to handle this in an appropriate way. For example, this is how unary arithmetic functions produce their return value. For most SEXP types, in particular all vector types, if a Duplicate method is provided that returns a non-NULL value, then that value should be freshly allocated with no references. This will allow attributes to be modified. If the class value can provide a writable data pointer then this also supports modifying the data.

@EmilHvitfeldt
Copy link
Member Author

add R_set_altrep_Duplicate_method() per #5

@EmilHvitfeldt
Copy link
Member Author

Fixed in #46

library(sparsevctrs)
  
options("sparsevctrs.verbose_materialize" = TRUE)
  
aaa <- sparse_double(1, 5, 10)

attributes(aaa) <- list(h = 3)

Created on 2024-05-13 with reprex v2.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

1 participant