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

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

Compute the average of arguments.

Definition at line 432 of file C-ptrdiff.c.

§ C◼ptrdiff◼var

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

Compute the variance of the arguments.

Definition at line 478 of file C-ptrdiff.c.

Function Documentation

§ C◼ptrdiff◼avgv()

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

Compute the average of array arr.

Returns
defaults to double if not overwritten by the importer.

Definition at line 423 of file C-ptrdiff.c.

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

§ C◼ptrdiff◼var3v()

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

448  {
449 #line 47 "/home/gustedt/build/cmod/C/C-snippet-avg.X"
452  for (__size i = 0; i < n; ++i) {
453 #line 50 "/home/gustedt/build/cmod/C/C-snippet-avg.X"
454  C◼snippet◼avg◼rettype val = (arr[i] - est);
455  m1 += val;
456  m2 += val*val;
457  }
458  return (m2 - m1*m1/n)/(n-1);
459 }
double C◼snippet◼avg◼rettype
The default type for the averaging functions.
Definition: C-snippet-avg.c:51

§ C◼ptrdiff◼varv()

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

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