1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-25 17:45:45 +02:00

speed improvements

This commit is contained in:
2018-07-17 10:32:26 +02:00
parent 715a7630ca
commit a5a4354651
12 changed files with 52 additions and 213 deletions

View File

@ -29,22 +29,10 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// rsi_calc_total
int rsi_calc_total(DoubleVector x);
RcppExport SEXP _AMR_rsi_calc_total(SEXP xSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< DoubleVector >::type x(xSEXP);
rcpp_result_gen = Rcpp::wrap(rsi_calc_total(x));
return rcpp_result_gen;
END_RCPP
}
static const R_CallMethodDef CallEntries[] = {
{"_AMR_rsi_calc_S", (DL_FUNC) &_AMR_rsi_calc_S, 2},
{"_AMR_rsi_calc_R", (DL_FUNC) &_AMR_rsi_calc_R, 2},
{"_AMR_rsi_calc_total", (DL_FUNC) &_AMR_rsi_calc_total, 1},
{NULL, NULL, 0}
};

View File

@ -1,28 +1,21 @@
#include <Rcpp.h>
#include <functional> // for std::less, etc
#include <algorithm> // for count_if
// #include <functional> // for std::less_equal and std::greater_equal
// #include <algorithm> // for count_if
using namespace Rcpp;
// [[Rcpp::export]]
int rsi_calc_S(DoubleVector x, bool include_I) {
if (include_I == TRUE) {
return count_if(x.begin(), x.end(), bind2nd(std::less_equal<double>(), 2));
} else {
return count_if(x.begin(), x.end(), bind2nd(std::less<double>(), 2));
}
return count_if(x.begin(),
x.end(),
bind2nd(std::less_equal<double>(),
1 + include_I));
}
// [[Rcpp::export]]
int rsi_calc_R(DoubleVector x, bool include_I) {
if (include_I == TRUE) {
return count_if(x.begin(), x.end(), bind2nd(std::greater_equal<double>(), 2));
} else {
return count_if(x.begin(), x.end(), bind2nd(std::greater<double>(), 2));
}
}
// [[Rcpp::export]]
int rsi_calc_total(DoubleVector x) {
return count_if(x.begin(), x.end(), bind2nd(std::less_equal<double>(), 3));
return count_if(x.begin(),
x.end(),
bind2nd(std::greater_equal<double>(),
3 - include_I));
}