Last active
March 13, 2018 11:13
-
-
Save pati-ni/bc43941a831c6a04f05f250b5c51d3f1 to your computer and use it in GitHub Desktop.
Big Memory Package matrix reference wrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library('bigmemory') | |
options(bigmemory.allow.dimnames = TRUE) | |
# Read SingleCellExperiment object | |
sce <- readRDS('lake.rds') | |
normcounts(sce) <- as.big.matrix(normcounts(sce)) | |
process(normcounts(sce)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [[Rcpp::depends(BH, bigmemory)]] | |
#include <Rcpp.h> | |
#include <RcppArmadillo.h> | |
#include <bigmemory/MatrixAccessor.hpp> | |
#include <bigmemory/BigMatrix.h> | |
arma::mat cast_big_matrix(const SEXP& mat) | |
{ | |
Rcpp::XPtr<BigMatrix> xpMat(mat); | |
return arma::mat((double*)xpMat->matrix(), xpMat->nrow(), xpMat->ncol(), false); | |
} | |
arma::mat process(const SEXP& mat) | |
{ | |
arma::mat matrix(cast_big_matrix(mat)); | |
// Do processing | |
return matrix; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pros
Cons