Compute the default set of or requested quantiles for a set of data the quantile formula used is same as Excel and R default method.
678 int init_quantiles = 0;
683 #if POSTGIS_DEBUG_LEVEL > 0
689 #if POSTGIS_DEBUG_LEVEL > 0
693 assert(NULL != stats);
694 assert(NULL != rtn_count);
697 rterror(
"rt_band_get_quantiles: rt_bandstats object has no value");
702 if (NULL == quantiles) {
704 if (quantiles_count < 2)
707 quantiles =
rtalloc(
sizeof(
double) * quantiles_count);
709 if (NULL == quantiles) {
710 rterror(
"rt_band_get_quantiles: Could not allocate memory for quantile input");
715 for (i = 0; i <= quantiles_count; i++)
716 quantiles[i] = ((
double) i) / quantiles_count;
721 for (i = 0; i < quantiles_count; i++) {
722 if (quantiles[i] < 0. || quantiles[i] > 1.) {
723 rterror(
"rt_band_get_quantiles: Quantile value not between 0 and 1");
724 if (init_quantiles)
rtdealloc(quantiles);
728 quicksort(quantiles, quantiles + quantiles_count - 1);
733 rterror(
"rt_band_get_quantiles: Could not allocate memory for quantile output");
734 if (init_quantiles)
rtdealloc(quantiles);
750 for (i = 0; i < quantiles_count; i++) {
753 h = ((stats->
count - 1.) * quantiles[i]) + 1.;
764 #if POSTGIS_DEBUG_LEVEL > 0
766 elapsed = ((double) (stop - start)) / CLOCKS_PER_SEC;
770 *rtn_count = quantiles_count;
771 if (init_quantiles)
rtdealloc(quantiles);
void rterror(const char *fmt,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.
#define RASTER_DEBUG(level, msg)
#define RASTER_DEBUGF(level, msg,...)
void rtdealloc(void *mem)
static void quicksort(double *left, double *right)