-
Notifications
You must be signed in to change notification settings - Fork 14
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
Interpreting NATIVE_UINT8
as integer in sparse matrices
#56
Comments
Hi @LTLA, Sorry for the slow response on this. Note that you can change the type of a DelayedArray object anytime with:
In particular, you don't need to re-create the HDF5ArraySeed or H5SparseMatrixSeed object if its type turns out to be
Would that be good enough or do you feel strongly about adding the Finally note that there would be no reason to not make similar changes to the H. |
Yes, that would solve my immediate problem (of getting an integer sparse matrix). However, this might cause some performance issues down the line... but not for the reasons you've stated. In my various frameworks (e.g., alabaster.xxx, chihaya), I can perform some optimizations if I detect that the If I use the (Also having thought about it some more,
Yes, that's what I was thinking, given that both of these already have a |
FWIW I recently encountered a related problem, where my library(HDF5Array)
m0 <- matrix(0, nrow=25, ncol=12,
dimnames=list(letters[1:25], LETTERS[1:12]))
m0[cbind(2:24, c(12:1, 2:12))] <- 100 + sample(55, 23, replace=TRUE)
out_file <- tempfile()
M0 <- writeTENxMatrix(m0, out_file, group="m0")
# Let's make the data more exciting.
fhandle <- H5Fopen(out_file, "H5F_ACC_RDWR")
ghandle <- H5Gopen(fhandle, "m0")
H5Ldelete(ghandle, "data")
shandle <- H5Screate_simple(23)
dhandle <- H5Dcreate(ghandle, "data", dtype_id="H5T_NATIVE_UINT32", h5space=shandle)
H5Dwrite(dhandle, .Machine$integer.max + as.double(1:23))
H5Dclose(dhandle)
H5Sclose(shandle)
H5Gclose(ghandle)
H5Fclose(fhandle)
H5SparseMatrix(out_file, "m0")
## <25 x 12> sparse H5SparseMatrix object of type "integer":
## [,1] [,2] [,3] [,4] ... [,9] [,10] [,11] [,12]
## [1,] 0 0 0 0 . 0 0 0 0
## [2,] 0 0 0 0 . 0 0 0 2147483647
## [3,] 0 0 0 0 . 0 0 2147483647 0
## [4,] 0 0 0 0 . 0 2147483647 0 0
## [5,] 0 0 0 0 . 2147483647 0 0 0
## ... . . . . . . . . .
## [21,] 0 0 0 0 . 2147483647 0 0 0
## [22,] 0 0 0 0 . 0 2147483647 0 0
## [23,] 0 0 0 0 . 0 0 2147483647 0
## [24,] 0 0 0 0 . 0 0 0 2147483647
## [25,] 0 0 0 0 . 0 0 0 0 |
Sometimes I store sparse counts in the HDF5 file as unsigned 8-bit integers to save some space. This is fine but the subsequent
H5SparseMatrix
instance is not able to participate in arithmetic operations:This might be easily solved with a
type=
option, just like in theHDF5ArraySeed
constructor for the dense case.Or even better, a dedicated
as.integer=
option that treats all HDF5 integer types as R integers. This would allow me to just setas.integer=TRUE
and everything should work; otherwise, even with atype=
option, I need to first create theHDF5ArraySeed
with default arguments, check if it'stype(mat) == "raw"
, and then create it again withtype="integer"
. (Presumably, I can't just settype="integer"
all the time, otherwise bad things will happen for floating-point matrices.)Session information
The text was updated successfully, but these errors were encountered: