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
52#ifdef RCPP_HAS_LONG_LONG_TYPES
57 template< std::
size_t I >
72#ifdef RCPP_HAS_LONG_LONG_TYPES
101#ifdef RCPP_HAS_LONG_LONG_TYPES
107 template<
typename T >
114#ifdef RCPP_HAS_LONG_LONG_TYPES
125#ifdef RCPP_HAS_LONG_LONG_TYPES
135 template<
typename T >
142#ifdef RCPP_HAS_LONG_LONG_TYPES
153#ifdef RCPP_HAS_LONG_LONG_TYPES
163 template<
typename T >
185 template<
typename T >
190 static inline T
NA() {
return helper_type::NA(); }
196 template<
typename T >
199 return std::log(
val);
207 template<
typename T >
210 return std::exp(
val);
218 template<
typename T >
221 return std::sqrt(
val);
229template<
typename InputIterator >
231 typename helpers::ctype< typename std::iterator_traits< InputIterator >::value_type >::type >::type
238 value_type start = rtype::ZERO();
240 while (begin != end) {
251 return rtype::ZERO();
254template<
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();
275template<
typename InputIterator >
277 typename helpers::ctype< typename std::iterator_traits< InputIterator >::value_type >::type >::type
284 value_type start = rtype::ONE();
286 while (begin != end) {
300template<
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) {
321template<
typename InputIterator >
323 typename helpers::ctype< typename std::iterator_traits< InputIterator >::value_type >::type >::type
330 value_type
max = *begin;
332 while (begin != end) {
334 max = std::max(
max, *begin++);
343 return std::numeric_limits< typename rtype::type >::infinity() * -rtype::ONE();
346template<
typename InputIterator >
348 typename helpers::ctype< typename std::iterator_traits< InputIterator >::value_type >::type >::type
355 value_type
max = *begin;
357 while (begin != end) {
358 max = std::max(
max, *begin++);
364 return std::numeric_limits< typename rtype::type >::infinity() * -rtype::ONE();
367template<
typename InputIterator >
369 typename helpers::ctype< typename std::iterator_traits< InputIterator >::value_type >::type >::type
376 value_type
min = *begin;
378 while (begin != end) {
380 min = std::min(
min, *begin++);
389 return std::numeric_limits< typename rtype::type >::infinity();
392template<
typename InputIterator >
394 typename helpers::ctype< typename std::iterator_traits< InputIterator >::value_type >::type >::type
401 value_type
min = *begin;
403 while (begin != end) {
404 min = std::min(
min, *begin++);
410 return std::numeric_limits< typename rtype::type >::infinity();
414template<
typename InputIterator >
421 std::size_t n = end - begin;
422 long double s = std::accumulate(begin, end, 0.0L);
426 long double t = 0.0L;
427 while (begin != end) {
441template<
typename InputIterator >
448 std::size_t n = end - begin;
449 long double s = std::accumulate(begin, end, 0.0L);
453 long double t = 0.0L;
454 while (begin != end) {
468template<
typename InputIterator,
typename OutputIterator >
473template<
typename InputIterator,
typename OutputIterator >
478template<
typename InputIterator,
typename OutputIterator >
486#undef RCPP_CONSTEXPR_FUNC
487#undef RCPP_CONSTEXPR_VAR
#define RCPP_CONSTEXPR_VAR
#define RCPP_CONSTEXPR_FUNC
void exp(InputIterator begin, InputIterator end, OutputIterator out)
traits::enable_if< helpers::decays_to_ctype< typenamestd::iterator_traits< InputIterator >::value_type >::value, typenamehelpers::ctype< typenamestd::iterator_traits< InputIterator >::value_type >::type >::type max_nona(InputIterator begin, InputIterator end)
traits::enable_if< helpers::decays_to_ctype< typenamestd::iterator_traits< InputIterator >::value_type >::value &&traits::same_type< typenamehelpers::ctype< typenamestd::iterator_traits< InputIterator >::value_type >::type, double >::value, double >::type mean(InputIterator begin, InputIterator end)
traits::enable_if< helpers::decays_to_ctype< typenamestd::iterator_traits< InputIterator >::value_type >::value, typenamehelpers::ctype< typenamestd::iterator_traits< InputIterator >::value_type >::type >::type sum(InputIterator begin, InputIterator end)
traits::enable_if< helpers::decays_to_ctype< typenamestd::iterator_traits< InputIterator >::value_type >::value, typenamehelpers::ctype< typenamestd::iterator_traits< InputIterator >::value_type >::type >::type prod(InputIterator begin, InputIterator end)
void log(InputIterator begin, InputIterator end, OutputIterator out)
void sqrt(InputIterator begin, InputIterator end, OutputIterator out)
traits::enable_if< helpers::decays_to_ctype< typenamestd::iterator_traits< InputIterator >::value_type >::value, typenamehelpers::ctype< typenamestd::iterator_traits< InputIterator >::value_type >::type >::type max(InputIterator begin, InputIterator end)
traits::enable_if< helpers::decays_to_ctype< typenamestd::iterator_traits< InputIterator >::value_type >::value, typenamehelpers::ctype< typenamestd::iterator_traits< InputIterator >::value_type >::type >::type min(InputIterator begin, InputIterator end)
traits::enable_if< helpers::decays_to_ctype< typenamestd::iterator_traits< InputIterator >::value_type >::value, typenamehelpers::ctype< typenamestd::iterator_traits< InputIterator >::value_type >::type >::type sum_nona(InputIterator begin, InputIterator end)
traits::enable_if< helpers::decays_to_ctype< typenamestd::iterator_traits< InputIterator >::value_type >::value, typenamehelpers::ctype< typenamestd::iterator_traits< InputIterator >::value_type >::type >::type prod_nona(InputIterator begin, InputIterator end)
traits::enable_if< helpers::decays_to_ctype< typenamestd::iterator_traits< InputIterator >::value_type >::value, typenamehelpers::ctype< typenamestd::iterator_traits< InputIterator >::value_type >::type >::type min_nona(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(...)
ctype_helper< sizeof(test(make()))>::type type
static CTYPE_DOUBLE test(const double &)
static CTYPE_FLOAT test(const float &)
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()
static RCPP_CONSTEXPR_FUNC T ZERO()
rtype_helper< typenamectype< T >::type >::type type