10#include <gsl/gsl_vector.h>
11#include <gsl/gsl_sort.h>
12#include <gsl/gsl_statistics.h>
32#undef GSLHELPERS_INT64
40std::shared_ptr<gsl_vector> NewGSLVector(
size_t n);
47 typedef typename std::iterator_traits<Iter_T>::value_type value_type;
48 typedef typename std::iterator_traits<Iter_T>::reference reference;
49 typedef typename std::iterator_traits<Iter_T>::difference_type
51 typedef typename std::iterator_traits<Iter_T>::pointer pointer;
52 typedef std::random_access_iterator_tag iterator_category;
53 typedef stride_iter self;
56 constexpr stride_iter( ) : iter(nullptr), step(0) { }
57 constexpr stride_iter(
const self &x) : iter(x.iter), step(x.step) { }
58 constexpr stride_iter(Iter_T x, difference_type n) : iter(x), step(n) { }
61 constexpr self &operator++( )
66 constexpr self operator++(
int)
72 constexpr self &operator+=(difference_type x)
77 constexpr self &operator--( )
82 constexpr self operator--(
int)
88 constexpr self &operator-=(difference_type x)
93 constexpr reference operator[](difference_type n)
95 return iter[n * step];
97 reference operator*( )
const
103 constexpr friend bool operator==(
const self &x,
const self &y)
105 assert(x.step == y.step);
106 return x.iter == y.iter;
108 constexpr friend bool operator!=(
const self &x,
const self &y)
110 assert(x.step == y.step);
111 return x.iter != y.iter;
113 constexpr friend bool operator<(
const self &x,
const self &y)
115 assert(x.step == y.step);
116 return x.iter < y.iter;
118 constexpr friend difference_type operator-(
const self &x,
const self &y)
120 assert(x.step == y.step);
121 return (x.iter - y.iter) / x.step;
123 constexpr friend self operator+(
const self &x, difference_type y)
125 assert(x.step == y.step);
126 return x += y * x.step;
128 constexpr friend self operator+(difference_type x,
const self &y)
130 assert(x.step == y.step);
131 return y += x * x.step;
135 difference_type step;
138template<
class Iter_T >
139constexpr static stride_iter<Iter_T> make_strided_iter(Iter_T i,
typename stride_iter<Iter_T>::difference_type stride)
141 return stride_iter<Iter_T>(i, stride);
147inline void gslSort(uint8_t data[],
const size_t stride,
const size_t n)
149 gsl_sort_uchar(data, stride, n);
151inline void gslSort(
double data[],
const size_t stride,
const size_t n)
153 gsl_sort(data, stride, n);
155inline void gslSort(
float data[],
const size_t stride,
const size_t n)
157 gsl_sort_float(data, stride, n);
159inline void gslSort(uint16_t data[],
const size_t stride,
const size_t n)
161 gsl_sort_ushort(data, stride, n);
163inline void gslSort(int16_t data[],
const size_t stride,
const size_t n)
165 gsl_sort_short(data, stride, n);
167inline void gslSort(uint32_t data[],
const size_t stride,
const size_t n)
169 gsl_sort_uint(data, stride, n);
171inline void gslSort(int32_t data[],
const size_t stride,
const size_t n)
173 gsl_sort_int(data, stride, n);
175#ifdef GSLHELPERS_INT64
176inline void gslSort(int64_t data[],
const size_t stride,
const size_t n)
178 gsl_sort_long(data, stride, n);
188inline double gslMean(
const uint8_t data[],
const size_t stride,
const size_t n)
190 return gsl_stats_uchar_mean(data, stride, n);
192inline double gslMean(
const double data[],
const size_t stride,
const size_t n)
194 return gsl_stats_mean(data, stride, n);
196inline double gslMean(
const float data[],
const size_t stride,
const size_t n)
198 return gsl_stats_float_mean(data, stride, n);
200inline double gslMean(
const uint16_t data[],
const size_t stride,
const size_t n)
202 return gsl_stats_ushort_mean(data, stride, n);
204inline double gslMean(
const int16_t data[],
const size_t stride,
const size_t n)
206 return gsl_stats_short_mean(data, stride, n);
208inline double gslMean(
const uint32_t data[],
const size_t stride,
const size_t n)
210 return gsl_stats_uint_mean(data, stride, n);
212inline double gslMean(
const int32_t data[],
const size_t stride,
const size_t n)
214 return gsl_stats_int_mean(data, stride, n);
216#ifdef GSLHELPERS_INT64
217inline double gslMean(
const int64_t data[],
const size_t stride,
const size_t n)
219 return gsl_stats_long_mean(data, stride, n);
224inline double gslGastwirthMeanFromSortedData(
const uint8_t data[],
const size_t stride,
const size_t n)
226 return gsl_stats_uchar_gastwirth_from_sorted_data(data, stride, n);
228inline double gslGastwirthMeanFromSortedData(
const double data[],
const size_t stride,
const size_t n)
230 return gsl_stats_gastwirth_from_sorted_data(data, stride, n);
232inline double gslGastwirthMeanFromSortedData(
const float data[],
const size_t stride,
const size_t n)
234 return gsl_stats_float_gastwirth_from_sorted_data(data, stride, n);
236inline double gslGastwirthMeanFromSortedData(
const uint16_t data[],
const size_t stride,
const size_t n)
238 return gsl_stats_ushort_gastwirth_from_sorted_data(data, stride, n);
240inline double gslGastwirthMeanFromSortedData(
const int16_t data[],
const size_t stride,
const size_t n)
242 return gsl_stats_short_gastwirth_from_sorted_data(data, stride, n);
244inline double gslGastwirthMeanFromSortedData(
const uint32_t data[],
const size_t stride,
const size_t n)
246 return gsl_stats_uint_gastwirth_from_sorted_data(data, stride, n);
248inline double gslGastwirthMeanFromSortedData(
const int32_t data[],
const size_t stride,
const size_t n)
250 return gsl_stats_int_gastwirth_from_sorted_data(data, stride, n);
252#ifdef GSLHELPERS_INT64
253inline double gslGastwirthMeanFromSortedData(
const int64_t data[],
const size_t stride,
const size_t n)
255 return gsl_stats_long_gastwirth_from_sorted_data(data, stride, n);
260inline double gslTrimmedMeanFromSortedData(
const double trim,
const uint8_t data[],
const size_t stride,
const size_t n)
262 return gsl_stats_uchar_trmean_from_sorted_data(trim, data, stride, n);
264inline double gslTrimmedMeanFromSortedData(
const double trim,
const double data[],
const size_t stride,
const size_t n)
266 return gsl_stats_trmean_from_sorted_data(trim, data, stride, n);
268inline double gslTrimmedMeanFromSortedData(
const double trim,
const float data[],
const size_t stride,
const size_t n)
270 return gsl_stats_float_trmean_from_sorted_data(trim, data, stride, n);
272inline double gslTrimmedMeanFromSortedData(
const double trim,
const uint16_t data[],
const size_t stride,
275 return gsl_stats_ushort_trmean_from_sorted_data(trim, data, stride, n);
277inline double gslTrimmedMeanFromSortedData(
const double trim,
const int16_t data[],
const size_t stride,
const size_t n)
279 return gsl_stats_short_trmean_from_sorted_data(trim, data, stride, n);
281inline double gslTrimmedMeanFromSortedData(
const double trim,
const uint32_t data[],
const size_t stride,
284 return gsl_stats_uint_trmean_from_sorted_data(trim, data, stride, n);
286inline double gslTrimmedMeanFromSortedData(
const double trim,
const int32_t data[],
const size_t stride,
const size_t n)
288 return gsl_stats_int_trmean_from_sorted_data(trim, data, stride, n);
290#ifdef GSLHELPERS_INT64
291inline double gslTrimmedMeanFromSortedData(
const double trim,
const int64_t data[],
const size_t stride,
const size_t n)
293 return gsl_stats_long_trmean_from_sorted_data(trim, data, stride, n);
300inline double gslMedianFromSortedData(
const uint8_t data[],
const size_t stride,
const size_t n)
302 return gsl_stats_uchar_median_from_sorted_data(data, stride, n);
304inline double gslMedianFromSortedData(
const double data[],
const size_t stride,
const size_t n)
306 return gsl_stats_median_from_sorted_data(data, stride, n);
308inline double gslMedianFromSortedData(
const float data[],
const size_t stride,
const size_t n)
310 return gsl_stats_float_median_from_sorted_data(data, stride, n);
312inline double gslMedianFromSortedData(
const uint16_t data[],
const size_t stride,
const size_t n)
314 return gsl_stats_ushort_median_from_sorted_data(data, stride, n);
316inline double gslMedianFromSortedData(
const int16_t data[],
const size_t stride,
const size_t n)
318 return gsl_stats_short_median_from_sorted_data(data, stride, n);
320inline double gslMedianFromSortedData(
const uint32_t data[],
const size_t stride,
const size_t n)
322 return gsl_stats_uint_median_from_sorted_data(data, stride, n);
324inline double gslMedianFromSortedData(
const int32_t data[],
const size_t stride,
const size_t n)
326 return gsl_stats_int_median_from_sorted_data(data, stride, n);
328#ifdef GSLHELPERS_INT64
329inline double gslMedianFromSortedData(
const int64_t data[],
const size_t stride,
const size_t n)
331 return gsl_stats_long_median_from_sorted_data(data, stride, n);
336inline double gslVariance(
const uint8_t data[],
const size_t stride,
const size_t n)
338 return gsl_stats_uchar_variance(data, stride, n);
340inline double gslVariance(
const double data[],
const size_t stride,
const size_t n)
342 return gsl_stats_variance(data, stride, n);
344inline double gslVariance(
const float data[],
const size_t stride,
const size_t n)
346 return gsl_stats_float_variance(data, stride, n);
348inline double gslVariance(
const uint16_t data[],
const size_t stride,
const size_t n)
350 return gsl_stats_ushort_variance(data, stride, n);
352inline double gslVariance(
const int16_t data[],
const size_t stride,
const size_t n)
354 return gsl_stats_short_variance(data, stride, n);
356inline double gslVariance(
const uint32_t data[],
const size_t stride,
const size_t n)
358 return gsl_stats_uint_variance(data, stride, n);
360inline double gslVariance(
const int32_t data[],
const size_t stride,
const size_t n)
362 return gsl_stats_int_variance(data, stride, n);
364#ifdef GSLHELPERS_INT64
365inline double gslVariance(
const int64_t data[],
const size_t stride,
const size_t n)
367 return gsl_stats_long_variance(data, stride, n);
373inline double gslStandardDeviation(
const uint8_t data[],
const size_t stride,
const size_t n)
375 return gsl_stats_uchar_sd(data, stride, n);
377inline double gslStandardDeviation(
const double data[],
const size_t stride,
const size_t n)
379 return gsl_stats_sd(data, stride, n);
381inline double gslStandardDeviation(
const float data[],
const size_t stride,
const size_t n)
383 return gsl_stats_float_sd(data, stride, n);
385inline double gslStandardDeviation(
const uint16_t data[],
const size_t stride,
const size_t n)
387 return gsl_stats_ushort_sd(data, stride, n);
389inline double gslStandardDeviation(
const int16_t data[],
const size_t stride,
const size_t n)
391 return gsl_stats_short_sd(data, stride, n);
393inline double gslStandardDeviation(
const uint32_t data[],
const size_t stride,
const size_t n)
395 return gsl_stats_uint_sd(data, stride, n);
397inline double gslStandardDeviation(
const int32_t data[],
const size_t stride,
const size_t n)
399 return gsl_stats_int_sd(data, stride, n);
401#ifdef GSLHELPERS_INT64
402inline double gslStandardDeviation(
const int64_t data[],
const size_t stride,
const size_t n)
404 return gsl_stats_long_sd(data, stride, n);
410inline double gslMAD(
const uint8_t data[],
const size_t stride,
const size_t n,
double work[])
412 return gsl_stats_uchar_mad(data, stride, n, work);
414inline double gslMAD(
const double data[],
const size_t stride,
const size_t n,
double work[])
416 return gsl_stats_mad(data, stride, n, work);
418inline double gslMAD(
const float data[],
const size_t stride,
const size_t n,
double work[])
420 return gsl_stats_float_mad(data, stride, n, work);
422inline double gslMAD(
const uint16_t data[],
const size_t stride,
const size_t n,
double work[])
424 return gsl_stats_ushort_mad(data, stride, n, work);
426inline double gslMAD(
const int16_t data[],
const size_t stride,
const size_t n,
double work[])
428 return gsl_stats_short_mad(data, stride, n, work);
430inline double gslMAD(
const uint32_t data[],
const size_t stride,
const size_t n,
double work[])
432 return gsl_stats_uint_mad(data, stride, n, work);
434inline double gslMAD(
const int32_t data[],
const size_t stride,
const size_t n,
double work[])
436 return gsl_stats_int_mad(data, stride, n, work);
438#ifdef GSLHELPERS_INT64
439inline double gslMAD(
const int64_t data[],
const size_t stride,
const size_t n,
double work[])
441 return gsl_stats_long_mad(data, stride, n, work);
446inline double gslSnFromSortedData(
const uint8_t data[],
const size_t stride,
const size_t n, uint8_t work[])
448 return gsl_stats_uchar_Sn_from_sorted_data(data, stride, n, work);
450inline double gslSnFromSortedData(
const double data[],
const size_t stride,
const size_t n,
double work[])
452 return gsl_stats_Sn_from_sorted_data(data, stride, n, work);
454inline double gslSnFromSortedData(
const float data[],
const size_t stride,
const size_t n,
float work[])
456 return gsl_stats_float_Sn_from_sorted_data(data, stride, n, work);
458inline double gslSnFromSortedData(
const uint16_t data[],
const size_t stride,
const size_t n, uint16_t work[])
460 return gsl_stats_ushort_Sn_from_sorted_data(data, stride, n, work);
462inline double gslSnFromSortedData(
const int16_t data[],
const size_t stride,
const size_t n, int16_t work[])
464 return gsl_stats_short_Sn_from_sorted_data(data, stride, n, work);
466inline double gslSnFromSortedData(
const uint32_t data[],
const size_t stride,
const size_t n, uint32_t work[])
468 return gsl_stats_uint_Sn_from_sorted_data(data, stride, n, work);
470inline double gslSnFromSortedData(
const int32_t data[],
const size_t stride,
const size_t n, int32_t work[])
472 return gsl_stats_int_Sn_from_sorted_data(data, stride, n, work);
474#ifdef GSLHELPERS_INT64
475inline double gslSnFromSortedData(
const int64_t data[],
const size_t stride,
const size_t n, int64_t work[])
477 return gsl_stats_long_Sn_from_sorted_data(data, stride, n, work);
481inline double gslQnFromSortedData(
const uint8_t data[],
const size_t stride,
const size_t n, uint8_t work[],
484 return gsl_stats_uchar_Qn_from_sorted_data(data, stride, n, work, work_int);
486inline double gslQnFromSortedData(
const double data[],
const size_t stride,
const size_t n,
double work[],
489 return gsl_stats_Qn_from_sorted_data(data, stride, n, work, work_int);
491inline double gslQnFromSortedData(
const float data[],
const size_t stride,
const size_t n,
float work[],
int work_int[])
493 return gsl_stats_float_Qn_from_sorted_data(data, stride, n, work, work_int);
495inline double gslQnFromSortedData(
const uint16_t data[],
const size_t stride,
const size_t n, uint16_t work[],
498 return gsl_stats_ushort_Qn_from_sorted_data(data, stride, n, work, work_int);
500inline double gslQnFromSortedData(
const int16_t data[],
const size_t stride,
const size_t n, int16_t work[],
503 return gsl_stats_short_Qn_from_sorted_data(data, stride, n, work, work_int);
505inline double gslQnFromSortedData(
const uint32_t data[],
const size_t stride,
const size_t n, uint32_t work[],
508 return gsl_stats_uint_Qn_from_sorted_data(data, stride, n, work, work_int);
510inline double gslQnFromSortedData(
const int32_t data[],
const size_t stride,
const size_t n, int32_t work[],
513 return gsl_stats_int_Qn_from_sorted_data(data, stride, n, work, work_int);
515#ifdef GSLHELPERS_INT64
516inline double gslQnFromSortedData(
const int64_t data[],
const size_t stride,
const size_t n, int64_t work[],
519 return gsl_stats_long_Qn_from_sorted_data(data, stride, n, work, work_int);