Lines Matching full:stats
34 #define sorted_value(stats, i) (stats->is_float ? stats->sorted_f[i] : stats->sorted_u64[i]) argument
35 #define unsorted_value(stats, i) (stats->is_float ? stats->values_f[i] : stats->values_u64[i]) argument
40 * @title: Stats
50 * igt_stats_t stats;
52 * igt_stats_init(&stats, 8);
54 * igt_stats_push(&stats, 2);
55 * igt_stats_push(&stats, 4);
56 * igt_stats_push(&stats, 4);
57 * igt_stats_push(&stats, 4);
58 * igt_stats_push(&stats, 5);
59 * igt_stats_push(&stats, 5);
60 * igt_stats_push(&stats, 7);
61 * igt_stats_push(&stats, 9);
63 * printf("Mean: %lf\n", igt_stats_get_mean(&stats));
65 * igt_stats_fini(&stats);
80 static void igt_stats_ensure_capacity(igt_stats_t *stats, in igt_stats_ensure_capacity() argument
83 unsigned int new_n_values = stats->n_values + n_additional_values; in igt_stats_ensure_capacity()
86 if (new_n_values <= stats->capacity) in igt_stats_ensure_capacity()
90 stats->values_u64 = realloc(stats->values_u64, in igt_stats_ensure_capacity()
91 sizeof(*stats->values_u64) * new_capacity); in igt_stats_ensure_capacity()
92 igt_assert(stats->values_u64); in igt_stats_ensure_capacity()
94 stats->capacity = new_capacity; in igt_stats_ensure_capacity()
96 free(stats->sorted_u64); in igt_stats_ensure_capacity()
97 stats->sorted_u64 = NULL; in igt_stats_ensure_capacity()
102 * @stats: An #igt_stats_t instance
105 * finished with @stats.
107 void igt_stats_init(igt_stats_t *stats) in igt_stats_init() argument
109 memset(stats, 0, sizeof(*stats)); in igt_stats_init()
111 igt_stats_ensure_capacity(stats, 128); in igt_stats_init()
113 stats->min = U64_MAX; in igt_stats_init()
114 stats->max = 0; in igt_stats_init()
119 * @stats: An #igt_stats_t instance
120 * @capacity: Number of data samples @stats can contain
124 * number of data points we want @stats to hold.
126 * igt_stats_fini() must be called once finished with @stats.
128 void igt_stats_init_with_size(igt_stats_t *stats, unsigned int capacity) in igt_stats_init_with_size() argument
130 memset(stats, 0, sizeof(*stats)); in igt_stats_init_with_size()
132 igt_stats_ensure_capacity(stats, capacity); in igt_stats_init_with_size()
134 stats->min = U64_MAX; in igt_stats_init_with_size()
135 stats->max = 0; in igt_stats_init_with_size()
136 stats->range[0] = HUGE_VAL; in igt_stats_init_with_size()
137 stats->range[1] = -HUGE_VAL; in igt_stats_init_with_size()
142 * @stats: An #igt_stats_t instance
146 void igt_stats_fini(igt_stats_t *stats) in igt_stats_fini() argument
148 free(stats->values_u64); in igt_stats_fini()
149 free(stats->sorted_u64); in igt_stats_fini()
155 * @stats: An #igt_stats_t instance
157 * Returns: #true if @stats represents a population, #false if only a sample.
161 bool igt_stats_is_population(igt_stats_t *stats) in igt_stats_is_population() argument
163 return stats->is_population; in igt_stats_is_population()
168 * @stats: An #igt_stats_t instance
187 * When giving #true to this function, the data set in @stats is considered a
190 * When newly created, @stats defaults to holding sample data.
192 void igt_stats_set_population(igt_stats_t *stats, bool full_population) in igt_stats_set_population() argument
194 if (full_population == stats->is_population) in igt_stats_set_population()
197 stats->is_population = full_population; in igt_stats_set_population()
198 stats->mean_variance_valid = false; in igt_stats_set_population()
203 * @stats: An #igt_stats_t instance
206 * Adds a new value to the @stats dataset.
208 void igt_stats_push(igt_stats_t *stats, uint64_t value) in igt_stats_push() argument
210 if (stats->is_float) { in igt_stats_push()
211 igt_stats_push_float(stats, value); in igt_stats_push()
215 igt_stats_ensure_capacity(stats, 1); in igt_stats_push()
217 stats->values_u64[stats->n_values++] = value; in igt_stats_push()
219 stats->mean_variance_valid = false; in igt_stats_push()
220 stats->sorted_array_valid = false; in igt_stats_push()
222 if (value < stats->min) in igt_stats_push()
223 stats->min = value; in igt_stats_push()
224 if (value > stats->max) in igt_stats_push()
225 stats->max = value; in igt_stats_push()
230 * @stats: An #igt_stats_t instance
233 * Adds a new value to the @stats dataset and converts the igt_stats from
236 void igt_stats_push_float(igt_stats_t *stats, double value) in igt_stats_push_float() argument
238 igt_stats_ensure_capacity(stats, 1); in igt_stats_push_float()
240 if (!stats->is_float) { in igt_stats_push_float()
243 for (n = 0; n < stats->n_values; n++) in igt_stats_push_float()
244 stats->values_f[n] = stats->values_u64[n]; in igt_stats_push_float()
246 stats->is_float = true; in igt_stats_push_float()
249 stats->values_f[stats->n_values++] = value; in igt_stats_push_float()
251 stats->mean_variance_valid = false; in igt_stats_push_float()
252 stats->sorted_array_valid = false; in igt_stats_push_float()
254 if (value < stats->range[0]) in igt_stats_push_float()
255 stats->range[0] = value; in igt_stats_push_float()
256 if (value > stats->range[1]) in igt_stats_push_float()
257 stats->range[1] = value; in igt_stats_push_float()
262 * @stats: An #igt_stats_t instance
266 * Adds an array of values to the @stats dataset.
268 void igt_stats_push_array(igt_stats_t *stats, in igt_stats_push_array() argument
273 igt_stats_ensure_capacity(stats, n_values); in igt_stats_push_array()
276 igt_stats_push(stats, values[i]); in igt_stats_push_array()
281 * @stats: An #igt_stats_t instance
283 * Retrieves the minimal value in @stats
285 uint64_t igt_stats_get_min(igt_stats_t *stats) in igt_stats_get_min() argument
287 igt_assert(!stats->is_float); in igt_stats_get_min()
288 return stats->min; in igt_stats_get_min()
293 * @stats: An #igt_stats_t instance
295 * Retrieves the maximum value in @stats
297 uint64_t igt_stats_get_max(igt_stats_t *stats) in igt_stats_get_max() argument
299 igt_assert(!stats->is_float); in igt_stats_get_max()
300 return stats->max; in igt_stats_get_max()
305 * @stats: An #igt_stats_t instance
307 * Retrieves the range of the values in @stats. The range is the difference
314 uint64_t igt_stats_get_range(igt_stats_t *stats) in igt_stats_get_range() argument
316 return igt_stats_get_max(stats) - igt_stats_get_min(stats); in igt_stats_get_range()
341 static void igt_stats_ensure_sorted_values(igt_stats_t *stats) in igt_stats_ensure_sorted_values() argument
343 if (stats->sorted_array_valid) in igt_stats_ensure_sorted_values()
346 if (!stats->sorted_u64) { in igt_stats_ensure_sorted_values()
353 stats->sorted_u64 = calloc(stats->capacity, in igt_stats_ensure_sorted_values()
354 sizeof(*stats->values_u64)); in igt_stats_ensure_sorted_values()
355 igt_assert(stats->sorted_u64); in igt_stats_ensure_sorted_values()
358 memcpy(stats->sorted_u64, stats->values_u64, in igt_stats_ensure_sorted_values()
359 sizeof(*stats->values_u64) * stats->n_values); in igt_stats_ensure_sorted_values()
361 qsort(stats->sorted_u64, stats->n_values, sizeof(*stats->values_u64), in igt_stats_ensure_sorted_values()
362 stats->is_float ? cmp_f : cmp_u64); in igt_stats_ensure_sorted_values()
364 stats->sorted_array_valid = true; in igt_stats_ensure_sorted_values()
372 igt_stats_get_median_internal(igt_stats_t *stats, in igt_stats_get_median_internal() argument
380 igt_stats_ensure_sorted_values(stats); in igt_stats_get_median_internal()
386 median = sorted_value(stats, mid); in igt_stats_get_median_internal()
402 median = (sorted_value(stats, mid) + sorted_value(stats, mid+1))/2.; in igt_stats_get_median_internal()
415 * @stats: An #igt_stats_t instance
421 * @stats dataset.
423 void igt_stats_get_quartiles(igt_stats_t *stats, in igt_stats_get_quartiles() argument
429 if (stats->n_values < 3) { in igt_stats_get_quartiles()
439 ret = igt_stats_get_median_internal(stats, 0, stats->n_values, in igt_stats_get_quartiles()
444 ret = igt_stats_get_median_internal(stats, 0, lower_end, NULL, NULL); in igt_stats_get_quartiles()
448 ret = igt_stats_get_median_internal(stats, upper_start, stats->n_values, in igt_stats_get_quartiles()
456 * @stats: An #igt_stats_t instance
460 * (IQR) of the @stats dataset.
462 double igt_stats_get_iqr(igt_stats_t *stats) in igt_stats_get_iqr() argument
466 igt_stats_get_quartiles(stats, &q1, NULL, &q3); in igt_stats_get_iqr()
472 * @stats: An #igt_stats_t instance
474 * Retrieves the median of the @stats dataset.
476 double igt_stats_get_median(igt_stats_t *stats) in igt_stats_get_median() argument
478 return igt_stats_get_median_internal(stats, 0, stats->n_values, in igt_stats_get_median()
490 static void igt_stats_knuth_mean_variance(igt_stats_t *stats) in igt_stats_knuth_mean_variance() argument
495 if (stats->mean_variance_valid) in igt_stats_knuth_mean_variance()
498 for (i = 0; i < stats->n_values; i++) { in igt_stats_knuth_mean_variance()
499 double delta = unsorted_value(stats, i) - mean; in igt_stats_knuth_mean_variance()
502 m2 += delta * (unsorted_value(stats, i) - mean); in igt_stats_knuth_mean_variance()
505 stats->mean = mean; in igt_stats_knuth_mean_variance()
506 if (stats->n_values > 1 && !stats->is_population) in igt_stats_knuth_mean_variance()
507 stats->variance = m2 / (stats->n_values - 1); in igt_stats_knuth_mean_variance()
509 stats->variance = m2 / stats->n_values; in igt_stats_knuth_mean_variance()
510 stats->mean_variance_valid = true; in igt_stats_knuth_mean_variance()
515 * @stats: An #igt_stats_t instance
517 * Retrieves the mean of the @stats dataset.
519 double igt_stats_get_mean(igt_stats_t *stats) in igt_stats_get_mean() argument
521 igt_stats_knuth_mean_variance(stats); in igt_stats_get_mean()
523 return stats->mean; in igt_stats_get_mean()
528 * @stats: An #igt_stats_t instance
530 * Retrieves the variance of the @stats dataset.
532 double igt_stats_get_variance(igt_stats_t *stats) in igt_stats_get_variance() argument
534 igt_stats_knuth_mean_variance(stats); in igt_stats_get_variance()
536 return stats->variance; in igt_stats_get_variance()
541 * @stats: An #igt_stats_t instance
543 * Retrieves the standard deviation of the @stats dataset.
545 double igt_stats_get_std_deviation(igt_stats_t *stats) in igt_stats_get_std_deviation() argument
547 igt_stats_knuth_mean_variance(stats); in igt_stats_get_std_deviation()
549 return sqrt(stats->variance); in igt_stats_get_std_deviation()
554 * @stats: An #igt_stats_t instance
558 * of the @stats dataset.
566 double igt_stats_get_iqm(igt_stats_t *stats) in igt_stats_get_iqm() argument
571 igt_stats_ensure_sorted_values(stats); in igt_stats_get_iqm()
573 q1 = (stats->n_values + 3) / 4; in igt_stats_get_iqm()
574 q3 = 3 * stats->n_values / 4; in igt_stats_get_iqm()
578 mean += (sorted_value(stats, q1 + i) - mean) / (i + 1); in igt_stats_get_iqm()
580 if (stats->n_values % 4) { in igt_stats_get_iqm()
581 double rem = .5 * (stats->n_values % 4) / 4; in igt_stats_get_iqm()
583 q1 = (stats->n_values) / 4; in igt_stats_get_iqm()
584 q3 = (3 * stats->n_values + 3) / 4; in igt_stats_get_iqm()
586 mean += rem * (sorted_value(stats, q1) - mean) / i++; in igt_stats_get_iqm()
587 mean += rem * (sorted_value(stats, q3) - mean) / i++; in igt_stats_get_iqm()
595 * @stats: An #igt_stats_t instance
597 * Retrieves the [trimean](https://en.wikipedia.org/wiki/Trimean) of the @stats
603 double igt_stats_get_trimean(igt_stats_t *stats) in igt_stats_get_trimean() argument
606 igt_stats_get_quartiles(stats, &q1, &q2, &q3); in igt_stats_get_trimean()