Modular C
C◼llong◼avgvar: symbols inserted from C◼snippet◼avg.
+ Collaboration diagram for C◼llong◼avgvar: symbols inserted from C◼snippet◼avg.:
C◼snippet◼avg◼rettype C◼llong◼avgv (__size n, C◼llong volatile arr[n])
 Compute the average of array arr. More...
 
C◼snippet◼avg◼rettype C◼llong◼var3v (__size n, C◼llong volatile arr[n], double est)
 compute the variance of vector arr, by using the estimate of the mean est. More...
 
C◼snippet◼avg◼rettype C◼llong◼varv (__size n, C◼llong volatile arr[n])
 Compute the variance of the values in array arr. More...
 
#define C◼llong◼avg(...)   C◼llong◼avgv(sizeof((C◼llong[]){ __VA_ARGS__ })/sizeof(C◼llong), (C◼llong[]){ __VA_ARGS__ })
 Compute the average of arguments. More...
 
#define C◼llong◼var(...)   C◼llong◼varv(sizeof((C◼llong[]){ __VA_ARGS__ })/sizeof(C◼llong), (C◼llong[]){ __VA_ARGS__ })
 Compute the variance of the arguments. More...
 

Detailed Description

See also
C◼snippet◼avg snippet: identifiers inserted directly to an importer for details
This import uses the following slot(s)
slotreplacement
C◼snippet◼avg◼rettypeuses default

Macro Definition Documentation

§ C◼llong◼avg

#define C◼llong◼avg (   ...)    C◼llong◼avgv(sizeof((C◼llong[]){ __VA_ARGS__ })/sizeof(C◼llong), (C◼llong[]){ __VA_ARGS__ })

Compute the average of arguments.

Definition at line 457 of file C-llong.c.

§ C◼llong◼var

#define C◼llong◼var (   ...)    C◼llong◼varv(sizeof((C◼llong[]){ __VA_ARGS__ })/sizeof(C◼llong), (C◼llong[]){ __VA_ARGS__ })

Compute the variance of the arguments.

Definition at line 503 of file C-llong.c.

Function Documentation

§ C◼llong◼avgv()

C◼snippet◼avg◼rettype C◼llong◼avgv ( __size  n,
C◼llong volatile  arr[n] 
)
inline

Compute the average of array arr.

Returns
defaults to double if not overwritten by the importer.

Definition at line 448 of file C-llong.c.

448  {
449 #line 23 "/home/gustedt/build/cmod/C/C-snippet-avg.X"
451  return ret/n;
452 }
double C◼snippet◼avg◼rettype
The default type for the averaging functions.
Definition: C-snippet-avg.c:51
C◼llong C◼llong◼sumv(__size n, C◼llong volatile arr[n])
Perform cumulative operation on array arr of length n.
Definition: C-llong.c:279

§ C◼llong◼var3v()

C◼snippet◼avg◼rettype C◼llong◼var3v ( __size  n,
C◼llong volatile  arr[n],
double  est 
)
inline

compute the variance of vector arr, by using the estimate of the mean est.

If est is the exact mean, the centered mean m1 would be zero if there wouldn't be any rounding errors, and theoretically we could avoid this part of the computation. But in case that there are in fact rounding errors, this here is the good strategy to compensate for them. This is in particular relevant if n is large and rounding errors may accumulate to a substantial value.

Returns
defaults to double if not overwritten by the importer.

Definition at line 473 of file C-llong.c.

473  {
474 #line 47 "/home/gustedt/build/cmod/C/C-snippet-avg.X"
477  for (__size i = 0; i < n; ++i) {
478 #line 50 "/home/gustedt/build/cmod/C/C-snippet-avg.X"
479  C◼snippet◼avg◼rettype val = (arr[i] - est);
480  m1 += val;
481  m2 += val*val;
482  }
483  return (m2 - m1*m1/n)/(n-1);
484 }
double C◼snippet◼avg◼rettype
The default type for the averaging functions.
Definition: C-snippet-avg.c:51

§ C◼llong◼varv()

C◼snippet◼avg◼rettype C◼llong◼varv ( __size  n,
C◼llong volatile  arr[n] 
)
inline

Compute the variance of the values in array arr.

This could be computed faster, by first computing the average and then only the squares of the deviations of that. Using var3v() results in so-called compensated variance calculation that is numerically more stable.

Definition at line 495 of file C-llong.c.

495  {
496 #line 67 "/home/gustedt/build/cmod/C/C-snippet-avg.X"
497  return C◼llong◼var3v(n, arr, C◼llong◼avgv(n, arr));
498 }
C◼snippet◼avg◼rettype C◼llong◼avgv(__size n, C◼llong volatile arr[n])
Compute the average of array arr.
Definition: C-llong.c:448
C◼snippet◼avg◼rettype C◼llong◼var3v(__size n, C◼llong volatile arr[n], double est)
compute the variance of vector arr, by using the estimate of the mean est.
Definition: C-llong.c:473