[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 75d7dd6c 2/2: Statistics: MAD only calculated
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 75d7dd6c 2/2: Statistics: MAD only calculated in one-row outputs with --mad |
Date: |
Tue, 19 Mar 2024 13:46:47 -0400 (EDT) |
branch: master
commit 75d7dd6c8582b523598a2f0c65d961d255922df9
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Statistics: MAD only calculated in one-row outputs with --mad
Until now, if the user requested '--median' or '--mad', the statistics
program would call 'gal_statistics_median_mad' (which calculates both!). As
a result, if the user just wanted the median (and not the MAD), the program
would un-necessarily become slow (to calculate the un-used MAD!).
With this commit, if the MAD is not requested, the Statistics program will
just call 'gal_statistics_median' to only do the requested job and nothing
extra.
---
bin/statistics/statistics.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/bin/statistics/statistics.c b/bin/statistics/statistics.c
index f01db3c0..5f0b512f 100644
--- a/bin/statistics/statistics.c
+++ b/bin/statistics/statistics.c
@@ -122,10 +122,10 @@ statistics_print_one_row(struct statisticsparams *p)
int mustfree;
char *toprint;
double arg, *d;
- uint8_t clipflag;
- gal_list_i32_t *tmp;
gal_data_t *medmad=NULL;
size_t dsize=1, counter;
+ uint8_t clipflag, hasmad;
+ gal_list_i32_t *tmp, *ttmp;
gal_data_t *sclip=NULL, *mclip=NULL;
gal_data_t *sum=NULL, *meanstd=NULL, *modearr=NULL;
gal_data_t *tmpv, *out=NULL, *num=NULL, *min=NULL, *max=NULL;
@@ -155,7 +155,18 @@ statistics_print_one_row(struct statisticsparams *p)
break;
case UI_KEY_MAD:
case UI_KEY_MEDIAN:
- medmad = medmad ? medmad : gal_statistics_median_mad(p->input, 0);
+ if(medmad==NULL)
+ {
+ /* If MAD is requested, the median is a free byproduct. But if
+ MAD is not requested, we don't want to waste the user's time
+ for calculating it. */
+ hasmad=0;
+ for(ttmp=p->singlevalue; ttmp!=NULL; ttmp=ttmp->next)
+ if(ttmp->v==UI_KEY_MAD) hasmad=1;
+ medmad = ( hasmad
+ ? gal_statistics_median_mad(p->input, 0)
+ : gal_statistics_median(p->input, 0) );
+ }
break;
case UI_KEY_MODE:
case UI_KEY_MODEQUANT: