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

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

Compute the average of arguments.

Definition at line 1182 of file C-real-double.c.

§ C◼real◼double◼var

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

Compute the variance of the arguments.

Definition at line 1228 of file C-real-double.c.

Function Documentation

§ C◼real◼double◼avgv()

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

Compute the average of array arr.

Returns
defaults to double if not overwritten by the importer.

Definition at line 1173 of file C-real-double.c.

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

§ C◼real◼double◼var3v()

C◼snippet◼avg◼rettype C◼real◼double◼var3v ( __size  n,
C◼real◼double 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 1198 of file C-real-double.c.

1198  {
1199 #line 47 "/home/gustedt/build/cmod/C/C-snippet-avg.X"
1202  for (__size i = 0; i < n; ++i) {
1203 #line 50 "/home/gustedt/build/cmod/C/C-snippet-avg.X"
1204  C◼snippet◼avg◼rettype val = (arr[i] - est);
1205  m1 += val;
1206  m2 += val*val;
1207  }
1208  return (m2 - m1*m1/n)/(n-1);
1209 }
double C◼snippet◼avg◼rettype
The default type for the averaging functions.
Definition: C-snippet-avg.c:51

§ C◼real◼double◼varv()

C◼snippet◼avg◼rettype C◼real◼double◼varv ( __size  n,
C◼real◼double 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 1220 of file C-real-double.c.

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