Skip to content

Commit

Permalink
Add progress bar to SparseRowVarStd
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristophH committed Jul 29, 2018
1 parent 058fe40 commit b215b39
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ SparseRowSd <- function(mat) {
.Call('_Seurat_SparseRowSd', PACKAGE = 'Seurat', mat)
}

SparseRowVarStd <- function(mat, mu, sd, vmax) {
.Call('_Seurat_SparseRowVarStd', PACKAGE = 'Seurat', mat, mu, sd, vmax)
SparseRowVarStd <- function(mat, mu, sd, vmax, display_progress) {
.Call('_Seurat_SparseRowVarStd', PACKAGE = 'Seurat', mat, mu, sd, vmax, display_progress)
}

FastExpVar <- function(mat, display_progress) {
Expand Down
3 changes: 2 additions & 1 deletion R/preprocessing.R
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,8 @@ FindVariableFeaturesNew.default <- function(
hvf.info$variance.standardized <- SparseRowVarStd(mat = object,
mu = hvf.info$mean,
sd = sqrt(hvf.info$variance.expected),
vmax = clip.max)
vmax = clip.max,
display_progress = verbose)
return(hvf.info)
}

Expand Down
9 changes: 5 additions & 4 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,17 @@ BEGIN_RCPP
END_RCPP
}
// SparseRowVarStd
Eigen::VectorXd SparseRowVarStd(Eigen::SparseMatrix<double> mat, Eigen::VectorXd mu, Eigen::VectorXd sd, double vmax);
RcppExport SEXP _Seurat_SparseRowVarStd(SEXP matSEXP, SEXP muSEXP, SEXP sdSEXP, SEXP vmaxSEXP) {
Eigen::VectorXd SparseRowVarStd(Eigen::SparseMatrix<double> mat, Eigen::VectorXd mu, Eigen::VectorXd sd, double vmax, bool display_progress);
RcppExport SEXP _Seurat_SparseRowVarStd(SEXP matSEXP, SEXP muSEXP, SEXP sdSEXP, SEXP vmaxSEXP, SEXP display_progressSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< Eigen::SparseMatrix<double> >::type mat(matSEXP);
Rcpp::traits::input_parameter< Eigen::VectorXd >::type mu(muSEXP);
Rcpp::traits::input_parameter< Eigen::VectorXd >::type sd(sdSEXP);
Rcpp::traits::input_parameter< double >::type vmax(vmaxSEXP);
rcpp_result_gen = Rcpp::wrap(SparseRowVarStd(mat, mu, sd, vmax));
Rcpp::traits::input_parameter< bool >::type display_progress(display_progressSEXP);
rcpp_result_gen = Rcpp::wrap(SparseRowVarStd(mat, mu, sd, vmax, display_progress));
return rcpp_result_gen;
END_RCPP
}
Expand Down Expand Up @@ -321,7 +322,7 @@ static const R_CallMethodDef CallEntries[] = {
{"_Seurat_FastExpMean", (DL_FUNC) &_Seurat_FastExpMean, 2},
{"_Seurat_SparseRowVar", (DL_FUNC) &_Seurat_SparseRowVar, 2},
{"_Seurat_SparseRowSd", (DL_FUNC) &_Seurat_SparseRowSd, 1},
{"_Seurat_SparseRowVarStd", (DL_FUNC) &_Seurat_SparseRowVarStd, 4},
{"_Seurat_SparseRowVarStd", (DL_FUNC) &_Seurat_SparseRowVarStd, 5},
{"_Seurat_FastExpVar", (DL_FUNC) &_Seurat_FastExpVar, 2},
{"_Seurat_FastLogVMR", (DL_FUNC) &_Seurat_FastLogVMR, 2},
{"_Seurat_RowSumOfSquares", (DL_FUNC) &_Seurat_RowSumOfSquares, 1},
Expand Down
9 changes: 8 additions & 1 deletion src/data_manipulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,19 @@ Eigen::VectorXd SparseRowSd(Eigen::SparseMatrix<double> mat){
Eigen::VectorXd SparseRowVarStd(Eigen::SparseMatrix<double> mat,
Eigen::VectorXd mu,
Eigen::VectorXd sd,
double vmax){
double vmax,
bool display_progress){
mat = mat.transpose();
Eigen::VectorXd allVars(mat.cols());
allVars.fill(0);

if(display_progress == true){
Rcpp::Rcerr << "Calculating feature variances of standardized and clipped values" << std::endl;
}
Progress p(mat.outerSize(), display_progress);

for (int k=0; k<mat.outerSize(); ++k){
p.increment();
if (sd(k) == 0) continue;
double colSum = 0;
int nZero = mat.rows();
Expand Down
3 changes: 2 additions & 1 deletion src/data_manipulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ Eigen::VectorXd SparseRowSd(Eigen::SparseMatrix<double> mat);
Eigen::VectorXd SparseRowVarStd(Eigen::SparseMatrix<double> mat,
Eigen::VectorXd mu,
Eigen::VectorXd sd,
double vmax);
double vmax,
bool display_progress);
NumericVector RowSumOfSquares(const NumericMatrix x);
NumericVector RowVar(Eigen::Map<Eigen::MatrixXd> x);
int IntersectLength(std::vector<int> a, std::vector<int> b);
Expand Down

0 comments on commit b215b39

Please sign in to comment.