R Under development (unstable) (2024-09-02 r87090 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > #!/usr/bin/Rscript > > library(RcppCNPy) > > set.seed(42) > M1 <- matrix(rnorm(1e6), 1e3, 1e3) > > ## double precision floating point, uncompressed > tempmatfile <- tempfile(pattern="npymat", fileext=".npy") > invisible(npySave(tempmatfile, M1)) > M2 <- npyLoad(tempmatfile) > identical(M1, M2) [1] TRUE > > ## double precision floating point, compressed > tempmatfile <- tempfile(pattern="npymat", fileext=".npy.gz") > invisible(npySave(tempmatfile, M1)) > M3 <- npyLoad(tempmatfile) > identical(M1, M3) [1] TRUE > > ## double precision floating point vector > dim(M1) <- NULL > tempmatfile <- tempfile(pattern="npyvec", fileext=".npy") > invisible(npySave(tempmatfile, M1)) Saving Numeric Vector > M2 <- npyLoad(tempmatfile) > identical(M1, M2) [1] TRUE > > ## double precision floating point vector, compressed > tempmatfile <- tempfile(pattern="npyvec", fileext=".npy.gz") > invisible(npySave(tempmatfile, M1)) Saving Numeric Vector > M3 <- npyLoad(tempmatfile) > identical(M1, M3) [1] TRUE > > ## integer, uncompressed > M4 <- matrix(as.integer(round(M1)), 1e3, 1e3) > tempmatfile <- tempfile(pattern="intnpymat", fileext=".npy") > invisible(npySave(tempmatfile, M4)) > M5 <- npyLoad(tempmatfile, "integer") > identical(M4, M5) [1] TRUE > > ## integer, compressed > tempmatfile <- tempfile(pattern="intnpymat", fileext=".npy.gz") > invisible(npySave(tempmatfile, M4)) > M6 <- npyLoad(tempmatfile, "integer") > identical(M4, M6) [1] TRUE > > ## integer vector, uncompressed > dim(M4) <- NULL > tempmatfile <- tempfile(pattern="intnpyvec", fileext=".npy") > invisible(npySave(tempmatfile, M4)) > M5 <- npyLoad(tempmatfile, "integer") > identical(M4, M5) [1] TRUE > > ## integer vector, compressed > tempmatfile <- tempfile(pattern="intnpyvec", fileext=".npy.gz") > invisible(npySave(tempmatfile, M4)) > M6 <- npyLoad(tempmatfile, "integer") > identical(M4, M6) [1] TRUE > > proc.time() user system elapsed 1.70 0.10 1.81