gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master 639a22f: Corrected type of number counter in c


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 639a22f: Corrected type of number counter in collapse-mean library
Date: Thu, 5 Jul 2018 20:04:50 -0400 (EDT)

branch: master
commit 639a22f1c4a3c187140e6cb2c3ec8c953813bd75
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    Corrected type of number counter in collapse-mean library
    
    The library's `gal_dimension_collapse_mean' function, uses the same
    counting pre-processor macros as `gal_dimension_collapse_sum'. But when
    calculating the sum, the actual number of points isn't important, only the
    fact that atleast one point was present there is important. So to speed up
    the sum operator and allow it to consume less memory, the counter dataset
    there has an unsigned 8-bit integer type. But in the mean, the number is
    important, so it has a signed 32-bit integer type. Since they have the same
    name, the macros will work on both.
    
    But the array pointers in `gal_dimension_collapse_mean', were mistakenly
    `int8_t' type (similar to the sum library function, since it was initially
    just a copy of that). With this commit the types of the pointers are
    corrected to be as described above.
---
 lib/dimension.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/lib/dimension.c b/lib/dimension.c
index ee76413..4cd4fed 100644
--- a/lib/dimension.c
+++ b/lib/dimension.c
@@ -370,11 +370,11 @@ dimension_collapse_sizes(gal_data_t *in, size_t c_dim, 
size_t *outndim,
     /* We need the sum when number operator is requested. */            \
     if(farr) farr[ OIND ] += (warr ? warr[w] : 1) * inarr[ IIND ];      \
                                                                         \
-    /* We don't need the number when the sum operator is requested. */  \
+    /* We don't need the number in some situations. */                  \
     if(iarr)                                                            \
       {                                                                 \
         if(num->type==GAL_TYPE_UINT8) iarr[ OIND ] = 1;                 \
-        else                          ++iarr[ OIND ];                   \
+        else                        ++iarr[ OIND ];                     \
       }                                                                 \
                                                                         \
     /* If the sum of weights for is needed, add it. */                  \
@@ -464,8 +464,8 @@ gal_data_t *
 gal_dimension_collapse_sum(gal_data_t *in, size_t c_dim, gal_data_t *weight)
 {
   double *wsumarr=NULL;
-  int8_t *ii, *iarr=NULL;
-  size_t a, b, i, j, k, w, cnum=0;
+  uint8_t *ii, *iarr=NULL;
+  size_t a, b, i, j, k, w=-1, cnum=0;
   size_t outdsize[10], slice, outndim;
   int hasblank=gal_blank_present(in, 0);
   double *dd, *df, *warr=NULL, *farr=NULL;
@@ -538,13 +538,14 @@ gal_dimension_collapse_mean(gal_data_t *in, size_t c_dim,
 {
   double wsum=NAN;
   double *wsumarr=NULL;
-  int8_t *ii, *iarr=NULL;
+  int32_t *ii, *iarr=NULL;
+  size_t a, b, i, j, k, w=-1, cnum=0;
   size_t outdsize[10], slice, outndim;
   int hasblank=gal_blank_present(in, 0);
-  size_t a, b, i, j, k, w, cnum=0;
   gal_data_t *wht=NULL, *sum=NULL, *num=NULL;
   double *dd, *dw, *df, *warr=NULL, *farr=NULL;
 
+
   /* Basic sanity checks. */
   wht=dimension_collapse_sanity_check(in, weight, c_dim, hasblank,
                                       &cnum, &warr);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]