# HG changeset patch # User Sjoerd Mullender <sjoerd@acm.org> # Date 1623398529 -7200 # Node ID 3b9611f1b0487781b88021637caf1a7d14392e0b # Parent 93846aa91deb83b4c4f514bb226f294579fd19d9 Some updates. diff -r 93846aa91deb -r 3b9611f1b048 gmean/README.rst --- a/gmean/README.rst Fri Jun 11 09:09:43 2021 +0200 +++ b/gmean/README.rst Fri Jun 11 10:02:09 2021 +0200 @@ -395,6 +395,23 @@ ``NULL``), the candidate iterator is initialized to iterate through all values. +Now that we know the size of the output BAT (it is equal to the number +of groups), we can create the output BAT. We initialize all rows with +zero so that we can immediately start accumulating the sum of the +logarithms. Note the construct ``&(dbl){0}``. This is a pointer to +an anonymous location with type ``dbl`` and value ``0``. + +.. code-block:: c + + bn = BATconstant(min, TYPE_dbl, &(dbl){0}, ngrp, TRANSIENT); + dbl *sums = (dbl *) Tloc(bn, 0); + +The function ``BATconstant`` creates a new BAT with, in this case, +``ngrp`` rows which are all initialized to the value pointed to by the +third argument. In reality we do error checking, and then we get the +pointer to the first value into ``sums``. This we can then use as a C +array and modify. + The next part of the code has a lot to do with the calculation of the geometric mean using the logarithms of the values. The important bits for us are how to iterate through the candidates: diff -r 93846aa91deb -r 3b9611f1b048 gmean/gmean.c --- a/gmean/gmean.c Fri Jun 11 09:09:43 2021 +0200 +++ b/gmean/gmean.c Fri Jun 11 10:02:09 2021 +0200 @@ -111,7 +111,7 @@ throw(MAL, "gmean.gmean", "%s\n", err); } - /* create a result BAT and initialize it with all NILs */ + /* create a result BAT and initialize it with all zeros */ bn = BATconstant(min, TYPE_dbl, &(dbl){0}, ngrp, TRANSIENT); if (bn == NULL) { BBPunfix(b->batCacheid);