Skip to content

Commit

Permalink
efficiently calculate column and row sums
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjdenny committed Oct 12, 2015
1 parent 8995d51 commit 93ecc47
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Calculate_TFIDF <- function(document_word_matrix) {
.Call('SpeedReader_Calculate_TFIDF', PACKAGE = 'SpeedReader', document_word_matrix)
}

Col_and_Row_Sums <- function(joint_dist) {
.Call('SpeedReader_Col_and_Row_Sums', PACKAGE = 'SpeedReader', joint_dist)
}

Combine_Document_Term_Matrices <- function(document_word_matrix_list, vocabularies, unique_words, number_of_corpora) {
.Call('SpeedReader_Combine_Document_Term_Matrices', PACKAGE = 'SpeedReader', document_word_matrix_list, vocabularies, unique_words, number_of_corpora)
}
Expand All @@ -17,7 +21,15 @@ Count_Words <- function(number_of_documents, Document_Words, Document_Lengths, m
.Call('SpeedReader_Count_Words', PACKAGE = 'SpeedReader', number_of_documents, Document_Words, Document_Lengths, max_vocab_size, add_to_vocabulary, existing_word_counts, existing_vocabulary, existing_vocabulary_size)
}

Fast_Mutual_Information <- function(joint_dist, non_zero_cols) {
.Call('SpeedReader_Fast_Mutual_Information', PACKAGE = 'SpeedReader', joint_dist, non_zero_cols)
}

Generate_Document_Term_Matrix <- function(number_of_documents, number_of_unique_words, unique_words, Document_Words, Document_Lengths) {
.Call('SpeedReader_Generate_Document_Term_Matrix', PACKAGE = 'SpeedReader', number_of_documents, number_of_unique_words, unique_words, Document_Words, Document_Lengths)
}

Mutual_Information <- function(joint_dist) {
.Call('SpeedReader_Mutual_Information', PACKAGE = 'SpeedReader', joint_dist)
}

17 changes: 17 additions & 0 deletions src/Col_and_Row_Sums.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <RcppArmadillo.h>
#include <cmath>
//[[Rcpp::depends(RcppArmadillo)]]
using namespace Rcpp;

// [[Rcpp::export]]
List Col_and_Row_Sums(
arma::mat joint_dist
){
List to_return(2);
arma::mat colsums = sum(joint_dist,0);
arma::mat rowsums = sum(joint_dist,1);

to_return[0] = colsums;
to_return[1] = colsums;
return to_return;
}

0 comments on commit 93ecc47

Please sign in to comment.