22 #ifndef Rcpp__Algorithm_h
23 #define Rcpp__Algorithm_h
25 #if __cplusplus >= 201103L || __INTEL_CXX11_MODE__ == 1
26 # define RCPP_CONSTEXPR_FUNC constexpr
27 # define RCPP_CONSTEXPR_VAR constexpr
29 # define RCPP_CONSTEXPR_FUNC
30 # define RCPP_CONSTEXPR_VAR const
41 #ifdef RCPP_HAS_LONG_LONG_TYPES
42 typedef struct {
char a[5];} CTYPE_LONG_LONG;
52 #ifdef RCPP_HAS_LONG_LONG_TYPES
53 typedef struct {
char a[14];} CTYPE_UNSIGNED_LONG_LONG;
57 template< std::
size_t I >
72 #ifdef RCPP_HAS_LONG_LONG_TYPES
74 struct ctype_helper< sizeof(CTYPE_LONG_LONG) > {
typedef rcpp_long_long_type type;
static const bool value =
true; };
101 #ifdef RCPP_HAS_LONG_LONG_TYPES
103 struct ctype_helper< sizeof(CTYPE_UNSIGNED_LONG_LONG) > {
typedef rcpp_ulong_long_type type;
static const bool value =
true; };
107 template<
typename T >
114 #ifdef RCPP_HAS_LONG_LONG_TYPES
115 static CTYPE_LONG_LONG
test(
const rcpp_long_long_type &);
125 #ifdef RCPP_HAS_LONG_LONG_TYPES
126 static CTYPE_UNSIGNED_LONG_LONG
test(
const rcpp_ulong_long_type &);
135 template<
typename T >
142 #ifdef RCPP_HAS_LONG_LONG_TYPES
143 static CTYPE_LONG_LONG
test(
const rcpp_long_long_type &);
153 #ifdef RCPP_HAS_LONG_LONG_TYPES
154 static CTYPE_UNSIGNED_LONG_LONG
test(
const rcpp_ulong_long_type &);
163 template<
typename T >
171 static inline double NA() {
return NA_REAL; }
180 static inline int NA() {
return NA_INTEGER; }
185 template<
typename T >
196 template<
typename T >
207 template<
typename T >
218 template<
typename T >
229 template<
typename InputIterator >
231 typename helpers::ctype< typename std::iterator_traits< InputIterator >::value_type >::type >::type
232 sum(InputIterator begin, InputIterator end) {
238 value_type start = rtype::ZERO();
240 while (begin != end) {
251 return rtype::ZERO();
254 template<
typename InputIterator >
256 typename helpers::ctype< typename std::iterator_traits< InputIterator >::value_type >::type >::type
263 value_type start = rtype::ZERO();
265 while (begin != end) {
272 return rtype::ZERO();
275 template<
typename InputIterator >
277 typename helpers::ctype< typename std::iterator_traits< InputIterator >::value_type >::type >::type
278 prod(InputIterator begin, InputIterator end) {
284 value_type start = rtype::ONE();
286 while (begin != end) {
300 template<
typename InputIterator >
302 typename helpers::ctype< typename std::iterator_traits< InputIterator >::value_type >::type >::type
309 value_type start = rtype::ONE();
311 while (begin != end) {
321 template<
typename InputIterator >
323 typename helpers::ctype< typename std::iterator_traits< InputIterator >::value_type >::type >::type
324 max(InputIterator begin, InputIterator end) {
330 value_type
max = *begin;
332 while (begin != end) {
343 return std::numeric_limits< typename rtype::type >::infinity() * -rtype::ONE();
346 template<
typename InputIterator >
348 typename helpers::ctype< typename std::iterator_traits< InputIterator >::value_type >::type >::type
355 value_type
max = *begin;
357 while (begin != end) {
364 return std::numeric_limits< typename rtype::type >::infinity() * -rtype::ONE();
367 template<
typename InputIterator >
369 typename helpers::ctype< typename std::iterator_traits< InputIterator >::value_type >::type >::type
370 min(InputIterator begin, InputIterator end) {
376 value_type
min = *begin;
378 while (begin != end) {
389 return std::numeric_limits< typename rtype::type >::infinity();
392 template<
typename InputIterator >
394 typename helpers::ctype< typename std::iterator_traits< InputIterator >::value_type >::type >::type
401 value_type
min = *begin;
403 while (begin != end) {
410 return std::numeric_limits< typename rtype::type >::infinity();
414 template<
typename InputIterator >
417 mean(InputIterator begin, InputIterator end)
421 std::size_t n = end - begin;
422 long double s = std::accumulate(begin, end, 0.0L);
425 if (R_FINITE((
double) s)) {
426 long double t = 0.0L;
427 while (begin != end) {
441 template<
typename InputIterator >
444 mean(InputIterator begin, InputIterator end)
448 std::size_t n = end - begin;
449 long double s = std::accumulate(begin, end, 0.0L);
452 if (R_FINITE((
double) s)) {
453 long double t = 0.0L;
454 while (begin != end) {
468 template<
typename InputIterator,
typename OutputIterator >
469 void log(InputIterator begin, InputIterator end, OutputIterator out) {
473 template<
typename InputIterator,
typename OutputIterator >
474 void exp(InputIterator begin, InputIterator end, OutputIterator out) {
478 template<
typename InputIterator,
typename OutputIterator >
479 void sqrt(InputIterator begin, InputIterator end, OutputIterator out) {
486 #undef RCPP_CONSTEXPR_FUNC
487 #undef RCPP_CONSTEXPR_VAR
#define RCPP_CONSTEXPR_VAR
#define RCPP_CONSTEXPR_FUNC
traits::enable_if< helpers::decays_to_ctype< typename std::iterator_traits< InputIterator >::value_type >::value, typename helpers::ctype< typename std::iterator_traits< InputIterator >::value_type >::type >::type prod(InputIterator begin, InputIterator end)
void exp(InputIterator begin, InputIterator end, OutputIterator out)
traits::enable_if< helpers::decays_to_ctype< typename std::iterator_traits< InputIterator >::value_type >::value, typename helpers::ctype< typename std::iterator_traits< InputIterator >::value_type >::type >::type min_nona(InputIterator begin, InputIterator end)
traits::enable_if< helpers::decays_to_ctype< typename std::iterator_traits< InputIterator >::value_type >::value, typename helpers::ctype< typename std::iterator_traits< InputIterator >::value_type >::type >::type prod_nona(InputIterator begin, InputIterator end)
void log(InputIterator begin, InputIterator end, OutputIterator out)
traits::enable_if< helpers::decays_to_ctype< typename std::iterator_traits< InputIterator >::value_type >::value, typename helpers::ctype< typename std::iterator_traits< InputIterator >::value_type >::type >::type sum(InputIterator begin, InputIterator end)
void sqrt(InputIterator begin, InputIterator end, OutputIterator out)
traits::enable_if< helpers::decays_to_ctype< typename std::iterator_traits< InputIterator >::value_type >::value, typename helpers::ctype< typename std::iterator_traits< InputIterator >::value_type >::type >::type max_nona(InputIterator begin, InputIterator end)
traits::enable_if< helpers::decays_to_ctype< typename std::iterator_traits< InputIterator >::value_type >::value, typename helpers::ctype< typename std::iterator_traits< InputIterator >::value_type >::type >::type sum_nona(InputIterator begin, InputIterator end)
traits::enable_if< helpers::decays_to_ctype< typename std::iterator_traits< InputIterator >::value_type >::value, typename helpers::ctype< typename std::iterator_traits< InputIterator >::value_type >::type >::type min(InputIterator begin, InputIterator end)
traits::enable_if< helpers::decays_to_ctype< typename std::iterator_traits< InputIterator >::value_type >::value &&traits::same_type< typename helpers::ctype< typename std::iterator_traits< InputIterator >::value_type >::type, double >::value, double >::type mean(InputIterator begin, InputIterator end)
traits::enable_if< helpers::decays_to_ctype< typename std::iterator_traits< InputIterator >::value_type >::value, typename helpers::ctype< typename std::iterator_traits< InputIterator >::value_type >::type >::type max(InputIterator begin, InputIterator end)
sugar::IsNa< RTYPE, NA, T > is_na(const Rcpp::VectorBase< RTYPE, NA, T > &t)
static CTYPE_STRING test(const std::string &)
static CTYPE_LONG test(const long &)
static CTYPE_CHAR test(const char &)
static CTYPE_UNSIGNED_INT test(const unsigned int &)
static CTYPE_INT test(const int &)
static CTYPE_UNSIGNED_SHORT test(const unsigned short &)
static CTYPE_UNSIGNED_CHAR test(const unsigned char &)
static CTYPE_SHORT test(const short &)
static CTYPE_UNKNOWN test(...)
static CTYPE_DOUBLE test(const double &)
static CTYPE_FLOAT test(const float &)
ctype_helper< sizeof(test(make())) >::type type
static CTYPE_UNSIGNED_LONG test(const unsigned long &)
static CTYPE_LONG_DOUBLE test(const long double &)
static CTYPE_CHAR test(const char &)
static CTYPE_FLOAT test(const float &)
static CTYPE_UNSIGNED_LONG test(const unsigned long &)
static CTYPE_SHORT test(const short &)
static CTYPE_UNSIGNED_INT test(const unsigned int &)
static CTYPE_UNSIGNED_CHAR test(const unsigned char &)
static CTYPE_DOUBLE test(const double &)
static CTYPE_LONG_DOUBLE test(const long double &)
static CTYPE_STRING test(const std::string &)
static CTYPE_INT test(const int &)
static CTYPE_LONG test(const long &)
static CTYPE_UNKNOWN test(...)
static CTYPE_UNSIGNED_SHORT test(const unsigned short &)
static RCPP_CONSTEXPR_FUNC double ZERO()
static RCPP_CONSTEXPR_FUNC double ONE()
static RCPP_CONSTEXPR_FUNC int ZERO()
static RCPP_CONSTEXPR_FUNC int ONE()
static RCPP_CONSTEXPR_VAR int RTYPE
rtype_helper< typename ctype< T >::type > helper_type
static RCPP_CONSTEXPR_FUNC T ONE()
rtype_helper< typename ctype< T >::type >::type type
static RCPP_CONSTEXPR_FUNC T ZERO()