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

Macro Definition Documentation

§ C◼complex◼double◼avg

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

Compute the average of arguments.

Definition at line 501 of file C-complex-double.c.

§ C◼complex◼double◼var

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

Compute the variance of the arguments.

Definition at line 547 of file C-complex-double.c.

Function Documentation

§ C◼complex◼double◼avgv()

C◼complex◼double C◼complex◼double◼avgv ( __size  n,
C◼complex◼double volatile  arr[n] 
)
inline

Compute the average of array arr.

Returns
defaults to double if not overwritten by the importer.

Definition at line 492 of file C-complex-double.c.

492  {
493 #line 23 "/home/gustedt/build/cmod/C/C-snippet-avg.X"
495  return ret/n;
496 }
C◼complex◼double C◼complex◼double◼sumv(__size n, C◼complex◼double volatile arr[n])
Perform cumulative operation on array arr of length n.
double _Complex C◼complex◼double

§ C◼complex◼double◼var3v()

C◼complex◼double C◼complex◼double◼var3v ( __size  n,
C◼complex◼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 517 of file C-complex-double.c.

517  {
518 #line 47 "/home/gustedt/build/cmod/C/C-snippet-avg.X"
519  C◼complex◼double m1 = 0;
520  C◼complex◼double m2 = 0;
521  for (__size i = 0; i < n; ++i) {
522 #line 50 "/home/gustedt/build/cmod/C/C-snippet-avg.X"
523  C◼complex◼double val = (arr[i] - est);
524  m1 += val;
525  m2 += val*val;
526  }
527  return (m2 - m1*m1/n)/(n-1);
528 }
double _Complex C◼complex◼double

§ C◼complex◼double◼varv()

C◼complex◼double C◼complex◼double◼varv ( __size  n,
C◼complex◼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 539 of file C-complex-double.c.

539  {
540 #line 67 "/home/gustedt/build/cmod/C/C-snippet-avg.X"
542 }
C◼complex◼double C◼complex◼double◼avgv(__size n, C◼complex◼double volatile arr[n])
Compute the average of array arr.
C◼complex◼double C◼complex◼double◼var3v(__size n, C◼complex◼double volatile arr[n], double est)
compute the variance of vector arr, by using the estimate of the mean est.