diff options
33 files changed, 874 insertions, 406 deletions
diff --git a/doc/HOWTO_BUILD_DOCS.rst.txt b/doc/HOWTO_BUILD_DOCS.rst.txt index 3b677263b..d0de6d5a4 100644 --- a/doc/HOWTO_BUILD_DOCS.rst.txt +++ b/doc/HOWTO_BUILD_DOCS.rst.txt @@ -85,9 +85,8 @@ The following extensions are available: changes or be eventually deprecated. - ``numpydoc.autosummary``: (DEPRECATED) An ``autosummary::`` directive. - Available in Sphinx 0.6.2 and (to-be) 1.0 as ``sphinx.ext.autosummary``, - and it the Sphinx 1.0 version is recommended over that included in - Numpydoc. + Available since Sphinx 0.6 as ``sphinx.ext.autosummary``, + recommended over that included in Numpydoc since Sphinx 1.0. - ``numpydoc.traitsdoc``: For gathering documentation about Traits attributes. diff --git a/doc/release/1.8.0-notes.rst b/doc/release/1.8.0-notes.rst index a70061fba..ed9a323ca 100644 --- a/doc/release/1.8.0-notes.rst +++ b/doc/release/1.8.0-notes.rst @@ -159,14 +159,27 @@ advantage of compiler builtins to avoid expensive calls to libc. This improves performance of these operations by about a factor of two on gnu libc systems. -Performance improvements to base math, `sqrt`, `absolute` and `minimum/maximum` -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The base math (add, subtract, divide, multiply), `sqrt`, `absolute` and -`minimum/maximum` functions for unit stride elementary operations have been -improved to make use of SSE2 CPU SIMD instructions. +Performance improvements via SSE2 vectorization +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Several functions have been optimized to make use of SSE2 CPU SIMD instructions. + + * Float32 and float64: + + * base math (`add`, `subtract`, `divide`, `multiply`) + * `sqrt` + * `minimum/maximum` + * `absolute` + + * Bool: + + * `logical_or` + * `logical_and` + * `logical_not` + This improves performance of these operations up to 4x/2x for float32/float64 -depending on the location of the data in the CPU caches. The performance gain -is greatest for in-place operations. +and up to 10x for bool depending on the location of the data in the CPU caches. +The performance gain is greatest for in-place operations. + In order to use the improved functions the SSE2 instruction set must be enabled at compile time. It is enabled by default on x86_64 systems. On x86_32 with a capable CPU it must be enabled by passing the appropriate flag to the CFLAGS diff --git a/doc/source/reference/routines.polynomials.classes.rst b/doc/source/reference/routines.polynomials.classes.rst index 9294728c8..14729f08b 100644 --- a/doc/source/reference/routines.polynomials.classes.rst +++ b/doc/source/reference/routines.polynomials.classes.rst @@ -30,10 +30,10 @@ and more generally .. math:: p(x) = \sum_{i=0}^n c_i T_i(x) -where in this case the :math:`T_n` are the Chebyshev functions of degree -`n`, but could just as easily be the basis functions of any of the other -classes. The convention for all the classes is that the coefficient -c[i] goes with the basis function of degree i. +where in this case the :math:`T_n` are the Chebyshev functions of +degree :math:`n`, but could just as easily be the basis functions of +any of the other classes. The convention for all the classes is that +the coefficient :math:`c[i]` goes with the basis function of degree i. All of the classes have the same methods, and especially they implement the Python numeric operators +, -, \*, //, %, divmod, \*\*, ==, @@ -47,7 +47,7 @@ Basics First we need a polynomial class and a polynomial instance to play with. The classes can be imported directly from the polynomial package or from the module of the relevant type. Here we import from the package and use -the conventional Polynomial class because of its familiarity.:: +the conventional Polynomial class because of its familiarity:: >>> from numpy.polynomial import Polynomial as P >>> p = P([1,2,3]) @@ -93,7 +93,7 @@ Powers:: Division: -Floor_division, '//', is the division operator for the polynomial classes, +Floor division, '//', is the division operator for the polynomial classes, polynomials are treated like integers in this regard. For Python versions < 3.x the '/' operator maps to '//', as it does for Python, for later versions the '/' will only work for division by scalars. At some point it @@ -182,7 +182,7 @@ and window casting:: >>> p(T([0, 1])) Chebyshev([ 2.5, 2. , 1.5], [-1., 1.], [-1., 1.]) -Which gives the polynomial 'p' in Chebyshev form. This works because +Which gives the polynomial `p` in Chebyshev form. This works because :math:`T_1(x) = x` and substituting :math:`x` for :math:`x` doesn't change the original polynomial. However, all the multiplications and divisions will be done using Chebyshev series, hence the type of the result. @@ -199,7 +199,7 @@ Polynomial instances can be integrated and differentiated.:: >>> p.integ(2) Polynomial([ 0., 0., 1., 1.], [-1., 1.], [-1., 1.]) -The first example integrates 'p' once, the second example integrates it +The first example integrates `p` once, the second example integrates it twice. By default, the lower bound of the integration and the integration constant are 0, but both can be specified.:: @@ -227,7 +227,7 @@ Constructing polynomials by specifying coefficients is just one way of obtaining a polynomial instance, they may also be created by specifying their roots, by conversion from other polynomial types, and by least squares fits. Fitting is discussed in its own section, the other methods -are demonstrated below.:: +are demonstrated below:: >>> from numpy.polynomial import Polynomial as P >>> from numpy.polynomial import Chebyshev as T @@ -244,9 +244,9 @@ The convert method can also convert domain and window:: >>> p.convert(kind=P, domain=[0, 1]) Polynomial([-1.875, 2.875, -1.125, 0.125], [ 0., 1.], [-1., 1.]) -In numpy versions >= 1.7.0 the 'basis' and 'cast' class methods are also +In numpy versions >= 1.7.0 the `basis` and `cast` class methods are also available. The cast method works like the convert method while the basis -method returns the basis polynomial of given degree.:: +method returns the basis polynomial of given degree:: >>> P.basis(3) Polynomial([ 0., 0., 0., 1.], [-1., 1.], [-1., 1.]) @@ -276,8 +276,8 @@ polynomials up to degree 5 are plotted below. <matplotlib.legend.Legend object at 0x3b3ee10> >>> plt.show() -In the range -1 <= x <= 1 they are nice, equiripple functions lying between +/- 1. -The same plots over the range -2 <= x <= 2 look very different: +In the range -1 <= `x` <= 1 they are nice, equiripple functions lying between +/- 1. +The same plots over the range -2 <= `x` <= 2 look very different: .. plot:: @@ -291,17 +291,17 @@ The same plots over the range -2 <= x <= 2 look very different: >>> plt.show() As can be seen, the "good" parts have shrunk to insignificance. In using -Chebyshev polynomials for fitting we want to use the region where x is -between -1 and 1 and that is what the 'window' specifies. However, it is +Chebyshev polynomials for fitting we want to use the region where `x` is +between -1 and 1 and that is what the `window` specifies. However, it is unlikely that the data to be fit has all its data points in that interval, -so we use 'domain' to specify the interval where the data points lie. When +so we use `domain` to specify the interval where the data points lie. When the fit is done, the domain is first mapped to the window by a linear transformation and the usual least squares fit is done using the mapped data points. The window and domain of the fit are part of the returned series and are automatically used when computing values, derivatives, and such. If they aren't specified in the call the fitting routine will use the default window and the smallest domain that holds all the data points. This is -illustrated below for a fit to a noisy sin curve. +illustrated below for a fit to a noisy sine curve. .. plot:: diff --git a/numpy/core/include/numpy/ufuncobject.h b/numpy/core/include/numpy/ufuncobject.h index 75611426c..8df96a44f 100644 --- a/numpy/core/include/numpy/ufuncobject.h +++ b/numpy/core/include/numpy/ufuncobject.h @@ -212,7 +212,7 @@ typedef struct _tagPyUFuncObject { * A function which returns a masked inner loop for the ufunc. */ PyUFunc_MaskedInnerLoopSelectionFunc *masked_inner_loop_selector; - + /* * List of flags for each operand when ufunc is called by nditer object. * These flags will be used in addition to the default flags for each @@ -406,7 +406,7 @@ typedef struct _loop1d_info { defined(__MINGW32__) || defined(__FreeBSD__) #include <fenv.h> #elif defined(__CYGWIN__) -#include "fenv/fenv.c" +#include "numpy/fenv/fenv.h" #endif #define UFUNC_CHECK_STATUS(ret) { \ diff --git a/numpy/core/src/multiarray/common.c b/numpy/core/src/multiarray/common.c index 4787c6482..c1b6ef5b3 100644 --- a/numpy/core/src/multiarray/common.c +++ b/numpy/core/src/multiarray/common.c @@ -49,31 +49,35 @@ PyArray_GetAttrString_SuppressException(PyObject *obj, char *name) { PyTypeObject *tp = Py_TYPE(obj); PyObject *res = (PyObject *)NULL; - if (/* Is not trivial type */ - obj != Py_None && - !PyList_CheckExact(obj) && - !PyTuple_CheckExact(obj)) { - /* Attribute referenced by (char *)name */ - if (tp->tp_getattr != NULL) { - res = (*tp->tp_getattr)(obj, name); - if (res == NULL) { - PyErr_Clear(); - } + + /* We do not need to check for special attributes on trivial types */ + if (obj == Py_None || + PyList_CheckExact(obj) || + PyTuple_CheckExact(obj)) { + return NULL; + } + + /* Attribute referenced by (char *)name */ + if (tp->tp_getattr != NULL) { + res = (*tp->tp_getattr)(obj, name); + if (res == NULL) { + PyErr_Clear(); } - /* Attribute referenced by (PyObject *)name */ - else if (tp->tp_getattro != NULL) { + } + /* Attribute referenced by (PyObject *)name */ + else if (tp->tp_getattro != NULL) { #if defined(NPY_PY3K) - PyObject *w = PyUnicode_InternFromString(name); + PyObject *w = PyUnicode_InternFromString(name); #else - PyObject *w = PyString_InternFromString(name); + PyObject *w = PyString_InternFromString(name); #endif - if (w == NULL) - return (PyObject *)NULL; - Py_DECREF(w); - res = (*tp->tp_getattro)(obj, w); - if (res == NULL) { - PyErr_Clear(); - } + if (w == NULL) { + return (PyObject *)NULL; + } + res = (*tp->tp_getattro)(obj, w); + Py_DECREF(w); + if (res == NULL) { + PyErr_Clear(); } } return res; diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c index c96258417..872f4e284 100644 --- a/numpy/core/src/multiarray/ctors.c +++ b/numpy/core/src/multiarray/ctors.c @@ -373,15 +373,14 @@ NPY_NO_EXPORT void copy_and_swap(void *dst, void *src, int itemsize, npy_intp numitems, npy_intp srcstrides, int swap) { - npy_intp i; - char *s1 = (char *)src; - char *d1 = (char *)dst; - - if ((numitems == 1) || (itemsize == srcstrides)) { - memcpy(d1, s1, itemsize*numitems); + memcpy(dst, src, itemsize*numitems); } else { + npy_intp i; + char *s1 = (char *)src; + char *d1 = (char *)dst; + for (i = 0; i < numitems; i++) { memcpy(d1, s1, itemsize); d1 += itemsize; @@ -390,7 +389,7 @@ copy_and_swap(void *dst, void *src, int itemsize, npy_intp numitems, } if (swap) { - byte_swap_vector(d1, numitems, itemsize); + byte_swap_vector(dst, numitems, itemsize); } } diff --git a/numpy/core/src/multiarray/item_selection.c b/numpy/core/src/multiarray/item_selection.c index 373e17425..9be9f7140 100644 --- a/numpy/core/src/multiarray/item_selection.c +++ b/numpy/core/src/multiarray/item_selection.c @@ -1045,6 +1045,8 @@ PyArray_Sort(PyArrayObject *op, int axis, NPY_SORTKIND which) return -1; } + SWAPAXES2(op); + switch (which) { case NPY_QUICKSORT : sort = npy_quicksort; @@ -1061,9 +1063,6 @@ PyArray_Sort(PyArrayObject *op, int axis, NPY_SORTKIND which) goto fail; } - - SWAPAXES2(op); - ap = (PyArrayObject *)PyArray_FromAny((PyObject *)op, NULL, 1, 0, NPY_ARRAY_DEFAULT | NPY_ARRAY_UPDATEIFCOPY, NULL); diff --git a/numpy/core/src/multiarray/lowlevel_strided_loops.c.src b/numpy/core/src/multiarray/lowlevel_strided_loops.c.src index bc2279a98..875656394 100644 --- a/numpy/core/src/multiarray/lowlevel_strided_loops.c.src +++ b/numpy/core/src/multiarray/lowlevel_strided_loops.c.src @@ -21,10 +21,15 @@ #include "lowlevel_strided_loops.h" /* - * x86 platform works with unaligned access + * x86 platform works with unaligned access but the compiler is allowed to + * assume all data is aligned to its size by the C standard. This means it can + * vectorize instructions peeling only by the size of the type, if the data is + * not aligned to this size one ends up with data not correctly aligned for SSE + * instructions (16 byte). + * So this flag can only be enabled if autovectorization is disabled. */ #if (defined(NPY_CPU_X86) || defined(NPY_CPU_AMD64)) -# define NPY_USE_UNALIGNED_ACCESS 1 +# define NPY_USE_UNALIGNED_ACCESS 0 #else # define NPY_USE_UNALIGNED_ACCESS 0 #endif diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c index 426ab695c..92bf93933 100644 --- a/numpy/core/src/multiarray/multiarraymodule.c +++ b/numpy/core/src/multiarray/multiarraymodule.c @@ -70,14 +70,12 @@ PyArray_GetPriority(PyObject *obj, double default_) return priority; ret = PyArray_GetAttrString_SuppressException(obj, "__array_priority__"); - if (ret != NULL) { - priority = PyFloat_AsDouble(ret); - } - if (PyErr_Occurred()) { - PyErr_Clear(); - priority = default_; + if (ret == NULL) { + return default_; } - Py_XDECREF(ret); + + priority = PyFloat_AsDouble(ret); + Py_DECREF(ret); return priority; } diff --git a/numpy/core/src/umath/loops.c.src b/numpy/core/src/umath/loops.c.src index 068ecde7c..59d144569 100644 --- a/numpy/core/src/umath/loops.c.src +++ b/numpy/core/src/umath/loops.c.src @@ -571,6 +571,9 @@ BOOL_@kind@(char **args, npy_intp *dimensions, npy_intp *steps, void *NPY_UNUSED *((npy_bool *)iop1) = io1; } else { + if (run_binary_simd_@kind@_BOOL(args, dimensions, steps)) { + return; + } BINARY_LOOP { const npy_bool in1 = *(npy_bool *)ip1; const npy_bool in2 = *(npy_bool *)ip2; @@ -613,6 +616,9 @@ BOOL_@kind@(char **args, npy_intp *dimensions, npy_intp *steps, void *NPY_UNUSED NPY_NO_EXPORT void BOOL_@kind@(char **args, npy_intp *dimensions, npy_intp *steps, void *NPY_UNUSED(func)) { + if (run_unary_simd_@kind@_BOOL(args, dimensions, steps)) { + return; + } UNARY_LOOP { npy_bool in1 = *(npy_bool *)ip1; *((npy_bool *)op1) = in1 @OP@ 0; diff --git a/numpy/core/src/umath/simd.inc.src b/numpy/core/src/umath/simd.inc.src index 746943097..0382f2cf7 100644 --- a/numpy/core/src/umath/simd.inc.src +++ b/numpy/core/src/umath/simd.inc.src @@ -19,6 +19,9 @@ #include "npy_config.h" /* for NO_FLOATING_POINT_SUPPORT */ #include "numpy/ufuncobject.h" +#ifdef HAVE_EMMINTRIN_H +#include <emmintrin.h> +#endif #include <assert.h> #include <stdlib.h> @@ -75,6 +78,12 @@ void PyUFunc_clearfperr(void); * if it was run returns true and false if nothing was done */ +/* + ***************************************************************************** + ** FLOAT DISPATCHERS + ***************************************************************************** + */ + /**begin repeat * Float types * #type = npy_float, npy_double, npy_longdouble# @@ -161,13 +170,66 @@ run_binary_simd_@kind@_@TYPE@(char **args, npy_intp *dimensions, npy_intp *steps /**end repeat**/ - /* - * Vectorized operations + ***************************************************************************** + ** BOOL DISPATCHERS + ***************************************************************************** + */ + +/**begin repeat + * # kind = logical_or, logical_and# */ +static void +sse2_binary_@kind@_BOOL(npy_bool * op, npy_bool * ip1, npy_bool * ip2, + npy_intp n); + +static NPY_INLINE int +run_binary_simd_@kind@_BOOL(char **args, npy_intp *dimensions, npy_intp *steps) +{ +#if defined HAVE_EMMINTRIN_H + if (sizeof(npy_bool) == 1 && IS_BLOCKABLE_BINARY(sizeof(npy_bool), 16)) { + sse2_binary_@kind@_BOOL((npy_bool*)args[2], (npy_bool*)args[0], + (npy_bool*)args[1], dimensions[0]); + return 1; + } +#endif + return 0; +} + +/**end repeat**/ + +/**begin repeat + * # kind = absolute, logical_not# + */ + +static void +sse2_@kind@_BOOL(npy_bool *, npy_bool *, const npy_intp n); + +static NPY_INLINE int +run_unary_simd_@kind@_BOOL(char **args, npy_intp *dimensions, npy_intp *steps) +{ +#if defined HAVE_EMMINTRIN_H + if (sizeof(npy_bool) == 1 && IS_BLOCKABLE_UNARY(sizeof(npy_bool), 16)) { + sse2_@kind@_BOOL((npy_bool*)args[1], (npy_bool*)args[0], dimensions[0]); + return 1; + } +#endif + return 0; +} + +/**end repeat**/ + #ifdef HAVE_EMMINTRIN_H -#include <emmintrin.h> + +/* + * Vectorized operations + */ +/* + ***************************************************************************** + ** FLOAT LOOPS + ***************************************************************************** + */ /**begin repeat * horizontal reductions on a vector @@ -446,6 +508,107 @@ sse2_@kind@_@TYPE@(@type@ * ip, @type@ * op, const npy_intp n) /**end repeat**/ +/* + ***************************************************************************** + ** BOOL LOOPS + ***************************************************************************** + */ + +/**begin repeat + * # kind = logical_or, logical_and# + * # and = 0, 1# + * # op = ||, &&# + * # vop = or, and# + * # vpre = _mm*2# + * # vsuf = si128*2# + * # vtype = __m128i*2# + * # type = npy_bool*2# + * # vloadu = _mm_loadu_si128*2# + * # vstore = _mm_store_si128*2# + */ + +/* + * convert any bit set to boolean true so vectorized and normal operations are + * consistent, should not be required if bool is used correctly everywhere but + * you never know + */ +#if !@and@ +static NPY_INLINE @vtype@ byte_to_true(@vtype@ v) +{ + const @vtype@ zero = @vpre@_setzero_@vsuf@(); + const @vtype@ truemask = @vpre@_set1_epi8(1 == 1); + /* get 0xFF for zeros */ + @vtype@ tmp = @vpre@_cmpeq_epi8(v, zero); + /* filled with 0xFF/0x00, negate and mask to boolean true */ + return @vpre@_andnot_@vsuf@(tmp, truemask); +} +#endif + +static void +sse2_binary_@kind@_BOOL(npy_bool * op, npy_bool * ip1, npy_bool * ip2, npy_intp n) +{ + LOOP_BLOCK_ALIGN_VAR(op, @type@, 16) + op[i] = ip1[i] @op@ ip2[i]; + LOOP_BLOCKED(@type@, 16) { + @vtype@ a = @vloadu@((__m128i*)&ip1[i]); + @vtype@ b = @vloadu@((__m128i*)&ip2[i]); +#if @and@ + const @vtype@ zero = @vpre@_setzero_@vsuf@(); + /* get 0xFF for non zeros*/ + @vtype@ tmp = @vpre@_cmpeq_epi8(a, zero); + /* andnot -> 0x00 for zeros xFF for non zeros, & with ip2 */ + tmp = @vpre@_andnot_@vsuf@(tmp, b); +#else + @vtype@ tmp = @vpre@_or_@vsuf@(a, b); +#endif + + @vstore@((__m128i*)&op[i], byte_to_true(tmp)); + } + LOOP_BLOCKED_END { + op[i] = (ip1[i] @op@ ip2[i]); + } +} + +/**end repeat**/ + +/**begin repeat + * # kind = absolute, logical_not# + * # op = !=, ==# + * # not = 0, 1# + * # vpre = _mm*2# + * # vsuf = si128*2# + * # vtype = __m128i*2# + * # type = npy_bool*2# + * # vloadu = _mm_loadu_si128*2# + * # vstore = _mm_store_si128*2# + */ + +static void +sse2_@kind@_BOOL(@type@ * op, @type@ * ip, const npy_intp n) +{ + LOOP_BLOCK_ALIGN_VAR(op, @type@, 16) + op[i] = (ip[i] @op@ 0); + LOOP_BLOCKED(@type@, 16) { + @vtype@ a = @vloadu@((__m128i*)&ip[i]); +#if @not@ + const @vtype@ zero = @vpre@_setzero_@vsuf@(); + const @vtype@ truemask = @vpre@_set1_epi8(1 == 1); + /* equivalent to byte_to_true but can skip the negation */ + a = @vpre@_cmpeq_epi8(a, zero); + a = @vpre@_and_@vsuf@(a, truemask); +#else + /* abs is kind of pointless but maybe its used for byte_to_true */ + a = byte_to_true(a); +#endif + @vstore@((__m128i*)&op[i], a); + } + LOOP_BLOCKED_END { + op[i] = (ip[i] @op@ 0); + } +} + +/**end repeat**/ + #endif /* HAVE_EMMINTRIN_H */ #endif diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py index 5c8de3734..ed4e0b79e 100644 --- a/numpy/core/tests/test_numeric.py +++ b/numpy/core/tests/test_numeric.py @@ -223,6 +223,76 @@ class TestBoolScalar(TestCase): self.assertTrue((f ^ f) is f) +class TestBoolArray(TestCase): + def setUp(self): + # offset for simd tests + self.t = array([True] * 41, dtype=np.bool)[1::] + self.f = array([False] * 41, dtype=np.bool)[1::] + self.o = array([False] * 42, dtype=np.bool)[2::] + self.nm = self.f.copy() + self.im = self.t.copy() + self.nm[3] = True + self.nm[-2] = True + self.im[3] = False + self.im[-2] = False + + def test_all_any(self): + self.assertTrue(self.t.all()) + self.assertTrue(self.t.any()) + self.assertFalse(self.f.all()) + self.assertFalse(self.f.any()) + self.assertTrue(self.nm.any()) + self.assertTrue(self.im.any()) + self.assertFalse(self.nm.all()) + self.assertFalse(self.im.all()) + + def test_logical_not_abs(self): + assert_array_equal(~self.t, self.f) + assert_array_equal(np.abs(~self.t), self.f) + assert_array_equal(np.abs(~self.f), self.t) + assert_array_equal(np.abs(self.f), self.f) + assert_array_equal(~np.abs(self.f), self.t) + assert_array_equal(~np.abs(self.t), self.f) + assert_array_equal(np.abs(~self.nm), self.im) + np.logical_not(self.t, out=self.o) + assert_array_equal(self.o, self.f) + np.abs(self.t, out=self.o) + assert_array_equal(self.o, self.t) + + def test_logical_and_or_xor(self): + assert_array_equal(self.t | self.t, self.t) + assert_array_equal(self.f | self.f, self.f) + assert_array_equal(self.t | self.f, self.t) + assert_array_equal(self.f | self.t, self.t) + np.logical_or(self.t, self.t, out=self.o) + assert_array_equal(self.o, self.t) + assert_array_equal(self.t & self.t, self.t) + assert_array_equal(self.f & self.f, self.f) + assert_array_equal(self.t & self.f, self.f) + assert_array_equal(self.f & self.t, self.f) + np.logical_and(self.t, self.t, out=self.o) + assert_array_equal(self.o, self.t) + assert_array_equal(self.t ^ self.t, self.f) + assert_array_equal(self.f ^ self.f, self.f) + assert_array_equal(self.t ^ self.f, self.t) + assert_array_equal(self.f ^ self.t, self.t) + np.logical_xor(self.t, self.t, out=self.o) + assert_array_equal(self.o, self.f) + + assert_array_equal(self.nm & self.t, self.nm) + assert_array_equal(self.im & self.f, False) + assert_array_equal(self.nm & True, self.nm) + assert_array_equal(self.im & False, self.f) + assert_array_equal(self.nm | self.t, self.t) + assert_array_equal(self.im | self.f, self.im) + assert_array_equal(self.nm | True, self.t) + assert_array_equal(self.im | False, self.im) + assert_array_equal(self.nm ^ self.t, self.im) + assert_array_equal(self.im ^ self.f, self.im) + assert_array_equal(self.nm ^ True, self.im) + assert_array_equal(self.im ^ False, self.im) + + class TestSeterr(TestCase): def test_default(self): err = geterr() diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index fcbb75ba2..6dfee51d8 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -263,6 +263,11 @@ class TestRegression(TestCase): """Ticket #143""" assert_equal(0,np.add.identity) + def test_numpy_float_python_long_addition(self): + # Check that numpy float and python longs can be added correctly. + a = np.float_(23.) + 2**135 + assert_equal(a, 23. + 2**135) + def test_binary_repr_0(self,level=rlevel): """Ticket #151""" assert_equal('0',np.binary_repr(0)) diff --git a/numpy/linalg/linalg.py b/numpy/linalg/linalg.py index 5d632fed7..279ce21f9 100644 --- a/numpy/linalg/linalg.py +++ b/numpy/linalg/linalg.py @@ -1732,9 +1732,9 @@ def lstsq(a, b, rcond=-1): Returns ------- - x : {(M,), (M, K)} ndarray - Least-squares solution. The shape of `x` depends on the shape of - `b`. + x : {(N,), (N, K)} ndarray + Least-squares solution. If `b` is two-dimensional, + the solutions are in the `K` columns of `x`. residuals : {(), (1,), (K,)} ndarray Sums of residuals; squared Euclidean 2-norm for each column in ``b - a*x``. diff --git a/numpy/ma/core.py b/numpy/ma/core.py index 223f119b8..b2e6ad91b 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -3003,7 +3003,7 @@ class MaskedArray(ndarray): # We should always re-cast to mvoid, otherwise users can # change masks on rows that already have masked values, but not # on rows that have no masked values, which is inconsistent. - dout = mvoid(dout, mask=mask) + dout = mvoid(dout, mask=mask, hardmask=self._hardmask) # Just a scalar............ elif _mask is not nomask and _mask[indx]: return masked @@ -5560,10 +5560,12 @@ class mvoid(MaskedArray): Fake a 'void' object to use for masked array with structured dtypes. """ # - def __new__(self, data, mask=nomask, dtype=None, fill_value=None): + def __new__(self, data, mask=nomask, dtype=None, fill_value=None, + hardmask=False): dtype = dtype or data.dtype _data = np.array(data, dtype=dtype) _data = _data.view(self) + _data._hardmask = hardmask if mask is not nomask: if isinstance(mask, np.void): _data._mask = mask @@ -5593,7 +5595,10 @@ class mvoid(MaskedArray): def __setitem__(self, indx, value): self._data[indx] = value - self._mask[indx] |= getattr(value, "_mask", False) + if self._hardmask: + self._mask[indx] |= getattr(value, "_mask", False) + else: + self._mask[indx] = getattr(value, "_mask", False) def __str__(self): m = self._mask @@ -5638,6 +5643,9 @@ class mvoid(MaskedArray): else: yield d + def __len__(self): + return self._data.__len__() + def filled(self, fill_value=None): """ Return a copy with masked fields filled with a given value. @@ -5975,9 +5983,10 @@ class _frommethod: Name of the method to transform. """ - def __init__(self, methodname): + def __init__(self, methodname, reversed=False): self.__name__ = methodname self.__doc__ = self.getdoc() + self.reversed = reversed # def getdoc(self): "Return the doc of the function (from the doc of the method)." @@ -5989,6 +5998,11 @@ class _frommethod: return doc # def __call__(self, a, *args, **params): + if self.reversed: + args = list(args) + arr = args[0] + args[0] = a + a = arr # Get the method from the array (if possible) method_name = self.__name__ method = getattr(a, method_name, None) @@ -6005,7 +6019,7 @@ class _frommethod: all = _frommethod('all') anomalies = anom = _frommethod('anom') any = _frommethod('any') -compress = _frommethod('compress') +compress = _frommethod('compress', reversed=True) cumprod = _frommethod('cumprod') cumsum = _frommethod('cumsum') copy = _frommethod('copy') diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py index 5a484ce9d..d14812093 100644 --- a/numpy/ma/extras.py +++ b/numpy/ma/extras.py @@ -455,7 +455,8 @@ def average(a, axis=None, weights=None, returned=False): The weights array can either be 1-D (in which case its length must be the size of `a` along the given axis) or of the same shape as `a`. If ``weights=None``, then all data in `a` are assumed to have a - weight equal to one. + weight equal to one. If `weights` is complex, the imaginary parts + are ignored. returned : bool, optional Flag indicating whether a tuple ``(result, sum of weights)`` should be returned as output (True), or just the result (False). @@ -515,7 +516,7 @@ def average(a, axis=None, weights=None, returned=False): if mask is nomask: if weights is None: d = ash[axis] * 1.0 - n = add.reduce(a._data, axis, dtype=float) + n = add.reduce(a._data, axis) else: w = filled(weights, 0.0) wsh = w.shape @@ -531,14 +532,14 @@ def average(a, axis=None, weights=None, returned=False): r = [None] * len(ash) r[axis] = slice(None, None, 1) w = eval ("w[" + repr(tuple(r)) + "] * ones(ash, float)") - n = add.reduce(a * w, axis, dtype=float) + n = add.reduce(a * w, axis) d = add.reduce(w, axis, dtype=float) del w, r else: raise ValueError('average: weights wrong shape.') else: if weights is None: - n = add.reduce(a, axis, dtype=float) + n = add.reduce(a, axis) d = umath.add.reduce((-mask), axis=axis, dtype=float) else: w = filled(weights, 0.0) @@ -547,7 +548,7 @@ def average(a, axis=None, weights=None, returned=False): wsh = (1,) if wsh == ash: w = array(w, dtype=float, mask=mask, copy=0) - n = add.reduce(a * w, axis, dtype=float) + n = add.reduce(a * w, axis) d = add.reduce(w, axis, dtype=float) elif wsh == (ash[axis],): ni = ash[axis] @@ -555,7 +556,7 @@ def average(a, axis=None, weights=None, returned=False): r[axis] = slice(None, None, 1) w = eval ("w[" + repr(tuple(r)) + \ "] * masked_array(ones(ash, float), mask)") - n = add.reduce(a * w, axis, dtype=float) + n = add.reduce(a * w, axis) d = add.reduce(w, axis, dtype=float) else: raise ValueError('average: weights wrong shape.') @@ -580,7 +581,6 @@ def average(a, axis=None, weights=None, returned=False): return result - def median(a, axis=None, out=None, overwrite_input=False): """ Compute the median along the specified axis. diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index 263a9735a..a32f6a76b 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -3381,6 +3381,19 @@ class TestMaskedArrayFunctions(TestCase): test = reshape(a, (2, 2)) assert_equal(test, m.reshape(2, 2)) + def test_compress(self): + # Test compress function on ndarray and masked array + # Address Github #2495. + arr = np.arange(8) + arr.shape = 4,2 + cond = np.array([True, False, True, True]) + control = arr[[0, 2, 3]] + test = np.ma.compress(cond, arr, axis=0) + assert_equal(test, control) + marr = np.ma.array(arr) + test = np.ma.compress(cond, marr, axis=0) + assert_equal(test, control) + #------------------------------------------------------------------------------ class TestMaskedFields(TestCase): @@ -3504,6 +3517,34 @@ class TestMaskedFields(TestCase): assert_equal_records(a[-2]._data, a._data[-2]) assert_equal_records(a[-2]._mask, a._mask[-2]) + def test_setitem(self): + # Issue 2403 + ndtype = np.dtype([('a', float), ('b', int)]) + mdtype = np.dtype([('a', bool), ('b', bool)]) + # soft mask + control = np.array([(False, True), (True, True)], dtype=mdtype) + a = np.ma.masked_all((2,), dtype=ndtype) + a['a'][0] = 2 + assert_equal(a.mask, control) + a = np.ma.masked_all((2,), dtype=ndtype) + a[0]['a'] = 2 + assert_equal(a.mask, control) + # hard mask + control = np.array([(True, True), (True, True)], dtype=mdtype) + a = np.ma.masked_all((2,), dtype=ndtype) + a.harden_mask() + a['a'][0] = 2 + assert_equal(a.mask, control) + a = np.ma.masked_all((2,), dtype=ndtype) + a.harden_mask() + a[0]['a'] = 2 + assert_equal(a.mask, control) + + def test_element_len(self): + # check that len() works for mvoid (Github issue #576) + for rec in self.data['base']: + assert_equal(len(rec), len(self.data['ddtype'])) + #------------------------------------------------------------------------------ class TestMaskedView(TestCase): diff --git a/numpy/ma/tests/test_extras.py b/numpy/ma/tests/test_extras.py index d9f94a01f..4b30813b2 100644 --- a/numpy/ma/tests/test_extras.py +++ b/numpy/ma/tests/test_extras.py @@ -16,9 +16,18 @@ __date__ = '$Date: 2007-10-29 17:18:13 +0200 (Mon, 29 Oct 2007) $' import numpy as np from numpy.testing import TestCase, run_module_suite -from numpy.ma.testutils import * -from numpy.ma.core import * -from numpy.ma.extras import * +from numpy.ma.testutils import (rand, assert_, assert_array_equal, + assert_equal, assert_almost_equal) +from numpy.ma.core import (array, arange, masked, MaskedArray, masked_array, + getmaskarray, shape, nomask, ones, zeros, count) +from numpy.ma.extras import (atleast_2d, mr_, dot, polyfit, + cov, corrcoef, median, average, + unique, setxor1d, setdiff1d, union1d, intersect1d, in1d, ediff1d, + apply_over_axes, apply_along_axis, + compress_rowcols, mask_rowcols, + clump_masked, clump_unmasked, + flatnotmasked_contiguous, notmasked_contiguous, notmasked_edges, + masked_all, masked_all_like) class TestGeneric(TestCase): @@ -53,7 +62,6 @@ class TestGeneric(TestCase): control = array([[(1, (1, 1))]], mask=[[(1, (1, 1))]], dtype=dt) assert_equal(test, control) - def test_masked_all_like(self): "Tests masked_all" # Standard dtype @@ -132,10 +140,10 @@ class TestAverage(TestCase): "More tests of average." w1 = [0, 1, 1, 1, 1, 0] w2 = [[0, 1, 1, 1, 1, 0], [1, 0, 0, 0, 0, 1]] - x = arange(6, dtype=float_) + x = arange(6, dtype=np.float_) assert_equal(average(x, axis=0), 2.5) assert_equal(average(x, axis=0, weights=w1), 2.5) - y = array([arange(6, dtype=float_), 2.0 * arange(6)]) + y = array([arange(6, dtype=np.float_), 2.0 * arange(6)]) assert_equal(average(y, None), np.add.reduce(np.arange(6)) * 3. / 12.) assert_equal(average(y, axis=0), np.arange(6) * 3. / 2.) assert_equal(average(y, axis=1), @@ -167,12 +175,12 @@ class TestAverage(TestCase): a = arange(6) b = arange(6) * 3 r1, w1 = average([[a, b], [b, a]], axis=1, returned=1) - assert_equal(shape(r1) , shape(w1)) - assert_equal(r1.shape , w1.shape) + assert_equal(shape(r1), shape(w1)) + assert_equal(r1.shape, w1.shape) r2, w2 = average(ones((2, 2, 3)), axis=0, weights=[3, 1], returned=1) - assert_equal(shape(w2) , shape(r2)) + assert_equal(shape(w2), shape(r2)) r2, w2 = average(ones((2, 2, 3)), returned=1) - assert_equal(shape(w2) , shape(r2)) + assert_equal(shape(w2), shape(r2)) r2, w2 = average(ones((2, 2, 3)), weights=ones((2, 2, 3)), returned=1) assert_equal(shape(w2), shape(r2)) a2d = array([[1, 2], [0, 4]], float) @@ -193,6 +201,50 @@ class TestAverage(TestCase): a = average(array([1, 2, 3, 4], mask=[False, False, True, True])) assert_equal(a, 1.5) + def test_complex(self): + # Test with complex data. + # (Regression test for https://github.com/numpy/numpy/issues/2684) + mask = np.array([[0, 0, 0, 1, 0], + [0, 1, 0, 0, 0]], dtype=bool) + a = masked_array([[0, 1+2j, 3+4j, 5+6j, 7+8j], + [9j, 0+1j, 2+3j, 4+5j, 7+7j]], + mask=mask) + + av = average(a) + expected = np.average(a.compressed()) + assert_almost_equal(av.real, expected.real) + assert_almost_equal(av.imag, expected.imag) + + av0 = average(a, axis=0) + expected0 = average(a.real, axis=0) + average(a.imag, axis=0)*1j + assert_almost_equal(av0.real, expected0.real) + assert_almost_equal(av0.imag, expected0.imag) + + av1 = average(a, axis=1) + expected1 = average(a.real, axis=1) + average(a.imag, axis=1)*1j + assert_almost_equal(av1.real, expected1.real) + assert_almost_equal(av1.imag, expected1.imag) + + # Test with the 'weights' argument. + wts = np.array([[0.5, 1.0, 2.0, 1.0, 0.5], + [1.0, 1.0, 1.0, 1.0, 1.0]]) + wav = average(a, weights=wts) + expected = np.average(a.compressed(), weights=wts[~mask]) + assert_almost_equal(wav.real, expected.real) + assert_almost_equal(wav.imag, expected.imag) + + wav0 = average(a, weights=wts, axis=0) + expected0 = (average(a.real, weights=wts, axis=0) + + average(a.imag, weights=wts, axis=0)*1j) + assert_almost_equal(wav0.real, expected0.real) + assert_almost_equal(wav0.imag, expected0.imag) + + wav1 = average(a, weights=wts, axis=1) + expected1 = (average(a.real, weights=wts, axis=1) + + average(a.imag, weights=wts, axis=1)*1j) + assert_almost_equal(wav1.real, expected1.real) + assert_almost_equal(wav1.imag, expected1.imag) + class TestConcatenator(TestCase): """ @@ -206,7 +258,7 @@ class TestConcatenator(TestCase): m = [1, 0, 0, 0, 0] d = masked_array(b, mask=m) c = mr_[d, 0, 0, d] - self.assertTrue(isinstance(c, MaskedArray) or isinstance(c, core.MaskedArray)) + self.assertTrue(isinstance(c, MaskedArray)) assert_array_equal(c, [1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1]) assert_array_equal(c.mask, mr_[m, 0, 0, m]) @@ -230,7 +282,6 @@ class TestConcatenator(TestCase): assert_array_equal(d.mask, np.r_[m_1, m_2]) - class TestNotMasked(TestCase): """ Tests notmasked_edges and notmasked_contiguous. @@ -270,7 +321,6 @@ class TestNotMasked(TestCase): assert_equal(test[0], [(0, 1, 2, 4), (0, 0, 2, 3)]) assert_equal(test[1], [(0, 1, 2, 4), (4, 2, 4, 4)]) - def test_contiguous(self): "Tests notmasked_contiguous" a = masked_array(np.arange(24).reshape(3, 8), @@ -295,12 +345,12 @@ class TestNotMasked(TestCase): assert_equal(tmp[2][-2], slice(0, 6, None)) - class Test2DFunctions(TestCase): "Tests 2D functions" def test_compress2d(self): "Tests compress2d" - x = array(np.arange(9).reshape(3, 3), mask=[[1, 0, 0], [0, 0, 0], [0, 0, 0]]) + x = array(np.arange(9).reshape(3, 3), + mask=[[1, 0, 0], [0, 0, 0], [0, 0, 0]]) assert_equal(compress_rowcols(x), [[4, 5], [7, 8]]) assert_equal(compress_rowcols(x, 0), [[3, 4, 5], [6, 7, 8]]) assert_equal(compress_rowcols(x, 1), [[1, 2], [4, 5], [7, 8]]) @@ -316,21 +366,31 @@ class Test2DFunctions(TestCase): assert_equal(compress_rowcols(x).size, 0) assert_equal(compress_rowcols(x, 0).size, 0) assert_equal(compress_rowcols(x, 1).size, 0) - # + def test_mask_rowcols(self): "Tests mask_rowcols." - x = array(np.arange(9).reshape(3, 3), mask=[[1, 0, 0], [0, 0, 0], [0, 0, 0]]) - assert_equal(mask_rowcols(x).mask, [[1, 1, 1], [1, 0, 0], [1, 0, 0]]) - assert_equal(mask_rowcols(x, 0).mask, [[1, 1, 1], [0, 0, 0], [0, 0, 0]]) - assert_equal(mask_rowcols(x, 1).mask, [[1, 0, 0], [1, 0, 0], [1, 0, 0]]) + x = array(np.arange(9).reshape(3, 3), + mask=[[1, 0, 0], [0, 0, 0], [0, 0, 0]]) + assert_equal(mask_rowcols(x).mask, + [[1, 1, 1], [1, 0, 0], [1, 0, 0]]) + assert_equal(mask_rowcols(x, 0).mask, + [[1, 1, 1], [0, 0, 0], [0, 0, 0]]) + assert_equal(mask_rowcols(x, 1).mask, + [[1, 0, 0], [1, 0, 0], [1, 0, 0]]) x = array(x._data, mask=[[0, 0, 0], [0, 1, 0], [0, 0, 0]]) - assert_equal(mask_rowcols(x).mask, [[0, 1, 0], [1, 1, 1], [0, 1, 0]]) - assert_equal(mask_rowcols(x, 0).mask, [[0, 0, 0], [1, 1, 1], [0, 0, 0]]) - assert_equal(mask_rowcols(x, 1).mask, [[0, 1, 0], [0, 1, 0], [0, 1, 0]]) + assert_equal(mask_rowcols(x).mask, + [[0, 1, 0], [1, 1, 1], [0, 1, 0]]) + assert_equal(mask_rowcols(x, 0).mask, + [[0, 0, 0], [1, 1, 1], [0, 0, 0]]) + assert_equal(mask_rowcols(x, 1).mask, + [[0, 1, 0], [0, 1, 0], [0, 1, 0]]) x = array(x._data, mask=[[1, 0, 0], [0, 1, 0], [0, 0, 0]]) - assert_equal(mask_rowcols(x).mask, [[1, 1, 1], [1, 1, 1], [1, 1, 0]]) - assert_equal(mask_rowcols(x, 0).mask, [[1, 1, 1], [1, 1, 1], [0, 0, 0]]) - assert_equal(mask_rowcols(x, 1,).mask, [[1, 1, 0], [1, 1, 0], [1, 1, 0]]) + assert_equal(mask_rowcols(x).mask, + [[1, 1, 1], [1, 1, 1], [1, 1, 0]]) + assert_equal(mask_rowcols(x, 0).mask, + [[1, 1, 1], [1, 1, 1], [0, 0, 0]]) + assert_equal(mask_rowcols(x, 1,).mask, + [[1, 1, 0], [1, 1, 0], [1, 1, 0]]) x = array(x._data, mask=[[1, 0, 0], [0, 1, 0], [0, 0, 1]]) self.assertTrue(mask_rowcols(x).all() is masked) self.assertTrue(mask_rowcols(x, 0).all() is masked) @@ -338,7 +398,7 @@ class Test2DFunctions(TestCase): self.assertTrue(mask_rowcols(x).mask.all()) self.assertTrue(mask_rowcols(x, 0).mask.all()) self.assertTrue(mask_rowcols(x, 1).mask.all()) - # + def test_dot(self): "Tests dot product" n = np.arange(1, 7) @@ -410,9 +470,7 @@ class Test2DFunctions(TestCase): assert_equal(c, np.dot(b.filled(0), a.filled(0))) - class TestApplyAlongAxis(TestCase): - # "Tests 2D functions" def test_3d(self): a = arange(12.).reshape(2, 2, 3) @@ -422,21 +480,20 @@ class TestApplyAlongAxis(TestCase): assert_equal(xa, [[1, 4], [7, 10]]) - class TestApplyOverAxes(TestCase): "Tests apply_over_axes" def test_basic(self): a = arange(24).reshape(2, 3, 4) test = apply_over_axes(np.sum, a, [0, 2]) - ctrl = np.array([[[ 60], [ 92], [124]]]) + ctrl = np.array([[[60], [92], [124]]]) assert_equal(test, ctrl) a[(a % 2).astype(np.bool)] = masked test = apply_over_axes(np.sum, a, [0, 2]) - ctrl = np.array([[[ 30], [ 44], [60]]]) + ctrl = np.array([[[30], [44], [60]]]) class TestMedian(TestCase): - # + def test_2d(self): "Tests median w/ 2D" (n, p) = (101, 30) @@ -452,7 +509,7 @@ class TestMedian(TestCase): assert_equal(median(z), 0) assert_equal(median(z, axis=0), np.zeros(p)) assert_equal(median(z.T, axis=1), np.zeros(p)) - # + def test_2d_waxis(self): "Tests median w/ 2D arrays and different axis." x = masked_array(np.arange(30).reshape(10, 3)) @@ -461,7 +518,7 @@ class TestMedian(TestCase): assert_equal(median(x, axis=0), [13.5, 14.5, 15.5]) assert_equal(median(x, axis=1), [0, 0, 0, 10, 13, 16, 19, 0, 0, 0]) assert_equal(median(x, axis=1).mask, [1, 1, 1, 0, 0, 0, 0, 1, 1, 1]) - # + def test_3d(self): "Tests median w/ 3D" x = np.ma.arange(24).reshape(3, 4, 2) @@ -474,7 +531,6 @@ class TestMedian(TestCase): assert_equal(median(x, 0), [[12, 10], [8, 9], [16, 17]]) - class TestCov(TestCase): def setUp(self): @@ -528,16 +584,18 @@ class TestCov(TestCase): valid = np.logical_not(getmaskarray(x)).astype(int) frac = np.dot(valid, valid.T) xf = (x - x.mean(1)[:, None]).filled(0) - assert_almost_equal(cov(x), np.cov(xf) * (x.shape[1] - 1) / (frac - 1.)) + assert_almost_equal(cov(x), + np.cov(xf) * (x.shape[1] - 1) / (frac - 1.)) assert_almost_equal(cov(x, bias=True), np.cov(xf, bias=True) * x.shape[1] / frac) frac = np.dot(valid.T, valid) xf = (x - x.mean(0)).filled(0) assert_almost_equal(cov(x, rowvar=False), - np.cov(xf, rowvar=False) * (x.shape[0] - 1) / (frac - 1.)) + (np.cov(xf, rowvar=False) * + (x.shape[0] - 1) / (frac - 1.))) assert_almost_equal(cov(x, rowvar=False, bias=True), - np.cov(xf, rowvar=False, bias=True) * x.shape[0] / frac) - + (np.cov(xf, rowvar=False, bias=True) * + x.shape[0] / frac)) class TestCorrcoef(TestCase): @@ -550,7 +608,6 @@ class TestCorrcoef(TestCase): x = self.data assert_almost_equal(np.corrcoef(x, ddof=0), corrcoef(x, ddof=0)) - def test_1d_wo_missing(self): "Test cov on 1D variable w/o missing values" x = self.data @@ -576,7 +633,8 @@ class TestCorrcoef(TestCase): x -= x.mean() nx = x.compressed() assert_almost_equal(np.corrcoef(nx), corrcoef(x)) - assert_almost_equal(np.corrcoef(nx, rowvar=False), corrcoef(x, rowvar=False)) + assert_almost_equal(np.corrcoef(nx, rowvar=False), + corrcoef(x, rowvar=False)) assert_almost_equal(np.corrcoef(nx, rowvar=False, bias=True), corrcoef(x, rowvar=False, bias=True)) # @@ -604,7 +662,6 @@ class TestCorrcoef(TestCase): assert_almost_equal(test[:-1, :-1], control[:-1, :-1]) - class TestPolynomial(TestCase): # def test_polyfit(self): @@ -620,7 +677,8 @@ class TestPolynomial(TestCase): y[0, 0] = y[-1, -1] = masked # (C, R, K, S, D) = polyfit(x, y[:, 0], 3, full=True) - (c, r, k, s, d) = np.polyfit(x[1:], y[1:, 0].compressed(), 3, full=True) + (c, r, k, s, d) = np.polyfit(x[1:], y[1:, 0].compressed(), 3, + full=True) for (a, a_) in zip((C, R, K, S, D), (c, r, k, s, d)): assert_almost_equal(a, a_) # @@ -634,7 +692,7 @@ class TestPolynomial(TestCase): for (a, a_) in zip((C, R, K, S, D), (c, r, k, s, d)): assert_almost_equal(a, a_) # - w = np.random.rand(10) + 1 + w = np.random.rand(10) + 1 wo = w.copy() xs = x[1:-1] ys = y[1:-1] @@ -647,7 +705,7 @@ class TestPolynomial(TestCase): class TestArraySetOps(TestCase): - # + def test_unique_onlist(self): "Test unique on list" data = [1, 1, 1, 2, 2, 3] @@ -696,7 +754,7 @@ class TestArraySetOps(TestCase): assert_equal(test, control) assert_equal(test.data, control.data) assert_equal(test.mask, control.mask) - # + def test_ediff1d_tobegin(self): "Test ediff1d w/ to_begin" x = masked_array(np.arange(5), mask=[1, 0, 0, 0, 1]) @@ -711,7 +769,7 @@ class TestArraySetOps(TestCase): assert_equal(test, control) assert_equal(test.data, control.data) assert_equal(test.mask, control.mask) - # + def test_ediff1d_toend(self): "Test ediff1d w/ to_end" x = masked_array(np.arange(5), mask=[1, 0, 0, 0, 1]) @@ -726,7 +784,7 @@ class TestArraySetOps(TestCase): assert_equal(test, control) assert_equal(test.data, control.data) assert_equal(test.mask, control.mask) - # + def test_ediff1d_tobegin_toend(self): "Test ediff1d w/ to_begin and to_end" x = masked_array(np.arange(5), mask=[1, 0, 0, 0, 1]) @@ -737,11 +795,12 @@ class TestArraySetOps(TestCase): assert_equal(test.mask, control.mask) # test = ediff1d(x, to_end=[1, 2, 3], to_begin=masked) - control = array([0, 1, 1, 1, 4, 1, 2, 3], mask=[1, 1, 0, 0, 1, 0, 0, 0]) + control = array([0, 1, 1, 1, 4, 1, 2, 3], + mask=[1, 1, 0, 0, 1, 0, 0, 0]) assert_equal(test, control) assert_equal(test.data, control.data) assert_equal(test.mask, control.mask) - # + def test_ediff1d_ndarray(self): "Test ediff1d w/ a ndarray" x = np.arange(5) @@ -758,7 +817,6 @@ class TestArraySetOps(TestCase): assert_equal(test.data, control.data) assert_equal(test.mask, control.mask) - def test_intersect1d(self): "Test intersect1d" x = array([1, 3, 3, 3], mask=[0, 0, 0, 1]) @@ -767,7 +825,6 @@ class TestArraySetOps(TestCase): control = array([1, 3, -1], mask=[0, 0, 1]) assert_equal(test, control) - def test_setxor1d(self): "Test setxor1d" a = array([1, 2, 5, 7, -1], mask=[0, 0, 0, 0, 1]) @@ -794,7 +851,6 @@ class TestArraySetOps(TestCase): # assert_array_equal([], setxor1d([], [])) - def test_in1d(self): "Test in1d" a = array([1, 2, 5, 7, -1], mask=[0, 0, 0, 0, 1]) @@ -809,7 +865,6 @@ class TestArraySetOps(TestCase): # assert_array_equal([], in1d([], [])) - def test_in1d_invert(self): "Test in1d's invert parameter" a = array([1, 2, 5, 7, -1], mask=[0, 0, 0, 0, 1]) @@ -822,7 +877,6 @@ class TestArraySetOps(TestCase): assert_array_equal([], in1d([], [], invert=True)) - def test_union1d(self): "Test union1d" a = array([1, 2, 5, 7, 5, -1], mask=[0, 0, 0, 0, 0, 1]) @@ -833,7 +887,6 @@ class TestArraySetOps(TestCase): # assert_array_equal([], union1d([], [])) - def test_setdiff1d(self): "Test setdiff1d" a = array([6, 5, 4, 7, 7, 1, 2, 1], mask=[0, 0, 0, 0, 0, 0, 0, 1]) @@ -845,7 +898,6 @@ class TestArraySetOps(TestCase): b = arange(8) assert_equal(setdiff1d(a, b), array([8, 9])) - def test_setdiff1d_char_array(self): "Test setdiff1d_charray" a = np.array(['a', 'b', 'c']) @@ -853,9 +905,6 @@ class TestArraySetOps(TestCase): assert_array_equal(setdiff1d(a, b), np.array(['c'])) - - - class TestShapeBase(TestCase): # def test_atleast2d(self): diff --git a/numpy/polynomial/chebyshev.py b/numpy/polynomial/chebyshev.py index dc1b27d76..db1b637fd 100644 --- a/numpy/polynomial/chebyshev.py +++ b/numpy/polynomial/chebyshev.py @@ -1795,7 +1795,7 @@ def chebcompanion(c): if len(c) < 2: raise ValueError('Series must have maximum degree of at least 1.') if len(c) == 2: - return np.array(-c[0]/c[1]) + return np.array([[-c[0]/c[1]]]) n = len(c) - 1 mat = np.zeros((n, n), dtype=c.dtype) diff --git a/numpy/polynomial/hermite.py b/numpy/polynomial/hermite.py index 9051bf533..13b9e6845 100644 --- a/numpy/polynomial/hermite.py +++ b/numpy/polynomial/hermite.py @@ -1573,7 +1573,7 @@ def hermcompanion(c): if len(c) < 2: raise ValueError('Series must have maximum degree of at least 1.') if len(c) == 2: - return np.array(-.5*c[0]/c[1]) + return np.array([[-.5*c[0]/c[1]]]) n = len(c) - 1 mat = np.zeros((n, n), dtype=c.dtype) diff --git a/numpy/polynomial/hermite_e.py b/numpy/polynomial/hermite_e.py index 13810c97f..9f10403dd 100644 --- a/numpy/polynomial/hermite_e.py +++ b/numpy/polynomial/hermite_e.py @@ -1570,7 +1570,7 @@ def hermecompanion(c): if len(c) < 2: raise ValueError('Series must have maximum degree of at least 1.') if len(c) == 2: - return np.array(-c[0]/c[1]) + return np.array([[-c[0]/c[1]]]) n = len(c) - 1 mat = np.zeros((n, n), dtype=c.dtype) diff --git a/numpy/polynomial/laguerre.py b/numpy/polynomial/laguerre.py index 1cc316bca..ea805e146 100644 --- a/numpy/polynomial/laguerre.py +++ b/numpy/polynomial/laguerre.py @@ -1571,7 +1571,7 @@ def lagcompanion(c): if len(c) < 2: raise ValueError('Series must have maximum degree of at least 1.') if len(c) == 2: - return np.array(1 + c[0]/c[1]) + return np.array([[1 + c[0]/c[1]]]) n = len(c) - 1 mat = np.zeros((n, n), dtype=c.dtype) diff --git a/numpy/polynomial/legendre.py b/numpy/polynomial/legendre.py index 1440cdf87..c7a1f2dd2 100644 --- a/numpy/polynomial/legendre.py +++ b/numpy/polynomial/legendre.py @@ -1596,7 +1596,7 @@ def legcompanion(c): if len(c) < 2: raise ValueError('Series must have maximum degree of at least 1.') if len(c) == 2: - return np.array(-c[0]/c[1]) + return np.array([[-c[0]/c[1]]]) n = len(c) - 1 mat = np.zeros((n, n), dtype=c.dtype) diff --git a/numpy/polynomial/polynomial.py b/numpy/polynomial/polynomial.py index 7a0b36cde..0b044e8e8 100644 --- a/numpy/polynomial/polynomial.py +++ b/numpy/polynomial/polynomial.py @@ -39,6 +39,7 @@ Misc Functions - `polyvander` -- Vandermonde-like matrix for powers. - `polyvander2d` -- Vandermonde-like matrix for 2D power series. - `polyvander3d` -- Vandermonde-like matrix for 3D power series. +- `polycompanion` -- companion matrix in power series form. - `polyfit` -- least-squares fit returning a polynomial. - `polytrim` -- trim leading coefficients from a polynomial. - `polyline` -- polynomial representing given straight line. @@ -1417,7 +1418,7 @@ def polycompanion(c): if len(c) < 2 : raise ValueError('Series must have maximum degree of at least 1.') if len(c) == 2: - return np.array(-c[0]/c[1]) + return np.array([[-c[0]/c[1]]]) n = len(c) - 1 mat = np.zeros((n, n), dtype=c.dtype) diff --git a/numpy/polynomial/tests/test_chebyshev.py b/numpy/polynomial/tests/test_chebyshev.py index 23a17b464..367d81f58 100644 --- a/numpy/polynomial/tests/test_chebyshev.py +++ b/numpy/polynomial/tests/test_chebyshev.py @@ -440,6 +440,22 @@ class TestFitting(TestCase): x = [1, 1j, -1, -1j] assert_almost_equal(cheb.chebfit(x, x, 1), [0, 1]) + +class TestCompanion(TestCase): + + def test_raises(self): + assert_raises(ValueError, cheb.chebcompanion, []) + assert_raises(ValueError, cheb.chebcompanion, [1]) + + def test_dimensions(self): + for i in range(1, 5): + coef = [0]*i + [1] + assert_(cheb.chebcompanion(coef).shape == (i, i)) + + def test_linear_root(self): + assert_(cheb.chebcompanion([1, 2])[0, 0] == -.5) + + class TestGauss(TestCase): def test_100(self): diff --git a/numpy/polynomial/tests/test_hermite.py b/numpy/polynomial/tests/test_hermite.py index 785f9b255..327283d0e 100644 --- a/numpy/polynomial/tests/test_hermite.py +++ b/numpy/polynomial/tests/test_hermite.py @@ -430,6 +430,22 @@ class TestFitting(TestCase): x = [1, 1j, -1, -1j] assert_almost_equal(herm.hermfit(x, x, 1), [0, .5]) + +class TestCompanion(TestCase): + + def test_raises(self): + assert_raises(ValueError, herm.hermcompanion, []) + assert_raises(ValueError, herm.hermcompanion, [1]) + + def test_dimensions(self): + for i in range(1, 5): + coef = [0]*i + [1] + assert_(herm.hermcompanion(coef).shape == (i, i)) + + def test_linear_root(self): + assert_(herm.hermcompanion([1, 2])[0, 0] == -.25) + + class TestGauss(TestCase): def test_100(self): diff --git a/numpy/polynomial/tests/test_hermite_e.py b/numpy/polynomial/tests/test_hermite_e.py index 84c952578..404a46fc7 100644 --- a/numpy/polynomial/tests/test_hermite_e.py +++ b/numpy/polynomial/tests/test_hermite_e.py @@ -427,6 +427,22 @@ class TestFitting(TestCase): x = [1, 1j, -1, -1j] assert_almost_equal(herme.hermefit(x, x, 1), [0, 1]) + +class TestCompanion(TestCase): + + def test_raises(self): + assert_raises(ValueError, herme.hermecompanion, []) + assert_raises(ValueError, herme.hermecompanion, [1]) + + def test_dimensions(self): + for i in range(1, 5): + coef = [0]*i + [1] + assert_(herme.hermecompanion(coef).shape == (i, i)) + + def test_linear_root(self): + assert_(herme.hermecompanion([1, 2])[0, 0] == -.5) + + class TestGauss(TestCase): def test_100(self): diff --git a/numpy/polynomial/tests/test_laguerre.py b/numpy/polynomial/tests/test_laguerre.py index b7268fe59..38fcce299 100644 --- a/numpy/polynomial/tests/test_laguerre.py +++ b/numpy/polynomial/tests/test_laguerre.py @@ -425,6 +425,22 @@ class TestFitting(TestCase): x = [1, 1j, -1, -1j] assert_almost_equal(lag.lagfit(x, x, 1), [1, -1]) + +class TestCompanion(TestCase): + + def test_raises(self): + assert_raises(ValueError, lag.lagcompanion, []) + assert_raises(ValueError, lag.lagcompanion, [1]) + + def test_dimensions(self): + for i in range(1, 5): + coef = [0]*i + [1] + assert_(lag.lagcompanion(coef).shape == (i, i)) + + def test_linear_root(self): + assert_(lag.lagcompanion([1, 2])[0, 0] == 1.5) + + class TestGauss(TestCase): def test_100(self): diff --git a/numpy/polynomial/tests/test_legendre.py b/numpy/polynomial/tests/test_legendre.py index ae86f65b6..379bdee31 100644 --- a/numpy/polynomial/tests/test_legendre.py +++ b/numpy/polynomial/tests/test_legendre.py @@ -428,6 +428,22 @@ class TestFitting(TestCase): x = [1, 1j, -1, -1j] assert_almost_equal(leg.legfit(x, x, 1), [0, 1]) + +class TestCompanion(TestCase): + + def test_raises(self): + assert_raises(ValueError, leg.legcompanion, []) + assert_raises(ValueError, leg.legcompanion, [1]) + + def test_dimensions(self): + for i in range(1, 5): + coef = [0]*i + [1] + assert_(leg.legcompanion(coef).shape == (i, i)) + + def test_linear_root(self): + assert_(leg.legcompanion([1, 2])[0, 0] == -.5) + + class TestGauss(TestCase): def test_100(self): diff --git a/numpy/polynomial/tests/test_polynomial.py b/numpy/polynomial/tests/test_polynomial.py index 3d9519679..583872978 100644 --- a/numpy/polynomial/tests/test_polynomial.py +++ b/numpy/polynomial/tests/test_polynomial.py @@ -383,6 +383,21 @@ class TestVander(TestCase): assert_(van.shape == (1, 5, 24)) +class TestCompanion(TestCase): + + def test_raises(self): + assert_raises(ValueError, poly.polycompanion, []) + assert_raises(ValueError, poly.polycompanion, [1]) + + def test_dimensions(self): + for i in range(1, 5): + coef = [0]*i + [1] + assert_(poly.polycompanion(coef).shape == (i, i)) + + def test_linear_root(self): + assert_(poly.polycompanion([1, 2])[0, 0] == -.5) + + class TestMisc(TestCase) : def test_polyfromroots(self) : diff --git a/numpy/random/mtrand/mtrand.c b/numpy/random/mtrand/mtrand.c index a81170674..c411298de 100644 --- a/numpy/random/mtrand/mtrand.c +++ b/numpy/random/mtrand/mtrand.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.19.1 on Mon May 27 11:39:14 2013 */ +/* Generated by Cython 0.19.1 on Thu Jun 13 06:23:57 2013 */ #define PY_SSIZE_T_CLEAN #ifndef CYTHON_USE_PYLONG_INTERNALS @@ -264,7 +264,7 @@ #ifndef CYTHON_RESTRICT #if defined(__GNUC__) #define CYTHON_RESTRICT __restrict__ - #elif defined(_MSC_VER) && _MSC_VER >= 1400 + #elif defined(_MSC_VER) #define CYTHON_RESTRICT __restrict #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L #define CYTHON_RESTRICT restrict @@ -854,11 +854,11 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ /* Module declarations from 'numpy' */ /* Module declarations from 'mtrand' */ -static PyTypeObject *__pyx_ptype_6mtrand_ndarray = 0; -static PyTypeObject *__pyx_ptype_6mtrand_broadcast = 0; static PyTypeObject *__pyx_ptype_6mtrand_RandomState = 0; static PyTypeObject *__pyx_ptype_6mtrand_flatiter = 0; +static PyTypeObject *__pyx_ptype_6mtrand_ndarray = 0; static PyTypeObject *__pyx_ptype_6mtrand_dtype = 0; +static PyTypeObject *__pyx_ptype_6mtrand_broadcast = 0; static PyObject *__pyx_f_6mtrand_cont0_array(rk_state *, __pyx_t_6mtrand_rk_cont0, PyObject *); /*proto*/ static PyObject *__pyx_f_6mtrand_cont1_array_sc(rk_state *, __pyx_t_6mtrand_rk_cont1, PyObject *, double); /*proto*/ static PyObject *__pyx_f_6mtrand_cont1_array(rk_state *, __pyx_t_6mtrand_rk_cont1, PyObject *, PyArrayObject *); /*proto*/ @@ -985,8 +985,8 @@ static char __pyx_k_156[] = "lam value too large."; static char __pyx_k_158[] = "a <= 1.0"; static char __pyx_k_161[] = "p < 0.0"; static char __pyx_k_163[] = "p > 1.0"; -static char __pyx_k_167[] = "ngood < 1"; -static char __pyx_k_169[] = "nbad < 1"; +static char __pyx_k_167[] = "ngood < 0"; +static char __pyx_k_169[] = "nbad < 0"; static char __pyx_k_171[] = "nsample < 1"; static char __pyx_k_173[] = "ngood + nbad < nsample"; static char __pyx_k_179[] = "p <= 0.0"; @@ -1071,7 +1071,7 @@ static char __pyx_k_269[] = "\n zipf(a, size=None)\n\n Draw sample static char __pyx_k_270[] = "RandomState.geometric (line 3770)"; static char __pyx_k_271[] = "\n geometric(p, size=None)\n\n Draw samples from the geometric distribution.\n\n Bernoulli trials are experiments with one of two outcomes:\n success or failure (an example of such an experiment is flipping\n a coin). The geometric distribution models the number of trials\n that must be run in order to achieve success. It is therefore\n supported on the positive integers, ``k = 1, 2, ...``.\n\n The probability mass function of the geometric distribution is\n\n .. math:: f(k) = (1 - p)^{k - 1} p\n\n where `p` is the probability of success of an individual trial.\n\n Parameters\n ----------\n p : float\n The probability of success of an individual trial.\n size : tuple of ints\n Number of values to draw from the distribution. The output\n is shaped according to `size`.\n\n Returns\n -------\n out : ndarray\n Samples from the geometric distribution, shaped according to\n `size`.\n\n Examples\n --------\n Draw ten thousand values from the geometric distribution,\n with the probability of an individual success equal to 0.35:\n\n >>> z = np.random.geometric(p=0.35, size=10000)\n\n How many trials succeeded after a single run?\n\n >>> (z == 1).sum() / 10000.\n 0.34889999999999999 #random\n\n "; static char __pyx_k_272[] = "RandomState.hypergeometric (line 3836)"; -static char __pyx_k_273[] = "\n hypergeometric(ngood, nbad, nsample, size=None)\n\n Draw samples from a Hypergeometric distribution.\n\n Samples are drawn from a Hypergeometric distribution with specified\n parameters, ngood (ways to make a good selection), nbad (ways to make\n a bad selection), and nsample = number of items sampled, which is less\n than or equal to the sum ngood + nbad.\n\n Parameters\n ----------\n ngood : float (but truncated to an integer)\n parameter, > 0.\n nbad : float\n parameter, >= 0.\n nsample : float\n parameter, > 0 and <= ngood+nbad\n size : {tuple, int}\n Output shape. If the given shape is, e.g., ``(m, n, k)``, then\n ``m * n * k`` samples are drawn.\n\n Returns\n -------\n samples : {ndarray, scalar}\n where the values are all integers in [0, n].\n\n See Also\n --------\n scipy.stats.distributions.hypergeom : probability density function,\n distribution or cumulative density function, etc.\n\n Notes\n -----\n The probability density for the Hypergeometric distribution is\n\n .. math:: P(x) = \\frac{\\binom{m}{n}\\binom{N-m}{n-x}}{\\binom{N}{n}},\n\n where :math:`0 \\le x \\le m` and :math:`n+m-N \\le x \\le n`\n\n for P(x) the probability of x successes, n = ngood, m = nbad, and\n N = number of samples.\n\n Consider an urn with black and white marbles in it, ngood of them\n black and nbad are white. If you draw nsample balls without\n replacement, then the Hypergeometric distribution describes the\n distribution of black balls in the drawn sample.\n\n Note that this distribution is very similar to the Binomial\n distribution, except that in this case, samples are drawn without\n replacement, whereas in the Binomial case samples are drawn wit""h\n replacement (or the sample space is infinite). As the sample space\n becomes large, this distribution approaches the Binomial.\n\n References\n ----------\n .. [1] Lentner, Marvin, \"Elementary Applied Statistics\", Bogden\n and Quigley, 1972.\n .. [2] Weisstein, Eric W. \"Hypergeometric Distribution.\" From\n MathWorld--A Wolfram Web Resource.\n http://mathworld.wolfram.com/HypergeometricDistribution.html\n .. [3] Wikipedia, \"Hypergeometric-distribution\",\n http://en.wikipedia.org/wiki/Hypergeometric-distribution\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> ngood, nbad, nsamp = 100, 2, 10\n # number of good, number of bad, and number of samples\n >>> s = np.random.hypergeometric(ngood, nbad, nsamp, 1000)\n >>> hist(s)\n # note that it is very unlikely to grab both bad items\n\n Suppose you have an urn with 15 white and 15 black marbles.\n If you pull 15 marbles at random, how likely is it that\n 12 or more of them are one color?\n\n >>> s = np.random.hypergeometric(15, 15, 15, 100000)\n >>> sum(s>=12)/100000. + sum(s<=3)/100000.\n # answer = 0.003 ... pretty unlikely!\n\n "; +static char __pyx_k_273[] = "\n hypergeometric(ngood, nbad, nsample, size=None)\n\n Draw samples from a Hypergeometric distribution.\n\n Samples are drawn from a Hypergeometric distribution with specified\n parameters, ngood (ways to make a good selection), nbad (ways to make\n a bad selection), and nsample = number of items sampled, which is less\n than or equal to the sum ngood + nbad.\n\n Parameters\n ----------\n ngood : int or array_like\n Number of ways to make a good selection. Must be nonnegative.\n nbad : int or array_like\n Number of ways to make a bad selection. Must be nonnegative.\n nsample : int or array_like\n Number of items sampled. Must be at least 1 and at most\n ``ngood + nbad``.\n size : int or tuple of int\n Output shape. If the given shape is, e.g., ``(m, n, k)``, then\n ``m * n * k`` samples are drawn.\n\n Returns\n -------\n samples : ndarray or scalar\n The values are all integers in [0, n].\n\n See Also\n --------\n scipy.stats.distributions.hypergeom : probability density function,\n distribution or cumulative density function, etc.\n\n Notes\n -----\n The probability density for the Hypergeometric distribution is\n\n .. math:: P(x) = \\frac{\\binom{m}{n}\\binom{N-m}{n-x}}{\\binom{N}{n}},\n\n where :math:`0 \\le x \\le m` and :math:`n+m-N \\le x \\le n`\n\n for P(x) the probability of x successes, n = ngood, m = nbad, and\n N = number of samples.\n\n Consider an urn with black and white marbles in it, ngood of them\n black and nbad are white. If you draw nsample balls without\n replacement, then the Hypergeometric distribution describes the\n distribution of black balls in the drawn sample.\n\n Note that this distribution is very similar to the Binomial\n distrib""ution, except that in this case, samples are drawn without\n replacement, whereas in the Binomial case samples are drawn with\n replacement (or the sample space is infinite). As the sample space\n becomes large, this distribution approaches the Binomial.\n\n References\n ----------\n .. [1] Lentner, Marvin, \"Elementary Applied Statistics\", Bogden\n and Quigley, 1972.\n .. [2] Weisstein, Eric W. \"Hypergeometric Distribution.\" From\n MathWorld--A Wolfram Web Resource.\n http://mathworld.wolfram.com/HypergeometricDistribution.html\n .. [3] Wikipedia, \"Hypergeometric-distribution\",\n http://en.wikipedia.org/wiki/Hypergeometric-distribution\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> ngood, nbad, nsamp = 100, 2, 10\n # number of good, number of bad, and number of samples\n >>> s = np.random.hypergeometric(ngood, nbad, nsamp, 1000)\n >>> hist(s)\n # note that it is very unlikely to grab both bad items\n\n Suppose you have an urn with 15 white and 15 black marbles.\n If you pull 15 marbles at random, how likely is it that\n 12 or more of them are one color?\n\n >>> s = np.random.hypergeometric(15, 15, 15, 100000)\n >>> sum(s>=12)/100000. + sum(s<=3)/100000.\n # answer = 0.003 ... pretty unlikely!\n\n "; static char __pyx_k_274[] = "RandomState.logseries (line 3955)"; static char __pyx_k_275[] = "\n logseries(p, size=None)\n\n Draw samples from a Logarithmic Series distribution.\n\n Samples are drawn from a Log Series distribution with specified\n parameter, p (probability, 0 < p < 1).\n\n Parameters\n ----------\n loc : float\n\n scale : float > 0.\n\n size : {tuple, int}\n Output shape. If the given shape is, e.g., ``(m, n, k)``, then\n ``m * n * k`` samples are drawn.\n\n Returns\n -------\n samples : {ndarray, scalar}\n where the values are all integers in [0, n].\n\n See Also\n --------\n scipy.stats.distributions.logser : probability density function,\n distribution or cumulative density function, etc.\n\n Notes\n -----\n The probability density for the Log Series distribution is\n\n .. math:: P(k) = \\frac{-p^k}{k \\ln(1-p)},\n\n where p = probability.\n\n The Log Series distribution is frequently used to represent species\n richness and occurrence, first proposed by Fisher, Corbet, and\n Williams in 1943 [2]. It may also be used to model the numbers of\n occupants seen in cars [3].\n\n References\n ----------\n .. [1] Buzas, Martin A.; Culver, Stephen J., Understanding regional\n species diversity through the log series distribution of\n occurrences: BIODIVERSITY RESEARCH Diversity & Distributions,\n Volume 5, Number 5, September 1999 , pp. 187-195(9).\n .. [2] Fisher, R.A,, A.S. Corbet, and C.B. Williams. 1943. The\n relation between the number of species and the number of\n individuals in a random sample of an animal population.\n Journal of Animal Ecology, 12:42-58.\n .. [3] D. J. Hand, F. Daly, D. Lunn, E. Ostrowski, A Handbook of Small\n Data Sets, CRC Press, 1994.\n .. [4] Wikipedia, \"Log""arithmic-distribution\",\n http://en.wikipedia.org/wiki/Logarithmic-distribution\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> a = .6\n >>> s = np.random.logseries(a, 10000)\n >>> count, bins, ignored = plt.hist(s)\n\n # plot against distribution\n\n >>> def logseries(k, p):\n ... return -p**k/(k*log(1-p))\n >>> plt.plot(bins, logseries(bins, a)*count.max()/\n logseries(bins, a).max(), 'r')\n >>> plt.show()\n\n "; static char __pyx_k_276[] = "RandomState.multivariate_normal (line 4050)"; @@ -18225,7 +18225,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_90geometric(struct __pyx_obj_6mt /* Python wrapper */ static PyObject *__pyx_pw_6mtrand_11RandomState_93hypergeometric(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_6mtrand_11RandomState_92hypergeometric[] = "\n hypergeometric(ngood, nbad, nsample, size=None)\n\n Draw samples from a Hypergeometric distribution.\n\n Samples are drawn from a Hypergeometric distribution with specified\n parameters, ngood (ways to make a good selection), nbad (ways to make\n a bad selection), and nsample = number of items sampled, which is less\n than or equal to the sum ngood + nbad.\n\n Parameters\n ----------\n ngood : float (but truncated to an integer)\n parameter, > 0.\n nbad : float\n parameter, >= 0.\n nsample : float\n parameter, > 0 and <= ngood+nbad\n size : {tuple, int}\n Output shape. If the given shape is, e.g., ``(m, n, k)``, then\n ``m * n * k`` samples are drawn.\n\n Returns\n -------\n samples : {ndarray, scalar}\n where the values are all integers in [0, n].\n\n See Also\n --------\n scipy.stats.distributions.hypergeom : probability density function,\n distribution or cumulative density function, etc.\n\n Notes\n -----\n The probability density for the Hypergeometric distribution is\n\n .. math:: P(x) = \\frac{\\binom{m}{n}\\binom{N-m}{n-x}}{\\binom{N}{n}},\n\n where :math:`0 \\le x \\le m` and :math:`n+m-N \\le x \\le n`\n\n for P(x) the probability of x successes, n = ngood, m = nbad, and\n N = number of samples.\n\n Consider an urn with black and white marbles in it, ngood of them\n black and nbad are white. If you draw nsample balls without\n replacement, then the Hypergeometric distribution describes the\n distribution of black balls in the drawn sample.\n\n Note that this distribution is very similar to the Binomial\n distribution, except that in this case, samples are drawn without\n replacement, whereas in the Binomial case samples are drawn wit""h\n replacement (or the sample space is infinite). As the sample space\n becomes large, this distribution approaches the Binomial.\n\n References\n ----------\n .. [1] Lentner, Marvin, \"Elementary Applied Statistics\", Bogden\n and Quigley, 1972.\n .. [2] Weisstein, Eric W. \"Hypergeometric Distribution.\" From\n MathWorld--A Wolfram Web Resource.\n http://mathworld.wolfram.com/HypergeometricDistribution.html\n .. [3] Wikipedia, \"Hypergeometric-distribution\",\n http://en.wikipedia.org/wiki/Hypergeometric-distribution\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> ngood, nbad, nsamp = 100, 2, 10\n # number of good, number of bad, and number of samples\n >>> s = np.random.hypergeometric(ngood, nbad, nsamp, 1000)\n >>> hist(s)\n # note that it is very unlikely to grab both bad items\n\n Suppose you have an urn with 15 white and 15 black marbles.\n If you pull 15 marbles at random, how likely is it that\n 12 or more of them are one color?\n\n >>> s = np.random.hypergeometric(15, 15, 15, 100000)\n >>> sum(s>=12)/100000. + sum(s<=3)/100000.\n # answer = 0.003 ... pretty unlikely!\n\n "; +static char __pyx_doc_6mtrand_11RandomState_92hypergeometric[] = "\n hypergeometric(ngood, nbad, nsample, size=None)\n\n Draw samples from a Hypergeometric distribution.\n\n Samples are drawn from a Hypergeometric distribution with specified\n parameters, ngood (ways to make a good selection), nbad (ways to make\n a bad selection), and nsample = number of items sampled, which is less\n than or equal to the sum ngood + nbad.\n\n Parameters\n ----------\n ngood : int or array_like\n Number of ways to make a good selection. Must be nonnegative.\n nbad : int or array_like\n Number of ways to make a bad selection. Must be nonnegative.\n nsample : int or array_like\n Number of items sampled. Must be at least 1 and at most\n ``ngood + nbad``.\n size : int or tuple of int\n Output shape. If the given shape is, e.g., ``(m, n, k)``, then\n ``m * n * k`` samples are drawn.\n\n Returns\n -------\n samples : ndarray or scalar\n The values are all integers in [0, n].\n\n See Also\n --------\n scipy.stats.distributions.hypergeom : probability density function,\n distribution or cumulative density function, etc.\n\n Notes\n -----\n The probability density for the Hypergeometric distribution is\n\n .. math:: P(x) = \\frac{\\binom{m}{n}\\binom{N-m}{n-x}}{\\binom{N}{n}},\n\n where :math:`0 \\le x \\le m` and :math:`n+m-N \\le x \\le n`\n\n for P(x) the probability of x successes, n = ngood, m = nbad, and\n N = number of samples.\n\n Consider an urn with black and white marbles in it, ngood of them\n black and nbad are white. If you draw nsample balls without\n replacement, then the Hypergeometric distribution describes the\n distribution of black balls in the drawn sample.\n\n Note that this distribution is very similar to the Binomial\n distrib""ution, except that in this case, samples are drawn without\n replacement, whereas in the Binomial case samples are drawn with\n replacement (or the sample space is infinite). As the sample space\n becomes large, this distribution approaches the Binomial.\n\n References\n ----------\n .. [1] Lentner, Marvin, \"Elementary Applied Statistics\", Bogden\n and Quigley, 1972.\n .. [2] Weisstein, Eric W. \"Hypergeometric Distribution.\" From\n MathWorld--A Wolfram Web Resource.\n http://mathworld.wolfram.com/HypergeometricDistribution.html\n .. [3] Wikipedia, \"Hypergeometric-distribution\",\n http://en.wikipedia.org/wiki/Hypergeometric-distribution\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> ngood, nbad, nsamp = 100, 2, 10\n # number of good, number of bad, and number of samples\n >>> s = np.random.hypergeometric(ngood, nbad, nsamp, 1000)\n >>> hist(s)\n # note that it is very unlikely to grab both bad items\n\n Suppose you have an urn with 15 white and 15 black marbles.\n If you pull 15 marbles at random, how likely is it that\n 12 or more of them are one color?\n\n >>> s = np.random.hypergeometric(15, 15, 15, 100000)\n >>> sum(s>=12)/100000. + sum(s<=3)/100000.\n # answer = 0.003 ... pretty unlikely!\n\n "; static PyObject *__pyx_pw_6mtrand_11RandomState_93hypergeometric(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_ngood = 0; PyObject *__pyx_v_nbad = 0; @@ -18332,7 +18332,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_92hypergeometric(struct __pyx_ob int __pyx_clineno = 0; __Pyx_RefNannySetupContext("hypergeometric", 0); - /* "mtrand.pyx":3923 + /* "mtrand.pyx":3924 * cdef long lngood, lnbad, lnsample * * lngood = PyInt_AsLong(ngood) # <<<<<<<<<<<<<< @@ -18341,7 +18341,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_92hypergeometric(struct __pyx_ob */ __pyx_v_lngood = PyInt_AsLong(__pyx_v_ngood); - /* "mtrand.pyx":3924 + /* "mtrand.pyx":3925 * * lngood = PyInt_AsLong(ngood) * lnbad = PyInt_AsLong(nbad) # <<<<<<<<<<<<<< @@ -18350,142 +18350,131 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_92hypergeometric(struct __pyx_ob */ __pyx_v_lnbad = PyInt_AsLong(__pyx_v_nbad); - /* "mtrand.pyx":3925 + /* "mtrand.pyx":3926 * lngood = PyInt_AsLong(ngood) * lnbad = PyInt_AsLong(nbad) * lnsample = PyInt_AsLong(nsample) # <<<<<<<<<<<<<< * if not PyErr_Occurred(): - * if ngood < 1: + * if lngood < 0: */ __pyx_v_lnsample = PyInt_AsLong(__pyx_v_nsample); - /* "mtrand.pyx":3926 + /* "mtrand.pyx":3927 * lnbad = PyInt_AsLong(nbad) * lnsample = PyInt_AsLong(nsample) * if not PyErr_Occurred(): # <<<<<<<<<<<<<< - * if ngood < 1: - * raise ValueError("ngood < 1") + * if lngood < 0: + * raise ValueError("ngood < 0") */ __pyx_t_1 = ((!(PyErr_Occurred() != 0)) != 0); if (__pyx_t_1) { - /* "mtrand.pyx":3927 + /* "mtrand.pyx":3928 * lnsample = PyInt_AsLong(nsample) * if not PyErr_Occurred(): - * if ngood < 1: # <<<<<<<<<<<<<< - * raise ValueError("ngood < 1") - * if nbad < 1: + * if lngood < 0: # <<<<<<<<<<<<<< + * raise ValueError("ngood < 0") + * if lnbad < 0: */ - __pyx_t_2 = PyObject_RichCompare(__pyx_v_ngood, __pyx_int_1, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3927; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3927; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = ((__pyx_v_lngood < 0) != 0); if (__pyx_t_1) { - /* "mtrand.pyx":3928 + /* "mtrand.pyx":3929 * if not PyErr_Occurred(): - * if ngood < 1: - * raise ValueError("ngood < 1") # <<<<<<<<<<<<<< - * if nbad < 1: - * raise ValueError("nbad < 1") + * if lngood < 0: + * raise ValueError("ngood < 0") # <<<<<<<<<<<<<< + * if lnbad < 0: + * raise ValueError("nbad < 0") */ - __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_168), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3928; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_168), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3929; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3928; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3929; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L4; } __pyx_L4:; - /* "mtrand.pyx":3929 - * if ngood < 1: - * raise ValueError("ngood < 1") - * if nbad < 1: # <<<<<<<<<<<<<< - * raise ValueError("nbad < 1") - * if nsample < 1: + /* "mtrand.pyx":3930 + * if lngood < 0: + * raise ValueError("ngood < 0") + * if lnbad < 0: # <<<<<<<<<<<<<< + * raise ValueError("nbad < 0") + * if lnsample < 1: */ - __pyx_t_2 = PyObject_RichCompare(__pyx_v_nbad, __pyx_int_1, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3929; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3929; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = ((__pyx_v_lnbad < 0) != 0); if (__pyx_t_1) { - /* "mtrand.pyx":3930 - * raise ValueError("ngood < 1") - * if nbad < 1: - * raise ValueError("nbad < 1") # <<<<<<<<<<<<<< - * if nsample < 1: + /* "mtrand.pyx":3931 + * raise ValueError("ngood < 0") + * if lnbad < 0: + * raise ValueError("nbad < 0") # <<<<<<<<<<<<<< + * if lnsample < 1: * raise ValueError("nsample < 1") */ - __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_170), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3930; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_170), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3931; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3930; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3931; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L5; } __pyx_L5:; - /* "mtrand.pyx":3931 - * if nbad < 1: - * raise ValueError("nbad < 1") - * if nsample < 1: # <<<<<<<<<<<<<< + /* "mtrand.pyx":3932 + * if lnbad < 0: + * raise ValueError("nbad < 0") + * if lnsample < 1: # <<<<<<<<<<<<<< * raise ValueError("nsample < 1") - * if ngood + nbad < nsample: + * if lngood + lnbad < lnsample: */ - __pyx_t_2 = PyObject_RichCompare(__pyx_v_nsample, __pyx_int_1, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3931; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3931; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = ((__pyx_v_lnsample < 1) != 0); if (__pyx_t_1) { - /* "mtrand.pyx":3932 - * raise ValueError("nbad < 1") - * if nsample < 1: + /* "mtrand.pyx":3933 + * raise ValueError("nbad < 0") + * if lnsample < 1: * raise ValueError("nsample < 1") # <<<<<<<<<<<<<< - * if ngood + nbad < nsample: + * if lngood + lnbad < lnsample: * raise ValueError("ngood + nbad < nsample") */ - __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_172), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3932; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_172), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3933; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3932; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3933; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L6; } __pyx_L6:; - /* "mtrand.pyx":3933 - * if nsample < 1: + /* "mtrand.pyx":3934 + * if lnsample < 1: * raise ValueError("nsample < 1") - * if ngood + nbad < nsample: # <<<<<<<<<<<<<< + * if lngood + lnbad < lnsample: # <<<<<<<<<<<<<< * raise ValueError("ngood + nbad < nsample") * return discnmN_array_sc(self.internal_state, rk_hypergeometric, size, */ - __pyx_t_2 = PyNumber_Add(__pyx_v_ngood, __pyx_v_nbad); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3933; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyObject_RichCompare(__pyx_t_2, __pyx_v_nsample, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3933; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3933; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_1 = (((__pyx_v_lngood + __pyx_v_lnbad) < __pyx_v_lnsample) != 0); if (__pyx_t_1) { - /* "mtrand.pyx":3934 + /* "mtrand.pyx":3935 * raise ValueError("nsample < 1") - * if ngood + nbad < nsample: + * if lngood + lnbad < lnsample: * raise ValueError("ngood + nbad < nsample") # <<<<<<<<<<<<<< * return discnmN_array_sc(self.internal_state, rk_hypergeometric, size, * lngood, lnbad, lnsample) */ - __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_174), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3934; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3934; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_174), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3935; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3935; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L7; } __pyx_L7:; - /* "mtrand.pyx":3935 - * if ngood + nbad < nsample: + /* "mtrand.pyx":3936 + * if lngood + lnbad < lnsample: * raise ValueError("ngood + nbad < nsample") * return discnmN_array_sc(self.internal_state, rk_hypergeometric, size, # <<<<<<<<<<<<<< * lngood, lnbad, lnsample) @@ -18493,24 +18482,24 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_92hypergeometric(struct __pyx_ob */ __Pyx_XDECREF(__pyx_r); - /* "mtrand.pyx":3936 + /* "mtrand.pyx":3937 * raise ValueError("ngood + nbad < nsample") * return discnmN_array_sc(self.internal_state, rk_hypergeometric, size, * lngood, lnbad, lnsample) # <<<<<<<<<<<<<< * - * + * PyErr_Clear() */ - __pyx_t_3 = __pyx_f_6mtrand_discnmN_array_sc(__pyx_v_self->internal_state, rk_hypergeometric, __pyx_v_size, __pyx_v_lngood, __pyx_v_lnbad, __pyx_v_lnsample); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3935; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_2 = __pyx_f_6mtrand_discnmN_array_sc(__pyx_v_self->internal_state, rk_hypergeometric, __pyx_v_size, __pyx_v_lngood, __pyx_v_lnbad, __pyx_v_lnsample); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3936; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; goto __pyx_L0; goto __pyx_L3; } __pyx_L3:; /* "mtrand.pyx":3939 - * + * lngood, lnbad, lnsample) * * PyErr_Clear() # <<<<<<<<<<<<<< * @@ -18525,92 +18514,92 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_92hypergeometric(struct __pyx_ob * onbad = <ndarray>PyArray_FROM_OTF(nbad, NPY_LONG, NPY_ARRAY_ALIGNED) * onsample = <ndarray>PyArray_FROM_OTF(nsample, NPY_LONG, NPY_ARRAY_ALIGNED) */ - __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_ngood, NPY_LONG, NPY_ARRAY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3941; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __pyx_t_3; - __Pyx_INCREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_ongood = ((PyArrayObject *)__pyx_t_2); - __pyx_t_2 = 0; - - /* "mtrand.pyx":3942 - * - * ongood = <ndarray>PyArray_FROM_OTF(ngood, NPY_LONG, NPY_ARRAY_ALIGNED) - * onbad = <ndarray>PyArray_FROM_OTF(nbad, NPY_LONG, NPY_ARRAY_ALIGNED) # <<<<<<<<<<<<<< - * onsample = <ndarray>PyArray_FROM_OTF(nsample, NPY_LONG, NPY_ARRAY_ALIGNED) - * if np.any(np.less(ongood, 1)): - */ - __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_nbad, NPY_LONG, NPY_ARRAY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3942; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_ngood, NPY_LONG, NPY_ARRAY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3941; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_onbad = ((PyArrayObject *)__pyx_t_3); + __pyx_v_ongood = ((PyArrayObject *)__pyx_t_3); __pyx_t_3 = 0; - /* "mtrand.pyx":3943 + /* "mtrand.pyx":3942 + * * ongood = <ndarray>PyArray_FROM_OTF(ngood, NPY_LONG, NPY_ARRAY_ALIGNED) - * onbad = <ndarray>PyArray_FROM_OTF(nbad, NPY_LONG, NPY_ARRAY_ALIGNED) - * onsample = <ndarray>PyArray_FROM_OTF(nsample, NPY_LONG, NPY_ARRAY_ALIGNED) # <<<<<<<<<<<<<< - * if np.any(np.less(ongood, 1)): - * raise ValueError("ngood < 1") + * onbad = <ndarray>PyArray_FROM_OTF(nbad, NPY_LONG, NPY_ARRAY_ALIGNED) # <<<<<<<<<<<<<< + * onsample = <ndarray>PyArray_FROM_OTF(nsample, NPY_LONG, NPY_ARRAY_ALIGNED) + * if np.any(np.less(ongood, 0)): */ - __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_nsample, NPY_LONG, NPY_ARRAY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3943; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_nbad, NPY_LONG, NPY_ARRAY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3942; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_onsample = ((PyArrayObject *)__pyx_t_2); + __pyx_v_onbad = ((PyArrayObject *)__pyx_t_2); __pyx_t_2 = 0; + /* "mtrand.pyx":3943 + * ongood = <ndarray>PyArray_FROM_OTF(ngood, NPY_LONG, NPY_ARRAY_ALIGNED) + * onbad = <ndarray>PyArray_FROM_OTF(nbad, NPY_LONG, NPY_ARRAY_ALIGNED) + * onsample = <ndarray>PyArray_FROM_OTF(nsample, NPY_LONG, NPY_ARRAY_ALIGNED) # <<<<<<<<<<<<<< + * if np.any(np.less(ongood, 0)): + * raise ValueError("ngood < 0") + */ + __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_nsample, NPY_LONG, NPY_ARRAY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3943; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __pyx_t_2; + __Pyx_INCREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_onsample = ((PyArrayObject *)__pyx_t_3); + __pyx_t_3 = 0; + /* "mtrand.pyx":3944 * onbad = <ndarray>PyArray_FROM_OTF(nbad, NPY_LONG, NPY_ARRAY_ALIGNED) * onsample = <ndarray>PyArray_FROM_OTF(nsample, NPY_LONG, NPY_ARRAY_ALIGNED) - * if np.any(np.less(ongood, 1)): # <<<<<<<<<<<<<< - * raise ValueError("ngood < 1") - * if np.any(np.less(onbad, 1)): + * if np.any(np.less(ongood, 0)): # <<<<<<<<<<<<<< + * raise ValueError("ngood < 0") + * if np.any(np.less(onbad, 0)): */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__less); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__less); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(((PyObject *)__pyx_v_ongood)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_ongood)); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_ongood)); __Pyx_GIVEREF(((PyObject *)__pyx_v_ongood)); - __Pyx_INCREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_1) { /* "mtrand.pyx":3945 * onsample = <ndarray>PyArray_FROM_OTF(nsample, NPY_LONG, NPY_ARRAY_ALIGNED) - * if np.any(np.less(ongood, 1)): - * raise ValueError("ngood < 1") # <<<<<<<<<<<<<< - * if np.any(np.less(onbad, 1)): - * raise ValueError("nbad < 1") + * if np.any(np.less(ongood, 0)): + * raise ValueError("ngood < 0") # <<<<<<<<<<<<<< + * if np.any(np.less(onbad, 0)): + * raise ValueError("nbad < 0") */ __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_175), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3945; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); @@ -18622,51 +18611,51 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_92hypergeometric(struct __pyx_ob __pyx_L8:; /* "mtrand.pyx":3946 - * if np.any(np.less(ongood, 1)): - * raise ValueError("ngood < 1") - * if np.any(np.less(onbad, 1)): # <<<<<<<<<<<<<< - * raise ValueError("nbad < 1") + * if np.any(np.less(ongood, 0)): + * raise ValueError("ngood < 0") + * if np.any(np.less(onbad, 0)): # <<<<<<<<<<<<<< + * raise ValueError("nbad < 0") * if np.any(np.less(onsample, 1)): */ __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3946; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3946; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3946; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3946; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__less); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3946; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__less); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3946; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3946; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_INCREF(((PyObject *)__pyx_v_onbad)); PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_onbad)); __Pyx_GIVEREF(((PyObject *)__pyx_v_onbad)); - __Pyx_INCREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3946; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3946; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3946; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3946; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3946; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3946; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_1) { /* "mtrand.pyx":3947 - * raise ValueError("ngood < 1") - * if np.any(np.less(onbad, 1)): - * raise ValueError("nbad < 1") # <<<<<<<<<<<<<< + * raise ValueError("ngood < 0") + * if np.any(np.less(onbad, 0)): + * raise ValueError("nbad < 0") # <<<<<<<<<<<<<< * if np.any(np.less(onsample, 1)): * raise ValueError("nsample < 1") */ @@ -18680,8 +18669,8 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_92hypergeometric(struct __pyx_ob __pyx_L9:; /* "mtrand.pyx":3948 - * if np.any(np.less(onbad, 1)): - * raise ValueError("nbad < 1") + * if np.any(np.less(onbad, 0)): + * raise ValueError("nbad < 0") * if np.any(np.less(onsample, 1)): # <<<<<<<<<<<<<< * raise ValueError("nsample < 1") * if np.any(np.less(np.add(ongood, onbad),onsample)): @@ -18693,8 +18682,8 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_92hypergeometric(struct __pyx_ob __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3948; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__less); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3948; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__less); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3948; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3948; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); @@ -18704,34 +18693,34 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_92hypergeometric(struct __pyx_ob __Pyx_INCREF(__pyx_int_1); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_1); __Pyx_GIVEREF(__pyx_int_1); - __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3948; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3948; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3948; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3948; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3948; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3948; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3948; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_1) { /* "mtrand.pyx":3949 - * raise ValueError("nbad < 1") + * raise ValueError("nbad < 0") * if np.any(np.less(onsample, 1)): * raise ValueError("nsample < 1") # <<<<<<<<<<<<<< * if np.any(np.less(np.add(ongood, onbad),onsample)): * raise ValueError("ngood + nbad < nsample") */ - __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_177), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3949; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_177), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3949; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3949; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L10; } @@ -18744,54 +18733,54 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_92hypergeometric(struct __pyx_ob * raise ValueError("ngood + nbad < nsample") * return discnmN_array(self.internal_state, rk_hypergeometric, size, */ - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__less); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__less); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__add); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__add); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)__pyx_v_ongood)); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_ongood)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_ongood)); __Pyx_GIVEREF(((PyObject *)__pyx_v_ongood)); __Pyx_INCREF(((PyObject *)__pyx_v_onbad)); - PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_onbad)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_onbad)); __Pyx_GIVEREF(((PyObject *)__pyx_v_onbad)); - __pyx_t_6 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_6); __Pyx_GIVEREF(__pyx_t_6); __Pyx_INCREF(((PyObject *)__pyx_v_onsample)); - PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_onsample)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_onsample)); __Pyx_GIVEREF(((PyObject *)__pyx_v_onsample)); __pyx_t_6 = 0; - __pyx_t_6 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_6); __Pyx_GIVEREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (__pyx_t_1) { @@ -22818,65 +22807,65 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GOTREF(__pyx_k_tuple_166); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_166)); - /* "mtrand.pyx":3928 + /* "mtrand.pyx":3929 * if not PyErr_Occurred(): - * if ngood < 1: - * raise ValueError("ngood < 1") # <<<<<<<<<<<<<< - * if nbad < 1: - * raise ValueError("nbad < 1") + * if lngood < 0: + * raise ValueError("ngood < 0") # <<<<<<<<<<<<<< + * if lnbad < 0: + * raise ValueError("nbad < 0") */ - __pyx_k_tuple_168 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_167)); if (unlikely(!__pyx_k_tuple_168)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3928; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_168 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_167)); if (unlikely(!__pyx_k_tuple_168)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3929; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_168); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_168)); - /* "mtrand.pyx":3930 - * raise ValueError("ngood < 1") - * if nbad < 1: - * raise ValueError("nbad < 1") # <<<<<<<<<<<<<< - * if nsample < 1: + /* "mtrand.pyx":3931 + * raise ValueError("ngood < 0") + * if lnbad < 0: + * raise ValueError("nbad < 0") # <<<<<<<<<<<<<< + * if lnsample < 1: * raise ValueError("nsample < 1") */ - __pyx_k_tuple_170 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_169)); if (unlikely(!__pyx_k_tuple_170)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3930; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_170 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_169)); if (unlikely(!__pyx_k_tuple_170)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3931; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_170); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_170)); - /* "mtrand.pyx":3932 - * raise ValueError("nbad < 1") - * if nsample < 1: + /* "mtrand.pyx":3933 + * raise ValueError("nbad < 0") + * if lnsample < 1: * raise ValueError("nsample < 1") # <<<<<<<<<<<<<< - * if ngood + nbad < nsample: + * if lngood + lnbad < lnsample: * raise ValueError("ngood + nbad < nsample") */ - __pyx_k_tuple_172 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_171)); if (unlikely(!__pyx_k_tuple_172)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3932; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_172 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_171)); if (unlikely(!__pyx_k_tuple_172)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3933; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_172); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_172)); - /* "mtrand.pyx":3934 + /* "mtrand.pyx":3935 * raise ValueError("nsample < 1") - * if ngood + nbad < nsample: + * if lngood + lnbad < lnsample: * raise ValueError("ngood + nbad < nsample") # <<<<<<<<<<<<<< * return discnmN_array_sc(self.internal_state, rk_hypergeometric, size, * lngood, lnbad, lnsample) */ - __pyx_k_tuple_174 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_173)); if (unlikely(!__pyx_k_tuple_174)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3934; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_174 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_173)); if (unlikely(!__pyx_k_tuple_174)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3935; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_174); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_174)); /* "mtrand.pyx":3945 * onsample = <ndarray>PyArray_FROM_OTF(nsample, NPY_LONG, NPY_ARRAY_ALIGNED) - * if np.any(np.less(ongood, 1)): - * raise ValueError("ngood < 1") # <<<<<<<<<<<<<< - * if np.any(np.less(onbad, 1)): - * raise ValueError("nbad < 1") + * if np.any(np.less(ongood, 0)): + * raise ValueError("ngood < 0") # <<<<<<<<<<<<<< + * if np.any(np.less(onbad, 0)): + * raise ValueError("nbad < 0") */ __pyx_k_tuple_175 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_167)); if (unlikely(!__pyx_k_tuple_175)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3945; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_175); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_175)); /* "mtrand.pyx":3947 - * raise ValueError("ngood < 1") - * if np.any(np.less(onbad, 1)): - * raise ValueError("nbad < 1") # <<<<<<<<<<<<<< + * raise ValueError("ngood < 0") + * if np.any(np.less(onbad, 0)): + * raise ValueError("nbad < 0") # <<<<<<<<<<<<<< * if np.any(np.less(onsample, 1)): * raise ValueError("nsample < 1") */ @@ -22885,7 +22874,7 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_176)); /* "mtrand.pyx":3949 - * raise ValueError("nbad < 1") + * raise ValueError("nbad < 0") * if np.any(np.less(onsample, 1)): * raise ValueError("nsample < 1") # <<<<<<<<<<<<<< * if np.any(np.less(np.add(ongood, onbad),onsample)): @@ -23132,13 +23121,13 @@ PyMODINIT_FUNC PyInit_mtrand(void) /*--- Variable export code ---*/ /*--- Function export code ---*/ /*--- Type init code ---*/ - __pyx_ptype_6mtrand_ndarray = __Pyx_ImportType("numpy", "ndarray", sizeof(PyArrayObject), 0); if (unlikely(!__pyx_ptype_6mtrand_ndarray)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_6mtrand_broadcast = __Pyx_ImportType("numpy", "broadcast", sizeof(PyArrayMultiIterObject), 0); if (unlikely(!__pyx_ptype_6mtrand_broadcast)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (PyType_Ready(&__pyx_type_6mtrand_RandomState) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "RandomState", (PyObject *)&__pyx_type_6mtrand_RandomState) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_6mtrand_RandomState = &__pyx_type_6mtrand_RandomState; __pyx_ptype_6mtrand_flatiter = __Pyx_ImportType("numpy", "flatiter", sizeof(PyArrayIterObject), 0); if (unlikely(!__pyx_ptype_6mtrand_flatiter)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_6mtrand_ndarray = __Pyx_ImportType("numpy", "ndarray", sizeof(PyArrayObject), 0); if (unlikely(!__pyx_ptype_6mtrand_ndarray)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_6mtrand_dtype = __Pyx_ImportType("numpy", "dtype", sizeof(PyArray_Descr), 0); if (unlikely(!__pyx_ptype_6mtrand_dtype)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_6mtrand_broadcast = __Pyx_ImportType("numpy", "broadcast", sizeof(PyArrayMultiIterObject), 0); if (unlikely(!__pyx_ptype_6mtrand_broadcast)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /*--- Type import code ---*/ /*--- Variable import code ---*/ /*--- Function import code ---*/ diff --git a/numpy/random/mtrand/mtrand.pyx b/numpy/random/mtrand/mtrand.pyx index 6e9028012..72e9a47cf 100644 --- a/numpy/random/mtrand/mtrand.pyx +++ b/numpy/random/mtrand/mtrand.pyx @@ -3846,20 +3846,21 @@ cdef class RandomState: Parameters ---------- - ngood : float (but truncated to an integer) - parameter, > 0. - nbad : float - parameter, >= 0. - nsample : float - parameter, > 0 and <= ngood+nbad - size : {tuple, int} + ngood : int or array_like + Number of ways to make a good selection. Must be nonnegative. + nbad : int or array_like + Number of ways to make a bad selection. Must be nonnegative. + nsample : int or array_like + Number of items sampled. Must be at least 1 and at most + ``ngood + nbad``. + size : int or tuple of int Output shape. If the given shape is, e.g., ``(m, n, k)``, then ``m * n * k`` samples are drawn. Returns ------- - samples : {ndarray, scalar} - where the values are all integers in [0, n]. + samples : ndarray or scalar + The values are all integers in [0, n]. See Also -------- @@ -3924,27 +3925,26 @@ cdef class RandomState: lnbad = PyInt_AsLong(nbad) lnsample = PyInt_AsLong(nsample) if not PyErr_Occurred(): - if ngood < 1: - raise ValueError("ngood < 1") - if nbad < 1: - raise ValueError("nbad < 1") - if nsample < 1: + if lngood < 0: + raise ValueError("ngood < 0") + if lnbad < 0: + raise ValueError("nbad < 0") + if lnsample < 1: raise ValueError("nsample < 1") - if ngood + nbad < nsample: + if lngood + lnbad < lnsample: raise ValueError("ngood + nbad < nsample") return discnmN_array_sc(self.internal_state, rk_hypergeometric, size, lngood, lnbad, lnsample) - PyErr_Clear() ongood = <ndarray>PyArray_FROM_OTF(ngood, NPY_LONG, NPY_ARRAY_ALIGNED) onbad = <ndarray>PyArray_FROM_OTF(nbad, NPY_LONG, NPY_ARRAY_ALIGNED) onsample = <ndarray>PyArray_FROM_OTF(nsample, NPY_LONG, NPY_ARRAY_ALIGNED) - if np.any(np.less(ongood, 1)): - raise ValueError("ngood < 1") - if np.any(np.less(onbad, 1)): - raise ValueError("nbad < 1") + if np.any(np.less(ongood, 0)): + raise ValueError("ngood < 0") + if np.any(np.less(onbad, 0)): + raise ValueError("nbad < 0") if np.any(np.less(onsample, 1)): raise ValueError("nsample < 1") if np.any(np.less(np.add(ongood, onbad),onsample)): diff --git a/numpy/random/tests/test_random.py b/numpy/random/tests/test_random.py index c9ced3569..f49592f7d 100644 --- a/numpy/random/tests/test_random.py +++ b/numpy/random/tests/test_random.py @@ -303,6 +303,24 @@ class TestRandomDist(TestCase): [ 9, 9]]) np.testing.assert_array_equal(actual, desired) + # Test nbad = 0 + actual = np.random.hypergeometric(5, 0, 3, size=4) + desired = np.array([3, 3, 3, 3]) + np.testing.assert_array_equal(actual, desired) + + actual = np.random.hypergeometric(15, 0, 12, size=4) + desired = np.array([12, 12, 12, 12]) + np.testing.assert_array_equal(actual, desired) + + # Test ngood = 0 + actual = np.random.hypergeometric(0, 5, 3, size=4) + desired = np.array([0, 0, 0, 0]) + np.testing.assert_array_equal(actual, desired) + + actual = np.random.hypergeometric(0, 15, 12, size=4) + desired = np.array([0, 0, 0, 0]) + np.testing.assert_array_equal(actual, desired) + def test_laplace(self): np.random.seed(self.seed) actual = np.random.laplace(loc=.123456789, scale=2.0, size=(3, 2)) |