Modular C
C◼real◼float◼avgvar: symbols inserted from C◼snippet◼avg.
+ Collaboration diagram for C◼real◼float◼avgvar: symbols inserted from C◼snippet◼avg.:
C◼real◼float C◼real◼float◼avgv (__size n, C◼real◼float volatile arr[n])
 Compute the average of array arr. More...
 
C◼real◼float C◼real◼float◼var3v (__size n, C◼real◼float volatile arr[n], double est)
 compute the variance of vector arr, by using the estimate of the mean est. More...
 
C◼real◼float C◼real◼float◼varv (__size n, C◼real◼float volatile arr[n])
 Compute the variance of the values in array arr. More...
 
#define C◼real◼float◼avg(...)   C◼real◼float◼avgv(sizeof((C◼real◼float[]){ __VA_ARGS__ })/sizeof(C◼real◼float), (C◼real◼float[]){ __VA_ARGS__ })
 Compute the average of arguments. More...
 
#define C◼real◼float◼var(...)   C◼real◼float◼varv(sizeof((C◼real◼float[]){ __VA_ARGS__ })/sizeof(C◼real◼float), (C◼real◼float[]){ __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◼rettypeC◼real◼float

Macro Definition Documentation

§ C◼real◼float◼avg

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

Compute the average of arguments.

Definition at line 1154 of file C-real-float.c.

§ C◼real◼float◼var

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

Compute the variance of the arguments.

Definition at line 1200 of file C-real-float.c.

Function Documentation

§ C◼real◼float◼avgv()

C◼real◼float C◼real◼float◼avgv ( __size  n,
C◼real◼float volatile  arr[n] 
)
inline

Compute the average of array arr.

Returns
defaults to double if not overwritten by the importer.

Definition at line 1145 of file C-real-float.c.

1145  {
1146 #line 23 "/home/gustedt/build/cmod/C/C-snippet-avg.X"
1148  return ret/n;
1149 }
C◼real◼float C◼real◼float◼sumv(__size n, C◼real◼float volatile arr[n])
Perform cumulative operation on array arr of length n.
Definition: C-real-float.c:976
float C◼real◼float
Definition: C-real-float.c:731

§ C◼real◼float◼var3v()

C◼real◼float C◼real◼float◼var3v ( __size  n,
C◼real◼float 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 1170 of file C-real-float.c.

1170  {
1171 #line 47 "/home/gustedt/build/cmod/C/C-snippet-avg.X"
1172  C◼real◼float m1 = 0;
1173  C◼real◼float m2 = 0;
1174  for (__size i = 0; i < n; ++i) {
1175 #line 50 "/home/gustedt/build/cmod/C/C-snippet-avg.X"
1176  C◼real◼float val = (arr[i] - est);
1177  m1 += val;
1178  m2 += val*val;
1179  }
1180  return (m2 - m1*m1/n)/(n-1);
1181 }
float C◼real◼float
Definition: C-real-float.c:731

§ C◼real◼float◼varv()

C◼real◼float C◼real◼float◼varv ( __size  n,
C◼real◼float 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 1192 of file C-real-float.c.

1192  {
1193 #line 67 "/home/gustedt/build/cmod/C/C-snippet-avg.X"
1194  return C◼real◼float◼var3v(n, arr, C◼real◼float◼avgv(n, arr));
1195 }
C◼real◼float C◼real◼float◼var3v(__size n, C◼real◼float volatile arr[n], double est)
compute the variance of vector arr, by using the estimate of the mean est.
C◼real◼float C◼real◼float◼avgv(__size n, C◼real◼float volatile arr[n])
Compute the average of array arr.