Loading...
Searching...
No Matches
matstat.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018 Eistec AB
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
32#ifndef MATSTAT_H
33#define MATSTAT_H
34
35#include <stdint.h>
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
44typedef struct {
45 int64_t sum;
46 uint64_t sum_sq;
47 uint32_t count;
48 int32_t mean;
49 int32_t min;
50 int32_t max;
52
56#define MATSTAT_STATE_INIT (const matstat_state_t) { \
57 .sum = 0, \
58 .sum_sq = 0, \
59 .count = 0, \
60 .mean = 0, \
61 .min = INT32_MAX, \
62 .max = INT32_MIN, \
63 }
64
71
78void matstat_add(matstat_state_t *state, int32_t value);
79
87static inline int32_t matstat_mean(const matstat_state_t *state)
88{
89 return state->mean;
90}
91
99uint64_t matstat_variance(const matstat_state_t *state);
100
111
112#ifdef __cplusplus
113}
114#endif
115
116#endif /* MATSTAT_H */
117
static int32_t matstat_mean(const matstat_state_t *state)
Return the computed mean value of all samples so far.
Definition matstat.h:87
uint64_t matstat_variance(const matstat_state_t *state)
Compute the sample variance of all samples so far.
void matstat_add(matstat_state_t *state, int32_t value)
Add a sample to state.
void matstat_clear(matstat_state_t *state)
Reset state.
void matstat_merge(matstat_state_t *dest, const matstat_state_t *src)
Combine two states.
Internal state for computing running statistics.
Definition matstat.h:44
uint32_t count
Number of values added.
Definition matstat.h:47
int64_t sum
Sum of values added.
Definition matstat.h:45
int32_t mean
Mean value.
Definition matstat.h:48
uint64_t sum_sq
Sum of squared differences.
Definition matstat.h:46
int32_t max
Maximum value seen.
Definition matstat.h:50
int32_t min
Minimum value seen.
Definition matstat.h:49