PebbleOS
Loading...
Searching...
No Matches
Typedefs | Enumerations | Functions
Statistics

Basic statistics over arrays of int32_t. More...

Typedefs

typedef bool(* pbl_stats_filter_t) (int index, int32_t value, void *context)
 Filter of the values included in pbl_stats_calculate().
 

Enumerations

enum  pbl_stats_op {
  PBL_STATS_OP_SUM = (1 << 0) , PBL_STATS_OP_AVERAGE = (1 << 1) , PBL_STATS_OP_MIN = (1 << 2) , PBL_STATS_OP_MAX = (1 << 3) ,
  PBL_STATS_OP_COUNT = (1 << 4) , PBL_STATS_OP_CONSECUTIVE = (1 << 5) , PBL_STATS_OP_CONSECUTIVE_FIRST = (1 << 6) , PBL_STATS_OP_MEDIAN = (1 << 7)
}
 Operations of pbl_stats_calculate(), combined as a bit field. More...
 

Functions

void pbl_stats_calculate (enum pbl_stats_op op, const int32_t *data, size_t num_data, pbl_stats_filter_t filter, void *context, int32_t *basic_out)
 Calculate basic statistics over an array.
 
int32_t pbl_stats_weighted_median (const int32_t *vals, const int32_t *weights_x100, size_t num_data)
 Calculate the weighted median of an array.
 

Detailed Description

Basic statistics over arrays of int32_t.

int32_t out[2];
pbl_stats_calculate(PBL_STATS_OP_SUM | PBL_STATS_OP_MAX, samples, num_samples, NULL, NULL,
out);
// out[0] is the sum, out[1] the maximum
void pbl_stats_calculate(enum pbl_stats_op op, const int32_t *data, size_t num_data, pbl_stats_filter_t filter, void *context, int32_t *basic_out)
Calculate basic statistics over an array.
@ PBL_STATS_OP_SUM
Sum.
Definition stats.h:42
@ PBL_STATS_OP_MAX
Maximum; INT32_MIN without values.
Definition stats.h:48

Typedef Documentation

◆ pbl_stats_filter_t

typedef bool(* pbl_stats_filter_t) (int index, int32_t value, void *context)

Filter of the values included in pbl_stats_calculate().

Parameters
indexIndex of the value in the data array.
valueValue.
contextFilter data.
Returns
true to include the value.

Enumeration Type Documentation

◆ pbl_stats_op

Operations of pbl_stats_calculate(), combined as a bit field.

With a filter, every operation only considers the values it accepts.

Enumerator
PBL_STATS_OP_SUM 

Sum.

PBL_STATS_OP_AVERAGE 

Average, truncated; 0 without values.

PBL_STATS_OP_MIN 

Minimum; INT32_MAX without values.

PBL_STATS_OP_MAX 

Maximum; INT32_MIN without values.

PBL_STATS_OP_COUNT 

Number of values included; the number of data points without a filter.

PBL_STATS_OP_CONSECUTIVE 

Longest run of consecutive values included; the number of data points without a filter.

PBL_STATS_OP_CONSECUTIVE_FIRST 

Length of the run of included values at the start of the data.

PBL_STATS_OP_MEDIAN 

Median; the lower of the two middle values for an even count.

Function Documentation

◆ pbl_stats_calculate()

void pbl_stats_calculate ( enum pbl_stats_op  op,
const int32_t *  data,
size_t  num_data,
pbl_stats_filter_t  filter,
void *  context,
int32_t *  basic_out 
)

Calculate basic statistics over an array.

Results are written to basic_out in the order of enum pbl_stats_op, without gaps: for PBL_STATS_OP_MAX | PBL_STATS_OP_SUM, basic_out[0] is the sum and basic_out[1] the maximum.

Parameters
opOperations, a combination of enum pbl_stats_op.
dataValues. Nothing is written if NULL.
num_dataNumber of values.
filterFilter, or NULL to include every value.
contextFilter data.
[out]basic_outOne result per operation in op.

◆ pbl_stats_weighted_median()

int32_t pbl_stats_weighted_median ( const int32_t *  vals,
const int32_t *  weights_x100,
size_t  num_data 
)

Calculate the weighted median of an array.

The weighted median is the value x[k] such that the total weight of the values below it and the total weight of the values above it are each at most half the total weight. When two values qualify, their mean is returned. Uses integer division throughout and allocates a temporary copy with calloc().

Parameters
valsValues.
weights_x100Positive weights, scaled by 100.
num_dataNumber of values.
Returns
Weighted median, or 0 for invalid arguments, zero total weight or allocation failure.