Skip to content

Instantly share code, notes, and snippets.

@pati-ni
Last active March 13, 2018 11:13
Show Gist options
  • Select an option

  • Save pati-ni/bc43941a831c6a04f05f250b5c51d3f1 to your computer and use it in GitHub Desktop.

Select an option

Save pati-ni/bc43941a831c6a04f05f250b5c51d3f1 to your computer and use it in GitHub Desktop.

Revisions

  1. pati-ni revised this gist Mar 13, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion big_memory.R
    Original file line number Diff line number Diff line change
    @@ -5,4 +5,4 @@ options(bigmemory.allow.dimnames = TRUE)
    sce <- readRDS('lake.rds')
    normcounts(sce) <- as.big.matrix(normcounts(sce))

    process(as.big.matrix(r))
    process(normcounts(sce))
  2. pati-ni created this gist Mar 13, 2018.
    8 changes: 8 additions & 0 deletions big_memory.R
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    library('bigmemory')
    options(bigmemory.allow.dimnames = TRUE)

    # Read SingleCellExperiment object
    sce <- readRDS('lake.rds')
    normcounts(sce) <- as.big.matrix(normcounts(sce))

    process(as.big.matrix(r))
    19 changes: 19 additions & 0 deletions process.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    // [[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;
    }