URL: <https://savannah.gnu.org/bugs/?67058>
Summary: gsl_stats_mean and gsl_stats_sd result to 0.0 when
array with zero length
Group: GNU Scientific Library
Submitter: fermelelundi
Submitted: Mon 28 Apr 2025 02:26:57 PM GMT
Category: Accuracy problem
Severity: 3 - Normal
Operating System:
Status: None
Assigned to: None
Open/Closed: Open
Discussion Lock: Any
Release: 2.8
_______________________________________________________
Follow-up Comments:
-------------------------------------------------------
Date: Mon 28 Apr 2025 02:26:57 PM GMT By: Fermé le Lundi <fermelelundi>
As per Zhenfei Yuan
(https://lists.gnu.org/archive/html/bug-gsl/2025-04/msg00001.html)
> On other computational platforms such as Matlab or R, the mean or
> standard deviation of an empty vector is typically computed as NaN.
> However, in GSL, functions like gsl_stats_mean and gsl_stats_sd return
> zero instead.
> May I ask what the rationale is behind this design choice?
Cannot speak for the design decision, but you can see one example where this
case is handled: file statistics/select_source.c
You would have to copy those lines:
if (n == 0)
GSL_ERROR_VAL("Array size n of data must be positive", GSL_EBADLEN, 0.0);
into the functions in the C programs of the statistics module that you are
using, and recompile. Possibly you would also have to add the header:
#include <gsl/gsl_math.h>
So rather than return a NaN, the GSL is more conservative and prints out an
error message.
Let us know if you need more help.
FlL
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?67058>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
signature.asc
Description: PGP signature
