Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
Stats Struct Reference

#include <Stats.h>

Public Member Functions

void log (int16_t golden, int16_t candidate)
 
void print () const
 
void log (int16_t golden, int16_t candidate)
 
void print () const
 
 Stats (const skia_private::TArray< double > &samples, bool want_plot)
 

Public Attributes

int64_t diff_8_bits = 0
 
int64_t max_diff = 0
 
int64_t min_diff = 0
 
int64_t total = 0
 
int diff_8_bits = 0
 
int max_diff = 0
 
int min_diff = 0
 
double min
 
double max
 
double mean
 
double var
 
double median
 
SkString plot
 

Detailed Description

Definition at line 15 of file bilerp-study.cpp.

Constructor & Destructor Documentation

◆ Stats()

Stats::Stats ( const skia_private::TArray< double > &  samples,
bool  want_plot 
)
inline

Definition at line 24 of file Stats.h.

24 {
25 int n = samples.size();
26 if (!n) {
27 min = max = mean = var = median = 0;
28 return;
29 }
30
31 min = samples[0];
32 max = samples[0];
33 for (int i = 0; i < n; i++) {
34 if (samples[i] < min) { min = samples[i]; }
35 if (samples[i] > max) { max = samples[i]; }
36 }
37
38 double sum = 0.0;
39 for (int i = 0 ; i < n; i++) {
40 sum += samples[i];
41 }
42 mean = sum / n;
43
44 double err = 0.0;
45 for (int i = 0 ; i < n; i++) {
46 err += (samples[i] - mean) * (samples[i] - mean);
47 }
48 var = sk_ieee_double_divide(err, n-1);
49
50 std::vector<double> sorted(samples.begin(), samples.end());
51 std::sort(sorted.begin(), sorted.end());
52 median = sorted[n/2];
53
54 // Normalize samples to [min, max] in as many quanta as we have distinct bars to print.
55 for (int i = 0; want_plot && i < n; i++) {
56 if (min == max) {
57 // All samples are the same value. Don't divide by zero.
58 plot.append(kBars[0]);
59 continue;
60 }
61
62 double s = samples[i];
63 s -= min;
64 s /= (max - min);
65 s *= (std::size(kBars) - 1);
66 const size_t bar = (size_t)(s + 0.5);
67 SkASSERT_RELEASE(bar < std::size(kBars));
68 plot.append(kBars[bar]);
69 }
70 }
#define SkASSERT_RELEASE(cond)
Definition SkAssert.h:100
static constexpr double sk_ieee_double_divide(double numer, double denom)
static const char * kBars[]
Definition Stats.h:20
void append(const char text[])
Definition SkString.h:203
int size() const
Definition SkTArray.h:416
struct MyStruct s
double var
Definition Stats.h:75
double max
Definition Stats.h:73
double min
Definition Stats.h:72
double mean
Definition Stats.h:74
SkString plot
Definition Stats.h:77
double median
Definition Stats.h:76

Member Function Documentation

◆ log() [1/2]

void Stats::log ( int16_t  golden,
int16_t  candidate 
)
inline

Definition at line 21 of file bilerp-study.cpp.

21 {
22 int64_t diff = candidate - golden;
23 max_diff = std::max(max_diff, diff);
24 min_diff = std::min(min_diff, diff);
25 diff_8_bits += candidate != golden;
26 total++;
27 }
int64_t total
int64_t min_diff
int64_t max_diff
int64_t diff_8_bits

◆ log() [2/2]

void Stats::log ( int16_t  golden,
int16_t  candidate 
)
inline

Definition at line 21 of file lerp-study.cpp.

21 {
22 int diff = candidate - golden;
23 max_diff = std::max(max_diff, diff);
24 min_diff = std::min(min_diff, diff);
25 diff_8_bits += candidate != golden;
26 total++;
27 }

◆ print() [1/2]

void Stats::print ( ) const
inline

Definition at line 29 of file bilerp-study.cpp.

29 {
30 printf("8-bit diff: %lld - %g%%\n", diff_8_bits, 100.0 * diff_8_bits / total);
31 printf("differences min: %lld max: %lld\n", min_diff, max_diff);
32 printf("total: %lld\n", total);
33 }
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1

◆ print() [2/2]

void Stats::print ( ) const
inline

Definition at line 29 of file lerp-study.cpp.

29 {
30 printf("8-bit diff: %d - %g%%\n", diff_8_bits, 100.0 * diff_8_bits / total);
31 printf("differences min: %d max: %d\n", min_diff, max_diff);
32 printf("total: %lld\n", total);
33 }

Member Data Documentation

◆ diff_8_bits [1/2]

int64_t Stats::diff_8_bits = 0

Definition at line 16 of file bilerp-study.cpp.

◆ diff_8_bits [2/2]

int Stats::diff_8_bits = 0

Definition at line 16 of file lerp-study.cpp.

◆ max

double Stats::max

Definition at line 73 of file Stats.h.

◆ max_diff [1/2]

int64_t Stats::max_diff = 0

Definition at line 17 of file bilerp-study.cpp.

◆ max_diff [2/2]

int Stats::max_diff = 0

Definition at line 17 of file lerp-study.cpp.

◆ mean

double Stats::mean

Definition at line 74 of file Stats.h.

◆ median

double Stats::median

Definition at line 76 of file Stats.h.

◆ min

double Stats::min

Definition at line 72 of file Stats.h.

◆ min_diff [1/2]

int64_t Stats::min_diff = 0

Definition at line 18 of file bilerp-study.cpp.

◆ min_diff [2/2]

int Stats::min_diff = 0

Definition at line 18 of file lerp-study.cpp.

◆ plot

SkString Stats::plot

Definition at line 77 of file Stats.h.

◆ total

int64_t Stats::total = 0

Definition at line 19 of file bilerp-study.cpp.

◆ var

double Stats::var

Definition at line 75 of file Stats.h.


The documentation for this struct was generated from the following files: