changeset 46:3b9611f1b048

Some updates.
author Sjoerd Mullender <sjoerd@acm.org>
date Fri, 11 Jun 2021 10:02:09 +0200 (2021-06-11)
parents 93846aa91deb
children c8140b1fabf5
files gmean/README.rst gmean/gmean.c
diffstat 2 files changed, 18 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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:
--- 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);