diff options
| author | Charles Harris <charlesr.harris@gmail.com> | 2012-04-29 13:05:23 -0600 |
|---|---|---|
| committer | Charles Harris <charlesr.harris@gmail.com> | 2012-04-29 13:05:23 -0600 |
| commit | ec753165aadde35abc15d7a3d4641d566cad44b4 (patch) | |
| tree | 4d9e1f441051eae42bb1936d2d3dfb10f14c6230 /numpy | |
| parent | 89d6d411d1bcd22524d55a042c6cc2a64c36f680 (diff) | |
| download | numpy-ec753165aadde35abc15d7a3d4641d566cad44b4.tar.gz | |
BUG: ticket #1952, allow floating ddof in std and var.
Also return nan for resulting non-positive degrees of freedom.
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/core/src/multiarray/calculation.c | 11 | ||||
| -rw-r--r-- | numpy/core/src/multiarray/calculation.h | 2 | ||||
| -rw-r--r-- | numpy/core/src/multiarray/methods.c | 8 |
3 files changed, 11 insertions, 10 deletions
diff --git a/numpy/core/src/multiarray/calculation.c b/numpy/core/src/multiarray/calculation.c index 93f104d62..41d96df01 100644 --- a/numpy/core/src/multiarray/calculation.c +++ b/numpy/core/src/multiarray/calculation.c @@ -351,10 +351,11 @@ PyArray_Std(PyArrayObject *self, int axis, int rtype, PyArrayObject *out, NPY_NO_EXPORT PyObject * __New_PyArray_Std(PyArrayObject *self, int axis, int rtype, PyArrayObject *out, - int variance, int num) + int variance, double num) { PyObject *obj1 = NULL, *obj2 = NULL, *obj3 = NULL, *new = NULL; PyObject *ret = NULL, *newshape = NULL; + double scl; int i, n; intp val; @@ -451,11 +452,11 @@ __New_PyArray_Std(PyArrayObject *self, int axis, int rtype, PyArrayObject *out, } n = PyArray_DIM(new,axis); Py_DECREF(new); - n = (n-num); - if (n == 0) { - n = 1; + scl = n - num; + if (scl <= 0) { + scl = NPY_NAN; } - obj2 = PyFloat_FromDouble(1.0/((double )n)); + obj2 = PyFloat_FromDouble(1.0/scl); if (obj2 == NULL) { Py_DECREF(obj1); return NULL; diff --git a/numpy/core/src/multiarray/calculation.h b/numpy/core/src/multiarray/calculation.h index 34bc31f69..0d6633ae5 100644 --- a/numpy/core/src/multiarray/calculation.h +++ b/numpy/core/src/multiarray/calculation.h @@ -41,7 +41,7 @@ PyArray_Std(PyArrayObject* self, int axis, int rtype, PyArrayObject* out, NPY_NO_EXPORT PyObject * __New_PyArray_Std(PyArrayObject *self, int axis, int rtype, PyArrayObject *out, - int variance, int num); + int variance, double num); NPY_NO_EXPORT PyObject* PyArray_Sum(PyArrayObject* self, int axis, int rtype, PyArrayObject* out); diff --git a/numpy/core/src/multiarray/methods.c b/numpy/core/src/multiarray/methods.c index ed86e208c..53dc67100 100644 --- a/numpy/core/src/multiarray/methods.c +++ b/numpy/core/src/multiarray/methods.c @@ -1854,10 +1854,10 @@ array_stddev(PyArrayObject *self, PyObject *args, PyObject *kwds) PyArray_Descr *dtype = NULL; PyArrayObject *out = NULL; int num; - int ddof = 0; + double ddof = 0; static char *kwlist[] = {"axis", "dtype", "out", "ddof", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&O&i", kwlist, + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&O&d", kwlist, PyArray_AxisConverter, &axis, PyArray_DescrConverter2, &dtype, PyArray_OutputConverter, &out, @@ -1879,10 +1879,10 @@ array_variance(PyArrayObject *self, PyObject *args, PyObject *kwds) PyArray_Descr *dtype = NULL; PyArrayObject *out = NULL; int num; - int ddof = 0; + double ddof = 0; static char *kwlist[] = {"axis", "dtype", "out", "ddof", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&O&i", kwlist, + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&O&d", kwlist, PyArray_AxisConverter, &axis, PyArray_DescrConverter2, &dtype, PyArray_OutputConverter, &out, |
