if (FALSE) {
# Create a sample large matrix in HDF5
library(BigDataStatMeth)
library(rhdf5)
# Create a sample large matrix in HDF5
A <- matrix(rnorm(10000), 1000, 10)
fn <- "test_temp.hdf5"
bdCreate_hdf5_matrix(filename = fn, object = A, group = "data", dataset = "matrix")
# Compute SVD with default parameters
res <- bdSVD_hdf5(fn, "data", "matrix")
# Compute SVD with custom parameters
res <- bdSVD_hdf5(fn, "data", "matrix",
k = 4, q = 2,
bcenter = TRUE, bscale = TRUE,
method = "blocks",
threads = 4)
# list contents
h5ls(res$fn)
# Extract the result from HDF5 (d)
result_d_hdf5 <- h5read(res$fn, res$ds_d)
result_d_hdf5
# Compute the same SVD in R
result_d_r <- svd(A)$d
result_d_r
# Compare both results (should be TRUE)
all.equal(result_d_hdf5, result_d_r)
# Remove file
if (file.exists(fn)) {
file.remove(fn)
}
}
Run the code above in your browser using DataLab