kuwisdelu / matter

Out-of-core statistical computing and signal processing
http://www.cardinalmsi.org
54 stars 4 forks source link

Problems using filemode = "rb" #2

Closed PeteHaitch closed 7 years ago

PeteHaitch commented 7 years ago

Hi Kylie,

I've just started exploring matter, it looks really cool! I hit an issue trying to specify filemode = "rb" when creating a matter matrix. Am I doing something wrong?

Thanks

library(matter)
#> Loading required package: biglm
#> Loading required package: DBI
#> 
#> Attaching package: 'matter'
#> The following objects are masked from 'package:base':
#> 
#>     apply, scale

# Using the default filemode = "rb+" works fine
x <- matter_mat(1:100, nrow=10, ncol=10)
x
#> An object of class 'matter_matc'
#>   <10 row, 10 column> on-disk matrix
#>     sources: 1 
#>     datamode: numeric 
#>     12.1 KB in-memory
#>     800 bytes on-disk

# Specifying filemode = "rb" causes R to hang (killed after 30 seconds)
x <- matter_mat(1:100, nrow=10, ncol=10, filemode = "rb")

sessionInfo()
#>R version 3.4.0 (2017-04-21)
#>Platform: x86_64-apple-darwin15.6.0 (64-bit)
#>Running under: macOS Sierra 10.12.5
#>
#>Matrix products: default
#>BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib
#>LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
#>
#>locale:
#>[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8
#>
#>attached base packages:
#>[1] stats     graphics  grDevices utils     datasets  methods   base
#>
#>other attached packages:
#>[1] matter_1.3.3 biglm_0.9-1  DBI_0.6-1

#>loaded via a namespace (and not attached):
#>[1] compiler_3.4.0      Matrix_1.2-10       parallel_3.4.0
#>[4] grid_3.4.0          BiocGenerics_0.23.0 irlba_2.2.1
#>[7] lattice_0.20-35
kuwisdelu commented 7 years ago

Hi Pete,

Using "rb" makes it read-only, so it expects that the matrix already exists in a file on disk. As a result, when it tries to create and assign initial values, it cannot write to the file (since it's opened as read-only).

Hanging is bad, so this should probably either throw an error if no existing file is given, or it should temporarily open the file as read/write for the initialization.

-Kylie

PeteHaitch commented 7 years ago

Oh, that makes sense! I thought "rb" was to create a read-only file rather than to read from a read-only file. What is the recommended way to create a file but then make it read-only for subsequent use? Thanks, Pete

kuwisdelu commented 7 years ago

Create it using filemode="rb+" (default) then do:

filemode(x) <- "rb"

-Kylie