summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPearu Peterson <pearu.peterson@gmail.com>2011-03-11 09:40:33 +0200
committerPearu Peterson <pearu.peterson@gmail.com>2011-03-11 09:40:33 +0200
commit87e0f5576f80cc3314ae368edae3461ec5c1b188 (patch)
tree89178833f79bcc4e98a94a8f9691a665b5e47f88
parent81fbb517544bdae0af202de2be7f4af34e29e509 (diff)
parent7bb54efde16bc81ee4eedd77828edc54c12dec75 (diff)
downloadnumpy-87e0f5576f80cc3314ae368edae3461ec5c1b188.tar.gz
Merge remote branch 'upstream/master' into f2py-assumed-shape
* upstream/master: (310 commits) REL: add 1.6.0 release notes. DEP: remove deprecated np.lib.ufunclike.log2 function. DOC: fix typo in test guidelines. DEP: remove deprecated items from ma/core.py DEP: remove deprecated get_numpy_include. DEP: remove unique1d, setmember1d and intersect1d_nu. DEP: remove deprecated names in fftpack. DEP: remove deprecated methods sync() and close() from memmap. DEP: Update deprecation messages in genloadtxt with a version number. BLD: update C API version again after Mark's renaming of functions. DOC: Replace 'deprecated' with 'superceded' in a few places, fix a typo. STY: Remove a micro-optimization to make code more clear DOC: Add some missing documentation, hyper-link the iterator documentation API: Remove PyArray_FillWithZero from public API API: Rename the iterator function pointer types to be more consistent with NumPy convention STY: Work around lack of variadic macros in debug tracing API: Change iterator API parameters ndim and niter from npy_intp to int ENH: add Intel 64-bit C compiler. Closes #960. TST: fix two divide-by-zero test warnings. BUG: Broadcast shape was backwards in error message (Ticket #1762) ...
-rw-r--r--.gitignore5
-rw-r--r--INSTALL.txt4
-rw-r--r--THANKS.txt2
-rw-r--r--doc/TESTS.rst.txt2
-rw-r--r--doc/neps/deferred-ufunc-evaluation.rst308
-rw-r--r--doc/neps/new-iterator-ufunc.rst1981
-rw-r--r--doc/release/1.6.0-notes.rst94
-rw-r--r--doc/release/2.0.0-notes.rst7
-rw-r--r--doc/source/reference/arrays.ndarray.rst1
-rw-r--r--doc/source/reference/c-api.array.rst266
-rw-r--r--doc/source/reference/c-api.iterator.rst1144
-rw-r--r--doc/source/reference/c-api.rst1
-rw-r--r--doc/source/reference/c-api.ufunc.rst20
-rw-r--r--doc/source/reference/distutils.rst6
-rw-r--r--doc/source/reference/maskedarray.generic.rst4
-rw-r--r--doc/source/reference/routines.dtype.rst3
-rw-r--r--doc/source/reference/routines.indexing.rst1
-rw-r--r--doc/source/reference/routines.linalg.rst1
-rw-r--r--doc/source/reference/routines.sort.rst11
-rw-r--r--doc/source/user/install.rst12
-rwxr-xr-xdoc/summarize.py21
-rwxr-xr-xdoc/swig/test/setup.py7
-rw-r--r--numpy/add_newdocs.py758
-rw-r--r--numpy/core/SConscript12
-rw-r--r--numpy/core/blasdot/_dotblas.c56
-rw-r--r--numpy/core/code_generators/cversions.txt3
-rw-r--r--numpy/core/code_generators/genapi.py5
-rw-r--r--numpy/core/code_generators/numpy_api.py505
-rw-r--r--numpy/core/fromnumeric.py46
-rw-r--r--numpy/core/getlimits.py44
-rw-r--r--numpy/core/include/numpy/ndarraytypes.h152
-rw-r--r--numpy/core/include/numpy/npy_common.h6
-rw-r--r--numpy/core/include/numpy/npy_math.h12
-rw-r--r--numpy/core/include/numpy/ufuncobject.h274
-rw-r--r--numpy/core/memmap.py10
-rw-r--r--numpy/core/numeric.py105
-rw-r--r--numpy/core/numerictypes.py77
-rw-r--r--numpy/core/setup.py15
-rw-r--r--numpy/core/setup_common.py4
-rw-r--r--numpy/core/shape_base.py14
-rw-r--r--numpy/core/src/multiarray/arrayobject.c151
-rw-r--r--numpy/core/src/multiarray/arraytypes.c.src247
-rw-r--r--numpy/core/src/multiarray/buffer.c2
-rw-r--r--numpy/core/src/multiarray/calculation.c3
-rw-r--r--numpy/core/src/multiarray/common.c87
-rw-r--r--numpy/core/src/multiarray/common.h3
-rw-r--r--numpy/core/src/multiarray/conversion_utils.c25
-rw-r--r--numpy/core/src/multiarray/convert.c145
-rw-r--r--numpy/core/src/multiarray/convert.h3
-rw-r--r--numpy/core/src/multiarray/convert_datatype.c1431
-rw-r--r--numpy/core/src/multiarray/convert_datatype.h12
-rw-r--r--numpy/core/src/multiarray/ctors.c2392
-rw-r--r--numpy/core/src/multiarray/ctors.h9
-rw-r--r--numpy/core/src/multiarray/datetime.c4
-rw-r--r--numpy/core/src/multiarray/descriptor.c31
-rw-r--r--numpy/core/src/multiarray/dtype_transfer.c2995
-rw-r--r--numpy/core/src/multiarray/einsum.c.src3115
-rw-r--r--numpy/core/src/multiarray/flagsobject.c12
-rw-r--r--numpy/core/src/multiarray/getset.c21
-rw-r--r--numpy/core/src/multiarray/item_selection.c267
-rw-r--r--numpy/core/src/multiarray/iterators.c77
-rw-r--r--numpy/core/src/multiarray/lowlevel_strided_loops.c.src1184
-rw-r--r--numpy/core/src/multiarray/mapping.c23
-rw-r--r--numpy/core/src/multiarray/methods.c279
-rw-r--r--numpy/core/src/multiarray/multiarraymodule.c887
-rw-r--r--numpy/core/src/multiarray/multiarraymodule_onefile.c6
-rw-r--r--numpy/core/src/multiarray/new_iterator.c.src6294
-rw-r--r--numpy/core/src/multiarray/new_iterator_pywrap.c2471
-rw-r--r--numpy/core/src/multiarray/new_iterator_pywrap.h8
-rw-r--r--numpy/core/src/multiarray/number.c45
-rw-r--r--numpy/core/src/multiarray/numpyos.c2
-rw-r--r--numpy/core/src/multiarray/refcount.c1
-rw-r--r--numpy/core/src/multiarray/scalarapi.c22
-rw-r--r--numpy/core/src/multiarray/scalartypes.c.src144
-rw-r--r--numpy/core/src/multiarray/scalartypes.h12
-rw-r--r--numpy/core/src/multiarray/sequence.c1
-rw-r--r--numpy/core/src/multiarray/shape.c161
-rw-r--r--numpy/core/src/multiarray/shape.h14
-rw-r--r--numpy/core/src/multiarray/testcalcs.py11
-rw-r--r--numpy/core/src/multiarray/usertypes.c7
-rw-r--r--numpy/core/src/npymath/halffloat.c66
-rw-r--r--numpy/core/src/npymath/ieee754.c.src124
-rw-r--r--numpy/core/src/npymath/npy_math_complex.c.src6
-rw-r--r--numpy/core/src/private/lowlevel_strided_loops.h397
-rw-r--r--numpy/core/src/scalarmathmodule.c.src38
-rw-r--r--numpy/core/src/umath/loops.c.src103
-rw-r--r--numpy/core/src/umath/loops.h3
-rw-r--r--numpy/core/src/umath/loops.h.src2
-rw-r--r--numpy/core/src/umath/ufunc_object.c5022
-rw-r--r--numpy/core/src/umath/umath_tests.c.src2
-rw-r--r--numpy/core/tests/test_blasdot.py65
-rw-r--r--numpy/core/tests/test_datetime.py6
-rw-r--r--numpy/core/tests/test_einsum.py470
-rw-r--r--numpy/core/tests/test_errstate.py4
-rw-r--r--numpy/core/tests/test_half.py45
-rw-r--r--numpy/core/tests/test_memmap.py8
-rw-r--r--numpy/core/tests/test_multiarray.py239
-rw-r--r--numpy/core/tests/test_new_iterator.py2206
-rw-r--r--numpy/core/tests/test_numeric.py276
-rw-r--r--numpy/core/tests/test_numerictypes.py66
-rw-r--r--numpy/core/tests/test_regression.py271
-rw-r--r--numpy/core/tests/test_scalarmath.py24
-rw-r--r--numpy/core/tests/test_ufunc.py37
-rw-r--r--numpy/core/tests/test_umath.py84
-rw-r--r--numpy/core/tests/test_umath_complex.py8
-rw-r--r--numpy/core/tests/test_unicode.py50
-rw-r--r--numpy/distutils/ccompiler.py17
-rw-r--r--numpy/distutils/fcompiler/__init__.py5
-rw-r--r--numpy/distutils/fcompiler/intel.py8
-rw-r--r--numpy/distutils/intelccompiler.py20
-rw-r--r--numpy/distutils/npy_pkg_config.py9
-rw-r--r--numpy/distutils/system_info.py10
-rw-r--r--numpy/distutils/tests/test_fcompiler_intel.py34
-rw-r--r--numpy/doc/structured_arrays.py57
-rwxr-xr-xnumpy/f2py/crackfortran.py30
-rw-r--r--numpy/fft/fftpack.py12
-rw-r--r--numpy/lib/arraysetops.py78
-rw-r--r--numpy/lib/arrayterator.py29
-rw-r--r--numpy/lib/benchmarks/bench_arraysetops.py65
-rw-r--r--numpy/lib/function_base.py46
-rw-r--r--numpy/lib/index_tricks.py66
-rw-r--r--numpy/lib/npyio.py94
-rw-r--r--numpy/lib/polynomial.py22
-rw-r--r--numpy/lib/recfunctions.py2
-rw-r--r--numpy/lib/src/_compiled_base.c533
-rw-r--r--numpy/lib/tests/test__datasource.py48
-rw-r--r--numpy/lib/tests/test_arraysetops.py45
-rw-r--r--numpy/lib/tests/test_format.py2
-rw-r--r--numpy/lib/tests/test_function_base.py96
-rw-r--r--numpy/lib/tests/test_index_tricks.py67
-rw-r--r--numpy/lib/tests/test_io.py12
-rw-r--r--numpy/lib/tests/test_polynomial.py19
-rw-r--r--numpy/lib/tests/test_recfunctions.py23
-rw-r--r--numpy/lib/tests/test_regression.py28
-rw-r--r--numpy/lib/tests/test_type_check.py9
-rw-r--r--numpy/lib/tests/test_ufunclike.py13
-rw-r--r--numpy/lib/ufunclike.py42
-rw-r--r--numpy/lib/utils.py3
-rw-r--r--numpy/linalg/linalg.py20
-rw-r--r--numpy/ma/core.py69
-rw-r--r--numpy/ma/extras.py10
-rw-r--r--numpy/ma/tests/test_core.py142
-rw-r--r--numpy/ma/tests/test_subclassing.py8
-rw-r--r--numpy/ma/testutils.py3
-rw-r--r--numpy/matrixlib/tests/test_defmatrix.py2
-rw-r--r--numpy/polynomial/chebyshev.py19
-rw-r--r--numpy/polynomial/legendre.py25
-rw-r--r--numpy/polynomial/polynomial.py10
-rw-r--r--numpy/polynomial/polytemplate.py52
-rw-r--r--numpy/random/mtrand/mtrand.c12487
-rw-r--r--numpy/random/mtrand/mtrand.pyx215
-rw-r--r--numpy/random/tests/test_random.py422
-rw-r--r--numpy/random/tests/test_regression.py57
-rwxr-xr-xnumpy/testing/print_coercion_tables.py19
-rw-r--r--numpy/testing/tests/test_utils.py2
-rw-r--r--numpy/testing/utils.py189
-rw-r--r--numpy/tests/test_ctypeslib.py4
-rw-r--r--pavement.py59
-rw-r--r--release.sh40
-rwxr-xr-xsetup.py33
-rw-r--r--site.cfg.example22
161 files changed, 41323 insertions, 12355 deletions
diff --git a/.gitignore b/.gitignore
index 23800b189..41a7eb369 100644
--- a/.gitignore
+++ b/.gitignore
@@ -63,6 +63,11 @@ doc/cdoc/build
*.sql
*.sqlite
+# Patches #
+###########
+*.patch
+*.diff
+
# OS generated files #
######################
.gdb_history
diff --git a/INSTALL.txt b/INSTALL.txt
index b16af0ef7..d75d4d9d0 100644
--- a/INSTALL.txt
+++ b/INSTALL.txt
@@ -27,12 +27,12 @@ Building NumPy requires the following software installed:
Python must also be compiled with the zlib module enabled.
-2) nose__ (pptional) 0.10.3 or later
+2) nose__ (optional) 0.10.3 or later
This is required for testing numpy, but not for using it.
Python__ http://www.python.org
-nose__ http://somethingaboutorange.com/mrl/projects/nose/
+nose__ http://somethingaboutorange.com/mrl/projects/nose/
Fortran ABI mismatch
====================
diff --git a/THANKS.txt b/THANKS.txt
index 5a29c0e3b..396f4fba1 100644
--- a/THANKS.txt
+++ b/THANKS.txt
@@ -47,6 +47,8 @@ Roberto de Almeida for the buffered array iterator.
Alan McIntyre for updating the NumPy test framework to use nose, improve
the test coverage, and enhancing the test system documentation.
Joe Harrington for administering the 2008 Documentation Sprint.
+Mark Wiebe for the new NumPy iterator, the float16 data type, improved
+ low-level data type operations, and other NumPy core improvements.
NumPy is based on the Numeric (Jim Hugunin, Paul Dubois, Konrad
Hinsen, and David Ascher) and NumArray (Perry Greenfield, J Todd
diff --git a/doc/TESTS.rst.txt b/doc/TESTS.rst.txt
index 936f00a1d..4f2f9e79a 100644
--- a/doc/TESTS.rst.txt
+++ b/doc/TESTS.rst.txt
@@ -46,7 +46,7 @@ can be turned on (recommended after installation and before upgrading) by
starting the interpreter with the -Wd switch, or by::
>>> import warnings
- >>> wwarnings.simplefilter('always', DeprecationWarning)
+ >>> warnings.simplefilter('always', DeprecationWarning)
The test method may take two or more arguments; the first is a string
label specifying what should be tested and the second is an integer
diff --git a/doc/neps/deferred-ufunc-evaluation.rst b/doc/neps/deferred-ufunc-evaluation.rst
new file mode 100644
index 000000000..95633cab5
--- /dev/null
+++ b/doc/neps/deferred-ufunc-evaluation.rst
@@ -0,0 +1,308 @@
+:Title: Deferred UFunc Evaluation
+:Author: Mark Wiebe <mwwiebe@gmail.com>
+:Content-Type: text/x-rst
+:Created: 30-Nov-2010
+
+********
+Abstract
+********
+
+This NEP describes a proposal to add deferred evaluation to NumPy's
+UFuncs. This will allow Python expressions like
+"a[:] = b + c + d + e" to be evaluated in a single pass through all
+the variables at once, with no temporary arrays. The resulting
+performance will likely be comparable to the *numexpr* library,
+but with a more natural syntax.
+
+This idea has some interaction with UFunc error handling and
+the UPDATEIFCOPY flag, affecting the design and implementation,
+but the result allows for the usage of deferred evaluation
+with minimal effort from the Python user's perspective.
+
+**********
+Motivation
+**********
+
+NumPy's style of UFunc execution causes suboptimal performance for
+large expressions, because multiple temporaries are allocated and
+the inputs are swept through in multiple passes. The *numexpr* library
+can outperform NumPy for such large expressions, by doing the execution
+in small cache-friendly blocks, and evaluating the whole expression
+per element. This results in one sweep through each input, which
+is significantly better for the cache.
+
+For an idea of how to get this kind of behavior in NumPy without
+changing the Python code, consider the C++ technique of
+expression templates. These can be used to quite arbitrarily
+rearrange expressions using
+vectors or other data structures, example,::
+
+ A = B + C + D;
+
+can be transformed into something equivalent to::
+
+ for(i = 0; i < A.size; ++i) {
+ A[i] = B[i] + C[i] + D[i];
+ }
+
+This is done by returning a proxy object that knows how to calculate
+the result instead of returning the actual object. With modern C++
+optimizing compilers, the resulting machine code is often the same
+as hand-written loops. For an example of this, see the
+`Blitz++ Library <http://www.oonumerics.org/blitz/docs/blitz_3.html>`_.
+A more recently created library for helping write expression templates
+is `Boost Proto <http://beta.boost.org/doc/libs/1_44_0/doc/html/proto.html>`_.
+
+By using the same idea of returning a proxy object in Python, we
+can accomplish the same thing dynamically. The return object is
+an ndarray without its buffer allocated, and with enough knowledge
+to calculate itself when needed. When a "deferred array" is
+finally evaluated, we can use the expression tree made up of
+all the operand deferred arrays, effectively creating a single new
+UFunc to evaluate on the fly.
+
+
+*******************
+Example Python Code
+*******************
+
+Here's how it might be used in NumPy.::
+
+ # a, b, c are large ndarrays
+
+ with np.deferredstate(True):
+
+ d = a + b + c
+ # Now d is a 'deferred array,' a, b, and c are marked READONLY
+ # similar to the existing UPDATEIFCOPY mechanism.
+
+ print d
+ # Since the value of d was required, it is evaluated so d becomes
+ # a regular ndarray and gets printed.
+
+ d[:] = a*b*c
+ # Here, the automatically combined "ufunc" that computes
+ # a*b*c effectively gets an out= parameter, so no temporary
+ # arrays are needed whatsoever.
+
+ e = a+b+c*d
+ # Now e is a 'deferred array,' a, b, c, and d are marked READONLY
+
+ d[:] = a
+ # d was marked readonly, but the assignment could see that
+ # this was due to it being a deferred expression operand.
+ # This triggered the deferred evaluation so it could assign
+ # the value of a to d.
+
+There may be some surprising behavior, though.::
+
+ with np.deferredstate(True):
+
+ d = a + b + c
+ # d is deferred
+
+ e[:] = d
+ f[:] = d
+ g[:] = d
+ # d is still deferred, and its deferred expression
+ # was evaluated three times, once for each assignment.
+ # This could be detected, with d being converted to
+ # a regular ndarray the second time it is evaluated.
+
+I believe the usage that should be recommended in the documentation
+is to leave the deferred state at its default, except when
+evaluating a large expression that can benefit from it.::
+
+ # calculations
+
+ with np.deferredstate(True):
+ x = <big expression>
+
+ # more calculations
+
+This will avoid surprises which would be cause by always keeping
+deferred usage True, like floating point warnings or exceptions
+at surprising times when deferred expression are used later.
+User questions like "Why does my print statement throw a
+divide by zero error?" can hopefully be avoided by recommending
+this approach.
+
+********************************
+Proposed Deferred Evaluation API
+********************************
+
+For deferred evaluation to work, the C API needs to be aware of its
+existence, and be able to trigger evaluation when necessary. The
+ndarray would gain two new flag.
+
+ ``NPY_ISDEFERRED``
+
+ Indicates the expression evaluation for this ndarray instance
+ has been deferred.
+
+ ``NPY_DEFERRED_WASWRITEABLE``
+
+ Can only be set when ``PyArray_GetDeferredUsageCount(arr) > 0``.
+ It indicates that when ``arr`` was first used in a deferred
+ expression, it was a writeable array. If this flag is set,
+ calling ``PyArray_CalculateAllDeferred()`` will make ``arr``
+ writeable again.
+
+.. note:: QUESTION
+
+ Should NPY_DEFERRED and NPY_DEFERRED_WASWRITEABLE be visible
+ to Python, or should accessing the flags from python trigger
+ PyArray_CalculateAllDeferred if necessary?
+
+The API would be expanded with a number of functions.
+
+``int PyArray_CalculateAllDeferred()``
+
+ This function forces all currently deferred calculations to occur.
+
+ For example, if the error state is set to ignore all, and
+ np.seterr({all='raise'}), this would change what happens
+ to already deferred expressions. Thus, all the existing
+ deferred arrays should be evaluated before changing the
+ error state.
+
+``int PyArray_CalculateDeferred(PyArrayObject* arr)``
+
+ If 'arr' is a deferred array, allocates memory for it and
+ evaluates the deferred expression. If 'arr' is not a deferred
+ array, simply returns success. Returns NPY_SUCCESS or NPY_FAILURE.
+
+``int PyArray_CalculateDeferredAssignment(PyArrayObject* arr, PyArrayObject* out)``
+
+ If 'arr' is a deferred array, evaluates the deferred expression
+ into 'out', and 'arr' remains a deferred array. If 'arr' is not
+ a deferred array, copies its value into out. Returns NPY_SUCCESS
+ or NPY_FAILURE.
+
+``int PyArray_GetDeferredUsageCount(PyArrayObject* arr)``
+
+ Returns a count of how many deferred expressions use this array
+ as an operand.
+
+The Python API would be expanded as follows.
+
+ ``numpy.setdeferred(state)``
+
+ Enables or disables deferred evaluation. True means to always
+ use deferred evaluation. False means to never use deferred
+ evaluation. None means to use deferred evaluation if the error
+ handling state is set to ignore everything. At NumPy initialization,
+ the deferred state is None.
+
+ Returns the previous deferred state.
+
+``numpy.getdeferred()``
+
+ Returns the current deferred state.
+
+``numpy.deferredstate(state)``
+
+ A context manager for deferred state handling, similar to
+ ``numpy.errstate``.
+
+
+Error Handling
+==============
+
+Error handling is a thorny issue for deferred evaluation. If the
+NumPy error state is {all='ignore'}, it might be reasonable to
+introduce deferred evaluation as the default, however if a UFunc
+can raise an error, it would be very strange for the later 'print'
+statement to throw the exception instead of the actual operation which
+caused the error.
+
+What may be a good approach is to by default enable deferred evaluation
+only when the error state is set to ignore all, but allow user control with
+'setdeferred' and 'getdeferred' functions. True would mean always
+use deferred evaluation, False would mean never use it, and None would
+mean use it only when safe (i.e. the error state is set to ignore all).
+
+Interaction With UPDATEIFCOPY
+=============================
+
+The ``NPY_UPDATEIFCOPY`` documentation states:
+
+ The data area represents a (well-behaved) copy whose information
+ should be transferred back to the original when this array is deleted.
+
+ This is a special flag that is set if this array represents a copy
+ made because a user required certain flags in PyArray_FromAny and a
+ copy had to be made of some other array (and the user asked for this
+ flag to be set in such a situation). The base attribute then points
+ to the “misbehaved” array (which is set read_only). When the array
+ with this flag set is deallocated, it will copy its contents back to
+ the “misbehaved” array (casting if necessary) and will reset the
+ “misbehaved” array to NPY_WRITEABLE. If the “misbehaved” array was
+ not NPY_WRITEABLE to begin with then PyArray_FromAny would have
+ returned an error because NPY_UPDATEIFCOPY would not have been possible.
+
+The current implementation of UPDATEIFCOPY assumes that it is the only
+mechanism mucking with the writeable flag in this manner. These mechanisms
+must be aware of each other to work correctly. Here's an example of how
+they might go wrong:
+
+1. Make a temporary copy of 'arr' with UPDATEIFCOPY ('arr' becomes read only)
+2. Use 'arr' in a deferred expression (deferred usage count becomes one,
+ NPY_DEFERRED_WASWRITEABLE is **not** set, since 'arr' is read only)
+3. Destroy the temporary copy, causing 'arr' to become writeable
+4. Writing to 'arr' destroys the value of the deferred expression
+
+To deal with this issue, we make these two states mutually exclusive.
+
+* Usage of UPDATEIFCOPY checks the ``NPY_DEFERRED_WASWRITEABLE`` flag,
+ and if it's set, calls ``PyArray_CalculateAllDeferred`` to flush
+ all deferred calculation before proceeding.
+* The ndarray gets a new flag ``NPY_UPDATEIFCOPY_TARGET`` indicating
+ the array will be updated and made writeable at some point in the
+ future. If the deferred evaluation mechanism sees this flag in
+ any operand, it triggers immediate evaluation.
+
+Other Implementation Details
+============================
+
+When a deferred array is created, it gets references to all the
+operands of the UFunc, along with the UFunc itself. The
+'DeferredUsageCount' is incremented for each operand, and later
+gets decremented when the deferred expression is calculated or
+the deferred array is destroyed.
+
+A global list of weak references to all the deferred arrays
+is tracked, in order of creation. When ``PyArray_CalculateAllDeferred``
+gets called, the newest deferred array is calculated first.
+This may release references to other deferred arrays contained
+in the deferred expression tree, which then
+never have to be calculated.
+
+Further Optimization
+====================
+
+Instead of conservatively disabling deferred evaluation when any
+errors are not set to 'ignore', each UFunc could give a set
+of possible errors it generates. Then, if all those errors
+are set to 'ignore', deferred evaluation could be used even
+if other errors are not set to ignore.
+
+Once the expression tree is explicitly stored, it is possible to
+do transformations on it. For example add(add(a,b),c) could
+be transformed into add3(a,b,c), or add(multiply(a,b),c) could
+become fma(a,b,c) using the CPU fused multiply-add instruction
+where available.
+
+While I've framed deferred evaluation as just for UFuncs, it could
+be extended to other functions, such as dot(). For example, chained
+matrix multiplications could be reordered to minimize the size
+of intermediates, or peep-hole style optimizer passes could search
+for patterns that match optimized BLAS/other high performance
+library calls.
+
+For operations on really large arrays, integrating a JIT like LLVM into
+this system might be a big benefit. The UFuncs and other operations
+would provide bitcode, which could be inlined together and optimized
+by the LLVM optimizers, then executed. In fact, the iterator itself
+could also be represented in bitcode, allowing LLVM to consider
+the entire iteration while doing its optimization.
diff --git a/doc/neps/new-iterator-ufunc.rst b/doc/neps/new-iterator-ufunc.rst
new file mode 100644
index 000000000..76b21d644
--- /dev/null
+++ b/doc/neps/new-iterator-ufunc.rst
@@ -0,0 +1,1981 @@
+:Title: Optimizing Iterator/UFunc Performance
+:Author: Mark Wiebe <mwwiebe@gmail.com>
+:Content-Type: text/x-rst
+:Created: 25-Nov-2010
+
+*****************
+Table of Contents
+*****************
+
+.. contents::
+
+********
+Abstract
+********
+
+This NEP proposes to replace the NumPy iterator and multi-iterator
+with a single new iterator, designed to be more flexible and allow for
+more cache-friendly data access. The new iterator also subsumes much
+of the core ufunc functionality, making it easy to get the current
+ufunc benefits in contexts which don't precisely fit the ufunc mold.
+Key benefits include:
+
+* automatic reordering to find a cache-friendly access pattern
+* standard and customizable broadcasting
+* automatic type/byte-order/alignment conversions
+* optional buffering to minimize conversion memory usage
+* optional output arrays, with automatic allocation when unsupplied
+* automatic output or common type selection
+
+A large fraction of this iterator design has already been implemented with
+promising results. Construction overhead is slightly greater (a.flat:
+0.5 us, newiter(a): 1.4 us and broadcast(a,b): 1.4 us, newiter([a,b]):
+2.2 us), but, as shown in an example, it is already possible to improve
+on the performance of the built-in NumPy mechanisms in pure Python code
+together with the iterator. One example rewrites np.add, getting a
+four times improvement with some Fortran-contiguous arrays, and
+another improves image compositing code from 1.4s to 180ms.
+
+The implementation attempts to take into account
+the design decisions made in the NumPy 2.0 refactor, to make its future
+integration into libndarray relatively simple.
+
+**********
+Motivation
+**********
+
+NumPy defaults to returning C-contiguous arrays from UFuncs. This can
+result in extremely poor memory access patterns when dealing with data
+that is structured differently. A simple timing example illustrates
+this with a more than eight times performance hit from adding
+Fortran-contiguous arrays together. All timings are done using Numpy
+2.0dev (Nov 22, 2010) on an Athlon 64 X2 4200+, with a 64-bit OS.::
+
+ In [1]: import numpy as np
+ In [2]: a = np.arange(1000000,dtype=np.float32).reshape(10,10,10,10,10,10)
+ In [3]: b, c, d = a.copy(), a.copy(), a.copy()
+
+ In [4]: timeit a+b+c+d
+ 10 loops, best of 3: 28.5 ms per loop
+
+ In [5]: timeit a.T+b.T+c.T+d.T
+ 1 loops, best of 3: 237 ms per loop
+
+ In [6]: timeit a.T.ravel('A')+b.T.ravel('A')+c.T.ravel('A')+d.T.ravel('A')
+ 10 loops, best of 3: 29.6 ms per loop
+
+In this case, it is simple to recover the performance by switching to
+a view of the memory, adding, then reshaping back. To further examine
+the problem and see how it isn’t always as trivial to work around,
+let’s consider simple code for working with image buffers in NumPy.
+
+Image Compositing Example
+=========================
+
+For a more realistic example, consider an image buffer. Images are
+generally stored in a Fortran-contiguous order, and the colour
+channel can be treated as either a structured 'RGB' type or an extra
+dimension of length three. The resulting memory layout is neither C-
+nor Fortran-contiguous, but is easy to work with directly in NumPy,
+because of the flexibility of the ndarray. This appears ideal, because
+it makes the memory layout compatible with typical C or C++ image code,
+while simultaneously giving natural access in Python. Getting the color
+of pixel (x,y) is just ‘image[x,y]’.
+
+The performance of this layout in NumPy turns out to be very poor.
+Here is code which creates two black images, and does an ‘over’
+compositing operation on them.::
+
+ In [9]: image1 = np.zeros((1080,1920,3), dtype=np.float32).swapaxes(0,1)
+ In [10]: alpha1 = np.zeros((1080,1920,1), dtype=np.float32).swapaxes(0,1)
+ In [11]: image2 = np.zeros((1080,1920,3), dtype=np.float32).swapaxes(0,1)
+ In [12]: alpha2 = np.zeros((1080,1920,1), dtype=np.float32).swapaxes(0,1)
+ In [13]: def composite_over(im1, al1, im2, al2):
+ ....: return (im1 + (1-al1)*im2, al1 + (1-al1)*al2)
+
+ In [14]: timeit composite_over(image1,alpha1,image2,alpha2)
+ 1 loops, best of 3: 3.51 s per loop
+
+If we give up the convenient layout, and use the C-contiguous default,
+the performance is about seven times better.::
+
+ In [16]: image1 = np.zeros((1080,1920,3), dtype=np.float32)
+ In [17]: alpha1 = np.zeros((1080,1920,1), dtype=np.float32)
+ In [18]: image2 = np.zeros((1080,1920,3), dtype=np.float32)
+ In [19]: alpha2 = np.zeros((1080,1920,1), dtype=np.float32)
+
+ In [20]: timeit composite_over(image1,alpha1,image2,alpha2)
+ 1 loops, best of 3: 581 ms per loop
+
+But this is not all, since it turns out that broadcasting the alpha
+channel is exacting a performance price as well. If we use an alpha
+channel with 3 values instead of one, we get::
+
+ In [21]: image1 = np.zeros((1080,1920,3), dtype=np.float32)
+ In [22]: alpha1 = np.zeros((1080,1920,3), dtype=np.float32)
+ In [23]: image2 = np.zeros((1080,1920,3), dtype=np.float32)
+ In [24]: alpha2 = np.zeros((1080,1920,3), dtype=np.float32)
+
+ In [25]: timeit composite_over(image1,alpha1,image2,alpha2)
+ 1 loops, best of 3: 313 ms per loop
+
+For a final comparison, let’s see how it performs when we use
+one-dimensional arrays to ensure just a single loop does the
+calculation.::
+
+ In [26]: image1 = np.zeros((1080*1920*3), dtype=np.float32)
+ In [27]: alpha1 = np.zeros((1080*1920*3), dtype=np.float32)
+ In [28]: image2 = np.zeros((1080*1920*3), dtype=np.float32)
+ In [29]: alpha2 = np.zeros((1080*1920*3), dtype=np.float32)
+
+ In [30]: timeit composite_over(image1,alpha1,image2,alpha2)
+ 1 loops, best of 3: 312 ms per loop
+
+To get a reference performance number, I implemented this simple operation
+straightforwardly in C (careful to use the same compile options as NumPy).
+If I emulated the memory allocation and layout of the Python code, the
+performance was roughly 0.3 seconds, very much in line with NumPy’s
+performance. Combining the operations into one pass reduced the time
+to roughly 0.15 seconds.
+
+A slight variation of this example is to use a single memory block
+with four channels (1920,1080,4) instead of separate image and alpha.
+This is more typical in image processing applications, and here’s how
+that looks with a C-contiguous layout.::
+
+ In [31]: image1 = np.zeros((1080,1920,4), dtype=np.float32)
+ In [32]: image2 = np.zeros((1080,1920,4), dtype=np.float32)
+ In [33]: def composite_over(im1, im2):
+ ....: ret = (1-im1[:,:,-1])[:,:,np.newaxis]*im2
+ ....: ret += im1
+ ....: return ret
+
+ In [34]: timeit composite_over(image1,image2)
+ 1 loops, best of 3: 481 ms per loop
+
+To see the improvements that implementation of the new iterator as
+proposed can produce, go to the example continued after the
+proposed API, near the bottom of the document.
+
+*************************
+Improving Cache-Coherency
+*************************
+
+In order to get the best performance from UFunc calls, the pattern of
+memory reads should be as regular as possible. Modern CPUs attempt to
+predict the memory read/write pattern and fill the cache ahead of time.
+The most predictable pattern is for all the inputs and outputs to be
+sequentially processed in the same order.
+
+I propose that by default, the memory layout of the UFunc outputs be as
+close to that of the inputs as possible. Whenever there is an ambiguity
+or a mismatch, it defaults to a C-contiguous layout.
+
+To understand how to accomplish this, we first consider the strides of
+all the inputs after the shapes have been normalized for broadcasting.
+By determining whether a set of strides are compatible and/or ambiguous,
+we can determine an output memory layout which maximizes coherency.
+
+In broadcasting, the input shapes are first transformed to broadcast
+shapes by prepending singular dimensions, then the broadcast strides
+are created, where any singular dimension’s stride is set to zero.
+
+Strides may be negative as well, and in certain cases this can be
+normalized to fit the following discussion. If all the strides for a
+particular axis are negative or zero, the strides for that dimension
+can be negated after adjusting the base data pointers appropriately.
+
+Here's an example of how three inputs with C-contiguous layouts result in
+broadcast strides. To simplify things, the examples use an itemsize of 1.
+
+================== ======== ======= =======
+Input shapes: (5,3,7) (5,3,1) (1,7)
+Broadcast shapes: (5,3,7) (5,3,1) (1,1,7)
+Broadcast strides: (21,7,1) (3,1,0) (0,0,1)
+================== ======== ======= =======
+
+*Compatible Strides* - A set of strides are compatible if there exists
+a permutation of the axes such that the strides are decreasing for every
+stride in the set, excluding entries that are zero.
+
+The example above satisfies the definition with the identity permutation.
+In the motivation image example, the strides are slightly different if
+we separate the colour and alpha information or not. The permutation
+which demonstrates compatibility here is the transposition (0,1).
+
+============================= ===================== =====================
+Input/Broadcast shapes: Image (1920, 1080, 3) Alpha (1920, 1080, 1)
+Broadcast strides (separate): (3,5760,1) (1,1920,0)
+Broadcast strides (together): (4,7680,1) (4,7680,0)
+============================= ===================== =====================
+
+*Ambiguous Strides* - A set of compatible strides are ambiguous if
+more than one permutation of the axes exists such that the strides are
+decreasing for every stride in the set, excluding entries that are zero.
+
+This typically occurs when every axis has a 0-stride somewhere in the
+set of strides. The simplest example is in two dimensions, as follows.
+
+================== ===== =====
+Broadcast shapes: (1,3) (5,1)
+Broadcast strides: (0,1) (1,0)
+================== ===== =====
+
+There may, however, be unambiguous compatible strides without a single
+input forcing the entire layout, as in this example:
+
+================== ======= =======
+Broadcast shapes: (1,3,4) (5,3,1)
+Broadcast strides: (0,4,1) (3,1,0)
+================== ======= =======
+
+In the face of ambiguity, we have a choice to either completely throw away
+the fact that the strides are compatible, or try to resolve the ambiguity
+by adding an additional constraint. I think the appropriate choice
+is to resolve it by picking the memory layout closest to C-contiguous,
+but still compatible with the input strides.
+
+Output Layout Selection Algorithm
+=================================
+
+The output ndarray memory layout we would like to produce is as follows:
+
+=============================== =============================================
+Consistent/Unambiguous strides: The single consistent layout
+Consistent/Ambiguous strides: The consistent layout closest to C-contiguous
+Inconsistent strides: C-contiguous
+=============================== =============================================
+
+Here is pseudo-code for an algorithm to compute the permutation for the
+output layout.::
+
+ perm = range(ndim) # Identity, i.e. C-contiguous
+ # Insertion sort, ignoring 0-strides
+ # Note that the sort must be stable, and 0-strides may
+ # be reordered if necessary, but should be moved as little
+ # as possible.
+ for i0 = 1 to ndim-1:
+ # ipos is where perm[i0] will get inserted
+ ipos = i0
+ j0 = perm[i0]
+ for i1 = i0-1 to 0:
+ j1 = perm[i1]
+ ambig, shouldswap = True, False
+ # Check whether any strides are ordered wrong
+ for strides in broadcast_strides:
+ if strides[j0] != 0 and strides[j1] != 0:
+ if strides[j0] > strides[j1]:
+ # Only set swap if it's still ambiguous.
+ if ambig:
+ shouldswap = True
+ else:
+ # Set swap even if it's not ambiguous,
+ # because not swapping is the choice
+ # for conflicts as well.
+ shouldswap = False
+ ambig = False
+ # If there was an unambiguous comparison, either shift ipos
+ # to i1 or stop looking for the comparison
+ if not ambig:
+ if shouldswap:
+ ipos = i1
+ else:
+ break
+ # Insert perm[i0] into the right place
+ if ipos != i0:
+ for i1 = i0-1 to ipos:
+ perm[i1+1] = perm[i1]
+ perm[ipos] = j0
+ # perm is now the closest consistent ordering to C-contiguous
+ return perm
+
+*********************
+Coalescing Dimensions
+*********************
+
+In many cases, the memory layout allows for the use of a one-dimensional
+loop instead of tracking multiple coordinates within the iterator.
+The existing code already exploits this when the data is C-contiguous,
+but since we're reordering the axes, we can apply this optimization
+more generally.
+
+Once the iteration strides have been sorted to be monotonically
+decreasing, any dimensions which could be coalesced are side by side.
+If for all the operands, incrementing by strides[i+1] shape[i+1] times
+is the same as incrementing by strides[i], or strides[i+1]*shape[i+1] ==
+strides[i], dimensions i and i+1 can be coalesced into a single dimension.
+
+Here is pseudo-code for coalescing.::
+
+ # Figure out which pairs of dimensions can be coalesced
+ can_coalesce = [False]*ndim
+ for strides, shape in zip(broadcast_strides, broadcast_shape):
+ for i = 0 to ndim-2:
+ if strides[i+1]*shape[i+1] == strides[i]:
+ can_coalesce[i] = True
+ # Coalesce the types
+ new_ndim = ndim - count_nonzero(can_coalesce)
+ for strides, shape in zip(broadcast_strides, broadcast_shape):
+ j = 0
+ for i = 0 to ndim-1:
+ # Note that can_coalesce[ndim-1] is always False, so
+ # there is no out-of-bounds access here.
+ if can_coalesce[i]:
+ shape[i+1] = shape[i]*shape[i+1]
+ else:
+ strides[j] = strides[i]
+ shape[j] = shape[i]
+ j += 1
+
+*************************
+Inner Loop Specialization
+*************************
+
+Specialization is handled purely by the inner loop function, so this
+optimization is independent of the others. Some specialization is
+already done, like for the reduce operation. The idea is mentioned in
+http://projects.scipy.org/numpy/wiki/ProjectIdeas, “use intrinsics
+(SSE-instructions) to speed up low-level loops in NumPy.”
+
+Here are some possibilities for two-argument functions,
+covering the important cases of add/subtract/multiply/divide.
+
+* The first or second argument is a single value (i.e. a 0 stride
+ value) and does not alias the output. arr = arr + 1; arr = 1 + arr
+
+ * Can load the constant once instead of reloading it from memory every time
+
+* The strides match the size of the data type. C- or
+ Fortran-contiguous data, for example
+
+ * Can do a simple loop without using strides
+
+* The strides match the size of the data type, and they are
+ both 16-byte aligned (or differ from 16-byte aligned by the same offset)
+
+ * Can use SSE to process multiple values at once
+
+* The first input and the output are the same single value
+ (i.e. a reduction operation).
+
+ * This is already specialized for many UFuncs in the existing code
+
+The above cases are not generally mutually exclusive, for example a
+constant argument may be combined with SSE when the strides match the
+data type size, and reductions can be optimized with SSE as well.
+
+**********************
+Implementation Details
+**********************
+
+Except for inner loop specialization, the discussed
+optimizations significantly affect ufunc_object.c and the
+PyArrayIterObject/PyArrayMultiIterObject used to do the broadcasting.
+In general, it should be possible to emulate the current behavior where it
+is desired, but I believe the default should be to produce and manipulate
+memory layouts which will give the best performance.
+
+To support the new cache-friendly behavior, we introduce a new
+option ‘K’ (for “keep”) for any ``order=`` parameter.
+
+The proposed ‘order=’ flags become as follows:
+
+=== =====================================================================================
+‘C’ C-contiguous layout
+‘F’ Fortran-contiguous layout
+‘A’ ‘F’ if the input(s) have a Fortran-contiguous layout, ‘C’ otherwise (“Any Contiguous”)
+‘K’ a layout equivalent to ‘C’ followed by some permutation of the axes, as close to the layout of the input(s) as possible (“Keep Layout”)
+=== =====================================================================================
+
+Or as an enum::
+
+ /* For specifying array memory layout or iteration order */
+ typedef enum {
+ /* Fortran order if inputs are all Fortran, C otherwise */
+ NPY_ANYORDER=-1,
+ /* C order */
+ NPY_CORDER=0,
+ /* Fortran order */
+ NPY_FORTRANORDER=1,
+ /* An order as close to the inputs as possible */
+ NPY_KEEPORDER=2
+ } NPY_ORDER;
+
+
+Perhaps a good strategy is to first implement the capabilities discussed
+here without changing the defaults. Once they are implemented and
+well-tested, the defaults can change from ``order='C'`` to ``order='K'``
+everywhere appropriate. UFuncs additionally should gain an ``order=``
+parameter to control the layout of their output(s).
+
+The iterator can do automatic casting, and I have created a sequence
+of progressively more permissive casting rules. Perhaps for 2.0, NumPy
+could adopt this enum as its prefered way of dealing with casting.::
+
+ /* For specifying allowed casting in operations which support it */
+ typedef enum {
+ /* Only allow identical types */
+ NPY_NO_CASTING=0,
+ /* Allow identical and byte swapped types */
+ NPY_EQUIV_CASTING=1,
+ /* Only allow safe casts */
+ NPY_SAFE_CASTING=2,
+ /* Allow safe casts and casts within the same kind */
+ NPY_SAME_KIND_CASTING=3,
+ /* Allow any casts */
+ NPY_UNSAFE_CASTING=4
+ } NPY_CASTING;
+
+Iterator Rewrite
+================
+
+Based on an analysis of the code, it appears that refactoring the existing
+iteration objects to implement these optimizations is prohibitively
+difficult. Additionally, some usage of the iterator requires modifying
+internal values or flags, so code using the iterator would have to
+change anyway. Thus we propose creating a new iterator object which
+subsumes the existing iterator functionality and expands it to account
+for the optimizations.
+
+High level goals for the replacement iterator include:
+
+* Small memory usage and a low number of memory allocations.
+* Simple cases (like flat arrays) should have very little overhead.
+* Combine single and multiple iteration into one object.
+
+Capabilities that should be provided to user code:
+
+* Iterate in C, Fortran, or “Fastest” (default) order.
+* Track a C-style or Fortran-style flat index if requested
+ (existing iterator always tracks a C-style index). This can be done
+ independently of the iteration order.
+* Track the coordinates if requested (the existing iterator requires
+ manually changing an internal iterator flag to guarantee this).
+* Skip iteration of the last internal dimension so that it can be
+ processed with an inner loop.
+* Jump to a specific coordinate in the array.
+* Iterate an arbitrary subset of axes (to support, for example, reduce
+ with multiple axes at once).
+* Ability to automatically allocate output parameters if a NULL input
+ is provided, These outputs should have a memory layout matching
+ the iteration order, and are the mechanism for the ``order='K'``
+ support.
+* Automatic copying and/or buffering of inputs which do not satisfy
+ type/byte-order/alignment requirements. The caller's iteration inner
+ loop should be the same no matter what buffering or copying is done.
+
+Notes for implementation:
+
+* User code must never touch the inside of the iterator. This allows
+ for drastic changes of the internal memory layout in the future, if
+ higher-performance implementation strategies are found.
+* Use a function pointer instead of a macro for iteration.
+ This way, specializations can be created for the common cases,
+ like when ndim is small, for different flag settings, and when the
+ number of arrays iterated is small. Also, an iteration pattern
+ can be prescribed that makes a copy of the function pointer first
+ to allow the compiler to keep the function pointer
+ in a register.
+* Dynamically create the memory layout, to minimize the number of
+ cache lines taken up by the iterator (for LP64,
+ sizeof(PyArrayIterObject) is about 2.5KB, and a binary operation
+ like plus needs three of these for the Multi-Iterator).
+* Isolate the C-API object from Python reference counting, so that
+ it can be used naturally from C. The Python object then becomes
+ a wrapper around the C iterator. This is analogous to the
+ PEP 3118 design separation of Py_buffer and memoryview.
+
+Proposed Iterator Memory Layout
+===============================
+
+The following struct describes the iterator memory. All items
+are packed together, which means that different values of the flags,
+ndim, and niter will produce slightly different layouts. ::
+
+ struct {
+ /* Flags indicate what optimizations have been applied, and
+ * affect the layout of this struct. */
+ uint32 itflags;
+ /* Number of iteration dimensions. If FLAGS_HASCOORDS is set,
+ * it matches the creation ndim, otherwise it may be smaller. */
+ uint16 ndim;
+ /* Number of objects being iterated. This is fixed at creation time. */
+ uint16 niter;
+
+ /* The number of times the iterator will iterate */
+ intp itersize;
+
+ /* The permutation is only used when FLAGS_HASCOORDS is set,
+ * and is placed here so its position depends on neither ndim
+ * nor niter. */
+ intp perm[ndim];
+
+ /* The data types of all the operands */
+ PyArray_Descr *dtypes[niter];
+ /* Backups of the starting axisdata 'ptr' values, to support Reset */
+ char *resetdataptr[niter];
+ /* Backup of the starting index value, to support Reset */
+ npy_intp resetindex;
+
+ /* When the iterator is destroyed, Py_XDECREF is called on all
+ these objects */
+ PyObject *objects[niter];
+
+ /* Flags indicating read/write status and buffering
+ * for each operand. */
+ uint8 opitflags[niter];
+ /* Padding to make things intp-aligned again */
+ uint8 padding[];
+
+ /* If some or all of the inputs are being buffered */
+ #if (flags&FLAGS_BUFFERED)
+ struct buffer_data {
+ /* The size of the buffer, and which buffer we're on.
+ * the i-th iteration has i = buffersize*bufferindex+pos
+ */
+ intp buffersize;
+ /* For tracking position inside the buffer */
+ intp size, pos;
+ /* The strides for the pointers */
+ intp stride[niter];
+ /* Pointers to the data for the current iterator position.
+ * The buffer_data.value ptr[i] equals either
+ * axis_data[0].ptr[i] or buffer_data.buffers[i] depending
+ * on whether copying to the buffer was necessary.
+ */
+ char* ptr[niter];
+ /* Functions to do the copyswap and casting necessary */
+ transferfn_t readtransferfn[niter];
+ void *readtransferdata[niter];
+ transferfn_t writetransferfn[niter];
+ void *writetransferdata[niter];
+ /* Pointers to the allocated buffers for operands
+ * which the iterator determined needed buffering
+ */
+ char *buffers[niter];
+ };
+ #endif /* FLAGS_BUFFERED */
+
+ /* Data per axis, starting with the most-frequently
+ * updated, and in decreasing order after that. */
+ struct axis_data {
+ /* The shape of this axis */
+ intp shape;
+ /* The current coordinate along this axis */
+ intp coord;
+ /* The operand and index strides for this axis
+ intp stride[niter];
+ {intp indexstride;} #if (flags&FLAGS_HASINDEX);
+ /* The operand pointers and index values for this axis */
+ char* ptr[niter];
+ {intp index;} #if (flags&FLAGS_HASINDEX);
+ }[ndim];
+ };
+
+The array of axis_data structs is ordered to be in increasing rapidity
+of increment updates. If the ``perm`` is the identity, this means it’s
+reversed from the C-order. This is done so data items touched
+most often are closest to the beginning of the struct, where the
+common properties are, resulting in increased cache coherency.
+It also simplifies the iternext call, while making getcoord and
+related functions slightly more complicated.
+
+Proposed Iterator API
+=====================
+
+The existing iterator API includes functions like PyArrayIter_Check,
+PyArray_Iter* and PyArray_ITER_*. The multi-iterator array includes
+PyArray_MultiIter*, PyArray_Broadcast, and PyArray_RemoveSmallest. The
+new iterator design replaces all of this functionality with a single object
+and associated API. One goal of the new API is that all uses of the
+existing iterator should be replaceable with the new iterator without
+significant effort.
+
+The C-API naming convention chosen is based on the one in the numpy-refactor
+branch, where libndarray has the array named ``NpyArray`` and functions
+named ``NpyArray_*``. The iterator is named ``NpyIter`` and functions are
+named ``NpyIter_*``.
+
+The Python exposure has the iterator named ``np.newiter``. One possible
+release strategy for this iterator would be to release a 1.X (1.6?) version
+with the iterator added, but not used by the NumPy code. Then, 2.0 can
+be release with it fully integrated. If this strategy is chosen, the
+naming convention and API should be finalized as much as possible before
+the 1.X release. The name ``np.iter`` can't be used because it conflicts
+with the Python built-in ``iter``. I would suggest the name ``np.nditer``
+within Python, as it is currently unused.
+
+In addition to the performance goals set out for the new iterator,
+it appears the API can be refactored to better support some common
+NumPy programming idioms.
+
+By moving some functionality currently in the UFunc code into the
+iterator, it should make it easier for extension code which wants
+to emulate UFunc behavior in cases which don't quite fit the
+UFunc paradigm. In particular, emulating the UFunc buffering behavior
+is not a trivial enterprise.
+
+Old -> New Iterator API Conversion
+----------------------------------
+
+For the regular iterator:
+
+=============================== =============================================
+``PyArray_IterNew`` ``NpyIter_New``
+``PyArray_IterAllButAxis`` ``NpyIter_New`` + ``axes`` parameter **or**
+ Iterator flag ``NPY_ITER_NO_INNER_ITERATION``
+``PyArray_BroadcastToShape`` **NOT SUPPORTED** (but could be, if needed)
+``PyArrayIter_Check`` Will need to add this in Python exposure
+``PyArray_ITER_RESET`` ``NpyIter_Reset``
+``PyArray_ITER_NEXT`` Function pointer from ``NpyIter_GetIterNext``
+``PyArray_ITER_DATA`` ``NpyIter_GetDataPtrArray``
+``PyArray_ITER_GOTO`` ``NpyIter_GotoCoords``
+``PyArray_ITER_GOTO1D`` ``NpyIter_GotoIndex``
+``PyArray_ITER_NOTDONE`` Return value of ``iternext`` function pointer
+=============================== =============================================
+
+For the multi-iterator:
+
+=============================== =============================================
+``PyArray_MultiIterNew`` ``NpyIter_MultiNew``
+``PyArray_MultiIter_RESET`` ``NpyIter_Reset``
+``PyArray_MultiIter_NEXT`` Function pointer from ``NpyIter_GetIterNext``
+``PyArray_MultiIter_DATA`` ``NpyIter_GetDataPtrArray``
+``PyArray_MultiIter_NEXTi`` **NOT SUPPORTED** (always lock-step iteration)
+``PyArray_MultiIter_GOTO`` ``NpyIter_GotoCoords``
+``PyArray_MultiIter_GOTO1D`` ``NpyIter_GotoIndex``
+``PyArray_MultiIter_NOTDONE`` Return value of ``iternext`` function pointer
+``PyArray_Broadcast`` Handled by ``NpyIter_MultiNew``
+``PyArray_RemoveSmallest`` Iterator flag ``NPY_ITER_NO_INNER_ITERATION``
+=============================== =============================================
+
+For other API calls:
+
+=============================== =============================================
+``PyArray_ConvertToCommonType`` Iterator flag ``NPY_ITER_COMMON_DTYPE``
+=============================== =============================================
+
+
+Iterator Pointer Type
+---------------------
+
+The iterator structure is internally generated, but a type is still needed
+to provide warnings and/or errors when the wrong type is passed to
+the API. We do this with a typedef of an incomplete struct
+
+``typedef struct NpyIter_InternalOnly NpyIter;``
+
+
+Construction and Destruction
+----------------------------
+
+``NpyIter* NpyIter_New(PyArrayObject* op, npy_uint32 flags, NPY_ORDER order, NPY_CASTING casting, PyArray_Descr* dtype, npy_intp a_ndim, npy_intp *axes, npy_intp buffersize)``
+
+ Creates an iterator for the given numpy array object ``op``.
+
+ Flags that may be passed in ``flags`` are any combination
+ of the global and per-operand flags documented in
+ ``NpyIter_MultiNew``, except for ``NPY_ITER_ALLOCATE``.
+
+ Any of the ``NPY_ORDER`` enum values may be passed to ``order``. For
+ efficient iteration, ``NPY_KEEPORDER`` is the best option, and the other
+ orders enforce the particular iteration pattern.
+
+ Any of the ``NPY_CASTING`` enum values may be passed to ``casting``.
+ The values include ``NPY_NO_CASTING``, ``NPY_EQUIV_CASTING``,
+ ``NPY_SAFE_CASTING``, ``NPY_SAME_KIND_CASTING``, and
+ ``NPY_UNSAFE_CASTING``. To allow the casts to occur, copying or
+ buffering must also be enabled.
+
+ If ``dtype`` isn't ``NULL``, then it requires that data type.
+ If copying is allowed, it will make a temporary copy if the data
+ is castable. If ``UPDATEIFCOPY`` is enabled, it will also copy
+ the data back with another cast upon iterator destruction.
+
+ If ``a_ndim`` is greater than zero, ``axes`` must also be provided.
+ In this case, ``axes`` is an ``a_ndim``-sized array of ``op``'s axes.
+ A value of -1 in ``axes`` means ``newaxis``. Within the ``axes``
+ array, axes may not be repeated.
+
+ If ``buffersize`` is zero, a default buffer size is used,
+ otherwise it specifies how big of a buffer to use. Buffers
+ which are powers of 2 such as 512 or 1024 are recommended.
+
+ Returns NULL if there is an error, otherwise returns the allocated
+ iterator.
+
+ To make an iterator similar to the old iterator, this should work.::
+
+ iter = NpyIter_New(op, NPY_ITER_READWRITE,
+ NPY_CORDER, NPY_NO_CASTING, NULL, 0, NULL);
+
+ If you want to edit an array with aligned ``double`` code,
+ but the order doesn't matter, you would use this.::
+
+ dtype = PyArray_DescrFromType(NPY_DOUBLE);
+ iter = NpyIter_New(op, NPY_ITER_READWRITE |
+ NPY_ITER_BUFFERED |
+ NPY_ITER_NBO,
+ NPY_ITER_ALIGNED,
+ NPY_KEEPORDER,
+ NPY_SAME_KIND_CASTING,
+ dtype, 0, NULL);
+ Py_DECREF(dtype);
+
+``NpyIter* NpyIter_MultiNew(npy_intp niter, PyArrayObject** op, npy_uint32 flags, NPY_ORDER order, NPY_CASTING casting, npy_uint32 *op_flags, PyArray_Descr** op_dtypes, npy_intp oa_ndim, npy_intp **op_axes, npy_intp buffersize)``
+
+ Creates an iterator for broadcasting the ``niter`` array objects provided
+ in ``op``.
+
+ For normal usage, use 0 for ``oa_ndim`` and NULL for ``op_axes``.
+ See below for a description of these parameters, which allow for
+ custom manual broadcasting as well as reordering and leaving out axes.
+
+ Any of the ``NPY_ORDER`` enum values may be passed to ``order``. For
+ efficient iteration, ``NPY_KEEPORDER`` is the best option, and the other
+ orders enforce the particular iteration pattern. When using
+ ``NPY_KEEPORDER``, if you also want to ensure that the iteration is
+ not reversed along an axis, you should pass the flag
+ ``NPY_ITER_DONT_NEGATE_STRIDES``.
+
+ Any of the ``NPY_CASTING`` enum values may be passed to ``casting``.
+ The values include ``NPY_NO_CASTING``, ``NPY_EQUIV_CASTING``,
+ ``NPY_SAFE_CASTING``, ``NPY_SAME_KIND_CASTING``, and
+ ``NPY_UNSAFE_CASTING``. To allow the casts to occur, copying or
+ buffering must also be enabled.
+
+ If ``op_dtypes`` isn't ``NULL``, it specifies a data type or ``NULL``
+ for each ``op[i]``.
+
+ The parameter ``oa_ndim``, when non-zero, specifies the number of
+ dimensions that will be iterated with customized broadcasting.
+ If it is provided, ``op_axes`` must also be provided.
+ These two parameters let you control in detail how the
+ axes of the operand arrays get matched together and iterated.
+ In ``op_axes``, you must provide an array of ``niter`` pointers
+ to ``oa_ndim``-sized arrays of type ``npy_intp``. If an entry
+ in ``op_axes`` is NULL, normal broadcasting rules will apply.
+ In ``op_axes[j][i]`` is stored either a valid axis of ``op[j]``, or
+ -1 which means ``newaxis``. Within each ``op_axes[j]`` array, axes
+ may not be repeated. The following example is how normal broadcasting
+ applies to a 3-D array, a 2-D array, a 1-D array and a scalar.::
+
+ npy_intp oa_ndim = 3; /* # iteration axes */
+ npy_intp op0_axes[] = {0, 1, 2}; /* 3-D operand */
+ npy_intp op1_axes[] = {-1, 0, 1}; /* 2-D operand */
+ npy_intp op2_axes[] = {-1, -1, 0}; /* 1-D operand */
+ npy_intp op3_axes[] = {-1, -1, -1} /* 0-D (scalar) operand */
+ npy_intp *op_axes[] = {op0_axes, op1_axes, op2_axes, op3_axes};
+
+ If ``buffersize`` is zero, a default buffer size is used,
+ otherwise it specifies how big of a buffer to use. Buffers
+ which are powers of 2 such as 512 or 1024 are recommended.
+
+ Returns NULL if there is an error, otherwise returns the allocated
+ iterator.
+
+ Flags that may be passed in ``flags``, applying to the whole
+ iterator, are:
+
+ ``NPY_ITER_C_INDEX``, ``NPY_ITER_F_INDEX``
+
+ Causes the iterator to track an index matching C or
+ Fortran order. These options are mutually exclusive.
+
+ ``NPY_ITER_COORDS``
+
+ Causes the iterator to track array coordinates.
+ This prevents the iterator from coalescing axes to
+ produce bigger inner loops.
+
+ ``NPY_ITER_NO_INNER_ITERATION``
+
+ Causes the iterator to skip iteration of the innermost
+ loop, allowing the user of the iterator to handle it.
+
+ This flag is incompatible with ``NPY_ITER_C_INDEX``,
+ ``NPY_ITER_F_INDEX``, and ``NPY_ITER_COORDS``.
+
+ ``NPY_ITER_DONT_NEGATE_STRIDES``
+
+ This only affects the iterator when NPY_KEEPORDER is specified
+ for the order parameter. By default with NPY_KEEPORDER, the
+ iterator reverses axes which have negative strides, so that
+ memory is traversed in a forward direction. This disables
+ this step. Use this flag if you want to use the underlying
+ memory-ordering of the axes, but don't want an axis reversed.
+ This is the behavior of ``numpy.ravel(a, order='K')``, for
+ instance.
+
+ ``NPY_ITER_COMMON_DTYPE``
+
+ Causes the iterator to convert all the operands to a common
+ data type, calculated based on the ufunc type promotion rules.
+ The flags for each operand must be set so that the appropriate
+ casting is permitted, and copying or buffering must be enabled.
+
+ If the common data type is known ahead of time, don't use this
+ flag. Instead, set the requested dtype for all the operands.
+
+ ``NPY_ITER_REFS_OK``
+
+ Indicates that arrays with reference types (object
+ arrays or structured arrays containing an object type)
+ may be accepted and used in the iterator. If this flag
+ is enabled, the caller must be sure to check whether
+ ``NpyIter_IterationNeedsAPI(iter)`` is true, in which case
+ it may not release the GIL during iteration.
+
+ ``NPY_ITER_ZEROSIZE_OK``
+
+ Indicates that arrays with a size of zero should be permitted.
+ Since the typical iteration loop does not naturally work with
+ zero-sized arrays, you must check that the IterSize is non-zero
+ before entering the iteration loop.
+
+ ``NPY_ITER_REDUCE_OK``
+
+ Permits writeable operands with a dimension with zero
+ stride and size greater than one. Note that such operands
+ must be read/write.
+
+ When buffering is enabled, this also switches to a special
+ buffering mode which reduces the loop length as necessary to
+ not trample on values being reduced.
+
+ Note that if you want to do a reduction on an automatically
+ allocated output, you must use ``NpyIter_GetOperandArray``
+ to get its reference, then set every value to the reduction
+ unit before doing the iteration loop. In the case of a
+ buffered reduction, this means you must also specify the
+ flag ``NPY_ITER_DELAY_BUFALLOC``, then reset the iterator
+ after initializing the allocated operand to prepare the
+ buffers.
+
+ ``NPY_ITER_RANGED``
+
+ Enables support for iteration of sub-ranges of the full
+ ``iterindex`` range ``[0, NpyIter_IterSize(iter))``. Use
+ the function ``NpyIter_ResetToIterIndexRange`` to specify
+ a range for iteration.
+
+ This flag can only be used with ``NPY_ITER_NO_INNER_ITERATION``
+ when ``NPY_ITER_BUFFERED`` is enabled. This is because
+ without buffering, the inner loop is always the size of the
+ innermost iteration dimension, and allowing it to get cut up
+ would require special handling, effectively making it more
+ like the buffered version.
+
+ ``NPY_ITER_BUFFERED``
+
+ Causes the iterator to store buffering data, and use buffering
+ to satisfy data type, alignment, and byte-order requirements.
+ To buffer an operand, do not specify the ``NPY_ITER_COPY``
+ or ``NPY_ITER_UPDATEIFCOPY`` flags, because they will
+ override buffering. Buffering is especially useful for Python
+ code using the iterator, allowing for larger chunks
+ of data at once to amortize the Python interpreter overhead.
+
+ If used with ``NPY_ITER_NO_INNER_ITERATION``, the inner loop
+ for the caller may get larger chunks than would be possible
+ without buffering, because of how the strides are laid out.
+
+ Note that if an operand is given the flag ``NPY_ITER_COPY``
+ or ``NPY_ITER_UPDATEIFCOPY``, a copy will be made in preference
+ to buffering. Buffering will still occur when the array was
+ broadcast so elements need to be duplicated to get a constant
+ stride.
+
+ In normal buffering, the size of each inner loop is equal
+ to the buffer size, or possibly larger if ``NPY_ITER_GROWINNER``
+ is specified. If ``NPY_ITER_REDUCE_OK`` is enabled and
+ a reduction occurs, the inner loops may become smaller depending
+ on the structure of the reduction.
+
+ ``NPY_ITER_GROWINNER``
+
+ When buffering is enabled, this allows the size of the inner
+ loop to grow when buffering isn't necessary. This option
+ is best used if you're doing a straight pass through all the
+ data, rather than anything with small cache-friendly arrays
+ of temporary values for each inner loop.
+
+ ``NPY_ITER_DELAY_BUFALLOC``
+
+ When buffering is enabled, this delays allocation of the
+ buffers until one of the ``NpyIter_Reset*`` functions is
+ called. This flag exists to avoid wasteful copying of
+ buffer data when making multiple copies of a buffered
+ iterator for multi-threaded iteration.
+
+ Another use of this flag is for setting up reduction operations.
+ After the iterator is created, and a reduction output
+ is allocated automatically by the iterator (be sure to use
+ READWRITE access), its value may be initialized to the reduction
+ unit. Use ``NpyIter_GetOperandArray`` to get the object.
+ Then, call ``NpyIter_Reset`` to allocate and fill the buffers
+ with their initial values.
+
+ Flags that may be passed in ``op_flags[i]``, where ``0 <= i < niter``:
+
+ ``NPY_ITER_READWRITE``, ``NPY_ITER_READONLY``, ``NPY_ITER_WRITEONLY``
+
+ Indicate how the user of the iterator will read or write
+ to ``op[i]``. Exactly one of these flags must be specified
+ per operand.
+
+ ``NPY_ITER_COPY``
+
+ Allow a copy of ``op[i]`` to be made if it does not
+ meet the data type or alignment requirements as specified
+ by the constructor flags and parameters.
+
+ ``NPY_ITER_UPDATEIFCOPY``
+
+ Triggers ``NPY_ITER_COPY``, and when an array operand
+ is flagged for writing and is copied, causes the data
+ in a copy to be copied back to ``op[i]`` when the iterator
+ is destroyed.
+
+ If the operand is flagged as write-only and a copy is needed,
+ an uninitialized temporary array will be created and then copied
+ to back to ``op[i]`` on destruction, instead of doing
+ the unecessary copy operation.
+
+ ``NPY_ITER_NBO``, ``NPY_ITER_ALIGNED``, ``NPY_ITER_CONTIG``
+
+ Causes the iterator to provide data for ``op[i]``
+ that is in native byte order, aligned according to
+ the dtype requirements, contiguous, or any combination.
+
+ By default, the iterator produces pointers into the
+ arrays provided, which may be aligned or unaligned, and
+ with any byte order. If copying or buffering is not
+ enabled and the operand data doesn't satisfy the constraints,
+ an error will be raised.
+
+ The contiguous constraint applies only to the inner loop,
+ successive inner loops may have arbitrary pointer changes.
+
+ If the requested data type is in non-native byte order,
+ the NBO flag overrides it and the requested data type is
+ converted to be in native byte order.
+
+ ``NPY_ITER_ALLOCATE``
+
+ This is for output arrays, and requires that the flag
+ ``NPY_ITER_WRITEONLY`` be set. If ``op[i]`` is NULL,
+ creates a new array with the final broadcast dimensions,
+ and a layout matching the iteration order of the iterator.
+
+ When ``op[i]`` is NULL, the requested data type
+ ``op_dtypes[i]`` may be NULL as well, in which case it is
+ automatically generated from the dtypes of the arrays which
+ are flagged as readable. The rules for generating the dtype
+ are the same is for UFuncs. Of special note is handling
+ of byte order in the selected dtype. If there is exactly
+ one input, the input's dtype is used as is. Otherwise,
+ if more than one input dtypes are combined together, the
+ output will be in native byte order.
+
+ After being allocated with this flag, the caller may retrieve
+ the new array by calling ``NpyIter_GetOperandArray`` and
+ getting the i-th object in the returned C array. The caller
+ must call Py_INCREF on it to claim a reference to the array.
+
+ ``NPY_ITER_NO_SUBTYPE``
+
+ For use with ``NPY_ITER_ALLOCATE``, this flag disables
+ allocating an array subtype for the output, forcing
+ it to be a straight ndarray.
+
+ TODO: Maybe it would be better to introduce a function
+ ``NpyIter_GetWrappedOutput`` and remove this flag?
+
+ ``NPY_ITER_NO_BROADCAST``
+
+ Ensures that the input or output matches the iteration
+ dimensions exactly.
+
+ ``NPY_ITER_WRITEABLE_REFERENCES``
+
+ By default, the iterator fails on creation if the iterator
+ has a writeable operand where the data type involves Python
+ references. Adding this flag indicates that the code using
+ the iterator is aware of this possibility and handles it
+ correctly.
+
+``NpyIter *NpyIter_Copy(NpyIter *iter)``
+
+ Makes a copy of the given iterator. This function is provided
+ primarily to enable multi-threaded iteration of the data.
+
+ *TODO*: Move this to a section about multithreaded iteration.
+
+ The recommended approach to multithreaded iteration is to
+ first create an iterator with the flags
+ ``NPY_ITER_NO_INNER_ITERATION``, ``NPY_ITER_RANGED``,
+ ``NPY_ITER_BUFFERED``, ``NPY_ITER_DELAY_BUFALLOC``, and
+ possibly ``NPY_ITER_GROWINNER``. Create a copy of this iterator
+ for each thread (minus one for the first iterator). Then, take
+ the iteration index range ``[0, NpyIter_GetIterSize(iter))`` and
+ split it up into tasks, for example using a TBB parallel_for loop.
+ When a thread gets a task to execute, it then uses its copy of
+ the iterator by calling ``NpyIter_ResetToIterIndexRange`` and
+ iterating over the full range.
+
+ When using the iterator in multi-threaded code or in code not
+ holding the Python GIL, care must be taken to only call functions
+ which are safe in that context. ``NpyIter_Copy`` cannot be safely
+ called without the Python GIL, because it increments Python
+ references. The ``Reset*`` and some other functions may be safely
+ called by passing in the ``errmsg`` parameter as non-NULL, so that
+ the functions will pass back errors through it instead of setting
+ a Python exception.
+
+``int NpyIter_UpdateIter(NpyIter *iter, npy_intp i, npy_uint32 op_flags, NPY_CASTING casting, PyArray_Descr *dtype)`` **UNIMPLEMENTED**
+
+ Updates the i-th operand within the iterator to possibly have a new
+ data type or more restrictive flag attributes. A use-case for
+ this is to allow the automatic allocation to determine an
+ output data type based on the standard NumPy type promotion rules,
+ then use this function to convert the inputs and possibly the
+ automatic output to a different data type during processing.
+
+ This operation can only be done if ``NPY_ITER_COORDS`` was passed
+ as a flag to the iterator. If coordinates are not needed,
+ call the function ``NpyIter_RemoveCoords()`` once no more calls to
+ ``NpyIter_UpdateIter`` are needed.
+
+ If the i-th operand has already been copied, an error is thrown. To
+ avoid this, leave all the flags out except the read/write indicators
+ for any operand that later has ``NpyIter_UpdateIter`` called on it.
+
+ The flags that may be passed in ``op_flags`` are
+ ``NPY_ITER_COPY``, ``NPY_ITER_UPDATEIFCOPY``,
+ ``NPY_ITER_NBO``, ``NPY_ITER_ALIGNED``, ``NPY_ITER_CONTIG``.
+
+``int NpyIter_RemoveAxis(NpyIter *iter, npy_intp axis)``
+
+ Removes an axis from iteration. This requires that
+ ``NPY_ITER_COORDS`` was set for iterator creation, and does not work
+ if buffering is enabled or an index is being tracked. This function
+ also resets the iterator to its initial state.
+
+ This is useful for setting up an accumulation loop, for example.
+ The iterator can first be created with all the dimensions, including
+ the accumulation axis, so that the output gets created correctly.
+ Then, the accumulation axis can be removed, and the calculation
+ done in a nested fashion.
+
+ **WARNING**: This function may change the internal memory layout of
+ the iterator. Any cached functions or pointers from the iterator
+ must be retrieved again!
+
+ Returns ``NPY_SUCCEED`` or ``NPY_FAIL``.
+
+
+``int NpyIter_RemoveCoords(NpyIter *iter)``
+
+ If the iterator has coordinates, this strips support for them, and
+ does further iterator optimizations that are possible if coordinates
+ are not needed. This function also resets the iterator to its initial
+ state.
+
+ **WARNING**: This function may change the internal memory layout of
+ the iterator. Any cached functions or pointers from the iterator
+ must be retrieved again!
+
+ After calling this function, ``NpyIter_HasCoords(iter)`` will
+ return false.
+
+ Returns ``NPY_SUCCEED`` or ``NPY_FAIL``.
+
+``int NpyIter_RemoveInnerLoop(NpyIter *iter)``
+
+ If UpdateIter/RemoveCoords was used, you may want to specify the
+ flag ``NPY_ITER_NO_INNER_ITERATION``. This flag is not permitted
+ together with ``NPY_ITER_COORDS``, so this function is provided
+ to enable the feature after ``NpyIter_RemoveCoords`` is called.
+ This function also resets the iterator to its initial state.
+
+ **WARNING**: This function changes the internal logic of the iterator.
+ Any cached functions or pointers from the iterator must be retrieved
+ again!
+
+ Returns ``NPY_SUCCEED`` or ``NPY_FAIL``.
+
+``int NpyIter_Deallocate(NpyIter *iter)``
+
+ Deallocates the iterator object. This additionally frees any
+ copies made, triggering UPDATEIFCOPY behavior where necessary.
+
+ Returns ``NPY_SUCCEED`` or ``NPY_FAIL``.
+
+``int NpyIter_Reset(NpyIter *iter, char **errmsg)``
+
+ Resets the iterator back to its initial state, at the beginning
+ of the iteration range.
+
+ Returns ``NPY_SUCCEED`` or ``NPY_FAIL``. If errmsg is non-NULL,
+ no Python exception is set when ``NPY_FAIL`` is returned.
+ Instead, \*errmsg is set to an error message. When errmsg is
+ non-NULL, the function may be safely called without holding
+ the Python GIL.
+
+``int NpyIter_ResetToIterIndexRange(NpyIter *iter, npy_intp istart, npy_intp iend, char **errmsg)``
+
+ Resets the iterator and restricts it to the ``iterindex`` range
+ ``[istart, iend)``. See ``NpyIter_Copy`` for an explanation of
+ how to use this for multi-threaded iteration. This requires that
+ the flag ``NPY_ITER_RANGED`` was passed to the iterator constructor.
+
+ If you want to reset both the ``iterindex`` range and the base
+ pointers at the same time, you can do the following to avoid
+ extra buffer copying (be sure to add the return code error checks
+ when you copy this code).::
+
+ /* Set to a trivial empty range */
+ NpyIter_ResetToIterIndexRange(iter, 0, 0);
+ /* Set the base pointers */
+ NpyIter_ResetBasePointers(iter, baseptrs);
+ /* Set to the desired range */
+ NpyIter_ResetToIterIndexRange(iter, istart, iend);
+
+ Returns ``NPY_SUCCEED`` or ``NPY_FAIL``. If errmsg is non-NULL,
+ no Python exception is set when ``NPY_FAIL`` is returned.
+ Instead, \*errmsg is set to an error message. When errmsg is
+ non-NULL, the function may be safely called without holding
+ the Python GIL.
+
+``int NpyIter_ResetBasePointers(NpyIter *iter, char **baseptrs, char **errmsg)``
+
+ Resets the iterator back to its initial state, but using the values
+ in ``baseptrs`` for the data instead of the pointers from the arrays
+ being iterated. This functions is intended to be used, together with
+ the ``op_axes`` parameter, by nested iteration code with two or more
+ iterators.
+
+ Returns ``NPY_SUCCEED`` or ``NPY_FAIL``. If errmsg is non-NULL,
+ no Python exception is set when ``NPY_FAIL`` is returned.
+ Instead, \*errmsg is set to an error message. When errmsg is
+ non-NULL, the function may be safely called without holding
+ the Python GIL.
+
+ *TODO*: Move the following into a special section on nested iterators.
+
+ Creating iterators for nested iteration requires some care. All
+ the iterator operands must match exactly, or the calls to
+ ``NpyIter_ResetBasePointers`` will be invalid. This means that
+ automatic copies and output allocation should not be used haphazardly.
+ It is possible to still use the automatic data conversion and casting
+ features of the iterator by creating one of the iterators with
+ all the conversion parameters enabled, then grabbing the allocated
+ operands with the ``NpyIter_GetOperandArray`` function and passing
+ them into the constructors for the rest of the iterators.
+
+ **WARNING**: When creating iterators for nested iteration,
+ the code must not use a dimension more than once in the different
+ iterators. If this is done, nested iteration will produce
+ out-of-bounds pointers during iteration.
+
+ **WARNING**: When creating iterators for nested iteration, buffering
+ can only be applied to the innermost iterator. If a buffered iterator
+ is used as the source for ``baseptrs``, it will point into a small buffer
+ instead of the array and the inner iteration will be invalid.
+
+ The pattern for using nested iterators is as follows.::
+
+ NpyIter *iter1, *iter1;
+ NpyIter_IterNext_Fn iternext1, iternext2;
+ char **dataptrs1;
+
+ /*
+ * With the exact same operands, no copies allowed, and
+ * no axis in op_axes used both in iter1 and iter2.
+ * Buffering may be enabled for iter2, but not for iter1.
+ */
+ iter1 = ...; iter2 = ...;
+
+ iternext1 = NpyIter_GetIterNext(iter1);
+ iternext2 = NpyIter_GetIterNext(iter2);
+ dataptrs1 = NpyIter_GetDataPtrArray(iter1);
+
+ do {
+ NpyIter_ResetBasePointers(iter2, dataptrs1);
+ do {
+ /* Use the iter2 values */
+ } while (iternext2(iter2));
+ } while (iternext1(iter1));
+
+``int NpyIter_GotoCoords(NpyIter *iter, npy_intp *coords)``
+
+ Adjusts the iterator to point to the ``ndim`` coordinates
+ pointed to by ``coords``. Returns an error if coordinates
+ are not being tracked, the coordinates are out of bounds,
+ or inner loop iteration is disabled.
+
+ Returns ``NPY_SUCCEED`` or ``NPY_FAIL``.
+
+``int NpyIter_GotoIndex(NpyIter *iter, npy_intp index)``
+
+ Adjusts the iterator to point to the ``index`` specified.
+ If the iterator was constructed with the flag
+ ``NPY_ITER_C_INDEX``, ``index`` is the C-order index,
+ and if the iterator was constructed with the flag
+ ``NPY_ITER_F_INDEX``, ``index`` is the Fortran-order
+ index. Returns an error if there is no index being tracked,
+ the index is out of bounds, or inner loop iteration is disabled.
+
+ Returns ``NPY_SUCCEED`` or ``NPY_FAIL``.
+
+``npy_intp NpyIter_GetIterSize(NpyIter *iter)``
+
+ Returns the number of elements being iterated. This is the product
+ of all the dimensions in the shape.
+
+``npy_intp NpyIter_GetReduceBlockSizeFactor(NpyIter *iter)`` **UNIMPLEMENTED**
+
+ This provides a factor that must divide into the blocksize used
+ for ranged iteration to safely multithread a reduction. If
+ the iterator has no reduction, it returns 1.
+
+ When using ranged iteration to multithread a reduction, there are
+ two possible ways to do the reduction:
+
+ If there is a big reduction to a small output, make a temporary
+ array initialized to the reduction unit for each thread, then have
+ each thread reduce into its temporary. When that is complete,
+ combine the temporaries together. You can detect this case by
+ observing that ``NpyIter_GetReduceBlockSizeFactor`` returns a
+ large value, for instance half or a third of ``NpyIter_GetIterSize``.
+ You should also check that the output is small just to be sure.
+
+ If there are many small reductions to a big output, and the reduction
+ dimensions are inner dimensions, ``NpyIter_GetReduceBlockSizeFactor``
+ will return a small number, and as long as the block size you choose
+ for multithreading is ``NpyIter_GetReduceBlockSizeFactor(iter)*n``
+ for some ``n``, the operation will be safe.
+
+ The bad case is when the a reduction dimension is the outermost
+ loop in the iterator. For example, if you have a C-order
+ array with shape (3,1000,1000), and you reduce on dimension 0,
+ ``NpyIter_GetReduceBlockSizeFactor`` will return a size equal to
+ ``NpyIter_GetIterSize`` for ``NPY_KEEPORDER`` or ``NPY_CORDER``
+ iteration orders. While it is bad for the CPU cache, perhaps
+ in the future another order possibility could be provided, maybe
+ ``NPY_REDUCEORDER``, which pushes the reduction axes to the inner
+ loop, but otherwise is the same as ``NPY_KEEPORDER``.
+
+``npy_intp NpyIter_GetIterIndex(NpyIter *iter)``
+
+ Gets the ``iterindex`` of the iterator, which is an index matching
+ the iteration order of the iterator.
+
+``void NpyIter_GetIterIndexRange(NpyIter *iter, npy_intp *istart, npy_intp *iend)``
+
+ Gets the ``iterindex`` sub-range that is being iterated. If
+ ``NPY_ITER_RANGED`` was not specified, this always returns the
+ range ``[0, NpyIter_IterSize(iter))``.
+
+``int NpyIter_GotoIterIndex(NpyIter *iter, npy_intp iterindex)``
+
+ Adjusts the iterator to point to the ``iterindex`` specified.
+ The IterIndex is an index matching the iteration order of the iterator.
+ Returns an error if the ``iterindex`` is out of bounds,
+ buffering is enabled, or inner loop iteration is disabled.
+
+ Returns ``NPY_SUCCEED`` or ``NPY_FAIL``.
+
+``int NpyIter_HasInnerLoop(NpyIter *iter``
+
+ Returns 1 if the iterator handles the inner loop,
+ or 0 if the caller needs to handle it. This is controlled
+ by the constructor flag ``NPY_ITER_NO_INNER_ITERATION``.
+
+``int NpyIter_HasCoords(NpyIter *iter)``
+
+ Returns 1 if the iterator was created with the
+ ``NPY_ITER_COORDS`` flag, 0 otherwise.
+
+``int NpyIter_HasIndex(NpyIter *iter)``
+
+ Returns 1 if the iterator was created with the
+ ``NPY_ITER_C_INDEX`` or ``NPY_ITER_F_INDEX``
+ flag, 0 otherwise.
+
+``int NpyIter_IsBuffered(NpyIter *iter)``
+
+ Returns 1 if the iterator was created with the
+ ``NPY_ITER_BUFFERED`` flag, 0 otherwise.
+
+``int NpyIter_IsGrowInner(NpyIter *iter)``
+
+ Returns 1 if the iterator was created with the
+ ``NPY_ITER_GROWINNER`` flag, 0 otherwise.
+
+``npy_intp NpyIter_GetBufferSize(NpyIter *iter)``
+
+ If the iterator is buffered, returns the size of the buffer
+ being used, otherwise returns 0.
+
+``npy_intp NpyIter_GetNDim(NpyIter *iter)``
+
+ Returns the number of dimensions being iterated. If coordinates
+ were not requested in the iterator constructor, this value
+ may be smaller than the number of dimensions in the original
+ objects.
+
+``npy_intp NpyIter_GetNIter(NpyIter *iter)``
+
+ Returns the number of objects being iterated.
+
+``npy_intp *NpyIter_GetAxisStrideArray(NpyIter *iter, npy_intp axis)``
+
+ Gets the array of strides for the specified axis. Requires that
+ the iterator be tracking coordinates, and that buffering not
+ be enabled.
+
+ This may be used when you want to match up operand axes in
+ some fashion, then remove them with ``NpyIter_RemoveAxis`` to
+ handle their processing manually. By calling this function
+ before removing the axes, you can get the strides for the
+ manual processing.
+
+ Returns ``NULL`` on error.
+
+``int NpyIter_GetShape(NpyIter *iter, npy_intp *outshape)``
+
+ Returns the broadcast shape of the iterator in ``outshape``.
+ This can only be called on an iterator which supports coordinates.
+
+ Returns ``NPY_SUCCEED`` or ``NPY_FAIL``.
+
+``PyArray_Descr **NpyIter_GetDescrArray(NpyIter *iter)``
+
+ This gives back a pointer to the ``niter`` data type Descrs for
+ the objects being iterated. The result points into ``iter``,
+ so the caller does not gain any references to the Descrs.
+
+ This pointer may be cached before the iteration loop, calling
+ ``iternext`` will not change it.
+
+``PyObject **NpyIter_GetOperandArray(NpyIter *iter)``
+
+ This gives back a pointer to the ``niter`` operand PyObjects
+ that are being iterated. The result points into ``iter``,
+ so the caller does not gain any references to the PyObjects.
+
+``PyObject *NpyIter_GetIterView(NpyIter *iter, npy_intp i)``
+
+ This gives back a reference to a new ndarray view, which is a view
+ into the i-th object in the array ``NpyIter_GetOperandArray()``,
+ whose dimensions and strides match the internal optimized
+ iteration pattern. A C-order iteration of this view is equivalent
+ to the iterator's iteration order.
+
+ For example, if an iterator was created with a single array as its
+ input, and it was possible to rearrange all its axes and then
+ collapse it into a single strided iteration, this would return
+ a view that is a one-dimensional array.
+
+``void NpyIter_GetReadFlags(NpyIter *iter, char *outreadflags)``
+
+ Fills ``niter`` flags. Sets ``outreadflags[i]`` to 1 if
+ ``op[i]`` can be read from, and to 0 if not.
+
+``void NpyIter_GetWriteFlags(NpyIter *iter, char *outwriteflags)``
+
+ Fills ``niter`` flags. Sets ``outwriteflags[i]`` to 1 if
+ ``op[i]`` can be written to, and to 0 if not.
+
+Functions For Iteration
+-----------------------
+
+``NpyIter_IterNext_Fn NpyIter_GetIterNext(NpyIter *iter, char **errmsg)``
+
+ Returns a function pointer for iteration. A specialized version
+ of the function pointer may be calculated by this function
+ instead of being stored in the iterator structure. Thus, to
+ get good performance, it is required that the function pointer
+ be saved in a variable rather than retrieved for each loop iteration.
+
+ Returns NULL if there is an error. If errmsg is non-NULL,
+ no Python exception is set when ``NPY_FAIL`` is returned.
+ Instead, \*errmsg is set to an error message. When errmsg is
+ non-NULL, the function may be safely called without holding
+ the Python GIL.
+
+ The typical looping construct is as follows.::
+
+ NpyIter_IterNext_Fn iternext = NpyIter_GetIterNext(iter, NULL);
+ char **dataptr = NpyIter_GetDataPtrArray(iter);
+
+ do {
+ /* use the addresses dataptr[0], ... dataptr[niter-1] */
+ } while(iternext(iter));
+
+ When ``NPY_ITER_NO_INNER_ITERATION`` is specified, the typical
+ inner loop construct is as follows.::
+
+ NpyIter_IterNext_Fn iternext = NpyIter_GetIterNext(iter, NULL);
+ char **dataptr = NpyIter_GetDataPtrArray(iter);
+ npy_intp *stride = NpyIter_GetInnerStrideArray(iter);
+ npy_intp *size_ptr = NpyIter_GetInnerLoopSizePtr(iter), size;
+ npy_intp iiter, niter = NpyIter_GetNIter(iter);
+
+ do {
+ size = *size_ptr;
+ while (size--) {
+ /* use the addresses dataptr[0], ... dataptr[niter-1] */
+ for (iiter = 0; iiter < niter; ++iiter) {
+ dataptr[iiter] += stride[iiter];
+ }
+ }
+ } while (iternext());
+
+ Observe that we are using the dataptr array inside the iterator, not
+ copying the values to a local temporary. This is possible because
+ when ``iternext()`` is called, these pointers will be overwritten
+ with fresh values, not incrementally updated.
+
+ If a compile-time fixed buffer is being used (both flags
+ ``NPY_ITER_BUFFERED`` and ``NPY_ITER_NO_INNER_ITERATION``), the
+ inner size may be used as a signal as well. The size is guaranteed
+ to become zero when ``iternext()`` returns false, enabling the
+ following loop construct. Note that if you use this construct,
+ you should not pass ``NPY_ITER_GROWINNER`` as a flag, because it
+ will cause larger sizes under some circumstances.::
+
+ /* The constructor should have buffersize passed as this value */
+ #define FIXED_BUFFER_SIZE 1024
+
+ NpyIter_IterNext_Fn iternext = NpyIter_GetIterNext(iter, NULL);
+ char **dataptr = NpyIter_GetDataPtrArray(iter);
+ npy_intp *stride = NpyIter_GetInnerStrideArray(iter);
+ npy_intp *size_ptr = NpyIter_GetInnerLoopSizePtr(iter), size;
+ npy_intp i, iiter, niter = NpyIter_GetNIter(iter);
+
+ /* One loop with a fixed inner size */
+ size = *size_ptr;
+ while (size == FIXED_BUFFER_SIZE) {
+ /*
+ * This loop could be manually unrolled by a factor
+ * which divides into FIXED_BUFFER_SIZE
+ */
+ for (i = 0; i < FIXED_BUFFER_SIZE; ++i) {
+ /* use the addresses dataptr[0], ... dataptr[niter-1] */
+ for (iiter = 0; iiter < niter; ++iiter) {
+ dataptr[iiter] += stride[iiter];
+ }
+ }
+ iternext();
+ size = *size_ptr;
+ }
+
+ /* Finish-up loop with variable inner size */
+ if (size > 0) do {
+ size = *size_ptr;
+ while (size--) {
+ /* use the addresses dataptr[0], ... dataptr[niter-1] */
+ for (iiter = 0; iiter < niter; ++iiter) {
+ dataptr[iiter] += stride[iiter];
+ }
+ }
+ } while (iternext());
+
+``NpyIter_GetCoords_Fn NpyIter_GetGetCoords(NpyIter *iter, char **errmsg)``
+
+ Returns a function pointer for getting the coordinates
+ of the iterator. Returns NULL if the iterator does not
+ support coordinates. It is recommended that this function
+ pointer be cached in a local variable before the iteration
+ loop.
+
+ Returns NULL if there is an error. If errmsg is non-NULL,
+ no Python exception is set when ``NPY_FAIL`` is returned.
+ Instead, \*errmsg is set to an error message. When errmsg is
+ non-NULL, the function may be safely called without holding
+ the Python GIL.
+
+``char **NpyIter_GetDataPtrArray(NpyIter *iter)``
+
+ This gives back a pointer to the ``niter`` data pointers. If
+ ``NPY_ITER_NO_INNER_ITERATION`` was not specified, each data
+ pointer points to the current data item of the iterator. If
+ no inner iteration was specified, it points to the first data
+ item of the inner loop.
+
+ This pointer may be cached before the iteration loop, calling
+ ``iternext`` will not change it. This function may be safely
+ called without holding the Python GIL.
+
+``npy_intp *NpyIter_GetIndexPtr(NpyIter *iter)``
+
+ This gives back a pointer to the index being tracked, or NULL
+ if no index is being tracked. It is only useable if one of
+ the flags ``NPY_ITER_C_INDEX`` or ``NPY_ITER_F_INDEX``
+ were specified during construction.
+
+When the flag ``NPY_ITER_NO_INNER_ITERATION`` is used, the code
+needs to know the parameters for doing the inner loop. These
+functions provide that information.
+
+``npy_intp *NpyIter_GetInnerStrideArray(NpyIter *iter)``
+
+ Returns a pointer to an array of the ``niter`` strides,
+ one for each iterated object, to be used by the inner loop.
+
+ This pointer may be cached before the iteration loop, calling
+ ``iternext`` will not change it. This function may be safely
+ called without holding the Python GIL.
+
+``npy_intp* NpyIter_GetInnerLoopSizePtr(NpyIter *iter)``
+
+ Returns a pointer to the number of iterations the
+ inner loop should execute.
+
+ This address may be cached before the iteration loop, calling
+ ``iternext`` will not change it. The value itself may change during
+ iteration, in particular if buffering is enabled. This function
+ may be safely called without holding the Python GIL.
+
+``void NpyIter_GetInnerFixedStrideArray(NpyIter *iter, npy_intp *out_strides)``
+
+ Gets an array of strides which are fixed, or will not change during
+ the entire iteration. For strides that may change, the value
+ NPY_MAX_INTP is placed in the stride.
+
+ Once the iterator is prepared for iteration (after a reset if
+ ``NPY_DELAY_BUFALLOC`` was used), call this to get the strides
+ which may be used to select a fast inner loop function. For example,
+ if the stride is 0, that means the inner loop can always load its
+ value into a variable once, then use the variable throughout the loop,
+ or if the stride equals the itemsize, a contiguous version for that
+ operand may be used.
+
+ This function may be safely called without holding the Python GIL.
+
+Examples
+--------
+
+A copy function using the iterator. The ``order`` parameter
+is used to control the memory layout of the allocated
+result.
+
+If the input is a reference type, this function will fail.
+To fix this, the code must be changed to specially handle writeable
+references, and add ``NPY_ITER_WRITEABLE_REFERENCES`` to the flags.::
+
+ /* NOTE: This code has not been compiled/tested */
+ PyObject *CopyArray(PyObject *arr, NPY_ORDER order)
+ {
+ NpyIter *iter;
+ NpyIter_IterNext_Fn iternext;
+ PyObject *op[2], *ret;
+ npy_uint32 flags;
+ npy_uint32 op_flags[2];
+ npy_intp itemsize, *innersizeptr, innerstride;
+ char **dataptrarray;
+
+ /*
+ * No inner iteration - inner loop is handled by CopyArray code
+ */
+ flags = NPY_ITER_NO_INNER_ITERATION;
+ /*
+ * Tell the constructor to automatically allocate the output.
+ * The data type of the output will match that of the input.
+ */
+ op[0] = arr;
+ op[1] = NULL;
+ op_flags[0] = NPY_ITER_READONLY;
+ op_flags[1] = NPY_ITER_WRITEONLY | NPY_ITER_ALLOCATE;
+
+ /* Construct the iterator */
+ iter = NpyIter_MultiNew(2, op, flags, order, NPY_NO_CASTING,
+ op_flags, NULL, 0, NULL);
+ if (iter == NULL) {
+ return NULL;
+ }
+
+ /*
+ * Make a copy of the iternext function pointer and
+ * a few other variables the inner loop needs.
+ */
+ iternext = NpyIter_GetIterNext(iter);
+ innerstride = NpyIter_GetInnerStrideArray(iter)[0];
+ itemsize = NpyIter_GetDescrArray(iter)[0]->elsize;
+ /*
+ * The inner loop size and data pointers may change during the
+ * loop, so just cache the addresses.
+ */
+ innersizeptr = NpyIter_GetInnerLoopSizePtr(iter);
+ dataptrarray = NpyIter_GetDataPtrArray(iter);
+
+ /*
+ * Note that because the iterator allocated the output,
+ * it matches the iteration order and is packed tightly,
+ * so we don't need to check it like the input.
+ */
+ if (innerstride == itemsize) {
+ do {
+ memcpy(dataptrarray[1], dataptrarray[0],
+ itemsize * (*innersizeptr));
+ } while (iternext(iter));
+ } else {
+ /* Should specialize this further based on item size... */
+ npy_intp i;
+ do {
+ npy_intp size = *innersizeptr;
+ char *src = dataaddr[0], *dst = dataaddr[1];
+ for(i = 0; i < size; i++, src += innerstride, dst += itemsize) {
+ memcpy(dst, src, itemsize);
+ }
+ } while (iternext(iter));
+ }
+
+ /* Get the result from the iterator object array */
+ ret = NpyIter_GetOperandArray(iter)[1];
+ Py_INCREF(ret);
+
+ if (NpyIter_Deallocate(iter) != NPY_SUCCEED) {
+ Py_DECREF(ret);
+ return NULL;
+ }
+
+ return ret;
+ }
+
+Python Lambda UFunc Example
+---------------------------
+
+To show how the new iterator allows the definition of efficient UFunc-like
+functions in pure Python, we demonstrate the function ``luf``, which
+makes a lambda-expression act like a UFunc. This is very similar to the
+``numexpr`` library, but only takes a few lines of code.
+
+First, here is the definition of the ``luf`` function.::
+
+ def luf(lamdaexpr, *args, **kwargs):
+ """Lambda UFunc
+
+ e.g.
+ c = luf(lambda i,j:i+j, a, b, order='K',
+ casting='safe', buffersize=8192)
+
+ c = np.empty(...)
+ luf(lambda i,j:i+j, a, b, out=c, order='K',
+ casting='safe', buffersize=8192)
+ """
+
+ nargs = len(args)
+ op = args + (kwargs.get('out',None),)
+ it = np.newiter(op, ['buffered','no_inner_iteration'],
+ [['readonly','nbo_aligned']]*nargs +
+ [['writeonly','allocate','no_broadcast']],
+ order=kwargs.get('order','K'),
+ casting=kwargs.get('casting','safe'),
+ buffersize=kwargs.get('buffersize',0))
+ while not it.finished:
+ it[-1] = lamdaexpr(*it[:-1])
+ it.iternext()
+
+ return it.operands[-1]
+
+Then, by using ``luf`` instead of straight Python expressions, we
+can gain some performance from better cache behavior.::
+
+ In [2]: a = np.random.random((50,50,50,10))
+ In [3]: b = np.random.random((50,50,1,10))
+ In [4]: c = np.random.random((50,50,50,1))
+
+ In [5]: timeit 3*a+b-(a/c)
+ 1 loops, best of 3: 138 ms per loop
+
+ In [6]: timeit luf(lambda a,b,c:3*a+b-(a/c), a, b, c)
+ 10 loops, best of 3: 60.9 ms per loop
+
+ In [7]: np.all(3*a+b-(a/c) == luf(lambda a,b,c:3*a+b-(a/c), a, b, c))
+ Out[7]: True
+
+
+Python Addition Example
+-----------------------
+
+The iterator has been mostly written and exposed to Python. To
+see how it behaves, let's see what we can do with the np.add ufunc.
+Even without changing the core of NumPy, we will be able to use
+the iterator to make a faster add function.
+
+The Python exposure supplies two iteration interfaces, one which
+follows the Python iterator protocol, and another which mirrors the
+C-style do-while pattern. The native Python approach is better
+in most cases, but if you need the iterator's coordinates or
+index, use the C-style pattern.
+
+Here is how we might write an ``iter_add`` function, using the
+Python iterator protocol.::
+
+ def iter_add_py(x, y, out=None):
+ addop = np.add
+
+ it = np.newiter([x,y,out], [],
+ [['readonly'],['readonly'],['writeonly','allocate']])
+
+ for (a, b, c) in it:
+ addop(a, b, c)
+
+ return it.operands[2]
+
+Here is the same function, but following the C-style pattern.::
+
+ def iter_add(x, y, out=None):
+ addop = np.add
+
+ it = np.newiter([x,y,out], [],
+ [['readonly'],['readonly'],['writeonly','allocate']])
+
+ while not it.finished:
+ addop(it[0], it[1], it[2])
+ it.iternext()
+
+ return it.operands[2]
+
+Some noteworthy points about this function:
+
+* Cache np.add as a local variable to reduce namespace lookups
+* Inputs are readonly, output is writeonly, and will be allocated
+ automatically if it is None.
+* Uses np.add's out parameter to avoid an extra copy.
+
+Let's create some test variables, and time this function as well as the
+built-in np.add.::
+
+ In [1]: a = np.arange(1000000,dtype='f4').reshape(100,100,100)
+ In [2]: b = np.arange(10000,dtype='f4').reshape(1,100,100)
+ In [3]: c = np.arange(10000,dtype='f4').reshape(100,100,1)
+
+ In [4]: timeit iter_add(a, b)
+ 1 loops, best of 3: 7.03 s per loop
+
+ In [5]: timeit np.add(a, b)
+ 100 loops, best of 3: 6.73 ms per loop
+
+At a thousand times slower, this is clearly not very good. One feature
+of the iterator, designed to help speed up the inner loops, is the flag
+``no_inner_iteration``. This is the same idea as the old iterator's
+``PyArray_IterAllButAxis``, but slightly smarter. Let's modify
+``iter_add`` to use this feature.::
+
+ def iter_add_noinner(x, y, out=None):
+ addop = np.add
+
+ it = np.newiter([x,y,out], ['no_inner_iteration'],
+ [['readonly'],['readonly'],['writeonly','allocate']])
+
+ for (a, b, c) in it:
+ addop(a, b, c)
+
+ return it.operands[2]
+
+The performance improves dramatically.::
+
+ In[6]: timeit iter_add_noinner(a, b)
+ 100 loops, best of 3: 7.1 ms per loop
+
+The performance is basically as good as the built-in function! It
+turns out this is because the iterator was able to coalesce the last two
+dimensions, resulting in 100 adds of 10000 elements each. If the
+inner loop doesn't become as large, the performance doesn't improve
+as dramatically. Let's use ``c`` instead of ``b`` to see how this works.::
+
+ In[7]: timeit iter_add_noinner(a, c)
+ 10 loops, best of 3: 76.4 ms per loop
+
+It's still a lot better than seven seconds, but still over ten times worse
+than the built-in function. Here, the inner loop has 100 elements,
+and it's iterating 10000 times. If we were coding in C, our performance
+would already be as good as the built-in performance, but in Python
+there is too much overhead.
+
+This leads us to another feature of the iterator, its ability to give
+us views of the iterated memory. The views it gives us are structured
+so that processing them in C-order, like the built-in NumPy code does,
+gives the same access order as the iterator itself. Effectively, we
+are using the iterator to solve for a good memory access pattern, then
+using other NumPy machinery to efficiently execute it. Let's
+modify ``iter_add`` once again.::
+
+ def iter_add_itview(x, y, out=None):
+ it = np.newiter([x,y,out], [],
+ [['readonly'],['readonly'],['writeonly','allocate']])
+
+ (a, b, c) = it.itviews
+ np.add(a, b, c)
+
+ return it.operands[2]
+
+Now the performance pretty closely matches the built-in function's.::
+
+ In [8]: timeit iter_add_itview(a, b)
+ 100 loops, best of 3: 6.18 ms per loop
+
+ In [9]: timeit iter_add_itview(a, c)
+ 100 loops, best of 3: 6.69 ms per loop
+
+Let us now step back to a case similar to the original motivation for the
+new iterator. Here are the same calculations in Fortran memory order instead
+Of C memory order.::
+
+ In [10]: a = np.arange(1000000,dtype='f4').reshape(100,100,100).T
+ In [12]: b = np.arange(10000,dtype='f4').reshape(100,100,1).T
+ In [11]: c = np.arange(10000,dtype='f4').reshape(1,100,100).T
+
+ In [39]: timeit np.add(a, b)
+ 10 loops, best of 3: 34.3 ms per loop
+
+ In [41]: timeit np.add(a, c)
+ 10 loops, best of 3: 31.6 ms per loop
+
+ In [44]: timeit iter_add_itview(a, b)
+ 100 loops, best of 3: 6.58 ms per loop
+
+ In [43]: timeit iter_add_itview(a, c)
+ 100 loops, best of 3: 6.33 ms per loop
+
+As you can see, the performance of the built-in function dropped
+significantly, but our newly-written add function maintained essentially
+the same performance. As one final test, let's try several adds chained
+together.::
+
+ In [4]: timeit np.add(np.add(np.add(a,b), c), a)
+ 1 loops, best of 3: 99.5 ms per loop
+
+ In [9]: timeit iter_add_itview(iter_add_itview(iter_add_itview(a,b), c), a)
+ 10 loops, best of 3: 29.3 ms per loop
+
+Also, just to check that it's doing the same thing,::
+
+ In [22]: np.all(
+ ....: iter_add_itview(iter_add_itview(iter_add_itview(a,b), c), a) ==
+ ....: np.add(np.add(np.add(a,b), c), a)
+ ....: )
+
+ Out[22]: True
+
+Image Compositing Example Revisited
+-----------------------------------
+
+For motivation, we had an example that did an 'over' composite operation
+on two images. Now let's see how we can write the function with
+the new iterator.
+
+Here is one of the original functions, for reference, and some
+random image data.::
+
+ In [5]: rand1 = np.random.random_sample(1080*1920*4).astype(np.float32)
+ In [6]: rand2 = np.random.random_sample(1080*1920*4).astype(np.float32)
+ In [7]: image1 = rand1.reshape(1080,1920,4).swapaxes(0,1)
+ In [8]: image2 = rand2.reshape(1080,1920,4).swapaxes(0,1)
+
+ In [3]: def composite_over(im1, im2):
+ ....: ret = (1-im1[:,:,-1])[:,:,np.newaxis]*im2
+ ....: ret += im1
+ ....: return ret
+
+ In [4]: timeit composite_over(image1,image2)
+ 1 loops, best of 3: 1.39 s per loop
+
+Here's the same function, rewritten to use a new iterator. Note how
+easy it was to add an optional output parameter.::
+
+ In [5]: def composite_over_it(im1, im2, out=None, buffersize=4096):
+ ....: it = np.newiter([im1, im1[:,:,-1], im2, out],
+ ....: ['buffered','no_inner_iteration'],
+ ....: [['readonly']]*3+[['writeonly','allocate']],
+ ....: op_axes=[None,[0,1,np.newaxis],None,None],
+ ....: buffersize=buffersize)
+ ....: while not it.finished:
+ ....: np.multiply(1-it[1], it[2], it[3])
+ ....: it[3] += it[0]
+ ....: it.iternext()
+ ....: return it.operands[3]
+
+ In [6]: timeit composite_over_it(image1, image2)
+ 1 loops, best of 3: 197 ms per loop
+
+A big speed improvement, over even the best previous attempt using
+straight NumPy and a C-order array! By playing with the buffer size, we can
+see how the speed improves until we hit the limits of the CPU cache
+in the inner loop.::
+
+ In [7]: timeit composite_over_it(image1, image2, buffersize=2**7)
+ 1 loops, best of 3: 1.23 s per loop
+
+ In [8]: timeit composite_over_it(image1, image2, buffersize=2**8)
+ 1 loops, best of 3: 699 ms per loop
+
+ In [9]: timeit composite_over_it(image1, image2, buffersize=2**9)
+ 1 loops, best of 3: 418 ms per loop
+
+ In [10]: timeit composite_over_it(image1, image2, buffersize=2**10)
+ 1 loops, best of 3: 287 ms per loop
+
+ In [11]: timeit composite_over_it(image1, image2, buffersize=2**11)
+ 1 loops, best of 3: 225 ms per loop
+
+ In [12]: timeit composite_over_it(image1, image2, buffersize=2**12)
+ 1 loops, best of 3: 194 ms per loop
+
+ In [13]: timeit composite_over_it(image1, image2, buffersize=2**13)
+ 1 loops, best of 3: 180 ms per loop
+
+ In [14]: timeit composite_over_it(image1, image2, buffersize=2**14)
+ 1 loops, best of 3: 192 ms per loop
+
+ In [15]: timeit composite_over_it(image1, image2, buffersize=2**15)
+ 1 loops, best of 3: 280 ms per loop
+
+ In [16]: timeit composite_over_it(image1, image2, buffersize=2**16)
+ 1 loops, best of 3: 328 ms per loop
+
+ In [17]: timeit composite_over_it(image1, image2, buffersize=2**17)
+ 1 loops, best of 3: 345 ms per loop
+
+And finally, to double check that it's working, we can compare the two
+functions.::
+
+ In [18]: np.all(composite_over(image1, image2) ==
+ ...: composite_over_it(image1, image2))
+ Out[18]: True
+
+Image Compositing With NumExpr
+------------------------------
+
+As a test of the iterator, numexpr has been enhanced to allow use of
+the iterator instead of its internal broadcasting code. First, let's
+implement the composite operation with numexpr.::
+
+ In [22]: def composite_over_ne(im1, im2, out=None):
+ ....: ima = im1[:,:,-1][:,:,np.newaxis]
+ ....: return ne.evaluate("im1+(1-ima)*im2")
+
+ In [23]: timeit composite_over_ne(image1,image2)
+ 1 loops, best of 3: 1.25 s per loop
+
+This beats the straight NumPy operation, but isn't very good. Switching
+to the iterator version of numexpr, we get a big improvement over the
+straight Python function using the iterator. Note that in this is on
+a dual core machine.::
+
+ In [29]: def composite_over_ne_it(im1, im2, out=None):
+ ....: ima = im1[:,:,-1][:,:,np.newaxis]
+ ....: return ne.evaluate_iter("im1+(1-ima)*im2")
+
+ In [30]: timeit composite_over_ne_it(image1,image2)
+ 10 loops, best of 3: 67.2 ms per loop
+
+ In [31]: ne.set_num_threads(1)
+ In [32]: timeit composite_over_ne_it(image1,image2)
+ 10 loops, best of 3: 91.1 ms per loop
+
diff --git a/doc/release/1.6.0-notes.rst b/doc/release/1.6.0-notes.rst
new file mode 100644
index 000000000..774b611e1
--- /dev/null
+++ b/doc/release/1.6.0-notes.rst
@@ -0,0 +1,94 @@
+=========================
+NumPy 1.6.0 Release Notes
+=========================
+
+This release includes several new features as well as numerous bug fixes and
+improved documentation. It is backward compatible with the 1.5.0 release, and
+supports Python 2.4 - 2.7 and 3.1 - 3.2.
+
+
+Highlights
+==========
+
+* Re-introduction of datetime dtype support to deal with dates in arrays.
+
+* A new 16-bit floating point type.
+
+* A new iterator, which improves performance of many functions.
+
+
+New features
+============
+
+New 16-bit floating point type
+------------------------------
+
+This release adds support for the IEEE 754-2008 binary16 format, available as
+the data type ``numpy.half``. Within Python, the type behaves similarly to
+`float` or `double`, and C extensions can add support for it with the exposed
+half-float API.
+
+
+Einstein summation convention evaluation function
+-------------------------------------------------
+
+
+
+
+Other new functions
+-------------------
+
+``numpy.ravel_coords`` : Converts a tuple of coordinate arrays into an array of
+flat indices, applying boundary modes to the coordinates.
+
+``numpy.slogdet`` : Compute the sign and (natural) logarithm of the determinant
+of an array.
+
+
+
+Changes
+=======
+
+
+
+Removed features
+================
+
+``numpy.fft``
+-------------
+
+The functions `refft`, `refft2`, `refftn`, `irefft`, `irefft2`, `irefftn`,
+which were aliases for the same functions without the 'e' in the name, were
+removed.
+
+
+``numpy.memmap``
+----------------
+
+The `sync()` and `close()` methods of memmap were removed. Use `flush()` and
+"del memmap" instead.
+
+
+``numpy.lib``
+-------------
+
+The deprecated functions ``numpy.unique1d``, ``numpy.setmember1d``,
+``numpy.intersect1d_nu`` and ``numpy.lib.ufunclike.log2`` were removed.
+
+
+``numpy.ma``
+------------
+
+Several deprecated items were removed from the ``numpy.ma`` module::
+
+ * ``numpy.ma.MaskedArray`` "raw_data" method
+ * ``numpy.ma.MaskedArray`` constructor "flag" keyword
+ * ``numpy.ma.make_mask`` "flag" keyword
+ * ``numpy.ma.allclose`` "fill_value" keyword
+
+
+``numpy.distutils``
+-------------------
+
+The ``numpy.get_numpy_include`` function was removed, use ``numpy.get_include``
+instead.
diff --git a/doc/release/2.0.0-notes.rst b/doc/release/2.0.0-notes.rst
index 3953960a4..cb5bdf14b 100644
--- a/doc/release/2.0.0-notes.rst
+++ b/doc/release/2.0.0-notes.rst
@@ -10,13 +10,6 @@ Highlights
New features
============
-New 16-bit floating point type
-------------------------------
-
-This release adds support for the IEEE 754-2008 binary16
-format, available as the data type `numpy.half`. Within Python,
-the type behaves similarly to `float` or `double`, and C extensions
-can add support for it with the exposed half-float API.
Changes
=======
diff --git a/doc/source/reference/arrays.ndarray.rst b/doc/source/reference/arrays.ndarray.rst
index c14e6869a..535ce8faa 100644
--- a/doc/source/reference/arrays.ndarray.rst
+++ b/doc/source/reference/arrays.ndarray.rst
@@ -254,6 +254,7 @@ Array conversion
ndarray.item
ndarray.tolist
ndarray.itemset
+ ndarray.setasflat
ndarray.tostring
ndarray.tofile
ndarray.dump
diff --git a/doc/source/reference/c-api.array.rst b/doc/source/reference/c-api.array.rst
index 49d073b7e..62746eb49 100644
--- a/doc/source/reference/c-api.array.rst
+++ b/doc/source/reference/c-api.array.rst
@@ -158,6 +158,24 @@ From scratch
*dims* and *strides* are copied into newly allocated dimension and
strides arrays for the new array object.
+.. cfunction:: PyObject* PyArray_NewLikeArray(PyArrayObject* prototype, NPY_ORDER order, PyArray_Descr* descr)
+
+ .. versionadded:: 1.6
+
+ This function steals a reference to *descr* if it is not NULL.
+
+ This array creation routine allows for the convenient creation of
+ a new array matching an existing array's shapes and memory layout,
+ possibly changing the layout and/or data type.
+
+ When *order* is :cdata:`NPY_ANYORDER`, the result order is
+ :cdata:`NPY_FORTRANORDER` if *prototype* is a fortran array,
+ :cdata:`NPY_CORDER` otherwise. When *order* is
+ :cdata:`NPY_KEEPORDER`, the result order matches that of *prototype*, even
+ when the axes of *prototype* aren't in C or Fortran order.
+
+ If *descr* is NULL, the data type of *prototype* is used.
+
.. cfunction:: PyObject* PyArray_New(PyTypeObject* subtype, int nd, npy_intp* dims, int type_num, npy_intp* strides, void* data, int itemsize, int flags, PyObject* obj)
This is similar to :cfunc:`PyArray_DescrNew` (...) except you
@@ -358,26 +376,88 @@ From other objects
:cdata:`NPY_F_CONTIGUOUS` \| :cdata:`NPY_ALIGNED`
- .. cvar:: NPY_INOUT_ARRAY
+ .. cvar:: NPY_OUT_ARRAY
:cdata:`NPY_C_CONTIGUOUS` \| :cdata:`NPY_WRITEABLE` \|
:cdata:`NPY_ALIGNED`
- .. cvar:: NPY_INOUT_FARRAY
+ .. cvar:: NPY_OUT_FARRAY
:cdata:`NPY_F_CONTIGUOUS` \| :cdata:`NPY_WRITEABLE` \|
:cdata:`NPY_ALIGNED`
- .. cvar:: NPY_OUT_ARRAY
+ .. cvar:: NPY_INOUT_ARRAY
:cdata:`NPY_C_CONTIGUOUS` \| :cdata:`NPY_WRITEABLE` \|
:cdata:`NPY_ALIGNED` \| :cdata:`NPY_UPDATEIFCOPY`
- .. cvar:: NPY_OUT_FARRAY
+ .. cvar:: NPY_INOUT_FARRAY
:cdata:`NPY_F_CONTIGUOUS` \| :cdata:`NPY_WRITEABLE` \|
- :cdata:`NPY_ALIGNED` \| :cdata:`UPDATEIFCOPY`
+ :cdata:`NPY_ALIGNED` \| :cdata:`NPY_UPDATEIFCOPY`
+
+.. cfunction:: int PyArray_GetArrayParamsFromObject(PyObject* op, PyArray_Descr* requested_dtype, npy_bool writeable, PyArray_Descr** out_dtype, int* out_ndim, npy_intp* out_dims, PyArrayObject** out_arr, PyObject* context)
+
+ .. versionadded:: 1.6
+
+ Retrieves the array parameters for viewing/converting an arbitrary
+ PyObject* to a NumPy array. This allows the "innate type and shape"
+ of Python list-of-lists to be discovered without
+ actually converting to an array. PyArray_FromAny calls this function
+ to analyze its input.
+
+ In some cases, such as structured arrays and the __array__ interface,
+ a data type needs to be used to make sense of the object. When
+ this is needed, provide a Descr for 'requested_dtype', otherwise
+ provide NULL. This reference is not stolen. Also, if the requested
+ dtype doesn't modify the interpretation of the input, out_dtype will
+ still get the "innate" dtype of the object, not the dtype passed
+ in 'requested_dtype'.
+
+ If writing to the value in 'op' is desired, set the boolean
+ 'writeable' to 1. This raises an error when 'op' is a scalar, list
+ of lists, or other non-writeable 'op'. This differs from passing
+ NPY_WRITEABLE to PyArray_FromAny, where the writeable array may
+ be a copy of the input.
+
+ When success (0 return value) is returned, either out_arr
+ is filled with a non-NULL PyArrayObject and
+ the rest of the parameters are untouched, or out_arr is
+ filled with NULL, and the rest of the parameters are filled.
+ Typical usage:
+
+ .. code-block:: c
+
+ PyArrayObject *arr = NULL;
+ PyArray_Descr *dtype = NULL;
+ int ndim = 0;
+ npy_intp dims[NPY_MAXDIMS];
+
+ if (PyArray_GetArrayParamsFromObject(op, NULL, 1, &dtype,
+ &ndim, &dims, &arr, NULL) < 0) {
+ return NULL;
+ }
+ if (arr == NULL) {
+ ... validate/change dtype, validate flags, ndim, etc ...
+ // Could make custom strides here too
+ arr = PyArray_NewFromDescr(&PyArray_Type, dtype, ndim,
+ dims, NULL,
+ fortran ? NPY_F_CONTIGUOUS : 0,
+ NULL);
+ if (arr == NULL) {
+ return NULL;
+ }
+ if (PyArray_CopyObject(arr, op) < 0) {
+ Py_DECREF(arr);
+ return NULL;
+ }
+ }
+ else {
+ ... in this case the other parameters weren't filled, just
+ validate and possibly copy arr itself ...
+ }
+ ... use arr ...
.. cfunction:: PyObject* PyArray_CheckFromAny(PyObject* op, PyArray_Descr* dtype, int min_depth, int max_depth, int requirements, PyObject* context)
@@ -817,6 +897,9 @@ Converting data types
.. cfunction:: int PyArray_CastTo(PyArrayObject* out, PyArrayObject* in)
+ As of 1.6, this function simply calls :cfunc:`PyArray_CopyInto`,
+ which handles the casting.
+
Cast the elements of the array *in* into the array *out*. The
output array should be writeable, have an integer-multiple of the
number of elements in the input array (more than one copy can be
@@ -844,15 +927,63 @@ Converting data types
.. cfunction:: int PyArray_CanCastTo(PyArray_Descr* fromtype, PyArray_Descr* totype)
+ :cfunc:`PyArray_CanCastTypeTo` supercedes this function in
+ NumPy 1.6 and later.
+
+ Equivalent to PyArray_CanCastTypeTo(fromtype, totype, NPY_SAFE_CASTING).
+
+.. cfunction:: int PyArray_CanCastTypeTo(PyArray_Descr* fromtype, PyArray_Descr* totype, NPY_CASTING casting)
+
+ .. versionadded:: 1.6
+
Returns non-zero if an array of data type *fromtype* (which can
include flexible types) can be cast safely to an array of data
- type *totype* (which can include flexible types). This is
- basically a wrapper around :cfunc:`PyArray_CanCastSafely` with
- additional support for size checking if *fromtype* and *totype*
- are :cdata:`NPY_STRING` or :cdata:`NPY_UNICODE`.
+ type *totype* (which can include flexible types) according to
+ the casting rule *casting*. For simple types with :cdata:`NPY_SAFE_CASTING`,
+ this is basically a wrapper around :cfunc:`PyArray_CanCastSafely`, but
+ for flexible types such as strings or unicode, it produces results
+ taking into account their sizes.
+
+.. cfunction:: int PyArray_CanCastArrayTo(PyArrayObject* arr, PyArray_Descr* totype, NPY_CASTING casting)
+
+ .. versionadded:: 1.6
+
+ Returns non-zero if *arr* can be cast to *totype* according
+ to the casting rule given in *casting*. If *arr* is an array
+ scalar, its value is taken into account, and non-zero is also
+ returned when the value will not overflow or be truncated to
+ an integer when converting to a smaller type.
+
+.. cfunction:: PyArray_Descr* PyArray_MinScalarType(PyArrayObject* arr)
+
+ .. versionadded:: 1.6
+
+ If *arr* is an array, returns its data type descriptor, but if
+ *arr* is an array scalar (has 0 dimensions), it finds the data type
+ of smallest kind and size to which the value may be converted
+ without overflow or truncation to an integer.
+
+.. cfunction:: PyArray_Descr* PyArray_PromoteTypes(PyArray_Descr* type1, PyArray_Descr* type2)
+
+ .. versionadded:: 1.6
+
+ Finds the data type of smallest size and kind to which *type1* and
+ *type2* may be safely converted.
+
+.. cfunction:: PyArray_Descr* PyArray_ResultType(npy_intp narrs, PyArrayObject**arrs, npy_intp ndtypes, PyArray_Descr**dtypes)
+
+ .. versionadded:: 1.6
+
+ This applies PyArray_PromoteTypes to all the inputs, along with
+ using the NumPy rules for combining scalars and arrays, to
+ determine the output type of a set of operands. This is the
+ same result type that ufuncs produce.
.. cfunction:: int PyArray_ObjectType(PyObject* op, int mintype)
+ This function is superceded by :cfunc:`PyArray_MinScalarType` and/or
+ :cfunc:`PyArray_ResultType`.
+
This function is useful for determining a common type that two or
more arrays can be converted to. It only works for non-flexible
array types as no itemsize information is passed. The *mintype*
@@ -863,6 +994,8 @@ Converting data types
.. cfunction:: void PyArray_ArrayType(PyObject* op, PyArray_Descr* mintype, PyArray_Descr* outtype)
+ This function is superceded by :cfunc:`PyArray_ResultType`.
+
This function works similarly to :cfunc:`PyArray_ObjectType` (...)
except it handles flexible arrays. The *mintype* argument can have
an itemsize member and the *outtype* argument will have an
@@ -871,6 +1004,11 @@ Converting data types
.. cfunction:: PyArrayObject** PyArray_ConvertToCommonType(PyObject* op, int* n)
+ The functionality this provides is largely superceded by iterator
+ :ctype:`NpyIter` introduced in 1.6, with flag
+ :cdata:`NPY_ITER_COMMON_DTYPE` or with the same dtype parameter for
+ all operands.
+
Convert a sequence of Python objects contained in *op* to an array
of ndarrays each having the same data type. The type is selected
based on the typenumber (larger type number is chosen over a
@@ -1018,8 +1156,8 @@ getting (and, if appropriate, setting) these flags.
Memory areas of all kinds can be pointed to by an ndarray,
necessitating these flags. If you get an arbitrary ``PyArrayObject``
in C-code, you need to be aware of the flags that are set. If you
-need to guarantee a certain kind of array (like ``NPY_CONTIGUOUS`` and
-``NPY_BEHAVED``), then pass these requirements into the
+need to guarantee a certain kind of array (like :cdata:`NPY_C_CONTIGUOUS` and
+:cdata:`NPY_BEHAVED`), then pass these requirements into the
PyArray_FromAny function.
@@ -1044,10 +1182,10 @@ associated with an array.
The data area is in Fortran-style contiguous order (first index varies
the fastest).
-Notice that contiguous 1-d arrays are always both ``NPY_FORTRAN``
+Notice that contiguous 1-d arrays are always both Fortran
contiguous and C contiguous. Both of these flags can be checked and
are convenience flags only as whether or not an array is
-``NPY_CONTIGUOUS`` or ``NPY_FORTRAN`` can be determined by the
+:cdata:`NPY_C_CONTIGUOUS` or :cdata:`NPY_F_CONTIGUOUS` can be determined by the
``strides``, ``dimensions``, and ``itemsize`` attributes.
.. cvar:: NPY_OWNDATA
@@ -1085,7 +1223,7 @@ are convenience flags only as whether or not an array is
:cfunc:`PyArray_UpdateFlags` (obj, flags) will update the
``obj->flags`` for ``flags`` which can be any of
-:cdata:`NPY_CONTIGUOUS`, :cdata:`NPY_FORTRAN`, :cdata:`NPY_ALIGNED`,
+:cdata:`NPY_C_CONTIGUOUS`, :cdata:`NPY_F_CONTIGUOUS`, :cdata:`NPY_ALIGNED`,
or :cdata:`NPY_WRITEABLE`.
@@ -1532,6 +1670,12 @@ Item selection and manipulation
). Return the *offset* diagonals of the 2-d arrays defined by
*axis1* and *axis2*.
+.. cfunction:: npy_intp PyArray_CountNonzero(PyArrayObject* self)
+
+ .. versionadded:: 1.6
+
+ Counts the number of non-zero elements in the array object *self*.
+
.. cfunction:: PyObject* PyArray_Nonzero(PyArrayObject* self)
Equivalent to :meth:`ndarray.nonzero` (*self*). Returns a tuple of index
@@ -1747,6 +1891,29 @@ Array Functions
second-to-last dimension of *obj2*. For 2-d arrays this is a
matrix-product. Neither array is conjugated.
+.. cfunction:: PyObject* PyArray_MatrixProduct2(PyObject* obj1, PyObject* obj, PyObject* out)
+
+ .. versionadded:: 1.6
+
+ Same as PyArray_MatrixProduct, but store the result in *out*. The
+ output array must have the correct shape, type, and be
+ C-contiguous, or an exception is raised.
+
+.. cfunction:: PyObject* PyArray_EinsteinSum(char* subscripts, npy_intp nop, PyArrayObject** op_in, PyArray_Descr* dtype, NPY_ORDER order, NPY_CASTING casting, PyArrayObject* out)
+
+ .. versionadded:: 1.6
+
+ Applies the einstein summation convention to the array operands
+ provided, returning a new array or placing the result in *out*.
+ The string in *subscripts* is a comma separated list of index
+ letters. The number of operands is in *nop*, and *op_in* is an
+ array containing those operands. The data type of the output can
+ be forced with *dtype*, the output order can be forced with *order*
+ (:cdata:`NPY_KEEPORDER` is recommended), and when *dtype* is specified,
+ *casting* indicates how permissive the data conversion should be.
+
+ See the :func:`einsum` function for more details.
+
.. cfunction:: PyObject* PyArray_CopyAndTranspose(PyObject \* op)
A specialized copy and transpose function that works only for 2-d
@@ -1827,6 +1994,9 @@ Other functions
Array Iterators
---------------
+As of Numpy 1.6, these array iterators are superceded by
+the new array iterator, :ctype:`NpyIter`.
+
An array iterator is a simple way to access the elements of an
N-dimensional array quickly and efficiently. Section `2
<#sec-array-iterator>`__ provides more description and examples of
@@ -2339,6 +2509,19 @@ to.
Convert Python strings into one of :cdata:`NPY_SEARCHLEFT` (starts with 'l'
or 'L'), or :cdata:`NPY_SEARCHRIGHT` (starts with 'r' or 'R').
+.. cfunction:: int PyArray_OrderConverter(PyObject* obj, NPY_ORDER* order)
+
+ Convert the Python strings 'C', 'F', 'A', and 'K' into the :ctype:`NPY_ORDER`
+ enumeration :cdata:`NPY_CORDER`, :cdata:`NPY_FORTRANORDER`,
+ :cdata:`NPY_ANYORDER`, and :cdata:`NPY_KEEPORDER`.
+
+.. cfunction:: int PyArray_CastingConverter(PyObject* obj, NPY_CASTING* casting)
+
+ Convert the Python strings 'no', 'equiv', 'safe', 'same_kind', and
+ 'unsafe' into the NPY_CASTING enumeration :cdata:`NPY_NO_CASTING`,
+ :cdata:`NPY_EQUIV_CASTING`, :cdata:`NPY_SAFE_CASTING`,
+ :cdata:`NPY_SAME_KIND_CASTING`, and :cdata:`NPY_UNSAFE_CASTING`.
+
Other conversions
^^^^^^^^^^^^^^^^^
@@ -2801,7 +2984,6 @@ Enumerated Types
**INTNEG_SCALAR**, **FLOAT_SCALAR**, **COMPLEX_SCALAR**,
**OBJECT_SCALAR**
-
.. cvar:: NPY_NSCALARKINDS
Defined to be the number of scalar kinds
@@ -2809,11 +2991,27 @@ Enumerated Types
.. ctype:: NPY_ORDER
- A variable type indicating the order that an array should be
- interpreted in. The value of a variable of this type can be
- :cdata:`NPY_{ORDER}` where ``{ORDER}`` is
+ An enumeration type indicating the element order that an array should be
+ interpreted in. When a brand new array is created, generally
+ only **NPY_CORDER** and **NPY_FORTRANORDER** are used, whereas
+ when one or more inputs are provided, the order can be based on them.
- **ANYORDER**, **CORDER**, **FORTRANORDER**
+ .. cvar:: NPY_ANYORDER
+
+ Fortran order if all the inputs are Fortran, C otherwise.
+
+ .. cvar:: NPY_CORDER
+
+ C order.
+
+ .. cvar:: NPY_FORTRANORDER
+
+ Fortran order.
+
+ .. cvar:: NPY_KEEPORDER
+
+ An order as close to the order of the inputs as possible, even
+ if the input is in neither C nor Fortran order.
.. ctype:: NPY_CLIPMODE
@@ -2823,5 +3021,35 @@ Enumerated Types
**CLIP**, **WRAP**, **RAISE**
+.. ctype:: NPY_CASTING
+
+ .. versionadded:: 1.6
+
+ An enumeration type indicating how permissive data conversions should
+ be. This is used by the iterator added in NumPy 1.6, and is intended
+ to be used more broadly in a future version.
+
+ .. cvar:: NPY_NO_CASTING
+
+ Only allow identical types.
+
+ .. cvar:: NPY_EQUIV_CASTING
+
+ Allow identical and casts involving byte swapping.
+
+ .. cvar:: NPY_SAFE_CASTING
+
+ Only allow casts which will not cause values to be rounded,
+ truncated, or otherwise changed.
+
+ .. cvar:: NPY_SAME_KIND_CASTING
+
+ Allow any safe casts, and casts between types of the same kind.
+ For example, float64 -> float32 is permitted with this rule.
+
+ .. cvar:: NPY_UNSAFE_CASTING
+
+ Allow any cast, no matter what kind of data loss may occur.
+
.. index::
pair: ndarray; C-API
diff --git a/doc/source/reference/c-api.iterator.rst b/doc/source/reference/c-api.iterator.rst
new file mode 100644
index 000000000..5e88ee9d2
--- /dev/null
+++ b/doc/source/reference/c-api.iterator.rst
@@ -0,0 +1,1144 @@
+Array Iterator API
+==================
+
+.. sectionauthor:: Mark Wiebe
+
+.. index::
+ pair: iterator; C-API
+ pair: C-API; iterator
+
+.. versionadded:: 1.6
+
+Array Iterator
+--------------
+
+The array iterator encapsulates many of the key features in ufuncs,
+allowing user code to support features like output parameters,
+preservation of memory layouts, and buffering of data with the wrong
+alignment or type, without requiring difficult coding.
+
+This page documents the API for the iterator.
+The C-API naming convention chosen is based on the one in the numpy-refactor
+branch, so will integrate naturally into the refactored code base.
+The iterator is named ``NpyIter`` and functions are
+named ``NpyIter_*``.
+
+Converting from Previous NumPy Iterators
+----------------------------------------
+
+The existing iterator API includes functions like PyArrayIter_Check,
+PyArray_Iter* and PyArray_ITER_*. The multi-iterator array includes
+PyArray_MultiIter*, PyArray_Broadcast, and PyArray_RemoveSmallest. The
+new iterator design replaces all of this functionality with a single object
+and associated API. One goal of the new API is that all uses of the
+existing iterator should be replaceable with the new iterator without
+significant effort. In 1.6, the major exception to this is the neighborhood
+iterator, which does not have corresponding features in this iterator.
+
+Here is a conversion table for which functions to use with the new iterator:
+
+===================================== =============================================
+*Iterator Functions*
+:cfunc:`PyArray_IterNew` :cfunc:`NpyIter_New`
+:cfunc:`PyArray_IterAllButAxis` :cfunc:`NpyIter_New` + ``axes`` parameter **or**
+ Iterator flag :cdata:`NPY_ITER_NO_INNER_ITERATION`
+:cfunc:`PyArray_BroadcastToShape` **NOT SUPPORTED** (Use the support for
+ multiple operands instead.)
+:cfunc:`PyArrayIter_Check` Will need to add this in Python exposure
+:cfunc:`PyArray_ITER_RESET` :cfunc:`NpyIter_Reset`
+:cfunc:`PyArray_ITER_NEXT` Function pointer from :cfunc:`NpyIter_GetIterNext`
+:cfunc:`PyArray_ITER_DATA` :cfunc:`NpyIter_GetDataPtrArray`
+:cfunc:`PyArray_ITER_GOTO` :cfunc:`NpyIter_GotoCoords`
+:cfunc:`PyArray_ITER_GOTO1D` :cfunc:`NpyIter_GotoIndex` or
+ :cfunc:`NpyIter_GotoIterIndex`
+:cfunc:`PyArray_ITER_NOTDONE` Return value of ``iternext`` function pointer
+*Multi-iterator Functions*
+:cfunc:`PyArray_MultiIterNew` :cfunc:`NpyIter_MultiNew`
+:cfunc:`PyArray_MultiIter_RESET` :cfunc:`NpyIter_Reset`
+:cfunc:`PyArray_MultiIter_NEXT` Function pointer from :cfunc:`NpyIter_GetIterNext`
+:cfunc:`PyArray_MultiIter_DATA` :cfunc:`NpyIter_GetDataPtrArray`
+:cfunc:`PyArray_MultiIter_NEXTi` **NOT SUPPORTED** (always lock-step iteration)
+:cfunc:`PyArray_MultiIter_GOTO` :cfunc:`NpyIter_GotoCoords`
+:cfunc:`PyArray_MultiIter_GOTO1D` :cfunc:`NpyIter_GotoIndex` or
+ :cfunc:`NpyIter_GotoIterIndex`
+:cfunc:`PyArray_MultiIter_NOTDONE` Return value of ``iternext`` function pointer
+:cfunc:`PyArray_Broadcast` Handled by :cfunc:`NpyIter_MultiNew`
+:cfunc:`PyArray_RemoveSmallest` Iterator flag :cdata:`NPY_ITER_NO_INNER_ITERATION`
+*Other Functions*
+:cfunc:`PyArray_ConvertToCommonType` Iterator flag :cdata:`NPY_ITER_COMMON_DTYPE`
+===================================== =============================================
+
+Simple Iteration Example
+------------------------
+
+The best way to become familiar with the iterator is to look at its
+usage within the NumPy codebase itself. For example, here is a slightly
+tweaked version of the code for :cfunc:`PyArray_CountNonzero`, which counts the
+number of non-zero elements in an array.
+
+.. code-block:: c
+
+ npy_intp PyArray_CountNonzero(PyArrayObject* self)
+ {
+ /* Nonzero boolean function */
+ PyArray_NonzeroFunc* nonzero = PyArray_DESCR(self)->f->nonzero;
+
+ NpyIter* iter;
+ NpyIter_IterNextFunc *iternext;
+ char** dataptr;
+ npy_intp* strideptr,* innersizeptr;
+
+ /* Handle zero-sized arrays specially */
+ if (PyArray_SIZE(self) == 0) {
+ return 0;
+ }
+
+ /*
+ * Create and use an iterator to count the nonzeros.
+ * flag NPY_ITER_READONLY
+ * - The array is never written to.
+ * flag NPY_ITER_NO_INNER_ITERATION
+ * - Inner loop is done outside the iterator for efficiency.
+ * flag NPY_ITER_NPY_ITER_REFS_OK
+ * - Reference types are acceptable.
+ * order NPY_KEEPORDER
+ * - Visit elements in memory order, regardless of strides.
+ * This is good for performance when the specific order
+ * elements are visited is unimportant.
+ * casting NPY_NO_CASTING
+ * - No casting is required for this operation.
+ */
+ iter = NpyIter_New(self, NPY_ITER_READONLY|
+ NPY_ITER_NO_INNER_ITERATION|
+ NPY_ITER_REFS_OK,
+ NPY_KEEPORDER, NPY_NO_CASTING,
+ NULL, 0, NULL, 0);
+ if (iter == NULL) {
+ return -1;
+ }
+
+ /*
+ * The iternext function gets stored in a local variable
+ * so it can be called repeatedly in an efficient manner.
+ */
+ iternext = NpyIter_GetIterNext(iter, NULL);
+ if (iternext == NULL) {
+ NpyIter_Deallocate(iter);
+ return -1;
+ }
+ /* The location of the data pointer which the iterator may update */
+ dataptr = NpyIter_GetDataPtrArray(iter);
+ /* The location of the stride which the iterator may update */
+ strideptr = NpyIter_GetInnerStrideArray(iter);
+ /* The location of the inner loop size which the iterator may update */
+ innersizeptr = NpyIter_GetInnerLoopSizePtr(iter);
+
+ /* The iteration loop */
+ do {
+ /* Get the inner loop data/stride/count values */
+ char* data = *dataptr;
+ npy_intp stride = *strideptr;
+ npy_intp count = *innersizeptr;
+
+ /* This is a typical inner loop for NPY_ITER_NO_INNER_ITERATION */
+ while (count--) {
+ if (nonzero(data, self)) {
+ ++nonzero_count;
+ }
+ data += stride;
+ }
+
+ /* Increment the iterator to the next inner loop */
+ } while(iternext(iter));
+
+ NpyIter_Deallocate(iter);
+
+ return nonzero_count;
+ }
+
+Simple Multi-Iteration Example
+------------------------------
+
+Here is a simple copy function using the iterator. The ``order`` parameter
+is used to control the memory layout of the allocated result, typically
+:cdata:`NPY_KEEPORDER` is desired.
+
+.. code-block:: c
+
+ PyObject *CopyArray(PyObject *arr, NPY_ORDER order)
+ {
+ NpyIter *iter;
+ NpyIter_IterNextFunc *iternext;
+ PyObject *op[2], *ret;
+ npy_uint32 flags;
+ npy_uint32 op_flags[2];
+ npy_intp itemsize, *innersizeptr, innerstride;
+ char **dataptrarray;
+
+ /*
+ * No inner iteration - inner loop is handled by CopyArray code
+ */
+ flags = NPY_ITER_NO_INNER_ITERATION;
+ /*
+ * Tell the constructor to automatically allocate the output.
+ * The data type of the output will match that of the input.
+ */
+ op[0] = arr;
+ op[1] = NULL;
+ op_flags[0] = NPY_ITER_READONLY;
+ op_flags[1] = NPY_ITER_WRITEONLY | NPY_ITER_ALLOCATE;
+
+ /* Construct the iterator */
+ iter = NpyIter_MultiNew(2, op, flags, order, NPY_NO_CASTING,
+ op_flags, NULL, 0, NULL);
+ if (iter == NULL) {
+ return NULL;
+ }
+
+ /*
+ * Make a copy of the iternext function pointer and
+ * a few other variables the inner loop needs.
+ */
+ iternext = NpyIter_GetIterNext(iter);
+ innerstride = NpyIter_GetInnerStrideArray(iter)[0];
+ itemsize = NpyIter_GetDescrArray(iter)[0]->elsize;
+ /*
+ * The inner loop size and data pointers may change during the
+ * loop, so just cache the addresses.
+ */
+ innersizeptr = NpyIter_GetInnerLoopSizePtr(iter);
+ dataptrarray = NpyIter_GetDataPtrArray(iter);
+
+ /*
+ * Note that because the iterator allocated the output,
+ * it matches the iteration order and is packed tightly,
+ * so we don't need to check it like the input.
+ */
+ if (innerstride == itemsize) {
+ do {
+ memcpy(dataptrarray[1], dataptrarray[0],
+ itemsize * (*innersizeptr));
+ } while (iternext(iter));
+ } else {
+ /* For efficiency, should specialize this based on item size... */
+ npy_intp i;
+ do {
+ npy_intp size = *innersizeptr;
+ char *src = dataaddr[0], *dst = dataaddr[1];
+ for(i = 0; i < size; i++, src += innerstride, dst += itemsize) {
+ memcpy(dst, src, itemsize);
+ }
+ } while (iternext(iter));
+ }
+
+ /* Get the result from the iterator object array */
+ ret = NpyIter_GetOperandArray(iter)[1];
+ Py_INCREF(ret);
+
+ if (NpyIter_Deallocate(iter) != NPY_SUCCEED) {
+ Py_DECREF(ret);
+ return NULL;
+ }
+
+ return ret;
+ }
+
+
+Iterator Data Types
+---------------------
+
+The iterator layout is an internal detail, and user code only sees
+an incomplete struct.
+
+.. ctype:: NpyIter
+
+ This is an opaque pointer type for the iterator. Access to its contents
+ can only be done through the iterator API.
+
+.. ctype:: NpyIter_IterNextFunc
+
+ This is a function pointer for the iteration loop, returned by
+ :cfunc:`NpyIter_GetIterNext`.
+
+.. ctype:: NpyIter_GetCoordsFunc
+
+ This is a function pointer for getting iterator coordinates, returned by
+ :cfunc:`NpyIter_GetGetCoords`.
+
+Construction and Destruction
+----------------------------
+
+.. cfunction:: NpyIter* NpyIter_New(PyArrayObject* op, npy_uint32 flags, NPY_ORDER order, NPY_CASTING casting, PyArray_Descr* dtype, int a_ndim, int* axes, npy_intp buffersize)
+
+ Creates an iterator for the given numpy array object ``op``.
+
+ Flags that may be passed in ``flags`` are any combination
+ of the global and per-operand flags documented in
+ :cfunc:`NpyIter_MultiNew`, except for :cdata:`NPY_ITER_ALLOCATE`.
+
+ Any of the :ctype:`NPY_ORDER` enum values may be passed to ``order``. For
+ efficient iteration, :ctype:`NPY_KEEPORDER` is the best option, and
+ the other orders enforce the particular iteration pattern.
+
+ Any of the :ctype:`NPY_CASTING` enum values may be passed to ``casting``.
+ The values include :cdata:`NPY_NO_CASTING`, :cdata:`NPY_EQUIV_CASTING`,
+ :cdata:`NPY_SAFE_CASTING`, :cdata:`NPY_SAME_KIND_CASTING`, and
+ :cdata:`NPY_UNSAFE_CASTING`. To allow the casts to occur, copying or
+ buffering must also be enabled.
+
+ If ``dtype`` isn't ``NULL``, then it requires that data type.
+ If copying is allowed, it will make a temporary copy if the data
+ is castable. If :cdata:`NPY_ITER_UPDATEIFCOPY` is enabled, it will
+ also copy the data back with another cast upon iterator destruction.
+
+ If ``a_ndim`` is greater than zero, ``axes`` must also be provided.
+ In this case, ``axes`` is an ``a_ndim``-sized array of ``op``'s axes.
+ A value of -1 in ``axes`` means ``newaxis``. Within the ``axes``
+ array, axes may not be repeated.
+
+ If ``buffersize`` is zero, a default buffer size is used,
+ otherwise it specifies how big of a buffer to use. Buffers
+ which are powers of 2 such as 512 or 1024 are recommended.
+
+ Returns NULL if there is an error, otherwise returns the allocated
+ iterator.
+
+ To make an iterator similar to the old iterator, this should work.
+
+ .. code-block:: c
+
+ iter = NpyIter_New(op, NPY_ITER_READWRITE,
+ NPY_CORDER, NPY_NO_CASTING, NULL, 0, NULL);
+
+ If you want to edit an array with aligned ``double`` code,
+ but the order doesn't matter, you would use this.
+
+ .. code-block:: c
+
+ dtype = PyArray_DescrFromType(NPY_DOUBLE);
+ iter = NpyIter_New(op, NPY_ITER_READWRITE |
+ NPY_ITER_BUFFERED |
+ NPY_ITER_NBO|
+ NPY_ITER_ALIGNED,
+ NPY_KEEPORDER,
+ NPY_SAME_KIND_CASTING,
+ dtype, 0, NULL);
+ Py_DECREF(dtype);
+
+.. cfunction:: NpyIter* NpyIter_MultiNew(npy_intp niter, PyArrayObject** op, npy_uint32 flags, NPY_ORDER order, NPY_CASTING casting, npy_uint32* op_flags, PyArray_Descr** op_dtypes, int oa_ndim, int** op_axes, npy_intp buffersize)
+
+ Creates an iterator for broadcasting the ``niter`` array objects provided
+ in ``op``.
+
+ For normal usage, use 0 for ``oa_ndim`` and NULL for ``op_axes``.
+ See below for a description of these parameters, which allow for
+ custom manual broadcasting as well as reordering and leaving out axes.
+
+ Any of the :ctype:`NPY_ORDER` enum values may be passed to ``order``. For
+ efficient iteration, :cdata:`NPY_KEEPORDER` is the best option, and the
+ other orders enforce the particular iteration pattern. When using
+ :cdata:`NPY_KEEPORDER`, if you also want to ensure that the iteration is
+ not reversed along an axis, you should pass the flag
+ :cdata:`NPY_ITER_DONT_NEGATE_STRIDES`.
+
+ Any of the :ctype:`NPY_CASTING` enum values may be passed to ``casting``.
+ The values include :cdata:`NPY_NO_CASTING`, :cdata:`NPY_EQUIV_CASTING`,
+ :cdata:`NPY_SAFE_CASTING`, :cdata:`NPY_SAME_KIND_CASTING`, and
+ :cdata:`NPY_UNSAFE_CASTING`. To allow the casts to occur, copying or
+ buffering must also be enabled.
+
+ If ``op_dtypes`` isn't ``NULL``, it specifies a data type or ``NULL``
+ for each ``op[i]``.
+
+ The parameter ``oa_ndim``, when non-zero, specifies the number of
+ dimensions that will be iterated with customized broadcasting.
+ If it is provided, ``op_axes`` must also be provided.
+ These two parameters let you control in detail how the
+ axes of the operand arrays get matched together and iterated.
+ In ``op_axes``, you must provide an array of ``niter`` pointers
+ to ``oa_ndim``-sized arrays of type ``npy_intp``. If an entry
+ in ``op_axes`` is NULL, normal broadcasting rules will apply.
+ In ``op_axes[j][i]`` is stored either a valid axis of ``op[j]``, or
+ -1 which means ``newaxis``. Within each ``op_axes[j]`` array, axes
+ may not be repeated. The following example is how normal broadcasting
+ applies to a 3-D array, a 2-D array, a 1-D array and a scalar.
+
+ .. code-block:: c
+
+ int oa_ndim = 3; /* # iteration axes */
+ int op0_axes[] = {0, 1, 2}; /* 3-D operand */
+ int op1_axes[] = {-1, 0, 1}; /* 2-D operand */
+ int op2_axes[] = {-1, -1, 0}; /* 1-D operand */
+ int op3_axes[] = {-1, -1, -1} /* 0-D (scalar) operand */
+ int* op_axes[] = {op0_axes, op1_axes, op2_axes, op3_axes};
+
+ If ``buffersize`` is zero, a default buffer size is used,
+ otherwise it specifies how big of a buffer to use. Buffers
+ which are powers of 2 such as 512 or 1024 are recommended.
+
+ Returns NULL if there is an error, otherwise returns the allocated
+ iterator.
+
+ Flags that may be passed in ``flags``, applying to the whole
+ iterator, are:
+
+ .. cvar:: NPY_ITER_C_INDEX
+
+ Causes the iterator to track a raveled flat index matching C
+ order. This option cannot be used with :cdata:`NPY_ITER_F_INDEX`.
+
+ .. cvar:: NPY_ITER_F_INDEX
+
+ Causes the iterator to track a raveled flat index matching Fortran
+ order. This option cannot be used with :cdata:`NPY_ITER_C_INDEX`.
+
+ .. cvar:: NPY_ITER_COORDS
+
+ Causes the iterator to track array coordinates.
+ This prevents the iterator from coalescing axes to
+ produce bigger inner loops.
+
+ .. cvar:: NPY_ITER_NO_INNER_ITERATION
+
+ Causes the iterator to skip iteration of the innermost
+ loop, allowing the user of the iterator to handle it.
+
+ This flag is incompatible with :cdata:`NPY_ITER_C_INDEX`,
+ :cdata:`NPY_ITER_F_INDEX`, and :cdata:`NPY_ITER_COORDS`.
+
+ .. cvar:: NPY_ITER_DONT_NEGATE_STRIDES
+
+ This only affects the iterator when :ctype:`NPY_KEEPORDER` is
+ specified for the order parameter. By default with
+ :ctype:`NPY_KEEPORDER`, the iterator reverses axes which have
+ negative strides, so that memory is traversed in a forward
+ direction. This disables this step. Use this flag if you
+ want to use the underlying memory-ordering of the axes,
+ but don't want an axis reversed. This is the behavior of
+ ``numpy.ravel(a, order='K')``, for instance.
+
+ .. cvar:: NPY_ITER_COMMON_DTYPE
+
+ Causes the iterator to convert all the operands to a common
+ data type, calculated based on the ufunc type promotion rules.
+ Copying or buffering must be enabled.
+
+ If the common data type is known ahead of time, don't use this
+ flag. Instead, set the requested dtype for all the operands.
+
+ .. cvar:: NPY_ITER_REFS_OK
+
+ Indicates that arrays with reference types (object
+ arrays or structured arrays containing an object type)
+ may be accepted and used in the iterator. If this flag
+ is enabled, the caller must be sure to check whether
+ :cfunc:`NpyIter_IterationNeedsAPI`(iter) is true, in which case
+ it may not release the GIL during iteration.
+
+ .. cvar:: NPY_ITER_ZEROSIZE_OK
+
+ Indicates that arrays with a size of zero should be permitted.
+ Since the typical iteration loop does not naturally work with
+ zero-sized arrays, you must check that the IterSize is non-zero
+ before entering the iteration loop.
+
+ .. cvar:: NPY_ITER_REDUCE_OK
+
+ Permits writeable operands with a dimension with zero
+ stride and size greater than one. Note that such operands
+ must be read/write.
+
+ When buffering is enabled, this also switches to a special
+ buffering mode which reduces the loop length as necessary to
+ not trample on values being reduced.
+
+ Note that if you want to do a reduction on an automatically
+ allocated output, you must use :cfunc:`NpyIter_GetOperandArray`
+ to get its reference, then set every value to the reduction
+ unit before doing the iteration loop. In the case of a
+ buffered reduction, this means you must also specify the
+ flag :cdata:`NPY_ITER_DELAY_BUFALLOC`, then reset the iterator
+ after initializing the allocated operand to prepare the
+ buffers.
+
+ .. cvar:: NPY_ITER_RANGED
+
+ Enables support for iteration of sub-ranges of the full
+ ``iterindex`` range ``[0, NpyIter_IterSize(iter))``. Use
+ the function :cfunc:`NpyIter_ResetToIterIndexRange` to specify
+ a range for iteration.
+
+ This flag can only be used with :cdata:`NPY_ITER_NO_INNER_ITERATION`
+ when :cdata:`NPY_ITER_BUFFERED` is enabled. This is because
+ without buffering, the inner loop is always the size of the
+ innermost iteration dimension, and allowing it to get cut up
+ would require special handling, effectively making it more
+ like the buffered version.
+
+ .. cvar:: NPY_ITER_BUFFERED
+
+ Causes the iterator to store buffering data, and use buffering
+ to satisfy data type, alignment, and byte-order requirements.
+ To buffer an operand, do not specify the :cdata:`NPY_ITER_COPY`
+ or :cdata:`NPY_ITER_UPDATEIFCOPY` flags, because they will
+ override buffering. Buffering is especially useful for Python
+ code using the iterator, allowing for larger chunks
+ of data at once to amortize the Python interpreter overhead.
+
+ If used with :cdata:`NPY_ITER_NO_INNER_ITERATION`, the inner loop
+ for the caller may get larger chunks than would be possible
+ without buffering, because of how the strides are laid out.
+
+ Note that if an operand is given the flag :cdata:`NPY_ITER_COPY`
+ or :cdata:`NPY_ITER_UPDATEIFCOPY`, a copy will be made in preference
+ to buffering. Buffering will still occur when the array was
+ broadcast so elements need to be duplicated to get a constant
+ stride.
+
+ In normal buffering, the size of each inner loop is equal
+ to the buffer size, or possibly larger if
+ :cdata:`NPY_ITER_GROWINNER` is specified. If
+ :cdata:`NPY_ITER_REDUCE_OK` is enabled and a reduction occurs,
+ the inner loops may become smaller depending
+ on the structure of the reduction.
+
+ .. cvar:: NPY_ITER_GROWINNER
+
+ When buffering is enabled, this allows the size of the inner
+ loop to grow when buffering isn't necessary. This option
+ is best used if you're doing a straight pass through all the
+ data, rather than anything with small cache-friendly arrays
+ of temporary values for each inner loop.
+
+ .. cvar:: NPY_ITER_DELAY_BUFALLOC
+
+ When buffering is enabled, this delays allocation of the
+ buffers until :cfunc:`NpyIter_Reset` or another reset function is
+ called. This flag exists to avoid wasteful copying of
+ buffer data when making multiple copies of a buffered
+ iterator for multi-threaded iteration.
+
+ Another use of this flag is for setting up reduction operations.
+ After the iterator is created, and a reduction output
+ is allocated automatically by the iterator (be sure to use
+ READWRITE access), its value may be initialized to the reduction
+ unit. Use :cfunc:`NpyIter_GetOperandArray` to get the object.
+ Then, call :cfunc:`NpyIter_Reset` to allocate and fill the buffers
+ with their initial values.
+
+ Flags that may be passed in ``op_flags[i]``, where ``0 <= i < niter``:
+
+ .. cvar:: NPY_ITER_READWRITE
+ .. cvar:: NPY_ITER_READONLY
+ .. cvar:: NPY_ITER_WRITEONLY
+
+ Indicate how the user of the iterator will read or write
+ to ``op[i]``. Exactly one of these flags must be specified
+ per operand.
+
+ .. cvar:: NPY_ITER_COPY
+
+ Allow a copy of ``op[i]`` to be made if it does not
+ meet the data type or alignment requirements as specified
+ by the constructor flags and parameters.
+
+ .. cvar:: NPY_ITER_UPDATEIFCOPY
+
+ Triggers :cdata:`NPY_ITER_COPY`, and when an array operand
+ is flagged for writing and is copied, causes the data
+ in a copy to be copied back to ``op[i]`` when the iterator
+ is destroyed.
+
+ If the operand is flagged as write-only and a copy is needed,
+ an uninitialized temporary array will be created and then copied
+ to back to ``op[i]`` on destruction, instead of doing
+ the unecessary copy operation.
+
+ .. cvar:: NPY_ITER_NBO
+ .. cvar:: NPY_ITER_ALIGNED
+ .. cvar:: NPY_ITER_CONTIG
+
+ Causes the iterator to provide data for ``op[i]``
+ that is in native byte order, aligned according to
+ the dtype requirements, contiguous, or any combination.
+
+ By default, the iterator produces pointers into the
+ arrays provided, which may be aligned or unaligned, and
+ with any byte order. If copying or buffering is not
+ enabled and the operand data doesn't satisfy the constraints,
+ an error will be raised.
+
+ The contiguous constraint applies only to the inner loop,
+ successive inner loops may have arbitrary pointer changes.
+
+ If the requested data type is in non-native byte order,
+ the NBO flag overrides it and the requested data type is
+ converted to be in native byte order.
+
+ .. cvar:: NPY_ITER_ALLOCATE
+
+ This is for output arrays, and requires that the flag
+ :cdata:`NPY_ITER_WRITEONLY` be set. If ``op[i]`` is NULL,
+ creates a new array with the final broadcast dimensions,
+ and a layout matching the iteration order of the iterator.
+
+ When ``op[i]`` is NULL, the requested data type
+ ``op_dtypes[i]`` may be NULL as well, in which case it is
+ automatically generated from the dtypes of the arrays which
+ are flagged as readable. The rules for generating the dtype
+ are the same is for UFuncs. Of special note is handling
+ of byte order in the selected dtype. If there is exactly
+ one input, the input's dtype is used as is. Otherwise,
+ if more than one input dtypes are combined together, the
+ output will be in native byte order.
+
+ After being allocated with this flag, the caller may retrieve
+ the new array by calling :cfunc:`NpyIter_GetOperandArray` and
+ getting the i-th object in the returned C array. The caller
+ must call Py_INCREF on it to claim a reference to the array.
+
+ .. cvar:: NPY_ITER_NO_SUBTYPE
+
+ For use with :cdata:`NPY_ITER_ALLOCATE`, this flag disables
+ allocating an array subtype for the output, forcing
+ it to be a straight ndarray.
+
+ TODO: Maybe it would be better to introduce a function
+ ``NpyIter_GetWrappedOutput`` and remove this flag?
+
+ .. cvar:: NPY_ITER_NO_BROADCAST
+
+ Ensures that the input or output matches the iteration
+ dimensions exactly.
+
+.. cfunction:: NpyIter* NpyIter_Copy(NpyIter* iter)
+
+ Makes a copy of the given iterator. This function is provided
+ primarily to enable multi-threaded iteration of the data.
+
+ *TODO*: Move this to a section about multithreaded iteration.
+
+ The recommended approach to multithreaded iteration is to
+ first create an iterator with the flags
+ :cdata:`NPY_ITER_NO_INNER_ITERATION`, :cdata:`NPY_ITER_RANGED`,
+ :cdata:`NPY_ITER_BUFFERED`, :cdata:`NPY_ITER_DELAY_BUFALLOC`, and
+ possibly :cdata:`NPY_ITER_GROWINNER`. Create a copy of this iterator
+ for each thread (minus one for the first iterator). Then, take
+ the iteration index range ``[0, NpyIter_GetIterSize(iter))`` and
+ split it up into tasks, for example using a TBB parallel_for loop.
+ When a thread gets a task to execute, it then uses its copy of
+ the iterator by calling :cfunc:`NpyIter_ResetToIterIndexRange` and
+ iterating over the full range.
+
+ When using the iterator in multi-threaded code or in code not
+ holding the Python GIL, care must be taken to only call functions
+ which are safe in that context. :cfunc:`NpyIter_Copy` cannot be safely
+ called without the Python GIL, because it increments Python
+ references. The ``Reset*`` and some other functions may be safely
+ called by passing in the ``errmsg`` parameter as non-NULL, so that
+ the functions will pass back errors through it instead of setting
+ a Python exception.
+
+.. cfunction:: int NpyIter_RemoveAxis(NpyIter* iter, int axis)``
+
+ Removes an axis from iteration. This requires that
+ :cdata:`NPY_ITER_COORDS` was set for iterator creation, and does not work
+ if buffering is enabled or an index is being tracked. This function
+ also resets the iterator to its initial state.
+
+ This is useful for setting up an accumulation loop, for example.
+ The iterator can first be created with all the dimensions, including
+ the accumulation axis, so that the output gets created correctly.
+ Then, the accumulation axis can be removed, and the calculation
+ done in a nested fashion.
+
+ **WARNING**: This function may change the internal memory layout of
+ the iterator. Any cached functions or pointers from the iterator
+ must be retrieved again!
+
+ Returns ``NPY_SUCCEED`` or ``NPY_FAIL``.
+
+
+.. cfunction:: int NpyIter_RemoveCoords(NpyIter* iter)
+
+ If the iterator has coordinates, this strips support for them, and
+ does further iterator optimizations that are possible if coordinates
+ are not needed. This function also resets the iterator to its initial
+ state.
+
+ **WARNING**: This function may change the internal memory layout of
+ the iterator. Any cached functions or pointers from the iterator
+ must be retrieved again!
+
+ After calling this function, :cfunc:`NpyIter_HasCoords`(iter) will
+ return false.
+
+ Returns ``NPY_SUCCEED`` or ``NPY_FAIL``.
+
+.. cfunction:: int NpyIter_RemoveInnerLoop(NpyIter* iter)
+
+ If RemoveCoords was used, you may want to specify the
+ flag :cdata:`NPY_ITER_NO_INNER_ITERATION`. This flag is not permitted
+ together with :cdata:`NPY_ITER_COORDS`, so this function is provided
+ to enable the feature after :cfunc:`NpyIter_RemoveCoords` is called.
+ This function also resets the iterator to its initial state.
+
+ **WARNING**: This function changes the internal logic of the iterator.
+ Any cached functions or pointers from the iterator must be retrieved
+ again!
+
+ Returns ``NPY_SUCCEED`` or ``NPY_FAIL``.
+
+.. cfunction:: int NpyIter_Deallocate(NpyIter* iter)
+
+ Deallocates the iterator object. This additionally frees any
+ copies made, triggering UPDATEIFCOPY behavior where necessary.
+
+ Returns ``NPY_SUCCEED`` or ``NPY_FAIL``.
+
+.. cfunction:: int NpyIter_Reset(NpyIter* iter, char** errmsg)
+
+ Resets the iterator back to its initial state, at the beginning
+ of the iteration range.
+
+ Returns ``NPY_SUCCEED`` or ``NPY_FAIL``. If errmsg is non-NULL,
+ no Python exception is set when ``NPY_FAIL`` is returned.
+ Instead, \*errmsg is set to an error message. When errmsg is
+ non-NULL, the function may be safely called without holding
+ the Python GIL.
+
+.. cfunction:: int NpyIter_ResetToIterIndexRange(NpyIter* iter, npy_intp istart, npy_intp iend, char** errmsg)
+
+ Resets the iterator and restricts it to the ``iterindex`` range
+ ``[istart, iend)``. See :cfunc:`NpyIter_Copy` for an explanation of
+ how to use this for multi-threaded iteration. This requires that
+ the flag :cdata:`NPY_ITER_RANGED` was passed to the iterator constructor.
+
+ If you want to reset both the ``iterindex`` range and the base
+ pointers at the same time, you can do the following to avoid
+ extra buffer copying (be sure to add the return code error checks
+ when you copy this code).
+
+ .. code-block:: c
+
+ /* Set to a trivial empty range */
+ NpyIter_ResetToIterIndexRange(iter, 0, 0);
+ /* Set the base pointers */
+ NpyIter_ResetBasePointers(iter, baseptrs);
+ /* Set to the desired range */
+ NpyIter_ResetToIterIndexRange(iter, istart, iend);
+
+ Returns ``NPY_SUCCEED`` or ``NPY_FAIL``. If errmsg is non-NULL,
+ no Python exception is set when ``NPY_FAIL`` is returned.
+ Instead, \*errmsg is set to an error message. When errmsg is
+ non-NULL, the function may be safely called without holding
+ the Python GIL.
+
+.. cfunction:: int NpyIter_ResetBasePointers(NpyIter *iter, char** baseptrs, char** errmsg)
+
+ Resets the iterator back to its initial state, but using the values
+ in ``baseptrs`` for the data instead of the pointers from the arrays
+ being iterated. This functions is intended to be used, together with
+ the ``op_axes`` parameter, by nested iteration code with two or more
+ iterators.
+
+ Returns ``NPY_SUCCEED`` or ``NPY_FAIL``. If errmsg is non-NULL,
+ no Python exception is set when ``NPY_FAIL`` is returned.
+ Instead, \*errmsg is set to an error message. When errmsg is
+ non-NULL, the function may be safely called without holding
+ the Python GIL.
+
+ *TODO*: Move the following into a special section on nested iterators.
+
+ Creating iterators for nested iteration requires some care. All
+ the iterator operands must match exactly, or the calls to
+ :cfunc:`NpyIter_ResetBasePointers` will be invalid. This means that
+ automatic copies and output allocation should not be used haphazardly.
+ It is possible to still use the automatic data conversion and casting
+ features of the iterator by creating one of the iterators with
+ all the conversion parameters enabled, then grabbing the allocated
+ operands with the :cfunc:`NpyIter_GetOperandArray` function and passing
+ them into the constructors for the rest of the iterators.
+
+ **WARNING**: When creating iterators for nested iteration,
+ the code must not use a dimension more than once in the different
+ iterators. If this is done, nested iteration will produce
+ out-of-bounds pointers during iteration.
+
+ **WARNING**: When creating iterators for nested iteration, buffering
+ can only be applied to the innermost iterator. If a buffered iterator
+ is used as the source for ``baseptrs``, it will point into a small buffer
+ instead of the array and the inner iteration will be invalid.
+
+ The pattern for using nested iterators is as follows.
+
+ .. code-block:: c
+
+ NpyIter *iter1, *iter1;
+ NpyIter_IterNextFunc *iternext1, *iternext2;
+ char **dataptrs1;
+
+ /*
+ * With the exact same operands, no copies allowed, and
+ * no axis in op_axes used both in iter1 and iter2.
+ * Buffering may be enabled for iter2, but not for iter1.
+ */
+ iter1 = ...; iter2 = ...;
+
+ iternext1 = NpyIter_GetIterNext(iter1);
+ iternext2 = NpyIter_GetIterNext(iter2);
+ dataptrs1 = NpyIter_GetDataPtrArray(iter1);
+
+ do {
+ NpyIter_ResetBasePointers(iter2, dataptrs1);
+ do {
+ /* Use the iter2 values */
+ } while (iternext2(iter2));
+ } while (iternext1(iter1));
+
+.. cfunction:: int NpyIter_GotoCoords(NpyIter* iter, npy_intp* coords)
+
+ Adjusts the iterator to point to the ``ndim`` coordinates
+ pointed to by ``coords``. Returns an error if coordinates
+ are not being tracked, the coordinates are out of bounds,
+ or inner loop iteration is disabled.
+
+ Returns ``NPY_SUCCEED`` or ``NPY_FAIL``.
+
+.. cfunction:: int NpyIter_GotoIndex(NpyIter* iter, npy_intp index)
+
+ Adjusts the iterator to point to the ``index`` specified.
+ If the iterator was constructed with the flag
+ :cdata:`NPY_ITER_C_INDEX`, ``index`` is the C-order index,
+ and if the iterator was constructed with the flag
+ :cdata:`NPY_ITER_F_INDEX`, ``index`` is the Fortran-order
+ index. Returns an error if there is no index being tracked,
+ the index is out of bounds, or inner loop iteration is disabled.
+
+ Returns ``NPY_SUCCEED`` or ``NPY_FAIL``.
+
+.. cfunction:: npy_intp NpyIter_GetIterSize(NpyIter* iter)
+
+ Returns the number of elements being iterated. This is the product
+ of all the dimensions in the shape.
+
+.. cfunction:: npy_intp NpyIter_GetIterIndex(NpyIter* iter)
+
+ Gets the ``iterindex`` of the iterator, which is an index matching
+ the iteration order of the iterator.
+
+.. cfunction:: void NpyIter_GetIterIndexRange(NpyIter* iter, npy_intp* istart, npy_intp* iend)
+
+ Gets the ``iterindex`` sub-range that is being iterated. If
+ :cdata:`NPY_ITER_RANGED` was not specified, this always returns the
+ range ``[0, NpyIter_IterSize(iter))``.
+
+.. cfunction:: int NpyIter_GotoIterIndex(NpyIter* iter, npy_intp iterindex)
+
+ Adjusts the iterator to point to the ``iterindex`` specified.
+ The IterIndex is an index matching the iteration order of the iterator.
+ Returns an error if the ``iterindex`` is out of bounds,
+ buffering is enabled, or inner loop iteration is disabled.
+
+ Returns ``NPY_SUCCEED`` or ``NPY_FAIL``.
+
+.. cfunction:: npy_bool NpyIter_HasDelayedBufAlloc(NpyIter* iter)
+
+ Returns 1 if the flag :cdata:`NPY_ITER_DELAY_BUFALLOC` was passed
+ to the iterator constructor, and no call to one of the Reset
+ functions has been done yet, 0 otherwise.
+
+.. cfunction:: npy_bool NpyIter_HasInnerLoop(NpyIter* iter)
+
+ Returns 1 if the iterator handles the inner loop,
+ or 0 if the caller needs to handle it. This is controlled
+ by the constructor flag :cdata:`NPY_ITER_NO_INNER_ITERATION`.
+
+.. cfunction:: npy_bool NpyIter_HasCoords(NpyIter* iter)
+
+ Returns 1 if the iterator was created with the
+ :cdata:`NPY_ITER_COORDS` flag, 0 otherwise.
+
+.. cfunction:: npy_bool NpyIter_HasIndex(NpyIter* iter)
+
+ Returns 1 if the iterator was created with the
+ :cdata:`NPY_ITER_C_INDEX` or :cdata:`NPY_ITER_F_INDEX`
+ flag, 0 otherwise.
+
+.. cfunction:: npy_bool NpyIter_RequiresBuffering(NpyIter* iter)
+
+ Returns 1 if the iterator requires buffering, which occurs
+ when an operand needs conversion or alignment and so cannot
+ be used directly.
+
+.. cfunction:: npy_bool NpyIter_IsBuffered(NpyIter* iter)
+
+ Returns 1 if the iterator was created with the
+ :cdata:`NPY_ITER_BUFFERED` flag, 0 otherwise.
+
+.. cfunction:: npy_bool NpyIter_IsGrowInner(NpyIter* iter)
+
+ Returns 1 if the iterator was created with the
+ :cdata:`NPY_ITER_GROWINNER` flag, 0 otherwise.
+
+.. cfunction:: npy_intp NpyIter_GetBufferSize(NpyIter* iter)
+
+ If the iterator is buffered, returns the size of the buffer
+ being used, otherwise returns 0.
+
+.. cfunction:: int NpyIter_GetNDim(NpyIter* iter)
+
+ Returns the number of dimensions being iterated. If coordinates
+ were not requested in the iterator constructor, this value
+ may be smaller than the number of dimensions in the original
+ objects.
+
+.. cfunction:: int NpyIter_GetNIter(NpyIter* iter)
+
+ Returns the number of operands in the iterator.
+
+.. cfunction:: npy_intp* NpyIter_GetAxisStrideArray(NpyIter* iter, int axis)
+
+ Gets the array of strides for the specified axis. Requires that
+ the iterator be tracking coordinates, and that buffering not
+ be enabled.
+
+ This may be used when you want to match up operand axes in
+ some fashion, then remove them with :cfunc:`NpyIter_RemoveAxis` to
+ handle their processing manually. By calling this function
+ before removing the axes, you can get the strides for the
+ manual processing.
+
+ Returns ``NULL`` on error.
+
+.. cfunction:: int NpyIter_GetShape(NpyIter* iter, npy_intp* outshape)
+
+ Returns the broadcast shape of the iterator in ``outshape``.
+ This can only be called on an iterator which supports coordinates.
+
+ Returns ``NPY_SUCCEED`` or ``NPY_FAIL``.
+
+.. cfunction:: PyArray_Descr** NpyIter_GetDescrArray(NpyIter* iter)
+
+ This gives back a pointer to the ``niter`` data type Descrs for
+ the objects being iterated. The result points into ``iter``,
+ so the caller does not gain any references to the Descrs.
+
+ This pointer may be cached before the iteration loop, calling
+ ``iternext`` will not change it.
+
+.. cfunction:: PyObject** NpyIter_GetOperandArray(NpyIter* iter)
+
+ This gives back a pointer to the ``niter`` operand PyObjects
+ that are being iterated. The result points into ``iter``,
+ so the caller does not gain any references to the PyObjects.
+
+.. cfunction:: PyObject* NpyIter_GetIterView(NpyIter* iter, npy_intp i)
+
+ This gives back a reference to a new ndarray view, which is a view
+ into the i-th object in the array :cfunc:`NpyIter_GetOperandArray`(),
+ whose dimensions and strides match the internal optimized
+ iteration pattern. A C-order iteration of this view is equivalent
+ to the iterator's iteration order.
+
+ For example, if an iterator was created with a single array as its
+ input, and it was possible to rearrange all its axes and then
+ collapse it into a single strided iteration, this would return
+ a view that is a one-dimensional array.
+
+.. cfunction:: void NpyIter_GetReadFlags(NpyIter* iter, char* outreadflags)
+
+ Fills ``niter`` flags. Sets ``outreadflags[i]`` to 1 if
+ ``op[i]`` can be read from, and to 0 if not.
+
+.. cfunction:: void NpyIter_GetWriteFlags(NpyIter* iter, char* outwriteflags)
+
+ Fills ``niter`` flags. Sets ``outwriteflags[i]`` to 1 if
+ ``op[i]`` can be written to, and to 0 if not.
+
+Functions For Iteration
+-----------------------
+
+.. cfunction:: NpyIter_IterNextFunc* NpyIter_GetIterNext(NpyIter* iter, char** errmsg)
+
+ Returns a function pointer for iteration. A specialized version
+ of the function pointer may be calculated by this function
+ instead of being stored in the iterator structure. Thus, to
+ get good performance, it is required that the function pointer
+ be saved in a variable rather than retrieved for each loop iteration.
+
+ Returns NULL if there is an error. If errmsg is non-NULL,
+ no Python exception is set when ``NPY_FAIL`` is returned.
+ Instead, \*errmsg is set to an error message. When errmsg is
+ non-NULL, the function may be safely called without holding
+ the Python GIL.
+
+ The typical looping construct is as follows.
+
+ .. code-block:: c
+
+ NpyIter_IterNextFunc *iternext = NpyIter_GetIterNext(iter, NULL);
+ char** dataptr = NpyIter_GetDataPtrArray(iter);
+
+ do {
+ /* use the addresses dataptr[0], ... dataptr[niter-1] */
+ } while(iternext(iter));
+
+ When :cdata:`NPY_ITER_NO_INNER_ITERATION` is specified, the typical
+ inner loop construct is as follows.
+
+ .. code-block:: c
+
+ NpyIter_IterNextFunc *iternext = NpyIter_GetIterNext(iter, NULL);
+ char** dataptr = NpyIter_GetDataPtrArray(iter);
+ npy_intp* stride = NpyIter_GetInnerStrideArray(iter);
+ npy_intp* size_ptr = NpyIter_GetInnerLoopSizePtr(iter), size;
+ npy_intp iiter, niter = NpyIter_GetNIter(iter);
+
+ do {
+ size = *size_ptr;
+ while (size--) {
+ /* use the addresses dataptr[0], ... dataptr[niter-1] */
+ for (iiter = 0; iiter < niter; ++iiter) {
+ dataptr[iiter] += stride[iiter];
+ }
+ }
+ } while (iternext());
+
+ Observe that we are using the dataptr array inside the iterator, not
+ copying the values to a local temporary. This is possible because
+ when ``iternext()`` is called, these pointers will be overwritten
+ with fresh values, not incrementally updated.
+
+ If a compile-time fixed buffer is being used (both flags
+ :cdata:`NPY_ITER_BUFFERED` and :cdata:`NPY_ITER_NO_INNER_ITERATION`), the
+ inner size may be used as a signal as well. The size is guaranteed
+ to become zero when ``iternext()`` returns false, enabling the
+ following loop construct. Note that if you use this construct,
+ you should not pass :cdata:`NPY_ITER_GROWINNER` as a flag, because it
+ will cause larger sizes under some circumstances.
+
+ .. code-block:: c
+
+ /* The constructor should have buffersize passed as this value */
+ #define FIXED_BUFFER_SIZE 1024
+
+ NpyIter_IterNextFunc *iternext = NpyIter_GetIterNext(iter, NULL);
+ char **dataptr = NpyIter_GetDataPtrArray(iter);
+ npy_intp *stride = NpyIter_GetInnerStrideArray(iter);
+ npy_intp *size_ptr = NpyIter_GetInnerLoopSizePtr(iter), size;
+ npy_intp i, iiter, niter = NpyIter_GetNIter(iter);
+
+ /* One loop with a fixed inner size */
+ size = *size_ptr;
+ while (size == FIXED_BUFFER_SIZE) {
+ /*
+ * This loop could be manually unrolled by a factor
+ * which divides into FIXED_BUFFER_SIZE
+ */
+ for (i = 0; i < FIXED_BUFFER_SIZE; ++i) {
+ /* use the addresses dataptr[0], ... dataptr[niter-1] */
+ for (iiter = 0; iiter < niter; ++iiter) {
+ dataptr[iiter] += stride[iiter];
+ }
+ }
+ iternext();
+ size = *size_ptr;
+ }
+
+ /* Finish-up loop with variable inner size */
+ if (size > 0) do {
+ size = *size_ptr;
+ while (size--) {
+ /* use the addresses dataptr[0], ... dataptr[niter-1] */
+ for (iiter = 0; iiter < niter; ++iiter) {
+ dataptr[iiter] += stride[iiter];
+ }
+ }
+ } while (iternext());
+
+.. cfunction:: NpyIter_GetCoordsFunc *NpyIter_GetGetCoords(NpyIter* iter, char** errmsg)
+
+ Returns a function pointer for getting the coordinates
+ of the iterator. Returns NULL if the iterator does not
+ support coordinates. It is recommended that this function
+ pointer be cached in a local variable before the iteration
+ loop.
+
+ Returns NULL if there is an error. If errmsg is non-NULL,
+ no Python exception is set when ``NPY_FAIL`` is returned.
+ Instead, \*errmsg is set to an error message. When errmsg is
+ non-NULL, the function may be safely called without holding
+ the Python GIL.
+
+.. cfunction:: char** NpyIter_GetDataPtrArray(NpyIter* iter)
+
+ This gives back a pointer to the ``niter`` data pointers. If
+ :cdata:`NPY_ITER_NO_INNER_ITERATION` was not specified, each data
+ pointer points to the current data item of the iterator. If
+ no inner iteration was specified, it points to the first data
+ item of the inner loop.
+
+ This pointer may be cached before the iteration loop, calling
+ ``iternext`` will not change it. This function may be safely
+ called without holding the Python GIL.
+
+.. cfunction:: char** NpyIter_GetInitialDataPtrArray(NpyIter* iter)
+
+ Gets the array of data pointers directly into the arrays (never
+ into the buffers), corresponding to iteration index 0.
+
+ These pointers are different from the pointers accepted by
+ ``NpyIter_ResetBasePointers``, because the direction along
+ some axes may have been reversed.
+
+ This function may be safely called without holding the Python GIL.
+
+.. cfunction:: npy_intp* NpyIter_GetIndexPtr(NpyIter* iter)
+
+ This gives back a pointer to the index being tracked, or NULL
+ if no index is being tracked. It is only useable if one of
+ the flags :cdata:`NPY_ITER_C_INDEX` or :cdata:`NPY_ITER_F_INDEX`
+ were specified during construction.
+
+When the flag :cdata:`NPY_ITER_NO_INNER_ITERATION` is used, the code
+needs to know the parameters for doing the inner loop. These
+functions provide that information.
+
+.. cfunction:: npy_intp* NpyIter_GetInnerStrideArray(NpyIter* iter)
+
+ Returns a pointer to an array of the ``niter`` strides,
+ one for each iterated object, to be used by the inner loop.
+
+ This pointer may be cached before the iteration loop, calling
+ ``iternext`` will not change it. This function may be safely
+ called without holding the Python GIL.
+
+.. cfunction:: npy_intp* NpyIter_GetInnerLoopSizePtr(NpyIter* iter)
+
+ Returns a pointer to the number of iterations the
+ inner loop should execute.
+
+ This address may be cached before the iteration loop, calling
+ ``iternext`` will not change it. The value itself may change during
+ iteration, in particular if buffering is enabled. This function
+ may be safely called without holding the Python GIL.
+
+.. cfunction:: void NpyIter_GetInnerFixedStrideArray(NpyIter* iter, npy_intp* out_strides)
+
+ Gets an array of strides which are fixed, or will not change during
+ the entire iteration. For strides that may change, the value
+ NPY_MAX_INTP is placed in the stride.
+
+ Once the iterator is prepared for iteration (after a reset if
+ :cdata:`NPY_DELAY_BUFALLOC` was used), call this to get the strides
+ which may be used to select a fast inner loop function. For example,
+ if the stride is 0, that means the inner loop can always load its
+ value into a variable once, then use the variable throughout the loop,
+ or if the stride equals the itemsize, a contiguous version for that
+ operand may be used.
+
+ This function may be safely called without holding the Python GIL.
+
+.. index::
+ pair: iterator; C-API
diff --git a/doc/source/reference/c-api.rst b/doc/source/reference/c-api.rst
index 9bcc68b49..7c7775889 100644
--- a/doc/source/reference/c-api.rst
+++ b/doc/source/reference/c-api.rst
@@ -44,6 +44,7 @@ code.
c-api.config
c-api.dtype
c-api.array
+ c-api.iterator
c-api.ufunc
c-api.generalized-ufuncs
c-api.coremath
diff --git a/doc/source/reference/c-api.ufunc.rst b/doc/source/reference/c-api.ufunc.rst
index f299251cb..45268b261 100644
--- a/doc/source/reference/c-api.ufunc.rst
+++ b/doc/source/reference/c-api.ufunc.rst
@@ -153,15 +153,17 @@ Functions
followed by the outputs assumed by the 1-d loop.
.. cfunction:: int PyUFunc_GenericFunction(PyUFuncObject* self,
- PyObject* args, PyArrayObject** mps)
-
- A generic ufunc call. The ufunc is passed in as *self*, the
- arguments to the ufunc as *args*. The *mps* argument is an array
- of :ctype:`PyArrayObject` pointers containing the converted input
- arguments as well as the ufunc outputs on return. The user is
- responsible for managing this array and receives a new reference
- for each array in *mps*. The total number of arrays in *mps* is
- given by *self* ->nin + *self* ->nout.
+ PyObject* args, PyObject* kwds, PyArrayObject** mps)
+
+ A generic ufunc call. The ufunc is passed in as *self*, the arguments
+ to the ufunc as *args* and *kwds*. The *mps* argument is an array of
+ :ctype:`PyArrayObject` pointers whose values are discarded and which
+ receive the converted input arguments as well as the ufunc outputs
+ when success is returned. The user is responsible for managing this
+ array and receives a new reference for each array in *mps*. The total
+ number of arrays in *mps* is given by *self* ->nin + *self* ->nout.
+
+ Returns 0 on success, -1 on error.
.. cfunction:: int PyUFunc_checkfperr(int errmask, PyObject* errobj)
diff --git a/doc/source/reference/distutils.rst b/doc/source/reference/distutils.rst
index 63174c2c7..5d11a6d4c 100644
--- a/doc/source/reference/distutils.rst
+++ b/doc/source/reference/distutils.rst
@@ -16,6 +16,7 @@ dictionary obtained from the todict() method of the class). More
information is available in the NumPy Distutils Users Guide in
``<site-packages>/numpy/doc/DISTUTILS.txt``.
+
.. index::
single: distutils
@@ -31,7 +32,6 @@ misc_util
.. autosummary::
:toctree: generated/
- Configuration
get_numpy_include_dirs
dict_append
appendpath
@@ -59,9 +59,9 @@ misc_util
.. class:: Configuration(package_name=None, parent_name=None, top_path=None, package_path=None, **attrs)
Construct a configuration instance for the given package name. If
- *parent_name* is not :const:`None`, then construct the package as a
+ *parent_name* is not None, then construct the package as a
sub-package of the *parent_name* package. If *top_path* and
- *package_path* are :const:`None` then they are assumed equal to
+ *package_path* are None then they are assumed equal to
the path of the file this instance was created in. The setup.py
files in the numpy distribution are good examples of how to use
the :class:`Configuration` instance.
diff --git a/doc/source/reference/maskedarray.generic.rst b/doc/source/reference/maskedarray.generic.rst
index bb8695408..f753a56f9 100644
--- a/doc/source/reference/maskedarray.generic.rst
+++ b/doc/source/reference/maskedarray.generic.rst
@@ -315,8 +315,8 @@ new valid values to them::
>>> x.soften_mask()
>>> x[-1] = 5
>>> x
- masked_array(data = [1 2 --],
- mask = [False False True],
+ masked_array(data = [1 2 5],
+ mask = [False False False],
fill_value = 999999)
>>> x.harden_mask()
diff --git a/doc/source/reference/routines.dtype.rst b/doc/source/reference/routines.dtype.rst
index a311f3da5..ec8d2981d 100644
--- a/doc/source/reference/routines.dtype.rst
+++ b/doc/source/reference/routines.dtype.rst
@@ -9,6 +9,9 @@ Data type routines
:toctree: generated/
can_cast
+ promote_types
+ min_scalar_type
+ result_type
common_type
obj2sctype
diff --git a/doc/source/reference/routines.indexing.rst b/doc/source/reference/routines.indexing.rst
index 9d8fde882..98b7817b8 100644
--- a/doc/source/reference/routines.indexing.rst
+++ b/doc/source/reference/routines.indexing.rst
@@ -20,6 +20,7 @@ Generating index arrays
indices
ix_
ogrid
+ ravel_coords
unravel_index
diag_indices
diag_indices_from
diff --git a/doc/source/reference/routines.linalg.rst b/doc/source/reference/routines.linalg.rst
index 4c3c676d9..173a6ad53 100644
--- a/doc/source/reference/routines.linalg.rst
+++ b/doc/source/reference/routines.linalg.rst
@@ -15,6 +15,7 @@ Matrix and vector products
inner
outer
tensordot
+ einsum
linalg.matrix_power
kron
diff --git a/doc/source/reference/routines.sort.rst b/doc/source/reference/routines.sort.rst
index 8dc769ea9..c10252c69 100644
--- a/doc/source/reference/routines.sort.rst
+++ b/doc/source/reference/routines.sort.rst
@@ -1,5 +1,5 @@
-Sorting and searching
-=====================
+Sorting, searching, and counting
+================================
.. currentmodule:: numpy
@@ -30,3 +30,10 @@ Searching
where
searchsorted
extract
+
+Counting
+--------
+.. autosummary::
+ :toctree: generated/
+
+ count_nonzero
diff --git a/doc/source/user/install.rst b/doc/source/user/install.rst
index aa16546d7..18e036ab0 100644
--- a/doc/source/user/install.rst
+++ b/doc/source/user/install.rst
@@ -126,14 +126,22 @@ means that g77 has been used. If libgfortran.so is a a dependency, gfortran
has been used. If both are dependencies, this means both have been used, which
is almost always a very bad idea.
-Disabling ATLAS and other accelerater libraries
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Disabling ATLAS and other accelerated libraries
+-----------------------------------------------
Usage of ATLAS and other accelerated libraries in Numpy can be disabled
via::
BLAS=None LAPACK=None ATLAS=None python setup.py build
+
+Supplying additional compiler flags
+-----------------------------------
+
+Additional compiler flags can be supplied by setting the ``OPT``,
+``FOPT`` (for Fortran), and ``CC`` environment variables.
+
+
Building with ATLAS support
---------------------------
diff --git a/doc/summarize.py b/doc/summarize.py
index e49df4838..f1888e046 100755
--- a/doc/summarize.py
+++ b/doc/summarize.py
@@ -42,7 +42,6 @@ random random.info random.mtrand random.ranf random.sample random.random
# --- numpy.fft:
fft fft.Tester fft.bench fft.fftpack fft.fftpack_lite fft.helper
-fft.refft fft.refft2 fft.refftn fft.irefft fft.irefft2 fft.irefftn
fft.info fft.test
# --- numpy.linalg:
@@ -67,10 +66,10 @@ def main():
fn = os.path.join(CUR_DIR, 'dump.xml')
if os.path.isfile(fn):
import_phantom_module(fn)
-
+
# check
documented, undocumented = check_numpy()
-
+
# report
in_sections = {}
for name, locations in documented.iteritems():
@@ -108,7 +107,7 @@ def check_numpy():
if k.startswith('numpy.'):
d[k[6:]] = d[k]
del d[k]
-
+
return documented, undocumented
def get_undocumented(documented, module, module_name=None, skip=[]):
@@ -123,24 +122,24 @@ def get_undocumented(documented, module, module_name=None, skip=[]):
"""
undocumented = {}
-
+
if module_name is None:
module_name = module.__name__
-
+
for name in dir(module):
obj = getattr(module, name)
if name.startswith('_'): continue
-
+
full_name = '.'.join([module_name, name])
if full_name in skip: continue
if full_name.startswith('numpy.') and full_name[6:] in skip: continue
if not (inspect.ismodule(obj) or callable(obj) or inspect.isclass(obj)):
continue
-
+
if full_name not in documented:
undocumented[full_name] = True
-
+
return undocumented
def format_in_columns(lst, max_columns):
@@ -160,9 +159,9 @@ def format_in_columns(lst, max_columns):
nrows = len(lst)//ncols
else:
nrows = 1 + len(lst)//ncols
-
+
fmt = ' %%-%ds ' % (col_len-2)
-
+
lines = []
for n in range(nrows):
lines.append("".join([fmt % x for x in lst[n::nrows]]))
diff --git a/doc/swig/test/setup.py b/doc/swig/test/setup.py
index fadf8b5cd..f2fc29aac 100755
--- a/doc/swig/test/setup.py
+++ b/doc/swig/test/setup.py
@@ -7,11 +7,8 @@ from distutils import sysconfig
# Third-party modules - we depend on numpy for everything
import numpy
-# Obtain the numpy include directory. This logic works across numpy versions.
-try:
- numpy_include = numpy.get_include()
-except AttributeError:
- numpy_include = numpy.get_numpy_include()
+# Obtain the numpy include directory.
+numpy_include = numpy.get_include()
# Array extension module
_Array = Extension("_Array",
diff --git a/numpy/add_newdocs.py b/numpy/add_newdocs.py
index baf5285f0..187180c5a 100644
--- a/numpy/add_newdocs.py
+++ b/numpy/add_newdocs.py
@@ -284,6 +284,36 @@ add_newdoc('numpy.core', 'broadcast', ('size',
"""))
+add_newdoc('numpy.core', 'broadcast', ('reset',
+ """
+ reset()
+
+ Reset the broadcasted result's iterator(s).
+
+ Parameters
+ ----------
+ None
+
+ Returns
+ -------
+ None
+
+ Examples
+ --------
+ >>> x = np.array([1, 2, 3])
+ >>> y = np.array([[4], [5], [6]]
+ >>> b = np.broadcast(x, y)
+ >>> b.index
+ 0
+ >>> b.next(), b.next(), b.next()
+ ((1, 4), (2, 4), (3, 4))
+ >>> b.index
+ 3
+ >>> b.reset()
+ >>> b.index
+ 0
+
+ """))
###############################################################################
#
@@ -330,6 +360,15 @@ add_newdoc('numpy.core.multiarray', 'array',
array should have. Ones will be pre-pended to the shape as
needed to meet this requirement.
+ Returns
+ -------
+ out : ndarray
+ An array object satisfying the specified requirements.
+
+ See Also
+ --------
+ empty, empty_like, zeros, zeros_like, ones, ones_like, fill
+
Examples
--------
>>> np.array([1, 2, 3])
@@ -413,6 +452,58 @@ add_newdoc('numpy.core.multiarray', 'empty',
""")
+add_newdoc('numpy.core.multiarray', 'empty_like',
+ """
+ empty_like(a, dtype=None, order='K')
+
+ Return a new array with the same shape and type as a given array.
+
+ Parameters
+ ----------
+ a : array_like
+ The shape and data-type of `a` define these same attributes of the
+ returned array.
+ dtype : data-type, optional
+ Overrides the data type of the result.
+ order : {'C', 'F', 'A', or 'K'}, optional
+ Overrides the memory layout of the result. 'C' means C-order,
+ 'F' means F-order, 'A' means 'F' if ``a`` is Fortran contiguous,
+ 'C' otherwise. 'K' means match the layout of ``a`` as closely
+ as possible.
+
+ Returns
+ -------
+ out : ndarray
+ Array of uninitialized (arbitrary) data with the same
+ shape and type as `a`.
+
+ See Also
+ --------
+ ones_like : Return an array of ones with shape and type of input.
+ zeros_like : Return an array of zeros with shape and type of input.
+ empty : Return a new uninitialized array.
+ ones : Return a new array setting values to one.
+ zeros : Return a new array setting values to zero.
+
+ Notes
+ -----
+ This function does *not* initialize the returned array; to do that use
+ `zeros_like` or `ones_like` instead. It may be marginally faster than
+ the functions that do set the array values.
+
+ Examples
+ --------
+ >>> a = ([1,2,3], [4,5,6]) # a is array-like
+ >>> np.empty_like(a)
+ array([[-1073741821, -1073741821, 3], #random
+ [ 0, 0, -1073741821]])
+ >>> a = np.array([[1., 2., 3.],[4.,5.,6.]])
+ >>> np.empty_like(a)
+ array([[ -2.00000715e+000, 1.48219694e-323, -2.00000572e+000],#random
+ [ 4.38791518e-305, -2.00000715e+000, 4.17269252e-309]])
+
+ """)
+
add_newdoc('numpy.core.multiarray', 'scalar',
"""
@@ -481,6 +572,35 @@ add_newdoc('numpy.core.multiarray', 'zeros',
""")
+add_newdoc('numpy.core.multiarray', 'count_nonzero',
+ """
+ count_nonzero(a)
+
+ Counts the number of non-zero values in the array ``a``.
+
+ Parameters
+ ----------
+ a : array_like
+ The array for which to count non-zeros.
+
+ Returns
+ -------
+ count : int
+ Number of non-zero values in the array.
+
+ See Also
+ --------
+ nonzero : Return the coordinates of all the non-zero values.
+
+ Examples
+ --------
+ >>> np.count_nonzero(np.eye(4))
+ 4
+
+ >>> np.count_nonzero([[0,1,7,0,0],[3,0,0,2,19]])
+ 5
+ """)
+
add_newdoc('numpy.core.multiarray','set_typeDict',
"""set_typeDict(dict)
@@ -493,28 +613,29 @@ add_newdoc('numpy.core.multiarray', 'fromstring',
"""
fromstring(string, dtype=float, count=-1, sep='')
- Return a new 1-D array initialized from raw binary or text data in string.
+ A new 1-D array initialized from raw binary or text data in a string.
Parameters
----------
string : str
A string containing the data.
- dtype : dtype, optional
- The data type of the array. For binary input data, the data must be
- in exactly this format.
+ dtype : data-type, optional
+ The data type of the array; default: float. For binary input data,
+ the data must be in exactly this format.
count : int, optional
- Read this number of `dtype` elements from the data. If this is
- negative, then the size will be determined from the length of the
- data.
+ Read this number of `dtype` elements from the data. If this is
+ negative (the default), the count will be determined from the
+ length of the data.
sep : str, optional
- If provided and not empty, then the data will be interpreted as
- ASCII text with decimal numbers. This argument is interpreted as the
- string separating numbers in the data. Extra whitespace between
- elements is also ignored.
+ If not provided or, equivalently, the empty string, the data will
+ be interpreted as binary data; otherwise, as ASCII text with
+ decimal numbers. Also in this latter case, this argument is
+ interpreted as the string separating numbers in the data; extra
+ whitespace between elements is also ignored.
Returns
-------
- arr : array
+ arr : ndarray
The constructed array.
Raises
@@ -523,6 +644,10 @@ add_newdoc('numpy.core.multiarray', 'fromstring',
If the string is not the correct size to satisfy the requested
`dtype` and `count`.
+ See Also
+ --------
+ frombuffer, fromfile, fromiter
+
Examples
--------
>>> np.fromstring('\\x01\\x02', dtype=np.uint8)
@@ -534,17 +659,6 @@ add_newdoc('numpy.core.multiarray', 'fromstring',
>>> np.fromstring('\\x01\\x02\\x03\\x04\\x05', dtype=np.uint8, count=3)
array([1, 2, 3], dtype=uint8)
- Invalid inputs:
-
- >>> np.fromstring('\\x01\\x02\\x03\\x04\\x05', dtype=np.int32)
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- ValueError: string size must be a multiple of element size
- >>> np.fromstring('\\x01\\x02', dtype=np.uint8, count=3)
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- ValueError: string is smaller than requested size
-
""")
add_newdoc('numpy.core.multiarray', 'fromiter',
@@ -558,9 +672,9 @@ add_newdoc('numpy.core.multiarray', 'fromiter',
iterable : iterable object
An iterable object providing data for the array.
dtype : data-type
- The data type of the returned array.
+ The data-type of the returned array.
count : int, optional
- The number of items to read from iterable. The default is -1,
+ The number of items to read from *iterable*. The default is -1,
which means all data is read.
Returns
@@ -570,9 +684,8 @@ add_newdoc('numpy.core.multiarray', 'fromiter',
Notes
-----
- Specify ``count`` to improve performance. It allows
- ``fromiter`` to pre-allocate the output array, instead of
- resizing it on demand.
+ Specify `count` to improve performance. It allows ``fromiter`` to
+ pre-allocate the output array, instead of resizing it on demand.
Examples
--------
@@ -665,26 +778,26 @@ add_newdoc('numpy.core.multiarray', 'frombuffer',
Parameters
----------
- buffer
+ buffer : buffer_like
An object that exposes the buffer interface.
dtype : data-type, optional
- Data type of the returned array.
+ Data-type of the returned array; default: float.
count : int, optional
Number of items to read. ``-1`` means all data in the buffer.
offset : int, optional
- Start reading the buffer from this offset.
+ Start reading the buffer from this offset; default: 0.
Notes
-----
- If the buffer has data that is not in machine byte-order, this
- should be specified as part of the data-type, e.g.::
+ If the buffer has data that is not in machine byte-order, this should
+ be specified as part of the data-type, e.g.::
>>> dt = np.dtype(int)
>>> dt = dt.newbyteorder('>')
>>> np.frombuffer(buf, dtype=dt)
- The data of the resulting array will not be byteswapped,
- but will be interpreted correctly.
+ The data of the resulting array will not be byteswapped, but will be
+ interpreted correctly.
Examples
--------
@@ -797,6 +910,7 @@ add_newdoc('numpy.core', 'inner',
--------
tensordot : Sum products over arbitrary axes.
dot : Generalised matrix product, using second last dimension of `b`.
+ einsum : Einstein summation convention.
Notes
-----
@@ -1115,9 +1229,12 @@ add_newdoc('numpy.core.multiarray', 'lexsort',
add_newdoc('numpy.core.multiarray', 'can_cast',
"""
- can_cast(fromtype, totype)
+ can_cast(from, totype, casting = 'safe')
- Returns True if cast between data types can occur without losing precision.
+ Returns True if cast between data types can occur according to the
+ casting rule. If from is a scalar or array scalar, also returns
+ True if the scalar value can be cast without overflow or truncation
+ to an integer.
Parameters
----------
@@ -1125,14 +1242,19 @@ add_newdoc('numpy.core.multiarray', 'can_cast',
Data type to cast from.
totype : dtype or dtype specifier
Data type to cast to.
+ casting : casting rule
+ May be any of 'no', 'equiv', 'safe', 'same_kind', or 'unsafe'.
Returns
-------
out : bool
- True if cast can occur without losing precision.
+ True if cast can occur according to the casting rule.
Examples
--------
+
+ Basic examples
+
>>> np.can_cast(np.int32, np.int64)
True
>>> np.can_cast(np.float64, np.complex)
@@ -1147,6 +1269,183 @@ add_newdoc('numpy.core.multiarray', 'can_cast',
>>> np.can_cast('i4', 'S4')
True
+ Casting scalars
+
+ >>> np.can_cast(100, 'i1')
+ True
+ >>> np.can_cast(150, 'i1')
+ False
+ >>> np.can_cast(150, 'u1')
+ True
+
+ >>> np.can_cast(3.5e100, np.float32)
+ False
+ >>> np.can_cast(1000.0, np.float32)
+ True
+
+ Array scalar checks the value, array does not
+
+ >>> np.can_cast(np.array(1000.0), np.float32)
+ True
+ >>> np.can_cast(np.array([1000.0]), np.float32)
+ False
+
+ Using the casting rules
+
+ >>> np.can_cast('i8', 'i8', 'no')
+ True
+ >>> np.can_cast('<i8', '>i8', 'no')
+ False
+
+ >>> np.can_cast('<i8', '>i8', 'equiv')
+ True
+ >>> np.can_cast('<i4', '>i8', 'equiv')
+ False
+
+ >>> np.can_cast('<i4', '>i8', 'safe')
+ True
+ >>> np.can_cast('<i8', '>i4', 'safe')
+ False
+
+ >>> np.can_cast('<i8', '>i4', 'same_kind')
+ True
+ >>> np.can_cast('<i8', '>u4', 'same_kind')
+ False
+
+ >>> np.can_cast('<i8', '>u4', 'unsafe')
+ True
+
+ """)
+
+add_newdoc('numpy.core.multiarray', 'promote_types',
+ """
+ promote_types(type1, type2)
+
+ Returns the data type with the smallest size and smallest scalar
+ kind to which both ``type1`` and ``type2`` may be safely cast.
+ The returned data type is always in native byte order.
+
+ Parameters
+ ----------
+ type1 : dtype or dtype specifier
+ First data type.
+ type2 : dtype or dtype specifier
+ Second data type.
+
+ Returns
+ -------
+ out : dtype
+ The promoted data type.
+
+ See Also
+ --------
+ issctype, issubsctype, issubdtype, obj2sctype, sctype2char,
+ maximum_sctype, min_scalar_type
+
+ Examples
+ --------
+ >>> np.promote_types('f4', 'f8')
+ dtype('float64')
+
+ >>> np.promote_types('i8', 'f4')
+ dtype('float64')
+
+ >>> np.promote_types('>i8', '<c8')
+ dtype('complex128')
+
+ >>> np.promote_types('i1', 'S8')
+ Traceback (most recent call last):
+ File "<stdin>", line 1, in <module>
+ TypeError: invalid type promotion
+
+ """)
+
+add_newdoc('numpy.core.multiarray', 'min_scalar_type',
+ """
+ min_scalar_type(a)
+
+ For scalar ``a``, returns the data type with the smallest size
+ and smallest scalar kind which can hold its value. For non-scalar
+ array ``a``, returns the vector's dtype unmodified.
+
+ As a special case, floating point values are not demoted to integers,
+ and complex values are not demoted to floats.
+
+ Parameters
+ ----------
+ a : scalar or array_like
+ The value whose minimal data type is to be found.
+
+ Returns
+ -------
+ out : dtype
+ The minimal data type.
+
+
+ See Also
+ --------
+ issctype, issubsctype, issubdtype, obj2sctype, sctype2char,
+ maximum_sctype, promote_types
+
+ Examples
+ --------
+ >>> np.min_scalar_type(10)
+ dtype('uint8')
+
+ >>> np.min_scalar_type(-260)
+ dtype('int16')
+
+ >>> np.min_scalar_type(3.1)
+ dtype('float16')
+
+ >>> np.min_scalar_type(1e50)
+ dtype('float64')
+
+ >>> np.min_scalar_type(np.arange(4,dtype='f8'))
+ dtype('float64')
+
+ """)
+
+add_newdoc('numpy.core.multiarray', 'result_type',
+ """
+ result_type(*arrays_and_dtypes)
+
+ Returns the type that results from applying the NumPy
+ type promotion rules to the arguments.
+
+ Type promotion in NumPy works similarly to the rules in languages
+ like C++, with some slight differences. When both scalars and
+ arrays are used, the array's type takes precedence and the actual value
+ of the scalar is taken into account.
+
+ For example, calculating 3*a, where a is an array of 32-bit floats,
+ intuitively should result in a 32-bit float output. If the 3 is a
+ 32-bit integer, the NumPy rules indicate it can't convert losslessly
+ into a 32-bit float, so a 64-bit float should be the result type.
+ By examining the value of the constant, '3', we see that it fits in
+ an 8-bit integer, which can be cast losslessly into the 32-bit float.
+
+ Parameters
+ ----------
+ arrays_and_dtypes : list of arrays and dtypes
+ The operands of some operation whose result type is needed.
+
+ Returns
+ -------
+ out : dtype
+ The result type.
+
+ Examples
+ --------
+ >>> np.result_type(3, np.arange(7, dtype='i1'))
+ dtype('int8')
+
+ >>> np.result_type('i4', 'c8')
+ dtype('complex128')
+
+ >>> np.result_type(3.0, -2)
+ dtype('float64')
+
""")
add_newdoc('numpy.core.multiarray','newbuffer',
@@ -1192,7 +1491,7 @@ add_newdoc('numpy.core.multiarray', 'getbuffer',
add_newdoc('numpy.core', 'dot',
"""
- dot(a, b)
+ dot(a, b, out=None)
Dot product of two arrays.
@@ -1209,6 +1508,13 @@ add_newdoc('numpy.core', 'dot',
First argument.
b : array_like
Second argument.
+ out : ndarray, optional
+ Output argument. This must have the exact kind that would be returned
+ if it was not used. In particular, it must have the right type, must be
+ C-contiguous, and its dtype must be the dtype that would be returned
+ for `dot(a,b)`. This is a performance feature. Therefore, if these
+ conditions are not met, an exception is raised, instead of attempting
+ to be flexible.
Returns
-------
@@ -1216,6 +1522,7 @@ add_newdoc('numpy.core', 'dot',
Returns the dot product of `a` and `b`. If `a` and `b` are both
scalars or both 1-D arrays then a scalar is returned; otherwise
an array is returned.
+ If `out` is given, then it is returned.
Raises
------
@@ -1227,6 +1534,7 @@ add_newdoc('numpy.core', 'dot',
--------
vdot : Complex-conjugating dot product.
tensordot : Sum products over arbitrary axes.
+ einsum : Einstein summation convention.
Examples
--------
@@ -1255,6 +1563,194 @@ add_newdoc('numpy.core', 'dot',
""")
+add_newdoc('numpy.core', 'einsum',
+ """
+ einsum(subscripts, *operands, out=None, dtype=None, order='K', casting='safe')
+
+ Evaluates the Einstein summation convention on the operands.
+
+ Using the Einstein summation convention, many common multi-dimensional
+ array operations can be represented in a simple fashion. This function
+ provides a way compute such summations. The best way to understand this
+ function is to try the examples below, which show how many common NumPy
+ functions can be implemented as calls to `einsum`.
+
+ Parameters
+ ----------
+ subscripts : str
+ Specifies the subscripts for summation.
+ operands : list of array_like
+ These are the arrays for the operation.
+ out : ndarray, optional
+ If provided, the calculation is done into this array.
+ dtype : data-type, optional
+ If provided, forces the calculation to use the data type specified.
+ Note that you may have to also give a more liberal `casting`
+ parameter to allow the conversions.
+ order : {'C', 'F', 'A', or 'K'}, optional
+ Controls the memory layout of the output. 'C' means it should
+ be C contiguous. 'F' means it should be Fortran contiguous,
+ 'A' means it should be 'F' if the inputs are all 'F', 'C' otherwise.
+ 'K' means it should be as close to the layout as the inputs as
+ is possible, including arbitrarily permuted axes.
+ Default is 'K'.
+ casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
+ Controls what kind of data casting may occur. Setting this to
+ 'unsafe' is not recommended, as it can adversely affect accumulations.
+
+ * 'no' means the data types should not be cast at all.
+ * 'equiv' means only byte-order changes are allowed.
+ * 'safe' means only casts which can preserve values are allowed.
+ * 'unsafe' means any data conversions may be done.
+ * 'same_kind' means only safe casts or casts within a kind,
+ like float64 to float32, are allowed.
+
+ Returns
+ -------
+ output : ndarray
+ The calculation based on the Einstein summation convention.
+
+ See Also
+ --------
+ dot, inner, outer, tensordot
+
+ Notes
+ -----
+ The subscripts string is a comma-separated list of subscript labels,
+ where each label refers to a dimension of the corresponding operand.
+ Repeated subscripts labels in one operand take the diagonal. For example,
+ ``np.einsum('ii', a)`` is equivalent to ``np.trace(a)``.
+
+ Whenever a label is repeated, it is summed, so ``np.einsum('i,i', a, b)``
+ is equivalent to ``np.inner(a,b)``. If a label appears only once,
+ it is not summed, so ``np.einsum('i', a)`` produces a view of ``a``
+ with no changes.
+
+ The order of labels in the output is by default alphabetical. This
+ means that ``np.einsum('ij', a)`` doesn't affect a 2D array, while
+ ``np.einsum('ji', a)`` takes its transpose.
+
+ The output can be controlled by specifying output subscript labels
+ as well. This specifies the label order, and allows summing to
+ be disallowed or forced when desired. The call ``np.einsum('i->', a)``
+ is like ``np.sum(a, axis=-1)``, and ``np.einsum('ii->i', a)``
+ is like ``np.diag(a)``. The difference is that `einsum` does not
+ allow broadcasting by default.
+
+ To enable and control broadcasting, use an ellipsis. Default
+ NumPy-style broadcasting is done by adding an ellipsis
+ to the left of each term, like ``np.einsum('...ii->...i', a)``.
+ To take the trace along the first and last axes,
+ you can do ``np.einsum('i...i', a)``, or to do a matrix-matrix
+ product with the left-most indices instead of rightmost, you can do
+ ``np.einsum('ij...,jk...->ik...', a, b)``.
+
+ When there is only one operand, no axes are summed, and no output
+ parameter is provided, a view into the operand is returned instead
+ of a new array. Thus, taking the diagonal as ``np.einsum('ii->i', a)``
+ produces a view.
+
+ An alternative way to provide the subscripts and operands is as
+ ``einsum(op0, sublist0, op1, sublist1, ..., [sublistout])``. The examples
+ below have corresponding `einsum` calls with the two parameter methods.
+
+ Examples
+ --------
+ >>> a = np.arange(25).reshape(5,5)
+ >>> b = np.arange(5)
+ >>> c = np.arange(6).reshape(2,3)
+
+ >>> np.einsum('ii', a)
+ 60
+ >>> np.einsum(a, [0,0])
+ 60
+ >>> np.trace(a)
+ 60
+
+ >>> np.einsum('ii->i', a)
+ array([ 0, 6, 12, 18, 24])
+ >>> np.einsum(a, [0,0], [0])
+ array([ 0, 6, 12, 18, 24])
+ >>> np.diag(a)
+ array([ 0, 6, 12, 18, 24])
+
+ >>> np.einsum('ij,j', a, b)
+ array([ 30, 80, 130, 180, 230])
+ >>> np.einsum(a, [0,1], b, [1])
+ array([ 30, 80, 130, 180, 230])
+ >>> np.dot(a, b)
+ array([ 30, 80, 130, 180, 230])
+
+ >>> np.einsum('ji', c)
+ array([[0, 3],
+ [1, 4],
+ [2, 5]])
+ >>> np.einsum(c, [1,0])
+ array([[0, 3],
+ [1, 4],
+ [2, 5]])
+ >>> c.T
+ array([[0, 3],
+ [1, 4],
+ [2, 5]])
+
+ >>> np.einsum('..., ...', 3, c)
+ array([[ 0, 3, 6],
+ [ 9, 12, 15]])
+ >>> np.einsum(3, [Ellipsis], c, [Ellipsis])
+ array([[ 0, 3, 6],
+ [ 9, 12, 15]])
+ >>> np.multiply(3, c)
+ array([[ 0, 3, 6],
+ [ 9, 12, 15]])
+
+ >>> np.einsum('i,i', b, b)
+ 30
+ >>> np.einsum(b, [0], b, [0])
+ 30
+ >>> np.inner(b,b)
+ 30
+
+ >>> np.einsum('i,j', np.arange(2)+1, b)
+ array([[0, 1, 2, 3, 4],
+ [0, 2, 4, 6, 8]])
+ >>> np.einsum(np.arange(2)+1, [0], b, [1])
+ array([[0, 1, 2, 3, 4],
+ [0, 2, 4, 6, 8]])
+ >>> np.outer(np.arange(2)+1, b)
+ array([[0, 1, 2, 3, 4],
+ [0, 2, 4, 6, 8]])
+
+ >>> np.einsum('i...->...', a)
+ array([50, 55, 60, 65, 70])
+ >>> np.einsum(a, [0,Ellipsis], [Ellipsis])
+ array([50, 55, 60, 65, 70])
+ >>> np.sum(a, axis=0)
+ array([50, 55, 60, 65, 70])
+
+ >>> a = np.arange(60.).reshape(3,4,5)
+ >>> b = np.arange(24.).reshape(4,3,2)
+ >>> np.einsum('ijk,jil->kl', a, b)
+ array([[ 4400., 4730.],
+ [ 4532., 4874.],
+ [ 4664., 5018.],
+ [ 4796., 5162.],
+ [ 4928., 5306.]])
+ >>> np.einsum(a, [0,1,2], b, [1,0,3], [2,3])
+ array([[ 4400., 4730.],
+ [ 4532., 4874.],
+ [ 4664., 5018.],
+ [ 4796., 5162.],
+ [ 4928., 5306.]])
+ >>> np.tensordot(a,b, axes=([1,0],[0,1]))
+ array([[ 4400., 4730.],
+ [ 4532., 4874.],
+ [ 4664., 5018.],
+ [ 4796., 5162.],
+ [ 4928., 5306.]])
+
+ """)
+
add_newdoc('numpy.core', 'alterdot',
"""
Change `dot`, `vdot`, and `innerproduct` to use accelerated BLAS functions.
@@ -2154,9 +2650,15 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('astype',
Parameters
----------
- t : string or dtype
+ t : str or dtype
Typecode or data-type to which the array is cast.
+ Raises
+ ------
+ ComplexWarning :
+ When casting from complex to float or int. To avoid this,
+ one should use ``a.real.astype(t)``.
+
Examples
--------
>>> x = np.array([1, 2, 2.5])
@@ -2365,6 +2867,35 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('diagonal',
"""))
+add_newdoc('numpy.core.multiarray', 'ndarray', ('dot',
+ """
+ a.dot(b, out=None)
+
+ Dot product of two arrays.
+
+ Refer to `numpy.dot` for full documentation.
+
+ See Also
+ --------
+ numpy.dot : equivalent function
+
+ Examples
+ --------
+ >>> a = np.eye(2)
+ >>> b = np.ones((2, 2)) * 2
+ >>> a.dot(b)
+ array([[ 2., 2.],
+ [ 2., 2.]])
+
+ This array method can be conveniently chained:
+
+ >>> a.dot(b).dot(b)
+ array([[ 8., 8.],
+ [ 8., 8.]])
+
+ """))
+
+
add_newdoc('numpy.core.multiarray', 'ndarray', ('dump',
"""a.dump(file)
@@ -2613,6 +3144,37 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('itemset',
"""))
+add_newdoc('numpy.core.multiarray', 'ndarray', ('setasflat',
+ """
+ a.setasflat(arr)
+
+ Equivalent to a.flat = arr.flat, but is generally more efficient.
+ This function does not check for overlap, so if ``arr`` and ``a``
+ are viewing the same data with different strides, the results will
+ be unpredictable.
+
+ Parameters
+ ----------
+ arr : array_like
+ The array to copy into a.
+
+ Examples
+ --------
+ >>> a = np.arange(2*4).reshape(2,4)[:,:-1]; a
+ array([[0, 1, 2],
+ [4, 5, 6]])
+ >>> b = np.arange(3*3, dtype='f4').reshape(3,3).T[::-1,:-1]; b
+ array([[ 2., 5.],
+ [ 1., 4.],
+ [ 0., 3.]], dtype=float32)
+ >>> a.setasflat(b)
+ >>> a
+ array([[2, 5, 1],
+ [4, 0, 3]])
+
+ """))
+
+
add_newdoc('numpy.core.multiarray', 'ndarray', ('max',
"""
a.max(axis=None, out=None)
@@ -3796,12 +4358,15 @@ add_newdoc('numpy.lib._compiled_base', 'digitize',
add_newdoc('numpy.lib._compiled_base', 'bincount',
"""
- bincount(x, weights=None)
+ bincount(x, weights=None, minlength=None)
Count number of occurrences of each value in array of non-negative ints.
The number of bins (of size 1) is one larger than the largest value in
- `x`. Each bin gives the number of occurrences of its index value in `x`.
+ `x`. If `minlength` is specified, there will be at least this number
+ of bins in the output array (though it will be longer if necessary,
+ depending on the contents of `x`).
+ Each bin gives the number of occurrences of its index value in `x`.
If `weights` is specified the input array is weighted by it, i.e. if a
value ``n`` is found at position ``i``, ``out[n] += weight[i]`` instead
of ``out[n] += 1``.
@@ -3812,6 +4377,10 @@ add_newdoc('numpy.lib._compiled_base', 'bincount',
Input array.
weights : array_like, optional
Weights, array of the same shape as `x`.
+ minlength : int, optional
+ .. versionadded:: 1.6.0
+
+ A minimum number of bins for the output array.
Returns
-------
@@ -3823,7 +4392,7 @@ add_newdoc('numpy.lib._compiled_base', 'bincount',
------
ValueError
If the input is not 1-dimensional, or contains elements with negative
- values.
+ values, or if `minlength` is non-positive.
TypeError
If the type of the input is float or complex.
@@ -3842,6 +4411,9 @@ add_newdoc('numpy.lib._compiled_base', 'bincount',
>>> np.bincount(x).size == np.amax(x)+1
True
+ The input array needs to be of integer dtype, otherwise a
+ TypeError is raised:
+
>>> np.bincount(np.arange(5, dtype=np.float))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
@@ -3857,6 +4429,106 @@ add_newdoc('numpy.lib._compiled_base', 'bincount',
""")
+add_newdoc('numpy.lib._compiled_base', 'ravel_coords',
+ """
+ ravel_coords(coords, dims, mode='raise', order='C')
+
+ Converts a tuple of coordinate arrays into an array of flat
+ indices, applying boundary modes to the coordinates.
+
+ Parameters
+ ----------
+ coords : tuple of array_like
+ A tuple of integer arrays, one array for each dimension.
+ dims : tuple of ints
+ The shape of array into which the indices from ``coords`` apply.
+ mode : {'raise', 'wrap', 'clip'}, optional
+ Specifies how out-of-bounds indices are handled. Can specify
+ either one mode or a tuple of modes, one mode per index.
+
+ * 'raise' -- raise an error (default)
+ * 'wrap' -- wrap around
+ * 'clip' -- clip to the range
+
+ In 'clip' mode, a negative index which would normally
+ wrap will clip to 0 instead.
+ order : {'C', 'F'}, optional
+ Determines whether the coords should be viewed as indexing in
+ C (row-major) order or FORTRAN (column-major) order.
+
+ Returns
+ -------
+ raveled_indices : ndarray
+ An array of indices into the flattened version of an array
+ of dimensions ``dims``.
+
+ See Also
+ --------
+ unravel_index
+
+ Notes
+ -----
+ .. versionadded:: 1.6.0
+
+ Examples
+ --------
+ >>> arr = np.array([[3,6,6],[4,5,1]])
+ >>> np.ravel_coords(arr, (7,6))
+ array([22, 41, 37])
+ >>> np.ravel_coords(arr, (7,6), order='F')
+ array([31, 41, 13])
+ >>> np.ravel_coords(arr, (4,6), mode='clip')
+ array([22, 23, 19])
+ >>> np.ravel_coords(arr, (4,4), mode=('clip','wrap'))
+ array([12, 13, 13])
+
+ >>> np.ravel_coords((3,1,4,1), (6,7,8,9))
+ 1621
+ """)
+
+add_newdoc('numpy.lib._compiled_base', 'unravel_index',
+ """
+ unravel_index(indices, dims, order='C')
+
+ Converts a flat index or array of flat indices into a tuple
+ of coordinate arrays.
+
+ Parameters
+ ----------
+ indices : array_like
+ An integer array whose elements are indices into the flattened
+ version of an array of dimensions ``dims``. Before version 1.6.0,
+ this function accepted just one index value.
+ dims : tuple of ints
+ The shape of the array to use for unraveling ``indices``.
+ order : {'C', 'F'}, optional
+ .. versionadded:: 1.6.0
+
+ Determines whether the indices should be viewed as indexing in
+ C (row-major) order or FORTRAN (column-major) order.
+
+ Returns
+ -------
+ unraveled_coords : tuple of ndarray
+ Each array in the tuple has the same shape as the ``indices``
+ array.
+
+ See Also
+ --------
+ ravel_coords
+
+ Examples
+ --------
+ >>> np.unravel_index([22, 41, 37], (7,6))
+ (array([3, 6, 6]), array([4, 5, 1]))
+ >>> np.unravel_index([31, 41, 13], (7,6), order='F')
+ (array([3, 6, 6]), array([4, 5, 1]))
+
+ >>> np.unravel_index(1621, (6,7,8,9))
+ (3, 1, 4, 1)
+
+ """)
+
add_newdoc('numpy.lib._compiled_base', 'add_docstring',
"""
docstring(obj, docstring)
diff --git a/numpy/core/SConscript b/numpy/core/SConscript
index 5f7212387..5bf6bc5a4 100644
--- a/numpy/core/SConscript
+++ b/numpy/core/SConscript
@@ -379,6 +379,11 @@ umath_funcs_src = env.GenerateFromTemplate(pjoin('src', 'umath', 'funcs.inc.src'
umath_loops_src = env.GenerateFromTemplate(pjoin('src', 'umath', 'loops.c.src'))
arraytypes_src = env.GenerateFromTemplate(
pjoin('src', 'multiarray', 'arraytypes.c.src'))
+new_iterator_src = env.GenerateFromTemplate(
+ pjoin('src', 'multiarray', 'new_iterator.c.src'))
+lowlevel_strided_loops_src = env.GenerateFromTemplate(
+ pjoin('src', 'multiarray', 'lowlevel_strided_loops.c.src'))
+einsum_src = env.GenerateFromTemplate(pjoin('src', 'multiarray', 'einsum.c.src'))
sortmodule_src = env.GenerateFromTemplate(pjoin('src', '_sortmodule.c.src'))
umathmodule_src = env.GenerateFromTemplate(pjoin('src', 'umath',
'umathmodule.c.src'))
@@ -455,9 +460,14 @@ if ENABLE_SEPARATE_COMPILATION:
pjoin('src', 'multiarray', 'usertypes.c'),
pjoin('src', 'multiarray', 'buffer.c'),
pjoin('src', 'multiarray', 'numpymemoryview.c'),
- pjoin('src', 'multiarray', 'scalarapi.c')]
+ pjoin('src', 'multiarray', 'scalarapi.c'),
+ pjoin('src', 'multiarray', 'new_iterator_pywrap.c'),
+ pjoin('src', 'multiarray', 'dtype_transfer.c')]
multiarray_src.extend(arraytypes_src)
multiarray_src.extend(scalartypes_src)
+ multiarray_src.extend(lowlevel_strided_loops_src)
+ multiarray_src.extend(new_iterator_src)
+ multiarray_src.extend(einsum_src)
if PYTHON_HAS_UNICODE_WIDE:
multiarray_src.extend([pjoin("src", "multiarray", "ucsnarrow.c")])
else:
diff --git a/numpy/core/blasdot/_dotblas.c b/numpy/core/blasdot/_dotblas.c
index 1dc24d8ea..35db1bf1c 100644
--- a/numpy/core/blasdot/_dotblas.c
+++ b/numpy/core/blasdot/_dotblas.c
@@ -213,10 +213,10 @@ _bad_strides(PyArrayObject *ap)
* NB: The first argument is not conjugated.;
*/
static PyObject *
-dotblas_matrixproduct(PyObject *NPY_UNUSED(dummy), PyObject *args)
+dotblas_matrixproduct(PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject* kwargs)
{
PyObject *op1, *op2;
- PyArrayObject *ap1 = NULL, *ap2 = NULL, *ret = NULL;
+ PyArrayObject *ap1 = NULL, *ap2 = NULL, *out = NULL, *ret = NULL;
int j, l, lda, ldb, ldc;
int typenum, nd;
npy_intp ap1stride = 0;
@@ -230,10 +230,15 @@ dotblas_matrixproduct(PyObject *NPY_UNUSED(dummy), PyObject *args)
PyTypeObject *subtype;
PyArray_Descr *dtype;
MatrixShape ap1shape, ap2shape;
+ char* kwords[] = {"a", "b", "out", NULL };
- if (!PyArg_ParseTuple(args, "OO", &op1, &op2)) {
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|O", kwords,
+ &op1, &op2, &out)) {
return NULL;
}
+ if (out == Py_None) {
+ out = NULL;
+ }
/*
* "Matrix product" using the BLAS.
@@ -246,7 +251,10 @@ dotblas_matrixproduct(PyObject *NPY_UNUSED(dummy), PyObject *args)
/* This function doesn't handle other types */
if ((typenum != PyArray_DOUBLE && typenum != PyArray_CDOUBLE &&
typenum != PyArray_FLOAT && typenum != PyArray_CFLOAT)) {
- return PyArray_Return((PyArrayObject *)PyArray_MatrixProduct(op1, op2));
+ return PyArray_Return((PyArrayObject *)PyArray_MatrixProduct2(
+ (PyObject *)op1,
+ (PyObject *)op2,
+ (PyObject *)out));
}
dtype = PyArray_DescrFromType(typenum);
@@ -279,8 +287,9 @@ dotblas_matrixproduct(PyObject *NPY_UNUSED(dummy), PyObject *args)
Py_DECREF(tmp1);
Py_DECREF(tmp2);
}
- ret = (PyArrayObject *)PyArray_MatrixProduct((PyObject *)ap1,
- (PyObject *)ap2);
+ ret = (PyArrayObject *)PyArray_MatrixProduct2((PyObject *)ap1,
+ (PyObject *)ap2,
+ (PyObject *)out);
Py_DECREF(ap1);
Py_DECREF(ap2);
return PyArray_Return(ret);
@@ -418,10 +427,34 @@ dotblas_matrixproduct(PyObject *NPY_UNUSED(dummy), PyObject *args)
subtype = Py_TYPE(ap1);
}
- ret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions,
- typenum, NULL, NULL, 0, 0,
- (PyObject *)
- (prior2 > prior1 ? ap2 : ap1));
+ if (out) {
+ int d;
+ /* verify that out is usable */
+ if (Py_TYPE(out) != subtype ||
+ PyArray_NDIM(out) != nd ||
+ PyArray_TYPE(out) != typenum ||
+ !PyArray_ISCARRAY(out)) {
+
+ PyErr_SetString(PyExc_ValueError,
+ "output array is not acceptable "
+ "(must have the right type, nr dimensions, and be a C-Array)");
+ goto fail;
+ }
+ for (d = 0; d < nd; ++d) {
+ if (dimensions[d] != PyArray_DIM(out, d)) {
+ PyErr_SetString(PyExc_ValueError,
+ "output array has wrong dimensions");
+ goto fail;
+ }
+ }
+ Py_INCREF(out);
+ ret = out;
+ } else {
+ ret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions,
+ typenum, NULL, NULL, 0, 0,
+ (PyObject *)
+ (prior2 > prior1 ? ap2 : ap1));
+ }
if (ret == NULL) {
goto fail;
@@ -434,7 +467,6 @@ dotblas_matrixproduct(PyObject *NPY_UNUSED(dummy), PyObject *args)
return PyArray_Return(ret);
}
-
if (ap2shape == _scalar) {
/*
* Multiplication by a scalar -- Level 1 BLAS
@@ -1167,7 +1199,7 @@ static PyObject *dotblas_vdot(PyObject *NPY_UNUSED(dummy), PyObject *args) {
}
static struct PyMethodDef dotblas_module_methods[] = {
- {"dot", (PyCFunction)dotblas_matrixproduct, 1, NULL},
+ {"dot", (PyCFunction)dotblas_matrixproduct, METH_VARARGS|METH_KEYWORDS, NULL},
{"inner", (PyCFunction)dotblas_innerproduct, 1, NULL},
{"vdot", (PyCFunction)dotblas_vdot, 1, NULL},
{"alterdot", (PyCFunction)dotblas_alterdot, 1, NULL},
diff --git a/numpy/core/code_generators/cversions.txt b/numpy/core/code_generators/cversions.txt
index 693ff506c..633c1be96 100644
--- a/numpy/core/code_generators/cversions.txt
+++ b/numpy/core/code_generators/cversions.txt
@@ -6,3 +6,6 @@
# version 4 added neighborhood iterators and PyArray_Correlate2
0x00000004 = 3d8940bf7b0d2a4e25be4338c14c3c85
0x00000005 = 77e2e846db87f25d7cf99f9d812076f0
+# Version 6 added new iterator, half float and casting functions,
+# PyArray_CountNonzero, PyArray_NewLikeArray and PyArray_MatrixProduct2.
+0x00000006 = a413221a7ff73fcf251aeb5ee8fa73ff
diff --git a/numpy/core/code_generators/genapi.py b/numpy/core/code_generators/genapi.py
index 5cac71a72..7c6b29e73 100644
--- a/numpy/core/code_generators/genapi.py
+++ b/numpy/core/code_generators/genapi.py
@@ -44,6 +44,9 @@ API_FILES = [join('multiarray', 'methods.c'),
join('multiarray', 'conversion_utils.c'),
join('multiarray', 'buffer.c'),
join('multiarray', 'datetime.c'),
+ join('multiarray', 'new_iterator.c.src'),
+ join('multiarray', 'new_iterator_pywrap.c'),
+ join('multiarray', 'einsum.c.src'),
join('umath', 'ufunc_object.c'),
join('umath', 'loops.c.src'),
]
@@ -57,7 +60,7 @@ def remove_whitespace(s):
return ''.join(s.split())
def _repl(str):
- return str.replace('intp', 'npy_intp').replace('Bool','npy_bool')
+ return str.replace('Bool','npy_bool')
class Function(object):
def __init__(self, name, return_type, args, doc=''):
diff --git a/numpy/core/code_generators/numpy_api.py b/numpy/core/code_generators/numpy_api.py
index 9474a131a..cd897e3ce 100644
--- a/numpy/core/code_generators/numpy_api.py
+++ b/numpy/core/code_generators/numpy_api.py
@@ -13,7 +13,7 @@ exception, so it should hopefully not get unnoticed).
"""
multiarray_global_vars = {
- 'NPY_NUMUSERTYPES': 6,
+ 'NPY_NUMUSERTYPES': 7,
}
multiarray_global_vars_types = {
@@ -21,50 +21,53 @@ multiarray_global_vars_types = {
}
multiarray_scalar_bool_values = {
- '_PyArrayScalar_BoolValues': 8
+ '_PyArrayScalar_BoolValues': 9
}
multiarray_types_api = {
- 'PyArray_Type': 1,
- 'PyArrayDescr_Type': 2,
- 'PyArrayFlags_Type': 3,
- 'PyArrayIter_Type': 4,
- 'PyArrayMultiIter_Type': 5,
- 'PyBoolArrType_Type': 7,
- 'PyGenericArrType_Type': 9,
- 'PyNumberArrType_Type': 10,
- 'PyIntegerArrType_Type': 11,
- 'PySignedIntegerArrType_Type': 12,
- 'PyUnsignedIntegerArrType_Type': 13,
- 'PyInexactArrType_Type': 14,
- 'PyFloatingArrType_Type': 15,
- 'PyComplexFloatingArrType_Type': 16,
- 'PyFlexibleArrType_Type': 17,
- 'PyCharacterArrType_Type': 18,
- 'PyByteArrType_Type': 19,
- 'PyShortArrType_Type': 20,
- 'PyIntArrType_Type': 21,
- 'PyLongArrType_Type': 22,
- 'PyLongLongArrType_Type': 23,
- 'PyUByteArrType_Type': 24,
- 'PyUShortArrType_Type': 25,
- 'PyUIntArrType_Type': 26,
- 'PyULongArrType_Type': 27,
- 'PyULongLongArrType_Type': 28,
- 'PyFloatArrType_Type': 29,
- 'PyDoubleArrType_Type': 30,
- 'PyLongDoubleArrType_Type': 31,
- 'PyCFloatArrType_Type': 32,
- 'PyCDoubleArrType_Type': 33,
- 'PyCLongDoubleArrType_Type': 34,
- 'PyObjectArrType_Type': 35,
- 'PyStringArrType_Type': 36,
- 'PyUnicodeArrType_Type': 37,
- 'PyVoidArrType_Type': 38,
- 'PyTimeIntegerArrType_Type': 39,
- 'PyDatetimeArrType_Type': 40,
- 'PyTimedeltaArrType_Type': 41,
- 'PyHalfArrType_Type': 221,
+ 'PyBigArray_Type': 1,
+ 'PyArray_Type': 2,
+ 'PyArrayDescr_Type': 3,
+ 'PyArrayFlags_Type': 4,
+ 'PyArrayIter_Type': 5,
+ 'PyArrayMultiIter_Type': 6,
+ 'PyBoolArrType_Type': 8,
+ 'PyGenericArrType_Type': 10,
+ 'PyNumberArrType_Type': 11,
+ 'PyIntegerArrType_Type': 12,
+ 'PySignedIntegerArrType_Type': 13,
+ 'PyUnsignedIntegerArrType_Type': 14,
+ 'PyInexactArrType_Type': 15,
+ 'PyFloatingArrType_Type': 16,
+ 'PyComplexFloatingArrType_Type': 17,
+ 'PyFlexibleArrType_Type': 18,
+ 'PyCharacterArrType_Type': 19,
+ 'PyByteArrType_Type': 20,
+ 'PyShortArrType_Type': 21,
+ 'PyIntArrType_Type': 22,
+ 'PyLongArrType_Type': 23,
+ 'PyLongLongArrType_Type': 24,
+ 'PyUByteArrType_Type': 25,
+ 'PyUShortArrType_Type': 26,
+ 'PyUIntArrType_Type': 27,
+ 'PyULongArrType_Type': 28,
+ 'PyULongLongArrType_Type': 29,
+ 'PyFloatArrType_Type': 30,
+ 'PyDoubleArrType_Type': 31,
+ 'PyLongDoubleArrType_Type': 32,
+ 'PyCFloatArrType_Type': 33,
+ 'PyCDoubleArrType_Type': 34,
+ 'PyCLongDoubleArrType_Type': 35,
+ 'PyObjectArrType_Type': 36,
+ 'PyStringArrType_Type': 37,
+ 'PyUnicodeArrType_Type': 38,
+ 'PyVoidArrType_Type': 39,
+ # End 1.5 API
+ 'PyTimeIntegerArrType_Type': 214,
+ 'PyDatetimeArrType_Type': 215,
+ 'PyTimedeltaArrType_Type': 216,
+ 'PyHalfArrType_Type': 217,
+ 'NpyIter_Type': 218,
}
#define NPY_NUMUSERTYPES (*(int *)PyArray_API[6])
@@ -73,185 +76,244 @@ multiarray_types_api = {
multiarray_funcs_api = {
'PyArray_GetNDArrayCVersion': 0,
- 'PyArray_SetNumericOps': 42,
- 'PyArray_GetNumericOps': 43,
- 'PyArray_INCREF': 44,
- 'PyArray_XDECREF': 45,
- 'PyArray_SetStringFunction': 46,
- 'PyArray_DescrFromType': 47,
- 'PyArray_TypeObjectFromType': 48,
- 'PyArray_Zero': 49,
- 'PyArray_One': 50,
- 'PyArray_CastToType': 51,
- 'PyArray_CastTo': 52,
- 'PyArray_CastAnyTo': 53,
- 'PyArray_CanCastSafely': 54,
- 'PyArray_CanCastTo': 55,
- 'PyArray_ObjectType': 56,
- 'PyArray_DescrFromObject': 57,
- 'PyArray_ConvertToCommonType': 58,
- 'PyArray_DescrFromScalar': 59,
- 'PyArray_DescrFromTypeObject': 60,
- 'PyArray_Size': 61,
- 'PyArray_Scalar': 62,
- 'PyArray_FromScalar': 63,
- 'PyArray_ScalarAsCtype': 64,
- 'PyArray_CastScalarToCtype': 65,
- 'PyArray_CastScalarDirect': 66,
- 'PyArray_ScalarFromObject': 67,
- 'PyArray_GetCastFunc': 68,
- 'PyArray_FromDims': 69,
- 'PyArray_FromDimsAndDataAndDescr': 70,
- 'PyArray_FromAny': 71,
- 'PyArray_EnsureArray': 72,
- 'PyArray_EnsureAnyArray': 73,
- 'PyArray_FromFile': 74,
- 'PyArray_FromString': 75,
- 'PyArray_FromBuffer': 76,
- 'PyArray_FromIter': 77,
- 'PyArray_Return': 78,
- 'PyArray_GetField': 79,
- 'PyArray_SetField': 80,
- 'PyArray_Byteswap': 81,
- 'PyArray_Resize': 82,
- 'PyArray_MoveInto': 83,
- 'PyArray_CopyInto': 84,
- 'PyArray_CopyAnyInto': 85,
- 'PyArray_CopyObject': 86,
- 'PyArray_NewCopy': 87,
- 'PyArray_ToList': 88,
- 'PyArray_ToString': 89,
- 'PyArray_ToFile': 90,
- 'PyArray_Dump': 91,
- 'PyArray_Dumps': 92,
- 'PyArray_ValidType': 93,
- 'PyArray_UpdateFlags': 94,
- 'PyArray_New': 95,
- 'PyArray_NewFromDescr': 96,
- 'PyArray_DescrNew': 97,
- 'PyArray_DescrNewFromType': 98,
- 'PyArray_GetPriority': 99,
- 'PyArray_IterNew': 100,
- 'PyArray_MultiIterNew': 101,
- 'PyArray_PyIntAsInt': 102,
- 'PyArray_PyIntAsIntp': 103,
- 'PyArray_Broadcast': 104,
- 'PyArray_FillObjectArray': 105,
- 'PyArray_FillWithScalar': 106,
- 'PyArray_CheckStrides': 107,
- 'PyArray_DescrNewByteorder': 108,
- 'PyArray_IterAllButAxis': 109,
- 'PyArray_CheckFromAny': 110,
- 'PyArray_FromArray': 111,
- 'PyArray_FromInterface': 112,
- 'PyArray_FromStructInterface': 113,
- 'PyArray_FromArrayAttr': 114,
- 'PyArray_ScalarKind': 115,
- 'PyArray_CanCoerceScalar': 116,
- 'PyArray_NewFlagsObject': 117,
- 'PyArray_CanCastScalar': 118,
- 'PyArray_CompareUCS4': 119,
- 'PyArray_RemoveSmallest': 120,
- 'PyArray_ElementStrides': 121,
- 'PyArray_Item_INCREF': 122,
- 'PyArray_Item_XDECREF': 123,
- 'PyArray_FieldNames': 124,
- 'PyArray_Transpose': 125,
- 'PyArray_TakeFrom': 126,
- 'PyArray_PutTo': 127,
- 'PyArray_PutMask': 128,
- 'PyArray_Repeat': 129,
- 'PyArray_Choose': 130,
- 'PyArray_Sort': 131,
- 'PyArray_ArgSort': 132,
- 'PyArray_SearchSorted': 133,
- 'PyArray_ArgMax': 134,
- 'PyArray_ArgMin': 135,
- 'PyArray_Reshape': 136,
- 'PyArray_Newshape': 137,
- 'PyArray_Squeeze': 138,
- 'PyArray_View': 139,
- 'PyArray_SwapAxes': 140,
- 'PyArray_Max': 141,
- 'PyArray_Min': 142,
- 'PyArray_Ptp': 143,
- 'PyArray_Mean': 144,
- 'PyArray_Trace': 145,
- 'PyArray_Diagonal': 146,
- 'PyArray_Clip': 147,
- 'PyArray_Conjugate': 148,
- 'PyArray_Nonzero': 149,
- 'PyArray_Std': 150,
- 'PyArray_Sum': 151,
- 'PyArray_CumSum': 152,
- 'PyArray_Prod': 153,
- 'PyArray_CumProd': 154,
- 'PyArray_All': 155,
- 'PyArray_Any': 156,
- 'PyArray_Compress': 157,
- 'PyArray_Flatten': 158,
- 'PyArray_Ravel': 159,
- 'PyArray_MultiplyList': 160,
- 'PyArray_MultiplyIntList': 161,
- 'PyArray_GetPtr': 162,
- 'PyArray_CompareLists': 163,
- 'PyArray_AsCArray': 164,
- 'PyArray_As1D': 165,
- 'PyArray_As2D': 166,
- 'PyArray_Free': 167,
- 'PyArray_Converter': 168,
- 'PyArray_IntpFromSequence': 169,
- 'PyArray_Concatenate': 170,
- 'PyArray_InnerProduct': 171,
- 'PyArray_MatrixProduct': 172,
- 'PyArray_CopyAndTranspose': 173,
- 'PyArray_Correlate': 174,
- 'PyArray_TypestrConvert': 175,
- 'PyArray_DescrConverter': 176,
- 'PyArray_DescrConverter2': 177,
- 'PyArray_IntpConverter': 178,
- 'PyArray_BufferConverter': 179,
- 'PyArray_AxisConverter': 180,
- 'PyArray_BoolConverter': 181,
- 'PyArray_ByteorderConverter': 182,
- 'PyArray_OrderConverter': 183,
- 'PyArray_EquivTypes': 184,
- 'PyArray_Zeros': 185,
- 'PyArray_Empty': 186,
- 'PyArray_Where': 187,
- 'PyArray_Arange': 188,
- 'PyArray_ArangeObj': 189,
- 'PyArray_SortkindConverter': 190,
- 'PyArray_LexSort': 191,
- 'PyArray_Round': 192,
- 'PyArray_EquivTypenums': 193,
- 'PyArray_RegisterDataType': 194,
- 'PyArray_RegisterCastFunc': 195,
- 'PyArray_RegisterCanCast': 196,
- 'PyArray_InitArrFuncs': 197,
- 'PyArray_IntTupleFromIntp': 198,
- 'PyArray_TypeNumFromName': 199,
- 'PyArray_ClipmodeConverter': 200,
- 'PyArray_OutputConverter': 201,
- 'PyArray_BroadcastToShape': 202,
- '_PyArray_SigintHandler': 203,
- '_PyArray_GetSigintBuf': 204,
- 'PyArray_DescrAlignConverter': 205,
- 'PyArray_DescrAlignConverter2': 206,
- 'PyArray_SearchsideConverter': 207,
- 'PyArray_CheckAxis': 208,
- 'PyArray_OverflowMultiplyList': 209,
- 'PyArray_CompareString': 210,
- 'PyArray_MultiIterFromObjects': 211,
- 'PyArray_GetEndianness': 212,
- 'PyArray_GetNDArrayCFeatureVersion': 213,
- 'PyArray_Correlate2': 214,
- 'PyArray_NeighborhoodIterNew': 215,
- 'PyArray_SetDatetimeParseFunction': 216,
- 'PyArray_DatetimeToDatetimeStruct': 217,
- 'PyArray_TimedeltaToTimedeltaStruct': 218,
- 'PyArray_DatetimeStructToDatetime': 219,
- 'PyArray_TimedeltaStructToTimedelta': 220,
+ 'PyArray_SetNumericOps': 40,
+ 'PyArray_GetNumericOps': 41,
+ 'PyArray_INCREF': 42,
+ 'PyArray_XDECREF': 43,
+ 'PyArray_SetStringFunction': 44,
+ 'PyArray_DescrFromType': 45,
+ 'PyArray_TypeObjectFromType': 46,
+ 'PyArray_Zero': 47,
+ 'PyArray_One': 48,
+ 'PyArray_CastToType': 49,
+ 'PyArray_CastTo': 50,
+ 'PyArray_CastAnyTo': 51,
+ 'PyArray_CanCastSafely': 52,
+ 'PyArray_CanCastTo': 53,
+ 'PyArray_ObjectType': 54,
+ 'PyArray_DescrFromObject': 55,
+ 'PyArray_ConvertToCommonType': 56,
+ 'PyArray_DescrFromScalar': 57,
+ 'PyArray_DescrFromTypeObject': 58,
+ 'PyArray_Size': 59,
+ 'PyArray_Scalar': 60,
+ 'PyArray_FromScalar': 61,
+ 'PyArray_ScalarAsCtype': 62,
+ 'PyArray_CastScalarToCtype': 63,
+ 'PyArray_CastScalarDirect': 64,
+ 'PyArray_ScalarFromObject': 65,
+ 'PyArray_GetCastFunc': 66,
+ 'PyArray_FromDims': 67,
+ 'PyArray_FromDimsAndDataAndDescr': 68,
+ 'PyArray_FromAny': 69,
+ 'PyArray_EnsureArray': 70,
+ 'PyArray_EnsureAnyArray': 71,
+ 'PyArray_FromFile': 72,
+ 'PyArray_FromString': 73,
+ 'PyArray_FromBuffer': 74,
+ 'PyArray_FromIter': 75,
+ 'PyArray_Return': 76,
+ 'PyArray_GetField': 77,
+ 'PyArray_SetField': 78,
+ 'PyArray_Byteswap': 79,
+ 'PyArray_Resize': 80,
+ 'PyArray_MoveInto': 81,
+ 'PyArray_CopyInto': 82,
+ 'PyArray_CopyAnyInto': 83,
+ 'PyArray_CopyObject': 84,
+ 'PyArray_NewCopy': 85,
+ 'PyArray_ToList': 86,
+ 'PyArray_ToString': 87,
+ 'PyArray_ToFile': 88,
+ 'PyArray_Dump': 89,
+ 'PyArray_Dumps': 90,
+ 'PyArray_ValidType': 91,
+ 'PyArray_UpdateFlags': 92,
+ 'PyArray_New': 93,
+ 'PyArray_NewFromDescr': 94,
+ 'PyArray_DescrNew': 95,
+ 'PyArray_DescrNewFromType': 96,
+ 'PyArray_GetPriority': 97,
+ 'PyArray_IterNew': 98,
+ 'PyArray_MultiIterNew': 99,
+ 'PyArray_PyIntAsInt': 100,
+ 'PyArray_PyIntAsIntp': 101,
+ 'PyArray_Broadcast': 102,
+ 'PyArray_FillObjectArray': 103,
+ 'PyArray_FillWithScalar': 104,
+ 'PyArray_CheckStrides': 105,
+ 'PyArray_DescrNewByteorder': 106,
+ 'PyArray_IterAllButAxis': 107,
+ 'PyArray_CheckFromAny': 108,
+ 'PyArray_FromArray': 109,
+ 'PyArray_FromInterface': 110,
+ 'PyArray_FromStructInterface': 111,
+ 'PyArray_FromArrayAttr': 112,
+ 'PyArray_ScalarKind': 113,
+ 'PyArray_CanCoerceScalar': 114,
+ 'PyArray_NewFlagsObject': 115,
+ 'PyArray_CanCastScalar': 116,
+ 'PyArray_CompareUCS4': 117,
+ 'PyArray_RemoveSmallest': 118,
+ 'PyArray_ElementStrides': 119,
+ 'PyArray_Item_INCREF': 120,
+ 'PyArray_Item_XDECREF': 121,
+ 'PyArray_FieldNames': 122,
+ 'PyArray_Transpose': 123,
+ 'PyArray_TakeFrom': 124,
+ 'PyArray_PutTo': 125,
+ 'PyArray_PutMask': 126,
+ 'PyArray_Repeat': 127,
+ 'PyArray_Choose': 128,
+ 'PyArray_Sort': 129,
+ 'PyArray_ArgSort': 130,
+ 'PyArray_SearchSorted': 131,
+ 'PyArray_ArgMax': 132,
+ 'PyArray_ArgMin': 133,
+ 'PyArray_Reshape': 134,
+ 'PyArray_Newshape': 135,
+ 'PyArray_Squeeze': 136,
+ 'PyArray_View': 137,
+ 'PyArray_SwapAxes': 138,
+ 'PyArray_Max': 139,
+ 'PyArray_Min': 140,
+ 'PyArray_Ptp': 141,
+ 'PyArray_Mean': 142,
+ 'PyArray_Trace': 143,
+ 'PyArray_Diagonal': 144,
+ 'PyArray_Clip': 145,
+ 'PyArray_Conjugate': 146,
+ 'PyArray_Nonzero': 147,
+ 'PyArray_Std': 148,
+ 'PyArray_Sum': 149,
+ 'PyArray_CumSum': 150,
+ 'PyArray_Prod': 151,
+ 'PyArray_CumProd': 152,
+ 'PyArray_All': 153,
+ 'PyArray_Any': 154,
+ 'PyArray_Compress': 155,
+ 'PyArray_Flatten': 156,
+ 'PyArray_Ravel': 157,
+ 'PyArray_MultiplyList': 158,
+ 'PyArray_MultiplyIntList': 159,
+ 'PyArray_GetPtr': 160,
+ 'PyArray_CompareLists': 161,
+ 'PyArray_AsCArray': 162,
+ 'PyArray_As1D': 163,
+ 'PyArray_As2D': 164,
+ 'PyArray_Free': 165,
+ 'PyArray_Converter': 166,
+ 'PyArray_IntpFromSequence': 167,
+ 'PyArray_Concatenate': 168,
+ 'PyArray_InnerProduct': 169,
+ 'PyArray_MatrixProduct': 170,
+ 'PyArray_CopyAndTranspose': 171,
+ 'PyArray_Correlate': 172,
+ 'PyArray_TypestrConvert': 173,
+ 'PyArray_DescrConverter': 174,
+ 'PyArray_DescrConverter2': 175,
+ 'PyArray_IntpConverter': 176,
+ 'PyArray_BufferConverter': 177,
+ 'PyArray_AxisConverter': 178,
+ 'PyArray_BoolConverter': 179,
+ 'PyArray_ByteorderConverter': 180,
+ 'PyArray_OrderConverter': 181,
+ 'PyArray_EquivTypes': 182,
+ 'PyArray_Zeros': 183,
+ 'PyArray_Empty': 184,
+ 'PyArray_Where': 185,
+ 'PyArray_Arange': 186,
+ 'PyArray_ArangeObj': 187,
+ 'PyArray_SortkindConverter': 188,
+ 'PyArray_LexSort': 189,
+ 'PyArray_Round': 190,
+ 'PyArray_EquivTypenums': 191,
+ 'PyArray_RegisterDataType': 192,
+ 'PyArray_RegisterCastFunc': 193,
+ 'PyArray_RegisterCanCast': 194,
+ 'PyArray_InitArrFuncs': 195,
+ 'PyArray_IntTupleFromIntp': 196,
+ 'PyArray_TypeNumFromName': 197,
+ 'PyArray_ClipmodeConverter': 198,
+ 'PyArray_OutputConverter': 199,
+ 'PyArray_BroadcastToShape': 200,
+ '_PyArray_SigintHandler': 201,
+ '_PyArray_GetSigintBuf': 202,
+ 'PyArray_DescrAlignConverter': 203,
+ 'PyArray_DescrAlignConverter2': 204,
+ 'PyArray_SearchsideConverter': 205,
+ 'PyArray_CheckAxis': 206,
+ 'PyArray_OverflowMultiplyList': 207,
+ 'PyArray_CompareString': 208,
+ 'PyArray_MultiIterFromObjects': 209,
+ 'PyArray_GetEndianness': 210,
+ 'PyArray_GetNDArrayCFeatureVersion': 211,
+ 'PyArray_Correlate2': 212,
+ 'PyArray_NeighborhoodIterNew': 213,
+ # End 1.5 API
+ 'PyArray_SetDatetimeParseFunction': 219,
+ 'PyArray_DatetimeToDatetimeStruct': 220,
+ 'PyArray_TimedeltaToTimedeltaStruct': 221,
+ 'PyArray_DatetimeStructToDatetime': 222,
+ 'PyArray_TimedeltaStructToTimedelta': 223,
+ # New Iterator API
+ 'NpyIter_New': 224,
+ 'NpyIter_MultiNew': 225,
+ 'NpyIter_Copy': 226,
+ 'NpyIter_Deallocate': 227,
+ 'NpyIter_HasDelayedBufAlloc': 228,
+ 'NpyIter_HasInnerLoop': 229,
+ 'NpyIter_RemoveInnerLoop': 230,
+ 'NpyIter_GetInnerStrideArray': 231,
+ 'NpyIter_GetInnerLoopSizePtr': 232,
+ 'NpyIter_Reset': 233,
+ 'NpyIter_ResetBasePointers': 234,
+ 'NpyIter_ResetToIterIndexRange': 235,
+ 'NpyIter_GetNDim': 236,
+ 'NpyIter_GetNIter': 237,
+ 'NpyIter_GetIterNext': 238,
+ 'NpyIter_GetIterSize': 239,
+ 'NpyIter_GetIterIndexRange': 240,
+ 'NpyIter_GetIterIndex': 241,
+ 'NpyIter_GotoIterIndex': 242,
+ 'NpyIter_HasCoords': 243,
+ 'NpyIter_GetShape': 244,
+ 'NpyIter_GetGetCoords': 245,
+ 'NpyIter_GotoCoords': 246,
+ 'NpyIter_RemoveCoords': 247,
+ 'NpyIter_HasIndex': 248,
+ 'NpyIter_IsBuffered': 249,
+ 'NpyIter_IsGrowInner': 250,
+ 'NpyIter_GetBufferSize': 251,
+ 'NpyIter_GetIndexPtr': 252,
+ 'NpyIter_GotoIndex': 253,
+ 'NpyIter_GetDataPtrArray': 254,
+ 'NpyIter_GetDescrArray': 255,
+ 'NpyIter_GetOperandArray': 256,
+ 'NpyIter_GetIterView': 257,
+ 'NpyIter_GetReadFlags': 258,
+ 'NpyIter_GetWriteFlags': 259,
+ 'NpyIter_DebugPrint': 260,
+ 'NpyIter_IterationNeedsAPI': 261,
+ 'NpyIter_GetInnerFixedStrideArray': 262,
+ 'NpyIter_RemoveAxis': 263,
+ 'NpyIter_GetAxisStrideArray': 264,
+ 'NpyIter_RequiresBuffering': 265,
+ 'NpyIter_GetInitialDataPtrArray': 266,
+ 'NpyIter_CreateCompatibleStrides': 267,
+ #
+ 'PyArray_CastingConverter': 268,
+ 'PyArray_CountNonzero': 269,
+ 'PyArray_PromoteTypes': 270,
+ 'PyArray_MinScalarType': 271,
+ 'PyArray_ResultType': 272,
+ 'PyArray_CanCastArrayTo': 273,
+ 'PyArray_CanCastTypeTo': 274,
+ 'PyArray_EinsteinSum': 275,
+ 'PyArray_NewLikeArray': 276,
+ 'PyArray_GetArrayParamsFromObject': 277,
+ 'PyArray_ConvertClipmodeSequence': 278,
+ 'PyArray_MatrixProduct2': 279,
}
ufunc_types_api = {
@@ -291,6 +353,7 @@ ufunc_funcs_api = {
'PyUFunc_ReplaceLoopBySignature': 30,
'PyUFunc_FromFuncAndDataAndSignature': 31,
'PyUFunc_SetUsesArraysAsData': 32,
+ # End 1.5 API
'PyUFunc_e_e': 33,
'PyUFunc_e_e_As_f_f': 34,
'PyUFunc_e_e_As_d_d': 35,
diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py
index e97e50c87..602c0ebc5 100644
--- a/numpy/core/fromnumeric.py
+++ b/numpy/core/fromnumeric.py
@@ -1051,13 +1051,16 @@ def ravel(a, order='C'):
Parameters
----------
a : array_like
- Input array. The elements in `a` are read in the order specified by
+ Input array. The elements in ``a`` are read in the order specified by
`order`, and packed as a 1-D array.
- order : {'C','F', 'A'}, optional
- The elements of `a` are read in this order. It can be
- 'C' for row-major order, `F` for column-major order, or
- 'A' to preserve the order of `a` when possible.
- By default, row-major order is used.
+ order : {'C','F', 'A', 'K'}, optional
+ The elements of ``a`` are read in this order. 'C' means to view
+ the elements in C (row-major) order. 'F' means to view the elements
+ in Fortran (column-major) order. 'A' means to view the elements
+ in 'F' order if a is Fortran contiguous, 'C' order otherwise.
+ 'K' means to view the elements in the order they occur in memory,
+ except for reversing the data when strides are negative.
+ By default, 'C' order is used.
Returns
-------
@@ -1092,12 +1095,33 @@ def ravel(a, order='C'):
>>> print np.ravel(x, order='F')
[1 4 2 5 3 6]
- When `order` is 'A', it will preserve the array's 'C' or 'F' ordering:
+ When ``order`` is 'A', it will preserve the array's 'C' or 'F' ordering:
>>> print np.ravel(x.T)
[1 4 2 5 3 6]
>>> print np.ravel(x.T, order='A')
[1 2 3 4 5 6]
+
+ When ``order`` is 'K', it will preserve orderings that are neither 'C'
+ nor 'F', but won't reverse axes:
+
+ >>> a = np.arange(3)[::-1]; a
+ array([2, 1, 0])
+ >>> a.ravel(order='C')
+ array([2, 1, 0])
+ >>> a.ravel(order='K')
+ array([2, 1, 0])
+
+ >>> a = np.arange(12).reshape(2,3,2).swapaxes(1,2); a
+ array([[[ 0, 2, 4],
+ [ 1, 3, 5]],
+ [[ 6, 8, 10],
+ [ 7, 9, 11]]])
+ >>> a.ravel(order='C')
+ array([ 0, 2, 4, 1, 3, 5, 6, 8, 10, 7, 9, 11])
+ >>> a.ravel(order='K')
+ array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
+
"""
return asarray(a).ravel(order)
@@ -1136,6 +1160,8 @@ def nonzero(a):
array.
ndarray.nonzero :
Equivalent ndarray method.
+ count_nonzero :
+ Counts the number of non-zero elements in the input array.
Examples
--------
@@ -1762,8 +1788,10 @@ def amax(a, axis=None, out=None):
Returns
-------
- amax : ndarray
- A new array or scalar array with the result.
+ amax : ndarray or scalar
+ Maximum of `a`. If `axis` is None, the result is a scalar value.
+ If `axis` is given, the result is an array of dimension
+ ``a.ndim - 1``.
See Also
--------
diff --git a/numpy/core/getlimits.py b/numpy/core/getlimits.py
index 198862d6a..53728bc59 100644
--- a/numpy/core/getlimits.py
+++ b/numpy/core/getlimits.py
@@ -27,18 +27,21 @@ class finfo(object):
Attributes
----------
- eps : floating point number of the appropriate type
- The smallest representable number such that ``1.0 + eps != 1.0``.
+ eps : float
+ The smallest representable positive number such that
+ ``1.0 + eps != 1.0``. Type of `eps` is an appropriate floating
+ point type.
epsneg : floating point number of the appropriate type
- The smallest representable number such that ``1.0 - epsneg != 1.0``.
+ The smallest representable positive number such that
+ ``1.0 - epsneg != 1.0``.
iexp : int
The number of bits in the exponent portion of the floating point
representation.
machar : MachAr
- The object which calculated these parameters and holds more detailed
- information.
+ The object which calculated these parameters and holds more
+ detailed information.
machep : int
- The exponent that yields ``eps``.
+ The exponent that yields `eps`.
max : floating point number of the appropriate type
The largest representable number.
maxexp : int
@@ -46,27 +49,28 @@ class finfo(object):
min : floating point number of the appropriate type
The smallest representable number, typically ``-max``.
minexp : int
- The most negative power of the base (2) consistent with there being
- no leading 0's in the mantissa.
+ The most negative power of the base (2) consistent with there
+ being no leading 0's in the mantissa.
negep : int
- The exponent that yields ``epsneg``.
+ The exponent that yields `epsneg`.
nexp : int
The number of bits in the exponent including its sign and bias.
nmant : int
The number of bits in the mantissa.
precision : int
- The approximate number of decimal digits to which this kind of float
- is precise.
+ The approximate number of decimal digits to which this kind of
+ float is precise.
resolution : floating point number of the appropriate type
- The approximate decimal resolution of this type, i.e.
+ The approximate decimal resolution of this type, i.e.,
``10**-precision``.
- tiny : floating point number of the appropriate type
- The smallest-magnitude usable number.
+ tiny : float
+ The smallest positive usable number. Type of `tiny` is an
+ appropriate floating point type.
Parameters
----------
- dtype : floating point type, dtype, or instance
- The kind of floating point data type to get information about.
+ dtype : float, dtype, or instance
+ Kind of floating point data-type about which to get information.
See Also
--------
@@ -75,10 +79,10 @@ class finfo(object):
Notes
-----
- For developers of NumPy: do not instantiate this at the module level. The
- initial calculation of these parameters is expensive and negatively impacts
- import times. These objects are cached, so calling ``finfo()`` repeatedly
- inside your functions is not a problem.
+ For developers of NumPy: do not instantiate this at the module level.
+ The initial calculation of these parameters is expensive and negatively
+ impacts import times. These objects are cached, so calling ``finfo()``
+ repeatedly inside your functions is not a problem.
"""
diff --git a/numpy/core/include/numpy/ndarraytypes.h b/numpy/core/include/numpy/ndarraytypes.h
index 98d02287a..d37f1ce38 100644
--- a/numpy/core/include/numpy/ndarraytypes.h
+++ b/numpy/core/include/numpy/ndarraytypes.h
@@ -65,16 +65,24 @@ enum NPY_TYPES { NPY_BOOL=0,
NPY_INT, NPY_UINT,
NPY_LONG, NPY_ULONG,
NPY_LONGLONG, NPY_ULONGLONG,
- NPY_HALF, NPY_FLOAT, NPY_DOUBLE, NPY_LONGDOUBLE,
+ NPY_FLOAT, NPY_DOUBLE, NPY_LONGDOUBLE,
NPY_CFLOAT, NPY_CDOUBLE, NPY_CLONGDOUBLE,
- NPY_DATETIME, NPY_TIMEDELTA,
- NPY_OBJECT=20,
+ NPY_OBJECT=17,
NPY_STRING, NPY_UNICODE,
NPY_VOID,
+ /*
+ * New 1.6 types appended, may be integrated
+ * into the above in 2.0.
+ */
+ NPY_DATETIME, NPY_TIMEDELTA, NPY_HALF,
+
NPY_NTYPES,
NPY_NOTYPE,
NPY_CHAR, /* special flag */
- NPY_USERDEF=256 /* leave room for characters */
+ NPY_USERDEF=256, /* leave room for characters */
+
+ /* The number of types not including the new 1.6 types */
+ NPY_NTYPES_ABI_COMPATIBLE=21
};
#define NPY_METADATA_DTSTR "__frequency__"
@@ -88,8 +96,7 @@ enum NPY_TYPES { NPY_BOOL=0,
/* default scalar priority */
#define NPY_SCALAR_PRIORITY -1000000.0
-/*TODO HALF - This is used as how many complex floating point types in the code */
-/* How many floating point types are there */
+/* How many floating point types are there (excluding half) */
#define NPY_NUM_FLOATTYPE 3
/*
@@ -174,12 +181,31 @@ typedef enum {
} NPY_SCALARKIND;
#define NPY_NSCALARKINDS (NPY_OBJECT_SCALAR + 1)
+/* For specifying array memory layout or iteration order */
typedef enum {
+ /* Fortran order if inputs are all Fortran, C otherwise */
NPY_ANYORDER=-1,
+ /* C order */
NPY_CORDER=0,
- NPY_FORTRANORDER=1
+ /* Fortran order */
+ NPY_FORTRANORDER=1,
+ /* An order as close to the inputs as possible */
+ NPY_KEEPORDER=2
} NPY_ORDER;
+/* For specifying allowed casting in operations which support it */
+typedef enum {
+ /* Only allow identical types */
+ NPY_NO_CASTING=0,
+ /* Allow identical and byte swapped types */
+ NPY_EQUIV_CASTING=1,
+ /* Only allow safe casts */
+ NPY_SAFE_CASTING=2,
+ /* Allow safe casts or casts within the same kind */
+ NPY_SAME_KIND_CASTING=3,
+ /* Allow any casts */
+ NPY_UNSAFE_CASTING=4
+} NPY_CASTING;
typedef enum {
NPY_CLIP=0,
@@ -394,6 +420,14 @@ typedef struct {
} PyArray_Dims;
typedef struct {
+ /*
+ * Functions to cast to most other standard types
+ * Can have some NULL entries. The types
+ * DATETIME, TIMEDELTA, and HALF go into the castdict
+ * even though they are built-in.
+ */
+ PyArray_VectorUnaryFunc *cast[NPY_NTYPES_ABI_COMPATIBLE];
+
/* The next four functions *cannot* be NULL */
/*
@@ -487,22 +521,6 @@ typedef struct {
PyArray_FastClipFunc *fastclip;
PyArray_FastPutmaskFunc *fastputmask;
PyArray_FastTakeFunc *fasttake;
-
- /*
- * A little room to grow --- should use generic function
- * interface for most additions
- */
- void *pad1;
- void *pad2;
- void *pad3;
- void *pad4;
-
- /*
- * Functions to cast to all other standard types
- * Can have some NULL entries
- */
- PyArray_VectorUnaryFunc *cast[NPY_NTYPES];
-
} PyArray_ArrFuncs;
/* The item must be reference counted when it is inserted or extracted. */
@@ -554,8 +572,7 @@ typedef struct _PyArray_Descr {
* '>' (big), '<' (little), '|'
* (not-applicable), or '=' (native).
*/
- char unused;
- int flags; /* flag describing data type */
+ char flags; /* flags describing data type */
int type_num; /* number representing this type */
int elsize; /* element size for this type */
int alignment; /* alignment needed for this type */
@@ -778,8 +795,9 @@ typedef int (PyArray_FinalizeFunc)(PyArrayObject *, PyObject *);
*/
#define NPY_MIN_BUFSIZE ((int)sizeof(cdouble))
#define NPY_MAX_BUFSIZE (((int)sizeof(cdouble))*1000000)
-#define NPY_BUFSIZE 10000
-/* #define NPY_BUFSIZE 80*/
+#define NPY_BUFSIZE 8192
+/* buffer stress test size: */
+/*#define NPY_BUFSIZE 17*/
#define PyArray_MAX(a,b) (((a)>(b))?(a):(b))
#define PyArray_MIN(a,b) (((a)<(b))?(a):(b))
@@ -807,6 +825,8 @@ typedef int (PyArray_FinalizeFunc)(PyArrayObject *, PyObject *);
#define PyArray_ISWRITEABLE(m) PyArray_CHKFLAGS(m, NPY_WRITEABLE)
#define PyArray_ISALIGNED(m) PyArray_CHKFLAGS(m, NPY_ALIGNED)
+#define PyArray_IS_C_CONTIGUOUS(m) PyArray_CHKFLAGS(m, NPY_C_CONTIGUOUS)
+#define PyArray_IS_F_CONTIGUOUS(m) PyArray_CHKFLAGS(m, NPY_F_CONTIGUOUS)
#if NPY_ALLOW_THREADS
#define NPY_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
@@ -840,6 +860,76 @@ typedef int (PyArray_FinalizeFunc)(PyArrayObject *, PyObject *);
#endif
/*****************************
+ * New iterator object
+ *****************************/
+
+/* The actual structure of the iterator is an internal detail */
+typedef struct NpyIter_InternalOnly NpyIter;
+
+/* Iterator function pointers that may be specialized */
+typedef int (NpyIter_IterNextFunc)(NpyIter *iter);
+typedef void (NpyIter_GetCoordsFunc)(NpyIter *iter,
+ npy_intp *outcoords);
+
+/*** Global flags that may be passed to the iterator constructors ***/
+
+/* Track an index representing C order */
+#define NPY_ITER_C_INDEX 0x00000001
+/* Track an index representing Fortran order */
+#define NPY_ITER_F_INDEX 0x00000002
+/* Track coordinates */
+#define NPY_ITER_COORDS 0x00000004
+/* Let the caller handle the inner loop of iteration */
+#define NPY_ITER_NO_INNER_ITERATION 0x00000008
+/* Convert all the operands to a common data type */
+#define NPY_ITER_COMMON_DTYPE 0x00000010
+/* Operands may hold references, requiring API access during iteration */
+#define NPY_ITER_REFS_OK 0x00000020
+/* Zero-sized operands should be permitted, iteration checks IterSize for 0 */
+#define NPY_ITER_ZEROSIZE_OK 0x00000040
+/* Permits reductions (size-0 stride with dimension size > 1) */
+#define NPY_ITER_REDUCE_OK 0x00000080
+/* Enables sub-range iteration */
+#define NPY_ITER_RANGED 0x00000100
+/* Enables buffering */
+#define NPY_ITER_BUFFERED 0x00000200
+/* When buffering is enabled, grows the inner loop if possible */
+#define NPY_ITER_GROWINNER 0x00000400
+/* Delay allocation of buffers until first Reset* call */
+#define NPY_ITER_DELAY_BUFALLOC 0x00000800
+/* When NPY_KEEPORDER is specified, disable reversing negative-stride axes */
+#define NPY_ITER_DONT_NEGATE_STRIDES 0x00001000
+
+/*** Per-operand flags that may be passed to the iterator constructors ***/
+
+/* The operand will be read from and written to */
+#define NPY_ITER_READWRITE 0x00010000
+/* The operand will only be read from */
+#define NPY_ITER_READONLY 0x00020000
+/* The operand will only be written to */
+#define NPY_ITER_WRITEONLY 0x00040000
+/* The operand's data must be in native byte order */
+#define NPY_ITER_NBO 0x00080000
+/* The operand's data must be aligned */
+#define NPY_ITER_ALIGNED 0x00100000
+/* The operand's data must be contiguous (within the inner loop) */
+#define NPY_ITER_CONTIG 0x00200000
+/* The operand may be copied to satisfy requirements */
+#define NPY_ITER_COPY 0x00400000
+/* The operand may be copied with UPDATEIFCOPY to satisfy requirements */
+#define NPY_ITER_UPDATEIFCOPY 0x00800000
+/* Allocate the operand if it is NULL */
+#define NPY_ITER_ALLOCATE 0x01000000
+/* If an operand is allocated, don't use any subtype */
+#define NPY_ITER_NO_SUBTYPE 0x02000000
+/* Require that the dimension match the iterator dimensions exactly */
+#define NPY_ITER_NO_BROADCAST 0x08000000
+
+#define NPY_ITER_GLOBAL_FLAGS 0x0000ffff
+#define NPY_ITER_PER_OP_FLAGS 0xffff0000
+
+
+/*****************************
* Basic iterator object
*****************************/
@@ -1232,10 +1322,12 @@ PyArrayNeighborhoodIter_Next2D(PyArrayNeighborhoodIterObject* iter);
#define PyTypeNum_ISINTEGER(type) (((type) >= NPY_BYTE) && \
((type) <= NPY_ULONGLONG))
-#define PyTypeNum_ISFLOAT(type) (((type) >= NPY_HALF) && \
- ((type) <= NPY_LONGDOUBLE))
+#define PyTypeNum_ISFLOAT(type) ((((type) >= NPY_FLOAT) && \
+ ((type) <= NPY_LONGDOUBLE)) || \
+ ((type) == NPY_HALF))
-#define PyTypeNum_ISNUMBER(type) ((type) <= NPY_CLONGDOUBLE)
+#define PyTypeNum_ISNUMBER(type) (((type) <= NPY_CLONGDOUBLE) || \
+ ((type) == NPY_HALF))
#define PyTypeNum_ISSTRING(type) (((type) == NPY_STRING) || \
((type) == NPY_UNICODE))
diff --git a/numpy/core/include/numpy/npy_common.h b/numpy/core/include/numpy/npy_common.h
index 998cfdaef..145fe2142 100644
--- a/numpy/core/include/numpy/npy_common.h
+++ b/numpy/core/include/numpy/npy_common.h
@@ -7,7 +7,11 @@
#if defined(_MSC_VER)
#define NPY_INLINE __inline
#elif defined(__GNUC__)
- #define NPY_INLINE inline
+ #if defined(__STRICT_ANSI__)
+ #define NPY_INLINE __inline__
+ #else
+ #define NPY_INLINE inline
+ #endif
#else
#define NPY_INLINE
#endif
diff --git a/numpy/core/include/numpy/npy_math.h b/numpy/core/include/numpy/npy_math.h
index abdb34d21..56c1c2b28 100644
--- a/numpy/core/include/numpy/npy_math.h
+++ b/numpy/core/include/numpy/npy_math.h
@@ -177,7 +177,7 @@ double npy_spacing(double x);
#ifndef NPY_HAVE_DECL_SIGNBIT
int _npy_signbit_f(float x);
int _npy_signbit_d(double x);
- int _npy_signbit_ld(npy_longdouble x);
+ int _npy_signbit_ld(long double x);
#define npy_signbit(x) \
(sizeof (x) == sizeof (long double) ? _npy_signbit_ld (x) \
: sizeof (x) == sizeof (double) ? _npy_signbit_d (x) \
@@ -422,4 +422,14 @@ npy_clongdouble npy_csqrtl(npy_clongdouble z);
npy_clongdouble npy_ccosl(npy_clongdouble z);
npy_clongdouble npy_csinl(npy_clongdouble z);
+/*
+ * Functions that set the floating point error
+ * status word.
+ */
+
+void npy_set_floatstatus_divbyzero(void);
+void npy_set_floatstatus_overflow(void);
+void npy_set_floatstatus_underflow(void);
+void npy_set_floatstatus_invalid(void);
+
#endif
diff --git a/numpy/core/include/numpy/ufuncobject.h b/numpy/core/include/numpy/ufuncobject.h
index 35d173cda..b6f534425 100644
--- a/numpy/core/include/numpy/ufuncobject.h
+++ b/numpy/core/include/numpy/ufuncobject.h
@@ -1,5 +1,8 @@
#ifndef Py_UFUNCOBJECT_H
#define Py_UFUNCOBJECT_H
+
+#include <numpy/npy_math.h>
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -8,31 +11,65 @@ typedef void (*PyUFuncGenericFunction) (char **, npy_intp *, npy_intp *, void *)
typedef struct {
PyObject_HEAD
+ /*
+ * nin: Number of inputs
+ * nout: Number of outputs
+ * nargs: Always nin + nout (Why is it stored?)
+ */
int nin, nout, nargs;
+
+ /* Identity for reduction, either PyUFunc_One or PyUFunc_Zero */
int identity;
+
+ /* Array of one-dimensional core loops */
PyUFuncGenericFunction *functions;
+ /* Array of funcdata that gets passed into the functions */
void **data;
+ /* The number of elements in 'functions' and 'data' */
int ntypes;
+
+ /* Does not appear to be used */
int check_return;
- char *name, *types;
+
+ /* The name of the ufunc */
+ char *name;
+
+ /* Array of type numbers, of size ('nargs' * 'ntypes') */
+ char *types;
+
+ /* Documentation string */
char *doc;
+
void *ptr;
PyObject *obj;
PyObject *userloops;
- /* generalized ufunc */
- int core_enabled; /* 0 for scalar ufunc; 1 for generalized ufunc */
- int core_num_dim_ix; /* number of distinct dimension names in
- signature */
+ /* generalized ufunc parameters */
+
+ /* 0 for scalar ufunc; 1 for generalized ufunc */
+ int core_enabled;
+ /* number of distinct dimension names in signature */
+ int core_num_dim_ix;
- /* dimension indices of input/output argument k are stored in
- core_dim_ixs[core_offsets[k]..core_offsets[k]+core_num_dims[k]-1] */
- int *core_num_dims; /* numbers of core dimensions of each argument */
- int *core_dim_ixs; /* dimension indices in a flatted form; indices
- are in the range of [0,core_num_dim_ix) */
- int *core_offsets; /* positions of 1st core dimensions of each
- argument in core_dim_ixs */
- char *core_signature; /* signature string for printing purpose */
+ /*
+ * dimension indices of input/output argument k are stored in
+ * core_dim_ixs[core_offsets[k]..core_offsets[k]+core_num_dims[k]-1]
+ */
+
+ /* numbers of core dimensions of each argument */
+ int *core_num_dims;
+ /*
+ * dimension indices in a flatted form; indices
+ * are in the range of [0,core_num_dim_ix)
+ */
+ int *core_dim_ixs;
+ /*
+ * positions of 1st core dimensions of each
+ * argument in core_dim_ixs
+ */
+ int *core_offsets;
+ /* signature string for printing purpose */
+ char *core_signature;
} PyUFuncObject;
#include "arrayobject.h"
@@ -65,7 +102,8 @@ typedef struct {
#define UFUNC_FPE_UNDERFLOW 4
#define UFUNC_FPE_INVALID 8
-#define UFUNC_ERR_DEFAULT 0 /* Error mode that avoids look-up (no checking) */
+/* Error mode that avoids look-up (no checking) */
+#define UFUNC_ERR_DEFAULT 0
#define UFUNC_OBJ_ISOBJECT 1
#define UFUNC_OBJ_NEEDS_API 2
@@ -76,126 +114,6 @@ typedef struct {
(UFUNC_ERR_PRINT << UFUNC_SHIFT_OVERFLOW) + \
(UFUNC_ERR_PRINT << UFUNC_SHIFT_INVALID)
- /* Only internal -- not exported, yet*/
-typedef struct {
- /* Multi-iterator portion --- needs to be present in this order
- to work with PyArray_Broadcast */
- PyObject_HEAD
- int numiter;
- npy_intp size;
- npy_intp index;
- int nd;
- npy_intp dimensions[NPY_MAXDIMS];
- PyArrayIterObject *iters[NPY_MAXARGS];
- /* End of Multi-iterator portion */
-
- /* The ufunc */
- PyUFuncObject *ufunc;
-
- /* The error handling */
- int errormask; /* Integer showing desired error handling */
- PyObject *errobj; /* currently a tuple with
- (string, func or obj with write method or None)
- */
- int first;
-
- /* Specific function and data to use */
- PyUFuncGenericFunction function;
- void *funcdata;
-
- /* Loop method */
- int meth;
-
- /* Whether we need to copy to a buffer or not.*/
- int needbuffer[NPY_MAXARGS];
- int leftover;
- int ninnerloops;
- int lastdim;
-
- /* Whether or not to swap */
- int swap[NPY_MAXARGS];
-
- /* Buffers for the loop */
- char *buffer[NPY_MAXARGS];
- int bufsize;
- npy_intp bufcnt;
- char *dptr[NPY_MAXARGS];
-
- /* For casting */
- char *castbuf[NPY_MAXARGS];
- PyArray_VectorUnaryFunc *cast[NPY_MAXARGS];
-
- /* usually points to buffer but when a cast is to be
- done it switches for that argument to castbuf.
- */
- char *bufptr[NPY_MAXARGS];
-
- /* Steps filled in from iters or sizeof(item)
- depending on loop method.
- */
- npy_intp steps[NPY_MAXARGS];
-
- int obj; /* This loop uses object arrays or needs the Python API */
- /* Flags: UFUNC_OBJ_ISOBJECT, UFUNC_OBJ_NEEDS_API */
- int notimplemented; /* The loop caused notimplemented */
- int objfunc; /* This loop calls object functions
- (an inner-loop function with argument types */
-
- /* generalized ufunc */
- npy_intp *core_dim_sizes; /* stores sizes of core dimensions;
- contains 1 + core_num_dim_ix elements */
- npy_intp *core_strides; /* strides of loop and core dimensions */
-} PyUFuncLoopObject;
-
-/* Could make this more clever someday */
-#define UFUNC_MAXIDENTITY 32
-
-typedef struct {
- PyObject_HEAD
- PyArrayIterObject *it;
- PyArrayObject *ret;
- PyArrayIterObject *rit; /* Needed for Accumulate */
- int outsize;
- npy_intp index;
- npy_intp size;
- char idptr[UFUNC_MAXIDENTITY];
-
- /* The ufunc */
- PyUFuncObject *ufunc;
-
- /* The error handling */
- int errormask;
- PyObject *errobj;
- int first;
-
- PyUFuncGenericFunction function;
- void *funcdata;
- int meth;
- int swap;
-
- char *buffer;
- int bufsize;
-
- char *castbuf;
- PyArray_VectorUnaryFunc *cast;
-
- char *bufptr[3];
- npy_intp steps[3];
-
- npy_intp N;
- int instrides;
- int insize;
- char *inptr;
-
- /* For copying small arrays */
- PyObject *decref;
-
- int obj;
- int retbase;
-
-} PyUFuncReduceObject;
-
-
#if NPY_ALLOW_THREADS
#define NPY_LOOP_BEGIN_THREADS do {if (!(loop->obj & UFUNC_OBJ_NEEDS_API)) _save = PyEval_SaveThread();} while (0)
#define NPY_LOOP_END_THREADS do {if (!(loop->obj & UFUNC_OBJ_NEEDS_API)) PyEval_RestoreThread(_save);} while (0)
@@ -289,7 +207,9 @@ typedef struct _loop1d_info {
/* Solaris --------------------------------------------------------*/
/* --------ignoring SunOS ieee_flags approach, someone else can
** deal with that! */
-#elif defined(sun) || defined(__BSD__) || defined(__OpenBSD__) || (defined(__FreeBSD__) && (__FreeBSD_version < 502114)) || defined(__NetBSD__)
+#elif defined(sun) || defined(__BSD__) || defined(__OpenBSD__) || \
+ (defined(__FreeBSD__) && (__FreeBSD_version < 502114)) || \
+ defined(__NetBSD__)
#include <ieeefp.h>
#define UFUNC_CHECK_STATUS(ret) { \
@@ -303,9 +223,12 @@ typedef struct _loop1d_info {
(void) fpsetsticky(0); \
}
-#elif defined(__GLIBC__) || defined(__APPLE__) || defined(__CYGWIN__) || defined(__MINGW32__) || (defined(__FreeBSD__) && (__FreeBSD_version >= 502114))
+#elif defined(__GLIBC__) || defined(__APPLE__) || \
+ defined(__CYGWIN__) || defined(__MINGW32__) || \
+ (defined(__FreeBSD__) && (__FreeBSD_version >= 502114))
-#if defined(__GLIBC__) || defined(__APPLE__) || defined(__MINGW32__) || defined(__FreeBSD__)
+#if defined(__GLIBC__) || defined(__APPLE__) || \
+ defined(__MINGW32__) || defined(__FreeBSD__)
#include <fenv.h>
#elif defined(__CYGWIN__)
#include "fenv/fenv.c"
@@ -322,11 +245,6 @@ typedef struct _loop1d_info {
FE_UNDERFLOW | FE_INVALID); \
}
-#define generate_divbyzero_error() feraiseexcept(FE_DIVBYZERO)
-#define generate_overflow_error() feraiseexcept(FE_OVERFLOW)
-#define generate_underflow_error() feraiseexcept(FE_UNDERFLOW)
-#define generate_invalid_error() feraiseexcept(FE_INVALID)
-
#elif defined(_AIX)
#include <float.h>
@@ -334,7 +252,7 @@ typedef struct _loop1d_info {
#define UFUNC_CHECK_STATUS(ret) { \
fpflag_t fpstatus; \
- \
+ \
fpstatus = fp_read_flag(); \
ret = ((FP_DIV_BY_ZERO & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0) \
| ((FP_OVERFLOW & fpstatus) ? UFUNC_FPE_OVERFLOW : 0) \
@@ -343,77 +261,21 @@ typedef struct _loop1d_info {
fp_swap_flag(0); \
}
-#define generate_divbyzero_error() fp_raise_xcp(FP_DIV_BY_ZERO)
-#define generate_overflow_error() fp_raise_xcp(FP_OVERFLOW)
-#define generate_underflow_error() fp_raise_xcp(FP_UNDERFLOW)
-#define generate_invalid_error() fp_raise_xcp(FP_INVALID)
-
#else
#define NO_FLOATING_POINT_SUPPORT
#define UFUNC_CHECK_STATUS(ret) { \
- ret = 0; \
+ ret = 0; \
}
#endif
-/* These should really be altered to just set the corresponding bit
- in the floating point status flag. Need to figure out how to do that
- on all the platforms...
-*/
-
-#if !defined(generate_divbyzero_error)
-static int numeric_zero2 = 0;
-static void generate_divbyzero_error(void) {
- double dummy;
- dummy = 1./numeric_zero2;
- if (dummy) /* to prevent optimizer from eliminating expression */
- return;
- else /* should never be called */
- numeric_zero2 += 1;
- return;
-}
-#endif
-
-#if !defined(generate_overflow_error)
-static double numeric_two = 2.0;
-static void generate_overflow_error(void) {
- double dummy;
- dummy = pow(numeric_two,1000);
- if (dummy)
- return;
- else
- numeric_two += 0.1;
- return;
- return;
-}
-#endif
-
-#if !defined(generate_underflow_error)
-static double numeric_small = 1e-300;
-static void generate_underflow_error(void) {
- double dummy;
- dummy = numeric_small * 1e-300;
- if (!dummy)
- return;
- else
- numeric_small += 1e-300;
- return;
-}
-#endif
-
-#if !defined(generate_invalid_error)
-static double numeric_inv_inf = NPY_INF;
-static void generate_invalid_error(void) {
- double dummy;
- dummy = numeric_inv_inf - NPY_INF;
- if (!dummy)
- return;
- else
- numeric_inv_inf += 1.0;
- return;
-}
-#endif
+/*
+ * THESE MACROS ARE DEPRECATED.
+ * Use npy_set_floatstatus_* in the npymath library.
+ */
+#define generate_divbyzero_error() npy_set_floatstatus_divbyzero()
+#define generate_overflow_error() npy_set_floatstatus_overflow()
/* Make sure it gets defined if it isn't already */
#ifndef UFUNC_NOFPE
diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py
index 71f5de93c..844e13c4e 100644
--- a/numpy/core/memmap.py
+++ b/numpy/core/memmap.py
@@ -278,11 +278,6 @@ class memmap(ndarray):
if self._mmap is not None:
self._mmap.flush()
- def sync(self):
- """This method is deprecated, use `flush`."""
- warnings.warn("Use ``flush``.", DeprecationWarning)
- self.flush()
-
def _close(self):
"""Close the memmap file. Only do this when deleting the object."""
if self.base is self._mmap:
@@ -292,11 +287,6 @@ class memmap(ndarray):
self._mmap.close()
self._mmap = None
- def close(self):
- """Close the memmap file. Does nothing."""
- warnings.warn("``close`` is deprecated on memmap arrays. Use del",
- DeprecationWarning)
-
def __del__(self):
# We first check if we are the owner of the mmap, rather than
# a view, so deleting a view does not call _close
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py
index dbad73cfe..fa9f19165 100644
--- a/numpy/core/numeric.py
+++ b/numpy/core/numeric.py
@@ -1,12 +1,12 @@
-__all__ = ['newaxis', 'ndarray', 'flatiter', 'ufunc',
- 'arange', 'array', 'zeros', 'empty', 'broadcast', 'dtype',
- 'fromstring', 'fromfile', 'frombuffer',
+__all__ = ['newaxis', 'ndarray', 'flatiter', 'newiter', 'nested_iters', 'ufunc',
+ 'arange', 'array', 'zeros', 'count_nonzero', 'empty', 'broadcast',
+ 'dtype', 'fromstring', 'fromfile', 'frombuffer',
'int_asbuffer', 'where', 'argwhere',
- 'concatenate', 'fastCopyAndTranspose', 'lexsort',
- 'set_numeric_ops', 'can_cast',
+ 'concatenate', 'fastCopyAndTranspose', 'lexsort', 'set_numeric_ops',
+ 'can_cast', 'promote_types', 'min_scalar_type', 'result_type',
'asarray', 'asanyarray', 'ascontiguousarray', 'asfortranarray',
'isfortran', 'empty_like', 'zeros_like',
- 'correlate', 'convolve', 'inner', 'dot', 'outer', 'vdot',
+ 'correlate', 'convolve', 'inner', 'dot', 'einsum', 'outer', 'vdot',
'alterdot', 'restoredot', 'roll', 'rollaxis', 'cross', 'tensordot',
'array2string', 'get_printoptions', 'set_printoptions',
'array_repr', 'array_str', 'set_string_function',
@@ -54,23 +54,32 @@ BUFSIZE = multiarray.BUFSIZE
ndarray = multiarray.ndarray
flatiter = multiarray.flatiter
+newiter = multiarray.newiter
+nested_iters = multiarray.nested_iters
broadcast = multiarray.broadcast
dtype = multiarray.dtype
ufunc = type(sin)
# originally from Fernando Perez's IPython
-def zeros_like(a):
+def zeros_like(a, dtype=None, order='K'):
"""
Return an array of zeros with the same shape and type as a given array.
- Equivalent to ``a.copy().fill(0)``.
+ With default parameters, is equivalent to ``a.copy().fill(0)``.
Parameters
----------
a : array_like
The shape and data-type of `a` define these same attributes of
the returned array.
+ dtype : data-type, optional
+ Overrides the data type of the result.
+ order : {'C', 'F', 'A', or 'K'}, optional
+ Overrides the memory layout of the result. 'C' means C-order,
+ 'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous,
+ 'C' otherwise. 'K' means match the layout of `a` as closely
+ as possible.
Returns
-------
@@ -103,72 +112,8 @@ def zeros_like(a):
array([ 0., 0., 0.])
"""
- if isinstance(a, ndarray):
- res = ndarray.__new__(type(a), a.shape, a.dtype, order=a.flags.fnc)
- res.fill(0)
- return res
- try:
- wrap = a.__array_wrap__
- except AttributeError:
- wrap = None
- a = asarray(a)
- res = zeros(a.shape, a.dtype)
- if wrap:
- res = wrap(res)
- return res
-
-def empty_like(a):
- """
- Return a new array with the same shape and type as a given array.
-
- Parameters
- ----------
- a : array_like
- The shape and data-type of `a` define these same attributes of the
- returned array.
-
- Returns
- -------
- out : ndarray
- Array of random data with the same shape and type as `a`.
-
- See Also
- --------
- ones_like : Return an array of ones with shape and type of input.
- zeros_like : Return an array of zeros with shape and type of input.
- empty : Return a new uninitialized array.
- ones : Return a new array setting values to one.
- zeros : Return a new array setting values to zero.
-
- Notes
- -----
- This function does *not* initialize the returned array; to do that use
- `zeros_like` or `ones_like` instead. It may be marginally faster than
- the functions that do set the array values.
-
- Examples
- --------
- >>> a = ([1,2,3], [4,5,6]) # a is array-like
- >>> np.empty_like(a)
- array([[-1073741821, -1073741821, 3], #random
- [ 0, 0, -1073741821]])
- >>> a = np.array([[1., 2., 3.],[4.,5.,6.]])
- >>> np.empty_like(a)
- array([[ -2.00000715e+000, 1.48219694e-323, -2.00000572e+000],#random
- [ 4.38791518e-305, -2.00000715e+000, 4.17269252e-309]])
-
- """
- if isinstance(a, ndarray):
- res = ndarray.__new__(type(a), a.shape, a.dtype, order=a.flags.fnc)
- return res
- try:
- wrap = a.__array_wrap__
- except AttributeError:
- wrap = None
- a = asarray(a)
- res = empty(a.shape, a.dtype)
- if wrap:
- res = wrap(res)
+ res = empty_like(a, dtype=dtype, order=order)
+ res.fill(0)
return res
# end Fernando's utilities
@@ -195,7 +140,9 @@ newaxis = None
arange = multiarray.arange
array = multiarray.array
zeros = multiarray.zeros
+count_nonzero = multiarray.count_nonzero
empty = multiarray.empty
+empty_like = multiarray.empty_like
fromstring = multiarray.fromstring
fromiter = multiarray.fromiter
fromfile = multiarray.fromfile
@@ -209,9 +156,13 @@ concatenate = multiarray.concatenate
fastCopyAndTranspose = multiarray._fastCopyAndTranspose
set_numeric_ops = multiarray.set_numeric_ops
can_cast = multiarray.can_cast
+promote_types = multiarray.promote_types
+min_scalar_type = multiarray.min_scalar_type
+result_type = multiarray.result_type
lexsort = multiarray.lexsort
compare_chararrays = multiarray.compare_chararrays
putmask = multiarray.putmask
+einsum = multiarray.einsum
def asarray(a, dtype=None, order=None):
"""
@@ -810,6 +761,10 @@ def outer(a,b):
out : ndarray, shape (M, N)
``out[i, j] = a[i] * b[j]``
+ See also
+ --------
+ inner, einsum
+
References
----------
.. [1] : G. H. Golub and C. F. van Loan, *Matrix Computations*, 3rd
@@ -900,7 +855,7 @@ def tensordot(a, b, axes=2):
See Also
--------
- numpy.dot
+ dot, einsum
Notes
-----
diff --git a/numpy/core/numerictypes.py b/numpy/core/numerictypes.py
index 4f16d2e3a..8874667d8 100644
--- a/numpy/core/numerictypes.py
+++ b/numpy/core/numerictypes.py
@@ -589,6 +589,11 @@ def issctype(rep):
>>> np.issctype(1.1)
False
+ Strings are also a scalar type:
+
+ >>> np.issctype(np.dtype('str'))
+ True
+
"""
if not isinstance(rep, (type, dtype)):
return False
@@ -601,6 +606,44 @@ def issctype(rep):
return False
def obj2sctype(rep, default=None):
+ """
+ Return the scalar dtype or NumPy equivalent of Python type of an object.
+
+ Parameters
+ ----------
+ rep : any
+ The object of which the type is returned.
+ default : any, optional
+ If given, this is returned for objects whose types can not be
+ determined. If not given, None is returned for those objects.
+
+ Returns
+ -------
+ dtype : dtype or Python type
+ The data type of `rep`.
+
+ See Also
+ --------
+ sctype2char, issctype, issubsctype, issubdtype, maximum_sctype
+
+ Examples
+ --------
+ >>> np.obj2sctype(np.int32)
+ <type 'numpy.int32'>
+ >>> np.obj2sctype(np.array([1., 2.]))
+ <type 'numpy.float64'>
+ >>> np.obj2sctype(np.array([1.j]))
+ <type 'numpy.complex128'>
+
+ >>> np.obj2sctype(dict)
+ <type 'numpy.object_'>
+ >>> np.obj2sctype('string')
+ <type 'numpy.string_'>
+
+ >>> np.obj2sctype(1, default=list)
+ <type 'list'>
+
+ """
try:
if issubclass(rep, generic):
return rep
@@ -620,6 +663,38 @@ def obj2sctype(rep, default=None):
def issubclass_(arg1, arg2):
+ """
+ Determine if a class is a subclass of a second class.
+
+ `issubclass_` is equivalent to the Python built-in ``issubclass``,
+ except that it returns False instead of raising a TypeError is one
+ of the arguments is not a class.
+
+ Parameters
+ ----------
+ arg1 : class
+ Input class. True is returned if `arg1` is a subclass of `arg2`.
+ arg2 : class or tuple of classes.
+ Input class. If a tuple of classes, True is returned if `arg1` is a
+ subclass of any of the tuple elements.
+
+ Returns
+ -------
+ out : bool
+ Whether `arg1` is a subclass of `arg2` or not.
+
+ See Also
+ --------
+ issubsctype, issubdtype, issctype
+
+ Examples
+ --------
+ >>> np.issubclass_(np.int32, np.int)
+ True
+ >>> np.issubclass_(np.int32, np.float)
+ False
+
+ """
try:
return issubclass(arg1, arg2)
except TypeError:
@@ -853,7 +928,7 @@ typeNA = sctypeNA
# O -> Python object
_kind_list = ['b', 'u', 'i', 'f', 'c', 'S', 'U', 'V', 'O', 'M', 'm']
-__test_types = typecodes['AllInteger'][:-2]+typecodes['AllFloat']+'O'
+__test_types = '?'+typecodes['AllInteger'][:-2]+typecodes['AllFloat']+'O'
__len_test_types = len(__test_types)
# Keep incrementing until a common type both can be coerced to
diff --git a/numpy/core/setup.py b/numpy/core/setup.py
index c6ba3880a..b03150309 100644
--- a/numpy/core/setup.py
+++ b/numpy/core/setup.py
@@ -600,7 +600,10 @@ def configuration(parent_package='',top_path=None):
subpath = join('src', 'multiarray')
sources = [join(local_dir, subpath, 'scalartypes.c.src'),
- join(local_dir, subpath, 'arraytypes.c.src')]
+ join(local_dir, subpath, 'arraytypes.c.src'),
+ join(local_dir, subpath, 'new_iterator.c.src'),
+ join(local_dir, subpath, 'lowlevel_strided_loops.c.src'),
+ join(local_dir, subpath, 'einsum.c.src')]
# numpy.distutils generate .c from .c.src in weird directories, we have
# to add them there as they depend on the build_dir
@@ -735,7 +738,8 @@ def configuration(parent_package='',top_path=None):
join('src', 'multiarray', 'sequence.h'),
join('src', 'multiarray', 'shape.h'),
join('src', 'multiarray', 'ucsnarrow.h'),
- join('src', 'multiarray', 'usertypes.h')]
+ join('src', 'multiarray', 'usertypes.h'),
+ join('src', 'private', 'lowlevel_strided_loops.h')]
multiarray_src = [join('src', 'multiarray', 'multiarraymodule.c'),
join('src', 'multiarray', 'hashdescr.c'),
@@ -764,7 +768,12 @@ def configuration(parent_package='',top_path=None):
join('src', 'multiarray', 'scalarapi.c'),
join('src', 'multiarray', 'refcount.c'),
join('src', 'multiarray', 'arraytypes.c.src'),
- join('src', 'multiarray', 'scalartypes.c.src')]
+ join('src', 'multiarray', 'scalartypes.c.src'),
+ join('src', 'multiarray', 'new_iterator.c.src'),
+ join('src', 'multiarray', 'lowlevel_strided_loops.c.src'),
+ join('src', 'multiarray', 'dtype_transfer.c'),
+ join('src', 'multiarray', 'new_iterator_pywrap.c'),
+ join('src', 'multiarray', 'einsum.c.src')]
if PYTHON_HAS_UNICODE_WIDE:
multiarray_src.append(join('src', 'multiarray', 'ucsnarrow.c'))
diff --git a/numpy/core/setup_common.py b/numpy/core/setup_common.py
index 2423ab0ef..e88be40b0 100644
--- a/numpy/core/setup_common.py
+++ b/numpy/core/setup_common.py
@@ -21,7 +21,7 @@ from distutils.ccompiler import CompileError
# Binary compatibility version number. This number is increased whenever the
# C-API is changed such that binary compatibility is broken, i.e. whenever a
# recompile of extension modules is needed.
-C_ABI_VERSION = 0x02000000
+C_ABI_VERSION = 0x01000009
# Minor API version. This number is increased whenever a change is made to the
# C-API -- whether it breaks binary compatibility or not. Some changes, such
@@ -29,7 +29,7 @@ C_ABI_VERSION = 0x02000000
# without breaking binary compatibility. In this case, only the C_API_VERSION
# (*not* C_ABI_VERSION) would be increased. Whenever binary compatibility is
# broken, both C_API_VERSION and C_ABI_VERSION should be increased.
-C_API_VERSION = 0x00000005
+C_API_VERSION = 0x00000006
class MismatchCAPIWarning(Warning):
pass
diff --git a/numpy/core/shape_base.py b/numpy/core/shape_base.py
index 4c84cf397..15f188792 100644
--- a/numpy/core/shape_base.py
+++ b/numpy/core/shape_base.py
@@ -102,18 +102,18 @@ def atleast_3d(*arys):
Parameters
----------
array1, array2, ... : array_like
- One or more array-like sequences. Non-array inputs are converted
- to arrays. Arrays that already have three or more dimensions are
+ One or more array-like sequences. Non-array inputs are converted to
+ arrays. Arrays that already have three or more dimensions are
preserved.
Returns
-------
res1, res2, ... : ndarray
- An array, or tuple of arrays, each with ``a.ndim >= 3``.
- Copies are avoided where possible, and views with three or more
- dimensions are returned. For example, a 1-D array of shape ``N``
- becomes a view of shape ``(1, N, 1)``. A 2-D array of shape ``(M, N)``
- becomes a view of shape ``(M, N, 1)``.
+ An array, or tuple of arrays, each with ``a.ndim >= 3``. Copies are
+ avoided where possible, and views with three or more dimensions are
+ returned. For example, a 1-D array of shape ``(N,)`` becomes a view
+ of shape ``(1, N, 1)``, and a 2-D array of shape ``(M, N)`` becomes a
+ view of shape ``(M, N, 1)``.
See Also
--------
diff --git a/numpy/core/src/multiarray/arrayobject.c b/numpy/core/src/multiarray/arrayobject.c
index 03760d3fa..a3008c888 100644
--- a/numpy/core/src/multiarray/arrayobject.c
+++ b/numpy/core/src/multiarray/arrayobject.c
@@ -53,7 +53,7 @@ maintainer email: oliphant.travis@ieee.org
/*NUMPY_API
Compute the size of an array (in number of items)
*/
-NPY_NO_EXPORT intp
+NPY_NO_EXPORT npy_intp
PyArray_Size(PyObject *op)
{
if (PyArray_Check(op)) {
@@ -68,17 +68,20 @@ PyArray_Size(PyObject *op)
NPY_NO_EXPORT int
PyArray_CopyObject(PyArrayObject *dest, PyObject *src_object)
{
- PyArrayObject *src;
- PyObject *r;
int ret;
+ PyArrayObject *src;
+ PyArray_Descr *dtype = NULL;
+ int ndim = 0;
+ npy_intp dims[NPY_MAXDIMS];
+ Py_INCREF(src_object);
/*
* Special code to mimic Numeric behavior for
* character arrays.
*/
if (dest->descr->type == PyArray_CHARLTR && dest->nd > 0 \
&& PyString_Check(src_object)) {
- intp n_new, n_old;
+ npy_intp n_new, n_old;
char *new_string;
PyObject *tmp;
@@ -90,33 +93,87 @@ PyArray_CopyObject(PyArrayObject *dest, PyObject *src_object)
memset(new_string + n_old, ' ', n_new - n_old);
tmp = PyString_FromStringAndSize(new_string, n_new);
free(new_string);
+ Py_DECREF(src_object);
src_object = tmp;
}
}
- if (PyArray_Check(src_object)) {
- src = (PyArrayObject *)src_object;
- Py_INCREF(src);
- }
- else if (!PyArray_IsScalar(src_object, Generic) &&
- PyArray_HasArrayInterface(src_object, r)) {
- src = (PyArrayObject *)r;
- }
- else {
- PyArray_Descr* dtype;
- dtype = dest->descr;
- Py_INCREF(dtype);
- src = (PyArrayObject *)PyArray_FromAny(src_object, dtype, 0,
- dest->nd,
- FORTRAN_IF(dest),
- NULL);
+ /*
+ * Get either an array object we can copy from, or its parameters
+ * if there isn't a convenient array available.
+ */
+ if (PyArray_GetArrayParamsFromObject(src_object, PyArray_DESCR(dest),
+ 0, &dtype, &ndim, dims, &src, NULL) < 0) {
+ Py_DECREF(src_object);
+ return -1;
}
+
+ /* If it's not an array, either assign from a sequence or as a scalar */
if (src == NULL) {
- return -1;
+ /* If the input is scalar */
+ if (ndim == 0) {
+ /* If there's one dest element and src is a Python scalar */
+ if (PyArray_IsScalar(src_object, Generic)) {
+ src = (PyArrayObject *)PyArray_FromScalar(src_object, dtype);
+ if (src == NULL) {
+ Py_DECREF(src_object);
+ return -1;
+ }
+ }
+ else {
+ if (PyArray_SIZE(dest) == 1) {
+ Py_DECREF(dtype);
+ return PyArray_DESCR(dest)->f->setitem(src_object,
+ PyArray_DATA(dest), dest);
+ }
+ else {
+ src = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type,
+ dtype, 0, NULL, NULL,
+ NULL, 0, NULL);
+ if (src == NULL) {
+ Py_DECREF(src_object);
+ return -1;
+ }
+ if (PyArray_DESCR(src)->f->setitem(src_object,
+ PyArray_DATA(src), src) < 0) {
+ Py_DECREF(src_object);
+ Py_DECREF(src);
+ return -1;
+ }
+ }
+ }
+ }
+ else {
+ /* If the dims match exactly, can assign directly */
+ if (ndim == PyArray_NDIM(dest) &&
+ PyArray_CompareLists(dims, PyArray_DIMS(dest),
+ ndim)) {
+ int res;
+ Py_DECREF(dtype);
+ res = PyArray_AssignFromSequence(dest, src_object);
+ Py_DECREF(src_object);
+ return res;
+ }
+ /* Otherwise convert to an array and do an array-based copy */
+ src = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type,
+ dtype, ndim, dims, NULL, NULL,
+ PyArray_ISFORTRAN(dest), NULL);
+ if (src == NULL) {
+ Py_DECREF(src_object);
+ return -1;
+ }
+ if (PyArray_AssignFromSequence(src, src_object) < 0) {
+ Py_DECREF(src);
+ Py_DECREF(src_object);
+ return -1;
+ }
+ }
}
+ /* If it's an array, do a move (handling possible overlapping data) */
ret = PyArray_MoveInto(dest, src);
Py_DECREF(src);
+ Py_DECREF(src_object);
return ret;
}
@@ -216,12 +273,12 @@ array_dealloc(PyArrayObject *self) {
static int
dump_data(char **string, int *n, int *max_n, char *data, int nd,
- intp *dimensions, intp *strides, PyArrayObject* self)
+ npy_intp *dimensions, npy_intp *strides, PyArrayObject* self)
{
PyArray_Descr *descr=self->descr;
PyObject *op, *sp;
char *ostring;
- intp i, N;
+ npy_intp i, N;
#define CHECK_MEMORY do { if (*n >= *max_n-16) { \
*max_n *= 2; \
@@ -444,15 +501,15 @@ _myunincmp(PyArray_UCS4 *s1, PyArray_UCS4 *s2, int len1, int len2)
PyArray_UCS4 *sptr;
PyArray_UCS4 *s1t=s1, *s2t=s2;
int val;
- intp size;
+ npy_intp size;
int diff;
- if ((intp)s1 % sizeof(PyArray_UCS4) != 0) {
+ if ((npy_intp)s1 % sizeof(PyArray_UCS4) != 0) {
size = len1*sizeof(PyArray_UCS4);
s1t = malloc(size);
memcpy(s1t, s1, size);
}
- if ((intp)s2 % sizeof(PyArray_UCS4) != 0) {
+ if ((npy_intp)s2 % sizeof(PyArray_UCS4) != 0) {
size = len2*sizeof(PyArray_UCS4);
s2t = malloc(size);
memcpy(s2t, s2, size);
@@ -627,7 +684,7 @@ _uni_release(char *ptr, int nc)
relfunc(aptr, N1); \
return -1; \
} \
- val = cmpfunc(aptr, bptr, N1, N2); \
+ val = compfunc(aptr, bptr, N1, N2); \
*dptr = (val CMP 0); \
PyArray_ITER_NEXT(iself); \
PyArray_ITER_NEXT(iother); \
@@ -639,7 +696,7 @@ _uni_release(char *ptr, int nc)
#define _reg_loop(CMP) { \
while(size--) { \
- val = cmpfunc((void *)iself->dataptr, \
+ val = compfunc((void *)iself->dataptr, \
(void *)iother->dataptr, \
N1, N2); \
*dptr = (val CMP 0); \
@@ -658,21 +715,21 @@ _compare_strings(PyObject *result, PyArrayMultiIterObject *multi,
{
PyArrayIterObject *iself, *iother;
Bool *dptr;
- intp size;
+ npy_intp size;
int val;
int N1, N2;
- int (*cmpfunc)(void *, void *, int, int);
+ int (*compfunc)(void *, void *, int, int);
void (*relfunc)(char *, int);
char* (*stripfunc)(char *, char *, int);
- cmpfunc = func;
+ compfunc = func;
dptr = (Bool *)PyArray_DATA(result);
iself = multi->iters[0];
iother = multi->iters[1];
size = multi->size;
N1 = iself->ao->descr->elsize;
N2 = iother->ao->descr->elsize;
- if ((void *)cmpfunc == (void *)_myunincmp) {
+ if ((void *)compfunc == (void *)_myunincmp) {
N1 >>= 2;
N2 >>= 2;
stripfunc = _uni_copy_n_strip;
@@ -827,7 +884,7 @@ _void_compare(PyArrayObject *self, PyArrayObject *other, int cmp_op)
PyObject *key, *value, *temp2;
PyObject *op;
Py_ssize_t pos = 0;
- intp result_ndim = PyArray_NDIM(self) > PyArray_NDIM(other) ?
+ npy_intp result_ndim = PyArray_NDIM(self) > PyArray_NDIM(other) ?
PyArray_NDIM(self) : PyArray_NDIM(other);
op = (cmp_op == Py_EQ ? n_ops.logical_and : n_ops.logical_or);
@@ -863,7 +920,7 @@ _void_compare(PyArrayObject *self, PyArrayObject *other, int cmp_op)
/* If the type was multidimensional, collapse that part to 1-D
*/
if (PyArray_NDIM(temp) != result_ndim+1) {
- intp dimensions[NPY_MAXDIMS];
+ npy_intp dimensions[NPY_MAXDIMS];
PyArray_Dims newdims;
newdims.ptr = dimensions;
@@ -871,7 +928,8 @@ _void_compare(PyArrayObject *self, PyArrayObject *other, int cmp_op)
memcpy(dimensions, PyArray_DIMS(temp),
sizeof(intp)*result_ndim);
dimensions[result_ndim] = -1;
- temp2 = PyArray_Newshape(temp, &newdims, PyArray_ANYORDER);
+ temp2 = PyArray_Newshape((PyArrayObject *)temp,
+ &newdims, PyArray_ANYORDER);
if (temp2 == NULL) {
Py_DECREF(temp);
Py_XDECREF(res);
@@ -881,7 +939,8 @@ _void_compare(PyArrayObject *self, PyArrayObject *other, int cmp_op)
temp = temp2;
}
/* Reduce the extra dimension of `temp` using `op` */
- temp2 = PyArray_GenericReduceFunction(temp, op, result_ndim,
+ temp2 = PyArray_GenericReduceFunction((PyArrayObject *)temp,
+ op, result_ndim,
PyArray_BOOL, NULL);
if (temp2 == NULL) {
Py_DECREF(temp);
@@ -1099,7 +1158,7 @@ PyArray_ElementStrides(PyObject *arr)
{
int itemsize = PyArray_ITEMSIZE(arr);
int i, N = PyArray_NDIM(arr);
- intp *strides = PyArray_STRIDES(arr);
+ npy_intp *strides = PyArray_STRIDES(arr);
for (i = 0; i < N; i++) {
if ((strides[i] % itemsize) != 0) {
@@ -1128,13 +1187,13 @@ PyArray_ElementStrides(PyObject *arr)
/*NUMPY_API*/
NPY_NO_EXPORT Bool
-PyArray_CheckStrides(int elsize, int nd, intp numbytes, intp offset,
- intp *dims, intp *newstrides)
+PyArray_CheckStrides(int elsize, int nd, npy_intp numbytes, npy_intp offset,
+ npy_intp *dims, npy_intp *newstrides)
{
int i;
- intp byte_begin;
- intp begin;
- intp end;
+ npy_intp byte_begin;
+ npy_intp begin;
+ npy_intp end;
if (numbytes == 0) {
numbytes = PyArray_MultiplyList(dims, nd) * elsize;
@@ -1201,7 +1260,7 @@ array_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
}
if (strides.ptr != NULL) {
- intp nb, off;
+ npy_intp nb, off;
if (strides.len != dims.len) {
PyErr_SetString(PyExc_ValueError,
"strides, if given, must be " \
@@ -1215,7 +1274,7 @@ array_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
}
else {
nb = buffer.len;
- off = (intp) offset;
+ off = (npy_intp) offset;
}
@@ -1252,10 +1311,10 @@ array_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
else {
/* buffer given -- use it */
if (dims.len == 1 && dims.ptr[0] == -1) {
- dims.ptr[0] = (buffer.len-(intp)offset) / itemsize;
+ dims.ptr[0] = (buffer.len-(npy_intp)offset) / itemsize;
}
else if ((strides.ptr == NULL) &&
- (buffer.len < (offset + (((intp)itemsize)*
+ (buffer.len < (offset + (((npy_intp)itemsize)*
PyArray_MultiplyList(dims.ptr,
dims.len))))) {
PyErr_SetString(PyExc_TypeError,
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src
index c9d517c50..3f2a9ac71 100644
--- a/numpy/core/src/multiarray/arraytypes.c.src
+++ b/numpy/core/src/multiarray/arraytypes.c.src
@@ -149,7 +149,8 @@ static int
temp = (@type@)@func2@(op);
}
if (PyErr_Occurred()) {
- if (PySequence_Check(op)) {
+ if (PySequence_Check(op) && !PyString_Check(op) &&
+ !PyUnicode_Check(op)) {
PyErr_Clear();
PyErr_SetString(PyExc_ValueError,
"setting an array element with a sequence.");
@@ -438,16 +439,25 @@ STRING_setitem(PyObject *op, char *ov, PyArrayObject *ap)
Py_ssize_t len;
PyObject *temp = NULL;
+ /* Handle case of assigning from an array scalar */
+ if (PyArray_Check(op) && PyArray_NDIM(op) == 0) {
+ temp = PyArray_ToScalar(PyArray_DATA(op), op);
+ if (temp == NULL) {
+ return -1;
+ }
+ else {
+ int res = STRING_setitem(temp, ov, ap);
+ Py_DECREF(temp);
+ return res;
+ }
+ }
+
if (!PyBytes_Check(op) && !PyUnicode_Check(op)
- && PySequence_Check(op) && PySequence_Size(op) > 0) {
+ && PySequence_Check(op) && PySequence_Size(op) != 0) {
PyErr_SetString(PyExc_ValueError,
- "setting an array element with a sequence");
+ "cannot set an array element with a sequence");
return -1;
}
- /* Sequence_Size might have returned an error */
- if (PyErr_Occurred()) {
- PyErr_Clear();
- }
#if defined(NPY_PY3K)
if (PyUnicode_Check(op)) {
/* Assume ASCII codec -- function similarly as Python 2 */
@@ -501,28 +511,15 @@ STRING_setitem(PyObject *op, char *ov, PyArrayObject *ap)
static PyObject *
OBJECT_getitem(char *ip, PyArrayObject *ap)
{
- /* TODO: We might be able to get away with just the "else" clause now */
- if (!ap || PyArray_ISALIGNED(ap)) {
- if (*(PyObject **)ip == NULL) {
- Py_INCREF(Py_None);
- return Py_None;
- }
- else {
- Py_INCREF(*(PyObject **)ip);
- return *(PyObject **)ip;
- }
+ PyObject *obj;
+ NPY_COPY_PYOBJECT_PTR(&obj, ip);
+ if (obj == NULL) {
+ Py_INCREF(Py_None);
+ return Py_None;
}
else {
- PyObject *obj;
- NPY_COPY_PYOBJECT_PTR(&obj, ip);
- if (obj == NULL) {
- Py_INCREF(Py_None);
- return Py_None;
- }
- else {
- Py_INCREF(obj);
- return obj;
- }
+ Py_INCREF(obj);
+ return obj;
}
}
@@ -530,18 +527,14 @@ OBJECT_getitem(char *ip, PyArrayObject *ap)
static int
OBJECT_setitem(PyObject *op, char *ov, PyArrayObject *ap)
{
+ PyObject *obj;
+
+ NPY_COPY_PYOBJECT_PTR(&obj, ov);
+ Py_XDECREF(obj);
+
Py_INCREF(op);
- /* TODO: We might be able to get away with just the "else" clause now */
- if (!ap || PyArray_ISALIGNED(ap)) {
- Py_XDECREF(*(PyObject **)ov);
- *(PyObject **)ov = op;
- }
- else {
- PyObject *obj;
- NPY_COPY_PYOBJECT_PTR(&obj, ov);
- Py_XDECREF(obj);
- NPY_COPY_PYOBJECT_PTR(ov, &op);
- }
+ NPY_COPY_PYOBJECT_PTR(ov, &op);
+
return PyErr_Occurred() ? -1 : 0;
}
@@ -555,7 +548,7 @@ VOID_getitem(char *ip, PyArrayObject *ap)
int itemsize;
descr = ap->descr;
- if (descr->names) {
+ if (descr->names != NULL) {
PyObject *key;
PyObject *names;
int i, n;
@@ -567,9 +560,6 @@ VOID_getitem(char *ip, PyArrayObject *ap)
/* get the names from the fields dictionary*/
names = descr->names;
- if (!names) {
- goto finish;
- }
n = PyTuple_GET_SIZE(names);
ret = PyTuple_New(n);
savedflags = ap->flags;
@@ -611,7 +601,7 @@ VOID_getitem(char *ip, PyArrayObject *ap)
Py_INCREF(descr->subarray->base);
ret = PyArray_NewFromDescr(&PyArray_Type,
descr->subarray->base, shape.len, shape.ptr,
- NULL, ip, ap->flags, NULL);
+ NULL, ip, ap->flags&(~NPY_F_CONTIGUOUS), NULL);
PyDimMem_FREE(shape.ptr);
if (!ret) {
return NULL;
@@ -1152,7 +1142,7 @@ DATETIME_setitem(PyObject *op, char *ov, PyArrayObject *ap) {
else if (PyUString_Check(op) || PyUnicode_Check(op)) {
#endif
/* FIXME: Converts to DateTime first and therefore does not handle extended notation */
- /* import _mx_datetime_parser
+ /* import _mx_datetime_parser
* res = _mx_datetime_parser(name)
* Convert from datetime to Int
*/
@@ -1532,6 +1522,7 @@ static void
#define _NPY_UNUSEDULONG NPY_UNUSED
#define _NPY_UNUSEDLONGLONG NPY_UNUSED
#define _NPY_UNUSEDULONGLONG NPY_UNUSED
+#define _NPY_UNUSEDHALF NPY_UNUSED
#define _NPY_UNUSEDFLOAT NPY_UNUSED
#define _NPY_UNUSEDDOUBLE NPY_UNUSED
#define _NPY_UNUSEDLONGDOUBLE NPY_UNUSED
@@ -1540,6 +1531,7 @@ static void
#define _NPY_UNUSEDCLONGDOUBLE NPY_UNUSED
#define _NPY_UNUSEDDATETIME NPY_UNUSED
#define _NPY_UNUSEDTIMEDELTA NPY_UNUSED
+#define _NPY_UNUSEDHALF NPY_UNUSED
#define _NPY_UNUSEDSTRING
#define _NPY_UNUSEDVOID
#define _NPY_UNUSEDUNICODE
@@ -1601,6 +1593,7 @@ static void
}
/* convert from Python object to needed one */
#if @convert@
+ {
PyObject *new, *args;
/* call out to the Python builtin given by convstr */
args = Py_BuildValue("(N)", temp);
@@ -1616,6 +1609,7 @@ static void
if (temp == NULL) {
return;
}
+ }
#endif /* @convert@ */
if (@to@_setitem(temp,(char *)op, aop)) {
Py_DECREF(temp);
@@ -1735,12 +1729,12 @@ static int
static int
BOOL_scan(FILE *fp, Bool *ip, void *NPY_UNUSED(ignore), PyArray_Descr *NPY_UNUSED(ignore2))
{
- int temp;
- int num;
+ double result;
+ int ret;
- num = fscanf(fp, "%d", &temp);
- *ip = (Bool) (temp != 0);
- return num;
+ ret = NumPyOS_ascii_ftolf(fp, &result);
+ *ip = (Bool) (result != 0.0);
+ return ret;
}
/**begin repeat
@@ -3622,6 +3616,29 @@ static int
* #endian = |, |, =#
*/
static PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {
+ {
+ (PyArray_VectorUnaryFunc*)@from@_to_BOOL,
+ (PyArray_VectorUnaryFunc*)@from@_to_BYTE,
+ (PyArray_VectorUnaryFunc*)@from@_to_UBYTE,
+ (PyArray_VectorUnaryFunc*)@from@_to_SHORT,
+ (PyArray_VectorUnaryFunc*)@from@_to_USHORT,
+ (PyArray_VectorUnaryFunc*)@from@_to_INT,
+ (PyArray_VectorUnaryFunc*)@from@_to_UINT,
+ (PyArray_VectorUnaryFunc*)@from@_to_LONG,
+ (PyArray_VectorUnaryFunc*)@from@_to_ULONG,
+ (PyArray_VectorUnaryFunc*)@from@_to_LONGLONG,
+ (PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG,
+ (PyArray_VectorUnaryFunc*)@from@_to_FLOAT,
+ (PyArray_VectorUnaryFunc*)@from@_to_DOUBLE,
+ (PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE,
+ (PyArray_VectorUnaryFunc*)@from@_to_CFLOAT,
+ (PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE,
+ (PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE,
+ (PyArray_VectorUnaryFunc*)@from@_to_OBJECT,
+ (PyArray_VectorUnaryFunc*)@from@_to_STRING,
+ (PyArray_VectorUnaryFunc*)@from@_to_UNICODE,
+ (PyArray_VectorUnaryFunc*)@from@_to_VOID
+ },
(PyArray_GetItemFunc*)@from@_getitem,
(PyArray_SetItemFunc*)@from@_setitem,
(PyArray_CopySwapNFunc*)@from@_copyswapn,
@@ -3646,34 +3663,7 @@ static PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {
NULL,
(PyArray_FastClipFunc *)NULL,
(PyArray_FastPutmaskFunc *)NULL,
- (PyArray_FastTakeFunc *)NULL,
- NULL, NULL, NULL, NULL,
- {
- (PyArray_VectorUnaryFunc*)@from@_to_BOOL,
- (PyArray_VectorUnaryFunc*)@from@_to_BYTE,
- (PyArray_VectorUnaryFunc*)@from@_to_UBYTE,
- (PyArray_VectorUnaryFunc*)@from@_to_SHORT,
- (PyArray_VectorUnaryFunc*)@from@_to_USHORT,
- (PyArray_VectorUnaryFunc*)@from@_to_INT,
- (PyArray_VectorUnaryFunc*)@from@_to_UINT,
- (PyArray_VectorUnaryFunc*)@from@_to_LONG,
- (PyArray_VectorUnaryFunc*)@from@_to_ULONG,
- (PyArray_VectorUnaryFunc*)@from@_to_LONGLONG,
- (PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG,
- (PyArray_VectorUnaryFunc*)@from@_to_HALF,
- (PyArray_VectorUnaryFunc*)@from@_to_FLOAT,
- (PyArray_VectorUnaryFunc*)@from@_to_DOUBLE,
- (PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE,
- (PyArray_VectorUnaryFunc*)@from@_to_CFLOAT,
- (PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE,
- (PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE,
- (PyArray_VectorUnaryFunc*)@from@_to_DATETIME,
- (PyArray_VectorUnaryFunc*)@from@_to_TIMEDELTA,
- (PyArray_VectorUnaryFunc*)@from@_to_OBJECT,
- (PyArray_VectorUnaryFunc*)@from@_to_STRING,
- (PyArray_VectorUnaryFunc*)@from@_to_UNICODE,
- (PyArray_VectorUnaryFunc*)@from@_to_VOID
- }
+ (PyArray_FastTakeFunc *)NULL
};
/*
@@ -3686,7 +3676,6 @@ static PyArray_Descr @from@_Descr = {
PyArray_@from@LTR,
'@endian@',
0,
- 0,
PyArray_@from@,
0,
_ALIGN(@align@),
@@ -3718,6 +3707,29 @@ static PyArray_Descr @from@_Descr = {
* #isobject= 0*18,NPY_OBJECT_DTYPE_FLAGS,0*2#
*/
static PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {
+ {
+ (PyArray_VectorUnaryFunc*)@from@_to_BOOL,
+ (PyArray_VectorUnaryFunc*)@from@_to_BYTE,
+ (PyArray_VectorUnaryFunc*)@from@_to_UBYTE,
+ (PyArray_VectorUnaryFunc*)@from@_to_SHORT,
+ (PyArray_VectorUnaryFunc*)@from@_to_USHORT,
+ (PyArray_VectorUnaryFunc*)@from@_to_INT,
+ (PyArray_VectorUnaryFunc*)@from@_to_UINT,
+ (PyArray_VectorUnaryFunc*)@from@_to_LONG,
+ (PyArray_VectorUnaryFunc*)@from@_to_ULONG,
+ (PyArray_VectorUnaryFunc*)@from@_to_LONGLONG,
+ (PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG,
+ (PyArray_VectorUnaryFunc*)@from@_to_FLOAT,
+ (PyArray_VectorUnaryFunc*)@from@_to_DOUBLE,
+ (PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE,
+ (PyArray_VectorUnaryFunc*)@from@_to_CFLOAT,
+ (PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE,
+ (PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE,
+ (PyArray_VectorUnaryFunc*)@from@_to_OBJECT,
+ (PyArray_VectorUnaryFunc*)@from@_to_STRING,
+ (PyArray_VectorUnaryFunc*)@from@_to_UNICODE,
+ (PyArray_VectorUnaryFunc*)@from@_to_VOID
+ },
(PyArray_GetItemFunc*)@from@_getitem,
(PyArray_SetItemFunc*)@from@_setitem,
(PyArray_CopySwapNFunc*)@from@_copyswapn,
@@ -3742,34 +3754,7 @@ static PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {
NULL,
(PyArray_FastClipFunc*)@from@_fastclip,
(PyArray_FastPutmaskFunc*)@from@_fastputmask,
- (PyArray_FastTakeFunc*)@from@_fasttake,
- NULL, NULL, NULL, NULL,
- {
- (PyArray_VectorUnaryFunc*)@from@_to_BOOL,
- (PyArray_VectorUnaryFunc*)@from@_to_BYTE,
- (PyArray_VectorUnaryFunc*)@from@_to_UBYTE,
- (PyArray_VectorUnaryFunc*)@from@_to_SHORT,
- (PyArray_VectorUnaryFunc*)@from@_to_USHORT,
- (PyArray_VectorUnaryFunc*)@from@_to_INT,
- (PyArray_VectorUnaryFunc*)@from@_to_UINT,
- (PyArray_VectorUnaryFunc*)@from@_to_LONG,
- (PyArray_VectorUnaryFunc*)@from@_to_ULONG,
- (PyArray_VectorUnaryFunc*)@from@_to_LONGLONG,
- (PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG,
- (PyArray_VectorUnaryFunc*)@from@_to_HALF,
- (PyArray_VectorUnaryFunc*)@from@_to_FLOAT,
- (PyArray_VectorUnaryFunc*)@from@_to_DOUBLE,
- (PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE,
- (PyArray_VectorUnaryFunc*)@from@_to_CFLOAT,
- (PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE,
- (PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE,
- (PyArray_VectorUnaryFunc*)@from@_to_DATETIME,
- (PyArray_VectorUnaryFunc*)@from@_to_TIMEDELTA,
- (PyArray_VectorUnaryFunc*)@from@_to_OBJECT,
- (PyArray_VectorUnaryFunc*)@from@_to_STRING,
- (PyArray_VectorUnaryFunc*)@from@_to_UNICODE,
- (PyArray_VectorUnaryFunc*)@from@_to_VOID
- }
+ (PyArray_FastTakeFunc*)@from@_fasttake
};
/*
@@ -3781,7 +3766,6 @@ NPY_NO_EXPORT PyArray_Descr @from@_Descr = {
PyArray_@kind@LTR,
PyArray_@from@LTR,
'@endian@',
- 0,
@isobject@,
PyArray_@from@,
@num@*sizeof(@fromtyp@),
@@ -3833,19 +3817,19 @@ static PyArray_Descr *_builtin_descrs[] = {
&ULONG_Descr,
&LONGLONG_Descr,
&ULONGLONG_Descr,
- &HALF_Descr,
&FLOAT_Descr,
&DOUBLE_Descr,
&LONGDOUBLE_Descr,
&CFLOAT_Descr,
&CDOUBLE_Descr,
&CLONGDOUBLE_Descr,
- &DATETIME_Descr,
- &TIMEDELTA_Descr,
&OBJECT_Descr,
&STRING_Descr,
&UNICODE_Descr,
&VOID_Descr,
+ &DATETIME_Descr,
+ &TIMEDELTA_Descr,
+ &HALF_Descr
};
/*NUMPY_API
@@ -3923,8 +3907,49 @@ set_typeinfo(PyObject *dict)
PyObject *infodict, *s;
int i;
+ PyArray_Descr *dtype;
+ PyObject *cobj, *key;
+
+ /* Add cast functions for the new types */
+/**begin repeat
+ *
+ * #name1 = BOOL, BYTE, UBYTE, SHORT, USHORT, INT, UINT,
+ * LONG, ULONG, LONGLONG, ULONGLONG, HALF, FLOAT, DOUBLE, LONGDOUBLE,
+ * CFLOAT, CDOUBLE, CLONGDOUBLE, OBJECT, STRING, UNICODE, VOID,
+ * DATETIME,TIMEDELTA#
+ */
+/**begin repeat1
+ *
+ * #name2 = HALF, DATETIME, TIMEDELTA#
+ */
+ dtype = _builtin_descrs[NPY_@name1@];
+ if (dtype->f->castdict == NULL) {
+ dtype->f->castdict = PyDict_New();
+ if (dtype->f->castdict == NULL) {
+ return -1;
+ }
+ }
+ key = PyInt_FromLong(NPY_@name2@);
+ if (key == NULL) {
+ return -1;
+ }
+ cobj = NpyCapsule_FromVoidPtr((void *)@name1@_to_@name2@, NULL);
+ if (cobj == NULL) {
+ Py_DECREF(key);
+ return -1;
+ }
+ if (PyDict_SetItem(dtype->f->castdict, key, cobj) < 0) {
+ Py_DECREF(key);
+ Py_DECREF(cobj);
+ return -1;
+ }
+ Py_DECREF(key);
+ Py_DECREF(cobj);
+/**end repeat1**/
+/**end repeat**/
+
for (i = 0; i < _MAX_LETTER; i++) {
- _letter_to_num[i] = PyArray_NTYPES;
+ _letter_to_num[i] = NPY_NTYPES;
}
/**begin repeat
diff --git a/numpy/core/src/multiarray/buffer.c b/numpy/core/src/multiarray/buffer.c
index 08e2687a0..16164011f 100644
--- a/numpy/core/src/multiarray/buffer.c
+++ b/numpy/core/src/multiarray/buffer.c
@@ -768,7 +768,7 @@ _descriptor_from_pep3118_format(char *s)
Py_DECREF(str);
return NULL;
}
- descr = (PyArray_Descr*)PyObject_CallMethod(
+ descr = PyObject_CallMethod(
_numpy_internal, "_dtype_from_pep3118", "O", str);
Py_DECREF(str);
Py_DECREF(_numpy_internal);
diff --git a/numpy/core/src/multiarray/calculation.c b/numpy/core/src/multiarray/calculation.c
index bc078f097..8f32ce21c 100644
--- a/numpy/core/src/multiarray/calculation.c
+++ b/numpy/core/src/multiarray/calculation.c
@@ -825,7 +825,7 @@ PyArray_Clip(PyArrayObject *self, PyObject *min, PyObject *max, PyArrayObject *o
*/
if (PyArray_ScalarKind(newdescr->type_num, NULL) >
PyArray_ScalarKind(self->descr->type_num, NULL)) {
- indescr = _array_small_type(newdescr, self->descr);
+ indescr = PyArray_PromoteTypes(newdescr, self->descr);
func = indescr->f->fastclip;
if (func == NULL) {
return _slow_array_clip(self, min, max, out);
@@ -1082,4 +1082,3 @@ PyArray_Trace(PyArrayObject *self, int offset, int axis1, int axis2,
Py_DECREF(diag);
return ret;
}
-
diff --git a/numpy/core/src/multiarray/common.c b/numpy/core/src/multiarray/common.c
index 33d7f719c..28846462d 100644
--- a/numpy/core/src/multiarray/common.c
+++ b/numpy/core/src/multiarray/common.c
@@ -13,79 +13,6 @@
#include "common.h"
#include "buffer.h"
-/*
- * new reference
- * doesn't alter refcount of chktype or mintype ---
- * unless one of them is returned
- */
-NPY_NO_EXPORT PyArray_Descr *
-_array_small_type(PyArray_Descr *chktype, PyArray_Descr* mintype)
-{
- PyArray_Descr *outtype;
- int outtype_num, save_num;
-
- if (PyArray_EquivTypes(chktype, mintype)) {
- Py_INCREF(mintype);
- return mintype;
- }
-
-
- if (chktype->type_num > mintype->type_num) {
- outtype_num = chktype->type_num;
- }
- else {
- if (PyDataType_ISOBJECT(chktype) &&
- PyDataType_ISSTRING(mintype)) {
- return PyArray_DescrFromType(NPY_OBJECT);
- }
- else {
- outtype_num = mintype->type_num;
- }
- }
-
- save_num = outtype_num;
- while (outtype_num < PyArray_NTYPES &&
- !(PyArray_CanCastSafely(chktype->type_num, outtype_num)
- && PyArray_CanCastSafely(mintype->type_num, outtype_num))) {
- outtype_num++;
- }
- if (outtype_num == PyArray_NTYPES) {
- outtype = PyArray_DescrFromType(save_num);
- }
- else {
- outtype = PyArray_DescrFromType(outtype_num);
- }
- if (PyTypeNum_ISEXTENDED(outtype->type_num)) {
- int testsize = outtype->elsize;
- int chksize, minsize;
- chksize = chktype->elsize;
- minsize = mintype->elsize;
- /*
- * Handle string->unicode case separately
- * because string itemsize is 4* as large
- */
- if (outtype->type_num == PyArray_UNICODE &&
- mintype->type_num == PyArray_STRING) {
- testsize = MAX(chksize, 4*minsize);
- }
- else if (chktype->type_num == PyArray_STRING &&
- mintype->type_num == PyArray_UNICODE) {
- testsize = MAX(chksize*4, minsize);
- }
- else {
- testsize = MAX(chksize, minsize);
- }
- if (testsize != outtype->elsize) {
- PyArray_DESCR_REPLACE(outtype);
- outtype->elsize = testsize;
- Py_XDECREF(outtype->fields);
- outtype->fields = NULL;
- Py_XDECREF(outtype->names);
- outtype->names = NULL;
- }
- }
- return outtype;
-}
NPY_NO_EXPORT PyArray_Descr *
_array_find_python_scalar_type(PyObject *op)
@@ -312,6 +239,9 @@ _array_find_type(PyObject *op, PyArray_Descr *minitype, int max)
if (l == 0 && minitype->type_num == PyArray_BOOL) {
Py_DECREF(minitype);
minitype = PyArray_DescrFromType(PyArray_DEFAULT);
+ if (minitype == NULL) {
+ return NULL;
+ }
}
while (--l >= 0) {
PyArray_Descr *newtype;
@@ -321,7 +251,11 @@ _array_find_type(PyObject *op, PyArray_Descr *minitype, int max)
goto deflt;
}
chktype = _array_find_type(ip, minitype, max-1);
- newtype = _array_small_type(chktype, minitype);
+ if (chktype == NULL) {
+ Py_DECREF(minitype);
+ return NULL;
+ }
+ newtype = PyArray_PromoteTypes(chktype, minitype);
Py_DECREF(minitype);
minitype = newtype;
Py_DECREF(chktype);
@@ -337,9 +271,12 @@ _array_find_type(PyObject *op, PyArray_Descr *minitype, int max)
chktype = _use_default_type(op);
finish:
- outtype = _array_small_type(chktype, minitype);
+ outtype = PyArray_PromoteTypes(chktype, minitype);
Py_DECREF(chktype);
Py_DECREF(minitype);
+ if (outtype == NULL) {
+ return NULL;
+ }
/*
* VOID Arrays should not occur by "default"
* unless input was already a VOID
diff --git a/numpy/core/src/multiarray/common.h b/numpy/core/src/multiarray/common.h
index 67ee9b66f..8242a0d18 100644
--- a/numpy/core/src/multiarray/common.h
+++ b/numpy/core/src/multiarray/common.h
@@ -7,9 +7,6 @@ NPY_NO_EXPORT PyArray_Descr *
_array_find_type(PyObject *op, PyArray_Descr *minitype, int max);
NPY_NO_EXPORT PyArray_Descr *
-_array_small_type(PyArray_Descr *chktype, PyArray_Descr* mintype);
-
-NPY_NO_EXPORT PyArray_Descr *
_array_find_python_scalar_type(PyObject *op);
NPY_NO_EXPORT PyArray_Descr *
diff --git a/numpy/core/src/multiarray/conversion_utils.c b/numpy/core/src/multiarray/conversion_utils.c
index 4ad2e9f51..e8ac99273 100644
--- a/numpy/core/src/multiarray/conversion_utils.c
+++ b/numpy/core/src/multiarray/conversion_utils.c
@@ -115,7 +115,7 @@ PyArray_IntpConverter(PyObject *obj, PyArray_Dims *seq)
}
}
seq->len = len;
- nd = PyArray_IntpFromSequence(obj, (intp *)seq->ptr, len);
+ nd = PyArray_IntpFromSequence(obj, (npy_intp *)seq->ptr, len);
if (nd == -1 || nd != len) {
PyDimMem_FREE(seq->ptr);
seq->ptr = NULL;
@@ -155,7 +155,7 @@ PyArray_BufferConverter(PyObject *obj, PyArray_Chunk *buf)
return PY_FAIL;
}
}
- buf->len = (intp) buflen;
+ buf->len = (npy_intp) buflen;
/* Point to the base of the buffer object if present */
#if defined(NPY_PY3K)
@@ -441,7 +441,7 @@ PyArray_PyIntAsInt(PyObject *o)
}
/*NUMPY_API*/
-NPY_NO_EXPORT intp
+NPY_NO_EXPORT npy_intp
PyArray_PyIntAsIntp(PyObject *o)
{
longlong long_value = -1;
@@ -449,7 +449,7 @@ PyArray_PyIntAsIntp(PyObject *o)
static char *msg = "an integer is required";
PyObject *arr;
PyArray_Descr *descr;
- intp ret;
+ npy_intp ret;
if (!o) {
PyErr_SetString(PyExc_TypeError, msg);
@@ -485,7 +485,7 @@ PyArray_PyIntAsIntp(PyObject *o)
arr = PyArray_FromScalar(o, descr);
}
if (arr != NULL) {
- ret = *((intp *)PyArray_DATA(arr));
+ ret = *((npy_intp *)PyArray_DATA(arr));
Py_DECREF(arr);
return ret;
}
@@ -536,7 +536,7 @@ PyArray_PyIntAsIntp(PyObject *o)
return -1;
}
#endif
- return (intp) long_value;
+ return (npy_intp) long_value;
}
/*NUMPY_API
@@ -545,7 +545,7 @@ PyArray_PyIntAsIntp(PyObject *o)
* vals must be large enough to hold maxvals
*/
NPY_NO_EXPORT int
-PyArray_IntpFromSequence(PyObject *seq, intp *vals, int maxvals)
+PyArray_IntpFromSequence(PyObject *seq, npy_intp *vals, int maxvals)
{
int nd, i;
PyObject *op, *err;
@@ -567,9 +567,9 @@ PyArray_IntpFromSequence(PyObject *seq, intp *vals, int maxvals)
#endif
nd = 1;
#if SIZEOF_LONG >= SIZEOF_INTP
- vals[0] = (intp ) PyInt_AsLong(op);
+ vals[0] = (npy_intp ) PyInt_AsLong(op);
#else
- vals[0] = (intp ) PyLong_AsLongLong(op);
+ vals[0] = (npy_intp ) PyLong_AsLongLong(op);
#endif
Py_DECREF(op);
@@ -596,9 +596,9 @@ PyArray_IntpFromSequence(PyObject *seq, intp *vals, int maxvals)
return -1;
}
#if SIZEOF_LONG >= SIZEOF_INTP
- vals[i]=(intp )PyInt_AsLong(op);
+ vals[i]=(npy_intp )PyInt_AsLong(op);
#else
- vals[i]=(intp )PyLong_AsLongLong(op);
+ vals[i]=(npy_intp )PyLong_AsLongLong(op);
#endif
Py_DECREF(op);
@@ -751,7 +751,7 @@ PyArray_TypestrConvert(int itemsize, int gentype)
PyArray_IntTupleFromIntp
*/
NPY_NO_EXPORT PyObject *
-PyArray_IntTupleFromIntp(int len, intp *vals)
+PyArray_IntTupleFromIntp(int len, npy_intp *vals)
{
int i;
PyObject *intTuple = PyTuple_New(len);
@@ -776,4 +776,3 @@ PyArray_IntTupleFromIntp(int len, intp *vals)
fail:
return intTuple;
}
-
diff --git a/numpy/core/src/multiarray/convert.c b/numpy/core/src/multiarray/convert.c
index a2c965181..b40519a4e 100644
--- a/numpy/core/src/multiarray/convert.c
+++ b/numpy/core/src/multiarray/convert.c
@@ -13,6 +13,7 @@
#include "arrayobject.h"
#include "mapping.h"
+#include "lowlevel_strided_loops.h"
#include "convert.h"
@@ -62,8 +63,8 @@ PyArray_ToList(PyArrayObject *self)
NPY_NO_EXPORT int
PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
{
- intp size;
- intp n, n2;
+ npy_intp size;
+ npy_intp n, n2;
size_t n3, n4;
PyArrayIterObject *it;
PyObject *obj, *strobj, *tupobj, *byteobj;
@@ -81,9 +82,33 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
if (PyArray_ISCONTIGUOUS(self)) {
size = PyArray_SIZE(self);
NPY_BEGIN_ALLOW_THREADS;
+
+#if defined (_MSC_VER) && defined(_WIN64)
+ /* Workaround Win64 fwrite() bug. Ticket #1660 */
+ {
+ npy_intp maxsize = 2147483648 / self->descr->elsize;
+ npy_intp chunksize;
+
+ n = 0;
+ while (size > 0) {
+ chunksize = (size > maxsize) ? maxsize : size;
+ n2 = fwrite((const void *)
+ ((char *)self->data + (n * self->descr->elsize)),
+ (size_t) self->descr->elsize,
+ (size_t) chunksize, fp);
+ if (n2 < chunksize) {
+ break;
+ }
+ n += n2;
+ size -= chunksize;
+ }
+ size = PyArray_SIZE(self);
+ }
+#else
n = fwrite((const void *)self->data,
(size_t) self->descr->elsize,
(size_t) size, fp);
+#endif
NPY_END_ALLOW_THREADS;
if (n < size) {
PyErr_Format(PyExc_ValueError,
@@ -328,27 +353,113 @@ PyArray_FillWithScalar(PyArrayObject *arr, PyObject *obj)
return 0;
}
+/*
+ * Fills an array with zeros.
+ *
+ * Returns 0 on success, -1 on failure.
+ */
+NPY_NO_EXPORT int
+PyArray_FillWithZero(PyArrayObject *a)
+{
+ PyArray_StridedTransferFn *stransfer = NULL;
+ void *transferdata = NULL;
+ PyArray_Descr *dtype = PyArray_DESCR(a);
+ NpyIter *iter;
+
+ NpyIter_IterNextFunc *iternext;
+ char **dataptr;
+ npy_intp stride, *countptr;
+ int needs_api;
+
+ NPY_BEGIN_THREADS_DEF;
+
+ if (!PyArray_ISWRITEABLE(a)) {
+ PyErr_SetString(PyExc_RuntimeError, "cannot write to array");
+ return -1;
+ }
+
+ /* A zero-sized array needs no zeroing */
+ if (PyArray_SIZE(a) == 0) {
+ return 0;
+ }
+
+ /* If it's possible to do a simple memset, do so */
+ if (!PyDataType_REFCHK(dtype) && (PyArray_ISCONTIGUOUS(a) ||
+ PyArray_ISFORTRAN(a))) {
+ memset(PyArray_DATA(a), 0, PyArray_NBYTES(a));
+ return 0;
+ }
+
+ /* Use an iterator to go through all the data */
+ iter = NpyIter_New(a, NPY_ITER_WRITEONLY|NPY_ITER_NO_INNER_ITERATION,
+ NPY_KEEPORDER, NPY_NO_CASTING,
+ NULL, 0, NULL, 0);
+
+ if (iter == NULL) {
+ return -1;
+ }
+
+ iternext = NpyIter_GetIterNext(iter, NULL);
+ if (iternext == NULL) {
+ NpyIter_Deallocate(iter);
+ return -1;
+ }
+ dataptr = NpyIter_GetDataPtrArray(iter);
+ stride = NpyIter_GetInnerStrideArray(iter)[0];
+ countptr = NpyIter_GetInnerLoopSizePtr(iter);
+
+ needs_api = NpyIter_IterationNeedsAPI(iter);
+
+ /*
+ * Because buffering is disabled in the iterator, the inner loop
+ * strides will be the same throughout the iteration loop. Thus,
+ * we can pass them to this function to take advantage of
+ * contiguous strides, etc.
+ *
+ * By setting the src_dtype to NULL, we get a function which sets
+ * the destination to zeros.
+ */
+ if (PyArray_GetDTypeTransferFunction(
+ PyArray_ISALIGNED(a),
+ 0, stride,
+ NULL, PyArray_DESCR(a),
+ 0,
+ &stransfer, &transferdata,
+ &needs_api) != NPY_SUCCEED) {
+ NpyIter_Deallocate(iter);
+ return -1;
+ }
+
+ if (!needs_api) {
+ NPY_BEGIN_THREADS;
+ }
+
+ do {
+ stransfer(NULL, 0, *dataptr, stride,
+ *countptr, 0, transferdata);
+ } while(iternext(iter));
+
+ if (!needs_api) {
+ NPY_END_THREADS;
+ }
+
+ PyArray_FreeStridedTransferData(transferdata);
+ NpyIter_Deallocate(iter);
+
+ return 0;
+}
+
/*NUMPY_API
- Copy an array.
-*/
+ * Copy an array.
+ */
NPY_NO_EXPORT PyObject *
-PyArray_NewCopy(PyArrayObject *m1, NPY_ORDER fortran)
+PyArray_NewCopy(PyArrayObject *m1, NPY_ORDER order)
{
- PyArrayObject *ret;
- if (fortran == PyArray_ANYORDER)
- fortran = PyArray_ISFORTRAN(m1);
-
- Py_INCREF(m1->descr);
- ret = (PyArrayObject *)PyArray_NewFromDescr(Py_TYPE(m1),
- m1->descr,
- m1->nd,
- m1->dimensions,
- NULL, NULL,
- fortran,
- (PyObject *)m1);
+ PyArrayObject *ret = (PyArrayObject *)PyArray_NewLikeArray(m1, order, NULL);
if (ret == NULL) {
return NULL;
}
+
if (PyArray_CopyInto(ret, m1) == -1) {
Py_DECREF(ret);
return NULL;
diff --git a/numpy/core/src/multiarray/convert.h b/numpy/core/src/multiarray/convert.h
index de24e27cf..1a34cfc52 100644
--- a/numpy/core/src/multiarray/convert.h
+++ b/numpy/core/src/multiarray/convert.h
@@ -1,4 +1,7 @@
#ifndef _NPY_ARRAYOBJECT_CONVERT_H_
#define _NPY_ARRAYOBJECT_CONVERT_H_
+NPY_NO_EXPORT int
+PyArray_FillWithZero(PyArrayObject *a);
+
#endif
diff --git a/numpy/core/src/multiarray/convert_datatype.c b/numpy/core/src/multiarray/convert_datatype.c
index 0040e8ad5..3359a5573 100644
--- a/numpy/core/src/multiarray/convert_datatype.c
+++ b/numpy/core/src/multiarray/convert_datatype.c
@@ -22,62 +22,57 @@
*
* Cast an array using typecode structure.
* steals reference to at --- cannot be NULL
+ *
+ * This function always makes a copy of arr, even if the dtype
+ * doesn't change.
*/
NPY_NO_EXPORT PyObject *
-PyArray_CastToType(PyArrayObject *mp, PyArray_Descr *at, int fortran)
+PyArray_CastToType(PyArrayObject *arr, PyArray_Descr *dtype, int fortran)
{
PyObject *out;
- int ret;
- PyArray_Descr *mpd;
+ PyArray_Descr *arr_dtype;
- mpd = mp->descr;
-
- if (((mpd == at) ||
- ((mpd->type_num == at->type_num) &&
- PyArray_EquivByteorders(mpd->byteorder, at->byteorder) &&
- ((mpd->elsize == at->elsize) || (at->elsize==0)))) &&
- PyArray_ISBEHAVED_RO(mp)) {
- Py_DECREF(at);
- Py_INCREF(mp);
- return (PyObject *)mp;
- }
+ arr_dtype = PyArray_DESCR(arr);
- if (at->elsize == 0) {
- PyArray_DESCR_REPLACE(at);
- if (at == NULL) {
+ if (dtype->elsize == 0) {
+ PyArray_DESCR_REPLACE(dtype);
+ if (dtype == NULL) {
return NULL;
}
- if (mpd->type_num == PyArray_STRING &&
- at->type_num == PyArray_UNICODE) {
- at->elsize = mpd->elsize << 2;
+
+ if (arr_dtype->type_num == dtype->type_num) {
+ dtype->elsize = arr_dtype->elsize;
+ }
+ else if (arr_dtype->type_num == NPY_STRING &&
+ dtype->type_num == NPY_UNICODE) {
+ dtype->elsize = arr_dtype->elsize * 4;
}
- if (mpd->type_num == PyArray_UNICODE &&
- at->type_num == PyArray_STRING) {
- at->elsize = mpd->elsize >> 2;
+ else if (arr_dtype->type_num == NPY_UNICODE &&
+ dtype->type_num == NPY_STRING) {
+ dtype->elsize = arr_dtype->elsize / 4;
}
- if (at->type_num == PyArray_VOID) {
- at->elsize = mpd->elsize;
+ else if (dtype->type_num == NPY_VOID) {
+ dtype->elsize = arr_dtype->elsize;
}
}
- out = PyArray_NewFromDescr(Py_TYPE(mp), at,
- mp->nd,
- mp->dimensions,
+ out = PyArray_NewFromDescr(Py_TYPE(arr), dtype,
+ arr->nd,
+ arr->dimensions,
NULL, NULL,
fortran,
- (PyObject *)mp);
+ (PyObject *)arr);
if (out == NULL) {
return NULL;
}
- ret = PyArray_CastTo((PyArrayObject *)out, mp);
- if (ret != -1) {
- return out;
- }
- Py_DECREF(out);
- return NULL;
+ if (PyArray_CopyInto((PyArrayObject *)out, arr) < 0) {
+ Py_DECREF(out);
+ return NULL;
+ }
+ return out;
}
/*NUMPY_API
@@ -90,10 +85,10 @@ PyArray_GetCastFunc(PyArray_Descr *descr, int type_num)
{
PyArray_VectorUnaryFunc *castfunc = NULL;
- if (type_num < PyArray_NTYPES) {
+ if (type_num < NPY_NTYPES_ABI_COMPATIBLE) {
castfunc = descr->f->cast[type_num];
}
- if (castfunc == NULL) {
+ else {
PyObject *obj = descr->f->castdict;
if (obj && PyDict_Check(obj)) {
PyObject *key;
@@ -120,17 +115,17 @@ PyArray_GetCastFunc(PyArray_Descr *descr, int type_num)
}
#if PY_VERSION_HEX >= 0x02050000
ret = PyErr_WarnEx(cls,
- "Casting complex values to real discards the imaginary "
- "part", 1);
+ "Casting complex values to real discards "
+ "the imaginary part", 1);
#else
ret = PyErr_Warn(cls,
- "Casting complex values to real discards the imaginary "
- "part");
+ "Casting complex values to real discards "
+ "the imaginary part");
#endif
Py_XDECREF(cls);
if (ret < 0) {
return NULL;
- }
+ }
}
if (castfunc) {
return castfunc;
@@ -141,161 +136,6 @@ PyArray_GetCastFunc(PyArray_Descr *descr, int type_num)
}
/*
- * Reference counts:
- * copyswapn is used which increases and decreases reference counts for OBJECT arrays.
- * All that needs to happen is for any reference counts in the buffers to be
- * decreased when completely finished with the buffers.
- *
- * buffers[0] is the destination
- * buffers[1] is the source
- */
-static void
-_strided_buffered_cast(char *dptr, intp dstride, int delsize, int dswap,
- PyArray_CopySwapNFunc *dcopyfunc,
- char *sptr, intp sstride, int selsize, int sswap,
- PyArray_CopySwapNFunc *scopyfunc,
- intp N, char **buffers, int bufsize,
- PyArray_VectorUnaryFunc *castfunc,
- PyArrayObject *dest, PyArrayObject *src)
-{
- int i;
- if (N <= bufsize) {
- /*
- * 1. copy input to buffer and swap
- * 2. cast input to output
- * 3. swap output if necessary and copy from output buffer
- */
- scopyfunc(buffers[1], selsize, sptr, sstride, N, sswap, src);
- castfunc(buffers[1], buffers[0], N, src, dest);
- dcopyfunc(dptr, dstride, buffers[0], delsize, N, dswap, dest);
- return;
- }
-
- /* otherwise we need to divide up into bufsize pieces */
- i = 0;
- while (N > 0) {
- int newN = MIN(N, bufsize);
-
- _strided_buffered_cast(dptr+i*dstride, dstride, delsize,
- dswap, dcopyfunc,
- sptr+i*sstride, sstride, selsize,
- sswap, scopyfunc,
- newN, buffers, bufsize, castfunc, dest, src);
- i += newN;
- N -= bufsize;
- }
- return;
-}
-
-static int
-_broadcast_cast(PyArrayObject *out, PyArrayObject *in,
- PyArray_VectorUnaryFunc *castfunc, int iswap, int oswap)
-{
- int delsize, selsize, maxaxis, i, N;
- PyArrayMultiIterObject *multi;
- intp maxdim, ostrides, istrides;
- char *buffers[2];
- PyArray_CopySwapNFunc *ocopyfunc, *icopyfunc;
- char *obptr;
- NPY_BEGIN_THREADS_DEF;
-
- delsize = PyArray_ITEMSIZE(out);
- selsize = PyArray_ITEMSIZE(in);
- multi = (PyArrayMultiIterObject *)PyArray_MultiIterNew(2, out, in);
- if (multi == NULL) {
- return -1;
- }
-
- if (multi->size != PyArray_SIZE(out)) {
- PyErr_SetString(PyExc_ValueError,
- "array dimensions are not "\
- "compatible for copy");
- Py_DECREF(multi);
- return -1;
- }
-
- icopyfunc = in->descr->f->copyswapn;
- ocopyfunc = out->descr->f->copyswapn;
- maxaxis = PyArray_RemoveSmallest(multi);
- if (maxaxis < 0) {
- /* cast 1 0-d array to another */
- N = 1;
- maxdim = 1;
- ostrides = delsize;
- istrides = selsize;
- }
- else {
- maxdim = multi->dimensions[maxaxis];
- N = (int) (MIN(maxdim, PyArray_BUFSIZE));
- ostrides = multi->iters[0]->strides[maxaxis];
- istrides = multi->iters[1]->strides[maxaxis];
-
- }
- buffers[0] = _pya_malloc(N*delsize);
- if (buffers[0] == NULL) {
- PyErr_NoMemory();
- return -1;
- }
- buffers[1] = _pya_malloc(N*selsize);
- if (buffers[1] == NULL) {
- _pya_free(buffers[0]);
- PyErr_NoMemory();
- return -1;
- }
- if (PyDataType_FLAGCHK(out->descr, NPY_NEEDS_INIT)) {
- memset(buffers[0], 0, N*delsize);
- }
- if (PyDataType_FLAGCHK(in->descr, NPY_NEEDS_INIT)) {
- memset(buffers[1], 0, N*selsize);
- }
-
-#if NPY_ALLOW_THREADS
- if (PyArray_ISNUMBER(in) && PyArray_ISNUMBER(out)) {
- NPY_BEGIN_THREADS;
- }
-#endif
-
- while (multi->index < multi->size) {
- _strided_buffered_cast(multi->iters[0]->dataptr,
- ostrides,
- delsize, oswap, ocopyfunc,
- multi->iters[1]->dataptr,
- istrides,
- selsize, iswap, icopyfunc,
- maxdim, buffers, N,
- castfunc, out, in);
- PyArray_MultiIter_NEXT(multi);
- }
-#if NPY_ALLOW_THREADS
- if (PyArray_ISNUMBER(in) && PyArray_ISNUMBER(out)) {
- NPY_END_THREADS;
- }
-#endif
- Py_DECREF(multi);
- if (PyDataType_REFCHK(in->descr)) {
- obptr = buffers[1];
- for (i = 0; i < N; i++, obptr+=selsize) {
- PyArray_Item_XDECREF(obptr, in->descr);
- }
- }
- if (PyDataType_REFCHK(out->descr)) {
- obptr = buffers[0];
- for (i = 0; i < N; i++, obptr+=delsize) {
- PyArray_Item_XDECREF(obptr, out->descr);
- }
- }
- _pya_free(buffers[0]);
- _pya_free(buffers[1]);
- if (PyErr_Occurred()) {
- return -1;
- }
-
- return 0;
-}
-
-
-
-/*
* Must be broadcastable.
* This code is very similar to PyArray_CopyInto/PyArray_MoveInto
* except casting is done --- PyArray_BUFSIZE is used
@@ -308,167 +148,8 @@ _broadcast_cast(PyArrayObject *out, PyArrayObject *in,
NPY_NO_EXPORT int
PyArray_CastTo(PyArrayObject *out, PyArrayObject *mp)
{
- int simple;
- int same;
- PyArray_VectorUnaryFunc *castfunc = NULL;
- intp mpsize = PyArray_SIZE(mp);
- int iswap, oswap;
- NPY_BEGIN_THREADS_DEF;
-
- if (mpsize == 0) {
- return 0;
- }
- if (!PyArray_ISWRITEABLE(out)) {
- PyErr_SetString(PyExc_ValueError, "output array is not writeable");
- return -1;
- }
-
- castfunc = PyArray_GetCastFunc(mp->descr, out->descr->type_num);
- if (castfunc == NULL) {
- return -1;
- }
-
- same = PyArray_SAMESHAPE(out, mp);
- simple = same && ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) ||
- (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));
- if (simple) {
-#if NPY_ALLOW_THREADS
- if (PyArray_ISNUMBER(mp) && PyArray_ISNUMBER(out)) {
- NPY_BEGIN_THREADS;
- }
-#endif
- castfunc(mp->data, out->data, mpsize, mp, out);
-
-#if NPY_ALLOW_THREADS
- if (PyArray_ISNUMBER(mp) && PyArray_ISNUMBER(out)) {
- NPY_END_THREADS;
- }
-#endif
- if (PyErr_Occurred()) {
- return -1;
- }
- return 0;
- }
-
- /*
- * If the input or output is OBJECT, STRING, UNICODE, or VOID
- * then getitem and setitem are used for the cast
- * and byteswapping is handled by those methods
- */
- if (PyArray_ISFLEXIBLE(mp) || PyArray_ISOBJECT(mp) || PyArray_ISOBJECT(out) ||
- PyArray_ISFLEXIBLE(out)) {
- iswap = oswap = 0;
- }
- else {
- iswap = PyArray_ISBYTESWAPPED(mp);
- oswap = PyArray_ISBYTESWAPPED(out);
- }
-
- return _broadcast_cast(out, mp, castfunc, iswap, oswap);
-}
-
-
-static int
-_bufferedcast(PyArrayObject *out, PyArrayObject *in,
- PyArray_VectorUnaryFunc *castfunc)
-{
- char *inbuffer, *bptr, *optr;
- char *outbuffer=NULL;
- PyArrayIterObject *it_in = NULL, *it_out = NULL;
- intp i, index;
- intp ncopies = PyArray_SIZE(out) / PyArray_SIZE(in);
- int elsize=in->descr->elsize;
- int nels = PyArray_BUFSIZE;
- int el;
- int inswap, outswap = 0;
- int obuf=!PyArray_ISCARRAY(out);
- int oelsize = out->descr->elsize;
- PyArray_CopySwapFunc *in_csn;
- PyArray_CopySwapFunc *out_csn;
- int retval = -1;
-
- in_csn = in->descr->f->copyswap;
- out_csn = out->descr->f->copyswap;
-
- /*
- * If the input or output is STRING, UNICODE, or VOID
- * then getitem and setitem are used for the cast
- * and byteswapping is handled by those methods
- */
-
- inswap = !(PyArray_ISFLEXIBLE(in) || PyArray_ISNOTSWAPPED(in));
-
- inbuffer = PyDataMem_NEW(PyArray_BUFSIZE*elsize);
- if (inbuffer == NULL) {
- return -1;
- }
- if (PyArray_ISOBJECT(in)) {
- memset(inbuffer, 0, PyArray_BUFSIZE*elsize);
- }
- it_in = (PyArrayIterObject *)PyArray_IterNew((PyObject *)in);
- if (it_in == NULL) {
- goto exit;
- }
- if (obuf) {
- outswap = !(PyArray_ISFLEXIBLE(out) ||
- PyArray_ISNOTSWAPPED(out));
- outbuffer = PyDataMem_NEW(PyArray_BUFSIZE*oelsize);
- if (outbuffer == NULL) {
- goto exit;
- }
- if (PyArray_ISOBJECT(out)) {
- memset(outbuffer, 0, PyArray_BUFSIZE*oelsize);
- }
- it_out = (PyArrayIterObject *)PyArray_IterNew((PyObject *)out);
- if (it_out == NULL) {
- goto exit;
- }
- nels = MIN(nels, PyArray_BUFSIZE);
- }
-
- optr = (obuf) ? outbuffer: out->data;
- bptr = inbuffer;
- el = 0;
- while (ncopies--) {
- index = it_in->size;
- PyArray_ITER_RESET(it_in);
- while (index--) {
- in_csn(bptr, it_in->dataptr, inswap, in);
- bptr += elsize;
- PyArray_ITER_NEXT(it_in);
- el += 1;
- if ((el == nels) || (index == 0)) {
- /* buffer filled, do cast */
- castfunc(inbuffer, optr, el, in, out);
- if (obuf) {
- /* Copy from outbuffer to array */
- for (i = 0; i < el; i++) {
- out_csn(it_out->dataptr,
- optr, outswap,
- out);
- optr += oelsize;
- PyArray_ITER_NEXT(it_out);
- }
- optr = outbuffer;
- }
- else {
- optr += out->descr->elsize * nels;
- }
- el = 0;
- bptr = inbuffer;
- }
- }
- }
- retval = 0;
-
- exit:
- Py_XDECREF(it_in);
- PyDataMem_FREE(inbuffer);
- PyDataMem_FREE(outbuffer);
- if (obuf) {
- Py_XDECREF(it_out);
- }
- return retval;
+ /* CopyInto handles the casting now */
+ return PyArray_CopyInto(out, mp);
}
/*NUMPY_API
@@ -478,42 +159,8 @@ _bufferedcast(PyArrayObject *out, PyArrayObject *in,
NPY_NO_EXPORT int
PyArray_CastAnyTo(PyArrayObject *out, PyArrayObject *mp)
{
- int simple;
- PyArray_VectorUnaryFunc *castfunc = NULL;
- npy_intp mpsize = PyArray_SIZE(mp);
-
- if (mpsize == 0) {
- return 0;
- }
- if (!PyArray_ISWRITEABLE(out)) {
- PyErr_SetString(PyExc_ValueError, "output array is not writeable");
- return -1;
- }
-
- if (!(mpsize == PyArray_SIZE(out))) {
- PyErr_SetString(PyExc_ValueError,
- "arrays must have the same number of"
- " elements for the cast.");
- return -1;
- }
-
- castfunc = PyArray_GetCastFunc(mp->descr, out->descr->type_num);
- if (castfunc == NULL) {
- return -1;
- }
- simple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) ||
- (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));
- if (simple) {
- castfunc(mp->data, out->data, mpsize, mp, out);
- return 0;
- }
- if (PyArray_SAMESHAPE(out, mp)) {
- int iswap, oswap;
- iswap = PyArray_ISBYTESWAPPED(mp) && !PyArray_ISFLEXIBLE(mp);
- oswap = PyArray_ISBYTESWAPPED(out) && !PyArray_ISFLEXIBLE(out);
- return _broadcast_cast(out, mp, castfunc, iswap, oswap);
- }
- return _bufferedcast(out, mp, castfunc);
+ /* CopyAnyInto handles the casting now */
+ return PyArray_CopyAnyInto(out, mp);
}
/*NUMPY_API
@@ -525,7 +172,8 @@ PyArray_CanCastSafely(int fromtype, int totype)
PyArray_Descr *from;
/* Fast table lookup for small type numbers */
- if ((unsigned int)fromtype < NPY_NTYPES && (unsigned int)totype < NPY_NTYPES) {
+ if ((unsigned int)fromtype < NPY_NTYPES &&
+ (unsigned int)totype < NPY_NTYPES) {
return _npy_can_cast_safely_table[fromtype][totype];
}
@@ -572,15 +220,18 @@ PyArray_CanCastSafely(int fromtype, int totype)
/*NUMPY_API
* leaves reference count alone --- cannot be NULL
+ *
+ * PyArray_CanCastTypeTo is equivalent to this, but adds a 'casting'
+ * parameter.
*/
-NPY_NO_EXPORT Bool
+NPY_NO_EXPORT npy_bool
PyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)
{
int fromtype=from->type_num;
int totype=to->type_num;
- Bool ret;
+ npy_bool ret;
- ret = (Bool) PyArray_CanCastSafely(fromtype, totype);
+ ret = (npy_bool) PyArray_CanCastSafely(fromtype, totype);
if (ret) {
/* Check String and Unicode more closely */
if (fromtype == PyArray_STRING) {
@@ -605,10 +256,212 @@ PyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)
return ret;
}
+/* Provides an ordering for the dtype 'kind' character codes */
+static int
+dtype_kind_to_ordering(char kind)
+{
+ switch (kind) {
+ /* Boolean kind */
+ case 'b':
+ return 0;
+ /* Unsigned int kind */
+ case 'u':
+ return 1;
+ /* Signed int kind */
+ case 'i':
+ return 2;
+ /* Float kind */
+ case 'f':
+ return 4;
+ /* Complex kind */
+ case 'c':
+ return 5;
+ /* String kind */
+ case 'S':
+ case 'a':
+ return 6;
+ /* Unicode kind */
+ case 'U':
+ return 7;
+ /* Void kind */
+ case 'V':
+ return 8;
+ /* Object kind */
+ case 'O':
+ return 9;
+ /* Anything else - ideally shouldn't happen... */
+ default:
+ return 10;
+ }
+}
+
+/* Converts a type number from unsigned to signed */
+static int
+type_num_unsigned_to_signed(int type_num)
+{
+ switch (type_num) {
+ case NPY_UBYTE:
+ return NPY_BYTE;
+ case NPY_USHORT:
+ return NPY_SHORT;
+ case NPY_UINT:
+ return NPY_INT;
+ case NPY_ULONG:
+ return NPY_LONG;
+ case NPY_ULONGLONG:
+ return NPY_LONGLONG;
+ default:
+ return type_num;
+ }
+}
+
+/*NUMPY_API
+ * Returns true if data of type 'from' may be cast to data of type
+ * 'to' according to the rule 'casting'.
+ */
+NPY_NO_EXPORT npy_bool
+PyArray_CanCastTypeTo(PyArray_Descr *from, PyArray_Descr *to,
+ NPY_CASTING casting)
+{
+ /* If unsafe casts are allowed */
+ if (casting == NPY_UNSAFE_CASTING) {
+ return 1;
+ }
+ /* Equivalent types can be cast with any value of 'casting' */
+ else if (PyArray_EquivTypenums(from->type_num, to->type_num)) {
+ /* For complicated case, use EquivTypes (for now) */
+ if (PyTypeNum_ISUSERDEF(from->type_num) ||
+ PyDataType_HASFIELDS(from) ||
+ from->subarray != NULL) {
+ int ret;
+
+ /* Only NPY_NO_CASTING prevents byte order conversion */
+ if ((casting != NPY_NO_CASTING) &&
+ (!PyArray_ISNBO(from->byteorder) ||
+ !PyArray_ISNBO(to->byteorder))) {
+ PyArray_Descr *nbo_from, *nbo_to;
+
+ nbo_from = PyArray_DescrNewByteorder(from, NPY_NATIVE);
+ nbo_to = PyArray_DescrNewByteorder(to, NPY_NATIVE);
+ if (nbo_from == NULL || nbo_to == NULL) {
+ Py_XDECREF(nbo_from);
+ Py_XDECREF(nbo_to);
+ PyErr_Clear();
+ return 0;
+ }
+ ret = PyArray_EquivTypes(nbo_from, nbo_to);
+ Py_DECREF(nbo_from);
+ Py_DECREF(nbo_to);
+ }
+ else {
+ ret = PyArray_EquivTypes(from, to);
+ }
+ return ret;
+ }
+
+ switch (casting) {
+ case NPY_NO_CASTING:
+ return (from->elsize == to->elsize) &&
+ PyArray_ISNBO(from->byteorder) ==
+ PyArray_ISNBO(to->byteorder);
+ case NPY_EQUIV_CASTING:
+ return (from->elsize == to->elsize);
+ case NPY_SAFE_CASTING:
+ return (from->elsize <= to->elsize);
+ default:
+ return 1;
+ }
+ }
+ /* If safe or same-kind casts are allowed */
+ else if (casting == NPY_SAFE_CASTING || casting == NPY_SAME_KIND_CASTING) {
+ if (PyArray_CanCastTo(from, to)) {
+ return 1;
+ }
+ else if(casting == NPY_SAME_KIND_CASTING) {
+ /*
+ * Also allow casting from lower to higher kinds, according
+ * to the ordering provided by dtype_kind_to_ordering.
+ */
+ return dtype_kind_to_ordering(from->kind) <=
+ dtype_kind_to_ordering(to->kind);
+ }
+ else {
+ return 0;
+ }
+ }
+ /* NPY_NO_CASTING or NPY_EQUIV_CASTING was specified */
+ else {
+ return 0;
+ }
+}
+
+/* CanCastArrayTo needs this function */
+static int min_scalar_type_num(char *valueptr, int type_num,
+ int *is_small_unsigned);
+
+/*NUMPY_API
+ * Returns 1 if the array object may be cast to the given data type using
+ * the casting rule, 0 otherwise. This differs from PyArray_CanCastTo in
+ * that it handles scalar arrays (0 dimensions) specially, by checking
+ * their value.
+ */
+NPY_NO_EXPORT npy_bool
+PyArray_CanCastArrayTo(PyArrayObject *arr, PyArray_Descr *to,
+ NPY_CASTING casting)
+{
+ PyArray_Descr *from = PyArray_DESCR(arr);
+
+ /* If it's not a scalar, use the standard rules */
+ if (PyArray_NDIM(arr) > 0 || !PyTypeNum_ISNUMBER(from->type_num)) {
+ return PyArray_CanCastTypeTo(from, to, casting);
+ }
+ /* Otherwise, check the value */
+ else {
+ int swap = !PyArray_ISNBO(from->byteorder);
+ int is_small_unsigned = 0, type_num;
+ npy_bool ret;
+ PyArray_Descr *dtype;
+
+ /* An aligned memory buffer large enough to hold any type */
+ npy_longlong value[4];
+
+ from->f->copyswap(&value, PyArray_BYTES(arr), swap, NULL);
+
+ type_num = min_scalar_type_num((char *)&value, from->type_num,
+ &is_small_unsigned);
+
+ /*
+ * If we've got a small unsigned scalar, and the 'to' type
+ * is not unsigned, then make it signed to allow the value
+ * to be cast more appropriately.
+ */
+ if (is_small_unsigned && !(PyTypeNum_ISUNSIGNED(to->type_num))) {
+ type_num = type_num_unsigned_to_signed(type_num);
+ }
+
+ dtype = PyArray_DescrFromType(type_num);
+ if (dtype == NULL) {
+ return 0;
+ }
+#if 0
+ printf("min scalar cast ");
+ PyObject_Print(dtype, stdout, 0);
+ printf(" to ");
+ PyObject_Print(to, stdout, 0);
+ printf("\n");
+#endif
+ ret = PyArray_CanCastTypeTo(dtype, to, casting);
+ Py_DECREF(dtype);
+ return ret;
+ }
+}
+
/*NUMPY_API
* See if array scalars can be cast.
+ *
+ * TODO: For NumPy 2.0, add a NPY_CASTING parameter.
*/
-NPY_NO_EXPORT Bool
+NPY_NO_EXPORT npy_bool
PyArray_CanCastScalar(PyTypeObject *from, PyTypeObject *to)
{
int fromtype;
@@ -619,7 +472,774 @@ PyArray_CanCastScalar(PyTypeObject *from, PyTypeObject *to)
if (fromtype == PyArray_NOTYPE || totype == PyArray_NOTYPE) {
return FALSE;
}
- return (Bool) PyArray_CanCastSafely(fromtype, totype);
+ return (npy_bool) PyArray_CanCastSafely(fromtype, totype);
+}
+
+/*
+ * Internal promote types function which handles unsigned integers which
+ * fit in same-sized signed integers specially.
+ */
+static PyArray_Descr *
+promote_types(PyArray_Descr *type1, PyArray_Descr *type2,
+ int is_small_unsigned1, int is_small_unsigned2)
+{
+ if (is_small_unsigned1) {
+ int type_num1 = type1->type_num;
+ int type_num2 = type2->type_num;
+ int ret_type_num;
+
+ if (type_num2 < NPY_NTYPES && !(PyTypeNum_ISBOOL(type_num2) ||
+ PyTypeNum_ISUNSIGNED(type_num2))) {
+ /* Convert to the equivalent-sized signed integer */
+ type_num1 = type_num_unsigned_to_signed(type_num1);
+
+ ret_type_num = _npy_type_promotion_table[type_num1][type_num2];
+ /* The table doesn't handle string/unicode/void, check the result */
+ if (ret_type_num >= 0) {
+ return PyArray_DescrFromType(ret_type_num);
+ }
+ }
+
+ return PyArray_PromoteTypes(type1, type2);
+ }
+ else if (is_small_unsigned2) {
+ int type_num1 = type1->type_num;
+ int type_num2 = type2->type_num;
+ int ret_type_num;
+
+ if (type_num1 < NPY_NTYPES && !(PyTypeNum_ISBOOL(type_num1) ||
+ PyTypeNum_ISUNSIGNED(type_num1))) {
+ /* Convert to the equivalent-sized signed integer */
+ type_num2 = type_num_unsigned_to_signed(type_num2);
+
+ ret_type_num = _npy_type_promotion_table[type_num1][type_num2];
+ /* The table doesn't handle string/unicode/void, check the result */
+ if (ret_type_num >= 0) {
+ return PyArray_DescrFromType(ret_type_num);
+ }
+ }
+
+ return PyArray_PromoteTypes(type1, type2);
+ }
+ else {
+ return PyArray_PromoteTypes(type1, type2);
+ }
+
+}
+
+/*NUMPY_API
+ * Produces the smallest size and lowest kind type to which both
+ * input types can be cast.
+ */
+NPY_NO_EXPORT PyArray_Descr *
+PyArray_PromoteTypes(PyArray_Descr *type1, PyArray_Descr *type2)
+{
+ int type_num1, type_num2, ret_type_num;
+
+ type_num1 = type1->type_num;
+ type_num2 = type2->type_num;
+
+ /* If they're built-in types, use the promotion table */
+ if (type_num1 < NPY_NTYPES && type_num2 < NPY_NTYPES) {
+ ret_type_num = _npy_type_promotion_table[type_num1][type_num2];
+ /* The table doesn't handle string/unicode/void, check the result */
+ if (ret_type_num >= 0) {
+ return PyArray_DescrFromType(ret_type_num);
+ }
+ }
+ /* If one or both are user defined, calculate it */
+ else {
+ int skind1 = NPY_NOSCALAR, skind2 = NPY_NOSCALAR, skind;
+
+ if (PyArray_CanCastTo(type2, type1)) {
+ /* Promoted types are always native byte order */
+ if (PyArray_ISNBO(type1->byteorder)) {
+ Py_INCREF(type1);
+ return type1;
+ }
+ else {
+ return PyArray_DescrNewByteorder(type1, NPY_NATIVE);
+ }
+ }
+ else if (PyArray_CanCastTo(type1, type2)) {
+ /* Promoted types are always native byte order */
+ if (PyArray_ISNBO(type2->byteorder)) {
+ Py_INCREF(type2);
+ return type2;
+ }
+ else {
+ return PyArray_DescrNewByteorder(type2, NPY_NATIVE);
+ }
+ }
+
+ /* Convert the 'kind' char into a scalar kind */
+ switch (type1->kind) {
+ case 'b':
+ skind1 = NPY_BOOL_SCALAR;
+ break;
+ case 'u':
+ skind1 = NPY_INTPOS_SCALAR;
+ break;
+ case 'i':
+ skind1 = NPY_INTNEG_SCALAR;
+ break;
+ case 'f':
+ skind1 = NPY_FLOAT_SCALAR;
+ break;
+ case 'c':
+ skind1 = NPY_COMPLEX_SCALAR;
+ break;
+ }
+ switch (type2->kind) {
+ case 'b':
+ skind2 = NPY_BOOL_SCALAR;
+ break;
+ case 'u':
+ skind2 = NPY_INTPOS_SCALAR;
+ break;
+ case 'i':
+ skind2 = NPY_INTNEG_SCALAR;
+ break;
+ case 'f':
+ skind2 = NPY_FLOAT_SCALAR;
+ break;
+ case 'c':
+ skind2 = NPY_COMPLEX_SCALAR;
+ break;
+ }
+
+ /* If both are scalars, there may be a promotion possible */
+ if (skind1 != NPY_NOSCALAR && skind2 != NPY_NOSCALAR) {
+
+ /* Start with the larger scalar kind */
+ skind = (skind1 > skind2) ? skind1 : skind2;
+ ret_type_num = _npy_smallest_type_of_kind_table[skind];
+
+ for (;;) {
+
+ /* If there is no larger type of this kind, try a larger kind */
+ if (ret_type_num < 0) {
+ ++skind;
+ /* Use -1 to signal no promoted type found */
+ if (skind < NPY_NSCALARKINDS) {
+ ret_type_num = _npy_smallest_type_of_kind_table[skind];
+ }
+ else {
+ break;
+ }
+ }
+
+ /* If we found a type to which we can promote both, done! */
+ if (PyArray_CanCastSafely(type_num1, ret_type_num) &&
+ PyArray_CanCastSafely(type_num2, ret_type_num)) {
+ return PyArray_DescrFromType(ret_type_num);
+ }
+
+ /* Try the next larger type of this kind */
+ ret_type_num = _npy_next_larger_type_table[ret_type_num];
+ }
+
+ }
+
+ PyErr_SetString(PyExc_TypeError,
+ "invalid type promotion with custom data type");
+ return NULL;
+ }
+
+ switch (type_num1) {
+ /* BOOL can convert to anything */
+ case NPY_BOOL:
+ Py_INCREF(type2);
+ return type2;
+ /* For strings and unicodes, take the larger size */
+ case NPY_STRING:
+ if (type_num2 == NPY_STRING) {
+ if (type1->elsize > type2->elsize) {
+ Py_INCREF(type1);
+ return type1;
+ }
+ else {
+ Py_INCREF(type2);
+ return type2;
+ }
+ }
+ else if (type_num2 == NPY_UNICODE) {
+ if (type2->elsize >= type1->elsize * 4) {
+ Py_INCREF(type2);
+ return type2;
+ }
+ else {
+ PyArray_Descr *d = PyArray_DescrNewFromType(NPY_UNICODE);
+ if (d == NULL) {
+ return NULL;
+ }
+ d->elsize = type1->elsize * 4;
+ return d;
+ }
+ }
+ /* Allow NUMBER -> STRING */
+ else if (PyTypeNum_ISNUMBER(type_num2)) {
+ Py_INCREF(type1);
+ return type1;
+ }
+ case NPY_UNICODE:
+ if (type_num2 == NPY_UNICODE) {
+ if (type1->elsize > type2->elsize) {
+ Py_INCREF(type1);
+ return type1;
+ }
+ else {
+ Py_INCREF(type2);
+ return type2;
+ }
+ }
+ else if (type_num2 == NPY_STRING) {
+ if (type1->elsize >= type2->elsize * 4) {
+ Py_INCREF(type1);
+ return type1;
+ }
+ else {
+ PyArray_Descr *d = PyArray_DescrNewFromType(NPY_UNICODE);
+ if (d == NULL) {
+ return NULL;
+ }
+ d->elsize = type2->elsize * 4;
+ return d;
+ }
+ }
+ /* Allow NUMBER -> UNICODE */
+ else if (PyTypeNum_ISNUMBER(type_num2)) {
+ Py_INCREF(type1);
+ return type1;
+ }
+ break;
+ }
+
+ switch (type_num2) {
+ /* BOOL can convert to anything */
+ case NPY_BOOL:
+ Py_INCREF(type1);
+ return type1;
+ case NPY_STRING:
+ /* Allow NUMBER -> STRING */
+ if (PyTypeNum_ISNUMBER(type_num1)) {
+ Py_INCREF(type2);
+ return type2;
+ }
+ case NPY_UNICODE:
+ /* Allow NUMBER -> UNICODE */
+ if (PyTypeNum_ISNUMBER(type_num1)) {
+ Py_INCREF(type2);
+ return type2;
+ }
+ break;
+ }
+
+ /* For equivalent types we can return either */
+ if (PyArray_EquivTypes(type1, type2)) {
+ Py_INCREF(type1);
+ return type1;
+ }
+
+ /* TODO: Also combine fields, subarrays, strings, etc */
+
+ /*
+ printf("invalid type promotion: ");
+ PyObject_Print(type1, stdout, 0);
+ printf(" ");
+ PyObject_Print(type2, stdout, 0);
+ printf("\n");
+ */
+ PyErr_SetString(PyExc_TypeError, "invalid type promotion");
+ return NULL;
+}
+
+/*
+ * NOTE: While this is unlikely to be a performance problem, if
+ * it is it could be reverted to a simple positive/negative
+ * check as the previous system used.
+ *
+ * The is_small_unsigned output flag indicates whether it's an unsigned integer,
+ * and would fit in a signed integer of the same bit size.
+ */
+static int min_scalar_type_num(char *valueptr, int type_num,
+ int *is_small_unsigned)
+{
+ switch (type_num) {
+ case NPY_BOOL: {
+ return NPY_BOOL;
+ }
+ case NPY_UBYTE: {
+ char value = *valueptr;
+ if (value <= NPY_MAX_BYTE) {
+ *is_small_unsigned = 1;
+ }
+ return NPY_UBYTE;
+ }
+ case NPY_BYTE: {
+ char value = *valueptr;
+ if (value >= 0) {
+ *is_small_unsigned = 1;
+ return NPY_UBYTE;
+ }
+ break;
+ }
+ case NPY_USHORT: {
+ npy_ushort value = *(npy_ushort *)valueptr;
+ if (value <= NPY_MAX_UBYTE) {
+ if (value <= NPY_MAX_BYTE) {
+ *is_small_unsigned = 1;
+ }
+ return NPY_UBYTE;
+ }
+
+ if (value <= NPY_MAX_SHORT) {
+ *is_small_unsigned = 1;
+ }
+ break;
+ }
+ case NPY_SHORT: {
+ npy_short value = *(npy_short *)valueptr;
+ if (value >= 0) {
+ return min_scalar_type_num(valueptr, NPY_USHORT, is_small_unsigned);
+ }
+ else if (value >= NPY_MIN_BYTE) {
+ return NPY_BYTE;
+ }
+ break;
+ }
+#if NPY_SIZEOF_LONG == NPY_SIZEOF_INT
+ case NPY_ULONG:
+#endif
+ case NPY_UINT: {
+ npy_uint value = *(npy_uint *)valueptr;
+ if (value <= NPY_MAX_UBYTE) {
+ if (value < NPY_MAX_BYTE) {
+ *is_small_unsigned = 1;
+ }
+ return NPY_UBYTE;
+ }
+ else if (value <= NPY_MAX_USHORT) {
+ if (value <= NPY_MAX_SHORT) {
+ *is_small_unsigned = 1;
+ }
+ return NPY_USHORT;
+ }
+
+ if (value <= NPY_MAX_INT) {
+ *is_small_unsigned = 1;
+ }
+ break;
+ }
+#if NPY_SIZEOF_LONG == NPY_SIZEOF_INT
+ case NPY_LONG:
+#endif
+ case NPY_INT: {
+ npy_int value = *(npy_int *)valueptr;
+ if (value >= 0) {
+ return min_scalar_type_num(valueptr, NPY_UINT, is_small_unsigned);
+ }
+ else if (value >= NPY_MIN_BYTE) {
+ return NPY_BYTE;
+ }
+ else if (value >= NPY_MIN_SHORT) {
+ return NPY_SHORT;
+ }
+ break;
+ }
+#if NPY_SIZEOF_LONG != NPY_SIZEOF_INT && NPY_SIZEOF_LONG != NPY_SIZEOF_LONGLONG
+ case NPY_ULONG: {
+ npy_ulong value = *(npy_ulong *)valueptr;
+ if (value <= NPY_MAX_UBYTE) {
+ if (value <= NPY_MAX_BYTE) {
+ *is_small_unsigned = 1;
+ }
+ return NPY_UBYTE;
+ }
+ else if (value <= NPY_MAX_USHORT) {
+ if (value <= NPY_MAX_SHORT) {
+ *is_small_unsigned = 1;
+ }
+ return NPY_USHORT;
+ }
+ else if (value <= NPY_MAX_UINT) {
+ if (value <= NPY_MAX_INT) {
+ *is_small_unsigned = 1;
+ }
+ return NPY_UINT;
+ }
+
+ if (value <= NPY_MAX_LONG) {
+ *is_small_unsigned = 1;
+ }
+ break;
+ }
+ case NPY_LONG: {
+ npy_long value = *(npy_long *)valueptr;
+ if (value >= 0) {
+ return min_scalar_type_num(valueptr, NPY_ULONG, is_small_unsigned);
+ }
+ else if (value >= NPY_MIN_BYTE) {
+ return NPY_BYTE;
+ }
+ else if (value >= NPY_MIN_SHORT) {
+ return NPY_SHORT;
+ }
+ else if (value >= NPY_MIN_INT) {
+ return NPY_INT;
+ }
+ break;
+ }
+#endif
+#if NPY_SIZEOF_LONG == NPY_SIZEOF_LONGLONG
+ case NPY_ULONG:
+#endif
+ case NPY_ULONGLONG: {
+ npy_ulonglong value = *(npy_ulonglong *)valueptr;
+ if (value <= NPY_MAX_UBYTE) {
+ if (value <= NPY_MAX_BYTE) {
+ *is_small_unsigned = 1;
+ }
+ return NPY_UBYTE;
+ }
+ else if (value <= NPY_MAX_USHORT) {
+ if (value <= NPY_MAX_SHORT) {
+ *is_small_unsigned = 1;
+ }
+ return NPY_USHORT;
+ }
+ else if (value <= NPY_MAX_UINT) {
+ if (value <= NPY_MAX_INT) {
+ *is_small_unsigned = 1;
+ }
+ return NPY_UINT;
+ }
+#if NPY_SIZEOF_LONG != NPY_SIZEOF_INT && NPY_SIZEOF_LONG != NPY_SIZEOF_LONGLONG
+ else if (value <= NPY_MAX_ULONG) {
+ if (value <= NPY_MAX_LONG) {
+ *is_small_unsigned = 1;
+ }
+ return NPY_ULONG;
+ }
+#endif
+
+ if (value <= NPY_MAX_LONGLONG) {
+ *is_small_unsigned = 1;
+ }
+ break;
+ }
+#if NPY_SIZEOF_LONG == NPY_SIZEOF_LONGLONG
+ case NPY_LONG:
+#endif
+ case NPY_LONGLONG: {
+ npy_longlong value = *(npy_longlong *)valueptr;
+ if (value >= 0) {
+ return min_scalar_type_num(valueptr, NPY_ULONGLONG, is_small_unsigned);
+ }
+ else if (value >= NPY_MIN_BYTE) {
+ return NPY_BYTE;
+ }
+ else if (value >= NPY_MIN_SHORT) {
+ return NPY_SHORT;
+ }
+ else if (value >= NPY_MIN_INT) {
+ return NPY_INT;
+ }
+#if NPY_SIZEOF_LONG != NPY_SIZEOF_INT && NPY_SIZEOF_LONG != NPY_SIZEOF_LONGLONG
+ else if (value >= NPY_MIN_LONG) {
+ return NPY_LONG;
+ }
+#endif
+ break;
+ }
+ /*
+ * Float types aren't allowed to be demoted to integer types,
+ * but precision loss is allowed.
+ */
+ case NPY_HALF: {
+ return NPY_HALF;
+ }
+ case NPY_FLOAT: {
+ float value = *(float *)valueptr;
+ if (value > -65000 && value < 65000) {
+ return NPY_HALF;
+ }
+ break;
+ }
+ case NPY_DOUBLE: {
+ double value = *(double *)valueptr;
+ if (value > -65000 && value < 65000) {
+ return NPY_HALF;
+ }
+ else if (value > -3.4e38 && value < 3.4e38) {
+ return NPY_FLOAT;
+ }
+ break;
+ }
+ case NPY_LONGDOUBLE: {
+ npy_longdouble value = *(npy_longdouble *)valueptr;
+ if (value > -65000 && value < 65000) {
+ return NPY_HALF;
+ }
+ else if (value > -3.4e38 && value < 3.4e38) {
+ return NPY_FLOAT;
+ }
+ else if (value > -1.7e308 && value < 1.7e308) {
+ return NPY_DOUBLE;
+ }
+ break;
+ }
+ /*
+ * The code to demote complex to float is disabled for now,
+ * as forcing complex by adding 0j is probably desireable.
+ */
+ case NPY_CFLOAT: {
+ /*
+ npy_cfloat value = *(npy_cfloat *)valueptr;
+ if (value.imag == 0) {
+ return min_scalar_type_num((char *)&value.real,
+ NPY_FLOAT, is_small_unsigned);
+ }
+ */
+ break;
+ }
+ case NPY_CDOUBLE: {
+ npy_cdouble value = *(npy_cdouble *)valueptr;
+ /*
+ if (value.imag == 0) {
+ return min_scalar_type_num((char *)&value.real,
+ NPY_DOUBLE, is_small_unsigned);
+ }
+ */
+ if (value.real > -3.4e38 && value.real < 3.4e38 &&
+ value.imag > -3.4e38 && value.imag < 3.4e38) {
+ return NPY_CFLOAT;
+ }
+ break;
+ }
+ case NPY_CLONGDOUBLE: {
+ npy_cdouble value = *(npy_cdouble *)valueptr;
+ /*
+ if (value.imag == 0) {
+ return min_scalar_type_num((char *)&value.real,
+ NPY_LONGDOUBLE, is_small_unsigned);
+ }
+ */
+ if (value.real > -3.4e38 && value.real < 3.4e38 &&
+ value.imag > -3.4e38 && value.imag < 3.4e38) {
+ return NPY_CFLOAT;
+ }
+ else if (value.real > -1.7e308 && value.real < 1.7e308 &&
+ value.imag > -1.7e308 && value.imag < 1.7e308) {
+ return NPY_CDOUBLE;
+ }
+ break;
+ }
+ }
+
+ return type_num;
+}
+
+/*NUMPY_API
+ * If arr is a scalar (has 0 dimensions) with a built-in number data type,
+ * finds the smallest type size/kind which can still represent its data.
+ * Otherwise, returns the array's data type.
+ *
+ */
+NPY_NO_EXPORT PyArray_Descr *
+PyArray_MinScalarType(PyArrayObject *arr)
+{
+ PyArray_Descr *dtype = PyArray_DESCR(arr);
+ if (PyArray_NDIM(arr) > 0 || !PyTypeNum_ISNUMBER(dtype->type_num)) {
+ Py_INCREF(dtype);
+ return dtype;
+ }
+ else {
+ char *data = PyArray_BYTES(arr);
+ int swap = !PyArray_ISNBO(dtype->byteorder);
+ int is_small_unsigned = 0;
+ /* An aligned memory buffer large enough to hold any type */
+#if NPY_SIZEOF_LONGLONG >= NPY_SIZEOF_CLONGDOUBLE
+ npy_longlong value;
+#else
+ npy_clongdouble value;
+#endif
+ dtype->f->copyswap(&value, data, swap, NULL);
+
+ return PyArray_DescrFromType(
+ min_scalar_type_num((char *)&value, dtype->type_num, &is_small_unsigned));
+
+ }
+}
+
+/*NUMPY_API
+ * Produces the result type of a bunch of inputs, using the UFunc
+ * type promotion rules.
+ *
+ * If all the inputs are scalars (have 0 dimensions), does a regular
+ * type promotion. Otherwise, does a type promotion on the MinScalarType
+ * of all the inputs. Data types passed directly are treated as vector
+ * types.
+ *
+ */
+NPY_NO_EXPORT PyArray_Descr *
+PyArray_ResultType(npy_intp narrs, PyArrayObject **arr,
+ npy_intp ndtypes, PyArray_Descr **dtypes)
+{
+ npy_intp i;
+ int all_scalar;
+ PyArray_Descr *ret = NULL, *tmpret;
+ int ret_is_small_unsigned = 0;
+
+ /* If there's just one type, pass it through */
+ if (narrs + ndtypes == 1) {
+ if (narrs == 1) {
+ ret = PyArray_DESCR(arr[0]);
+ }
+ else {
+ ret = dtypes[0];
+ }
+ Py_INCREF(ret);
+ return ret;
+ }
+
+ /* Determine if there are any scalars */
+ if (ndtypes > 0) {
+ all_scalar = 0;
+ }
+ else {
+ all_scalar = 1;
+ for (i = 0; i < narrs; ++i) {
+ if (PyArray_NDIM(arr[i]) != 0) {
+ all_scalar = 0;
+ break;
+ }
+ }
+ }
+
+ /* Loop through all the types, promoting them */
+ if (all_scalar) {
+ for (i = 0; i < narrs; ++i) {
+ PyArray_Descr *tmp = PyArray_DESCR(arr[i]);
+ /* Combine it with the existing type */
+ if (ret == NULL) {
+ ret = tmp;
+ Py_INCREF(ret);
+ }
+ else {
+ /* Only call promote if the types aren't the same dtype */
+ if (tmp != ret || !PyArray_ISNBO(ret->byteorder)) {
+ tmpret = PyArray_PromoteTypes(tmp, ret);
+ Py_DECREF(ret);
+ ret = tmpret;
+ }
+ }
+ }
+ }
+ else {
+ for (i = 0; i < narrs; ++i) {
+ /* Get the min scalar type for the array */
+ PyArray_Descr *tmp = PyArray_DESCR(arr[i]);
+ int tmp_is_small_unsigned = 0;
+ /*
+ * If it's a scalar, find the min scalar type. The function
+ * is expanded here so that we can flag whether we've got an
+ * unsigned integer which would fit an a signed integer
+ * of the same size, something not exposed in the public API.
+ */
+ if (PyArray_NDIM(arr[i]) == 0 &&
+ PyTypeNum_ISNUMBER(tmp->type_num)) {
+ char *data = PyArray_BYTES(arr[i]);
+ int swap = !PyArray_ISNBO(tmp->byteorder);
+ int type_num;
+ /* An aligned memory buffer large enough to hold any type */
+#if NPY_SIZEOF_LONGLONG >= NPY_SIZEOF_CLONGDOUBLE
+ npy_longlong value;
+#else
+ npy_clongdouble value;
+#endif
+ tmp->f->copyswap(&value, data, swap, NULL);
+ type_num = min_scalar_type_num((char *)&value,
+ tmp->type_num, &tmp_is_small_unsigned);
+ tmp = PyArray_DescrFromType(type_num);
+ if (tmp == NULL) {
+ Py_XDECREF(ret);
+ return NULL;
+ }
+ }
+ else {
+ Py_INCREF(tmp);
+ }
+ /* Combine it with the existing type */
+ if (ret == NULL) {
+ ret = tmp;
+ ret_is_small_unsigned = tmp_is_small_unsigned;
+ }
+ else {
+#if 0
+ printf("promoting type ");
+ PyObject_Print(tmp, stdout, 0);
+ printf(" (%d) ", tmp_is_small_unsigned);
+ PyObject_Print(ret, stdout, 0);
+ printf(" (%d) ", ret_is_small_unsigned);
+ printf("\n");
+#endif
+ /* If they point to the same type, don't call promote */
+ if (tmp == ret && PyArray_ISNBO(tmp->byteorder)) {
+ Py_DECREF(tmp);
+ }
+ else {
+ tmpret = promote_types(tmp, ret, tmp_is_small_unsigned,
+ ret_is_small_unsigned);
+ if (tmpret == NULL) {
+ Py_DECREF(tmp);
+ Py_DECREF(ret);
+ return NULL;
+ }
+ Py_DECREF(tmp);
+ Py_DECREF(ret);
+ ret = tmpret;
+ }
+ ret_is_small_unsigned = tmp_is_small_unsigned &&
+ ret_is_small_unsigned;
+ }
+ }
+
+ for (i = 0; i < ndtypes; ++i) {
+ PyArray_Descr *tmp = dtypes[i];
+ /* Combine it with the existing type */
+ if (ret == NULL) {
+ ret = tmp;
+ Py_INCREF(ret);
+ }
+ else {
+ /* Only call promote if the types aren't the same dtype */
+ if (tmp != ret || !PyArray_ISNBO(tmp->byteorder)) {
+ if (ret_is_small_unsigned) {
+ tmpret = promote_types(tmp, ret, 0,
+ ret_is_small_unsigned);
+ if (tmpret == NULL) {
+ Py_DECREF(tmp);
+ Py_DECREF(ret);
+ return NULL;
+ }
+ }
+ else {
+ tmpret = PyArray_PromoteTypes(tmp, ret);
+ }
+ Py_DECREF(ret);
+ ret = tmpret;
+ }
+ }
+ }
+ }
+
+ if (ret == NULL) {
+ PyErr_SetString(PyExc_TypeError,
+ "no arrays or types available to calculate result type");
+ }
+
+ return ret;
}
/*NUMPY_API
@@ -804,12 +1424,18 @@ PyArray_ConvertToCommonType(PyObject *op, int *retn)
}
for (i = 0; i < n; i++) {
+ mps[i] = NULL;
+ }
+
+ for (i = 0; i < n; i++) {
otmp = PySequence_GetItem(op, i);
if (!PyArray_CheckAnyScalar(otmp)) {
newtype = PyArray_DescrFromObject(otmp, intype);
Py_XDECREF(intype);
+ if (newtype == NULL) {
+ goto fail;
+ }
intype = newtype;
- mps[i] = NULL;
intypekind = PyArray_ScalarKind(intype->type_num, NULL);
}
else {
@@ -841,7 +1467,7 @@ PyArray_ConvertToCommonType(PyObject *op, int *retn)
if (!PyArray_CanCoerceScalar(stype->type_num,
intype->type_num,
scalarkind)) {
- newtype = _array_small_type(intype, stype);
+ newtype = PyArray_PromoteTypes(intype, stype);
Py_XDECREF(intype);
intype = newtype;
}
@@ -886,4 +1512,3 @@ PyArray_ConvertToCommonType(PyObject *op, int *retn)
PyDataMem_FREE(mps);
return NULL;
}
-
diff --git a/numpy/core/src/multiarray/convert_datatype.h b/numpy/core/src/multiarray/convert_datatype.h
index 60bdd8274..844cce0c9 100644
--- a/numpy/core/src/multiarray/convert_datatype.h
+++ b/numpy/core/src/multiarray/convert_datatype.h
@@ -1,22 +1,10 @@
#ifndef _NPY_ARRAY_CONVERT_DATATYPE_H_
#define _NPY_ARRAY_CONVERT_DATATYPE_H_
-NPY_NO_EXPORT PyObject *
-PyArray_CastToType(PyArrayObject *mp, PyArray_Descr *at, int fortran);
-
-NPY_NO_EXPORT int
-PyArray_CastTo(PyArrayObject *out, PyArrayObject *mp);
-
NPY_NO_EXPORT PyArray_VectorUnaryFunc *
PyArray_GetCastFunc(PyArray_Descr *descr, int type_num);
NPY_NO_EXPORT int
-PyArray_CanCastSafely(int fromtype, int totype);
-
-NPY_NO_EXPORT Bool
-PyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to);
-
-NPY_NO_EXPORT int
PyArray_ObjectType(PyObject *op, int minimum_type);
NPY_NO_EXPORT PyArrayObject **
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index ecffb0dc1..93a26c1e9 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -17,10 +17,14 @@
#include "ctors.h"
+#include "shape.h"
+
#include "buffer.h"
#include "numpymemoryview.h"
+#include "lowlevel_strided_loops.h"
+
/*
* Reading from a file or a string.
*
@@ -206,13 +210,13 @@ fromfile_skip_separator(FILE **fp, const char *sep, void *NPY_UNUSED(stream_data
* Strides are only added if given (because data is given).
*/
static int
-_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims,
- intp *newstrides, int oldnd)
+_update_descr_and_dimensions(PyArray_Descr **des, npy_intp *newdims,
+ npy_intp *newstrides, int oldnd)
{
PyArray_Descr *old;
int newnd;
int numnew;
- intp *mydim;
+ npy_intp *mydim;
int i;
int tuple;
@@ -236,17 +240,17 @@ _update_descr_and_dimensions(PyArray_Descr **des, intp *newdims,
}
if (tuple) {
for (i = 0; i < numnew; i++) {
- mydim[i] = (intp) PyInt_AsLong(
+ mydim[i] = (npy_intp) PyInt_AsLong(
PyTuple_GET_ITEM(old->subarray->shape, i));
}
}
else {
- mydim[0] = (intp) PyInt_AsLong(old->subarray->shape);
+ mydim[0] = (npy_intp) PyInt_AsLong(old->subarray->shape);
}
if (newstrides) {
- intp tempsize;
- intp *mystrides;
+ npy_intp tempsize;
+ npy_intp *mystrides;
mystrides = newstrides + oldnd;
/* Make new strides -- alwasy C-contiguous */
@@ -263,161 +267,11 @@ _update_descr_and_dimensions(PyArray_Descr **des, intp *newdims,
return newnd;
}
-/*
- * If s is not a list, return 0
- * Otherwise:
- *
- * run object_depth_and_dimension on all the elements
- * and make sure the returned shape and size is the
- * same for each element
- */
-static int
-object_depth_and_dimension(PyObject *s, int max, intp *dims)
-{
- intp *newdims, *test_dims;
- int nd, test_nd;
- int i, islist, istuple;
- intp size;
- PyObject *obj;
-
- islist = PyList_Check(s);
- istuple = PyTuple_Check(s);
- if (!(islist || istuple)) {
- return 0;
- }
-
- size = PySequence_Size(s);
- if (size == 0) {
- return 0;
- }
- if (max < 1) {
- return 0;
- }
- if (max < 2) {
- dims[0] = size;
- return 1;
- }
-
- newdims = PyDimMem_NEW(2*(max - 1));
- test_dims = newdims + (max - 1);
- if (islist) {
- obj = PyList_GET_ITEM(s, 0);
- }
- else {
- obj = PyTuple_GET_ITEM(s, 0);
- }
- nd = object_depth_and_dimension(obj, max - 1, newdims);
-
- for (i = 1; i < size; i++) {
- if (islist) {
- obj = PyList_GET_ITEM(s, i);
- }
- else {
- obj = PyTuple_GET_ITEM(s, i);
- }
- test_nd = object_depth_and_dimension(obj, max-1, test_dims);
-
- if ((nd != test_nd) ||
- (!PyArray_CompareLists(newdims, test_dims, nd))) {
- nd = 0;
- break;
- }
- }
-
- for (i = 1; i <= nd; i++) {
- dims[i] = newdims[i-1];
- }
- dims[0] = size;
- PyDimMem_FREE(newdims);
- return nd + 1;
-}
-
-static void
-_strided_byte_copy(char *dst, intp outstrides, char *src, intp instrides,
- intp N, int elsize)
-{
- intp i, j;
- char *tout = dst;
- char *tin = src;
-
-#define _FAST_MOVE(_type_) \
- for(i=0; i<N; i++) { \
- ((_type_ *)tout)[0] = ((_type_ *)tin)[0]; \
- tin += instrides; \
- tout += outstrides; \
- } \
- return
-
- switch(elsize) {
- case 8:
- _FAST_MOVE(Int64);
- case 4:
- _FAST_MOVE(Int32);
- case 1:
- _FAST_MOVE(Int8);
- case 2:
- _FAST_MOVE(Int16);
- case 16:
- for (i = 0; i < N; i++) {
- ((Int64 *)tout)[0] = ((Int64 *)tin)[0];
- ((Int64 *)tout)[1] = ((Int64 *)tin)[1];
- tin += instrides;
- tout += outstrides;
- }
- return;
- default:
- for(i = 0; i < N; i++) {
- for(j=0; j<elsize; j++) {
- *tout++ = *tin++;
- }
- tin = tin + instrides - elsize;
- tout = tout + outstrides - elsize;
- }
- }
-#undef _FAST_MOVE
-
-}
-
-static void
-_unaligned_strided_byte_move(char *dst, intp outstrides, char *src,
- intp instrides, intp N, int elsize)
-{
- intp i;
- char *tout = dst;
- char *tin = src;
-
-
-#define _MOVE_N_SIZE(size) \
- for(i=0; i<N; i++) { \
- memmove(tout, tin, size); \
- tin += instrides; \
- tout += outstrides; \
- } \
- return
-
- switch(elsize) {
- case 8:
- _MOVE_N_SIZE(8);
- case 4:
- _MOVE_N_SIZE(4);
- case 1:
- _MOVE_N_SIZE(1);
- case 2:
- _MOVE_N_SIZE(2);
- case 16:
- _MOVE_N_SIZE(16);
- default:
- _MOVE_N_SIZE(elsize);
- }
-#undef _MOVE_N_SIZE
-
-}
-
NPY_NO_EXPORT void
-_unaligned_strided_byte_copy(char *dst, intp outstrides, char *src,
- intp instrides, intp N, int elsize)
+_unaligned_strided_byte_copy(char *dst, npy_intp outstrides, char *src,
+ npy_intp instrides, npy_intp N, int elsize)
{
- intp i;
+ npy_intp i;
char *tout = dst;
char *tin = src;
@@ -448,7 +302,7 @@ _unaligned_strided_byte_copy(char *dst, intp outstrides, char *src,
}
NPY_NO_EXPORT void
-_strided_byte_swap(void *p, intp stride, intp n, int size)
+_strided_byte_swap(void *p, npy_intp stride, npy_intp n, int size)
{
char *a, *b, c = 0;
int j, m;
@@ -491,18 +345,18 @@ _strided_byte_swap(void *p, intp stride, intp n, int size)
}
NPY_NO_EXPORT void
-byte_swap_vector(void *p, intp n, int size)
+byte_swap_vector(void *p, npy_intp n, int size)
{
- _strided_byte_swap(p, (intp) size, n, size);
+ _strided_byte_swap(p, (npy_intp) size, n, size);
return;
}
/* If numitems > 1, then dst must be contiguous */
NPY_NO_EXPORT void
-copy_and_swap(void *dst, void *src, int itemsize, intp numitems,
- intp srcstrides, int swap)
+copy_and_swap(void *dst, void *src, int itemsize, npy_intp numitems,
+ npy_intp srcstrides, int swap)
{
- intp i;
+ npy_intp i;
char *s1 = (char *)src;
char *d1 = (char *)dst;
@@ -523,398 +377,139 @@ copy_and_swap(void *dst, void *src, int itemsize, intp numitems,
}
}
-static int
-_copy_from0d(PyArrayObject *dest, PyArrayObject *src, int usecopy, int swap)
+/* Gets a half-open range [start, end) which contains the array data */
+NPY_NO_EXPORT void
+_get_array_memory_extents(PyArrayObject *arr,
+ npy_uintp *out_start, npy_uintp *out_end)
{
- char *aligned = NULL;
- char *sptr;
- intp numcopies, nbytes;
- void (*myfunc)(char *, intp, char *, intp, intp, int);
- int retval = -1;
- NPY_BEGIN_THREADS_DEF;
-
- numcopies = PyArray_SIZE(dest);
- if (numcopies < 1) {
- return 0;
- }
- nbytes = PyArray_ITEMSIZE(src);
-
- if (!PyArray_ISALIGNED(src)) {
- aligned = malloc((size_t)nbytes);
- if (aligned == NULL) {
- PyErr_NoMemory();
- return -1;
- }
- memcpy(aligned, src->data, (size_t) nbytes);
- usecopy = 1;
- sptr = aligned;
- }
- else {
- sptr = src->data;
- }
- if (PyArray_SAFEALIGNEDCOPY(dest)) {
- myfunc = _strided_byte_copy;
- }
- else if (usecopy) {
- myfunc = _unaligned_strided_byte_copy;
- }
- else {
- myfunc = _unaligned_strided_byte_move;
- }
-
- if ((dest->nd < 2) || PyArray_ISONESEGMENT(dest)) {
- char *dptr;
- intp dstride;
-
- dptr = dest->data;
- if (dest->nd == 1) {
- dstride = dest->strides[0];
+ npy_uintp start, end;
+ npy_intp idim, ndim = PyArray_NDIM(arr);
+ npy_intp *dimensions = PyArray_DIMS(arr),
+ *strides = PyArray_STRIDES(arr);
+
+ /* Calculate with a closed range [start, end] */
+ start = end = (npy_uintp)PyArray_DATA(arr);
+ for (idim = 0; idim < ndim; ++idim) {
+ npy_intp stride = strides[idim], dim = dimensions[idim];
+ /* If the array size is zero, return an empty range */
+ if (dim == 0) {
+ *out_start = *out_end = (npy_uintp)PyArray_DATA(arr);
+ return;
}
+ /* Expand either upwards or downwards depending on stride */
else {
- dstride = nbytes;
- }
-
- /* Refcount note: src and dest may have different sizes */
- PyArray_INCREF(src);
- PyArray_XDECREF(dest);
- NPY_BEGIN_THREADS;
- myfunc(dptr, dstride, sptr, 0, numcopies, (int) nbytes);
- if (swap) {
- _strided_byte_swap(dptr, dstride, numcopies, (int) nbytes);
- }
- NPY_END_THREADS;
- PyArray_INCREF(dest);
- PyArray_XDECREF(src);
- }
- else {
- PyArrayIterObject *dit;
- int axis = -1;
-
- dit = (PyArrayIterObject *)
- PyArray_IterAllButAxis((PyObject *)dest, &axis);
- if (dit == NULL) {
- goto finish;
- }
- /* Refcount note: src and dest may have different sizes */
- PyArray_INCREF(src);
- PyArray_XDECREF(dest);
- NPY_BEGIN_THREADS;
- while(dit->index < dit->size) {
- myfunc(dit->dataptr, PyArray_STRIDE(dest, axis), sptr, 0,
- PyArray_DIM(dest, axis), nbytes);
- if (swap) {
- _strided_byte_swap(dit->dataptr, PyArray_STRIDE(dest, axis),
- PyArray_DIM(dest, axis), nbytes);
+ if (stride > 0) {
+ end += stride*(dim-1);
+ }
+ else if (stride < 0) {
+ start += stride*(dim-1);
}
- PyArray_ITER_NEXT(dit);
}
- NPY_END_THREADS;
- PyArray_INCREF(dest);
- PyArray_XDECREF(src);
- Py_DECREF(dit);
}
- retval = 0;
-finish:
- if (aligned != NULL) {
- free(aligned);
- }
- return retval;
+ /* Return a half-open range */
+ *out_start = start;
+ *out_end = end + arr->descr->elsize;
}
-/*
- * Special-case of PyArray_CopyInto when dst is 1-d
- * and contiguous (and aligned).
- * PyArray_CopyInto requires broadcastable arrays while
- * this one is a flattening operation...
- */
+/* Returns 1 if the arrays have overlapping data, 0 otherwise */
NPY_NO_EXPORT int
-_flat_copyinto(PyObject *dst, PyObject *src, NPY_ORDER order)
+_arrays_overlap(PyArrayObject *arr1, PyArrayObject *arr2)
{
- PyArrayIterObject *it;
- PyObject *orig_src;
- void (*myfunc)(char *, intp, char *, intp, intp, int);
- char *dptr;
- int axis;
- int elsize;
- intp nbytes;
- NPY_BEGIN_THREADS_DEF;
-
-
- orig_src = src;
- if (PyArray_NDIM(src) == 0) {
- /* Refcount note: src and dst have the same size */
- PyArray_INCREF((PyArrayObject *)src);
- PyArray_XDECREF((PyArrayObject *)dst);
- NPY_BEGIN_THREADS;
- memcpy(PyArray_BYTES(dst), PyArray_BYTES(src),
- PyArray_ITEMSIZE(src));
- NPY_END_THREADS;
- return 0;
- }
-
- axis = PyArray_NDIM(src)-1;
-
- if (order == PyArray_FORTRANORDER) {
- if (PyArray_NDIM(src) <= 2) {
- axis = 0;
- }
- /* fall back to a more general method */
- else {
- src = PyArray_Transpose((PyArrayObject *)orig_src, NULL);
- }
- }
-
- it = (PyArrayIterObject *)PyArray_IterAllButAxis(src, &axis);
- if (it == NULL) {
- if (src != orig_src) {
- Py_DECREF(src);
- }
- return -1;
- }
-
- if (PyArray_SAFEALIGNEDCOPY(src)) {
- myfunc = _strided_byte_copy;
- }
- else {
- myfunc = _unaligned_strided_byte_copy;
- }
+ npy_uintp start1 = 0, start2 = 0, end1 = 0, end2 = 0;
- dptr = PyArray_BYTES(dst);
- elsize = PyArray_ITEMSIZE(dst);
- nbytes = elsize * PyArray_DIM(src, axis);
+ _get_array_memory_extents(arr1, &start1, &end1);
+ _get_array_memory_extents(arr2, &start2, &end2);
- /* Refcount note: src and dst have the same size */
- PyArray_INCREF((PyArrayObject *)src);
- PyArray_XDECREF((PyArrayObject *)dst);
- NPY_BEGIN_THREADS;
- while(it->index < it->size) {
- myfunc(dptr, elsize, it->dataptr, PyArray_STRIDE(src,axis),
- PyArray_DIM(src,axis), elsize);
- dptr += nbytes;
- PyArray_ITER_NEXT(it);
- }
- NPY_END_THREADS;
-
- if (src != orig_src) {
- Py_DECREF(src);
- }
- Py_DECREF(it);
- return 0;
+ return (start1 < end2) && (start2 < end1);
}
-
-static int
-_copy_from_same_shape(PyArrayObject *dest, PyArrayObject *src,
- void (*myfunc)(char *, intp, char *, intp, intp, int),
- int swap)
-{
- int maxaxis = -1, elsize;
- intp maxdim;
- PyArrayIterObject *dit, *sit;
- NPY_BEGIN_THREADS_DEF;
-
- dit = (PyArrayIterObject *)
- PyArray_IterAllButAxis((PyObject *)dest, &maxaxis);
- sit = (PyArrayIterObject *)
- PyArray_IterAllButAxis((PyObject *)src, &maxaxis);
-
- maxdim = dest->dimensions[maxaxis];
-
- if ((dit == NULL) || (sit == NULL)) {
- Py_XDECREF(dit);
- Py_XDECREF(sit);
- return -1;
- }
- elsize = PyArray_ITEMSIZE(dest);
-
- /* Refcount note: src and dst have the same size */
- PyArray_INCREF(src);
- PyArray_XDECREF(dest);
-
- NPY_BEGIN_THREADS;
- while(dit->index < dit->size) {
- /* strided copy of elsize bytes */
- myfunc(dit->dataptr, dest->strides[maxaxis],
- sit->dataptr, src->strides[maxaxis],
- maxdim, elsize);
- if (swap) {
- _strided_byte_swap(dit->dataptr,
- dest->strides[maxaxis],
- dest->dimensions[maxaxis],
- elsize);
- }
- PyArray_ITER_NEXT(dit);
- PyArray_ITER_NEXT(sit);
- }
- NPY_END_THREADS;
-
- Py_DECREF(sit);
- Py_DECREF(dit);
- return 0;
-}
-
-static int
-_broadcast_copy(PyArrayObject *dest, PyArrayObject *src,
- void (*myfunc)(char *, intp, char *, intp, intp, int),
- int swap)
+/*NUMPY_API
+ * Move the memory of one array into another, allowing for overlapping data.
+ *
+ * This is in general a difficult problem to solve efficiently, because
+ * strides can be negative. Consider "a = np.arange(3); a[::-1] = a", which
+ * previously produced the incorrect [0, 1, 0].
+ *
+ * Instead of trying to be fancy, we simply check for overlap and make
+ * a temporary copy when one exists.
+ *
+ * Returns 0 on success, negative on failure.
+ */
+NPY_NO_EXPORT int
+PyArray_MoveInto(PyArrayObject *dst, PyArrayObject *src)
{
- int elsize;
- PyArrayMultiIterObject *multi;
- int maxaxis; intp maxdim;
- NPY_BEGIN_THREADS_DEF;
-
- elsize = PyArray_ITEMSIZE(dest);
- multi = (PyArrayMultiIterObject *)PyArray_MultiIterNew(2, dest, src);
- if (multi == NULL) {
- return -1;
- }
-
- if (multi->size != PyArray_SIZE(dest)) {
- PyErr_SetString(PyExc_ValueError,
- "array dimensions are not "\
- "compatible for copy");
- Py_DECREF(multi);
- return -1;
- }
-
- maxaxis = PyArray_RemoveSmallest(multi);
- if (maxaxis < 0) {
- /*
- * copy 1 0-d array to another
- * Refcount note: src and dst have the same size
- */
- PyArray_INCREF(src);
- PyArray_XDECREF(dest);
- memcpy(dest->data, src->data, elsize);
- if (swap) {
- byte_swap_vector(dest->data, 1, elsize);
- }
- return 0;
- }
- maxdim = multi->dimensions[maxaxis];
-
/*
- * Increment the source and decrement the destination
- * reference counts
+ * Performance fix for expresions like "a[1000:6000] += x". In this
+ * case, first an in-place add is done, followed by an assignment,
+ * equivalently expressed like this:
+ *
+ * tmp = a[1000:6000] # Calls array_subscript_nice in mapping.c
+ * np.add(tmp, x, tmp)
+ * a[1000:6000] = tmp # Calls array_ass_sub in mapping.c
+ *
+ * In the assignment the underlying data type, shape, strides, and
+ * data pointers are identical, but src != dst because they are separately
+ * generated slices. By detecting this and skipping the redundant
+ * copy of values to themselves, we potentially give a big speed boost.
*
- * Refcount note: src and dest may have different sizes
+ * Note that we don't call EquivTypes, because usually the exact same
+ * dtype object will appear, and we don't want to slow things down
+ * with a complicated comparison. The comparisons are ordered to
+ * try and reject this with as little work as possible.
*/
- PyArray_INCREF(src);
- PyArray_XDECREF(dest);
-
- NPY_BEGIN_THREADS;
- while(multi->index < multi->size) {
- myfunc(multi->iters[0]->dataptr,
- multi->iters[0]->strides[maxaxis],
- multi->iters[1]->dataptr,
- multi->iters[1]->strides[maxaxis],
- maxdim, elsize);
- if (swap) {
- _strided_byte_swap(multi->iters[0]->dataptr,
- multi->iters[0]->strides[maxaxis],
- maxdim, elsize);
- }
- PyArray_MultiIter_NEXT(multi);
- }
- NPY_END_THREADS;
-
- PyArray_INCREF(dest);
- PyArray_XDECREF(src);
-
- Py_DECREF(multi);
- return 0;
-}
-
-/* If destination is not the right type, then src
- will be cast to destination -- this requires
- src and dest to have the same shape
-*/
-
-/* Requires arrays to have broadcastable shapes
-
- The arrays are assumed to have the same number of elements
- They can be different sizes and have different types however.
-*/
-
-static int
-_array_copy_into(PyArrayObject *dest, PyArrayObject *src, int usecopy)
-{
- int swap;
- void (*myfunc)(char *, intp, char *, intp, intp, int);
- int simple;
- int same;
- NPY_BEGIN_THREADS_DEF;
-
-
- if (!PyArray_EquivArrTypes(dest, src)) {
- return PyArray_CastTo(dest, src);
- }
- if (!PyArray_ISWRITEABLE(dest)) {
- PyErr_SetString(PyExc_RuntimeError,
- "cannot write to array");
- return -1;
- }
- same = PyArray_SAMESHAPE(dest, src);
- simple = same && ((PyArray_ISCARRAY_RO(src) && PyArray_ISCARRAY(dest)) ||
- (PyArray_ISFARRAY_RO(src) && PyArray_ISFARRAY(dest)));
-
- if (simple) {
- /* Refcount note: src and dest have the same size */
- PyArray_INCREF(src);
- PyArray_XDECREF(dest);
- NPY_BEGIN_THREADS;
- if (usecopy) {
- memcpy(dest->data, src->data, PyArray_NBYTES(dest));
- }
- else {
- memmove(dest->data, src->data, PyArray_NBYTES(dest));
- }
- NPY_END_THREADS;
+ if (PyArray_DATA(src) == PyArray_DATA(dst) &&
+ PyArray_DESCR(src) == PyArray_DESCR(dst) &&
+ PyArray_NDIM(src) == PyArray_NDIM(dst) &&
+ PyArray_CompareLists(PyArray_DIMS(src),
+ PyArray_DIMS(dst),
+ PyArray_NDIM(src)) &&
+ PyArray_CompareLists(PyArray_STRIDES(src),
+ PyArray_STRIDES(dst),
+ PyArray_NDIM(src))) {
+ /*printf("Redundant copy operation detected\n");*/
return 0;
}
- swap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);
-
- if (src->nd == 0) {
- return _copy_from0d(dest, src, usecopy, swap);
- }
-
- if (PyArray_SAFEALIGNEDCOPY(dest) && PyArray_SAFEALIGNEDCOPY(src)) {
- myfunc = _strided_byte_copy;
- }
- else if (usecopy) {
- myfunc = _unaligned_strided_byte_copy;
- }
- else {
- myfunc = _unaligned_strided_byte_move;
- }
/*
- * Could combine these because _broadcasted_copy would work as well.
- * But, same-shape copying is so common we want to speed it up.
+ * A special case is when there is just one dimension with positive
+ * strides, and we pass that to CopyInto, which correctly handles
+ * it for most cases. It may still incorrectly handle copying of
+ * partially-overlapping data elements, where the data pointer was offset
+ * by a fraction of the element size.
*/
- if (same) {
- return _copy_from_same_shape(dest, src, myfunc, swap);
+ if ((PyArray_NDIM(dst) == 1 &&
+ PyArray_NDIM(src) == 1 &&
+ PyArray_STRIDE(dst, 0) > 0 &&
+ PyArray_STRIDE(src, 0) > 0) ||
+ !_arrays_overlap(dst, src)) {
+ return PyArray_CopyInto(dst, src);
}
else {
- return _broadcast_copy(dest, src, myfunc, swap);
- }
-}
+ PyArrayObject *tmp;
+ int ret;
-/*NUMPY_API
- * Move the memory of one array into another.
- */
-NPY_NO_EXPORT int
-PyArray_MoveInto(PyArrayObject *dest, PyArrayObject *src)
-{
- return _array_copy_into(dest, src, 0);
+ /*
+ * Allocate a temporary copy array.
+ */
+ tmp = (PyArrayObject *)PyArray_NewLikeArray(dst, NPY_KEEPORDER, NULL);
+ if (tmp == NULL) {
+ return -1;
+ }
+ ret = PyArray_CopyInto(tmp, src);
+ if (ret == 0) {
+ ret = PyArray_CopyInto(dst, tmp);
+ }
+ Py_DECREF(tmp);
+ return ret;
+ }
}
/* adapted from Numarray */
static int
-setArrayFromSequence(PyArrayObject *a, PyObject *s, int dim, intp offset)
+setArrayFromSequence(PyArrayObject *a, PyObject *s, int dim, npy_intp offset)
{
Py_ssize_t i, slen;
int res = -1;
@@ -935,18 +530,25 @@ setArrayFromSequence(PyArrayObject *a, PyObject *s, int dim, intp offset)
*/
/* This will DECREF(s) if replaced */
s = PyArray_EnsureArray(s);
+ if (s == NULL) {
+ goto fail;
+ }
}
if (dim > a->nd) {
PyErr_Format(PyExc_ValueError,
- "setArrayFromSequence: sequence/array dimensions mismatch.");
+ "setArrayFromSequence: sequence/array dimensions mismatch.");
goto fail;
}
slen = PySequence_Length(s);
+ if (slen < 0) {
+ goto fail;
+ }
if (slen != a->dimensions[dim]) {
PyErr_Format(PyExc_ValueError,
- "setArrayFromSequence: sequence/array shape mismatch.");
+ "cannot copy sequence with size %d to array axis "
+ "with dimension %d", (int)slen, (int)a->dimensions[dim]);
goto fail;
}
@@ -973,8 +575,8 @@ setArrayFromSequence(PyArrayObject *a, PyObject *s, int dim, intp offset)
return res;
}
-static int
-Assign_Array(PyArrayObject *self, PyObject *v)
+NPY_NO_EXPORT int
+PyArray_AssignFromSequence(PyArrayObject *self, PyObject *v)
{
if (!PySequence_Check(v)) {
PyErr_SetString(PyExc_ValueError,
@@ -990,376 +592,312 @@ Assign_Array(PyArrayObject *self, PyObject *v)
}
/*
- * "Array Scalars don't call this code"
- * steals reference to typecode -- no NULL
+ * The rest of this code is to build the right kind of array
+ * from a python object.
*/
-static PyObject *
-Array_FromPyScalar(PyObject *op, PyArray_Descr *typecode)
-{
- PyArrayObject *ret;
- int itemsize;
- int type;
- itemsize = typecode->elsize;
- type = typecode->type_num;
+static int
+discover_itemsize(PyObject *s, int nd, int *itemsize)
+{
+ int n, r, i;
- if (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {
- itemsize = PyObject_Length(op);
- if (type == PyArray_UNICODE) {
- itemsize *= 4;
- }
- if (itemsize != typecode->elsize) {
- PyArray_DESCR_REPLACE(typecode);
- typecode->elsize = itemsize;
- }
+ if (PyArray_Check(s)) {
+ *itemsize = MAX(*itemsize, PyArray_ITEMSIZE(s));
+ return 0;
}
- ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, typecode,
- 0, NULL,
- NULL, NULL, 0, NULL);
- if (ret == NULL) {
- return NULL;
- }
- if (ret->nd > 0) {
- PyErr_SetString(PyExc_ValueError,
- "shape-mismatch on array construction");
- Py_DECREF(ret);
- return NULL;
- }
+ if ((nd == 0) || PyString_Check(s) ||
+#if defined(NPY_PY3K)
+ PyMemoryView_Check(s) ||
+#else
+ PyBuffer_Check(s) ||
+#endif
+ PyUnicode_Check(s)) {
- ret->descr->f->setitem(op, ret->data, ret);
- if (PyErr_Occurred()) {
- Py_DECREF(ret);
- return NULL;
- }
- else {
- return (PyObject *)ret;
+ /* If an object has no length, leave it be */
+ n = PyObject_Length(s);
+ if (n == -1) {
+ PyErr_Clear();
+ }
+ else {
+ *itemsize = MAX(*itemsize, n);
+ }
+ return 0;
}
-}
+ n = PySequence_Length(s);
+ for (i = 0; i < n; i++) {
+ PyObject *e = PySequence_GetItem(s,i);
-static PyObject *
-ObjectArray_FromNestedList(PyObject *s, PyArray_Descr *typecode, int fortran)
-{
- int nd;
- intp d[MAX_DIMS];
- PyArrayObject *r;
+ if (e == NULL) {
+ return -1;
+ }
- /* Get the depth and the number of dimensions */
- nd = object_depth_and_dimension(s, MAX_DIMS, d);
- if (nd < 0) {
- return NULL;
- }
- if (nd == 0) {
- return Array_FromPyScalar(s, typecode);
- }
- r = (PyArrayObject*)PyArray_NewFromDescr(&PyArray_Type, typecode,
- nd, d,
- NULL, NULL,
- fortran, NULL);
- if (!r) {
- return NULL;
- }
- if(Assign_Array(r,s) == -1) {
- Py_DECREF(r);
- return NULL;
+ r = discover_itemsize(e,nd-1,itemsize);
+ Py_DECREF(e);
+ if (r == -1) {
+ return -1;
+ }
}
- return (PyObject*)r;
+
+ return 0;
}
/*
- * The rest of this code is to build the right kind of array
- * from a python object.
+ * Take an arbitrary object and discover how many dimensions it
+ * has, filling in the dimensions as we go.
*/
-
static int
-discover_depth(PyObject *s, int max, int stop_at_string, int stop_at_tuple)
+discover_dimensions(PyObject *s, int *maxndim, npy_intp *d, int check_it,
+ int stop_at_string, int stop_at_tuple,
+ int *out_is_object)
{
- int d = 0;
PyObject *e;
+ int r, n, i;
#if PY_VERSION_HEX >= 0x02060000
Py_buffer buffer_view;
#endif
- if(max < 1) {
- return -1;
- }
- if(!PySequence_Check(s) ||
-#if defined(NPY_PY3K)
- /* FIXME: XXX -- what is the correct thing to do here? */
-#else
- PyInstance_Check(s) ||
-#endif
- PySequence_Length(s) < 0) {
- PyErr_Clear();
+ if (*maxndim == 0) {
return 0;
}
+
+ /* s is an Array */
if (PyArray_Check(s)) {
- return PyArray_NDIM(s);
+ if (PyArray_NDIM(s) < *maxndim) {
+ *maxndim = PyArray_NDIM(s);
+ }
+
+ for (i=0; i<*maxndim; i++) {
+ d[i] = PyArray_DIM(s,i);
+ }
+ return 0;
}
+
+ /* s is a Scalar */
if (PyArray_IsScalar(s, Generic)) {
+ *maxndim = 0;
return 0;
}
+
+ /* s is not a Sequence */
+ if (!PySequence_Check(s) ||
+#if defined(NPY_PY3K)
+ /* FIXME: XXX -- what is the correct thing to do here? */
+#else
+ PyInstance_Check(s) ||
+#endif
+ PySequence_Length(s) < 0) {
+ *maxndim = 0;
+ PyErr_Clear();
+ return 0;
+ }
+
+ /* s is a String */
if (PyString_Check(s) ||
#if defined(NPY_PY3K)
#else
- PyBuffer_Check(s) ||
+ PyBuffer_Check(s) ||
#endif
- PyUnicode_Check(s)) {
- return stop_at_string ? 0:1;
+ PyUnicode_Check(s)) {
+ if (stop_at_string) {
+ *maxndim = 0;
+ }
+ else {
+ d[0] = PySequence_Length(s);
+ *maxndim = 1;
+ }
+ return 0;
}
+
+ /* s is a Tuple, but tuples aren't expanded */
if (stop_at_tuple && PyTuple_Check(s)) {
+ *maxndim = 0;
return 0;
}
+
+ /* s is a PEP 3118 buffer */
#if PY_VERSION_HEX >= 0x02060000
/* PEP 3118 buffer interface */
memset(&buffer_view, 0, sizeof(Py_buffer));
if (PyObject_GetBuffer(s, &buffer_view, PyBUF_STRIDES) == 0 ||
PyObject_GetBuffer(s, &buffer_view, PyBUF_ND) == 0) {
- d = buffer_view.ndim;
+ int nd = buffer_view.ndim;
+ if (nd < *maxndim) {
+ *maxndim = nd;
+ }
+ for (i=0; i<*maxndim; i++) {
+ d[i] = buffer_view.shape[i];
+ }
PyBuffer_Release(&buffer_view);
- return d;
+ return 0;
}
else if (PyObject_GetBuffer(s, &buffer_view, PyBUF_SIMPLE) == 0) {
+ d[0] = buffer_view.len;
+ *maxndim = 1;
PyBuffer_Release(&buffer_view);
- return 1;
+ return 0;
}
else {
PyErr_Clear();
}
#endif
+
+ /* s has the __array_struct__ interface */
if ((e = PyObject_GetAttrString(s, "__array_struct__")) != NULL) {
- d = -1;
+ int nd = -1;
if (NpyCapsule_Check(e)) {
PyArrayInterface *inter;
inter = (PyArrayInterface *)NpyCapsule_AsVoidPtr(e);
if (inter->two == 2) {
- d = inter->nd;
+ nd = inter->nd;
+ if (nd >= 0) {
+ if (nd < *maxndim) {
+ *maxndim = nd;
+ }
+ for (i=0; i<*maxndim; i++) {
+ d[i] = inter->shape[i];
+ }
+ }
}
}
Py_DECREF(e);
- if (d > -1) {
- return d;
+ if (nd >= 0) {
+ return 0;
}
}
else {
PyErr_Clear();
}
- if ((e=PyObject_GetAttrString(s, "__array_interface__")) != NULL) {
- d = -1;
+
+ /* s has the __array_interface__ interface */
+ if ((e = PyObject_GetAttrString(s, "__array_interface__")) != NULL) {
+ int nd = -1;
if (PyDict_Check(e)) {
PyObject *new;
new = PyDict_GetItemString(e, "shape");
if (new && PyTuple_Check(new)) {
- d = PyTuple_GET_SIZE(new);
+ nd = PyTuple_GET_SIZE(new);
+ if (nd < *maxndim) {
+ *maxndim = nd;
+ }
+ for (i=0; i<*maxndim; i++) {
+#if (PY_VERSION_HEX >= 0x02050000)
+ d[i] = PyInt_AsSsize_t(PyTuple_GET_ITEM(new, i));
+#else
+ d[i] = PyInt_AsLong(PyTuple_GET_ITEM(new, i));
+#endif
+ if (d[i] < 0) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Invalid shape in __array_interface__");
+ Py_DECREF(e);
+ return -1;
+ }
+ }
}
}
Py_DECREF(e);
- if (d>-1) {
- return d;
+ if (nd >= 0) {
+ return 0;
}
}
- else PyErr_Clear();
-
- if (PySequence_Length(s) == 0) {
- return 1;
- }
- if ((e=PySequence_GetItem(s,0)) == NULL) {
- return -1;
- }
- if (e != s) {
- d = discover_depth(e, max-1, stop_at_string, stop_at_tuple);
- if (d >= 0) {
- d++;
- }
+ else {
+ PyErr_Clear();
}
- Py_DECREF(e);
- return d;
-}
-static int
-discover_itemsize(PyObject *s, int nd, int *itemsize)
-{
- int n, r, i;
- PyObject *e;
+ n = PySequence_Size(s);
- if (PyArray_Check(s)) {
- *itemsize = MAX(*itemsize, PyArray_ITEMSIZE(s));
- return 0;
+ if (n < 0) {
+ return -1;
}
- n = PyObject_Length(s);
- if ((nd == 0) || PyString_Check(s) ||
-#if defined(NPY_PY3K)
- PyMemoryView_Check(s) ||
-#else
- PyBuffer_Check(s) ||
-#endif
- PyUnicode_Check(s)) {
+ d[0] = n;
- *itemsize = MAX(*itemsize, n);
+ /* 1-dimensional sequence */
+ if (n == 0 || *maxndim == 1) {
+ *maxndim = 1;
return 0;
}
- for (i = 0; i < n; i++) {
- if ((e = PySequence_GetItem(s,i))==NULL) {
- return -1;
- }
- r = discover_itemsize(e,nd-1,itemsize);
- Py_DECREF(e);
- if (r == -1) {
- return -1;
- }
- }
- return 0;
-}
-
-/*
- * Take an arbitrary object known to represent
- * an array of ndim nd, and determine the size in each dimension
- */
-static int
-discover_dimensions(PyObject *s, int nd, intp *d, int check_it)
-{
- PyObject *e;
- int r, n, i, n_lower;
-
+ else {
+ npy_intp dtmp[NPY_MAXDIMS];
+ int j, maxndim_m1 = *maxndim - 1;
- if (PyArray_Check(s)) {
- /*
- * XXXX: we handle the case of scalar arrays (0 dimensions) separately.
- * This is an hack, the function discover_dimensions needs to be
- * improved.
- */
- if (PyArray_NDIM(s) == 0) {
- d[0] = 0;
- } else {
- for (i=0; i<nd; i++) {
- d[i] = PyArray_DIM(s,i);
+ if ((e = PySequence_GetItem(s, 0)) == NULL) {
+ /*
+ * PySequence_Check detects whether an old type object is a
+ * sequence by the presence of the __getitem__ attribute, and
+ * for new type objects that aren't dictionaries by the
+ * presence of the __len__ attribute as well. In either case it
+ * is possible to have an object that tests as a sequence but
+ * doesn't behave as a sequence and consequently, the
+ * PySequence_GetItem call can fail. When that happens and the
+ * object looks like a dictionary, we truncate the dimensions
+ * and set the object creation flag, otherwise we pass the
+ * error back up the call chain.
+ */
+ if (PyErr_ExceptionMatches(PyExc_KeyError)) {
+ PyErr_Clear();
+ *maxndim = 0;
+ *out_is_object = 1;
+ return 0;
+ }
+ else {
+ return -1;
}
}
- return 0;
- }
- n = PyObject_Length(s);
- *d = n;
- if (*d < 0) {
- return -1;
- }
- if (nd <= 1) {
- return 0;
- }
- n_lower = 0;
- for(i = 0; i < n; i++) {
- if ((e = PySequence_GetItem(s,i)) == NULL) {
- return -1;
- }
- r = discover_dimensions(e, nd - 1, d + 1, check_it);
+ r = discover_dimensions(e, &maxndim_m1, d + 1, check_it,
+ stop_at_string, stop_at_tuple,
+ out_is_object);
Py_DECREF(e);
+ if (r < 0) {
+ return r;
+ }
+
+ /* For the dimension truncation check below */
+ *maxndim = maxndim_m1 + 1;
+ for (i = 1; i < n; ++i) {
+ /* Get the dimensions of the first item */
+ if ((e = PySequence_GetItem(s, i)) == NULL) {
+ /* see comment above */
+ if (PyErr_ExceptionMatches(PyExc_KeyError)) {
+ PyErr_Clear();
+ *maxndim = 0;
+ *out_is_object = 1;
+ return 0;
+ }
+ else {
+ return -1;
+ }
+ }
+ r = discover_dimensions(e, &maxndim_m1, dtmp, check_it,
+ stop_at_string, stop_at_tuple,
+ out_is_object);
+ Py_DECREF(e);
+ if (r < 0) {
+ return r;
+ }
- if (r == -1) {
- return -1;
- }
- if (check_it && n_lower != 0 && n_lower != d[1]) {
- PyErr_SetString(PyExc_ValueError,
- "inconsistent shape in sequence");
- return -1;
+ /* Reduce max_ndim_m1 to just items which match */
+ for (j = 0; j < maxndim_m1; ++j) {
+ if (dtmp[j] != d[j+1]) {
+ maxndim_m1 = j;
+ break;
+ }
+ }
}
- if (d[1] > n_lower) {
- n_lower = d[1];
+ /*
+ * If the dimensions are truncated, need to produce
+ * an object array.
+ */
+ if (maxndim_m1 + 1 < *maxndim) {
+ *out_is_object = 1;
+ *maxndim = maxndim_m1 + 1;
}
}
- d[1] = n_lower;
return 0;
}
-/*
- * isobject means that we are constructing an
- * object array on-purpose with a nested list.
- * Only a list is interpreted as a sequence with these rules
- * steals reference to typecode
- */
-static PyObject *
-Array_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran,
- int min_depth, int max_depth)
-{
- PyArrayObject *r;
- int nd;
- int err;
- intp d[MAX_DIMS];
- int stop_at_string;
- int stop_at_tuple;
- int check_it;
- int type = typecode->type_num;
- int itemsize = typecode->elsize;
-
- check_it = (typecode->type != PyArray_CHARLTR);
- stop_at_string = (type != PyArray_STRING) ||
- (typecode->type == PyArray_STRINGLTR);
- stop_at_tuple = (type == PyArray_VOID && (typecode->names
- || typecode->subarray));
-
- nd = discover_depth(s, MAX_DIMS + 1, stop_at_string, stop_at_tuple);
- if (nd == 0) {
- return Array_FromPyScalar(s, typecode);
- }
- else if (nd < 0) {
- PyErr_SetString(PyExc_ValueError,
- "invalid input sequence");
- goto fail;
- }
- if (max_depth && PyTypeNum_ISOBJECT(type) && (nd > max_depth)) {
- nd = max_depth;
- }
- if ((max_depth && nd > max_depth) || (min_depth && nd < min_depth)) {
- PyErr_SetString(PyExc_ValueError,
- "invalid number of dimensions");
- goto fail;
- }
-
- err = discover_dimensions(s, nd, d, check_it);
- if (err == -1) {
- goto fail;
- }
- if (typecode->type == PyArray_CHARLTR && nd > 0 && d[nd - 1] == 1) {
- nd = nd - 1;
- }
-
- if (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {
- err = discover_itemsize(s, nd, &itemsize);
- if (err == -1) {
- goto fail;
- }
- if (type == PyArray_UNICODE) {
- itemsize *= 4;
- }
- }
- if (itemsize != typecode->elsize) {
- PyArray_DESCR_REPLACE(typecode);
- typecode->elsize = itemsize;
- }
-
- r = (PyArrayObject*)PyArray_NewFromDescr(&PyArray_Type, typecode,
- nd, d,
- NULL, NULL,
- fortran, NULL);
- if (!r) {
- return NULL;
- }
-
- err = Assign_Array(r,s);
- if (err == -1) {
- Py_DECREF(r);
- return NULL;
- }
- return (PyObject*)r;
-
- fail:
- Py_DECREF(typecode);
- return NULL;
-}
-
-
-
/*NUMPY_API
* Generic new array creation routine.
*
@@ -1367,23 +905,23 @@ Array_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran,
*/
NPY_NO_EXPORT PyObject *
PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
- intp *dims, intp *strides, void *data,
+ npy_intp *dims, npy_intp *strides, void *data,
int flags, PyObject *obj)
{
PyArrayObject *self;
int i;
size_t sd;
- intp largest;
- intp size;
+ npy_intp largest;
+ npy_intp size;
if (descr->subarray) {
PyObject *ret;
- intp newdims[2*MAX_DIMS];
- intp *newstrides = NULL;
- memcpy(newdims, dims, nd*sizeof(intp));
+ npy_intp newdims[2*NPY_MAXDIMS];
+ npy_intp *newstrides = NULL;
+ memcpy(newdims, dims, nd*sizeof(npy_intp));
if (strides) {
- newstrides = newdims + MAX_DIMS;
- memcpy(newstrides, strides, nd*sizeof(intp));
+ newstrides = newdims + NPY_MAXDIMS;
+ memcpy(newstrides, strides, nd*sizeof(npy_intp));
}
nd =_update_descr_and_dimensions(&descr, newdims,
newstrides, nd);
@@ -1392,15 +930,11 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
data, flags, obj);
return ret;
}
- if (nd < 0) {
- PyErr_SetString(PyExc_ValueError,
- "number of dimensions must be >=0");
- Py_DECREF(descr);
- return NULL;
- }
- if (nd > MAX_DIMS) {
+
+ if ((unsigned int)nd > (unsigned int)NPY_MAXDIMS) {
PyErr_Format(PyExc_ValueError,
- "maximum number of dimensions is %d", MAX_DIMS);
+ "number of dimensions must be within [0, %d]",
+ NPY_MAXDIMS);
Py_DECREF(descr);
return NULL;
}
@@ -1410,23 +944,22 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
sd = (size_t) descr->elsize;
if (sd == 0) {
if (!PyDataType_ISSTRING(descr)) {
- PyErr_SetString(PyExc_ValueError, "Empty data-type");
+ PyErr_SetString(PyExc_TypeError, "Empty data-type");
Py_DECREF(descr);
return NULL;
}
PyArray_DESCR_REPLACE(descr);
if (descr->type_num == NPY_STRING) {
- descr->elsize = 1;
+ sd = descr->elsize = 1;
}
else {
- descr->elsize = sizeof(PyArray_UCS4);
+ sd = descr->elsize = sizeof(PyArray_UCS4);
}
- sd = descr->elsize;
}
largest = NPY_MAX_INTP / sd;
for (i = 0; i < nd; i++) {
- intp dim = dims[i];
+ npy_intp dim = dims[i];
if (dim == 0) {
/*
@@ -1435,6 +968,7 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
*/
continue;
}
+
if (dim < 0) {
PyErr_SetString(PyExc_ValueError,
"negative dimensions " \
@@ -1442,14 +976,15 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
Py_DECREF(descr);
return NULL;
}
- if (dim > largest) {
+
+ size *= dim;
+
+ if (size > largest) {
PyErr_SetString(PyExc_ValueError,
"array is too big.");
Py_DECREF(descr);
return NULL;
}
- size *= dim;
- largest /= dim;
}
self = (PyArrayObject *) subtype->tp_alloc(subtype, 0);
@@ -1463,15 +998,15 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
if (data == NULL) {
self->flags = DEFAULT;
if (flags) {
- self->flags |= FORTRAN;
+ self->flags |= NPY_F_CONTIGUOUS;
if (nd > 1) {
- self->flags &= ~CONTIGUOUS;
+ self->flags &= ~NPY_C_CONTIGUOUS;
}
- flags = FORTRAN;
+ flags = NPY_F_CONTIGUOUS;
}
}
else {
- self->flags = (flags & ~UPDATEIFCOPY);
+ self->flags = (flags & ~NPY_UPDATEIFCOPY);
}
self->descr = descr;
self->base = (PyObject *)NULL;
@@ -1484,7 +1019,7 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
goto fail;
}
self->strides = self->dimensions + nd;
- memcpy(self->dimensions, dims, sizeof(intp)*nd);
+ memcpy(self->dimensions, dims, sizeof(npy_intp)*nd);
if (strides == NULL) { /* fill it in */
sd = _array_fill_strides(self->strides, dims, nd, sd,
flags, &(self->flags));
@@ -1494,12 +1029,13 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
* we allow strides even when we create
* the memory, but be careful with this...
*/
- memcpy(self->strides, strides, sizeof(intp)*nd);
+ memcpy(self->strides, strides, sizeof(npy_intp)*nd);
sd *= size;
}
}
else {
self->dimensions = self->strides = NULL;
+ self->flags |= NPY_F_CONTIGUOUS;
}
if (data == NULL) {
@@ -1512,7 +1048,8 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
if (sd == 0) {
sd = descr->elsize;
}
- if ((data = PyDataMem_NEW(sd)) == NULL) {
+ data = PyDataMem_NEW(sd);
+ if (data == NULL) {
PyErr_NoMemory();
goto fail;
}
@@ -1589,11 +1126,99 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
}
/*NUMPY_API
+ * Creates a new array with the same shape as the provided one,
+ * with possible memory layout order and data type changes.
+ *
+ * prototype - The array the new one should be like.
+ * order - NPY_CORDER - C-contiguous result.
+ * NPY_FORTRANORDER - Fortran-contiguous result.
+ * NPY_ANYORDER - Fortran if prototype is Fortran, C otherwise.
+ * NPY_KEEPORDER - Keeps the axis ordering of prototype.
+ * dtype - If not NULL, overrides the data type of the result.
+ *
+ * NOTE: If dtype is not NULL, steals the dtype reference.
+ */
+NPY_NO_EXPORT PyObject *
+PyArray_NewLikeArray(PyArrayObject *prototype, NPY_ORDER order,
+ PyArray_Descr *dtype)
+{
+ PyObject *ret = NULL;
+ int ndim = PyArray_NDIM(prototype);
+
+ /* If no override data type, use the one from the prototype */
+ if (dtype == NULL) {
+ dtype = PyArray_DESCR(prototype);
+ Py_INCREF(dtype);
+ }
+
+ /* Handle ANYORDER and simple KEEPORDER cases */
+ switch (order) {
+ case NPY_ANYORDER:
+ order = PyArray_ISFORTRAN(prototype) ?
+ NPY_FORTRANORDER : NPY_CORDER;
+ break;
+ case NPY_KEEPORDER:
+ if (PyArray_IS_C_CONTIGUOUS(prototype) || ndim <= 1) {
+ order = NPY_CORDER;
+ break;
+ }
+ else if (PyArray_IS_F_CONTIGUOUS(prototype)) {
+ order = NPY_FORTRANORDER;
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+
+ /* If it's not KEEPORDER, this is simple */
+ if (order != NPY_KEEPORDER) {
+ ret = PyArray_NewFromDescr(Py_TYPE(prototype),
+ dtype,
+ ndim,
+ PyArray_DIMS(prototype),
+ NULL,
+ NULL,
+ order,
+ (PyObject *)prototype);
+ }
+ /* KEEPORDER needs some analysis of the strides */
+ else {
+ npy_intp strides[NPY_MAXDIMS], stride;
+ npy_intp *shape = PyArray_DIMS(prototype);
+ _npy_stride_sort_item strideperm[NPY_MAXDIMS];
+ int i;
+
+ PyArray_CreateSortedStridePerm(prototype, strideperm);
+
+ /* Build the new strides */
+ stride = dtype->elsize;
+ for (i = ndim-1; i >= 0; --i) {
+ npy_intp i_perm = strideperm[i].perm;
+ strides[i_perm] = stride;
+ stride *= shape[i_perm];
+ }
+
+ /* Finally, allocate the array */
+ ret = PyArray_NewFromDescr(Py_TYPE(prototype),
+ dtype,
+ ndim,
+ shape,
+ strides,
+ NULL,
+ 0,
+ (PyObject *)prototype);
+ }
+
+ return ret;
+}
+
+/*NUMPY_API
* Generic new array creation routine.
*/
NPY_NO_EXPORT PyObject *
-PyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,
- intp *strides, void *data, int itemsize, int flags,
+PyArray_New(PyTypeObject *subtype, int nd, npy_intp *dims, int type_num,
+ npy_intp *strides, void *data, int itemsize, int flags,
PyObject *obj)
{
PyArray_Descr *descr;
@@ -1640,7 +1265,7 @@ _array_from_buffer_3118(PyObject *obj, PyObject **out)
view = PyMemoryView_GET_BUFFER(memoryview);
if (view->format != NULL) {
- descr = (PyObject*)_descriptor_from_pep3118_format(view->format);
+ descr = _descriptor_from_pep3118_format(view->format);
if (descr == NULL) {
PyObject *msg;
msg = PyBytes_FromFormat("Invalid PEP 3118 format string: '%s'",
@@ -1714,160 +1339,460 @@ fail:
#endif
}
-
/*NUMPY_API
- * Does not check for ENSURECOPY and NOTSWAPPED in flags
- * Steals a reference to newtype --- which can be NULL
+ * Retrieves the array parameters for viewing/converting an arbitrary
+ * PyObject* to a NumPy array. This allows the "innate type and shape"
+ * of Python list-of-lists to be discovered without
+ * actually converting to an array.
+ *
+ * In some cases, such as structured arrays and the __array__ interface,
+ * a data type needs to be used to make sense of the object. When
+ * this is needed, provide a Descr for 'requested_dtype', otherwise
+ * provide NULL. This reference is not stolen. Also, if the requested
+ * dtype doesn't modify the interpretation of the input, out_dtype will
+ * still get the "innate" dtype of the object, not the dtype passed
+ * in 'requested_dtype'.
+ *
+ * If writing to the value in 'op' is desired, set the boolean
+ * 'writeable' to 1. This raises an error when 'op' is a scalar, list
+ * of lists, or other non-writeable 'op'.
+ *
+ * Result: When success (0 return value) is returned, either out_arr
+ * is filled with a non-NULL PyArrayObject and
+ * the rest of the parameters are untouched, or out_arr is
+ * filled with NULL, and the rest of the parameters are
+ * filled.
+ *
+ * Typical usage:
+ *
+ * PyArrayObject *arr = NULL;
+ * PyArray_Descr *dtype = NULL;
+ * int ndim = 0;
+ * npy_intp dims[NPY_MAXDIMS];
+ *
+ * if (PyArray_GetArrayParamsFromObject(op, NULL, 1, &dtype,
+ * &ndim, &dims, &arr, NULL) < 0) {
+ * return NULL;
+ * }
+ * if (arr == NULL) {
+ * ... validate/change dtype, validate flags, ndim, etc ...
+ * // Could make custom strides here too
+ * arr = PyArray_NewFromDescr(&PyArray_Type, dtype, ndim,
+ * dims, NULL,
+ * fortran ? NPY_F_CONTIGUOUS : 0,
+ * NULL);
+ * if (arr == NULL) {
+ * return NULL;
+ * }
+ * if (PyArray_CopyObject(arr, op) < 0) {
+ * Py_DECREF(arr);
+ * return NULL;
+ * }
+ * }
+ * else {
+ * ... in this case the other parameters weren't filled, just
+ * validate and possibly copy arr itself ...
+ * }
+ * ... use arr ...
*/
-NPY_NO_EXPORT PyObject *
-PyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,
- int max_depth, int flags, PyObject *context)
+NPY_NO_EXPORT int
+PyArray_GetArrayParamsFromObject(PyObject *op,
+ PyArray_Descr *requested_dtype,
+ npy_bool writeable,
+ PyArray_Descr **out_dtype,
+ int *out_ndim, npy_intp *out_dims,
+ PyArrayObject **out_arr, PyObject *context)
{
- /*
- * This is the main code to make a NumPy array from a Python
- * Object. It is called from lot's of different places which
- * is why there are so many checks. The comments try to
- * explain some of the checks.
- */
- PyObject *r = NULL;
- int seq = FALSE;
+ PyObject *tmp;
- /*
- * Is input object already an array?
- * This is where the flags are used
- */
+ /* If op is an array */
if (PyArray_Check(op)) {
- r = PyArray_FromArray((PyArrayObject *)op, newtype, flags);
+ if (writeable && !PyArray_ISWRITEABLE((PyArrayObject *)op)) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "cannot write to array");
+ return -1;
+ }
+ Py_INCREF(op);
+ *out_arr = (PyArrayObject *)op;
+ return 0;
}
- else if (PyArray_IsScalar(op, Generic)) {
- if (flags & UPDATEIFCOPY) {
- goto err;
+
+ /* If op is a NumPy scalar */
+ if (PyArray_IsScalar(op, Generic)) {
+ if (writeable) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "cannot write to scalar");
+ return -1;
}
- r = PyArray_FromScalar(op, newtype);
+ *out_dtype = PyArray_DescrFromScalar(op);
+ if (*out_dtype == NULL) {
+ return -1;
+ }
+ *out_ndim = 0;
+ *out_arr = NULL;
+ return 0;
}
- else if (newtype == NULL &&
- (newtype = _array_find_python_scalar_type(op))) {
- if (flags & UPDATEIFCOPY) {
- goto err;
+
+ /* If op is a Python scalar */
+ *out_dtype = _array_find_python_scalar_type(op);
+ if (*out_dtype != NULL) {
+ if (writeable) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "cannot write to scalar");
+ Py_DECREF(*out_dtype);
+ return -1;
}
- r = Array_FromPyScalar(op, newtype);
+ *out_ndim = 0;
+ *out_arr = NULL;
+ return 0;
}
- else if (!PyBytes_Check(op) && !PyUnicode_Check(op) &&
- _array_from_buffer_3118(op, &r) == 0) {
- /* PEP 3118 buffer -- but don't accept Bytes objects here */
- PyObject *new;
- if (newtype != NULL || flags != 0) {
- new = PyArray_FromArray((PyArrayObject *)r, newtype, flags);
- Py_DECREF(r);
- r = new;
+
+ /* If op supports the PEP 3118 buffer interface */
+ if (!PyBytes_Check(op) && !PyUnicode_Check(op) &&
+ _array_from_buffer_3118(op, (PyObject **)out_arr) == 0) {
+ if (writeable && !PyArray_ISWRITEABLE(*out_arr)) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "cannot write to PEP 3118 buffer");
+ Py_DECREF(*out_arr);
+ return -1;
}
+ return (*out_arr) == NULL ? -1 : 0;
}
- else if (PyArray_HasArrayInterfaceType(op, newtype, context, r)) {
- PyObject *new;
- if (r == NULL) {
- Py_XDECREF(newtype);
- return NULL;
+
+ /* If op supports the __array_struct__ or __array_interface__ interface */
+ tmp = PyArray_FromStructInterface(op);
+ if (tmp == Py_NotImplemented) {
+ tmp = PyArray_FromInterface(op);
+ }
+ if (tmp != Py_NotImplemented) {
+ if (writeable && !PyArray_ISWRITEABLE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "cannot write to array interface object");
+ Py_DECREF(tmp);
+ return -1;
}
- if (newtype != NULL || flags != 0) {
- new = PyArray_FromArray((PyArrayObject *)r, newtype, flags);
- Py_DECREF(r);
- r = new;
+ *out_arr = (PyArrayObject *)tmp;
+ return (*out_arr) == NULL ? -1 : 0;
+ }
+
+ /*
+ * If op supplies the __array__ function.
+ * The documentation says this should produce a copy, so
+ * we skip this method if writeable is true, because the intent
+ * of writeable is to modify the operand.
+ * XXX: If the implementation is wrong, and/or if actual
+ * usage requires this behave differently,
+ * this should be changed!
+ */
+ if (!writeable) {
+ tmp = PyArray_FromArrayAttr(op, requested_dtype, context);
+ if (tmp != Py_NotImplemented) {
+ if (writeable && !PyArray_ISWRITEABLE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "cannot write to array interface object");
+ Py_DECREF(tmp);
+ return -1;
+ }
+ *out_arr = (PyArrayObject *)tmp;
+ return (*out_arr) == NULL ? -1 : 0;
}
}
- else {
- int isobject = 0;
- if (flags & UPDATEIFCOPY) {
- goto err;
+ /* Try to treat op as a list of lists */
+ if (!writeable && PySequence_Check(op)) {
+ int check_it, stop_at_string, stop_at_tuple, is_object;
+ int type_num, type;
+
+ /*
+ * Determine the type, using the requested data type if
+ * it will affect how the array is retrieved
+ */
+ if (requested_dtype != NULL && (
+ requested_dtype->type_num == NPY_STRING ||
+ requested_dtype->type_num == NPY_UNICODE ||
+ (requested_dtype->type_num == NPY_VOID &&
+ (requested_dtype->names || requested_dtype->subarray)) ||
+ requested_dtype->type == NPY_CHARLTR ||
+ requested_dtype->type_num == NPY_OBJECT)) {
+ Py_INCREF(requested_dtype);
+ *out_dtype = requested_dtype;
}
- if (newtype == NULL) {
- newtype = _array_find_type(op, NULL, MAX_DIMS);
+ else {
+ *out_dtype = _array_find_type(op, NULL, MAX_DIMS);
+ if (*out_dtype == NULL) {
+ if (PyErr_Occurred() &&
+ PyErr_GivenExceptionMatches(PyErr_Occurred(),
+ PyExc_MemoryError)) {
+ return -1;
+ }
+ /* Say it's an OBJECT array if there's an error */
+ PyErr_Clear();
+ *out_dtype = PyArray_DescrFromType(NPY_OBJECT);
+ if (*out_dtype == NULL) {
+ return -1;
+ }
+ }
+ }
+
+ type_num = (*out_dtype)->type_num;
+ type = (*out_dtype)->type;
+
+ check_it = (type != NPY_CHARLTR);
+ stop_at_string = (type_num != NPY_STRING) ||
+ (type == NPY_STRINGLTR);
+ stop_at_tuple = (type_num == NPY_VOID &&
+ ((*out_dtype)->names || (*out_dtype)->subarray));
+
+ *out_ndim = NPY_MAXDIMS;
+ is_object = 0;
+ if (discover_dimensions(op, out_ndim, out_dims, check_it,
+ stop_at_string, stop_at_tuple,
+ &is_object) < 0) {
+ Py_DECREF(*out_dtype);
+ if (PyErr_Occurred()) {
+ return -1;
+ }
+ *out_dtype = PyArray_DescrFromType(NPY_OBJECT);
+ if (*out_dtype == NULL) {
+ return -1;
+ }
+ *out_ndim = 0;
+ *out_arr = NULL;
+ return 0;
+ }
+ /* If object arrays are forced */
+ if (is_object) {
+ Py_DECREF(*out_dtype);
+ *out_dtype = PyArray_DescrFromType(NPY_OBJECT);
+ if (*out_dtype == NULL) {
+ return -1;
+ }
}
- else if (newtype->type_num == PyArray_OBJECT) {
- isobject = 1;
+
+ if ((*out_dtype)->type == NPY_CHARLTR && (*out_ndim) > 0 &&
+ out_dims[(*out_ndim) - 1] == 1) {
+ (*out_ndim) -= 1;
}
- if (PySequence_Check(op)) {
- PyObject *thiserr = NULL;
- /* necessary but not sufficient */
- Py_INCREF(newtype);
- r = Array_FromSequence(op, newtype, flags & FORTRAN,
- min_depth, max_depth);
- if (r == NULL && (thiserr=PyErr_Occurred())) {
- if (PyErr_GivenExceptionMatches(thiserr,
+ /* If the type is flexible, determine its size */
+ if ((*out_dtype)->elsize == 0 &&
+ PyTypeNum_ISEXTENDED((*out_dtype)->type_num)) {
+ int itemsize = 0;
+ if (discover_itemsize(op, *out_ndim, &itemsize) < 0) {
+ Py_DECREF(*out_dtype);
+ if (PyErr_Occurred() &&
+ PyErr_GivenExceptionMatches(PyErr_Occurred(),
PyExc_MemoryError)) {
- return NULL;
+ return -1;
}
- /*
- * If object was explicitly requested,
- * then try nested list object array creation
- */
+ /* Say it's an OBJECT scalar if there's an error */
PyErr_Clear();
- if (isobject) {
- Py_INCREF(newtype);
- r = ObjectArray_FromNestedList
- (op, newtype, flags & FORTRAN);
- seq = TRUE;
- Py_DECREF(newtype);
- }
+ *out_dtype = PyArray_DescrFromType(NPY_OBJECT);
+ *out_ndim = 0;
+ *out_arr = NULL;
+ return 0;
}
- else {
- seq = TRUE;
- Py_DECREF(newtype);
+ if ((*out_dtype)->type_num == NPY_UNICODE) {
+ itemsize *= 4;
+ }
+
+ if (itemsize != (*out_dtype)->elsize) {
+ PyArray_DESCR_REPLACE(*out_dtype);
+ (*out_dtype)->elsize = itemsize;
}
}
- if (!seq) {
- r = Array_FromPyScalar(op, newtype);
+
+ *out_arr = NULL;
+ return 0;
+ }
+
+ /* Anything can be viewed as an object, unless it needs to be writeable */
+ if (!writeable) {
+ *out_dtype = PyArray_DescrFromType(NPY_OBJECT);
+ if (*out_dtype == NULL) {
+ return -1;
}
+ *out_ndim = 0;
+ *out_arr = NULL;
+ return 0;
}
- /* If we didn't succeed return NULL */
- if (r == NULL) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "object cannot be viewed as a writeable numpy array");
+ return -1;
+}
+
+/*NUMPY_API
+ * Does not check for NPY_ENSURECOPY and NPY_NOTSWAPPED in flags
+ * Steals a reference to newtype --- which can be NULL
+ */
+NPY_NO_EXPORT PyObject *
+PyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,
+ int max_depth, int flags, PyObject *context)
+{
+ /*
+ * This is the main code to make a NumPy array from a Python
+ * Object. It is called from many different places.
+ */
+ PyArrayObject *arr = NULL, *ret;
+ PyArray_Descr *dtype = NULL;
+ int ndim = 0;
+ npy_intp dims[NPY_MAXDIMS];
+
+ /* Get either the array or its parameters if it isn't an array */
+ if (PyArray_GetArrayParamsFromObject(op, newtype,
+ 0, &dtype,
+ &ndim, dims, &arr, context) < 0) {
+ Py_XDECREF(newtype);
+ ret = NULL;
return NULL;
}
- /* Be sure we succeed here */
- if(!PyArray_Check(r)) {
- PyErr_SetString(PyExc_RuntimeError,
- "internal error: PyArray_FromAny "\
- "not producing an array");
- Py_DECREF(r);
- return NULL;
+ /* If the requested dtype is flexible, adjust its size */
+ if (newtype != NULL && newtype->elsize == 0) {
+ PyArray_DESCR_REPLACE(newtype);
+ if (newtype == NULL) {
+ ret = NULL;
+ return NULL;
+ }
+ if (arr != NULL) {
+ dtype = PyArray_DESCR(arr);
+ }
+
+ if (newtype->type_num == dtype->type_num) {
+ newtype->elsize = dtype->elsize;
+ }
+ else {
+ switch(newtype->type_num) {
+ case NPY_STRING:
+ if (dtype->type_num == NPY_UNICODE) {
+ newtype->elsize = dtype->elsize >> 2;
+ }
+ else {
+ newtype->elsize = dtype->elsize;
+ }
+ break;
+ case NPY_UNICODE:
+ newtype->elsize = dtype->elsize << 2;
+ break;
+ case NPY_VOID:
+ newtype->elsize = dtype->elsize;
+ break;
+ }
+ }
}
- if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {
- PyErr_SetString(PyExc_ValueError,
- "object of too small depth for desired array");
- Py_DECREF(r);
- return NULL;
+ /* If we got dimensions and dtype instead of an array */
+ if (arr == NULL) {
+ if (flags&NPY_UPDATEIFCOPY) {
+ Py_XDECREF(newtype);
+ PyErr_SetString(PyExc_TypeError,
+ "UPDATEIFCOPY used for non-array input.");
+ return NULL;
+ }
+ else if (min_depth != 0 && ndim < min_depth) {
+ Py_DECREF(dtype);
+ Py_XDECREF(newtype);
+ PyErr_SetString(PyExc_ValueError,
+ "object of too small depth for desired array");
+ ret = NULL;
+ }
+ else if (max_depth != 0 && ndim > max_depth) {
+ Py_DECREF(dtype);
+ Py_XDECREF(newtype);
+ PyErr_SetString(PyExc_ValueError,
+ "object too deep for desired array");
+ ret = NULL;
+ }
+ else if (ndim == 0 && PyArray_IsScalar(op, Generic)) {
+ ret = (PyArrayObject *)PyArray_FromScalar(op, newtype);
+ Py_DECREF(dtype);
+ }
+ else {
+ if (newtype == NULL) {
+ newtype = dtype;
+ }
+ else {
+ /*
+ * TODO: would be nice to do this too, but it's
+ * a behavior change. It's also a bit tricky
+ * for downcasting to small integer and float
+ * types, and might be better to modify
+ * PyArray_AssignFromSequence and descr->f->setitem
+ * to have a 'casting' parameter and
+ * to check each value with scalar rules like
+ * in PyArray_MinScalarType.
+ */
+ /*
+ if (!(flags&NPY_FORCECAST) && ndim > 0 &&
+ !PyArray_CanCastTo(dtype, newtype)) {
+ Py_DECREF(dtype);
+ Py_XDECREF(newtype);
+ PyErr_SetString(PyExc_TypeError,
+ "object cannot be safely cast to array "
+ "of required type");
+ return NULL;
+ }
+ */
+ Py_DECREF(dtype);
+ }
+
+ /* Create an array and copy the data */
+ ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, newtype,
+ ndim, dims,
+ NULL, NULL,
+ flags&NPY_F_CONTIGUOUS, NULL);
+ if (ret != NULL) {
+ if (ndim > 0) {
+ if (PyArray_AssignFromSequence(ret, op) < 0) {
+ Py_DECREF(ret);
+ ret = NULL;
+ }
+ }
+ else {
+ if (PyArray_DESCR(ret)->f->setitem(op,
+ PyArray_DATA(ret), ret) < 0) {
+ Py_DECREF(ret);
+ ret = NULL;
+ }
+ }
+ }
+ }
}
- if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {
- PyErr_SetString(PyExc_ValueError,
- "object too deep for desired array");
- Py_DECREF(r);
- return NULL;
+ else {
+ if (min_depth != 0 && PyArray_NDIM(arr) < min_depth) {
+ PyErr_SetString(PyExc_ValueError,
+ "object of too small depth for desired array");
+ Py_DECREF(arr);
+ ret = NULL;
+ }
+ else if (max_depth != 0 && PyArray_NDIM(arr) > max_depth) {
+ PyErr_SetString(PyExc_ValueError,
+ "object too deep for desired array");
+ Py_DECREF(arr);
+ ret = NULL;
+ }
+ else {
+ ret = (PyArrayObject *)PyArray_FromArray(arr, newtype, flags);
+ Py_DECREF(arr);
+ }
}
- return r;
- err:
- Py_XDECREF(newtype);
- PyErr_SetString(PyExc_TypeError,
- "UPDATEIFCOPY used for non-array input.");
- return NULL;
+ return (PyObject *)ret;
}
/*
* flags is any of
- * CONTIGUOUS,
- * FORTRAN,
- * ALIGNED,
- * WRITEABLE,
- * NOTSWAPPED,
- * ENSURECOPY,
- * UPDATEIFCOPY,
- * FORCECAST,
- * ENSUREARRAY,
- * ELEMENTSTRIDES
+ * NPY_C_CONTIGUOUS (CONTIGUOUS),
+ * NPY_F_CONTIGUOUS (FORTRAN),
+ * NPY_ALIGNED,
+ * NPY_WRITEABLE,
+ * NPY_NOTSWAPPED,
+ * NPY_ENSURECOPY,
+ * NPY_UPDATEIFCOPY,
+ * NPY_FORCECAST,
+ * NPY_ENSUREARRAY,
+ * NPY_ELEMENTSTRIDES
*
* or'd (|) together
*
@@ -1876,24 +1801,24 @@ PyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,
* won't guarantee it -- it will depend on the object as to whether or
* not it has such features.
*
- * Note that ENSURECOPY is enough
- * to guarantee CONTIGUOUS, ALIGNED and WRITEABLE
+ * Note that NPY_ENSURECOPY is enough
+ * to guarantee NPY_C_CONTIGUOUS, NPY_ALIGNED and NPY_WRITEABLE
* and therefore it is redundant to include those as well.
*
- * BEHAVED == ALIGNED | WRITEABLE
- * CARRAY = CONTIGUOUS | BEHAVED
- * FARRAY = FORTRAN | BEHAVED
+ * NPY_BEHAVED == NPY_ALIGNED | NPY_WRITEABLE
+ * NPY_CARRAY = NPY_C_CONTIGUOUS | NPY_BEHAVED
+ * NPY_FARRAY = NPY_F_CONTIGUOUS | NPY_BEHAVED
*
- * FORTRAN can be set in the FLAGS to request a FORTRAN array.
+ * NPY_F_CONTIGUOUS can be set in the FLAGS to request a FORTRAN array.
* Fortran arrays are always behaved (aligned,
* notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d).
*
- * UPDATEIFCOPY flag sets this flag in the returned array if a copy is
+ * NPY_UPDATEIFCOPY flag sets this flag in the returned array if a copy is
* made and the base argument points to the (possibly) misbehaved array.
* When the new array is deallocated, the original array held in base
* is updated with the contents of the new array.
*
- * FORCECAST will cause a cast to occur regardless of whether or not
+ * NPY_FORCECAST will cause a cast to occur regardless of whether or not
* it is safe.
*/
@@ -1905,7 +1830,7 @@ PyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth,
int max_depth, int requires, PyObject *context)
{
PyObject *obj;
- if (requires & NOTSWAPPED) {
+ if (requires & NPY_NOTSWAPPED) {
if (!descr && PyArray_Check(op) &&
!PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {
descr = PyArray_DescrNew(PyArray_DESCR(op));
@@ -1922,10 +1847,10 @@ PyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth,
if (obj == NULL) {
return NULL;
}
- if ((requires & ELEMENTSTRIDES) &&
+ if ((requires & NPY_ELEMENTSTRIDES) &&
!PyArray_ElementStrides(obj)) {
PyObject *new;
- new = PyArray_NewCopy((PyArrayObject *)obj, PyArray_ANYORDER);
+ new = PyArray_NewCopy((PyArrayObject *)obj, NPY_ANYORDER);
Py_DECREF(obj);
obj = new;
}
@@ -1963,10 +1888,10 @@ PyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)
}
/*
- * Can't cast unless ndim-0 array, FORCECAST is specified
+ * Can't cast unless ndim-0 array, NPY_FORCECAST is specified
* or the cast is safe.
*/
- if (!(flags & FORCECAST) && !PyArray_NDIM(arr) == 0 &&
+ if (!(flags & NPY_FORCECAST) && !PyArray_NDIM(arr) == 0 &&
!PyArray_CanCastTo(oldtype, newtype)) {
Py_DECREF(newtype);
PyErr_SetString(PyExc_TypeError,
@@ -1976,23 +1901,27 @@ PyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)
}
/* Don't copy if sizes are compatible */
- if ((flags & ENSURECOPY) || PyArray_EquivTypes(oldtype, newtype)) {
+ if ((flags & NPY_ENSURECOPY) || PyArray_EquivTypes(oldtype, newtype)) {
arrflags = arr->flags;
- copy = (flags & ENSURECOPY) ||
- ((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS)))
- || ((flags & ALIGNED) && (!(arrflags & ALIGNED)))
+ if (arr->nd <= 1 && (flags & NPY_F_CONTIGUOUS)) {
+ flags |= NPY_C_CONTIGUOUS;
+ }
+ copy = (flags & NPY_ENSURECOPY) ||
+ ((flags & NPY_C_CONTIGUOUS) && (!(arrflags & NPY_C_CONTIGUOUS)))
+ || ((flags & NPY_ALIGNED) && (!(arrflags & NPY_ALIGNED)))
|| (arr->nd > 1 &&
- ((flags & FORTRAN) && (!(arrflags & FORTRAN))))
- || ((flags & WRITEABLE) && (!(arrflags & WRITEABLE)));
+ ((flags & NPY_F_CONTIGUOUS) &&
+ (!(arrflags & NPY_F_CONTIGUOUS))))
+ || ((flags & NPY_WRITEABLE) && (!(arrflags & NPY_WRITEABLE)));
if (copy) {
- if ((flags & UPDATEIFCOPY) &&
+ if ((flags & NPY_UPDATEIFCOPY) &&
(!PyArray_ISWRITEABLE(arr))) {
Py_DECREF(newtype);
PyErr_SetString(PyExc_ValueError, msg);
return NULL;
}
- if ((flags & ENSUREARRAY)) {
+ if ((flags & NPY_ENSUREARRAY)) {
subtype = &PyArray_Type;
}
ret = (PyArrayObject *)
@@ -2000,7 +1929,7 @@ PyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)
arr->nd,
arr->dimensions,
NULL, NULL,
- flags & FORTRAN,
+ flags & NPY_F_CONTIGUOUS,
(PyObject *)arr);
if (ret == NULL) {
return NULL;
@@ -2009,10 +1938,10 @@ PyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)
Py_DECREF(ret);
return NULL;
}
- if (flags & UPDATEIFCOPY) {
- ret->flags |= UPDATEIFCOPY;
+ if (flags & NPY_UPDATEIFCOPY) {
+ ret->flags |= NPY_UPDATEIFCOPY;
ret->base = (PyObject *)arr;
- PyArray_FLAGS(ret->base) &= ~WRITEABLE;
+ PyArray_FLAGS(ret->base) &= ~NPY_WRITEABLE;
Py_INCREF(arr);
}
}
@@ -2022,7 +1951,7 @@ PyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)
*/
else {
Py_DECREF(newtype);
- if ((flags & ENSUREARRAY) &&
+ if ((flags & NPY_ENSUREARRAY) &&
!PyArray_CheckExact(arr)) {
Py_INCREF(arr->descr);
ret = (PyArrayObject *)
@@ -2050,20 +1979,20 @@ PyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)
* array type and copy was not specified
*/
else {
- if ((flags & UPDATEIFCOPY) &&
+ if ((flags & NPY_UPDATEIFCOPY) &&
(!PyArray_ISWRITEABLE(arr))) {
Py_DECREF(newtype);
PyErr_SetString(PyExc_ValueError, msg);
return NULL;
}
- if ((flags & ENSUREARRAY)) {
+ if ((flags & NPY_ENSUREARRAY)) {
subtype = &PyArray_Type;
}
ret = (PyArrayObject *)
PyArray_NewFromDescr(subtype, newtype,
arr->nd, arr->dimensions,
NULL, NULL,
- flags & FORTRAN,
+ flags & NPY_F_CONTIGUOUS,
(PyObject *)arr);
if (ret == NULL) {
return NULL;
@@ -2072,10 +2001,10 @@ PyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)
Py_DECREF(ret);
return NULL;
}
- if (flags & UPDATEIFCOPY) {
- ret->flags |= UPDATEIFCOPY;
+ if (flags & NPY_UPDATEIFCOPY) {
+ ret->flags |= NPY_UPDATEIFCOPY;
ret->base = (PyObject *)arr;
- PyArray_FLAGS(ret->base) &= ~WRITEABLE;
+ PyArray_FLAGS(ret->base) &= ~NPY_WRITEABLE;
Py_INCREF(arr);
}
}
@@ -2104,9 +2033,9 @@ PyArray_FromStructInterface(PyObject *input)
if (inter->two != 2) {
goto fail;
}
- if ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {
+ if ((inter->flags & NPY_NOTSWAPPED) != NPY_NOTSWAPPED) {
endian = PyArray_OPPBYTE;
- inter->flags &= ~NOTSWAPPED;
+ inter->flags &= ~NPY_NOTSWAPPED;
}
if (inter->flags & ARR_HAS_DESCR) {
@@ -2201,7 +2130,7 @@ PyArray_FromInterface(PyObject *input)
if (res < 0) {
goto fail;
}
- dataflags &= ~WRITEABLE;
+ dataflags &= ~NPY_WRITEABLE;
}
attr = PyDict_GetItemString(inter, "offset");
if (attr) {
@@ -2246,7 +2175,7 @@ PyArray_FromInterface(PyObject *input)
goto fail;
}
if (PyObject_IsTrue(PyTuple_GET_ITEM(attr,1))) {
- dataflags &= ~WRITEABLE;
+ dataflags &= ~NPY_WRITEABLE;
}
}
attr = tstr;
@@ -2319,7 +2248,7 @@ PyArray_FromInterface(PyObject *input)
if (PyErr_Occurred()) {
PyErr_Clear();
}
- memcpy(ret->strides, strides, n*sizeof(intp));
+ memcpy(ret->strides, strides, n*sizeof(npy_intp));
}
else PyErr_Clear();
PyArray_UpdateFlags(ret, UPDATE_ALL);
@@ -2406,7 +2335,7 @@ PyArray_FromDimsAndDataAndDescr(int nd, int *d,
{
PyObject *ret;
int i;
- intp newd[MAX_DIMS];
+ npy_intp newd[MAX_DIMS];
char msg[] = "PyArray_FromDimsAndDataAndDescr: use PyArray_NewFromDescr.";
if (DEPRECATE(msg) < 0) {
@@ -2415,7 +2344,7 @@ PyArray_FromDimsAndDataAndDescr(int nd, int *d,
if (!PyArray_ISNBO(descr->byteorder))
descr->byteorder = '=';
for (i = 0; i < nd; i++) {
- newd[i] = (intp) d[i];
+ newd[i] = (npy_intp) d[i];
}
ret = PyArray_NewFromDescr(&PyArray_Type, descr,
nd, newd,
@@ -2476,7 +2405,7 @@ PyArray_EnsureArray(PyObject *op)
new = PyArray_FromScalar(op, NULL);
}
else {
- new = PyArray_FromAny(op, NULL, 0, 0, ENSUREARRAY, NULL);
+ new = PyArray_FromAny(op, NULL, 0, 0, NPY_ENSUREARRAY, NULL);
}
Py_XDECREF(op);
return new;
@@ -2492,92 +2421,353 @@ PyArray_EnsureAnyArray(PyObject *op)
return PyArray_EnsureArray(op);
}
-/*NUMPY_API
- * Copy an Array into another array -- memory must not overlap
- * Does not require src and dest to have "broadcastable" shapes
- * (only the same number of elements).
- */
+/* TODO: Put the order parameter in PyArray_CopyAnyInto and remove this */
NPY_NO_EXPORT int
-PyArray_CopyAnyInto(PyArrayObject *dest, PyArrayObject *src)
+PyArray_CopyAnyIntoOrdered(PyArrayObject *dst, PyArrayObject *src,
+ NPY_ORDER order)
{
- int elsize, simple;
- PyArrayIterObject *idest, *isrc;
- void (*myfunc)(char *, intp, char *, intp, intp, int);
+ PyArray_StridedTransferFn *stransfer = NULL;
+ void *transferdata = NULL;
+ NpyIter *dst_iter, *src_iter;
+
+ NpyIter_IterNextFunc *dst_iternext, *src_iternext;
+ char **dst_dataptr, **src_dataptr;
+ npy_intp dst_stride, src_stride;
+ npy_intp *dst_countptr, *src_countptr;
+
+ char *dst_data, *src_data;
+ npy_intp dst_count, src_count, count;
+ npy_intp src_itemsize;
+ npy_intp dst_size, src_size;
+ int needs_api;
+
NPY_BEGIN_THREADS_DEF;
- if (!PyArray_EquivArrTypes(dest, src)) {
- return PyArray_CastAnyTo(dest, src);
- }
- if (!PyArray_ISWRITEABLE(dest)) {
+ if (!PyArray_ISWRITEABLE(dst)) {
PyErr_SetString(PyExc_RuntimeError,
"cannot write to array");
return -1;
}
- if (PyArray_SIZE(dest) != PyArray_SIZE(src)) {
+
+ /*
+ * If the shapes match and a particular order is forced
+ * for both, use the more efficient CopyInto
+ */
+ if (order != NPY_ANYORDER && order != NPY_KEEPORDER &&
+ PyArray_NDIM(dst) == PyArray_NDIM(src) &&
+ PyArray_CompareLists(PyArray_DIMS(dst), PyArray_DIMS(src),
+ PyArray_NDIM(dst))) {
+ return PyArray_CopyInto(dst, src);
+ }
+
+ dst_size = PyArray_SIZE(dst);
+ src_size = PyArray_SIZE(src);
+ if (dst_size != src_size) {
PyErr_SetString(PyExc_ValueError,
"arrays must have the same number of elements"
" for copy");
return -1;
}
- simple = ((PyArray_ISCARRAY_RO(src) && PyArray_ISCARRAY(dest)) ||
- (PyArray_ISFARRAY_RO(src) && PyArray_ISFARRAY(dest)));
- if (simple) {
- /* Refcount note: src and dest have the same size */
- PyArray_INCREF(src);
- PyArray_XDECREF(dest);
- NPY_BEGIN_THREADS;
- memcpy(dest->data, src->data, PyArray_NBYTES(dest));
- NPY_END_THREADS;
+ /* Zero-sized arrays require nothing be done */
+ if (dst_size == 0) {
return 0;
}
- if (PyArray_SAMESHAPE(dest, src)) {
- int swap;
- if (PyArray_SAFEALIGNEDCOPY(dest) && PyArray_SAFEALIGNEDCOPY(src)) {
- myfunc = _strided_byte_copy;
- }
- else {
- myfunc = _unaligned_strided_byte_copy;
- }
- swap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);
- return _copy_from_same_shape(dest, src, myfunc, swap);
+ /*
+ * This copy is based on matching C-order traversals of src and dst.
+ * By using two iterators, we can find maximal sub-chunks that
+ * can be processed at once.
+ */
+ dst_iter = NpyIter_New(dst, NPY_ITER_WRITEONLY|
+ NPY_ITER_NO_INNER_ITERATION|
+ NPY_ITER_DONT_NEGATE_STRIDES|
+ NPY_ITER_REFS_OK,
+ order,
+ NPY_NO_CASTING,
+ NULL, 0, NULL, 0);
+ if (dst_iter == NULL) {
+ return -1;
}
+ src_iter = NpyIter_New(src, NPY_ITER_READONLY|
+ NPY_ITER_NO_INNER_ITERATION|
+ NPY_ITER_DONT_NEGATE_STRIDES|
+ NPY_ITER_REFS_OK,
+ order,
+ NPY_NO_CASTING,
+ NULL, 0, NULL, 0);
+ if (src_iter == NULL) {
+ NpyIter_Deallocate(dst_iter);
+ return -1;
+ }
+
+ /* Get all the values needed for the inner loop */
+ dst_iternext = NpyIter_GetIterNext(dst_iter, NULL);
+ dst_dataptr = NpyIter_GetDataPtrArray(dst_iter);
+ /* Since buffering is disabled, we can cache the stride */
+ dst_stride = *NpyIter_GetInnerStrideArray(dst_iter);
+ dst_countptr = NpyIter_GetInnerLoopSizePtr(dst_iter);
- /* Otherwise we have to do an iterator-based copy */
- idest = (PyArrayIterObject *)PyArray_IterNew((PyObject *)dest);
- if (idest == NULL) {
+ src_iternext = NpyIter_GetIterNext(src_iter, NULL);
+ src_dataptr = NpyIter_GetDataPtrArray(src_iter);
+ /* Since buffering is disabled, we can cache the stride */
+ src_stride = *NpyIter_GetInnerStrideArray(src_iter);
+ src_countptr = NpyIter_GetInnerLoopSizePtr(src_iter);
+
+ if (dst_iternext == NULL || src_iternext == NULL) {
+ NpyIter_Deallocate(dst_iter);
+ NpyIter_Deallocate(src_iter);
return -1;
}
- isrc = (PyArrayIterObject *)PyArray_IterNew((PyObject *)src);
- if (isrc == NULL) {
- Py_DECREF(idest);
+
+ src_itemsize = PyArray_DESCR(src)->elsize;
+
+ needs_api = NpyIter_IterationNeedsAPI(dst_iter) ||
+ NpyIter_IterationNeedsAPI(src_iter);
+
+ /*
+ * Because buffering is disabled in the iterator, the inner loop
+ * strides will be the same throughout the iteration loop. Thus,
+ * we can pass them to this function to take advantage of
+ * contiguous strides, etc.
+ */
+ if (PyArray_GetDTypeTransferFunction(
+ PyArray_ISALIGNED(src) && PyArray_ISALIGNED(dst),
+ src_stride, dst_stride,
+ PyArray_DESCR(src), PyArray_DESCR(dst),
+ 0,
+ &stransfer, &transferdata,
+ &needs_api) != NPY_SUCCEED) {
+ NpyIter_Deallocate(dst_iter);
+ NpyIter_Deallocate(src_iter);
return -1;
}
- elsize = dest->descr->elsize;
- /* Refcount note: src and dest have the same size */
- PyArray_INCREF(src);
- PyArray_XDECREF(dest);
- NPY_BEGIN_THREADS;
- while(idest->index < idest->size) {
- memcpy(idest->dataptr, isrc->dataptr, elsize);
- PyArray_ITER_NEXT(idest);
- PyArray_ITER_NEXT(isrc);
- }
- NPY_END_THREADS;
- Py_DECREF(idest);
- Py_DECREF(isrc);
- return 0;
+
+
+ if (!needs_api) {
+ NPY_BEGIN_THREADS;
+ }
+
+ dst_count = *dst_countptr;
+ src_count = *src_countptr;
+ dst_data = *dst_dataptr;
+ src_data = *src_dataptr;
+ /*
+ * The tests did not trigger this code, so added a new function
+ * ndarray.setasflat to the Python exposure in order to test it.
+ */
+ for(;;) {
+ /* Transfer the biggest amount that fits both */
+ count = (src_count < dst_count) ? src_count : dst_count;
+ stransfer(dst_data, dst_stride,
+ src_data, src_stride,
+ count, src_itemsize, transferdata);
+
+ /* If we exhausted the dst block, refresh it */
+ if (dst_count == count) {
+ if (!dst_iternext(dst_iter)) {
+ break;
+ }
+ dst_count = *dst_countptr;
+ dst_data = *dst_dataptr;
+ }
+ else {
+ dst_count -= count;
+ dst_data += count*dst_stride;
+ }
+
+ /* If we exhausted the src block, refresh it */
+ if (src_count == count) {
+ if (!src_iternext(src_iter)) {
+ break;
+ }
+ src_count = *src_countptr;
+ src_data = *src_dataptr;
+ }
+ else {
+ src_count -= count;
+ src_data += count*src_stride;
+ }
+ }
+
+ if (!needs_api) {
+ NPY_END_THREADS;
+ }
+
+ PyArray_FreeStridedTransferData(transferdata);
+ NpyIter_Deallocate(dst_iter);
+ NpyIter_Deallocate(src_iter);
+
+ return PyErr_Occurred() ? -1 : 0;
+}
+
+/*NUMPY_API
+ * Copy an Array into another array -- memory must not overlap
+ * Does not require src and dest to have "broadcastable" shapes
+ * (only the same number of elements).
+ *
+ * TODO: For NumPy 2.0, this could accept an order parameter which
+ * only allows NPY_CORDER and NPY_FORDER. Could also rename
+ * this to CopyAsFlat to make the name more intuitive.
+ *
+ * Returns 0 on success, -1 on error.
+ */
+NPY_NO_EXPORT int
+PyArray_CopyAnyInto(PyArrayObject *dst, PyArrayObject *src)
+{
+ return PyArray_CopyAnyIntoOrdered(dst, src, NPY_CORDER);
}
/*NUMPY_API
* Copy an Array into another array -- memory must not overlap.
+ * Broadcast to the destination shape if necessary.
+ *
+ * Returns 0 on success, -1 on failure.
*/
NPY_NO_EXPORT int
-PyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)
+PyArray_CopyInto(PyArrayObject *dst, PyArrayObject *src)
{
- return _array_copy_into(dest, src, 1);
+ PyArray_StridedTransferFn *stransfer = NULL;
+ void *transferdata = NULL;
+ NPY_BEGIN_THREADS_DEF;
+
+ if (!PyArray_ISWRITEABLE(dst)) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "cannot write to array");
+ return -1;
+ }
+
+ if (PyArray_NDIM(dst) >= PyArray_NDIM(src) &&
+ PyArray_TRIVIALLY_ITERABLE_PAIR(dst, src)) {
+ char *dst_data, *src_data;
+ npy_intp count, dst_stride, src_stride, src_itemsize;
+
+ int needs_api = 0;
+
+ PyArray_PREPARE_TRIVIAL_PAIR_ITERATION(dst, src, count,
+ dst_data, src_data, dst_stride, src_stride);
+
+ /*
+ * Check for overlap with positive strides, and if found,
+ * possibly reverse the order
+ */
+ if (dst_data > src_data && src_stride > 0 && dst_stride > 0 &&
+ (dst_data < src_data+src_stride*count) &&
+ (src_data < dst_data+dst_stride*count)) {
+ dst_data += dst_stride*(count-1);
+ src_data += src_stride*(count-1);
+ dst_stride = -dst_stride;
+ src_stride = -src_stride;
+ }
+
+ if (PyArray_GetDTypeTransferFunction(
+ PyArray_ISALIGNED(src) && PyArray_ISALIGNED(dst),
+ src_stride, dst_stride,
+ PyArray_DESCR(src), PyArray_DESCR(dst),
+ 0,
+ &stransfer, &transferdata,
+ &needs_api) != NPY_SUCCEED) {
+ return -1;
+ }
+
+ src_itemsize = PyArray_DESCR(src)->elsize;
+
+ if (!needs_api) {
+ NPY_BEGIN_THREADS;
+ }
+
+ stransfer(dst_data, dst_stride, src_data, src_stride,
+ count, src_itemsize, transferdata);
+
+ if (!needs_api) {
+ NPY_END_THREADS;
+ }
+
+ PyArray_FreeStridedTransferData(transferdata);
+
+ return PyErr_Occurred() ? -1 : 0;
+ }
+ else {
+ PyArrayObject *op[2];
+ npy_uint32 op_flags[2];
+ NpyIter *iter;
+
+ NpyIter_IterNextFunc *iternext;
+ char **dataptr;
+ npy_intp *stride;
+ npy_intp *countptr;
+ npy_intp src_itemsize;
+ int needs_api;
+
+ op[0] = dst;
+ op[1] = src;
+ op_flags[0] = NPY_ITER_WRITEONLY|NPY_ITER_NO_BROADCAST;
+ op_flags[1] = NPY_ITER_READONLY;
+
+ iter = NpyIter_MultiNew(2, op,
+ NPY_ITER_NO_INNER_ITERATION|
+ NPY_ITER_REFS_OK|
+ NPY_ITER_ZEROSIZE_OK,
+ NPY_KEEPORDER,
+ NPY_NO_CASTING,
+ op_flags,
+ NULL, 0, NULL, 0);
+ if (iter == NULL) {
+ return -1;
+ }
+
+ iternext = NpyIter_GetIterNext(iter, NULL);
+ if (iternext == NULL) {
+ NpyIter_Deallocate(iter);
+ return -1;
+ }
+ dataptr = NpyIter_GetDataPtrArray(iter);
+ stride = NpyIter_GetInnerStrideArray(iter);
+ countptr = NpyIter_GetInnerLoopSizePtr(iter);
+ src_itemsize = PyArray_DESCR(src)->elsize;
+
+ needs_api = NpyIter_IterationNeedsAPI(iter);
+
+ /*
+ * Because buffering is disabled in the iterator, the inner loop
+ * strides will be the same throughout the iteration loop. Thus,
+ * we can pass them to this function to take advantage of
+ * contiguous strides, etc.
+ */
+ if (PyArray_GetDTypeTransferFunction(
+ PyArray_ISALIGNED(src) && PyArray_ISALIGNED(dst),
+ stride[1], stride[0],
+ PyArray_DESCR(src), PyArray_DESCR(dst),
+ 0,
+ &stransfer, &transferdata,
+ &needs_api) != NPY_SUCCEED) {
+ NpyIter_Deallocate(iter);
+ return -1;
+ }
+
+
+ if (NpyIter_GetIterSize(iter) != 0) {
+ if (!needs_api) {
+ NPY_BEGIN_THREADS;
+ }
+
+ do {
+ stransfer(dataptr[0], stride[0],
+ dataptr[1], stride[1],
+ *countptr, src_itemsize, transferdata);
+ } while(iternext(iter));
+
+ if (!needs_api) {
+ NPY_END_THREADS;
+ }
+ }
+
+ PyArray_FreeStridedTransferData(transferdata);
+ NpyIter_Deallocate(iter);
+
+ return PyErr_Occurred() ? -1 : 0;
+ }
}
@@ -2648,7 +2838,7 @@ PyArray_CheckAxis(PyArrayObject *arr, int *axis, int flags)
* accepts NULL type
*/
NPY_NO_EXPORT PyObject *
-PyArray_Zeros(int nd, intp *dims, PyArray_Descr *type, int fortran)
+PyArray_Zeros(int nd, npy_intp *dims, PyArray_Descr *type, int fortran)
{
PyArrayObject *ret;
@@ -2677,7 +2867,7 @@ PyArray_Zeros(int nd, intp *dims, PyArray_Descr *type, int fortran)
* steals referenct to type
*/
NPY_NO_EXPORT PyObject *
-PyArray_Empty(int nd, intp *dims, PyArray_Descr *type, int fortran)
+PyArray_Empty(int nd, npy_intp *dims, PyArray_Descr *type, int fortran)
{
PyArrayObject *ret;
@@ -2705,7 +2895,7 @@ PyArray_Empty(int nd, intp *dims, PyArray_Descr *type, int fortran)
* Return 0 on success, -1 on failure. In case of failure, set a PyExc_Overflow
* exception
*/
-static int _safe_ceil_to_intp(double value, intp* ret)
+static int _safe_ceil_to_intp(double value, npy_intp* ret)
{
double ivalue;
@@ -2714,7 +2904,7 @@ static int _safe_ceil_to_intp(double value, intp* ret)
return -1;
}
- *ret = (intp)ivalue;
+ *ret = (npy_intp)ivalue;
return 0;
}
@@ -2725,7 +2915,7 @@ static int _safe_ceil_to_intp(double value, intp* ret)
NPY_NO_EXPORT PyObject *
PyArray_Arange(double start, double stop, double step, int type_num)
{
- intp length;
+ npy_intp length;
PyObject *range;
PyArray_ArrFuncs *funcs;
PyObject *obj;
@@ -2790,10 +2980,10 @@ PyArray_Arange(double start, double stop, double step, int type_num)
/*
* the formula is len = (intp) ceil((start - stop) / step);
*/
-static intp
+static npy_intp
_calc_length(PyObject *start, PyObject *stop, PyObject *step, PyObject **next, int cmplx)
{
- intp len, tmp;
+ npy_intp len, tmp;
PyObject *val;
double value;
@@ -2870,7 +3060,7 @@ PyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr
PyObject *range;
PyArray_ArrFuncs *funcs;
PyObject *next, *err;
- intp length;
+ npy_intp length;
PyArray_Descr *native = NULL;
int swap;
@@ -2996,22 +3186,40 @@ PyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr
}
static PyArrayObject *
-array_fromfile_binary(FILE *fp, PyArray_Descr *dtype, intp num, size_t *nread)
+array_fromfile_binary(FILE *fp, PyArray_Descr *dtype, npy_intp num, size_t *nread)
{
PyArrayObject *r;
- intp start, numbytes;
+ npy_intp start, numbytes;
if (num < 0) {
int fail = 0;
- start = (intp )ftell(fp);
+#if defined(_MSC_VER) && defined(_WIN64) && (_MSC_VER > 1400)
+ /* Workaround Win64 fwrite() bug. Ticket #1660 */
+ start = (npy_intp )_ftelli64(fp);
+ if (start < 0) {
+ fail = 1;
+ }
+ if (_fseeki64(fp, 0, SEEK_END) < 0) {
+ fail = 1;
+ }
+ numbytes = (npy_intp) _ftelli64(fp);
+ if (numbytes < 0) {
+ fail = 1;
+ }
+ numbytes -= start;
+ if (_fseeki64(fp, start, SEEK_SET) < 0) {
+ fail = 1;
+ }
+#else
+ start = (npy_intp)ftell(fp);
if (start < 0) {
fail = 1;
}
if (fseek(fp, 0, SEEK_END) < 0) {
fail = 1;
}
- numbytes = (intp) ftell(fp);
+ numbytes = (npy_intp) ftell(fp);
if (numbytes < 0) {
fail = 1;
}
@@ -3019,6 +3227,7 @@ array_fromfile_binary(FILE *fp, PyArray_Descr *dtype, intp num, size_t *nread)
if (fseek(fp, start, SEEK_SET) < 0) {
fail = 1;
}
+#endif
if (fail) {
PyErr_SetString(PyExc_IOError,
"could not seek in file");
@@ -3047,17 +3256,17 @@ array_fromfile_binary(FILE *fp, PyArray_Descr *dtype, intp num, size_t *nread)
*/
#define FROM_BUFFER_SIZE 4096
static PyArrayObject *
-array_from_text(PyArray_Descr *dtype, intp num, char *sep, size_t *nread,
+array_from_text(PyArray_Descr *dtype, npy_intp num, char *sep, size_t *nread,
void *stream, next_element next, skip_separator skip_sep,
void *stream_data)
{
PyArrayObject *r;
- intp i;
+ npy_intp i;
char *dptr, *clean_sep, *tmp;
int err = 0;
- intp thisbuf = 0;
- intp size;
- intp bytes, totalbytes;
+ npy_intp thisbuf = 0;
+ npy_intp size;
+ npy_intp bytes, totalbytes;
size = (num >= 0) ? num : FROM_BUFFER_SIZE;
r = (PyArrayObject *)
@@ -3138,7 +3347,7 @@ array_from_text(PyArray_Descr *dtype, intp num, char *sep, size_t *nread,
* necessary is read by this routine.
*/
NPY_NO_EXPORT PyObject *
-PyArray_FromFile(FILE *fp, PyArray_Descr *dtype, intp num, char *sep)
+PyArray_FromFile(FILE *fp, PyArray_Descr *dtype, npy_intp num, char *sep)
{
PyArrayObject *ret;
size_t nread = 0;
@@ -3173,7 +3382,7 @@ PyArray_FromFile(FILE *fp, PyArray_Descr *dtype, intp num, char *sep)
Py_DECREF(dtype);
return NULL;
}
- if (((intp) nread) < num) {
+ if (((npy_intp) nread) < num) {
/* Realloc memory for smaller number of elements */
const size_t nsize = NPY_MAX(nread,1)*ret->descr->elsize;
char *tmp;
@@ -3191,14 +3400,14 @@ PyArray_FromFile(FILE *fp, PyArray_Descr *dtype, intp num, char *sep)
/*NUMPY_API*/
NPY_NO_EXPORT PyObject *
PyArray_FromBuffer(PyObject *buf, PyArray_Descr *type,
- intp count, intp offset)
+ npy_intp count, npy_intp offset)
{
PyArrayObject *ret;
char *data;
Py_ssize_t ts;
- intp s, n;
+ npy_intp s, n;
int itemsize;
- int write = 1;
+ int writeable = 1;
if (PyDataType_REFCHK(type)) {
@@ -3235,7 +3444,7 @@ PyArray_FromBuffer(PyObject *buf, PyArray_Descr *type,
}
if (PyObject_AsWriteBuffer(buf, (void *)&data, &ts) == -1) {
- write = 0;
+ writeable = 0;
PyErr_Clear();
if (PyObject_AsReadBuffer(buf, (void *)&data, &ts) == -1) {
Py_DECREF(buf);
@@ -3247,15 +3456,15 @@ PyArray_FromBuffer(PyObject *buf, PyArray_Descr *type,
if ((offset < 0) || (offset >= ts)) {
PyErr_Format(PyExc_ValueError,
"offset must be non-negative and smaller than buffer "\
- "lenth (%" INTP_FMT ")", (intp)ts);
+ "lenth (%" INTP_FMT ")", (npy_intp)ts);
Py_DECREF(buf);
Py_DECREF(type);
return NULL;
}
data += offset;
- s = (intp)ts - offset;
- n = (intp)count;
+ s = (npy_intp)ts - offset;
+ n = (npy_intp)count;
itemsize = type->elsize;
if (n < 0 ) {
if (s % itemsize != 0) {
@@ -3289,12 +3498,12 @@ PyArray_FromBuffer(PyObject *buf, PyArray_Descr *type,
return NULL;
}
- if (!write) {
- ret->flags &= ~WRITEABLE;
+ if (!writeable) {
+ ret->flags &= ~NPY_WRITEABLE;
}
/* Store a reference for decref on deallocation */
ret->base = buf;
- PyArray_UpdateFlags(ret, ALIGNED);
+ PyArray_UpdateFlags(ret, NPY_ALIGNED);
return (PyObject *)ret;
}
@@ -3320,8 +3529,8 @@ PyArray_FromBuffer(PyObject *buf, PyArray_Descr *type,
* for whitespace around the separator is added.
*/
NPY_NO_EXPORT PyObject *
-PyArray_FromString(char *data, intp slen, PyArray_Descr *dtype,
- intp num, char *sep)
+PyArray_FromString(char *data, npy_intp slen, PyArray_Descr *dtype,
+ npy_intp num, char *sep)
{
int itemsize;
PyArrayObject *ret;
@@ -3407,12 +3616,12 @@ PyArray_FromString(char *data, intp slen, PyArray_Descr *dtype,
* steals a reference to dtype (which cannot be NULL)
*/
NPY_NO_EXPORT PyObject *
-PyArray_FromIter(PyObject *obj, PyArray_Descr *dtype, intp count)
+PyArray_FromIter(PyObject *obj, PyArray_Descr *dtype, npy_intp count)
{
PyObject *value;
PyObject *iter = PyObject_GetIter(obj);
PyArrayObject *ret = NULL;
- intp i, elsize, elcount;
+ npy_intp i, elsize, elcount;
char *item, *new_data;
if (iter == NULL) {
@@ -3511,9 +3720,9 @@ PyArray_FromIter(PyObject *obj, PyArray_Descr *dtype, intp count)
*
* If data is given, then flags is flags associated with data.
* If strides is not given, then a contiguous strides array will be created
- * and the CONTIGUOUS bit will be set. If the flags argument
- * has the FORTRAN bit set, then a FORTRAN-style strides array will be
- * created (and of course the FORTRAN flag bit will be set).
+ * and the NPY_C_CONTIGUOUS bit will be set. If the flags argument
+ * has the NPY_F_CONTIGUOUS bit set, then a FORTRAN-style strides array will be
+ * created (and of course the NPY_F_CONTIGUOUS flag bit will be set).
*
* If data is not given but created here, then flags will be DEFAULT
* and a non-zero flags argument can be used to indicate a FORTRAN style
@@ -3521,22 +3730,21 @@ PyArray_FromIter(PyObject *obj, PyArray_Descr *dtype, intp count)
*/
NPY_NO_EXPORT size_t
-_array_fill_strides(intp *strides, intp *dims, int nd, size_t itemsize,
+_array_fill_strides(npy_intp *strides, npy_intp *dims, int nd, size_t itemsize,
int inflag, int *objflags)
{
int i;
/* Only make Fortran strides if not contiguous as well */
- if ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {
+ if ((inflag & (NPY_F_CONTIGUOUS|NPY_C_CONTIGUOUS)) == NPY_F_CONTIGUOUS) {
for (i = 0; i < nd; i++) {
strides[i] = itemsize;
itemsize *= dims[i] ? dims[i] : 1;
}
- *objflags |= FORTRAN;
if (nd > 1) {
- *objflags &= ~CONTIGUOUS;
+ *objflags = ((*objflags)|NPY_F_CONTIGUOUS) & ~NPY_C_CONTIGUOUS;
}
else {
- *objflags |= CONTIGUOUS;
+ *objflags |= (NPY_F_CONTIGUOUS|NPY_C_CONTIGUOUS);
}
}
else {
@@ -3544,14 +3752,12 @@ _array_fill_strides(intp *strides, intp *dims, int nd, size_t itemsize,
strides[i] = itemsize;
itemsize *= dims[i] ? dims[i] : 1;
}
- *objflags |= CONTIGUOUS;
if (nd > 1) {
- *objflags &= ~FORTRAN;
+ *objflags = ((*objflags)|NPY_C_CONTIGUOUS) & ~NPY_F_CONTIGUOUS;
}
else {
- *objflags |= FORTRAN;
+ *objflags |= (NPY_C_CONTIGUOUS|NPY_F_CONTIGUOUS);
}
}
return itemsize;
}
-
diff --git a/numpy/core/src/multiarray/ctors.h b/numpy/core/src/multiarray/ctors.h
index 5fd1d8e58..13f5d0da6 100644
--- a/numpy/core/src/multiarray/ctors.h
+++ b/numpy/core/src/multiarray/ctors.h
@@ -45,10 +45,12 @@ PyArray_CopyAnyInto(PyArrayObject *dest, PyArrayObject *src);
NPY_NO_EXPORT PyObject *
PyArray_CheckAxis(PyArrayObject *arr, int *axis, int flags);
-/* FIXME: remove those from here */
+/* TODO: Put the order parameter in PyArray_CopyAnyInto and remove this */
NPY_NO_EXPORT int
-_flat_copyinto(PyObject *dst, PyObject *src, NPY_ORDER order);
+PyArray_CopyAnyIntoOrdered(PyArrayObject *dst, PyArrayObject *src,
+ NPY_ORDER order);
+/* FIXME: remove those from here */
NPY_NO_EXPORT size_t
_array_fill_strides(intp *strides, intp *dims, int nd, size_t itemsize,
int inflag, int *objflags);
@@ -67,4 +69,7 @@ copy_and_swap(void *dst, void *src, int itemsize, intp numitems,
NPY_NO_EXPORT void
byte_swap_vector(void *p, intp n, int size);
+NPY_NO_EXPORT int
+PyArray_AssignFromSequence(PyArrayObject *self, PyObject *v);
+
#endif
diff --git a/numpy/core/src/multiarray/datetime.c b/numpy/core/src/multiarray/datetime.c
index 83c95bef3..ad1d98270 100644
--- a/numpy/core/src/multiarray/datetime.c
+++ b/numpy/core/src/multiarray/datetime.c
@@ -267,7 +267,7 @@ NPY_NO_EXPORT npy_datetime
PyArray_DatetimeStructToDatetime(NPY_DATETIMEUNIT fr, npy_datetimestruct *d)
{
npy_datetime ret;
- npy_longlong days; /* The absolute number of days since Jan 1, 1970 */
+ npy_longlong days = 0; /* The absolute number of days since Jan 1, 1970 */
if (fr > NPY_FR_M) {
days = days_from_ymd(d->year, d->month, d->day);
@@ -596,7 +596,7 @@ PyArray_DatetimeToDatetimeStruct(npy_datetime val, NPY_DATETIMEUNIT fr,
ymd = days_to_ymdstruct((val - 86399) / 86400);
sec = 86399 + (val + 1) % 86400;
}
- hms = seconds_to_hmsstruct(val);
+ hms = seconds_to_hmsstruct(sec);
year = ymd.year;
month = ymd.month;
day = ymd.day;
diff --git a/numpy/core/src/multiarray/descriptor.c b/numpy/core/src/multiarray/descriptor.c
index 7cbcd7866..bf4ea27a6 100644
--- a/numpy/core/src/multiarray/descriptor.c
+++ b/numpy/core/src/multiarray/descriptor.c
@@ -576,7 +576,7 @@ static NPY_DATETIMEUNIT
return unit;
}
-static int _multiples_table[16][4] = {
+static NPY_DATETIMEUNIT _multiples_table[16][4] = {
{12, 52, 365}, /* NPY_FR_Y */
{NPY_FR_M, NPY_FR_W, NPY_FR_D},
{4, 30, 720}, /* NPY_FR_M */
@@ -601,13 +601,13 @@ static int
_convert_divisor_to_multiple(PyArray_DatetimeMetaData *meta)
{
int i, num, ind;
- int *totry;
+ NPY_DATETIMEUNIT *totry;
NPY_DATETIMEUNIT *baseunit;
int q, r;
ind = ((int)meta->base - (int)NPY_FR_Y)*2;
totry = _multiples_table[ind];
- baseunit = (NPY_DATETIMEUNIT *)_multiples_table[ind + 1];
+ baseunit = _multiples_table[ind + 1];
num = 3;
if (meta->base == NPY_FR_W) {
@@ -619,7 +619,7 @@ _convert_divisor_to_multiple(PyArray_DatetimeMetaData *meta)
if (meta->base >= NPY_FR_s) {
ind = ((int)NPY_FR_s - (int)NPY_FR_Y)*2;
totry = _multiples_table[ind];
- baseunit = (NPY_DATETIMEUNIT *)_multiples_table[ind + 1];
+ baseunit = _multiples_table[ind + 1];
baseunit[0] = meta->base + 1;
baseunit[1] = meta->base + 2;
if (meta->base == NPY_DATETIME_NUMUNITS - 2) {
@@ -705,7 +705,7 @@ _convert_from_datetime_tuple(PyObject *obj)
PyArray_Descr *new;
PyObject *dt_tuple;
PyObject *dt_cobj;
- PyObject *datetime;
+ PyObject *datetime_flag;
if (!PyTuple_Check(obj) || PyTuple_GET_SIZE(obj)!=2) {
PyErr_SetString(PyExc_RuntimeError,
@@ -714,10 +714,10 @@ _convert_from_datetime_tuple(PyObject *obj)
}
dt_tuple = PyTuple_GET_ITEM(obj, 0);
- datetime = PyTuple_GET_ITEM(obj, 1);
+ datetime_flag = PyTuple_GET_ITEM(obj, 1);
if (!PyTuple_Check(dt_tuple)
|| PyTuple_GET_SIZE(dt_tuple) != 4
- || !PyInt_Check(datetime)) {
+ || !PyInt_Check(datetime_flag)) {
PyErr_SetString(PyExc_RuntimeError,
"_datetimestring is not returning a length 4 tuple"\
" and an integer");
@@ -725,7 +725,7 @@ _convert_from_datetime_tuple(PyObject *obj)
}
/* Create new timedelta or datetime dtype */
- if (PyObject_IsTrue(datetime)) {
+ if (PyObject_IsTrue(datetime_flag)) {
new = PyArray_DescrNewFromType(PyArray_DATETIME);
}
else {
@@ -1814,15 +1814,12 @@ arraydescr_metadata_get(PyArray_Descr *self)
static PyObject *
arraydescr_hasobject_get(PyArray_Descr *self)
{
- PyObject *res;
if (PyDataType_FLAGCHK(self, NPY_ITEM_HASOBJECT)) {
- res = Py_True;
+ Py_RETURN_TRUE;
}
else {
- res = Py_False;
+ Py_RETURN_FALSE;
}
- Py_INCREF(res);
- return res;
}
static PyObject *
@@ -2693,10 +2690,10 @@ arraydescr_str(PyArray_Descr *self)
PyObject *sh;
p = arraydescr_str(self->subarray->base);
if (!self->subarray->base->names && !self->subarray->base->subarray) {
- PyObject *t=PyUString_FromString("'");
- PyUString_Concat(&p, t);
- PyUString_ConcatAndDel(&t, p);
- p = t;
+ PyObject *tmp=PyUString_FromString("'");
+ PyUString_Concat(&p, tmp);
+ PyUString_ConcatAndDel(&tmp, p);
+ p = tmp;
}
PyUString_ConcatAndDel(&t, p);
PyUString_ConcatAndDel(&t, PyUString_FromString(","));
diff --git a/numpy/core/src/multiarray/dtype_transfer.c b/numpy/core/src/multiarray/dtype_transfer.c
new file mode 100644
index 000000000..b64e1684a
--- /dev/null
+++ b/numpy/core/src/multiarray/dtype_transfer.c
@@ -0,0 +1,2995 @@
+/*
+ * This file contains low-level loops for data type transfers.
+ * In particular the function PyArray_GetDTypeTransferFunction is
+ * implemented here.
+ *
+ * Copyright (c) 2010 by Mark Wiebe (mwwiebe@gmail.com)
+ * The Univerity of British Columbia
+ *
+ * See LICENSE.txt for the license.
+
+ */
+
+#define PY_SSIZE_T_CLEAN
+#include "Python.h"
+#include "structmember.h"
+
+#define _MULTIARRAYMODULE
+#include <numpy/ndarrayobject.h>
+#include <numpy/ufuncobject.h>
+#include <numpy/npy_cpu.h>
+
+#include "lowlevel_strided_loops.h"
+
+#define NPY_LOWLEVEL_BUFFER_BLOCKSIZE 128
+
+/********** PRINTF DEBUG TRACING **************/
+#define NPY_DT_DBG_TRACING 0
+/* Tracing incref/decref can be very noisy */
+#define NPY_DT_REF_DBG_TRACING 0
+
+#if NPY_DT_REF_DBG_TRACING
+#define NPY_DT_DBG_REFTRACE(msg, ref) \
+ printf("%-12s %20p %s%d%s\n", msg, ref, \
+ ref ? "(refcnt " : "", \
+ ref ? (int)ref->ob_refcnt : 0, \
+ ref ? ((ref->ob_refcnt <= 0) ? \
+ ") <- BIG PROBLEM!!!!" : ")") : ""); \
+ fflush(stdout);
+#else
+#define NPY_DT_DBG_REFTRACE(msg, ref)
+#endif
+/**********************************************/
+
+/*
+ * Returns a transfer function which DECREFs any references in src_type.
+ *
+ * Returns NPY_SUCCEED or NPY_FAIL.
+ */
+static int
+get_decsrcref_transfer_function(int aligned,
+ npy_intp src_stride,
+ PyArray_Descr *src_dtype,
+ PyArray_StridedTransferFn **out_stransfer,
+ void **out_transferdata,
+ int *out_needs_api);
+
+/*
+ * Returns a transfer function which zeros out the dest values.
+ *
+ * Returns NPY_SUCCEED or NPY_FAIL.
+ */
+static int
+get_setdstzero_transfer_function(int aligned,
+ npy_intp dst_stride,
+ PyArray_Descr *dst_dtype,
+ PyArray_StridedTransferFn **out_stransfer,
+ void **out_transferdata,
+ int *out_needs_api);
+
+/*
+ * Returns a transfer function which sets a boolean type to ones.
+ *
+ * Returns NPY_SUCCEED or NPY_FAIL.
+ */
+NPY_NO_EXPORT int
+get_bool_setdstone_transfer_function(npy_intp dst_stride,
+ PyArray_StridedTransferFn **out_stransfer,
+ void **out_transferdata,
+ int *NPY_UNUSED(out_needs_api));
+
+/*************************** COPY REFERENCES *******************************/
+
+/* Moves references from src to dst */
+static void
+_strided_to_strided_move_references(char *dst, npy_intp dst_stride,
+ char *src, npy_intp src_stride,
+ npy_intp N, npy_intp src_itemsize,
+ void *data)
+{
+ PyObject *src_ref = NULL, *dst_ref = NULL;
+ while (N > 0) {
+ NPY_COPY_PYOBJECT_PTR(&src_ref, src);
+ NPY_COPY_PYOBJECT_PTR(&dst_ref, dst);
+
+ /* Release the reference in dst */
+ NPY_DT_DBG_REFTRACE("dec dst ref", dst_ref);
+ Py_XDECREF(dst_ref);
+ /* Move the reference */
+ NPY_DT_DBG_REFTRACE("move src ref", src_ref);
+ NPY_COPY_PYOBJECT_PTR(dst, &src_ref);
+ /* Set the source reference to NULL */
+ src_ref = NULL;
+ NPY_COPY_PYOBJECT_PTR(src, &src_ref);
+
+ src += src_stride;
+ dst += dst_stride;
+ --N;
+ }
+}
+
+/* Copies references from src to dst */
+static void
+_strided_to_strided_copy_references(char *dst, npy_intp dst_stride,
+ char *src, npy_intp src_stride,
+ npy_intp N, npy_intp src_itemsize,
+ void *data)
+{
+ PyObject *src_ref = NULL, *dst_ref = NULL;
+ while (N > 0) {
+ NPY_COPY_PYOBJECT_PTR(&src_ref, src);
+ NPY_COPY_PYOBJECT_PTR(&dst_ref, dst);
+
+ /* Release the reference in dst */
+ NPY_DT_DBG_REFTRACE("dec dst ref", dst_ref);
+ Py_XDECREF(dst_ref);
+ /* Copy the reference */
+ NPY_DT_DBG_REFTRACE("copy src ref", src_ref);
+ NPY_COPY_PYOBJECT_PTR(dst, &src_ref);
+ /* Claim the reference */
+ Py_XINCREF(src_ref);
+
+ src += src_stride;
+ dst += dst_stride;
+ --N;
+ }
+}
+
+/************************** ZERO-PADDED COPY ******************************/
+
+typedef void (*free_strided_transfer_data)(void *);
+typedef void *(*copy_strided_transfer_data)(void *);
+
+/* Does a zero-padded copy */
+typedef struct {
+ free_strided_transfer_data freefunc;
+ copy_strided_transfer_data copyfunc;
+ npy_intp dst_itemsize;
+} _strided_zero_pad_data;
+
+/* zero-padded data copy function */
+void *_strided_zero_pad_data_copy(void *data)
+{
+ _strided_zero_pad_data *newdata =
+ (_strided_zero_pad_data *)PyArray_malloc(
+ sizeof(_strided_zero_pad_data));
+ if (newdata == NULL) {
+ return NULL;
+ }
+
+ memcpy(newdata, data, sizeof(_strided_zero_pad_data));
+
+ return newdata;
+}
+
+/*
+ * Does a strided to strided zero-padded copy for the case where
+ * dst_itemsize > src_itemsize
+ */
+static void
+_strided_to_strided_zero_pad_copy(char *dst, npy_intp dst_stride,
+ char *src, npy_intp src_stride,
+ npy_intp N, npy_intp src_itemsize,
+ void *data)
+{
+ _strided_zero_pad_data *d = (_strided_zero_pad_data *)data;
+ npy_intp dst_itemsize = d->dst_itemsize;
+ npy_intp zero_size = dst_itemsize-src_itemsize;
+
+ while (N > 0) {
+ memcpy(dst, src, src_itemsize);
+ memset(dst + src_itemsize, 0, zero_size);
+ src += src_stride;
+ dst += dst_stride;
+ --N;
+ }
+}
+
+/*
+ * Does a strided to strided zero-padded copy for the case where
+ * dst_itemsize < src_itemsize
+ */
+static void
+_strided_to_strided_truncate_copy(char *dst, npy_intp dst_stride,
+ char *src, npy_intp src_stride,
+ npy_intp N, npy_intp src_itemsize,
+ void *data)
+{
+ _strided_zero_pad_data *d = (_strided_zero_pad_data *)data;
+ npy_intp dst_itemsize = d->dst_itemsize;
+
+ while (N > 0) {
+ memcpy(dst, src, dst_itemsize);
+ src += src_stride;
+ dst += dst_stride;
+ --N;
+ }
+}
+
+NPY_NO_EXPORT int
+PyArray_GetStridedZeroPadCopyFn(int aligned,
+ npy_intp src_stride, npy_intp dst_stride,
+ npy_intp src_itemsize, npy_intp dst_itemsize,
+ PyArray_StridedTransferFn **out_stransfer,
+ void **out_transferdata)
+{
+ if (src_itemsize == dst_itemsize) {
+ *out_stransfer = PyArray_GetStridedCopyFn(aligned, src_stride,
+ dst_stride, src_itemsize);
+ *out_transferdata = NULL;
+ return (*out_stransfer == NULL) ? NPY_FAIL : NPY_SUCCEED;
+ }
+ else {
+ _strided_zero_pad_data *d = PyArray_malloc(
+ sizeof(_strided_zero_pad_data));
+ if (d == NULL) {
+ PyErr_NoMemory();
+ return NPY_FAIL;
+ }
+ d->dst_itemsize = dst_itemsize;
+ d->freefunc = &PyArray_free;
+ d->copyfunc = &_strided_zero_pad_data_copy;
+
+ if (src_itemsize < dst_itemsize) {
+ *out_stransfer = &_strided_to_strided_zero_pad_copy;
+ }
+ else {
+ *out_stransfer = &_strided_to_strided_truncate_copy;
+ }
+
+ *out_transferdata = d;
+ return NPY_SUCCEED;
+ }
+}
+
+/***************** WRAP ALIGNED CONTIGUOUS TRANSFER FUNCTION **************/
+
+/* Wraps a transfer function + data in alignment code */
+typedef struct {
+ free_strided_transfer_data freefunc;
+ copy_strided_transfer_data copyfunc;
+ PyArray_StridedTransferFn *wrapped,
+ *tobuffer, *frombuffer;
+ void *wrappeddata, *todata, *fromdata;
+ npy_intp src_itemsize, dst_itemsize;
+ char *bufferin, *bufferout;
+} _align_wrap_data;
+
+/* transfer data free function */
+void _align_wrap_data_free(void *data)
+{
+ _align_wrap_data *d = (_align_wrap_data *)data;
+ PyArray_FreeStridedTransferData(d->wrappeddata);
+ PyArray_FreeStridedTransferData(d->todata);
+ PyArray_FreeStridedTransferData(d->fromdata);
+ PyArray_free(data);
+}
+
+/* transfer data copy function */
+void *_align_wrap_data_copy(void *data)
+{
+ _align_wrap_data *d = (_align_wrap_data *)data;
+ _align_wrap_data *newdata;
+ npy_intp basedatasize, datasize;
+
+ /* Round up the structure size to 16-byte boundary */
+ basedatasize = (sizeof(_align_wrap_data)+15)&(-0x10);
+ /* Add space for two low level buffers */
+ datasize = basedatasize +
+ NPY_LOWLEVEL_BUFFER_BLOCKSIZE*d->src_itemsize +
+ NPY_LOWLEVEL_BUFFER_BLOCKSIZE*d->dst_itemsize;
+
+ /* Allocate the data, and populate it */
+ newdata = (_align_wrap_data *)PyArray_malloc(datasize);
+ if (newdata == NULL) {
+ return NULL;
+ }
+ memcpy(newdata, data, basedatasize);
+ newdata->bufferin = (char *)newdata + basedatasize;
+ newdata->bufferout = newdata->bufferin +
+ NPY_LOWLEVEL_BUFFER_BLOCKSIZE*newdata->src_itemsize;
+ if (newdata->wrappeddata != NULL) {
+ newdata->wrappeddata =
+ PyArray_CopyStridedTransferData(d->wrappeddata);
+ if (newdata->wrappeddata == NULL) {
+ PyArray_free(newdata);
+ return NULL;
+ }
+ }
+ if (newdata->todata != NULL) {
+ newdata->todata = PyArray_CopyStridedTransferData(d->todata);
+ if (newdata->todata == NULL) {
+ PyArray_FreeStridedTransferData(newdata->wrappeddata);
+ PyArray_free(newdata);
+ return NULL;
+ }
+ }
+ if (newdata->fromdata != NULL) {
+ newdata->fromdata = PyArray_CopyStridedTransferData(d->fromdata);
+ if (newdata->fromdata == NULL) {
+ PyArray_FreeStridedTransferData(newdata->wrappeddata);
+ PyArray_FreeStridedTransferData(newdata->todata);
+ PyArray_free(newdata);
+ return NULL;
+ }
+ }
+
+ return (void *)newdata;
+}
+
+static void
+_strided_to_strided_contig_align_wrap(char *dst, npy_intp dst_stride,
+ char *src, npy_intp src_stride,
+ npy_intp N, npy_intp src_itemsize,
+ void *data)
+{
+ _align_wrap_data *d = (_align_wrap_data *)data;
+ PyArray_StridedTransferFn *wrapped = d->wrapped,
+ *tobuffer = d->tobuffer,
+ *frombuffer = d->frombuffer;
+ npy_intp dst_itemsize = d->dst_itemsize;
+ void *wrappeddata = d->wrappeddata,
+ *todata = d->todata,
+ *fromdata = d->fromdata;
+ char *bufferin = d->bufferin, *bufferout = d->bufferout;
+
+ for(;;) {
+ if (N > NPY_LOWLEVEL_BUFFER_BLOCKSIZE) {
+ tobuffer(bufferin, src_itemsize, src, src_stride,
+ NPY_LOWLEVEL_BUFFER_BLOCKSIZE,
+ src_itemsize, todata);
+ wrapped(bufferout, dst_itemsize, bufferin, src_itemsize,
+ NPY_LOWLEVEL_BUFFER_BLOCKSIZE,
+ src_itemsize, wrappeddata);
+ frombuffer(dst, dst_stride, bufferout, dst_itemsize,
+ NPY_LOWLEVEL_BUFFER_BLOCKSIZE,
+ dst_itemsize, fromdata);
+ N -= NPY_LOWLEVEL_BUFFER_BLOCKSIZE;
+ src += NPY_LOWLEVEL_BUFFER_BLOCKSIZE*src_stride;
+ dst += NPY_LOWLEVEL_BUFFER_BLOCKSIZE*dst_stride;
+ }
+ else {
+ tobuffer(bufferin, src_itemsize, src, src_stride, N,
+ src_itemsize, todata);
+ wrapped(bufferout, dst_itemsize, bufferin, src_itemsize, N,
+ src_itemsize, wrappeddata);
+ frombuffer(dst, dst_stride, bufferout, dst_itemsize, N,
+ dst_itemsize, fromdata);
+ return;
+ }
+ }
+}
+
+static void
+_strided_to_strided_contig_align_wrap_init_dest(char *dst, npy_intp dst_stride,
+ char *src, npy_intp src_stride,
+ npy_intp N, npy_intp src_itemsize,
+ void *data)
+{
+ _align_wrap_data *d = (_align_wrap_data *)data;
+ PyArray_StridedTransferFn *wrapped = d->wrapped,
+ *tobuffer = d->tobuffer,
+ *frombuffer = d->frombuffer;
+ npy_intp dst_itemsize = d->dst_itemsize;
+ void *wrappeddata = d->wrappeddata,
+ *todata = d->todata,
+ *fromdata = d->fromdata;
+ char *bufferin = d->bufferin, *bufferout = d->bufferout;
+
+ for(;;) {
+ if (N > NPY_LOWLEVEL_BUFFER_BLOCKSIZE) {
+ tobuffer(bufferin, src_itemsize, src, src_stride,
+ NPY_LOWLEVEL_BUFFER_BLOCKSIZE,
+ src_itemsize, todata);
+ memset(bufferout, 0, dst_itemsize*NPY_LOWLEVEL_BUFFER_BLOCKSIZE);
+ wrapped(bufferout, dst_itemsize, bufferin, src_itemsize,
+ NPY_LOWLEVEL_BUFFER_BLOCKSIZE,
+ src_itemsize, wrappeddata);
+ frombuffer(dst, dst_stride, bufferout, dst_itemsize,
+ NPY_LOWLEVEL_BUFFER_BLOCKSIZE,
+ dst_itemsize, fromdata);
+ N -= NPY_LOWLEVEL_BUFFER_BLOCKSIZE;
+ src += NPY_LOWLEVEL_BUFFER_BLOCKSIZE*src_stride;
+ dst += NPY_LOWLEVEL_BUFFER_BLOCKSIZE*dst_stride;
+ }
+ else {
+ tobuffer(bufferin, src_itemsize, src, src_stride, N,
+ src_itemsize, todata);
+ memset(bufferout, 0, dst_itemsize*N);
+ wrapped(bufferout, dst_itemsize, bufferin, src_itemsize, N,
+ src_itemsize, wrappeddata);
+ frombuffer(dst, dst_stride, bufferout, dst_itemsize, N,
+ dst_itemsize, fromdata);
+ return;
+ }
+ }
+}
+
+/*
+ * Wraps an aligned contig to contig transfer function between either
+ * copies or byte swaps to temporary buffers.
+ *
+ * src_itemsize/dst_itemsize - The sizes of the src and dst datatypes.
+ * tobuffer - copy/swap function from src to an aligned contiguous buffer.
+ * todata - data for tobuffer
+ * frombuffer - copy/swap function from an aligned contiguous buffer to dst.
+ * fromdata - data for frombuffer
+ * wrapped - contig to contig transfer function being wrapped
+ * wrappeddata - data for wrapped
+ * init_dest - 1 means to memset the dest buffer to 0 before calling wrapped.
+ *
+ * Returns NPY_SUCCEED or NPY_FAIL.
+ */
+NPY_NO_EXPORT int
+wrap_aligned_contig_transfer_function(
+ npy_intp src_itemsize, npy_intp dst_itemsize,
+ PyArray_StridedTransferFn *tobuffer, void *todata,
+ PyArray_StridedTransferFn *frombuffer, void *fromdata,
+ PyArray_StridedTransferFn *wrapped, void *wrappeddata,
+ int init_dest,
+ PyArray_StridedTransferFn **out_stransfer,
+ void **out_transferdata)
+{
+ _align_wrap_data *data;
+ npy_intp basedatasize, datasize;
+
+ /* Round up the structure size to 16-byte boundary */
+ basedatasize = (sizeof(_align_wrap_data)+15)&(-0x10);
+ /* Add space for two low level buffers */
+ datasize = basedatasize +
+ NPY_LOWLEVEL_BUFFER_BLOCKSIZE*src_itemsize +
+ NPY_LOWLEVEL_BUFFER_BLOCKSIZE*dst_itemsize;
+
+ /* Allocate the data, and populate it */
+ data = (_align_wrap_data *)PyArray_malloc(datasize);
+ if (data == NULL) {
+ PyErr_NoMemory();
+ return NPY_FAIL;
+ }
+ data->freefunc = &_align_wrap_data_free;
+ data->copyfunc = &_align_wrap_data_copy;
+ data->tobuffer = tobuffer;
+ data->todata = todata;
+ data->frombuffer = frombuffer;
+ data->fromdata = fromdata;
+ data->wrapped = wrapped;
+ data->wrappeddata = wrappeddata;
+ data->src_itemsize = src_itemsize;
+ data->dst_itemsize = dst_itemsize;
+ data->bufferin = (char *)data + basedatasize;
+ data->bufferout = data->bufferin +
+ NPY_LOWLEVEL_BUFFER_BLOCKSIZE*src_itemsize;
+
+ /* Set the function and data */
+ if (init_dest) {
+ *out_stransfer = &_strided_to_strided_contig_align_wrap_init_dest;
+ }
+ else {
+ *out_stransfer = &_strided_to_strided_contig_align_wrap;
+ }
+ *out_transferdata = data;
+
+ return NPY_SUCCEED;
+}
+
+/*************************** WRAP DTYPE COPY/SWAP *************************/
+/* Wraps the dtype copy swap function */
+typedef struct {
+ free_strided_transfer_data freefunc;
+ copy_strided_transfer_data copyfunc;
+ PyArray_CopySwapNFunc *copyswapn;
+ int swap;
+ PyArrayObject *arr;
+} _wrap_copy_swap_data;
+
+/* wrap copy swap data free function */
+void _wrap_copy_swap_data_free(void *data)
+{
+ _wrap_copy_swap_data *d = (_wrap_copy_swap_data *)data;
+ Py_DECREF(d->arr);
+ PyArray_free(data);
+}
+
+/* wrap copy swap data copy function */
+void *_wrap_copy_swap_data_copy(void *data)
+{
+ _wrap_copy_swap_data *newdata =
+ (_wrap_copy_swap_data *)PyArray_malloc(sizeof(_wrap_copy_swap_data));
+ if (newdata == NULL) {
+ return NULL;
+ }
+
+ memcpy(newdata, data, sizeof(_wrap_copy_swap_data));
+ Py_INCREF(newdata->arr);
+
+ return (void *)newdata;
+}
+
+static void
+_strided_to_strided_wrap_copy_swap(char *dst, npy_intp dst_stride,
+ char *src, npy_intp src_stride,
+ npy_intp N, npy_intp NPY_UNUSED(src_itemsize),
+ void *data)
+{
+ _wrap_copy_swap_data *d = (_wrap_copy_swap_data *)data;
+
+ d->copyswapn(dst, dst_stride, src, src_stride, N, d->swap, d->arr);
+}
+
+/* This only gets used for custom data types */
+static int
+wrap_copy_swap_function(int aligned,
+ npy_intp src_stride, npy_intp dst_stride,
+ PyArray_Descr *dtype,
+ int should_swap,
+ PyArray_StridedTransferFn **out_stransfer,
+ void **out_transferdata)
+{
+ _wrap_copy_swap_data *data;
+ npy_intp shape = 1;
+
+ /* Allocate the data for the copy swap */
+ data = (_wrap_copy_swap_data *)PyArray_malloc(sizeof(_wrap_copy_swap_data));
+ if (data == NULL) {
+ PyErr_NoMemory();
+ *out_stransfer = NULL;
+ *out_transferdata = NULL;
+ return NPY_FAIL;
+ }
+
+ data->freefunc = &_wrap_copy_swap_data_free;
+ data->copyfunc = &_wrap_copy_swap_data_copy;
+ data->copyswapn = dtype->f->copyswapn;
+ data->swap = should_swap;
+
+ /*
+ * TODO: This is a hack so the copyswap functions have an array.
+ * The copyswap functions shouldn't need that.
+ */
+ Py_INCREF(dtype);
+ data->arr = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, dtype,
+ 1, &shape, NULL, NULL, 0, NULL);
+ if (data->arr == NULL) {
+ PyArray_free(data);
+ return NPY_FAIL;
+ }
+
+ *out_stransfer = &_strided_to_strided_wrap_copy_swap;
+ *out_transferdata = data;
+
+ return NPY_SUCCEED;
+}
+
+/*************************** DTYPE CAST FUNCTIONS *************************/
+
+/* Does a simple aligned cast */
+typedef struct {
+ free_strided_transfer_data freefunc;
+ copy_strided_transfer_data copyfunc;
+ PyArray_VectorUnaryFunc *castfunc;
+ PyArrayObject *aip, *aop;
+} _strided_cast_data;
+
+/* strided cast data free function */
+void _strided_cast_data_free(void *data)
+{
+ _strided_cast_data *d = (_strided_cast_data *)data;
+ Py_DECREF(d->aip);
+ Py_DECREF(d->aop);
+ PyArray_free(data);
+}
+
+/* strided cast data copy function */
+void *_strided_cast_data_copy(void *data)
+{
+ _strided_cast_data *newdata =
+ (_strided_cast_data *)PyArray_malloc(sizeof(_strided_cast_data));
+ if (newdata == NULL) {
+ return NULL;
+ }
+
+ memcpy(newdata, data, sizeof(_strided_cast_data));
+ Py_INCREF(newdata->aip);
+ Py_INCREF(newdata->aop);
+
+ return (void *)newdata;
+}
+
+static void
+_aligned_strided_to_strided_cast(char *dst, npy_intp dst_stride,
+ char *src, npy_intp src_stride,
+ npy_intp N, npy_intp src_itemsize,
+ void *data)
+{
+ _strided_cast_data *d = (_strided_cast_data *)data;
+ PyArray_VectorUnaryFunc *castfunc = d->castfunc;
+ PyArrayObject *aip = d->aip, *aop = d->aop;
+
+ while (N > 0) {
+ castfunc(src, dst, 1, aip, aop);
+ dst += dst_stride;
+ src += src_stride;
+ --N;
+ }
+}
+
+/* This one requires src be of type NPY_OBJECT */
+static void
+_aligned_strided_to_strided_cast_decref_src(char *dst, npy_intp dst_stride,
+ char *src, npy_intp src_stride,
+ npy_intp N, npy_intp src_itemsize,
+ void *data)
+{
+ _strided_cast_data *d = (_strided_cast_data *)data;
+ PyArray_VectorUnaryFunc *castfunc = d->castfunc;
+ PyArrayObject *aip = d->aip, *aop = d->aop;
+ PyObject *src_ref;
+
+ while (N > 0) {
+ castfunc(src, dst, 1, aip, aop);
+
+ /* After casting, decrement the source ref */
+ NPY_COPY_PYOBJECT_PTR(&src_ref, src);
+ NPY_DT_DBG_REFTRACE("dec src ref (cast object -> not object)", src_ref);
+ Py_XDECREF(src_ref);
+
+ dst += dst_stride;
+ src += src_stride;
+ --N;
+ }
+}
+
+static void
+_aligned_contig_to_contig_cast(char *dst, npy_intp NPY_UNUSED(dst_stride),
+ char *src, npy_intp NPY_UNUSED(src_stride),
+ npy_intp N, npy_intp NPY_UNUSED(itemsize),
+ void *data)
+{
+ _strided_cast_data *d = (_strided_cast_data *)data;
+
+ d->castfunc(src, dst, N, d->aip, d->aop);
+}
+
+static int
+get_nbo_cast_numeric_transfer_function(int aligned,
+ npy_intp src_stride, npy_intp dst_stride,
+ int src_type_num, int dst_type_num,
+ PyArray_StridedTransferFn **out_stransfer,
+ void **out_transferdata)
+{
+ /* Emit a warning if complex imaginary is being cast away */
+ if (PyTypeNum_ISCOMPLEX(src_type_num) &&
+ !PyTypeNum_ISCOMPLEX(dst_type_num) &&
+ !PyTypeNum_ISBOOL(dst_type_num)) {
+ PyObject *cls = NULL, *obj = NULL;
+ int ret;
+ obj = PyImport_ImportModule("numpy.core");
+ if (obj) {
+ cls = PyObject_GetAttrString(obj, "ComplexWarning");
+ Py_DECREF(obj);
+ }
+#if PY_VERSION_HEX >= 0x02050000
+ ret = PyErr_WarnEx(cls,
+ "Casting complex values to real discards "
+ "the imaginary part", 1);
+#else
+ ret = PyErr_Warn(cls,
+ "Casting complex values to real discards "
+ "the imaginary part");
+#endif
+ Py_XDECREF(cls);
+ if (ret < 0) {
+ return NPY_FAIL;
+ }
+ }
+
+ *out_stransfer = PyArray_GetStridedNumericCastFn(aligned,
+ src_stride, dst_stride,
+ src_type_num, dst_type_num);
+ *out_transferdata = NULL;
+ if (*out_stransfer == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "unexpected error in GetStridedNumericCastFn");
+ return NPY_FAIL;
+ }
+
+ return NPY_SUCCEED;
+}
+
+static int
+get_nbo_cast_transfer_function(int aligned,
+ npy_intp src_stride, npy_intp dst_stride,
+ PyArray_Descr *src_dtype, PyArray_Descr *dst_dtype,
+ int move_references,
+ PyArray_StridedTransferFn **out_stransfer,
+ void **out_transferdata,
+ int *out_needs_api,
+ int *out_needs_wrap)
+{
+ _strided_cast_data *data;
+ PyArray_VectorUnaryFunc *castfunc;
+ PyArray_Descr *tmp_dtype;
+ npy_intp shape = 1, src_itemsize = src_dtype->elsize,
+ dst_itemsize = dst_dtype->elsize;
+
+ if (PyTypeNum_ISNUMBER(src_dtype->type_num) &&
+ PyTypeNum_ISNUMBER(dst_dtype->type_num)) {
+ *out_needs_wrap = !PyArray_ISNBO(src_dtype->byteorder) ||
+ !PyArray_ISNBO(dst_dtype->byteorder);
+ return get_nbo_cast_numeric_transfer_function(aligned,
+ src_stride, dst_stride,
+ src_dtype->type_num, dst_dtype->type_num,
+ out_stransfer, out_transferdata);
+ }
+
+ *out_needs_wrap = !aligned ||
+ !PyArray_ISNBO(src_dtype->byteorder) ||
+ !PyArray_ISNBO(dst_dtype->byteorder);
+
+ /* Check the data types whose casting functions use API calls */
+ switch (src_dtype->type_num) {
+ case NPY_OBJECT:
+ case NPY_STRING:
+ case NPY_UNICODE:
+ case NPY_VOID:
+ if (out_needs_api) {
+ *out_needs_api = 1;
+ }
+ break;
+ }
+ switch (dst_dtype->type_num) {
+ case NPY_OBJECT:
+ case NPY_STRING:
+ case NPY_UNICODE:
+ case NPY_VOID:
+ if (out_needs_api) {
+ *out_needs_api = 1;
+ }
+ break;
+ }
+
+ /* Get the cast function */
+ castfunc = PyArray_GetCastFunc(src_dtype, dst_dtype->type_num);
+ if (!castfunc) {
+ *out_stransfer = NULL;
+ *out_transferdata = NULL;
+ return NPY_FAIL;
+ }
+
+ /* Allocate the data for the casting */
+ data = (_strided_cast_data *)PyArray_malloc(sizeof(_strided_cast_data));
+ if (data == NULL) {
+ PyErr_NoMemory();
+ *out_stransfer = NULL;
+ *out_transferdata = NULL;
+ return NPY_FAIL;
+ }
+ data->freefunc = &_strided_cast_data_free;
+ data->copyfunc = &_strided_cast_data_copy;
+ data->castfunc = castfunc;
+ /*
+ * TODO: This is a hack so the cast functions have an array.
+ * The cast functions shouldn't need that. Also, since we
+ * always handle byte order conversions, this array should
+ * have native byte order.
+ */
+ if (PyArray_ISNBO(src_dtype->byteorder)) {
+ tmp_dtype = src_dtype;
+ Py_INCREF(tmp_dtype);
+ }
+ else {
+ tmp_dtype = PyArray_DescrNewByteorder(src_dtype, NPY_NATIVE);
+ if (tmp_dtype == NULL) {
+ PyArray_free(data);
+ return NPY_FAIL;
+ }
+ }
+ data->aip = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, tmp_dtype,
+ 1, &shape, NULL, NULL, 0, NULL);
+ if (data->aip == NULL) {
+ PyArray_free(data);
+ return NPY_FAIL;
+ }
+ /*
+ * TODO: This is a hack so the cast functions have an array.
+ * The cast functions shouldn't need that. Also, since we
+ * always handle byte order conversions, this array should
+ * have native byte order.
+ */
+ if (PyArray_ISNBO(dst_dtype->byteorder)) {
+ tmp_dtype = dst_dtype;
+ Py_INCREF(tmp_dtype);
+ }
+ else {
+ tmp_dtype = PyArray_DescrNewByteorder(dst_dtype, NPY_NATIVE);
+ if (tmp_dtype == NULL) {
+ Py_DECREF(data->aip);
+ PyArray_free(data);
+ return NPY_FAIL;
+ }
+ }
+ data->aop = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, tmp_dtype,
+ 1, &shape, NULL, NULL, 0, NULL);
+ if (data->aop == NULL) {
+ Py_DECREF(data->aip);
+ PyArray_free(data);
+ return NPY_FAIL;
+ }
+
+ /* If it's aligned and all native byte order, we're all done */
+ if (move_references && src_dtype->type_num == NPY_OBJECT) {
+ *out_stransfer = _aligned_strided_to_strided_cast_decref_src;
+ }
+ else {
+ /*
+ * Use the contig version if the strides are contiguous or
+ * we're telling the caller to wrap the return, because
+ * the wrapping uses a contiguous buffer.
+ */
+ if ((src_stride == src_itemsize && dst_stride == dst_itemsize) ||
+ *out_needs_wrap) {
+ *out_stransfer = _aligned_contig_to_contig_cast;
+ }
+ else {
+ *out_stransfer = _aligned_strided_to_strided_cast;
+ }
+ }
+ *out_transferdata = data;
+
+ return NPY_SUCCEED;
+}
+
+static int
+get_cast_transfer_function(int aligned,
+ npy_intp src_stride, npy_intp dst_stride,
+ PyArray_Descr *src_dtype, PyArray_Descr *dst_dtype,
+ int move_references,
+ PyArray_StridedTransferFn **out_stransfer,
+ void **out_transferdata,
+ int *out_needs_api)
+{
+ PyArray_StridedTransferFn *caststransfer;
+ void *castdata, *todata = NULL, *fromdata = NULL;
+ int needs_wrap = 0;
+ npy_intp src_itemsize = src_dtype->elsize,
+ dst_itemsize = dst_dtype->elsize;
+
+ if (src_dtype->type_num == dst_dtype->type_num) {
+ PyErr_SetString(PyExc_ValueError,
+ "low level cast function is for unequal type numbers");
+ return NPY_FAIL;
+ }
+
+ if (get_nbo_cast_transfer_function(aligned,
+ src_stride, dst_stride,
+ src_dtype, dst_dtype,
+ move_references,
+ &caststransfer,
+ &castdata,
+ out_needs_api,
+ &needs_wrap) != NPY_SUCCEED) {
+ return NPY_FAIL;
+ }
+
+ /*
+ * If all native byte order and doesn't need alignment wrapping,
+ * return the function
+ */
+ if (!needs_wrap) {
+ *out_stransfer = caststransfer;
+ *out_transferdata = castdata;
+
+ return NPY_SUCCEED;
+ }
+ /* Otherwise, we have to copy and/or swap to aligned temporaries */
+ else {
+ PyArray_StridedTransferFn *tobuffer, *frombuffer;
+
+ /* Get the copy/swap operation from src */
+
+ /* If it's a custom data type, wrap its copy swap function */
+ if (src_dtype->type_num >= NPY_NTYPES) {
+ tobuffer = NULL;
+ wrap_copy_swap_function(aligned,
+ src_stride, src_itemsize,
+ src_dtype,
+ !PyArray_ISNBO(src_dtype->byteorder),
+ &tobuffer, &todata);
+ }
+ /* A straight copy */
+ else if (src_itemsize == 1 || PyArray_ISNBO(src_dtype->byteorder)) {
+ tobuffer = PyArray_GetStridedCopyFn(aligned,
+ src_stride, src_itemsize,
+ src_itemsize);
+ }
+ /* If it's not complex, one swap */
+ else if(src_dtype->kind != 'c') {
+ tobuffer = PyArray_GetStridedCopySwapFn(aligned,
+ src_stride, src_itemsize,
+ src_itemsize);
+ }
+ /* If complex, a paired swap */
+ else {
+ tobuffer = PyArray_GetStridedCopySwapPairFn(aligned,
+ src_stride, src_itemsize,
+ src_itemsize);
+ }
+
+ /* Get the copy/swap operation to dst */
+
+ /* If it's a custom data type, wrap its copy swap function */
+ if (dst_dtype->type_num >= NPY_NTYPES) {
+ frombuffer = NULL;
+ wrap_copy_swap_function(aligned,
+ dst_itemsize, dst_stride,
+ dst_dtype,
+ !PyArray_ISNBO(dst_dtype->byteorder),
+ &frombuffer, &fromdata);
+ }
+ /* A straight copy */
+ else if (dst_itemsize == 1 || PyArray_ISNBO(dst_dtype->byteorder)) {
+ if (dst_dtype->type_num == NPY_OBJECT) {
+ frombuffer = &_strided_to_strided_move_references;
+ }
+ else {
+ frombuffer = PyArray_GetStridedCopyFn(aligned,
+ dst_itemsize, dst_stride,
+ dst_itemsize);
+ }
+ }
+ /* If it's not complex, one swap */
+ else if(dst_dtype->kind != 'c') {
+ frombuffer = PyArray_GetStridedCopySwapFn(aligned,
+ dst_itemsize, dst_stride,
+ dst_itemsize);
+ }
+ /* If complex, a paired swap */
+ else {
+ frombuffer = PyArray_GetStridedCopySwapPairFn(aligned,
+ dst_itemsize, dst_stride,
+ dst_itemsize);
+ }
+
+ if (frombuffer == NULL || tobuffer == NULL) {
+ PyArray_FreeStridedTransferData(castdata);
+ PyArray_FreeStridedTransferData(todata);
+ PyArray_FreeStridedTransferData(fromdata);
+ return NPY_FAIL;
+ }
+
+ *out_stransfer = caststransfer;
+
+ /* Wrap it all up in a new transfer function + data */
+ if (wrap_aligned_contig_transfer_function(
+ src_itemsize, dst_itemsize,
+ tobuffer, todata,
+ frombuffer, fromdata,
+ caststransfer, castdata,
+ PyDataType_FLAGCHK(dst_dtype, NPY_NEEDS_INIT),
+ out_stransfer, out_transferdata) != NPY_SUCCEED) {
+ PyArray_FreeStridedTransferData(castdata);
+ PyArray_FreeStridedTransferData(todata);
+ PyArray_FreeStridedTransferData(fromdata);
+ return NPY_FAIL;
+ }
+
+ return NPY_SUCCEED;
+ }
+}
+
+/**************************** COPY 1 TO N CONTIGUOUS ************************/
+
+/* Copies 1 element to N contiguous elements */
+typedef struct {
+ free_strided_transfer_data freefunc;
+ copy_strided_transfer_data copyfunc;
+ PyArray_StridedTransferFn *stransfer;
+ void *data;
+ npy_intp N, dst_itemsize;
+ /* If this is non-NULL the source type has references needing a decref */
+ PyArray_StridedTransferFn *stransfer_finish_src;
+ void *data_finish_src;
+} _one_to_n_data;
+
+/* transfer data free function */
+void _one_to_n_data_free(void *data)
+{
+ _one_to_n_data *d = (_one_to_n_data *)data;
+ PyArray_FreeStridedTransferData(d->data);
+ PyArray_FreeStridedTransferData(d->data_finish_src);
+ PyArray_free(data);
+}
+
+/* transfer data copy function */
+void *_one_to_n_data_copy(void *data)
+{
+ _one_to_n_data *d = (_one_to_n_data *)data;
+ _one_to_n_data *newdata;
+
+ /* Allocate the data, and populate it */
+ newdata = (_one_to_n_data *)PyArray_malloc(sizeof(_one_to_n_data));
+ if (newdata == NULL) {
+ return NULL;
+ }
+ memcpy(newdata, data, sizeof(_one_to_n_data));
+ if (d->data != NULL) {
+ newdata->data = PyArray_CopyStridedTransferData(d->data);
+ if (newdata->data == NULL) {
+ PyArray_free(newdata);
+ return NULL;
+ }
+ }
+ if (d->data_finish_src != NULL) {
+ newdata->data_finish_src =
+ PyArray_CopyStridedTransferData(d->data_finish_src);
+ if (newdata->data_finish_src == NULL) {
+ PyArray_FreeStridedTransferData(newdata->data);
+ PyArray_free(newdata);
+ return NULL;
+ }
+ }
+
+ return (void *)newdata;
+}
+
+static void
+_strided_to_strided_one_to_n(char *dst, npy_intp dst_stride,
+ char *src, npy_intp src_stride,
+ npy_intp N, npy_intp src_itemsize,
+ void *data)
+{
+ _one_to_n_data *d = (_one_to_n_data *)data;
+ PyArray_StridedTransferFn *subtransfer = d->stransfer;
+ void *subdata = d->data;
+ npy_intp subN = d->N, dst_itemsize = d->dst_itemsize;
+
+ while (N > 0) {
+ subtransfer(dst, dst_itemsize,
+ src, 0,
+ subN, src_itemsize,
+ subdata);
+
+ src += src_stride;
+ dst += dst_stride;
+ --N;
+ }
+}
+
+static void
+_strided_to_strided_one_to_n_with_finish(char *dst, npy_intp dst_stride,
+ char *src, npy_intp src_stride,
+ npy_intp N, npy_intp src_itemsize,
+ void *data)
+{
+ _one_to_n_data *d = (_one_to_n_data *)data;
+ PyArray_StridedTransferFn *subtransfer = d->stransfer,
+ *stransfer_finish_src = d->stransfer_finish_src;
+ void *subdata = d->data, *data_finish_src = data_finish_src;
+ npy_intp subN = d->N, dst_itemsize = d->dst_itemsize;
+
+ while (N > 0) {
+ subtransfer(dst, dst_itemsize,
+ src, 0,
+ subN, src_itemsize,
+ subdata);
+
+
+ stransfer_finish_src(NULL, 0,
+ src, 0,
+ 1, src_itemsize,
+ data_finish_src);
+
+ src += src_stride;
+ dst += dst_stride;
+ --N;
+ }
+}
+
+/*
+ * Wraps a transfer function to produce one that copies one element
+ * of src to N contiguous elements of dst. If stransfer_finish_src is
+ * not NULL, it should be a transfer function which just affects
+ * src, for example to do a final DECREF operation for references.
+ */
+static int
+wrap_transfer_function_one_to_n(
+ PyArray_StridedTransferFn *stransfer_inner,
+ void *data_inner,
+ PyArray_StridedTransferFn *stransfer_finish_src,
+ void *data_finish_src,
+ npy_intp dst_itemsize,
+ npy_intp N,
+ PyArray_StridedTransferFn **out_stransfer,
+ void **out_transferdata)
+{
+ _one_to_n_data *data;
+
+
+ data = PyArray_malloc(sizeof(_one_to_n_data));
+ if (data == NULL) {
+ PyErr_NoMemory();
+ return NPY_FAIL;
+ }
+
+ data->freefunc = &_one_to_n_data_free;
+ data->copyfunc = &_one_to_n_data_copy;
+ data->stransfer = stransfer_inner;
+ data->data = data_inner;
+ data->stransfer_finish_src = stransfer_finish_src;
+ data->data_finish_src = data_finish_src;
+ data->N = N;
+ data->dst_itemsize = dst_itemsize;
+
+ if (stransfer_finish_src == NULL) {
+ *out_stransfer = &_strided_to_strided_one_to_n;
+ }
+ else {
+ *out_stransfer = &_strided_to_strided_one_to_n_with_finish;
+ }
+ *out_transferdata = data;
+
+ return NPY_SUCCEED;
+}
+
+static int
+get_one_to_n_transfer_function(int aligned,
+ npy_intp src_stride, npy_intp dst_stride,
+ PyArray_Descr *src_dtype, PyArray_Descr *dst_dtype,
+ int move_references,
+ npy_intp N,
+ PyArray_StridedTransferFn **out_stransfer,
+ void **out_transferdata,
+ int *out_needs_api)
+{
+ PyArray_StridedTransferFn *stransfer, *stransfer_finish_src = NULL;
+ void *data, *data_finish_src = NULL;
+
+ /*
+ * move_references is set to 0, handled in the wrapping transfer fn,
+ * src_stride is set to zero, because its 1 to N copying,
+ * and dst_stride is set to contiguous, because subarrays are always
+ * contiguous.
+ */
+ if (PyArray_GetDTypeTransferFunction(aligned,
+ 0, dst_dtype->elsize,
+ src_dtype, dst_dtype,
+ 0,
+ &stransfer, &data,
+ out_needs_api) != NPY_SUCCEED) {
+ return NPY_FAIL;
+ }
+
+ /* If the src object will need a DECREF, set src_dtype */
+ if (move_references && PyDataType_REFCHK(src_dtype)) {
+ if (get_decsrcref_transfer_function(aligned,
+ src_stride,
+ src_dtype,
+ &stransfer_finish_src,
+ &data_finish_src,
+ out_needs_api) != NPY_SUCCEED) {
+ PyArray_FreeStridedTransferData(data);
+ return NPY_FAIL;
+ }
+ }
+
+ if (wrap_transfer_function_one_to_n(stransfer, data,
+ stransfer_finish_src, data_finish_src,
+ dst_dtype->elsize,
+ N,
+ out_stransfer, out_transferdata) != NPY_SUCCEED) {
+ PyArray_FreeStridedTransferData(data);
+ PyArray_FreeStridedTransferData(data_finish_src);
+ return NPY_FAIL;
+ }
+
+ return NPY_SUCCEED;
+}
+
+/**************************** COPY N TO N CONTIGUOUS ************************/
+
+/* Copies N contiguous elements to N contiguous elements */
+typedef struct {
+ free_strided_transfer_data freefunc;
+ copy_strided_transfer_data copyfunc;
+ PyArray_StridedTransferFn *stransfer;
+ void *data;
+ npy_intp N, src_itemsize, dst_itemsize;
+} _n_to_n_data;
+
+/* transfer data free function */
+void _n_to_n_data_free(void *data)
+{
+ _n_to_n_data *d = (_n_to_n_data *)data;
+ PyArray_FreeStridedTransferData(d->data);
+ PyArray_free(data);
+}
+
+/* transfer data copy function */
+void *_n_to_n_data_copy(void *data)
+{
+ _n_to_n_data *d = (_n_to_n_data *)data;
+ _n_to_n_data *newdata;
+
+ /* Allocate the data, and populate it */
+ newdata = (_n_to_n_data *)PyArray_malloc(sizeof(_n_to_n_data));
+ if (newdata == NULL) {
+ return NULL;
+ }
+ memcpy(newdata, data, sizeof(_n_to_n_data));
+ if (newdata->data != NULL) {
+ newdata->data = PyArray_CopyStridedTransferData(d->data);
+ if (newdata->data == NULL) {
+ PyArray_free(newdata);
+ return NULL;
+ }
+ }
+
+ return (void *)newdata;
+}
+
+static void
+_strided_to_strided_n_to_n(char *dst, npy_intp dst_stride,
+ char *src, npy_intp src_stride,
+ npy_intp N, npy_intp src_itemsize,
+ void *data)
+{
+ _n_to_n_data *d = (_n_to_n_data *)data;
+ PyArray_StridedTransferFn *subtransfer = d->stransfer;
+ void *subdata = d->data;
+ npy_intp subN = d->N, src_subitemsize = d->src_itemsize,
+ dst_subitemsize = d->dst_itemsize;
+
+ while (N > 0) {
+ subtransfer(dst, dst_subitemsize,
+ src, src_subitemsize,
+ subN, src_subitemsize,
+ subdata);
+
+ src += src_stride;
+ dst += dst_stride;
+ --N;
+ }
+}
+
+static void
+_contig_to_contig_n_to_n(char *dst, npy_intp NPY_UNUSED(dst_stride),
+ char *src, npy_intp NPY_UNUSED(src_stride),
+ npy_intp N, npy_intp NPY_UNUSED(src_itemsize),
+ void *data)
+{
+ _n_to_n_data *d = (_n_to_n_data *)data;
+ PyArray_StridedTransferFn *subtransfer = d->stransfer;
+ void *subdata = d->data;
+ npy_intp subN = d->N, src_subitemsize = d->src_itemsize,
+ dst_subitemsize = d->dst_itemsize;
+
+ subtransfer(dst, dst_subitemsize,
+ src, src_subitemsize,
+ subN*N, src_subitemsize,
+ subdata);
+}
+
+/*
+ * Wraps a transfer function to produce one that copies N contiguous elements
+ * of src to N contiguous elements of dst.
+ */
+static int
+wrap_transfer_function_n_to_n(
+ PyArray_StridedTransferFn *stransfer_inner,
+ void *data_inner,
+ npy_intp src_stride, npy_intp dst_stride,
+ npy_intp src_itemsize, npy_intp dst_itemsize,
+ npy_intp N,
+ PyArray_StridedTransferFn **out_stransfer,
+ void **out_transferdata)
+{
+ _n_to_n_data *data;
+
+ data = PyArray_malloc(sizeof(_n_to_n_data));
+ if (data == NULL) {
+ PyErr_NoMemory();
+ return NPY_FAIL;
+ }
+
+ data->freefunc = &_n_to_n_data_free;
+ data->copyfunc = &_n_to_n_data_copy;
+ data->stransfer = stransfer_inner;
+ data->data = data_inner;
+ data->N = N;
+ data->src_itemsize = src_itemsize;
+ data->dst_itemsize = dst_itemsize;
+
+ /*
+ * If the N subarray elements exactly fit in the strides,
+ * then can do a faster contiguous transfer.
+ */
+ if (src_stride == N * src_itemsize &&
+ dst_stride == N * dst_itemsize) {
+ *out_stransfer = &_contig_to_contig_n_to_n;
+ }
+ else {
+ *out_stransfer = &_strided_to_strided_n_to_n;
+ }
+ *out_transferdata = data;
+
+ return NPY_SUCCEED;
+}
+
+static int
+get_n_to_n_transfer_function(int aligned,
+ npy_intp src_stride, npy_intp dst_stride,
+ PyArray_Descr *src_dtype, PyArray_Descr *dst_dtype,
+ int move_references,
+ npy_intp N,
+ PyArray_StridedTransferFn **out_stransfer,
+ void **out_transferdata,
+ int *out_needs_api)
+{
+ PyArray_StridedTransferFn *stransfer;
+ void *data;
+
+ /*
+ * src_stride and dst_stride are set to contiguous, because
+ * subarrays are always contiguous.
+ */
+ if (PyArray_GetDTypeTransferFunction(aligned,
+ src_dtype->elsize, dst_dtype->elsize,
+ src_dtype, dst_dtype,
+ move_references,
+ &stransfer, &data,
+ out_needs_api) != NPY_SUCCEED) {
+ return NPY_FAIL;
+ }
+
+ if (wrap_transfer_function_n_to_n(stransfer, data,
+ src_stride, dst_stride,
+ src_dtype->elsize, dst_dtype->elsize,
+ N,
+ out_stransfer,
+ out_transferdata) != NPY_SUCCEED) {
+ PyArray_FreeStridedTransferData(data);
+ return NPY_FAIL;
+ }
+
+ return NPY_SUCCEED;
+}
+
+/********************** COPY WITH SUBARRAY BROADCAST ************************/
+
+typedef struct {
+ npy_intp offset, count;
+} _subarray_broadcast_offsetrun;
+
+/* Copies element with subarray broadcasting */
+typedef struct {
+ free_strided_transfer_data freefunc;
+ copy_strided_transfer_data copyfunc;
+ PyArray_StridedTransferFn *stransfer;
+ void *data;
+ npy_intp src_N, dst_N, src_itemsize, dst_itemsize;
+ PyArray_StridedTransferFn *stransfer_decsrcref;
+ void *data_decsrcref;
+ PyArray_StridedTransferFn *stransfer_decdstref;
+ void *data_decdstref;
+ /* This gets a run-length encoded representation of the transfer */
+ npy_intp run_count;
+ _subarray_broadcast_offsetrun offsetruns;
+} _subarray_broadcast_data;
+
+/* transfer data free function */
+void _subarray_broadcast_data_free(void *data)
+{
+ _subarray_broadcast_data *d = (_subarray_broadcast_data *)data;
+ PyArray_FreeStridedTransferData(d->data);
+ PyArray_FreeStridedTransferData(d->data_decsrcref);
+ PyArray_FreeStridedTransferData(d->data_decdstref);
+ PyArray_free(data);
+}
+
+/* transfer data copy function */
+void *_subarray_broadcast_data_copy( void *data)
+{
+ _subarray_broadcast_data *d = (_subarray_broadcast_data *)data;
+ _subarray_broadcast_data *newdata;
+ npy_intp run_count = d->run_count, structsize;
+
+ structsize = sizeof(_subarray_broadcast_data) +
+ run_count*sizeof(_subarray_broadcast_offsetrun);
+
+ /* Allocate the data and populate it */
+ newdata = (_subarray_broadcast_data *)PyArray_malloc(structsize);
+ if (newdata == NULL) {
+ return NULL;
+ }
+ memcpy(newdata, data, structsize);
+ if (d->data != NULL) {
+ newdata->data = PyArray_CopyStridedTransferData(d->data);
+ if (newdata->data == NULL) {
+ PyArray_free(newdata);
+ return NULL;
+ }
+ }
+ if (d->data_decsrcref != NULL) {
+ newdata->data_decsrcref =
+ PyArray_CopyStridedTransferData(d->data_decsrcref);
+ if (newdata->data_decsrcref == NULL) {
+ PyArray_FreeStridedTransferData(newdata->data);
+ PyArray_free(newdata);
+ return NULL;
+ }
+ }
+ if (d->data_decdstref != NULL) {
+ newdata->data_decdstref =
+ PyArray_CopyStridedTransferData(d->data_decdstref);
+ if (newdata->data_decdstref == NULL) {
+ PyArray_FreeStridedTransferData(newdata->data);
+ PyArray_FreeStridedTransferData(newdata->data_decsrcref);
+ PyArray_free(newdata);
+ return NULL;
+ }
+ }
+
+ return newdata;
+}
+
+static void
+_strided_to_strided_subarray_broadcast(char *dst, npy_intp dst_stride,
+ char *src, npy_intp src_stride,
+ npy_intp N, npy_intp NPY_UNUSED(src_itemsize),
+ void *data)
+{
+ _subarray_broadcast_data *d = (_subarray_broadcast_data *)data;
+ PyArray_StridedTransferFn *subtransfer = d->stransfer;
+ void *subdata = d->data;
+ npy_intp run, run_count = d->run_count,
+ src_subitemsize = d->src_itemsize,
+ dst_subitemsize = d->dst_itemsize;
+ npy_intp loop_index, offset, count;
+ char *dst_ptr;
+ _subarray_broadcast_offsetrun *offsetruns = &d->offsetruns;
+
+ while (N > 0) {
+ loop_index = 0;
+ for (run = 0; run < run_count; ++run) {
+ offset = offsetruns[run].offset;
+ count = offsetruns[run].count;
+ dst_ptr = dst + loop_index*dst_subitemsize;
+ if (offset != -1) {
+ subtransfer(dst_ptr, dst_subitemsize,
+ src + offset, src_subitemsize,
+ count, src_subitemsize,
+ subdata);
+ }
+ else {
+ memset(dst_ptr, 0, count*dst_subitemsize);
+ }
+ loop_index += count;
+ }
+
+ src += src_stride;
+ dst += dst_stride;
+ --N;
+ }
+}
+
+
+static void
+_strided_to_strided_subarray_broadcast_withrefs(char *dst, npy_intp dst_stride,
+ char *src, npy_intp src_stride,
+ npy_intp N, npy_intp NPY_UNUSED(src_itemsize),
+ void *data)
+{
+ _subarray_broadcast_data *d = (_subarray_broadcast_data *)data;
+ PyArray_StridedTransferFn *subtransfer = d->stransfer;
+ void *subdata = d->data;
+ PyArray_StridedTransferFn *stransfer_decsrcref = d->stransfer_decsrcref;
+ void *data_decsrcref = d->data_decsrcref;
+ PyArray_StridedTransferFn *stransfer_decdstref = d->stransfer_decdstref;
+ void *data_decdstref = d->data_decdstref;
+ npy_intp run, run_count = d->run_count,
+ src_subitemsize = d->src_itemsize,
+ dst_subitemsize = d->dst_itemsize,
+ src_subN = d->src_N;
+ npy_intp loop_index, offset, count;
+ char *dst_ptr;
+ _subarray_broadcast_offsetrun *offsetruns = &d->offsetruns;
+
+ while (N > 0) {
+ loop_index = 0;
+ for (run = 0; run < run_count; ++run) {
+ offset = offsetruns[run].offset;
+ count = offsetruns[run].count;
+ dst_ptr = dst + loop_index*dst_subitemsize;
+ if (offset != -1) {
+ subtransfer(dst_ptr, dst_subitemsize,
+ src + offset, src_subitemsize,
+ count, src_subitemsize,
+ subdata);
+ }
+ else {
+ if (stransfer_decdstref != NULL) {
+ stransfer_decdstref(NULL, 0, dst_ptr, dst_subitemsize,
+ count, dst_subitemsize,
+ data_decdstref);
+ }
+ memset(dst_ptr, 0, count*dst_subitemsize);
+ }
+ loop_index += count;
+ }
+
+ if (stransfer_decsrcref != NULL) {
+ stransfer_decsrcref(NULL, 0, src, src_subitemsize,
+ src_subN, src_subitemsize,
+ data_decsrcref);
+ }
+
+ src += src_stride;
+ dst += dst_stride;
+ --N;
+ }
+}
+
+
+static int
+get_subarray_broadcast_transfer_function(int aligned,
+ npy_intp src_stride, npy_intp dst_stride,
+ PyArray_Descr *src_dtype, PyArray_Descr *dst_dtype,
+ npy_intp src_size, npy_intp dst_size,
+ PyArray_Dims src_shape, PyArray_Dims dst_shape,
+ int move_references,
+ PyArray_StridedTransferFn **out_stransfer,
+ void **out_transferdata,
+ int *out_needs_api)
+{
+ _subarray_broadcast_data *data;
+ npy_intp structsize, loop_index, run, run_size,
+ src_index, dst_index, i, ndim;
+ _subarray_broadcast_offsetrun *offsetruns;
+
+ structsize = sizeof(_subarray_broadcast_data) +
+ dst_size*sizeof(_subarray_broadcast_offsetrun);
+
+ /* Allocate the data and populate it */
+ data = (_subarray_broadcast_data *)PyArray_malloc(structsize);
+ if (data == NULL) {
+ PyErr_NoMemory();
+ return NPY_FAIL;
+ }
+
+ /*
+ * move_references is set to 0, handled in the wrapping transfer fn,
+ * src_stride and dst_stride are set to contiguous, as N will always
+ * be 1 when it's called.
+ */
+ if (PyArray_GetDTypeTransferFunction(aligned,
+ src_dtype->elsize, dst_dtype->elsize,
+ src_dtype, dst_dtype,
+ 0,
+ &data->stransfer, &data->data,
+ out_needs_api) != NPY_SUCCEED) {
+ PyArray_free(data);
+ return NPY_FAIL;
+ }
+ data->freefunc = &_subarray_broadcast_data_free;
+ data->copyfunc = &_subarray_broadcast_data_copy;
+ data->src_N = src_size;
+ data->dst_N = dst_size;
+ data->src_itemsize = src_dtype->elsize;
+ data->dst_itemsize = dst_dtype->elsize;
+
+ /* If the src object will need a DECREF */
+ if (move_references && PyDataType_REFCHK(src_dtype)) {
+ if (PyArray_GetDTypeTransferFunction(aligned,
+ src_dtype->elsize, 0,
+ src_dtype, NULL,
+ 1,
+ &data->stransfer_decsrcref,
+ &data->data_decsrcref,
+ out_needs_api) != NPY_SUCCEED) {
+ PyArray_FreeStridedTransferData(data->data);
+ PyArray_free(data);
+ return NPY_FAIL;
+ }
+ }
+ else {
+ data->stransfer_decsrcref = NULL;
+ data->data_decsrcref = NULL;
+ }
+
+ /* If the dst object needs a DECREF to set it to NULL */
+ if (PyDataType_REFCHK(dst_dtype)) {
+ if (PyArray_GetDTypeTransferFunction(aligned,
+ dst_dtype->elsize, 0,
+ dst_dtype, NULL,
+ 1,
+ &data->stransfer_decdstref,
+ &data->data_decdstref,
+ out_needs_api) != NPY_SUCCEED) {
+ PyArray_FreeStridedTransferData(data->data);
+ PyArray_FreeStridedTransferData(data->data_decsrcref);
+ PyArray_free(data);
+ return NPY_FAIL;
+ }
+ }
+ else {
+ data->stransfer_decdstref = NULL;
+ data->data_decdstref = NULL;
+ }
+
+ /* Calculate the broadcasting and set the offsets */
+ offsetruns = &data->offsetruns;
+ ndim = (src_shape.len > dst_shape.len) ? src_shape.len : dst_shape.len;
+ for (loop_index = 0; loop_index < dst_size; ++loop_index) {
+ npy_intp src_factor = 1;
+
+ dst_index = loop_index;
+ src_index = 0;
+ for (i = ndim-1; i >= 0; --i) {
+ npy_intp coord = 0, shape;
+
+ /* Get the dst coord of this index for dimension i */
+ if (i >= ndim - dst_shape.len) {
+ shape = dst_shape.ptr[i-(ndim-dst_shape.len)];
+ coord = dst_index % shape;
+ dst_index /= shape;
+ }
+
+ /* Translate it into a src coord and update src_index */
+ if (i >= ndim - src_shape.len) {
+ shape = src_shape.ptr[i-(ndim-src_shape.len)];
+ if (shape == 1) {
+ coord = 0;
+ }
+ else {
+ if (coord < shape) {
+ src_index += src_factor*coord;
+ src_factor *= shape;
+ }
+ else {
+ /* Out of bounds, flag with -1 */
+ src_index = -1;
+ break;
+ }
+ }
+ }
+ }
+ /* Set the offset */
+ if (src_index == -1) {
+ offsetruns[loop_index].offset = -1;
+ }
+ else {
+ offsetruns[loop_index].offset = src_index;
+ }
+ }
+
+ /* Run-length encode the result */
+ run = 0;
+ run_size = 1;
+ for (loop_index = 1; loop_index < dst_size; ++loop_index) {
+ if (offsetruns[run].offset == -1) {
+ /* Stop the run when there's a valid index again */
+ if (offsetruns[loop_index].offset != -1) {
+ offsetruns[run].count = run_size;
+ run++;
+ run_size = 1;
+ offsetruns[run].offset = offsetruns[loop_index].offset;
+ }
+ else {
+ run_size++;
+ }
+ }
+ else {
+ /* Stop the run when there's a valid index again */
+ if (offsetruns[loop_index].offset !=
+ offsetruns[loop_index-1].offset + 1) {
+ offsetruns[run].count = run_size;
+ run++;
+ run_size = 1;
+ offsetruns[run].offset = offsetruns[loop_index].offset;
+ }
+ else {
+ run_size++;
+ }
+ }
+ }
+ offsetruns[run].count = run_size;
+ run++;
+ data->run_count = run;
+
+ /* Multiply all the offsets by the src item size */
+ while (run--) {
+ if (offsetruns[run].offset != -1) {
+ offsetruns[run].offset *= src_dtype->elsize;
+ }
+ }
+
+ if (data->stransfer_decsrcref == NULL &&
+ data->stransfer_decdstref == NULL) {
+ *out_stransfer = &_strided_to_strided_subarray_broadcast;
+ }
+ else {
+ *out_stransfer = &_strided_to_strided_subarray_broadcast_withrefs;
+ }
+ *out_transferdata = data;
+
+ return NPY_SUCCEED;
+}
+
+/*
+ * Handles subarray transfer. To call this, at least one of the dtype's
+ * subarrays must be non-NULL
+ */
+static int
+get_subarray_transfer_function(int aligned,
+ npy_intp src_stride, npy_intp dst_stride,
+ PyArray_Descr *src_dtype, PyArray_Descr *dst_dtype,
+ int move_references,
+ PyArray_StridedTransferFn **out_stransfer,
+ void **out_transferdata,
+ int *out_needs_api)
+{
+ PyArray_Dims src_shape = {NULL, -1}, dst_shape = {NULL, -1};
+ npy_intp src_size = 1, dst_size = 1;
+
+ /* Get the subarray shapes and sizes */
+ if (src_dtype->subarray != NULL) {
+ if (!(PyArray_IntpConverter(src_dtype->subarray->shape,
+ &src_shape))) {
+ PyErr_SetString(PyExc_ValueError,
+ "invalid subarray shape");
+ return NPY_FAIL;
+ }
+ src_size = PyArray_MultiplyList(src_shape.ptr, src_shape.len);
+ src_dtype = src_dtype->subarray->base;
+ }
+ if (dst_dtype->subarray != NULL) {
+ if (!(PyArray_IntpConverter(dst_dtype->subarray->shape,
+ &dst_shape))) {
+ if (src_shape.ptr != NULL) {
+ PyDimMem_FREE(src_shape.ptr);
+ }
+ PyErr_SetString(PyExc_ValueError,
+ "invalid subarray shape");
+ return NPY_FAIL;
+ }
+ dst_size = PyArray_MultiplyList(dst_shape.ptr, dst_shape.len);
+ dst_dtype = dst_dtype->subarray->base;
+ }
+
+ /*
+ * Just a straight one-element copy.
+ */
+ if (dst_size == 1 && src_size == 1) {
+ PyDimMem_FREE(src_shape.ptr);
+ PyDimMem_FREE(dst_shape.ptr);
+
+ return PyArray_GetDTypeTransferFunction(aligned,
+ src_stride, dst_stride,
+ src_dtype, dst_dtype,
+ move_references,
+ out_stransfer, out_transferdata,
+ out_needs_api);
+ }
+ /* Copy the src value to all the dst values */
+ else if (src_size == 1) {
+ PyDimMem_FREE(src_shape.ptr);
+ PyDimMem_FREE(dst_shape.ptr);
+
+ return get_one_to_n_transfer_function(aligned,
+ src_stride, dst_stride,
+ src_dtype, dst_dtype,
+ move_references,
+ dst_size,
+ out_stransfer, out_transferdata,
+ out_needs_api);
+ }
+ /* If the shapes match exactly, do an n to n copy */
+ else if (src_shape.len == dst_shape.len &&
+ PyArray_CompareLists(src_shape.ptr, dst_shape.ptr,
+ src_shape.len)) {
+ PyDimMem_FREE(src_shape.ptr);
+ PyDimMem_FREE(dst_shape.ptr);
+
+ return get_n_to_n_transfer_function(aligned,
+ src_stride, dst_stride,
+ src_dtype, dst_dtype,
+ move_references,
+ src_size,
+ out_stransfer, out_transferdata,
+ out_needs_api);
+ }
+ /*
+ * Copy the subarray with broadcasting, truncating, and zero-padding
+ * as necessary.
+ */
+ else {
+ int ret = get_subarray_broadcast_transfer_function(aligned,
+ src_stride, dst_stride,
+ src_dtype, dst_dtype,
+ src_size, dst_size,
+ src_shape, dst_shape,
+ move_references,
+ out_stransfer, out_transferdata,
+ out_needs_api);
+
+ PyDimMem_FREE(src_shape.ptr);
+ PyDimMem_FREE(dst_shape.ptr);
+ return ret;
+ }
+}
+
+/**************************** COPY FIELDS *******************************/
+typedef struct {
+ npy_intp src_offset, dst_offset, src_itemsize;
+ PyArray_StridedTransferFn *stransfer;
+ void *data;
+} _single_field_transfer;
+
+typedef struct {
+ free_strided_transfer_data freefunc;
+ copy_strided_transfer_data copyfunc;
+ npy_intp field_count;
+
+ _single_field_transfer fields;
+} _field_transfer_data;
+
+/* transfer data free function */
+void _field_transfer_data_free(void *data)
+{
+ _field_transfer_data *d = (_field_transfer_data *)data;
+ npy_intp i, field_count;
+ _single_field_transfer *fields;
+
+ field_count = d->field_count;
+ fields = &d->fields;
+
+ for (i = 0; i < field_count; ++i) {
+ PyArray_FreeStridedTransferData(fields[i].data);
+ }
+ PyArray_free(d);
+}
+
+/* transfer data copy function */
+void *_field_transfer_data_copy(void *data)
+{
+ _field_transfer_data *d = (_field_transfer_data *)data;
+ _field_transfer_data *newdata;
+ npy_intp i, field_count = d->field_count, structsize;
+ _single_field_transfer *fields, *newfields;
+
+ structsize = sizeof(_field_transfer_data) +
+ field_count * sizeof(_single_field_transfer);
+
+ /* Allocate the data and populate it */
+ newdata = (_field_transfer_data *)PyArray_malloc(structsize);
+ if (newdata == NULL) {
+ return NULL;
+ }
+ memcpy(newdata, d, structsize);
+ /* Copy all the fields transfer data */
+ fields = &d->fields;
+ newfields = &newdata->fields;
+ for (i = 0; i < field_count; ++i) {
+ if (fields[i].data != NULL) {
+ newfields[i].data =
+ PyArray_CopyStridedTransferData(fields[i].data);
+ if (newfields[i].data == NULL) {
+ for (i = i-1; i >= 0; --i) {
+ PyArray_FreeStridedTransferData(newfields[i].data);
+ }
+ PyArray_free(newdata);
+ return NULL;
+ }
+ }
+
+ }
+
+ return (void *)newdata;
+}
+
+static void
+_strided_to_strided_field_transfer(char *dst, npy_intp dst_stride,
+ char *src, npy_intp src_stride,
+ npy_intp N, npy_intp NPY_UNUSED(src_itemsize),
+ void *data)
+{
+ _field_transfer_data *d = (_field_transfer_data *)data;
+ npy_intp i, field_count = d->field_count;
+ _single_field_transfer *field;
+
+ /* Do the transfer a block at a time */
+ for (;;) {
+ field = &d->fields;
+ if (N > NPY_LOWLEVEL_BUFFER_BLOCKSIZE) {
+ for (i = 0; i < field_count; ++i, ++field) {
+ field->stransfer(dst + field->dst_offset, dst_stride,
+ src + field->src_offset, src_stride,
+ NPY_LOWLEVEL_BUFFER_BLOCKSIZE,
+ field->src_itemsize,
+ field->data);
+ }
+ N -= NPY_LOWLEVEL_BUFFER_BLOCKSIZE;
+ src += NPY_LOWLEVEL_BUFFER_BLOCKSIZE*src_stride;
+ dst += NPY_LOWLEVEL_BUFFER_BLOCKSIZE*dst_stride;
+ }
+ else {
+ for (i = 0; i < field_count; ++i, ++field) {
+ field->stransfer(dst + field->dst_offset, dst_stride,
+ src + field->src_offset, src_stride,
+ N,
+ field->src_itemsize,
+ field->data);
+ }
+ return;
+ }
+ }
+}
+
+/*
+ * Handles fields transfer. To call this, at least one of the dtypes
+ * must have fields
+ */
+static int
+get_fields_transfer_function(int aligned,
+ npy_intp src_stride, npy_intp dst_stride,
+ PyArray_Descr *src_dtype, PyArray_Descr *dst_dtype,
+ int move_references,
+ PyArray_StridedTransferFn **out_stransfer,
+ void **out_transferdata,
+ int *out_needs_api)
+{
+ PyObject *names, *key, *tup, *title;
+ PyArray_Descr *src_fld_dtype, *dst_fld_dtype;
+ npy_int i, names_size, field_count, structsize;
+ int src_offset, dst_offset;
+ _field_transfer_data *data;
+ _single_field_transfer *fields;
+
+ /* Copy the src value to all the fields of dst */
+ if (!PyDescr_HASFIELDS(src_dtype)) {
+ names = dst_dtype->names;
+ names_size = PyTuple_GET_SIZE(dst_dtype->names);
+
+ field_count = names_size;
+ structsize = sizeof(_field_transfer_data) +
+ (field_count + 1) * sizeof(_single_field_transfer);
+ /* Allocate the data and populate it */
+ data = (_field_transfer_data *)PyArray_malloc(structsize);
+ if (data == NULL) {
+ PyErr_NoMemory();
+ return NPY_FAIL;
+ }
+ data->freefunc = &_field_transfer_data_free;
+ data->copyfunc = &_field_transfer_data_copy;
+ fields = &data->fields;
+
+ for (i = 0; i < names_size; ++i) {
+ key = PyTuple_GET_ITEM(names, i);
+ tup = PyDict_GetItem(dst_dtype->fields, key);
+ if (!PyArg_ParseTuple(tup, "Oi|O", &dst_fld_dtype,
+ &dst_offset, &title)) {
+ PyArray_free(data);
+ return NPY_FAIL;
+ }
+ if (PyArray_GetDTypeTransferFunction(0,
+ src_stride, dst_stride,
+ src_dtype, dst_fld_dtype,
+ 0,
+ &fields[i].stransfer,
+ &fields[i].data,
+ out_needs_api) != NPY_SUCCEED) {
+ for (i = i-1; i >= 0; --i) {
+ PyArray_FreeStridedTransferData(fields[i].data);
+ }
+ PyArray_free(data);
+ return NPY_FAIL;
+ }
+ fields[i].src_offset = 0;
+ fields[i].dst_offset = dst_offset;
+ fields[i].src_itemsize = src_dtype->elsize;
+ }
+
+ /*
+ * If the references should be removed from src, add
+ * another transfer function to do that.
+ */
+ if (move_references && PyDataType_REFCHK(src_dtype)) {
+ if (get_decsrcref_transfer_function(0,
+ src_stride,
+ src_dtype,
+ &fields[field_count].stransfer,
+ &fields[field_count].data,
+ out_needs_api) != NPY_SUCCEED) {
+ for (i = 0; i < field_count; ++i) {
+ PyArray_FreeStridedTransferData(fields[i].data);
+ }
+ PyArray_free(data);
+ return NPY_FAIL;
+ }
+ fields[field_count].src_offset = 0;
+ fields[field_count].dst_offset = 0;
+ fields[field_count].src_itemsize = src_dtype->elsize;
+ field_count++;
+ }
+ data->field_count = field_count;
+
+ *out_stransfer = &_strided_to_strided_field_transfer;
+ *out_transferdata = data;
+
+ return NPY_SUCCEED;
+ }
+ /* Copy the value of the first field to dst */
+ else if (!PyDescr_HASFIELDS(dst_dtype)) {
+ names = src_dtype->names;
+ names_size = PyTuple_GET_SIZE(src_dtype->names);
+
+ /*
+ * If DECREF is needed on source fields, may need
+ * to process all the fields
+ */
+ if (move_references && PyDataType_REFCHK(src_dtype)) {
+ field_count = names_size + 1;
+ }
+ else {
+ field_count = 1;
+ }
+ structsize = sizeof(_field_transfer_data) +
+ field_count * sizeof(_single_field_transfer);
+ /* Allocate the data and populate it */
+ data = (_field_transfer_data *)PyArray_malloc(structsize);
+ if (data == NULL) {
+ PyErr_NoMemory();
+ return NPY_FAIL;
+ }
+ data->freefunc = &_field_transfer_data_free;
+ data->copyfunc = &_field_transfer_data_copy;
+ fields = &data->fields;
+
+ key = PyTuple_GET_ITEM(names, 0);
+ tup = PyDict_GetItem(src_dtype->fields, key);
+ if (!PyArg_ParseTuple(tup, "Oi|O", &src_fld_dtype,
+ &src_offset, &title)) {
+ PyArray_free(data);
+ return NPY_FAIL;
+ }
+ field_count = 0;
+ /*
+ * Special case bool type, the existence of fields implies True
+ *
+ * TODO: Perhaps a better behavior would be to combine all the
+ * input fields with an OR? The same would apply to subarrays.
+ */
+ if (dst_dtype->type_num == NPY_BOOL) {
+ if (get_bool_setdstone_transfer_function(dst_stride,
+ &fields[field_count].stransfer,
+ &fields[field_count].data,
+ out_needs_api) != NPY_SUCCEED) {
+ PyArray_free(data);
+ return NPY_FAIL;
+ }
+ fields[field_count].src_offset = 0;
+ fields[field_count].dst_offset = 0;
+ fields[field_count].src_itemsize = 0;
+ field_count++;
+
+ /* If the src field has references, may need to clear them */
+ if (move_references && PyDataType_REFCHK(src_fld_dtype)) {
+ if (get_decsrcref_transfer_function(0,
+ src_stride,
+ src_fld_dtype,
+ &fields[field_count].stransfer,
+ &fields[field_count].data,
+ out_needs_api) != NPY_SUCCEED) {
+ PyArray_FreeStridedTransferData(fields[0].data);
+ PyArray_free(data);
+ return NPY_FAIL;
+ }
+ fields[field_count].src_offset = src_offset;
+ fields[field_count].dst_offset = 0;
+ fields[field_count].src_itemsize = src_fld_dtype->elsize;
+ field_count++;
+ }
+ }
+ /* Transfer the first field to the output */
+ else {
+ if (PyArray_GetDTypeTransferFunction(0,
+ src_stride, dst_stride,
+ src_fld_dtype, dst_dtype,
+ move_references,
+ &fields[field_count].stransfer,
+ &fields[field_count].data,
+ out_needs_api) != NPY_SUCCEED) {
+ PyArray_free(data);
+ return NPY_FAIL;
+ }
+ fields[field_count].src_offset = src_offset;
+ fields[field_count].dst_offset = 0;
+ fields[field_count].src_itemsize = src_fld_dtype->elsize;
+ field_count++;
+ }
+
+ /*
+ * If the references should be removed from src, add
+ * more transfer functions to decrement the references
+ * for all the other fields.
+ */
+ if (move_references && PyDataType_REFCHK(src_dtype)) {
+ for (i = 1; i < names_size; ++i) {
+ key = PyTuple_GET_ITEM(names, i);
+ tup = PyDict_GetItem(src_dtype->fields, key);
+ if (!PyArg_ParseTuple(tup, "Oi|O", &src_fld_dtype,
+ &src_offset, &title)) {
+ return NPY_FAIL;
+ }
+ if (PyDataType_REFCHK(src_fld_dtype)) {
+ if (get_decsrcref_transfer_function(0,
+ src_stride,
+ src_fld_dtype,
+ &fields[field_count].stransfer,
+ &fields[field_count].data,
+ out_needs_api) != NPY_SUCCEED) {
+ for (i = field_count-1; i >= 0; --i) {
+ PyArray_FreeStridedTransferData(fields[i].data);
+ }
+ PyArray_free(data);
+ return NPY_FAIL;
+ }
+ fields[field_count].src_offset = src_offset;
+ fields[field_count].dst_offset = 0;
+ fields[field_count].src_itemsize = src_fld_dtype->elsize;
+ field_count++;
+ }
+ }
+ }
+
+ data->field_count = field_count;
+
+ *out_stransfer = &_strided_to_strided_field_transfer;
+ *out_transferdata = data;
+
+ return NPY_SUCCEED;
+ }
+ /* Match up the fields to copy */
+ else {
+ /* Keeps track of the names we already used */
+ PyObject *used_names_dict = NULL;
+
+ names = dst_dtype->names;
+ names_size = PyTuple_GET_SIZE(dst_dtype->names);
+
+ /*
+ * If DECREF is needed on source fields, will need
+ * to also go through its fields.
+ */
+ if (move_references && PyDataType_REFCHK(src_dtype)) {
+ field_count = names_size + PyTuple_GET_SIZE(src_dtype->names);
+ used_names_dict = PyDict_New();
+ if (used_names_dict == NULL) {
+ return NPY_FAIL;
+ }
+ }
+ else {
+ field_count = names_size;
+ }
+ structsize = sizeof(_field_transfer_data) +
+ field_count * sizeof(_single_field_transfer);
+ /* Allocate the data and populate it */
+ data = (_field_transfer_data *)PyArray_malloc(structsize);
+ if (data == NULL) {
+ PyErr_NoMemory();
+ Py_XDECREF(used_names_dict);
+ return NPY_FAIL;
+ }
+ data->freefunc = &_field_transfer_data_free;
+ data->copyfunc = &_field_transfer_data_copy;
+ fields = &data->fields;
+
+ for (i = 0; i < names_size; ++i) {
+ key = PyTuple_GET_ITEM(names, i);
+ tup = PyDict_GetItem(dst_dtype->fields, key);
+ if (!PyArg_ParseTuple(tup, "Oi|O", &dst_fld_dtype,
+ &dst_offset, &title)) {
+ for (i = i-1; i >= 0; --i) {
+ PyArray_FreeStridedTransferData(fields[i].data);
+ }
+ PyArray_free(data);
+ Py_XDECREF(used_names_dict);
+ return NPY_FAIL;
+ }
+ tup = PyDict_GetItem(src_dtype->fields, key);
+ if (tup != NULL) {
+ if (!PyArg_ParseTuple(tup, "Oi|O", &src_fld_dtype,
+ &src_offset, &title)) {
+ for (i = i-1; i >= 0; --i) {
+ PyArray_FreeStridedTransferData(fields[i].data);
+ }
+ PyArray_free(data);
+ Py_XDECREF(used_names_dict);
+ return NPY_FAIL;
+ }
+ if (PyArray_GetDTypeTransferFunction(0,
+ src_stride, dst_stride,
+ src_fld_dtype, dst_fld_dtype,
+ move_references,
+ &fields[i].stransfer,
+ &fields[i].data,
+ out_needs_api) != NPY_SUCCEED) {
+ for (i = i-1; i >= 0; --i) {
+ PyArray_FreeStridedTransferData(fields[i].data);
+ }
+ PyArray_free(data);
+ Py_XDECREF(used_names_dict);
+ return NPY_FAIL;
+ }
+ fields[i].src_offset = src_offset;
+ fields[i].dst_offset = dst_offset;
+ fields[i].src_itemsize = src_fld_dtype->elsize;
+
+ if (used_names_dict != NULL) {
+ PyDict_SetItem(used_names_dict, key, Py_True);
+ }
+ }
+ else {
+ if (get_setdstzero_transfer_function(0,
+ dst_stride,
+ dst_fld_dtype,
+ &fields[i].stransfer,
+ &fields[i].data,
+ out_needs_api) != NPY_SUCCEED) {
+ for (i = i-1; i >= 0; --i) {
+ PyArray_FreeStridedTransferData(fields[i].data);
+ }
+ PyArray_free(data);
+ Py_XDECREF(used_names_dict);
+ return NPY_FAIL;
+ }
+ fields[i].src_offset = 0;
+ fields[i].dst_offset = dst_offset;
+ fields[i].src_itemsize = 0;
+ }
+ }
+
+ if (move_references && PyDataType_REFCHK(src_dtype)) {
+ /* Use field_count to track additional functions added */
+ field_count = names_size;
+
+ names = src_dtype->names;
+ names_size = PyTuple_GET_SIZE(src_dtype->names);
+ for (i = 0; i < names_size; ++i) {
+ key = PyTuple_GET_ITEM(names, i);
+ if (PyDict_GetItem(used_names_dict, key) == NULL) {
+ tup = PyDict_GetItem(src_dtype->fields, key);
+ if (!PyArg_ParseTuple(tup, "Oi|O", &src_fld_dtype,
+ &src_offset, &title)) {
+ for (i = field_count-1; i >= 0; --i) {
+ PyArray_FreeStridedTransferData(fields[i].data);
+ }
+ PyArray_free(data);
+ Py_XDECREF(used_names_dict);
+ return NPY_FAIL;
+ }
+ if (PyDataType_REFCHK(src_fld_dtype)) {
+ if (get_decsrcref_transfer_function(0,
+ src_stride,
+ src_fld_dtype,
+ &fields[field_count].stransfer,
+ &fields[field_count].data,
+ out_needs_api) != NPY_SUCCEED) {
+ for (i = field_count-1; i >= 0; --i) {
+ PyArray_FreeStridedTransferData(fields[i].data);
+ }
+ PyArray_free(data);
+ return NPY_FAIL;
+ }
+ fields[field_count].src_offset = src_offset;
+ fields[field_count].dst_offset = 0;
+ fields[field_count].src_itemsize =
+ src_fld_dtype->elsize;
+ field_count++;
+ }
+ }
+ }
+ }
+
+ Py_XDECREF(used_names_dict);
+
+ data->field_count = field_count;
+
+ *out_stransfer = &_strided_to_strided_field_transfer;
+ *out_transferdata = data;
+
+ return NPY_SUCCEED;
+ }
+}
+
+static int
+get_decsrcref_fields_transfer_function(int aligned,
+ npy_intp src_stride,
+ PyArray_Descr *src_dtype,
+ PyArray_StridedTransferFn **out_stransfer,
+ void **out_transferdata,
+ int *out_needs_api)
+{
+ PyObject *names, *key, *tup, *title;
+ PyArray_Descr *src_fld_dtype;
+ npy_int i, names_size, field_count, structsize;
+ int src_offset;
+ _field_transfer_data *data;
+ _single_field_transfer *fields;
+
+ names = src_dtype->names;
+ names_size = PyTuple_GET_SIZE(src_dtype->names);
+
+ field_count = names_size;
+ structsize = sizeof(_field_transfer_data) +
+ field_count * sizeof(_single_field_transfer);
+ /* Allocate the data and populate it */
+ data = (_field_transfer_data *)PyArray_malloc(structsize);
+ if (data == NULL) {
+ PyErr_NoMemory();
+ return NPY_FAIL;
+ }
+ data->freefunc = &_field_transfer_data_free;
+ data->copyfunc = &_field_transfer_data_copy;
+ fields = &data->fields;
+
+ field_count = 0;
+ for (i = 0; i < names_size; ++i) {
+ key = PyTuple_GET_ITEM(names, i);
+ tup = PyDict_GetItem(src_dtype->fields, key);
+ if (!PyArg_ParseTuple(tup, "Oi|O", &src_fld_dtype,
+ &src_offset, &title)) {
+ PyArray_free(data);
+ return NPY_FAIL;
+ }
+ if (PyDataType_REFCHK(src_fld_dtype)) {
+ if (out_needs_api) {
+ *out_needs_api = 1;
+ }
+ if (get_decsrcref_transfer_function(0,
+ src_stride,
+ src_fld_dtype,
+ &fields[field_count].stransfer,
+ &fields[field_count].data,
+ out_needs_api) != NPY_SUCCEED) {
+ for (i = field_count-1; i >= 0; --i) {
+ PyArray_FreeStridedTransferData(fields[i].data);
+ }
+ PyArray_free(data);
+ return NPY_FAIL;
+ }
+ fields[field_count].src_offset = src_offset;
+ fields[field_count].dst_offset = 0;
+ fields[field_count].src_itemsize = src_dtype->elsize;
+ field_count++;
+ }
+ }
+
+ data->field_count = field_count;
+
+ *out_stransfer = &_strided_to_strided_field_transfer;
+ *out_transferdata = data;
+
+ return NPY_SUCCEED;
+}
+
+static int
+get_setdestzero_fields_transfer_function(int aligned,
+ npy_intp dst_stride,
+ PyArray_Descr *dst_dtype,
+ PyArray_StridedTransferFn **out_stransfer,
+ void **out_transferdata,
+ int *out_needs_api)
+{
+ PyObject *names, *key, *tup, *title;
+ PyArray_Descr *dst_fld_dtype;
+ npy_int i, names_size, field_count, structsize;
+ int dst_offset;
+ _field_transfer_data *data;
+ _single_field_transfer *fields;
+
+ names = dst_dtype->names;
+ names_size = PyTuple_GET_SIZE(dst_dtype->names);
+
+ field_count = names_size;
+ structsize = sizeof(_field_transfer_data) +
+ field_count * sizeof(_single_field_transfer);
+ /* Allocate the data and populate it */
+ data = (_field_transfer_data *)PyArray_malloc(structsize);
+ if (data == NULL) {
+ PyErr_NoMemory();
+ return NPY_FAIL;
+ }
+ data->freefunc = &_field_transfer_data_free;
+ data->copyfunc = &_field_transfer_data_copy;
+ fields = &data->fields;
+
+ for (i = 0; i < names_size; ++i) {
+ key = PyTuple_GET_ITEM(names, i);
+ tup = PyDict_GetItem(dst_dtype->fields, key);
+ if (!PyArg_ParseTuple(tup, "Oi|O", &dst_fld_dtype,
+ &dst_offset, &title)) {
+ PyArray_free(data);
+ return NPY_FAIL;
+ }
+ if (get_setdstzero_transfer_function(0,
+ dst_stride,
+ dst_fld_dtype,
+ &fields[i].stransfer,
+ &fields[i].data,
+ out_needs_api) != NPY_SUCCEED) {
+ for (i = i-1; i >= 0; --i) {
+ PyArray_FreeStridedTransferData(fields[i].data);
+ }
+ PyArray_free(data);
+ return NPY_FAIL;
+ }
+ fields[i].src_offset = 0;
+ fields[i].dst_offset = dst_offset;
+ fields[i].src_itemsize = 0;
+ }
+
+ data->field_count = field_count;
+
+ *out_stransfer = &_strided_to_strided_field_transfer;
+ *out_transferdata = data;
+
+ return NPY_SUCCEED;
+}
+
+/************************* DEST BOOL SETONE *******************************/
+
+static void
+_null_to_strided_set_bool_one(char *dst,
+ npy_intp dst_stride,
+ char *NPY_UNUSED(src), npy_intp NPY_UNUSED(src_stride),
+ npy_intp N, npy_intp NPY_UNUSED(src_itemsize),
+ void *NPY_UNUSED(data))
+{
+ /* bool type is one byte, so can just use the char */
+
+ while (N > 0) {
+ *dst = 1;
+
+ dst += dst_stride;
+ --N;
+ }
+}
+
+static void
+_null_to_contig_set_bool_one(char *dst,
+ npy_intp NPY_UNUSED(dst_stride),
+ char *NPY_UNUSED(src), npy_intp NPY_UNUSED(src_stride),
+ npy_intp N, npy_intp NPY_UNUSED(src_itemsize),
+ void *NPY_UNUSED(data))
+{
+ /* bool type is one byte, so can just use the char */
+
+ memset(dst, 1, N);
+}
+
+/* Only for the bool type, sets the destination to 1 */
+NPY_NO_EXPORT int
+get_bool_setdstone_transfer_function(npy_intp dst_stride,
+ PyArray_StridedTransferFn **out_stransfer,
+ void **out_transferdata,
+ int *NPY_UNUSED(out_needs_api))
+{
+ if (dst_stride == 1) {
+ *out_stransfer = &_null_to_contig_set_bool_one;
+ }
+ else {
+ *out_stransfer = &_null_to_strided_set_bool_one;
+ }
+ *out_transferdata = NULL;
+
+ return NPY_SUCCEED;
+}
+
+/*************************** DEST SETZERO *******************************/
+
+/* Sets dest to zero */
+typedef struct {
+ free_strided_transfer_data freefunc;
+ copy_strided_transfer_data copyfunc;
+ npy_intp dst_itemsize;
+} _dst_memset_zero_data;
+
+/* zero-padded data copy function */
+void *_dst_memset_zero_data_copy(void *data)
+{
+ _dst_memset_zero_data *newdata =
+ (_dst_memset_zero_data *)PyArray_malloc(
+ sizeof(_dst_memset_zero_data));
+ if (newdata == NULL) {
+ return NULL;
+ }
+
+ memcpy(newdata, data, sizeof(_dst_memset_zero_data));
+
+ return newdata;
+}
+
+static void
+_null_to_strided_memset_zero(char *dst,
+ npy_intp dst_stride,
+ char *NPY_UNUSED(src), npy_intp NPY_UNUSED(src_stride),
+ npy_intp N, npy_intp NPY_UNUSED(src_itemsize),
+ void *data)
+{
+ _dst_memset_zero_data *d = (_dst_memset_zero_data *)data;
+ npy_intp dst_itemsize = d->dst_itemsize;
+
+ while (N > 0) {
+ memset(dst, 0, dst_itemsize);
+ dst += dst_stride;
+ --N;
+ }
+}
+
+static void
+_null_to_contig_memset_zero(char *dst,
+ npy_intp dst_stride,
+ char *NPY_UNUSED(src), npy_intp NPY_UNUSED(src_stride),
+ npy_intp N, npy_intp NPY_UNUSED(src_itemsize),
+ void *data)
+{
+ _dst_memset_zero_data *d = (_dst_memset_zero_data *)data;
+ npy_intp dst_itemsize = d->dst_itemsize;
+
+ memset(dst, 0, N*dst_itemsize);
+}
+
+static void
+_null_to_strided_reference_setzero(char *dst,
+ npy_intp dst_stride,
+ char *NPY_UNUSED(src), npy_intp NPY_UNUSED(src_stride),
+ npy_intp N, npy_intp NPY_UNUSED(src_itemsize),
+ void *NPY_UNUSED(data))
+{
+ PyObject *dst_ref = NULL;
+
+ while (N > 0) {
+ NPY_COPY_PYOBJECT_PTR(&dst_ref, dst);
+
+ /* Release the reference in dst */
+ NPY_DT_DBG_REFTRACE("dec dest ref (to set zero)", dst_ref);
+ Py_XDECREF(dst_ref);
+
+ /* Set it to zero */
+ dst_ref = NULL;
+ NPY_COPY_PYOBJECT_PTR(dst, &dst_ref);
+
+ dst += dst_stride;
+ --N;
+ }
+}
+
+NPY_NO_EXPORT int
+get_setdstzero_transfer_function(int aligned,
+ npy_intp dst_stride,
+ PyArray_Descr *dst_dtype,
+ PyArray_StridedTransferFn **out_stransfer,
+ void **out_transferdata,
+ int *out_needs_api)
+{
+ _dst_memset_zero_data *data;
+
+ /* If there are no references, just set the whole thing to zero */
+ if (!PyDataType_REFCHK(dst_dtype)) {
+ data = (_dst_memset_zero_data *)
+ PyArray_malloc(sizeof(_dst_memset_zero_data));
+ if (data == NULL) {
+ PyErr_NoMemory();
+ return NPY_FAIL;
+ }
+
+ data->freefunc = &PyArray_free;
+ data->copyfunc = &_dst_memset_zero_data_copy;
+ data->dst_itemsize = dst_dtype->elsize;
+
+ if (dst_stride == data->dst_itemsize) {
+ *out_stransfer = &_null_to_contig_memset_zero;
+ }
+ else {
+ *out_stransfer = &_null_to_strided_memset_zero;
+ }
+ *out_transferdata = data;
+ }
+ /* If it's exactly one reference, use the decref function */
+ else if (dst_dtype->type_num == NPY_OBJECT) {
+ if (out_needs_api) {
+ *out_needs_api = 1;
+ }
+
+ *out_stransfer = &_null_to_strided_reference_setzero;
+ *out_transferdata = NULL;
+ }
+ /* If there are subarrays, need to wrap it */
+ else if (dst_dtype->subarray != NULL) {
+ PyArray_Dims dst_shape = {NULL, -1};
+ npy_intp dst_size = 1;
+ PyArray_StridedTransferFn *contig_stransfer;
+ void *contig_data;
+
+ if (out_needs_api) {
+ *out_needs_api = 1;
+ }
+
+ if (!(PyArray_IntpConverter(dst_dtype->subarray->shape,
+ &dst_shape))) {
+ PyErr_SetString(PyExc_ValueError,
+ "invalid subarray shape");
+ return NPY_FAIL;
+ }
+ dst_size = PyArray_MultiplyList(dst_shape.ptr, dst_shape.len);
+ PyDimMem_FREE(dst_shape.ptr);
+
+ /* Get a function for contiguous dst of the subarray type */
+ if (get_setdstzero_transfer_function(aligned,
+ dst_dtype->subarray->base->elsize,
+ dst_dtype->subarray->base,
+ &contig_stransfer, &contig_data,
+ out_needs_api) != NPY_SUCCEED) {
+ return NPY_FAIL;
+ }
+
+ if (wrap_transfer_function_n_to_n(contig_stransfer, contig_data,
+ 0, dst_stride,
+ 0, dst_dtype->subarray->base->elsize,
+ dst_size,
+ out_stransfer, out_transferdata) != NPY_SUCCEED) {
+ PyArray_FreeStridedTransferData(contig_data);
+ return NPY_FAIL;
+ }
+ }
+ /* If there are fields, need to do each field */
+ else if (PyDataType_HASFIELDS(dst_dtype)) {
+ if (out_needs_api) {
+ *out_needs_api = 1;
+ }
+
+ return get_setdestzero_fields_transfer_function(aligned,
+ dst_stride, dst_dtype,
+ out_stransfer,
+ out_transferdata,
+ out_needs_api);
+ }
+
+ return NPY_SUCCEED;
+}
+
+static void
+_dec_src_ref_nop(char *NPY_UNUSED(dst),
+ npy_intp NPY_UNUSED(dst_stride),
+ char *NPY_UNUSED(src), npy_intp NPY_UNUSED(src_stride),
+ npy_intp NPY_UNUSED(N),
+ npy_intp NPY_UNUSED(src_itemsize),
+ void *NPY_UNUSED(data))
+{
+ /* NOP */
+}
+
+static void
+_strided_to_null_dec_src_ref_reference(char *NPY_UNUSED(dst),
+ npy_intp NPY_UNUSED(dst_stride),
+ char *src, npy_intp src_stride,
+ npy_intp N,
+ npy_intp NPY_UNUSED(src_itemsize),
+ void *NPY_UNUSED(data))
+{
+ PyObject *src_ref = NULL;
+ while (N > 0) {
+ NPY_COPY_PYOBJECT_PTR(&src_ref, src);
+
+ /* Release the reference in src */
+ NPY_DT_DBG_REFTRACE("dec src ref (null dst)", src_ref);
+ Py_XDECREF(src_ref);
+
+ src += src_stride;
+ --N;
+ }
+}
+
+
+NPY_NO_EXPORT int
+get_decsrcref_transfer_function(int aligned,
+ npy_intp src_stride,
+ PyArray_Descr *src_dtype,
+ PyArray_StridedTransferFn **out_stransfer,
+ void **out_transferdata,
+ int *out_needs_api)
+{
+ /* If there are no references, it's a nop */
+ if (!PyDataType_REFCHK(src_dtype)) {
+ *out_stransfer = &_dec_src_ref_nop;
+ *out_transferdata = NULL;
+
+ return NPY_SUCCEED;
+ }
+ /* If it's a single reference, it's one decref */
+ else if (src_dtype->type_num == NPY_OBJECT) {
+ if (out_needs_api) {
+ *out_needs_api = 1;
+ }
+
+ *out_stransfer = &_strided_to_null_dec_src_ref_reference;
+ *out_transferdata = NULL;
+
+ return NPY_SUCCEED;
+ }
+ /* If there are subarrays, need to wrap it */
+ else if (src_dtype->subarray != NULL) {
+ PyArray_Dims src_shape = {NULL, -1};
+ npy_intp src_size = 1;
+ PyArray_StridedTransferFn *stransfer;
+ void *data;
+
+ if (out_needs_api) {
+ *out_needs_api = 1;
+ }
+
+ if (!(PyArray_IntpConverter(src_dtype->subarray->shape,
+ &src_shape))) {
+ PyErr_SetString(PyExc_ValueError,
+ "invalid subarray shape");
+ return NPY_FAIL;
+ }
+ src_size = PyArray_MultiplyList(src_shape.ptr, src_shape.len);
+ PyDimMem_FREE(src_shape.ptr);
+
+ /* Get a function for contiguous src of the subarray type */
+ if (get_decsrcref_transfer_function(aligned,
+ src_dtype->subarray->base->elsize,
+ src_dtype->subarray->base,
+ &stransfer, &data,
+ out_needs_api) != NPY_SUCCEED) {
+ return NPY_FAIL;
+ }
+
+ if (wrap_transfer_function_n_to_n(stransfer, data,
+ src_stride, 0,
+ src_dtype->subarray->base->elsize, 0,
+ src_size,
+ out_stransfer, out_transferdata) != NPY_SUCCEED) {
+ PyArray_FreeStridedTransferData(data);
+ return NPY_FAIL;
+ }
+
+ return NPY_SUCCEED;
+ }
+ /* If there are fields, need to do each field */
+ else {
+ if (out_needs_api) {
+ *out_needs_api = 1;
+ }
+
+ return get_decsrcref_fields_transfer_function(aligned,
+ src_stride, src_dtype,
+ out_stransfer,
+ out_transferdata,
+ out_needs_api);
+ }
+}
+
+/********************* MAIN DTYPE TRANSFER FUNCTION ***********************/
+
+NPY_NO_EXPORT int
+PyArray_GetDTypeTransferFunction(int aligned,
+ npy_intp src_stride, npy_intp dst_stride,
+ PyArray_Descr *src_dtype, PyArray_Descr *dst_dtype,
+ int move_references,
+ PyArray_StridedTransferFn **out_stransfer,
+ void **out_transferdata,
+ int *out_needs_api)
+{
+ npy_intp src_itemsize, dst_itemsize;
+ int src_type_num, dst_type_num;
+
+#if NPY_DT_DBG_TRACING
+ printf("Calculating dtype transfer from ");
+ PyObject_Print((PyObject *)src_dtype, stdout, 0);
+ printf(" to ");
+ PyObject_Print((PyObject *)dst_dtype, stdout, 0);
+ printf("\n");
+#endif
+
+ /*
+ * If one of the dtypes is NULL, we give back either a src decref
+ * function or a dst setzero function
+ */
+ if (dst_dtype == NULL) {
+ if (move_references) {
+ return get_decsrcref_transfer_function(aligned,
+ src_dtype->elsize,
+ src_dtype,
+ out_stransfer, out_transferdata,
+ out_needs_api);
+ }
+ else {
+ *out_stransfer = &_dec_src_ref_nop;
+ *out_transferdata = NULL;
+ return NPY_SUCCEED;
+ }
+ }
+ else if (src_dtype == NULL) {
+ return get_setdstzero_transfer_function(aligned,
+ dst_dtype->elsize,
+ dst_dtype,
+ out_stransfer, out_transferdata,
+ out_needs_api);
+ }
+
+ src_itemsize = src_dtype->elsize;
+ dst_itemsize = dst_dtype->elsize;
+ src_type_num = src_dtype->type_num;
+ dst_type_num = dst_dtype->type_num;
+
+ /* Common special case - number -> number NBO cast */
+ if (PyTypeNum_ISNUMBER(src_type_num) &&
+ PyTypeNum_ISNUMBER(dst_type_num) &&
+ PyArray_ISNBO(src_dtype->byteorder) &&
+ PyArray_ISNBO(dst_dtype->byteorder)) {
+ if (PyArray_EquivTypenums(src_type_num, dst_type_num)) {
+ *out_stransfer = PyArray_GetStridedCopyFn(aligned,
+ src_stride, dst_stride,
+ src_itemsize);
+ *out_transferdata = NULL;
+ return (*out_stransfer == NULL) ? NPY_FAIL : NPY_SUCCEED;
+ }
+ else {
+ return get_nbo_cast_numeric_transfer_function (aligned,
+ src_stride, dst_stride,
+ src_type_num, dst_type_num,
+ out_stransfer, out_transferdata);
+ }
+ }
+
+ /*
+ * If there are no references and the data types are equivalent,
+ * return a simple copy
+ */
+ if (!PyDataType_REFCHK(src_dtype) && !PyDataType_REFCHK(dst_dtype) &&
+ PyArray_EquivTypes(src_dtype, dst_dtype)) {
+ /*
+ * We can't pass through the aligned flag because it's not
+ * appropriate. Consider a size-8 string, it will say it's
+ * aligned because strings only need alignment 1, but the
+ * copy function wants to know if it's alignment 8.
+ *
+ * TODO: Change align from a flag to a "best power of 2 alignment"
+ * which holds the strongest alignment value for all
+ * the data which will be used.
+ */
+ *out_stransfer = PyArray_GetStridedCopyFn(0,
+ src_stride, dst_stride,
+ src_dtype->elsize);
+ *out_transferdata = NULL;
+ return NPY_SUCCEED;
+ }
+
+ /* First look at the possibilities of just a copy or swap */
+ if (src_itemsize == dst_itemsize && src_dtype->kind == dst_dtype->kind &&
+ !PyDataType_HASFIELDS(src_dtype) &&
+ !PyDataType_HASFIELDS(dst_dtype) &&
+ src_dtype->subarray == NULL && dst_dtype->subarray == NULL) {
+ /* A custom data type requires that we use its copy/swap */
+ if (src_type_num >= NPY_NTYPES || dst_type_num >= NPY_NTYPES) {
+ /*
+ * If the sizes and kinds are identical, but they're different
+ * custom types, then get a cast function
+ */
+ if (src_type_num != dst_type_num) {
+ return get_cast_transfer_function(aligned,
+ src_stride, dst_stride,
+ src_dtype, dst_dtype,
+ move_references,
+ out_stransfer, out_transferdata,
+ out_needs_api);
+ }
+ else {
+ return wrap_copy_swap_function(aligned,
+ src_stride, dst_stride,
+ src_dtype,
+ PyArray_ISNBO(src_dtype->byteorder) !=
+ PyArray_ISNBO(dst_dtype->byteorder),
+ out_stransfer, out_transferdata);
+ }
+
+
+ }
+
+ /* The special types, which have no byte-order */
+ switch (src_type_num) {
+ case NPY_VOID:
+ case NPY_STRING:
+ case NPY_UNICODE:
+ *out_stransfer = PyArray_GetStridedCopyFn(0,
+ src_stride, dst_stride,
+ src_itemsize);
+ *out_transferdata = NULL;
+ return NPY_SUCCEED;
+ case NPY_OBJECT:
+ if (out_needs_api) {
+ *out_needs_api = 1;
+ }
+ if (move_references) {
+ *out_stransfer = &_strided_to_strided_move_references;
+ *out_transferdata = NULL;
+ }
+ else {
+ *out_stransfer = &_strided_to_strided_copy_references;
+ *out_transferdata = NULL;
+ }
+ return NPY_SUCCEED;
+ }
+
+ /* This is a straight copy */
+ if (src_itemsize == 1 || PyArray_ISNBO(src_dtype->byteorder) ==
+ PyArray_ISNBO(dst_dtype->byteorder)) {
+ *out_stransfer = PyArray_GetStridedCopyFn(aligned,
+ src_stride, dst_stride,
+ src_itemsize);
+ *out_transferdata = NULL;
+ return (*out_stransfer == NULL) ? NPY_FAIL : NPY_SUCCEED;
+ }
+ /* This is a straight copy + byte swap */
+ else if (!PyTypeNum_ISCOMPLEX(src_type_num)) {
+ *out_stransfer = PyArray_GetStridedCopySwapFn(aligned,
+ src_stride, dst_stride,
+ src_itemsize);
+ *out_transferdata = NULL;
+ return (*out_stransfer == NULL) ? NPY_FAIL : NPY_SUCCEED;
+ }
+ /* This is a straight copy + element pair byte swap */
+ else {
+ *out_stransfer = PyArray_GetStridedCopySwapPairFn(aligned,
+ src_stride, dst_stride,
+ src_itemsize);
+ *out_transferdata = NULL;
+ return (*out_stransfer == NULL) ? NPY_FAIL : NPY_SUCCEED;
+ }
+ }
+
+ /* Handle subarrays */
+ if (src_dtype->subarray != NULL || dst_dtype->subarray != NULL) {
+ return get_subarray_transfer_function(aligned,
+ src_stride, dst_stride,
+ src_dtype, dst_dtype,
+ move_references,
+ out_stransfer, out_transferdata,
+ out_needs_api);
+ }
+
+ /* Handle fields */
+ if (PyDataType_HASFIELDS(src_dtype) ||
+ PyDataType_HASFIELDS(dst_dtype)) {
+ return get_fields_transfer_function(aligned,
+ src_stride, dst_stride,
+ src_dtype, dst_dtype,
+ move_references,
+ out_stransfer, out_transferdata,
+ out_needs_api);
+ }
+
+ /* Check for different-sized strings, unicodes, or voids */
+ if (src_type_num == dst_type_num) {
+ switch (src_type_num) {
+ case NPY_STRING:
+ case NPY_UNICODE:
+ case NPY_VOID:
+ return PyArray_GetStridedZeroPadCopyFn(0,
+ src_stride, dst_stride,
+ src_dtype->elsize, dst_dtype->elsize,
+ out_stransfer, out_transferdata);
+ }
+ }
+
+ /* Otherwise a cast is necessary */
+ return get_cast_transfer_function(aligned,
+ src_stride, dst_stride,
+ src_dtype, dst_dtype,
+ move_references,
+ out_stransfer, out_transferdata,
+ out_needs_api);
+}
diff --git a/numpy/core/src/multiarray/einsum.c.src b/numpy/core/src/multiarray/einsum.c.src
new file mode 100644
index 000000000..ab939f734
--- /dev/null
+++ b/numpy/core/src/multiarray/einsum.c.src
@@ -0,0 +1,3115 @@
+/*
+ * This file contains the implementation of the 'einsum' function,
+ * which provides an einstein-summation operation.
+ *
+ * Copyright (c) 2011 by Mark Wiebe (mwwiebe@gmail.com)
+ * The Univerity of British Columbia
+ *
+ * See LICENSE.txt for the license.
+ */
+
+#define PY_SSIZE_T_CLEAN
+#include "Python.h"
+#include "structmember.h"
+
+#define _MULTIARRAYMODULE
+#include <numpy/ndarrayobject.h>
+#include <numpy/halffloat.h>
+#include <numpy/npy_3kcompat.h>
+
+#include <ctype.h>
+
+#include "convert.h"
+
+#ifdef __SSE__
+#define EINSUM_USE_SSE1 1
+#else
+#define EINSUM_USE_SSE1 0
+#endif
+
+/*
+ * TODO: Only some SSE2 for float64 is implemented.
+ */
+#ifdef __SSE2__
+#define EINSUM_USE_SSE2 1
+#else
+#define EINSUM_USE_SSE2 0
+#endif
+
+#if EINSUM_USE_SSE1
+#include <xmmintrin.h>
+#endif
+
+#if EINSUM_USE_SSE2
+#include <emmintrin.h>
+#endif
+
+#define EINSUM_IS_SSE_ALIGNED(x) ((((npy_intp)x)&0xf) == 0)
+
+/********** PRINTF DEBUG TRACING **************/
+#define NPY_EINSUM_DBG_TRACING 0
+
+#if NPY_EINSUM_DBG_TRACING
+#define NPY_EINSUM_DBG_PRINT(s) printf("%s", s);
+#define NPY_EINSUM_DBG_PRINT1(s, p1) printf(s, p1);
+#define NPY_EINSUM_DBG_PRINT2(s, p1, p2) printf(s, p1, p2);
+#define NPY_EINSUM_DBG_PRINT3(s, p1, p2, p3) printf(s);
+#else
+#define NPY_EINSUM_DBG_PRINT(s)
+#define NPY_EINSUM_DBG_PRINT1(s, p1)
+#define NPY_EINSUM_DBG_PRINT2(s, p1, p2)
+#define NPY_EINSUM_DBG_PRINT3(s, p1, p2, p3)
+#endif
+/**********************************************/
+
+typedef enum {
+ BROADCAST_NONE,
+ BROADCAST_LEFT,
+ BROADCAST_RIGHT,
+ BROADCAST_MIDDLE
+} EINSUM_BROADCAST;
+
+/**begin repeat
+ * #name = byte, short, int, long, longlong,
+ * ubyte, ushort, uint, ulong, ulonglong,
+ * half, float, double, longdouble,
+ * cfloat, cdouble, clongdouble#
+ * #temp = byte, short, int, long, longlong,
+ * ubyte, ushort, uint, ulong, ulonglong,
+ * float, float, double, longdouble,
+ * float, double, longdouble#
+ * #to = ,,,,,
+ * ,,,,,
+ * npy_float_to_half,,,,
+ * ,,#
+ * #from = ,,,,,
+ * ,,,,,
+ * npy_half_to_float,,,,
+ * ,,#
+ * #complex = 0*5,
+ * 0*5,
+ * 0*4,
+ * 1*3#
+ * #float32 = 0*5,
+ * 0*5,
+ * 0,1,0,0,
+ * 0*3#
+ * #float64 = 0*5,
+ * 0*5,
+ * 0,0,1,0,
+ * 0*3#
+ */
+
+/**begin repeat1
+ * #nop = 1, 2, 3, 1000#
+ * #noplabel = one, two, three, any#
+ */
+static void
+@name@_sum_of_products_@noplabel@(int nop, char **dataptr,
+ npy_intp *strides, npy_intp count)
+{
+#if (@nop@ == 1) || (@nop@ <= 3 && !@complex@)
+ char *data0 = dataptr[0];
+ npy_intp stride0 = strides[0];
+#endif
+#if (@nop@ == 2 || @nop@ == 3) && !@complex@
+ char *data1 = dataptr[1];
+ npy_intp stride1 = strides[1];
+#endif
+#if (@nop@ == 3) && !@complex@
+ char *data2 = dataptr[2];
+ npy_intp stride2 = strides[2];
+#endif
+#if (@nop@ == 1) || (@nop@ <= 3 && !@complex@)
+ char *data_out = dataptr[@nop@];
+ npy_intp stride_out = strides[@nop@];
+#endif
+
+ NPY_EINSUM_DBG_PRINT1("@name@_sum_of_products_@noplabel@ (%d)\n", (int)count);
+
+ while (count--) {
+#if !@complex@
+# if @nop@ == 1
+ *(npy_@name@ *)data_out = @to@(@from@(*(npy_@name@ *)data0) +
+ @from@(*(npy_@name@ *)data_out));
+ data0 += stride0;
+ data_out += stride_out;
+# elif @nop@ == 2
+ *(npy_@name@ *)data_out = @to@(@from@(*(npy_@name@ *)data0) *
+ @from@(*(npy_@name@ *)data1) +
+ @from@(*(npy_@name@ *)data_out));
+ data0 += stride0;
+ data1 += stride1;
+ data_out += stride_out;
+# elif @nop@ == 3
+ *(npy_@name@ *)data_out = @to@(@from@(*(npy_@name@ *)data0) *
+ @from@(*(npy_@name@ *)data1) *
+ @from@(*(npy_@name@ *)data2) +
+ @from@(*(npy_@name@ *)data_out));
+ data0 += stride0;
+ data1 += stride1;
+ data2 += stride2;
+ data_out += stride_out;
+# else
+ npy_@temp@ temp = @from@(*(npy_@name@ *)dataptr[0]);
+ int i;
+ for (i = 1; i < nop; ++i) {
+ temp *= @from@(*(npy_@name@ *)dataptr[i]);
+ }
+ *(npy_@name@ *)dataptr[nop] = @to@(temp +
+ @from@(*(npy_@name@ *)dataptr[i]));
+ for (i = 0; i <= nop; ++i) {
+ dataptr[i] += strides[i];
+ }
+# endif
+#else /* complex */
+# if @nop@ == 1
+ ((npy_@temp@ *)data_out)[0] = ((npy_@temp@ *)data0)[0] +
+ ((npy_@temp@ *)data_out)[0];
+ ((npy_@temp@ *)data_out)[1] = ((npy_@temp@ *)data0)[1] +
+ ((npy_@temp@ *)data_out)[1];
+ data0 += stride0;
+ data_out += stride_out;
+# else
+# if @nop@ <= 3
+#define _SUMPROD_NOP @nop@
+# else
+#define _SUMPROD_NOP nop
+# endif
+ npy_@temp@ re, im, tmp;
+ int i;
+ re = ((npy_@temp@ *)dataptr[0])[0];
+ im = ((npy_@temp@ *)dataptr[0])[1];
+ for (i = 1; i < _SUMPROD_NOP; ++i) {
+ tmp = re * ((npy_@temp@ *)dataptr[i])[0] -
+ im * ((npy_@temp@ *)dataptr[i])[1];
+ im = re * ((npy_@temp@ *)dataptr[i])[1] +
+ im * ((npy_@temp@ *)dataptr[i])[0];
+ re = tmp;
+ }
+ ((npy_@temp@ *)dataptr[_SUMPROD_NOP])[0] = re +
+ ((npy_@temp@ *)dataptr[_SUMPROD_NOP])[0];
+ ((npy_@temp@ *)dataptr[_SUMPROD_NOP])[1] = im +
+ ((npy_@temp@ *)dataptr[_SUMPROD_NOP])[1];
+
+ for (i = 0; i <= _SUMPROD_NOP; ++i) {
+ dataptr[i] += strides[i];
+ }
+#undef _SUMPROD_NOP
+# endif
+#endif
+ }
+}
+
+#if @nop@ == 1
+
+static void
+@name@_sum_of_products_contig_one(int nop, char **dataptr,
+ npy_intp *NPY_UNUSED(strides), npy_intp count)
+{
+ npy_@name@ *data0 = (npy_@name@ *)dataptr[0];
+ npy_@name@ *data_out = (npy_@name@ *)dataptr[1];
+
+ NPY_EINSUM_DBG_PRINT1("@name@_sum_of_products_contig_one (%d)\n",
+ (int)count);
+
+/* This is placed before the main loop to make small counts faster */
+finish_after_unrolled_loop:
+ switch (count) {
+/**begin repeat2
+ * #i = 6, 5, 4, 3, 2, 1, 0#
+ */
+ case @i@+1:
+#if !@complex@
+ data_out[@i@] = @to@(@from@(data0[@i@]) +
+ @from@(data_out[@i@]));
+#else
+ ((npy_@temp@ *)data_out + 2*@i@)[0] =
+ ((npy_@temp@ *)data0 + 2*@i@)[0] +
+ ((npy_@temp@ *)data_out + 2*@i@)[0];
+ ((npy_@temp@ *)data_out + 2*@i@)[1] =
+ ((npy_@temp@ *)data0 + 2*@i@)[1] +
+ ((npy_@temp@ *)data_out + 2*@i@)[1];
+#endif
+/**end repeat2**/
+ case 0:
+ return;
+ }
+
+ /* Unroll the loop by 8 */
+ while (count >= 8) {
+ count -= 8;
+
+/**begin repeat2
+ * #i = 0, 1, 2, 3, 4, 5, 6, 7#
+ */
+#if !@complex@
+ data_out[@i@] = @to@(@from@(data0[@i@]) +
+ @from@(data_out[@i@]));
+#else /* complex */
+ ((npy_@temp@ *)data_out + 2*@i@)[0] =
+ ((npy_@temp@ *)data0 + 2*@i@)[0] +
+ ((npy_@temp@ *)data_out + 2*@i@)[0];
+ ((npy_@temp@ *)data_out + 2*@i@)[1] =
+ ((npy_@temp@ *)data0 + 2*@i@)[1] +
+ ((npy_@temp@ *)data_out + 2*@i@)[1];
+#endif
+/**end repeat2**/
+ data0 += 8;
+ data_out += 8;
+ }
+
+ /* Finish off the loop */
+ goto finish_after_unrolled_loop;
+}
+
+#elif @nop@ == 2 && !@complex@
+
+static void
+@name@_sum_of_products_contig_two(int nop, char **dataptr,
+ npy_intp *NPY_UNUSED(strides), npy_intp count)
+{
+ npy_@name@ *data0 = (npy_@name@ *)dataptr[0];
+ npy_@name@ *data1 = (npy_@name@ *)dataptr[1];
+ npy_@name@ *data_out = (npy_@name@ *)dataptr[2];
+
+#if EINSUM_USE_SSE1 && @float32@
+ __m128 a, b;
+#endif
+
+ NPY_EINSUM_DBG_PRINT1("@name@_sum_of_products_contig_two (%d)\n",
+ (int)count);
+
+/* This is placed before the main loop to make small counts faster */
+finish_after_unrolled_loop:
+ switch (count) {
+/**begin repeat2
+ * #i = 6, 5, 4, 3, 2, 1, 0#
+ */
+ case @i@+1:
+ data_out[@i@] = @to@(@from@(data0[@i@]) *
+ @from@(data1[@i@]) +
+ @from@(data_out[@i@]));
+/**end repeat2**/
+ case 0:
+ return;
+ }
+
+#if EINSUM_USE_SSE1 && @float32@
+ /* Use aligned instructions if possible */
+ if (EINSUM_IS_SSE_ALIGNED(data0) && EINSUM_IS_SSE_ALIGNED(data1) &&
+ EINSUM_IS_SSE_ALIGNED(data_out)) {
+ /* Unroll the loop by 8 */
+ while (count >= 8) {
+ count -= 8;
+
+/**begin repeat2
+ * #i = 0, 4#
+ */
+ a = _mm_mul_ps(_mm_load_ps(data0+@i@), _mm_load_ps(data1+@i@));
+ b = _mm_add_ps(a, _mm_load_ps(data_out+@i@));
+ _mm_store_ps(data_out+@i@, b);
+/**end repeat2**/
+ data0 += 8;
+ data1 += 8;
+ data_out += 8;
+ }
+
+ /* Finish off the loop */
+ goto finish_after_unrolled_loop;
+ }
+#endif
+
+ /* Unroll the loop by 8 */
+ while (count >= 8) {
+ count -= 8;
+
+#if EINSUM_USE_SSE1 && @float32@
+/**begin repeat2
+ * #i = 0, 4#
+ */
+ a = _mm_mul_ps(_mm_loadu_ps(data0+@i@), _mm_loadu_ps(data1+@i@));
+ b = _mm_add_ps(a, _mm_loadu_ps(data_out+@i@));
+ _mm_storeu_ps(data_out+@i@, b);
+/**end repeat2**/
+#else
+/**begin repeat2
+ * #i = 0, 1, 2, 3, 4, 5, 6, 7#
+ */
+ data_out[@i@] = @to@(@from@(data0[@i@]) *
+ @from@(data1[@i@]) +
+ @from@(data_out[@i@]));
+/**end repeat2**/
+#endif
+ data0 += 8;
+ data1 += 8;
+ data_out += 8;
+ }
+
+ /* Finish off the loop */
+ goto finish_after_unrolled_loop;
+}
+
+/* Some extra specializations for the two operand case */
+static void
+@name@_sum_of_products_stride0_contig_outcontig_two(int nop, char **dataptr,
+ npy_intp *NPY_UNUSED(strides), npy_intp count)
+{
+ npy_@temp@ value0 = @from@(*(npy_@name@ *)dataptr[0]);
+ npy_@name@ *data1 = (npy_@name@ *)dataptr[1];
+ npy_@name@ *data_out = (npy_@name@ *)dataptr[2];
+
+#if EINSUM_USE_SSE1 && @float32@
+ __m128 a, b, value0_sse;
+#elif EINSUM_USE_SSE2 && @float64@
+ __m128d a, b, value0_sse;
+#endif
+
+ NPY_EINSUM_DBG_PRINT1("@name@_sum_of_products_stride0_contig_outcontig_two (%d)\n",
+ (int)count);
+
+/* This is placed before the main loop to make small counts faster */
+finish_after_unrolled_loop:
+ switch (count) {
+/**begin repeat2
+ * #i = 6, 5, 4, 3, 2, 1, 0#
+ */
+ case @i@+1:
+ data_out[@i@] = @to@(value0 *
+ @from@(data1[@i@]) +
+ @from@(data_out[@i@]));
+/**end repeat2**/
+ case 0:
+ return;
+ }
+
+#if EINSUM_USE_SSE1 && @float32@
+ value0_sse = _mm_set_ps1(value0);
+
+ /* Use aligned instructions if possible */
+ if (EINSUM_IS_SSE_ALIGNED(data1) && EINSUM_IS_SSE_ALIGNED(data_out)) {
+ /* Unroll the loop by 8 */
+ while (count >= 8) {
+ count -= 8;
+
+/**begin repeat2
+ * #i = 0, 4#
+ */
+ a = _mm_mul_ps(value0_sse, _mm_load_ps(data1+@i@));
+ b = _mm_add_ps(a, _mm_load_ps(data_out+@i@));
+ _mm_store_ps(data_out+@i@, b);
+/**end repeat2**/
+ data1 += 8;
+ data_out += 8;
+ }
+
+ /* Finish off the loop */
+ if (count > 0) {
+ goto finish_after_unrolled_loop;
+ }
+ else {
+ return;
+ }
+ }
+#elif EINSUM_USE_SSE2 && @float64@
+ value0_sse = _mm_set1_pd(value0);
+
+ /* Use aligned instructions if possible */
+ if (EINSUM_IS_SSE_ALIGNED(data1) && EINSUM_IS_SSE_ALIGNED(data_out)) {
+ /* Unroll the loop by 8 */
+ while (count >= 8) {
+ count -= 8;
+
+/**begin repeat2
+ * #i = 0, 2, 4, 6#
+ */
+ a = _mm_mul_pd(value0_sse, _mm_load_pd(data1+@i@));
+ b = _mm_add_pd(a, _mm_load_pd(data_out+@i@));
+ _mm_store_pd(data_out+@i@, b);
+/**end repeat2**/
+ data1 += 8;
+ data_out += 8;
+ }
+
+ /* Finish off the loop */
+ if (count > 0) {
+ goto finish_after_unrolled_loop;
+ }
+ else {
+ return;
+ }
+ }
+#endif
+
+ /* Unroll the loop by 8 */
+ while (count >= 8) {
+ count -= 8;
+
+#if EINSUM_USE_SSE1 && @float32@
+/**begin repeat2
+ * #i = 0, 4#
+ */
+ a = _mm_mul_ps(value0_sse, _mm_loadu_ps(data1+@i@));
+ b = _mm_add_ps(a, _mm_loadu_ps(data_out+@i@));
+ _mm_storeu_ps(data_out+@i@, b);
+/**end repeat2**/
+#elif EINSUM_USE_SSE2 && @float64@
+/**begin repeat2
+ * #i = 0, 2, 4, 6#
+ */
+ a = _mm_mul_pd(value0_sse, _mm_loadu_pd(data1+@i@));
+ b = _mm_add_pd(a, _mm_loadu_pd(data_out+@i@));
+ _mm_storeu_pd(data_out+@i@, b);
+/**end repeat2**/
+#else
+/**begin repeat2
+ * #i = 0, 1, 2, 3, 4, 5, 6, 7#
+ */
+ data_out[@i@] = @to@(value0 *
+ @from@(data1[@i@]) +
+ @from@(data_out[@i@]));
+/**end repeat2**/
+#endif
+ data1 += 8;
+ data_out += 8;
+ }
+
+ /* Finish off the loop */
+ if (count > 0) {
+ goto finish_after_unrolled_loop;
+ }
+}
+
+static void
+@name@_sum_of_products_contig_stride0_outcontig_two(int nop, char **dataptr,
+ npy_intp *NPY_UNUSED(strides), npy_intp count)
+{
+ npy_@name@ *data0 = (npy_@name@ *)dataptr[0];
+ npy_@temp@ value1 = @from@(*(npy_@name@ *)dataptr[1]);
+ npy_@name@ *data_out = (npy_@name@ *)dataptr[2];
+
+#if EINSUM_USE_SSE1 && @float32@
+ __m128 a, b, value1_sse;
+#endif
+
+ NPY_EINSUM_DBG_PRINT1("@name@_sum_of_products_contig_stride0_outcontig_two (%d)\n",
+ (int)count);
+
+/* This is placed before the main loop to make small counts faster */
+finish_after_unrolled_loop:
+ switch (count) {
+/**begin repeat2
+ * #i = 6, 5, 4, 3, 2, 1, 0#
+ */
+ case @i@+1:
+ data_out[@i@] = @to@(@from@(data0[@i@])*
+ value1 +
+ @from@(data_out[@i@]));
+/**end repeat2**/
+ case 0:
+ return;
+ }
+
+#if EINSUM_USE_SSE1 && @float32@
+ value1_sse = _mm_set_ps1(value1);
+
+ /* Use aligned instructions if possible */
+ if (EINSUM_IS_SSE_ALIGNED(data0) && EINSUM_IS_SSE_ALIGNED(data_out)) {
+ /* Unroll the loop by 8 */
+ while (count >= 8) {
+ count -= 8;
+
+/**begin repeat2
+ * #i = 0, 4#
+ */
+ a = _mm_mul_ps(_mm_load_ps(data0+@i@), value1_sse);
+ b = _mm_add_ps(a, _mm_load_ps(data_out+@i@));
+ _mm_store_ps(data_out+@i@, b);
+/**end repeat2**/
+ data0 += 8;
+ data_out += 8;
+ }
+
+ /* Finish off the loop */
+ goto finish_after_unrolled_loop;
+ }
+#endif
+
+ /* Unroll the loop by 8 */
+ while (count >= 8) {
+ count -= 8;
+
+#if EINSUM_USE_SSE1 && @float32@
+/**begin repeat2
+ * #i = 0, 4#
+ */
+ a = _mm_mul_ps(_mm_loadu_ps(data0+@i@), value1_sse);
+ b = _mm_add_ps(a, _mm_loadu_ps(data_out+@i@));
+ _mm_storeu_ps(data_out+@i@, b);
+/**end repeat2**/
+#else
+/**begin repeat2
+ * #i = 0, 1, 2, 3, 4, 5, 6, 7#
+ */
+ data_out[@i@] = @to@(@from@(data0[@i@])*
+ value1 +
+ @from@(data_out[@i@]));
+/**end repeat2**/
+#endif
+ data0 += 8;
+ data_out += 8;
+ }
+
+ /* Finish off the loop */
+ goto finish_after_unrolled_loop;
+}
+
+static void
+@name@_sum_of_products_contig_contig_outstride0_two(int nop, char **dataptr,
+ npy_intp *NPY_UNUSED(strides), npy_intp count)
+{
+ npy_@name@ *data0 = (npy_@name@ *)dataptr[0];
+ npy_@name@ *data1 = (npy_@name@ *)dataptr[1];
+ npy_@temp@ accum = 0;
+
+#if EINSUM_USE_SSE1 && @float32@
+ __m128 a, accum_sse = _mm_setzero_ps();
+#elif EINSUM_USE_SSE2 && @float64@
+ __m128d a, accum_sse = _mm_setzero_pd();
+#endif
+
+ NPY_EINSUM_DBG_PRINT1("@name@_sum_of_products_contig_contig_outstride0_two (%d)\n",
+ (int)count);
+
+/* This is placed before the main loop to make small counts faster */
+finish_after_unrolled_loop:
+ switch (count) {
+/**begin repeat2
+ * #i = 6, 5, 4, 3, 2, 1, 0#
+ */
+ case @i@+1:
+ accum += @from@(data0[@i@]) * @from@(data1[@i@]);
+/**end repeat2**/
+ case 0:
+ *(npy_@name@ *)dataptr[2] += @to@(accum);
+ return;
+ }
+
+#if EINSUM_USE_SSE1 && @float32@
+ /* Use aligned instructions if possible */
+ if (EINSUM_IS_SSE_ALIGNED(data0) && EINSUM_IS_SSE_ALIGNED(data1)) {
+ /* Unroll the loop by 8 */
+ while (count >= 8) {
+ count -= 8;
+
+ _mm_prefetch(data0 + 512, _MM_HINT_T0);
+ _mm_prefetch(data1 + 512, _MM_HINT_T0);
+
+/**begin repeat2
+ * #i = 0, 4#
+ */
+ /*
+ * NOTE: This accumulation changes the order, so will likely
+ * produce slightly different results.
+ */
+ a = _mm_mul_ps(_mm_load_ps(data0+@i@), _mm_load_ps(data1+@i@));
+ accum_sse = _mm_add_ps(accum_sse, a);
+/**end repeat2**/
+ data0 += 8;
+ data1 += 8;
+ }
+
+ /* Add the four SSE values and put in accum */
+ a = _mm_shuffle_ps(accum_sse, accum_sse, _MM_SHUFFLE(2,3,0,1));
+ accum_sse = _mm_add_ps(a, accum_sse);
+ a = _mm_shuffle_ps(accum_sse, accum_sse, _MM_SHUFFLE(1,0,3,2));
+ accum_sse = _mm_add_ps(a, accum_sse);
+ _mm_store_ss(&accum, accum_sse);
+
+ /* Finish off the loop */
+ goto finish_after_unrolled_loop;
+ }
+#elif EINSUM_USE_SSE2 && @float64@
+ /* Use aligned instructions if possible */
+ if (EINSUM_IS_SSE_ALIGNED(data0) && EINSUM_IS_SSE_ALIGNED(data1)) {
+ /* Unroll the loop by 8 */
+ while (count >= 8) {
+ count -= 8;
+
+ _mm_prefetch(data0 + 512, _MM_HINT_T0);
+ _mm_prefetch(data1 + 512, _MM_HINT_T0);
+
+/**begin repeat2
+ * #i = 0, 2, 4, 6#
+ */
+ /*
+ * NOTE: This accumulation changes the order, so will likely
+ * produce slightly different results.
+ */
+ a = _mm_mul_pd(_mm_load_pd(data0+@i@), _mm_load_pd(data1+@i@));
+ accum_sse = _mm_add_pd(accum_sse, a);
+/**end repeat2**/
+ data0 += 8;
+ data1 += 8;
+ }
+
+ /* Add the two SSE2 values and put in accum */
+ a = _mm_shuffle_pd(accum_sse, accum_sse, _MM_SHUFFLE2(0,1));
+ accum_sse = _mm_add_pd(a, accum_sse);
+ _mm_store_sd(&accum, accum_sse);
+
+ /* Finish off the loop */
+ goto finish_after_unrolled_loop;
+ }
+#endif
+
+ /* Unroll the loop by 8 */
+ while (count >= 8) {
+ count -= 8;
+
+#if EINSUM_USE_SSE1 && @float32@
+ _mm_prefetch(data0 + 512, _MM_HINT_T0);
+ _mm_prefetch(data1 + 512, _MM_HINT_T0);
+
+/**begin repeat2
+ * #i = 0, 4#
+ */
+ /*
+ * NOTE: This accumulation changes the order, so will likely
+ * produce slightly different results.
+ */
+ a = _mm_mul_ps(_mm_loadu_ps(data0+@i@), _mm_loadu_ps(data1+@i@));
+ accum_sse = _mm_add_ps(accum_sse, a);
+/**end repeat2**/
+#elif EINSUM_USE_SSE2 && @float64@
+ _mm_prefetch(data0 + 512, _MM_HINT_T0);
+ _mm_prefetch(data1 + 512, _MM_HINT_T0);
+
+/**begin repeat2
+ * #i = 0, 2, 4, 6#
+ */
+ /*
+ * NOTE: This accumulation changes the order, so will likely
+ * produce slightly different results.
+ */
+ a = _mm_mul_pd(_mm_loadu_pd(data0+@i@), _mm_loadu_pd(data1+@i@));
+ accum_sse = _mm_add_pd(accum_sse, a);
+/**end repeat2**/
+#else
+/**begin repeat2
+ * #i = 0, 1, 2, 3, 4, 5, 6, 7#
+ */
+ accum += @from@(data0[@i@]) * @from@(data1[@i@]);
+/**end repeat2**/
+#endif
+ data0 += 8;
+ data1 += 8;
+ }
+
+#if EINSUM_USE_SSE1 && @float32@
+ /* Add the four SSE values and put in accum */
+ a = _mm_shuffle_ps(accum_sse, accum_sse, _MM_SHUFFLE(2,3,0,1));
+ accum_sse = _mm_add_ps(a, accum_sse);
+ a = _mm_shuffle_ps(accum_sse, accum_sse, _MM_SHUFFLE(1,0,3,2));
+ accum_sse = _mm_add_ps(a, accum_sse);
+ _mm_store_ss(&accum, accum_sse);
+#elif EINSUM_USE_SSE2 && @float64@
+ /* Add the two SSE2 values and put in accum */
+ a = _mm_shuffle_pd(accum_sse, accum_sse, _MM_SHUFFLE2(0,1));
+ accum_sse = _mm_add_pd(a, accum_sse);
+ _mm_store_sd(&accum, accum_sse);
+#endif
+
+ /* Finish off the loop */
+ goto finish_after_unrolled_loop;
+}
+
+static void
+@name@_sum_of_products_stride0_contig_outstride0_two(int nop, char **dataptr,
+ npy_intp *NPY_UNUSED(strides), npy_intp count)
+{
+ npy_@temp@ value0 = @from@(*(npy_@name@ *)dataptr[0]);
+ npy_@name@ *data1 = (npy_@name@ *)dataptr[1];
+ npy_@temp@ accum = 0;
+
+#if EINSUM_USE_SSE1 && @float32@
+ __m128 a, accum_sse = _mm_setzero_ps();
+#endif
+
+ NPY_EINSUM_DBG_PRINT1("@name@_sum_of_products_stride0_contig_outstride0_two (%d)\n",
+ (int)count);
+
+/* This is placed before the main loop to make small counts faster */
+finish_after_unrolled_loop:
+ switch (count) {
+/**begin repeat2
+ * #i = 6, 5, 4, 3, 2, 1, 0#
+ */
+ case @i@+1:
+ accum += @from@(data1[@i@]);
+/**end repeat2**/
+ case 0:
+ *(npy_@name@ *)dataptr[2] += @to@(value0 * accum);
+ return;
+ }
+
+#if EINSUM_USE_SSE1 && @float32@
+ /* Use aligned instructions if possible */
+ if (EINSUM_IS_SSE_ALIGNED(data1)) {
+ /* Unroll the loop by 8 */
+ while (count >= 8) {
+ count -= 8;
+
+/**begin repeat2
+ * #i = 0, 4#
+ */
+ /*
+ * NOTE: This accumulation changes the order, so will likely
+ * produce slightly different results.
+ */
+ accum_sse = _mm_add_ps(accum_sse, _mm_load_ps(data1+@i@));
+/**end repeat2**/
+ data1 += 8;
+ }
+
+#if EINSUM_USE_SSE1 && @float32@
+ /* Add the four SSE values and put in accum */
+ a = _mm_shuffle_ps(accum_sse, accum_sse, _MM_SHUFFLE(2,3,0,1));
+ accum_sse = _mm_add_ps(a, accum_sse);
+ a = _mm_shuffle_ps(accum_sse, accum_sse, _MM_SHUFFLE(1,0,3,2));
+ accum_sse = _mm_add_ps(a, accum_sse);
+ _mm_store_ss(&accum, accum_sse);
+#endif
+
+ /* Finish off the loop */
+ goto finish_after_unrolled_loop;
+ }
+#endif
+
+ /* Unroll the loop by 8 */
+ while (count >= 8) {
+ count -= 8;
+
+#if EINSUM_USE_SSE1 && @float32@
+/**begin repeat2
+ * #i = 0, 4#
+ */
+ /*
+ * NOTE: This accumulation changes the order, so will likely
+ * produce slightly different results.
+ */
+ accum_sse = _mm_add_ps(accum_sse, _mm_loadu_ps(data1+@i@));
+/**end repeat2**/
+#else
+/**begin repeat2
+ * #i = 0, 1, 2, 3, 4, 5, 6, 7#
+ */
+ accum += @from@(data1[@i@]);
+/**end repeat2**/
+#endif
+ data1 += 8;
+ }
+
+#if EINSUM_USE_SSE1 && @float32@
+ /* Add the four SSE values and put in accum */
+ a = _mm_shuffle_ps(accum_sse, accum_sse, _MM_SHUFFLE(2,3,0,1));
+ accum_sse = _mm_add_ps(a, accum_sse);
+ a = _mm_shuffle_ps(accum_sse, accum_sse, _MM_SHUFFLE(1,0,3,2));
+ accum_sse = _mm_add_ps(a, accum_sse);
+ _mm_store_ss(&accum, accum_sse);
+#endif
+
+ /* Finish off the loop */
+ goto finish_after_unrolled_loop;
+}
+
+static void
+@name@_sum_of_products_contig_stride0_outstride0_two(int nop, char **dataptr,
+ npy_intp *NPY_UNUSED(strides), npy_intp count)
+{
+ npy_@name@ *data0 = (npy_@name@ *)dataptr[0];
+ npy_@temp@ value1 = @from@(*(npy_@name@ *)dataptr[1]);
+ npy_@temp@ accum = 0;
+
+#if EINSUM_USE_SSE1 && @float32@
+ __m128 a, accum_sse = _mm_setzero_ps();
+#endif
+
+ NPY_EINSUM_DBG_PRINT1("@name@_sum_of_products_contig_stride0_outstride0_two (%d)\n",
+ (int)count);
+
+/* This is placed before the main loop to make small counts faster */
+finish_after_unrolled_loop:
+ switch (count) {
+/**begin repeat2
+ * #i = 6, 5, 4, 3, 2, 1, 0#
+ */
+ case @i@+1:
+ accum += @from@(data0[@i@]);
+/**end repeat2**/
+ case 0:
+ *(npy_@name@ *)dataptr[2] += @to@(accum * value1);
+ return;
+ }
+
+#if EINSUM_USE_SSE1 && @float32@
+ /* Use aligned instructions if possible */
+ if (EINSUM_IS_SSE_ALIGNED(data0)) {
+ /* Unroll the loop by 8 */
+ while (count >= 8) {
+ count -= 8;
+
+/**begin repeat2
+ * #i = 0, 4#
+ */
+ /*
+ * NOTE: This accumulation changes the order, so will likely
+ * produce slightly different results.
+ */
+ accum_sse = _mm_add_ps(accum_sse, _mm_load_ps(data0+@i@));
+/**end repeat2**/
+ data0 += 8;
+ }
+
+#if EINSUM_USE_SSE1 && @float32@
+ /* Add the four SSE values and put in accum */
+ a = _mm_shuffle_ps(accum_sse, accum_sse, _MM_SHUFFLE(2,3,0,1));
+ accum_sse = _mm_add_ps(a, accum_sse);
+ a = _mm_shuffle_ps(accum_sse, accum_sse, _MM_SHUFFLE(1,0,3,2));
+ accum_sse = _mm_add_ps(a, accum_sse);
+ _mm_store_ss(&accum, accum_sse);
+#endif
+
+ /* Finish off the loop */
+ goto finish_after_unrolled_loop;
+ }
+#endif
+
+ /* Unroll the loop by 8 */
+ while (count >= 8) {
+ count -= 8;
+
+#if EINSUM_USE_SSE1 && @float32@
+/**begin repeat2
+ * #i = 0, 4#
+ */
+ /*
+ * NOTE: This accumulation changes the order, so will likely
+ * produce slightly different results.
+ */
+ accum_sse = _mm_add_ps(accum_sse, _mm_loadu_ps(data0+@i@));
+/**end repeat2**/
+#else
+/**begin repeat2
+ * #i = 0, 1, 2, 3, 4, 5, 6, 7#
+ */
+ accum += @from@(data0[@i@]);
+/**end repeat2**/
+#endif
+ data0 += 8;
+ }
+
+#if EINSUM_USE_SSE1 && @float32@
+ /* Add the four SSE values and put in accum */
+ a = _mm_shuffle_ps(accum_sse, accum_sse, _MM_SHUFFLE(2,3,0,1));
+ accum_sse = _mm_add_ps(a, accum_sse);
+ a = _mm_shuffle_ps(accum_sse, accum_sse, _MM_SHUFFLE(1,0,3,2));
+ accum_sse = _mm_add_ps(a, accum_sse);
+ _mm_store_ss(&accum, accum_sse);
+#endif
+
+ /* Finish off the loop */
+ goto finish_after_unrolled_loop;
+}
+
+#elif @nop@ == 3 && !@complex@
+
+static void
+@name@_sum_of_products_contig_three(int nop, char **dataptr,
+ npy_intp *NPY_UNUSED(strides), npy_intp count)
+{
+ npy_@name@ *data0 = (npy_@name@ *)dataptr[0];
+ npy_@name@ *data1 = (npy_@name@ *)dataptr[1];
+ npy_@name@ *data2 = (npy_@name@ *)dataptr[2];
+ npy_@name@ *data_out = (npy_@name@ *)dataptr[3];
+
+ /* Unroll the loop by 8 */
+ while (count >= 8) {
+ count -= 8;
+
+/**begin repeat2
+ * #i = 0, 1, 2, 3, 4, 5, 6, 7#
+ */
+ data_out[@i@] = @to@(@from@(data0[@i@]) *
+ @from@(data1[@i@]) *
+ @from@(data2[@i@]) +
+ @from@(data_out[@i@]));
+/**end repeat2**/
+ data0 += 8;
+ data1 += 8;
+ data_out += 8;
+ }
+
+ /* Finish off the loop */
+
+/**begin repeat2
+ * #i = 0, 1, 2, 3, 4, 5, 6, 7#
+ */
+ if (count-- == 0) {
+ return;
+ }
+ data_out[@i@] = @to@(@from@(data0[@i@]) *
+ @from@(data1[@i@]) *
+ @from@(data2[@i@]) +
+ @from@(data_out[@i@]));
+/**end repeat2**/
+}
+
+#else /* @nop@ > 3 || @complex */
+
+static void
+@name@_sum_of_products_contig_@noplabel@(int nop, char **dataptr,
+ npy_intp *NPY_UNUSED(strides), npy_intp count)
+{
+ NPY_EINSUM_DBG_PRINT1("@name@_sum_of_products_contig_@noplabel@ (%d)\n",
+ (int)count);
+
+ while (count--) {
+#if !@complex@
+ npy_@temp@ temp = @from@(*(npy_@name@ *)dataptr[0]);
+ int i;
+ for (i = 1; i < nop; ++i) {
+ temp *= @from@(*(npy_@name@ *)dataptr[i]);
+ }
+ *(npy_@name@ *)dataptr[nop] = @to@(temp +
+ @from@(*(npy_@name@ *)dataptr[i]));
+ for (i = 0; i <= nop; ++i) {
+ dataptr[i] += sizeof(npy_@name@);
+ }
+#else /* complex */
+# if @nop@ <= 3
+# define _SUMPROD_NOP @nop@
+# else
+# define _SUMPROD_NOP nop
+# endif
+ npy_@temp@ re, im, tmp;
+ int i;
+ re = ((npy_@temp@ *)dataptr[0])[0];
+ im = ((npy_@temp@ *)dataptr[0])[1];
+ for (i = 1; i < _SUMPROD_NOP; ++i) {
+ tmp = re * ((npy_@temp@ *)dataptr[i])[0] -
+ im * ((npy_@temp@ *)dataptr[i])[1];
+ im = re * ((npy_@temp@ *)dataptr[i])[1] +
+ im * ((npy_@temp@ *)dataptr[i])[0];
+ re = tmp;
+ }
+ ((npy_@temp@ *)dataptr[_SUMPROD_NOP])[0] = re +
+ ((npy_@temp@ *)dataptr[_SUMPROD_NOP])[0];
+ ((npy_@temp@ *)dataptr[_SUMPROD_NOP])[1] = im +
+ ((npy_@temp@ *)dataptr[_SUMPROD_NOP])[1];
+
+ for (i = 0; i <= _SUMPROD_NOP; ++i) {
+ dataptr[i] += sizeof(npy_@name@);
+ }
+# undef _SUMPROD_NOP
+#endif
+ }
+}
+
+#endif /* functions for various @nop@ */
+
+#if @nop@ == 1
+
+static void
+@name@_sum_of_products_contig_outstride0_one(int nop, char **dataptr,
+ npy_intp *strides, npy_intp count)
+{
+#if @complex@
+ npy_@temp@ accum_re = 0, accum_im = 0;
+ npy_@temp@ *data0 = (npy_@temp@ *)dataptr[0];
+#else
+ npy_@temp@ accum = 0;
+ npy_@name@ *data0 = (npy_@name@ *)dataptr[0];
+#endif
+
+#if EINSUM_USE_SSE1 && @float32@
+ __m128 a, accum_sse = _mm_setzero_ps();
+#elif EINSUM_USE_SSE2 && @float64@
+ __m128d a, accum_sse = _mm_setzero_pd();
+#endif
+
+
+ NPY_EINSUM_DBG_PRINT1("@name@_sum_of_products_contig_outstride0_one (%d)\n",
+ (int)count);
+
+/* This is placed before the main loop to make small counts faster */
+finish_after_unrolled_loop:
+ switch (count) {
+/**begin repeat2
+ * #i = 6, 5, 4, 3, 2, 1, 0#
+ */
+ case @i@+1:
+#if !@complex@
+ accum += @from@(data0[@i@]);
+#else /* complex */
+ accum_re += data0[2*@i@+0];
+ accum_im += data0[2*@i@+1];
+#endif
+/**end repeat2**/
+ case 0:
+#if @complex@
+ ((npy_@temp@ *)dataptr[1])[0] += accum_re;
+ ((npy_@temp@ *)dataptr[1])[1] += accum_im;
+#else
+ *((npy_@name@ *)dataptr[1]) = @to@(accum +
+ @from@(*((npy_@name@ *)dataptr[1])));
+#endif
+ return;
+ }
+
+#if EINSUM_USE_SSE1 && @float32@
+ /* Use aligned instructions if possible */
+ if (EINSUM_IS_SSE_ALIGNED(data0)) {
+ /* Unroll the loop by 8 */
+ while (count >= 8) {
+ count -= 8;
+
+ _mm_prefetch(data0 + 512, _MM_HINT_T0);
+
+/**begin repeat2
+ * #i = 0, 4#
+ */
+ /*
+ * NOTE: This accumulation changes the order, so will likely
+ * produce slightly different results.
+ */
+ accum_sse = _mm_add_ps(accum_sse, _mm_load_ps(data0+@i@));
+/**end repeat2**/
+ data0 += 8;
+ }
+
+ /* Add the four SSE values and put in accum */
+ a = _mm_shuffle_ps(accum_sse, accum_sse, _MM_SHUFFLE(2,3,0,1));
+ accum_sse = _mm_add_ps(a, accum_sse);
+ a = _mm_shuffle_ps(accum_sse, accum_sse, _MM_SHUFFLE(1,0,3,2));
+ accum_sse = _mm_add_ps(a, accum_sse);
+ _mm_store_ss(&accum, accum_sse);
+
+ /* Finish off the loop */
+ goto finish_after_unrolled_loop;
+ }
+#elif EINSUM_USE_SSE2 && @float64@
+ /* Use aligned instructions if possible */
+ if (EINSUM_IS_SSE_ALIGNED(data0)) {
+ /* Unroll the loop by 8 */
+ while (count >= 8) {
+ count -= 8;
+
+ _mm_prefetch(data0 + 512, _MM_HINT_T0);
+
+/**begin repeat2
+ * #i = 0, 2, 4, 6#
+ */
+ /*
+ * NOTE: This accumulation changes the order, so will likely
+ * produce slightly different results.
+ */
+ accum_sse = _mm_add_pd(accum_sse, _mm_load_pd(data0+@i@));
+/**end repeat2**/
+ data0 += 8;
+ }
+
+ /* Add the two SSE2 values and put in accum */
+ a = _mm_shuffle_pd(accum_sse, accum_sse, _MM_SHUFFLE2(0,1));
+ accum_sse = _mm_add_pd(a, accum_sse);
+ _mm_store_sd(&accum, accum_sse);
+
+ /* Finish off the loop */
+ goto finish_after_unrolled_loop;
+ }
+#endif
+
+ /* Unroll the loop by 8 */
+ while (count >= 8) {
+ count -= 8;
+
+#if EINSUM_USE_SSE1 && @float32@
+ _mm_prefetch(data0 + 512, _MM_HINT_T0);
+
+/**begin repeat2
+ * #i = 0, 4#
+ */
+ /*
+ * NOTE: This accumulation changes the order, so will likely
+ * produce slightly different results.
+ */
+ accum_sse = _mm_add_ps(accum_sse, _mm_loadu_ps(data0+@i@));
+/**end repeat2**/
+#elif EINSUM_USE_SSE2 && @float64@
+ _mm_prefetch(data0 + 512, _MM_HINT_T0);
+
+/**begin repeat2
+ * #i = 0, 2, 4, 6#
+ */
+ /*
+ * NOTE: This accumulation changes the order, so will likely
+ * produce slightly different results.
+ */
+ accum_sse = _mm_add_pd(accum_sse, _mm_loadu_pd(data0+@i@));
+/**end repeat2**/
+#else
+/**begin repeat2
+ * #i = 0, 1, 2, 3, 4, 5, 6, 7#
+ */
+# if !@complex@
+ accum += @from@(data0[@i@]);
+# else /* complex */
+ accum_re += data0[2*@i@+0];
+ accum_im += data0[2*@i@+1];
+# endif
+/**end repeat2**/
+#endif
+
+#if !@complex@
+ data0 += 8;
+#else
+ data0 += 8*2;
+#endif
+ }
+
+#if EINSUM_USE_SSE1 && @float32@
+ /* Add the four SSE values and put in accum */
+ a = _mm_shuffle_ps(accum_sse, accum_sse, _MM_SHUFFLE(2,3,0,1));
+ accum_sse = _mm_add_ps(a, accum_sse);
+ a = _mm_shuffle_ps(accum_sse, accum_sse, _MM_SHUFFLE(1,0,3,2));
+ accum_sse = _mm_add_ps(a, accum_sse);
+ _mm_store_ss(&accum, accum_sse);
+#elif EINSUM_USE_SSE2 && @float64@
+ /* Add the two SSE2 values and put in accum */
+ a = _mm_shuffle_pd(accum_sse, accum_sse, _MM_SHUFFLE2(0,1));
+ accum_sse = _mm_add_pd(a, accum_sse);
+ _mm_store_sd(&accum, accum_sse);
+#endif
+
+ /* Finish off the loop */
+ goto finish_after_unrolled_loop;
+}
+
+#endif /* @nop@ == 1 */
+
+static void
+@name@_sum_of_products_outstride0_@noplabel@(int nop, char **dataptr,
+ npy_intp *strides, npy_intp count)
+{
+#if @complex@
+ npy_@temp@ accum_re = 0, accum_im = 0;
+#else
+ npy_@temp@ accum = 0;
+#endif
+
+#if (@nop@ == 1) || (@nop@ <= 3 && !@complex@)
+ char *data0 = dataptr[0];
+ npy_intp stride0 = strides[0];
+#endif
+#if (@nop@ == 2 || @nop@ == 3) && !@complex@
+ char *data1 = dataptr[1];
+ npy_intp stride1 = strides[1];
+#endif
+#if (@nop@ == 3) && !@complex@
+ char *data2 = dataptr[2];
+ npy_intp stride2 = strides[2];
+#endif
+
+ NPY_EINSUM_DBG_PRINT1("@name@_sum_of_products_outstride0_@noplabel@ (%d)\n",
+ (int)count);
+
+ while (count--) {
+#if !@complex@
+# if @nop@ == 1
+ accum += @from@(*(npy_@name@ *)data0);
+ data0 += stride0;
+# elif @nop@ == 2
+ accum += @from@(*(npy_@name@ *)data0) *
+ @from@(*(npy_@name@ *)data1);
+ data0 += stride0;
+ data1 += stride1;
+# elif @nop@ == 3
+ accum += @from@(*(npy_@name@ *)data0) *
+ @from@(*(npy_@name@ *)data1) *
+ @from@(*(npy_@name@ *)data2);
+ data0 += stride0;
+ data1 += stride1;
+ data2 += stride2;
+# else
+ npy_@temp@ temp = @from@(*(npy_@name@ *)dataptr[0]);
+ int i;
+ for (i = 1; i < nop; ++i) {
+ temp *= @from@(*(npy_@name@ *)dataptr[i]);
+ }
+ accum += temp;
+ for (i = 0; i < nop; ++i) {
+ dataptr[i] += strides[i];
+ }
+# endif
+#else /* complex */
+# if @nop@ == 1
+ accum_re += ((npy_@temp@ *)data0)[0];
+ accum_im += ((npy_@temp@ *)data0)[1];
+ data0 += stride0;
+# else
+# if @nop@ <= 3
+#define _SUMPROD_NOP @nop@
+# else
+#define _SUMPROD_NOP nop
+# endif
+ npy_@temp@ re, im, tmp;
+ int i;
+ re = ((npy_@temp@ *)dataptr[0])[0];
+ im = ((npy_@temp@ *)dataptr[0])[1];
+ for (i = 1; i < _SUMPROD_NOP; ++i) {
+ tmp = re * ((npy_@temp@ *)dataptr[i])[0] -
+ im * ((npy_@temp@ *)dataptr[i])[1];
+ im = re * ((npy_@temp@ *)dataptr[i])[1] +
+ im * ((npy_@temp@ *)dataptr[i])[0];
+ re = tmp;
+ }
+ accum_re += re;
+ accum_im += im;
+ for (i = 0; i < _SUMPROD_NOP; ++i) {
+ dataptr[i] += strides[i];
+ }
+#undef _SUMPROD_NOP
+# endif
+#endif
+ }
+
+#if @complex@
+# if @nop@ <= 3
+ ((npy_@temp@ *)dataptr[@nop@])[0] += accum_re;
+ ((npy_@temp@ *)dataptr[@nop@])[1] += accum_im;
+# else
+ ((npy_@temp@ *)dataptr[nop])[0] += accum_re;
+ ((npy_@temp@ *)dataptr[nop])[1] += accum_im;
+# endif
+#else
+# if @nop@ <= 3
+ *((npy_@name@ *)dataptr[@nop@]) = @to@(accum +
+ @from@(*((npy_@name@ *)dataptr[@nop@])));
+# else
+ *((npy_@name@ *)dataptr[nop]) = @to@(accum +
+ @from@(*((npy_@name@ *)dataptr[nop])));
+# endif
+#endif
+
+}
+
+/**end repeat1**/
+
+/**end repeat**/
+
+
+/* Do OR of ANDs for the boolean type */
+
+/**begin repeat
+ * #nop = 1, 2, 3, 1000#
+ * #noplabel = one, two, three, any#
+ */
+
+static void
+bool_sum_of_products_@noplabel@(int nop, char **dataptr,
+ npy_intp *strides, npy_intp count)
+{
+#if (@nop@ <= 3)
+ char *data0 = dataptr[0];
+ npy_intp stride0 = strides[0];
+#endif
+#if (@nop@ == 2 || @nop@ == 3)
+ char *data1 = dataptr[1];
+ npy_intp stride1 = strides[1];
+#endif
+#if (@nop@ == 3)
+ char *data2 = dataptr[2];
+ npy_intp stride2 = strides[2];
+#endif
+#if (@nop@ <= 3)
+ char *data_out = dataptr[@nop@];
+ npy_intp stride_out = strides[@nop@];
+#endif
+
+ while (count--) {
+#if @nop@ == 1
+ *(npy_bool *)data_out = *(npy_bool *)data0 ||
+ *(npy_bool *)data_out;
+ data0 += stride0;
+ data_out += stride_out;
+#elif @nop@ == 2
+ *(npy_bool *)data_out = (*(npy_bool *)data0 &&
+ *(npy_bool *)data1) ||
+ *(npy_bool *)data_out;
+ data0 += stride0;
+ data1 += stride1;
+ data_out += stride_out;
+#elif @nop@ == 3
+ *(npy_bool *)data_out = (*(npy_bool *)data0 &&
+ *(npy_bool *)data1 &&
+ *(npy_bool *)data2) ||
+ *(npy_bool *)data_out;
+ data0 += stride0;
+ data1 += stride1;
+ data2 += stride2;
+ data_out += stride_out;
+#else
+ npy_bool temp = *(npy_bool *)dataptr[0];
+ int i;
+ for (i = 1; i < nop; ++i) {
+ temp = temp && *(npy_bool *)dataptr[i];
+ }
+ *(npy_bool *)dataptr[nop] = temp || *(npy_bool *)dataptr[i];
+ for (i = 0; i <= nop; ++i) {
+ dataptr[i] += strides[i];
+ }
+#endif
+ }
+}
+
+static void
+bool_sum_of_products_contig_@noplabel@(int nop, char **dataptr,
+ npy_intp *strides, npy_intp count)
+{
+#if (@nop@ <= 3)
+ char *data0 = dataptr[0];
+#endif
+#if (@nop@ == 2 || @nop@ == 3)
+ char *data1 = dataptr[1];
+#endif
+#if (@nop@ == 3)
+ char *data2 = dataptr[2];
+#endif
+#if (@nop@ <= 3)
+ char *data_out = dataptr[@nop@];
+#endif
+
+#if (@nop@ <= 3)
+/* This is placed before the main loop to make small counts faster */
+finish_after_unrolled_loop:
+ switch (count) {
+/**begin repeat1
+ * #i = 6, 5, 4, 3, 2, 1, 0#
+ */
+ case @i@+1:
+# if @nop@ == 1
+ *((npy_bool *)data_out + @i@) = (*((npy_bool *)data0 + @i@)) ||
+ (*((npy_bool *)data_out + @i@));
+ data0 += 8*sizeof(npy_bool);
+ data_out += 8*sizeof(npy_bool);
+# elif @nop@ == 2
+ *((npy_bool *)data_out + @i@) =
+ ((*((npy_bool *)data0 + @i@)) &&
+ (*((npy_bool *)data1 + @i@))) ||
+ (*((npy_bool *)data_out + @i@));
+ data0 += 8*sizeof(npy_bool);
+ data1 += 8*sizeof(npy_bool);
+ data_out += 8*sizeof(npy_bool);
+# elif @nop@ == 3
+ *((npy_bool *)data_out + @i@) =
+ ((*((npy_bool *)data0 + @i@)) &&
+ (*((npy_bool *)data1 + @i@)) &&
+ (*((npy_bool *)data2 + @i@))) ||
+ (*((npy_bool *)data_out + @i@));
+ data0 += 8*sizeof(npy_bool);
+ data1 += 8*sizeof(npy_bool);
+ data2 += 8*sizeof(npy_bool);
+ data_out += 8*sizeof(npy_bool);
+# endif
+/**end repeat1**/
+ case 0:
+ return;
+ }
+#endif
+
+/* Unroll the loop by 8 for fixed-size nop */
+#if (@nop@ <= 3)
+ while (count >= 8) {
+ count -= 8;
+#else
+ while (count--) {
+#endif
+
+# if @nop@ == 1
+/**begin repeat1
+ * #i = 0, 1, 2, 3, 4, 5, 6, 7#
+ */
+ *((npy_bool *)data_out + @i@) = (*((npy_bool *)data0 + @i@)) ||
+ (*((npy_bool *)data_out + @i@));
+/**end repeat1**/
+ data0 += 8*sizeof(npy_bool);
+ data_out += 8*sizeof(npy_bool);
+# elif @nop@ == 2
+/**begin repeat1
+ * #i = 0, 1, 2, 3, 4, 5, 6, 7#
+ */
+ *((npy_bool *)data_out + @i@) =
+ ((*((npy_bool *)data0 + @i@)) &&
+ (*((npy_bool *)data1 + @i@))) ||
+ (*((npy_bool *)data_out + @i@));
+/**end repeat1**/
+ data0 += 8*sizeof(npy_bool);
+ data1 += 8*sizeof(npy_bool);
+ data_out += 8*sizeof(npy_bool);
+# elif @nop@ == 3
+/**begin repeat1
+ * #i = 0, 1, 2, 3, 4, 5, 6, 7#
+ */
+ *((npy_bool *)data_out + @i@) =
+ ((*((npy_bool *)data0 + @i@)) &&
+ (*((npy_bool *)data1 + @i@)) &&
+ (*((npy_bool *)data2 + @i@))) ||
+ (*((npy_bool *)data_out + @i@));
+/**end repeat1**/
+ data0 += 8*sizeof(npy_bool);
+ data1 += 8*sizeof(npy_bool);
+ data2 += 8*sizeof(npy_bool);
+ data_out += 8*sizeof(npy_bool);
+# else
+ npy_bool temp = *(npy_bool *)dataptr[0];
+ int i;
+ for (i = 1; i < nop; ++i) {
+ temp = temp && *(npy_bool *)dataptr[i];
+ }
+ *(npy_bool *)dataptr[nop] = temp || *(npy_bool *)dataptr[i];
+ for (i = 0; i <= nop; ++i) {
+ dataptr[i] += sizeof(npy_bool);
+ }
+# endif
+ }
+
+ /* If the loop was unrolled, we need to finish it off */
+#if (@nop@ <= 3)
+ goto finish_after_unrolled_loop;
+#endif
+}
+
+static void
+bool_sum_of_products_outstride0_@noplabel@(int nop, char **dataptr,
+ npy_intp *strides, npy_intp count)
+{
+ npy_bool accum = 0;
+
+#if (@nop@ <= 3)
+ char *data0 = dataptr[0];
+ npy_intp stride0 = strides[0];
+#endif
+#if (@nop@ == 2 || @nop@ == 3)
+ char *data1 = dataptr[1];
+ npy_intp stride1 = strides[1];
+#endif
+#if (@nop@ == 3)
+ char *data2 = dataptr[2];
+ npy_intp stride2 = strides[2];
+#endif
+
+ while (count--) {
+#if @nop@ == 1
+ accum = *(npy_bool *)data0 || accum;
+ data0 += stride0;
+#elif @nop@ == 2
+ accum = (*(npy_bool *)data0 && *(npy_bool *)data1) || accum;
+ data0 += stride0;
+ data1 += stride1;
+#elif @nop@ == 3
+ accum = (*(npy_bool *)data0 &&
+ *(npy_bool *)data1 &&
+ *(npy_bool *)data2) || accum;
+ data0 += stride0;
+ data1 += stride1;
+ data2 += stride2;
+#else
+ npy_bool temp = *(npy_bool *)dataptr[0];
+ int i;
+ for (i = 1; i < nop; ++i) {
+ temp = temp && *(npy_bool *)dataptr[i];
+ }
+ accum = temp || accum;
+ for (i = 0; i <= nop; ++i) {
+ dataptr[i] += strides[i];
+ }
+#endif
+ }
+
+# if @nop@ <= 3
+ *((npy_bool *)dataptr[@nop@]) = accum || *((npy_bool *)dataptr[@nop@]);
+# else
+ *((npy_bool *)dataptr[nop]) = accum || *((npy_bool *)dataptr[nop]);
+# endif
+}
+
+/**end repeat**/
+
+typedef void (*sum_of_products_fn)(int, char **, npy_intp *, npy_intp);
+
+/* These tables need to match up with the type enum */
+static sum_of_products_fn
+_contig_outstride0_unary_specialization_table[NPY_NTYPES] = {
+/**begin repeat
+ * #name = bool,
+ * byte, ubyte,
+ * short, ushort,
+ * int, uint,
+ * long, ulong,
+ * longlong, ulonglong,
+ * float, double, longdouble,
+ * cfloat, cdouble, clongdouble,
+ * object, string, unicode, void,
+ * datetime, timedelta, half#
+ * #use = 0,
+ * 1, 1,
+ * 1, 1,
+ * 1, 1,
+ * 1, 1,
+ * 1, 1,
+ * 1, 1, 1,
+ * 1, 1, 1,
+ * 0, 0, 0, 0,
+ * 0, 0, 1#
+ */
+#if @use@
+ &@name@_sum_of_products_contig_outstride0_one,
+#else
+ NULL,
+#endif
+/**end repeat**/
+}; /* End of _contig_outstride0_unary_specialization_table */
+
+static sum_of_products_fn _binary_specialization_table[NPY_NTYPES][5] = {
+/**begin repeat
+ * #name = bool,
+ * byte, ubyte,
+ * short, ushort,
+ * int, uint,
+ * long, ulong,
+ * longlong, ulonglong,
+ * float, double, longdouble,
+ * cfloat, cdouble, clongdouble,
+ * object, string, unicode, void,
+ * datetime, timedelta, half#
+ * #use = 0,
+ * 1, 1,
+ * 1, 1,
+ * 1, 1,
+ * 1, 1,
+ * 1, 1,
+ * 1, 1, 1,
+ * 0, 0, 0,
+ * 0, 0, 0, 0,
+ * 0, 0, 1#
+ */
+#if @use@
+{
+ &@name@_sum_of_products_stride0_contig_outstride0_two,
+ &@name@_sum_of_products_stride0_contig_outcontig_two,
+ &@name@_sum_of_products_contig_stride0_outstride0_two,
+ &@name@_sum_of_products_contig_stride0_outcontig_two,
+ &@name@_sum_of_products_contig_contig_outstride0_two,
+},
+#else
+ {NULL, NULL, NULL, NULL, NULL},
+#endif
+/**end repeat**/
+}; /* End of _binary_specialization_table */
+
+static sum_of_products_fn _outstride0_specialized_table[NPY_NTYPES][4] = {
+/**begin repeat
+ * #name = bool,
+ * byte, ubyte,
+ * short, ushort,
+ * int, uint,
+ * long, ulong,
+ * longlong, ulonglong,
+ * float, double, longdouble,
+ * cfloat, cdouble, clongdouble,
+ * object, string, unicode, void,
+ * datetime, timedelta, half#
+ * #use = 1,
+ * 1, 1,
+ * 1, 1,
+ * 1, 1,
+ * 1, 1,
+ * 1, 1,
+ * 1, 1, 1,
+ * 1, 1, 1,
+ * 0, 0, 0, 0,
+ * 0, 0, 1#
+ */
+#if @use@
+{
+ &@name@_sum_of_products_outstride0_any,
+ &@name@_sum_of_products_outstride0_one,
+ &@name@_sum_of_products_outstride0_two,
+ &@name@_sum_of_products_outstride0_three
+},
+#else
+ {NULL, NULL, NULL, NULL},
+#endif
+/**end repeat**/
+}; /* End of _outstride0_specialized_table */
+
+static sum_of_products_fn _allcontig_specialized_table[NPY_NTYPES][4] = {
+/**begin repeat
+ * #name = bool,
+ * byte, ubyte,
+ * short, ushort,
+ * int, uint,
+ * long, ulong,
+ * longlong, ulonglong,
+ * float, double, longdouble,
+ * cfloat, cdouble, clongdouble,
+ * object, string, unicode, void,
+ * datetime, timedelta, half#
+ * #use = 1,
+ * 1, 1,
+ * 1, 1,
+ * 1, 1,
+ * 1, 1,
+ * 1, 1,
+ * 1, 1, 1,
+ * 1, 1, 1,
+ * 0, 0, 0, 0,
+ * 0, 0, 1#
+ */
+#if @use@
+{
+ &@name@_sum_of_products_contig_any,
+ &@name@_sum_of_products_contig_one,
+ &@name@_sum_of_products_contig_two,
+ &@name@_sum_of_products_contig_three
+},
+#else
+ {NULL, NULL, NULL, NULL},
+#endif
+/**end repeat**/
+}; /* End of _allcontig_specialized_table */
+
+static sum_of_products_fn _unspecialized_table[NPY_NTYPES][4] = {
+/**begin repeat
+ * #name = bool,
+ * byte, ubyte,
+ * short, ushort,
+ * int, uint,
+ * long, ulong,
+ * longlong, ulonglong,
+ * float, double, longdouble,
+ * cfloat, cdouble, clongdouble,
+ * object, string, unicode, void,
+ * datetime, timedelta, half#
+ * #use = 1,
+ * 1, 1,
+ * 1, 1,
+ * 1, 1,
+ * 1, 1,
+ * 1, 1,
+ * 1, 1, 1,
+ * 1, 1, 1,
+ * 0, 0, 0, 0,
+ * 0, 0, 1#
+ */
+#if @use@
+{
+ &@name@_sum_of_products_any,
+ &@name@_sum_of_products_one,
+ &@name@_sum_of_products_two,
+ &@name@_sum_of_products_three
+},
+#else
+ {NULL, NULL, NULL, NULL},
+#endif
+/**end repeat**/
+}; /* End of _unnspecialized_table */
+
+static sum_of_products_fn
+get_sum_of_products_function(int nop, int type_num,
+ npy_intp itemsize, npy_intp *fixed_strides)
+{
+ int iop;
+
+ if (type_num >= NPY_NTYPES) {
+ return NULL;
+ }
+
+ /* contiguous reduction */
+ if (nop == 1 && fixed_strides[0] == itemsize && fixed_strides[1] == 0) {
+ sum_of_products_fn ret =
+ _contig_outstride0_unary_specialization_table[type_num];
+ if (ret != NULL) {
+ return ret;
+ }
+ }
+
+ /* nop of 2 has more specializations */
+ if (nop == 2) {
+ /* Encode the zero/contiguous strides */
+ int code;
+ code = (fixed_strides[0] == 0) ? 0 :
+ (fixed_strides[0] == itemsize) ? 2*2*1 : 8;
+ code += (fixed_strides[1] == 0) ? 0 :
+ (fixed_strides[1] == itemsize) ? 2*1 : 8;
+ code += (fixed_strides[2] == 0) ? 0 :
+ (fixed_strides[2] == itemsize) ? 1 : 8;
+ if (code >= 2 && code < 7) {
+ sum_of_products_fn ret =
+ _binary_specialization_table[type_num][code-2];
+ if (ret != NULL) {
+ return ret;
+ }
+ }
+ }
+
+ /* Inner loop with an output stride of 0 */
+ if (fixed_strides[nop] == 0) {
+ return _outstride0_specialized_table[type_num][nop <= 3 ? nop : 0];
+ }
+
+ /* Check for all contiguous */
+ for (iop = 0; iop < nop; ++iop) {
+ if (fixed_strides[iop] != itemsize) {
+ break;
+ }
+ }
+
+ /* Contiguous loop */
+ if (iop == nop) {
+ return _allcontig_specialized_table[type_num][nop <= 3 ? nop : 0];
+ }
+
+ /* None of the above specializations caught it, general loops */
+ return _unspecialized_table[type_num][nop <= 3 ? nop : 0];
+}
+
+/*
+ * Parses the subscripts for one operand into an output
+ * of 'ndim' labels
+ */
+static int
+parse_operand_subscripts(char *subscripts, int length,
+ int ndim,
+ int iop, char *out_labels,
+ char *out_label_counts,
+ int *out_min_label,
+ int *out_max_label,
+ int *out_num_labels,
+ EINSUM_BROADCAST *out_broadcast)
+{
+ int i, idim, ndim_left, label;
+ int left_labels = 0, right_labels = 0, ellipsis = 0;
+
+ /* Process the labels from the end until the ellipsis */
+ idim = ndim-1;
+ for (i = length-1; i >= 0; --i) {
+ label = subscripts[i];
+ /* A label for an axis */
+ if (label > 0 && isalpha(label)) {
+ if (idim >= 0) {
+ out_labels[idim--] = label;
+ /* Calculate the min and max labels */
+ if (label < *out_min_label) {
+ *out_min_label = label;
+ }
+ if (label > *out_max_label) {
+ *out_max_label = label;
+ }
+ /* If it's the first time we see this label, count it */
+ if (out_label_counts[label] == 0) {
+ (*out_num_labels)++;
+ }
+ out_label_counts[label]++;
+ right_labels = 1;
+ }
+ else {
+ PyErr_Format(PyExc_ValueError,
+ "einstein sum subscripts string contains "
+ "too many subscripts for operand %d", iop);
+ return 0;
+ }
+ }
+ /* The end of the ellipsis */
+ else if (label == '.') {
+ /* A valid ellipsis */
+ if (i >= 2 && subscripts[i-1] == '.' && subscripts[i-2] == '.') {
+ ellipsis = 1;
+ length = i-2;
+ break;
+ }
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "einstein sum subscripts string contains a "
+ "'.' that is not part of an ellipsis ('...')");
+ return 0;
+
+ }
+ }
+ else if (label != ' ') {
+ PyErr_Format(PyExc_ValueError,
+ "invalid subscript '%c' in einstein sum "
+ "subscripts string, subscripts must "
+ "be letters", (char)label);
+ return 0;
+ }
+ }
+
+ if (!ellipsis && idim != -1) {
+ PyErr_Format(PyExc_ValueError,
+ "operand has more dimensions than subscripts "
+ "given in einstein sum, but no '...' ellipsis "
+ "provided to broadcast the extra dimensions.");
+ return 0;
+ }
+
+ /* Reduce ndim to just the dimensions left to fill at the beginning */
+ ndim_left = idim+1;
+ idim = 0;
+
+ /*
+ * If we stopped because of an ellipsis, start again from the beginning.
+ * The length was truncated to end at the ellipsis in this case.
+ */
+ if (i > 0) {
+ for (i = 0; i < length; ++i) {
+ label = subscripts[i];
+ /* A label for an axis */
+ if (label > 0 && isalnum(label)) {
+ if (idim < ndim_left) {
+ out_labels[idim++] = label;
+ /* Calculate the min and max labels */
+ if (label < *out_min_label) {
+ *out_min_label = label;
+ }
+ if (label > *out_max_label) {
+ *out_max_label = label;
+ }
+ /* If it's the first time we see this label, count it */
+ if (out_label_counts[label] == 0) {
+ (*out_num_labels)++;
+ }
+ out_label_counts[label]++;
+ left_labels = 1;
+ }
+ else {
+ PyErr_Format(PyExc_ValueError,
+ "einstein sum subscripts string contains "
+ "too many subscripts for operand %d", iop);
+ return 0;
+ }
+ }
+ else if (label != ' ') {
+ PyErr_Format(PyExc_ValueError,
+ "invalid subscript '%c' in einstein sum "
+ "subscripts string, subscripts must "
+ "be letters", (char)label);
+ return 0;
+ }
+ }
+ }
+
+ /* Set the remaining labels to 0 */
+ while (idim < ndim_left) {
+ out_labels[idim++] = 0;
+ }
+
+ /*
+ * Find any labels duplicated for this operand, and turn them
+ * into negative offets to the axis to merge with.
+ */
+ for (idim = 0; idim < ndim-1; ++idim) {
+ char *next;
+ /* If this is a proper label, find any duplicates of it */
+ label = out_labels[idim];
+ if (label > 0) {
+ /* Search for the next matching label */
+ next = (char *)memchr(out_labels+idim+1, label,
+ ndim-idim-1);
+ while (next != NULL) {
+ /* The offset from next to out_labels[idim] (negative) */
+ *next = (out_labels+idim)-next;
+ /* Search for the next matching label */
+ next = (char *)memchr(next+1, label,
+ out_labels+ndim-1-next);
+ }
+ }
+ }
+
+ if (!ellipsis) {
+ *out_broadcast = BROADCAST_NONE;
+ }
+ else if (left_labels && right_labels) {
+ *out_broadcast = BROADCAST_MIDDLE;
+ }
+ else if (!left_labels) {
+ *out_broadcast = BROADCAST_RIGHT;
+ }
+ else {
+ *out_broadcast = BROADCAST_LEFT;
+ }
+
+ return 1;
+}
+
+/*
+ * Parses the subscripts for the output operand into an output
+ * that requires 'ndim_broadcast' unlabeled dimensions, returning
+ * the number of output dimensions. Returns -1 if there is an error.
+ */
+static int
+parse_output_subscripts(char *subscripts, int length,
+ int ndim_broadcast,
+ const char *label_counts,
+ char *out_labels,
+ EINSUM_BROADCAST *out_broadcast)
+{
+ int i, nlabels, label, idim, ndim, ndim_left;
+ int left_labels = 0, right_labels = 0, ellipsis = 0;
+
+ /* Count the labels, making sure they're all unique and valid */
+ nlabels = 0;
+ for (i = 0; i < length; ++i) {
+ label = subscripts[i];
+ if (label > 0 && isalpha(label)) {
+ /* Check if it occurs again */
+ if (memchr(subscripts+i+1, label, length-i-1) == NULL) {
+ /* Check that it was used in the inputs */
+ if (label_counts[label] == 0) {
+ PyErr_Format(PyExc_ValueError,
+ "einstein sum subscripts string included "
+ "output subscript '%c' which never appeared "
+ "in an input", (char)label);
+ return -1;
+ }
+
+ nlabels++;
+ }
+ else {
+ PyErr_Format(PyExc_ValueError,
+ "einstein sum subscripts string includes "
+ "output subscript '%c' multiple times",
+ (char)label);
+ return -1;
+ }
+ }
+ else if (label != '.' && label != ' ') {
+ PyErr_Format(PyExc_ValueError,
+ "invalid subscript '%c' in einstein sum "
+ "subscripts string, subscripts must "
+ "be letters", (char)label);
+ return -1;
+ }
+ }
+
+ /* The number of output dimensions */
+ ndim = ndim_broadcast + nlabels;
+
+ /* Process the labels from the end until the ellipsis */
+ idim = ndim-1;
+ for (i = length-1; i >= 0; --i) {
+ label = subscripts[i];
+ /* A label for an axis */
+ if (label != '.' && label != ' ') {
+ if (idim >= 0) {
+ out_labels[idim--] = label;
+ }
+ else {
+ PyErr_Format(PyExc_ValueError,
+ "einstein sum subscripts string contains "
+ "too many output subscripts");
+ return -1;
+ }
+ right_labels = 1;
+ }
+ /* The end of the ellipsis */
+ else if (label == '.') {
+ /* A valid ellipsis */
+ if (i >= 2 && subscripts[i-1] == '.' && subscripts[i-2] == '.') {
+ ellipsis = 1;
+ length = i-2;
+ break;
+ }
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "einstein sum subscripts string contains a "
+ "'.' that is not part of an ellipsis ('...')");
+ return -1;
+
+ }
+ }
+ }
+
+ if (!ellipsis && idim != -1) {
+ PyErr_SetString(PyExc_ValueError,
+ "output has more dimensions than subscripts "
+ "given in einstein sum, but no '...' ellipsis "
+ "provided to broadcast the extra dimensions.");
+ return 0;
+ }
+
+ /* Reduce ndim to just the dimensions left to fill at the beginning */
+ ndim_left = idim+1;
+ idim = 0;
+
+ /*
+ * If we stopped because of an ellipsis, start again from the beginning.
+ * The length was truncated to end at the ellipsis in this case.
+ */
+ if (i > 0) {
+ for (i = 0; i < length; ++i) {
+ label = subscripts[i];
+ /* A label for an axis */
+ if (label != '.' && label != ' ') {
+ if (idim < ndim_left) {
+ out_labels[idim++] = label;
+ }
+ else {
+ PyErr_Format(PyExc_ValueError,
+ "einstein sum subscripts string contains "
+ "too many subscripts for the output");
+ return -1;
+ }
+ left_labels = 1;
+ }
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "einstein sum subscripts string contains a "
+ "'.' that is not part of an ellipsis ('...')");
+ return -1;
+ }
+ }
+ }
+
+ /* Set the remaining output labels to 0 */
+ while (idim < ndim_left) {
+ out_labels[idim++] = 0;
+ }
+
+ if (!ellipsis) {
+ *out_broadcast = BROADCAST_NONE;
+ }
+ else if (left_labels && right_labels) {
+ *out_broadcast = BROADCAST_MIDDLE;
+ }
+ else if (!left_labels) {
+ *out_broadcast = BROADCAST_RIGHT;
+ }
+ else {
+ *out_broadcast = BROADCAST_LEFT;
+ }
+
+ return ndim;
+}
+
+
+/*
+ * When there's just one operand and no reduction, we
+ * can return a view into op. This calculates the view
+ * if possible.
+ */
+static int
+get_single_op_view(PyArrayObject *op, int iop, char *labels,
+ int ndim_output, char *output_labels,
+ PyArrayObject **ret)
+{
+ npy_intp new_strides[NPY_MAXDIMS];
+ npy_intp new_dims[NPY_MAXDIMS];
+ char *out_label;
+ int label, i, idim, ndim, ibroadcast = 0;
+
+ ndim = PyArray_NDIM(op);
+
+ /* Initialize the dimensions and strides to zero */
+ for (idim = 0; idim < ndim_output; ++idim) {
+ new_dims[idim] = 0;
+ new_strides[idim] = 0;
+ }
+
+ /* Match the labels in the operand with the output labels */
+ for (idim = 0; idim < ndim; ++idim) {
+ label = labels[idim];
+ /* If this label says to merge axes, get the actual label */
+ if (label < 0) {
+ label = labels[idim+label];
+ }
+ /* If the label is 0, it's an unlabeled broadcast dimension */
+ if (label == 0) {
+ /* The next output label that's a broadcast dimension */
+ for (; ibroadcast < ndim_output; ++ibroadcast) {
+ if (output_labels[ibroadcast] == 0) {
+ break;
+ }
+ }
+ if (ibroadcast == ndim_output) {
+ PyErr_SetString(PyExc_ValueError,
+ "output had too few broadcast dimensions");
+ return 0;
+ }
+ new_dims[ibroadcast] = PyArray_DIM(op, idim);
+ new_strides[ibroadcast] = PyArray_STRIDE(op, idim);
+ ++ibroadcast;
+ }
+ else {
+ /* Find the position for this dimension in the output */
+ out_label = (char *)memchr(output_labels, label,
+ ndim_output);
+ /* If it's not found, reduction -> can't return a view */
+ if (out_label == NULL) {
+ break;
+ }
+ /* Update the dimensions and strides of the output */
+ i = out_label - output_labels;
+ if (new_dims[i] != 0 &&
+ new_dims[i] != PyArray_DIM(op, idim)) {
+ PyErr_Format(PyExc_ValueError,
+ "dimensions in operand %d for collapsing "
+ "index '%c' don't match (%d != %d)",
+ iop, label, (int)new_dims[i],
+ (int)PyArray_DIM(op, idim));
+ return 0;
+ }
+ new_dims[i] = PyArray_DIM(op, idim);
+ new_strides[i] += PyArray_STRIDE(op, idim);
+ }
+ }
+ /* If we processed all the input axes, return a view */
+ if (idim == ndim) {
+ Py_INCREF(PyArray_DESCR(op));
+ *ret = (PyArrayObject *)PyArray_NewFromDescr(
+ Py_TYPE(op),
+ PyArray_DESCR(op),
+ ndim_output, new_dims, new_strides,
+ PyArray_DATA(op),
+ 0, (PyObject *)op);
+
+ if (*ret == NULL) {
+ return 0;
+ }
+ if (!PyArray_Check(*ret)) {
+ Py_DECREF(*ret);
+ *ret = NULL;
+ PyErr_SetString(PyExc_RuntimeError,
+ "NewFromDescr failed to return an array");
+ return 0;
+ }
+ PyArray_UpdateFlags(*ret,
+ NPY_C_CONTIGUOUS|NPY_ALIGNED|NPY_F_CONTIGUOUS);
+ Py_INCREF(op);
+ PyArray_BASE(*ret) = (PyObject *)op;
+ return 1;
+ }
+
+ /* Return success, but that we couldn't make a view */
+ *ret = NULL;
+ return 1;
+}
+
+static PyArrayObject *
+get_combined_dims_view(PyArrayObject *op, int iop, char *labels)
+{
+ npy_intp new_strides[NPY_MAXDIMS];
+ npy_intp new_dims[NPY_MAXDIMS];
+ int i, idim, ndim, icombine, combineoffset, label;
+ int icombinemap[NPY_MAXDIMS];
+
+ PyArrayObject *ret = NULL;
+
+ ndim = PyArray_NDIM(op);
+
+ /* Initialize the dimensions and strides to zero */
+ for (idim = 0; idim < ndim; ++idim) {
+ new_dims[idim] = 0;
+ new_strides[idim] = 0;
+ }
+
+ /* Copy the dimensions and strides, except when collapsing */
+ icombine = 0;
+ for (idim = 0; idim < ndim; ++idim) {
+ label = labels[idim];
+ /* If this label says to merge axes, get the actual label */
+ if (label < 0) {
+ combineoffset = label;
+ label = labels[idim+label];
+ }
+ else {
+ combineoffset = 0;
+ if (icombine != idim) {
+ labels[icombine] = labels[idim];
+ }
+ icombinemap[idim] = icombine;
+ }
+ /* If the label is 0, it's an unlabeled broadcast dimension */
+ if (label == 0) {
+ new_dims[icombine] = PyArray_DIM(op, idim);
+ new_strides[icombine] = PyArray_STRIDE(op, idim);
+ }
+ else {
+ /* Update the combined axis dimensions and strides */
+ i = idim + combineoffset;
+ if (combineoffset < 0 &&
+ new_dims[i] != PyArray_DIM(op, idim)) {
+ PyErr_Format(PyExc_ValueError,
+ "dimensions in operand %d for collapsing "
+ "index '%c' don't match (%d != %d)",
+ iop, label, (int)new_dims[i],
+ (int)PyArray_DIM(op, idim));
+ return NULL;
+ }
+ i = icombinemap[i];
+ new_dims[i] = PyArray_DIM(op, idim);
+ new_strides[i] += PyArray_STRIDE(op, idim);
+ }
+
+ /* If the label didn't say to combine axes, increment dest i */
+ if (combineoffset == 0) {
+ icombine++;
+ }
+ }
+
+ /* The compressed number of dimensions */
+ ndim = icombine;
+
+ Py_INCREF(PyArray_DESCR(op));
+ ret = (PyArrayObject *)PyArray_NewFromDescr(
+ Py_TYPE(op),
+ PyArray_DESCR(op),
+ ndim, new_dims, new_strides,
+ PyArray_DATA(op),
+ PyArray_ISWRITEABLE(op) ? NPY_WRITEABLE : 0,
+ (PyObject *)op);
+
+ if (ret == NULL) {
+ return NULL;
+ }
+ if (!PyArray_Check(ret)) {
+ Py_DECREF(ret);
+ PyErr_SetString(PyExc_RuntimeError,
+ "NewFromDescr failed to return an array");
+ return NULL;
+ }
+ PyArray_UpdateFlags(ret,
+ NPY_C_CONTIGUOUS|NPY_ALIGNED|NPY_F_CONTIGUOUS);
+ Py_INCREF(op);
+ PyArray_BASE(ret) = (PyObject *)op;
+
+ return ret;
+}
+
+static int
+prepare_op_axes(int ndim, int iop, char *labels, int *axes,
+ int ndim_iter, char *iter_labels, EINSUM_BROADCAST broadcast)
+{
+ int i, label, ibroadcast;
+
+ /* Regular broadcasting */
+ if (broadcast == BROADCAST_RIGHT) {
+ /* broadcast dimensions get placed in rightmost position */
+ ibroadcast = ndim-1;
+ for (i = ndim_iter-1; i >= 0; --i) {
+ label = iter_labels[i];
+ /*
+ * If it's an unlabeled broadcast dimension, choose
+ * the next broadcast dimension from the operand.
+ */
+ if (label == 0) {
+ while (ibroadcast >= 0 && labels[ibroadcast] != 0) {
+ --ibroadcast;
+ }
+ /*
+ * If we used up all the operand broadcast dimensions,
+ * extend it with a "newaxis"
+ */
+ if (ibroadcast < 0) {
+ axes[i] = -1;
+ }
+ /* Otherwise map to the broadcast axis */
+ else {
+ axes[i] = ibroadcast;
+ --ibroadcast;
+ }
+ }
+ /* It's a labeled dimension, find the matching one */
+ else {
+ char *match = memchr(labels, label, ndim);
+ /* If the op doesn't have the label, broadcast it */
+ if (match == NULL) {
+ axes[i] = -1;
+ }
+ /* Otherwise use it */
+ else {
+ axes[i] = match - labels;
+ }
+ }
+ }
+ }
+ /* Reverse broadcasting */
+ else if (broadcast == BROADCAST_LEFT) {
+ /* broadcast dimensions get placed in leftmost position */
+ ibroadcast = 0;
+ for (i = 0; i < ndim_iter; ++i) {
+ label = iter_labels[i];
+ /*
+ * If it's an unlabeled broadcast dimension, choose
+ * the next broadcast dimension from the operand.
+ */
+ if (label == 0) {
+ while (ibroadcast < ndim && labels[ibroadcast] != 0) {
+ ++ibroadcast;
+ }
+ /*
+ * If we used up all the operand broadcast dimensions,
+ * extend it with a "newaxis"
+ */
+ if (ibroadcast >= ndim) {
+ axes[i] = -1;
+ }
+ /* Otherwise map to the broadcast axis */
+ else {
+ axes[i] = ibroadcast;
+ ++ibroadcast;
+ }
+ }
+ /* It's a labeled dimension, find the matching one */
+ else {
+ char *match = memchr(labels, label, ndim);
+ /* If the op doesn't have the label, broadcast it */
+ if (match == NULL) {
+ axes[i] = -1;
+ }
+ /* Otherwise use it */
+ else {
+ axes[i] = match - labels;
+ }
+ }
+ }
+ }
+ /* Middle or None broadcasting */
+ else {
+ /* broadcast dimensions get placed in leftmost position */
+ ibroadcast = 0;
+ for (i = 0; i < ndim_iter; ++i) {
+ label = iter_labels[i];
+ /*
+ * If it's an unlabeled broadcast dimension, choose
+ * the next broadcast dimension from the operand.
+ */
+ if (label == 0) {
+ while (ibroadcast < ndim && labels[ibroadcast] != 0) {
+ ++ibroadcast;
+ }
+ /*
+ * If we used up all the operand broadcast dimensions,
+ * it's an error
+ */
+ if (ibroadcast >= ndim) {
+ PyErr_Format(PyExc_ValueError,
+ "operand %d did not have enough dimensions "
+ "to match the broadcasting, and couldn't be "
+ "extended because einstein sum subscripts "
+ "were specified at both the start and end",
+ iop);
+ return 0;
+ }
+ /* Otherwise map to the broadcast axis */
+ else {
+ axes[i] = ibroadcast;
+ ++ibroadcast;
+ }
+ }
+ /* It's a labeled dimension, find the matching one */
+ else {
+ char *match = memchr(labels, label, ndim);
+ /* If the op doesn't have the label, broadcast it */
+ if (match == NULL) {
+ axes[i] = -1;
+ }
+ /* Otherwise use it */
+ else {
+ axes[i] = match - labels;
+ }
+ }
+ }
+ }
+
+ return 1;
+}
+
+static int
+unbuffered_loop_nop1_ndim2(NpyIter *iter)
+{
+ npy_intp coord, shape[2], strides[2][2];
+ char *ptrs[2][2], *ptr;
+ sum_of_products_fn sop;
+
+#if NPY_EINSUM_DBG_TRACING
+ NpyIter_DebugPrint(iter);
+#endif
+ NPY_EINSUM_DBG_PRINT("running hand-coded 1-op 2-dim loop\n");
+
+ NpyIter_GetShape(iter, shape);
+ memcpy(strides[0], NpyIter_GetAxisStrideArray(iter, 0),
+ 2*sizeof(npy_intp));
+ memcpy(strides[1], NpyIter_GetAxisStrideArray(iter, 1),
+ 2*sizeof(npy_intp));
+ memcpy(ptrs[0], NpyIter_GetInitialDataPtrArray(iter),
+ 2*sizeof(char *));
+ memcpy(ptrs[1], ptrs[0], 2*sizeof(char*));
+
+ sop = get_sum_of_products_function(1,
+ NpyIter_GetDescrArray(iter)[0]->type_num,
+ NpyIter_GetDescrArray(iter)[0]->elsize,
+ strides[0]);
+
+ if (sop == NULL) {
+ PyErr_SetString(PyExc_TypeError,
+ "invalid data type for einsum");
+ return -1;
+ }
+
+ /*
+ * Since the iterator wasn't tracking coordinates, the
+ * loop provided by the iterator is in Fortran-order.
+ */
+ for (coord = shape[1]; coord > 0; --coord) {
+ sop(1, ptrs[0], strides[0], shape[0]);
+
+ ptr = ptrs[1][0] + strides[1][0];
+ ptrs[0][0] = ptrs[1][0] = ptr;
+ ptr = ptrs[1][1] + strides[1][1];
+ ptrs[0][1] = ptrs[1][1] = ptr;
+ }
+
+ return 0;
+}
+
+static int
+unbuffered_loop_nop1_ndim3(NpyIter *iter)
+{
+ npy_intp coords[2], shape[3], strides[3][2];
+ char *ptrs[3][2], *ptr;
+ sum_of_products_fn sop;
+
+#if NPY_EINSUM_DBG_TRACING
+ NpyIter_DebugPrint(iter);
+#endif
+ NPY_EINSUM_DBG_PRINT("running hand-coded 1-op 3-dim loop\n");
+
+ NpyIter_GetShape(iter, shape);
+ memcpy(strides[0], NpyIter_GetAxisStrideArray(iter, 0),
+ 2*sizeof(npy_intp));
+ memcpy(strides[1], NpyIter_GetAxisStrideArray(iter, 1),
+ 2*sizeof(npy_intp));
+ memcpy(strides[2], NpyIter_GetAxisStrideArray(iter, 2),
+ 2*sizeof(npy_intp));
+ memcpy(ptrs[0], NpyIter_GetInitialDataPtrArray(iter),
+ 2*sizeof(char *));
+ memcpy(ptrs[1], ptrs[0], 2*sizeof(char*));
+ memcpy(ptrs[2], ptrs[0], 2*sizeof(char*));
+
+ sop = get_sum_of_products_function(1,
+ NpyIter_GetDescrArray(iter)[0]->type_num,
+ NpyIter_GetDescrArray(iter)[0]->elsize,
+ strides[0]);
+
+ if (sop == NULL) {
+ PyErr_SetString(PyExc_TypeError,
+ "invalid data type for einsum");
+ return -1;
+ }
+
+ /*
+ * Since the iterator wasn't tracking coordinates, the
+ * loop provided by the iterator is in Fortran-order.
+ */
+ for (coords[1] = shape[2]; coords[1] > 0; --coords[1]) {
+ for (coords[0] = shape[1]; coords[0] > 0; --coords[0]) {
+ sop(1, ptrs[0], strides[0], shape[0]);
+
+ ptr = ptrs[1][0] + strides[1][0];
+ ptrs[0][0] = ptrs[1][0] = ptr;
+ ptr = ptrs[1][1] + strides[1][1];
+ ptrs[0][1] = ptrs[1][1] = ptr;
+ }
+ ptr = ptrs[2][0] + strides[2][0];
+ ptrs[0][0] = ptrs[1][0] = ptrs[2][0] = ptr;
+ ptr = ptrs[2][1] + strides[2][1];
+ ptrs[0][1] = ptrs[1][1] = ptrs[2][1] = ptr;
+ }
+
+ return 0;
+}
+
+static int
+unbuffered_loop_nop2_ndim2(NpyIter *iter)
+{
+ npy_intp coord, shape[2], strides[2][3];
+ char *ptrs[2][3], *ptr;
+ sum_of_products_fn sop;
+
+#if NPY_EINSUM_DBG_TRACING
+ NpyIter_DebugPrint(iter);
+#endif
+ NPY_EINSUM_DBG_PRINT("running hand-coded 2-op 2-dim loop\n");
+
+ NpyIter_GetShape(iter, shape);
+ memcpy(strides[0], NpyIter_GetAxisStrideArray(iter, 0),
+ 3*sizeof(npy_intp));
+ memcpy(strides[1], NpyIter_GetAxisStrideArray(iter, 1),
+ 3*sizeof(npy_intp));
+ memcpy(ptrs[0], NpyIter_GetInitialDataPtrArray(iter),
+ 3*sizeof(char *));
+ memcpy(ptrs[1], ptrs[0], 3*sizeof(char*));
+
+ sop = get_sum_of_products_function(2,
+ NpyIter_GetDescrArray(iter)[0]->type_num,
+ NpyIter_GetDescrArray(iter)[0]->elsize,
+ strides[0]);
+
+ if (sop == NULL) {
+ PyErr_SetString(PyExc_TypeError,
+ "invalid data type for einsum");
+ return -1;
+ }
+
+ /*
+ * Since the iterator wasn't tracking coordinates, the
+ * loop provided by the iterator is in Fortran-order.
+ */
+ for (coord = shape[1]; coord > 0; --coord) {
+ sop(2, ptrs[0], strides[0], shape[0]);
+
+ ptr = ptrs[1][0] + strides[1][0];
+ ptrs[0][0] = ptrs[1][0] = ptr;
+ ptr = ptrs[1][1] + strides[1][1];
+ ptrs[0][1] = ptrs[1][1] = ptr;
+ ptr = ptrs[1][2] + strides[1][2];
+ ptrs[0][2] = ptrs[1][2] = ptr;
+ }
+
+ return 0;
+}
+
+static int
+unbuffered_loop_nop2_ndim3(NpyIter *iter)
+{
+ npy_intp coords[2], shape[3], strides[3][3];
+ char *ptrs[3][3], *ptr;
+ sum_of_products_fn sop;
+
+#if NPY_EINSUM_DBG_TRACING
+ NpyIter_DebugPrint(iter);
+#endif
+ NPY_EINSUM_DBG_PRINT("running hand-coded 2-op 3-dim loop\n");
+
+ NpyIter_GetShape(iter, shape);
+ memcpy(strides[0], NpyIter_GetAxisStrideArray(iter, 0),
+ 3*sizeof(npy_intp));
+ memcpy(strides[1], NpyIter_GetAxisStrideArray(iter, 1),
+ 3*sizeof(npy_intp));
+ memcpy(strides[2], NpyIter_GetAxisStrideArray(iter, 2),
+ 3*sizeof(npy_intp));
+ memcpy(ptrs[0], NpyIter_GetInitialDataPtrArray(iter),
+ 3*sizeof(char *));
+ memcpy(ptrs[1], ptrs[0], 3*sizeof(char*));
+ memcpy(ptrs[2], ptrs[0], 3*sizeof(char*));
+
+ sop = get_sum_of_products_function(2,
+ NpyIter_GetDescrArray(iter)[0]->type_num,
+ NpyIter_GetDescrArray(iter)[0]->elsize,
+ strides[0]);
+
+ if (sop == NULL) {
+ PyErr_SetString(PyExc_TypeError,
+ "invalid data type for einsum");
+ return -1;
+ }
+
+ /*
+ * Since the iterator wasn't tracking coordinates, the
+ * loop provided by the iterator is in Fortran-order.
+ */
+ for (coords[1] = shape[2]; coords[1] > 0; --coords[1]) {
+ for (coords[0] = shape[1]; coords[0] > 0; --coords[0]) {
+ sop(2, ptrs[0], strides[0], shape[0]);
+
+ ptr = ptrs[1][0] + strides[1][0];
+ ptrs[0][0] = ptrs[1][0] = ptr;
+ ptr = ptrs[1][1] + strides[1][1];
+ ptrs[0][1] = ptrs[1][1] = ptr;
+ ptr = ptrs[1][2] + strides[1][2];
+ ptrs[0][2] = ptrs[1][2] = ptr;
+ }
+ ptr = ptrs[2][0] + strides[2][0];
+ ptrs[0][0] = ptrs[1][0] = ptrs[2][0] = ptr;
+ ptr = ptrs[2][1] + strides[2][1];
+ ptrs[0][1] = ptrs[1][1] = ptrs[2][1] = ptr;
+ ptr = ptrs[2][2] + strides[2][2];
+ ptrs[0][2] = ptrs[1][2] = ptrs[2][2] = ptr;
+ }
+
+ return 0;
+}
+
+
+/*NUMPY_API
+ * This function provides summation of array elements according to
+ * the Einstein summation convention. For example:
+ * - trace(a) -> einsum("ii", a)
+ * - transpose(a) -> einsum("ji", a)
+ * - multiply(a,b) -> einsum(",", a, b)
+ * - inner(a,b) -> einsum("i,i", a, b)
+ * - outer(a,b) -> einsum("i,j", a, b)
+ * - matvec(a,b) -> einsum("ij,j", a, b)
+ * - matmat(a,b) -> einsum("ij,jk", a, b)
+ *
+ * subscripts: The string of subscripts for einstein summation.
+ * nop: The number of operands
+ * op_in: The array of operands
+ * dtype: Either NULL, or the data type to force the calculation as.
+ * order: The order for the calculation/the output axes.
+ * casting: What kind of casts should be permitted.
+ * out: Either NULL, or an array into which the output should be placed.
+ *
+ * By default, the labels get placed in alphabetical order
+ * at the end of the output. So, if c = einsum("i,j", a, b)
+ * then c[i,j] == a[i]*b[j], but if c = einsum("j,i", a, b)
+ * then c[i,j] = a[j]*b[i].
+ *
+ * Alternatively, you can control the output order or prevent
+ * an axis from being summed/force an axis to be summed by providing
+ * indices for the output. This allows us to turn 'trace' into
+ * 'diag', for example.
+ * - diag(a) -> einsum("ii->i", a)
+ * - sum(a, axis=0) -> einsum("i...->", a)
+ *
+ * Subscripts at the beginning and end may be specified by
+ * putting an ellipsis "..." in the middle. For example,
+ * the function einsum("i...i", a) takes the diagonal of
+ * the first and last dimensions of the operand, and
+ * einsum("ij...,jk...->ik...") takes the matrix product using
+ * the first two indices of each operand instead of the last two.
+ *
+ * When there is only one operand, no axes being summed, and
+ * no output parameter, this function returns a view
+ * into the operand instead of making a copy.
+ */
+NPY_NO_EXPORT PyArrayObject *
+PyArray_EinsteinSum(char *subscripts, npy_intp nop,
+ PyArrayObject **op_in,
+ PyArray_Descr *dtype,
+ NPY_ORDER order, NPY_CASTING casting,
+ PyArrayObject *out)
+{
+ int iop, label, min_label = 127, max_label = 0, num_labels;
+ char label_counts[128];
+ char op_labels[NPY_MAXARGS][NPY_MAXDIMS];
+ char output_labels[NPY_MAXDIMS], *iter_labels;
+ int idim, ndim_output, ndim_broadcast, ndim_iter;
+
+ EINSUM_BROADCAST broadcast[NPY_MAXARGS];
+ PyArrayObject *op[NPY_MAXARGS], *ret = NULL;
+ PyArray_Descr *op_dtypes_array[NPY_MAXARGS], **op_dtypes;
+
+ int op_axes_arrays[NPY_MAXARGS][NPY_MAXDIMS];
+ int *op_axes[NPY_MAXARGS];
+ npy_uint32 op_flags[NPY_MAXARGS];
+
+ NpyIter *iter;
+ sum_of_products_fn sop;
+ npy_intp fixed_strides[NPY_MAXARGS];
+
+ /* nop+1 (+1 is for the output) must fit in NPY_MAXARGS */
+ if (nop >= NPY_MAXARGS) {
+ PyErr_SetString(PyExc_ValueError,
+ "too many operands provided to einstein sum function");
+ return NULL;
+ }
+ else if (nop < 1) {
+ PyErr_SetString(PyExc_ValueError,
+ "not enough operands provided to einstein sum function");
+ return NULL;
+ }
+
+ /* Parse the subscripts string into label_counts and op_labels */
+ memset(label_counts, 0, sizeof(label_counts));
+ num_labels = 0;
+ for (iop = 0; iop < nop; ++iop) {
+ int length = (int)strcspn(subscripts, ",-");
+
+ if (iop == nop-1 && subscripts[length] == ',') {
+ PyErr_SetString(PyExc_ValueError,
+ "more operands provided to einstein sum function "
+ "than specified in the subscripts string");
+ return NULL;
+ }
+ else if(iop < nop-1 && subscripts[length] != ',') {
+ PyErr_SetString(PyExc_ValueError,
+ "fewer operands provided to einstein sum function "
+ "than specified in the subscripts string");
+ return NULL;
+ }
+
+ if (!parse_operand_subscripts(subscripts, length,
+ PyArray_NDIM(op_in[iop]),
+ iop, op_labels[iop], label_counts,
+ &min_label, &max_label, &num_labels,
+ &broadcast[iop])) {
+ return NULL;
+ }
+
+ /* Move subscripts to the start of the labels for the next op */
+ subscripts += length;
+ if (iop < nop-1) {
+ subscripts++;
+ }
+ }
+
+ /*
+ * Find the number of broadcast dimensions, which is the maximum
+ * number of labels == 0 in an op_labels array.
+ */
+ ndim_broadcast = 0;
+ for (iop = 0; iop < nop; ++iop) {
+ npy_intp count_zeros = 0;
+ int ndim;
+ char *labels = op_labels[iop];
+
+ ndim = PyArray_NDIM(op_in[iop]);
+ for (idim = 0; idim < ndim; ++idim) {
+ if (labels[idim] == 0) {
+ ++count_zeros;
+ }
+ }
+
+ if (count_zeros > ndim_broadcast) {
+ ndim_broadcast = count_zeros;
+ }
+ }
+
+ /*
+ * If there is no output signature, create one using each label
+ * that appeared once, in alphabetical order
+ */
+ if (subscripts[0] == '\0') {
+ char outsubscripts[NPY_MAXDIMS + 3];
+ int length;
+ /* If no output was specified, always broadcast left (like normal) */
+ outsubscripts[0] = '.';
+ outsubscripts[1] = '.';
+ outsubscripts[2] = '.';
+ length = 3;
+ for (label = min_label; label <= max_label; ++label) {
+ if (label_counts[label] == 1) {
+ if (length < NPY_MAXDIMS-1) {
+ outsubscripts[length++] = label;
+ }
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "einstein sum subscript string has too many "
+ "distinct labels");
+ return NULL;
+ }
+ }
+ }
+ /* Parse the output subscript string */
+ ndim_output = parse_output_subscripts(outsubscripts, length,
+ ndim_broadcast, label_counts,
+ output_labels, &broadcast[nop]);
+ }
+ else {
+ if (subscripts[0] != '-' || subscripts[1] != '>') {
+ PyErr_SetString(PyExc_ValueError,
+ "einstein sum subscript string does not "
+ "contain proper '->' output specified");
+ return NULL;
+ }
+ subscripts += 2;
+
+ /* Parse the output subscript string */
+ ndim_output = parse_output_subscripts(subscripts, strlen(subscripts),
+ ndim_broadcast, label_counts,
+ output_labels, &broadcast[nop]);
+ }
+ if (ndim_output < 0) {
+ return NULL;
+ }
+
+ if (out != NULL && PyArray_NDIM(out) != ndim_output) {
+ PyErr_Format(PyExc_ValueError,
+ "out parameter does not have the correct number of "
+ "dimensions, has %d but should have %d",
+ (int)PyArray_NDIM(out), (int)ndim_output);
+ return NULL;
+ }
+
+ /* Set all the op references to NULL */
+ for (iop = 0; iop < nop; ++iop) {
+ op[iop] = NULL;
+ }
+
+ /*
+ * Process all the input ops, combining dimensions into their
+ * diagonal where specified.
+ */
+ for (iop = 0; iop < nop; ++iop) {
+ char *labels = op_labels[iop];
+ int combine, ndim;
+
+ ndim = PyArray_NDIM(op_in[iop]);
+
+ /*
+ * If there's just one operand and no output parameter,
+ * first try remapping the axes to the output to return
+ * a view instead of a copy.
+ */
+ if (iop == 0 && nop == 1 && out == NULL) {
+ ret = NULL;
+
+ if (!get_single_op_view(op_in[iop], iop, labels,
+ ndim_output, output_labels,
+ &ret)) {
+ return NULL;
+ }
+
+ if (ret != NULL) {
+ return ret;
+ }
+ }
+
+ /* Check whether any dimensions need to be combined */
+ combine = 0;
+ for (idim = 0; idim < ndim; ++idim) {
+ if (labels[idim] < 0) {
+ combine = 1;
+ }
+ }
+
+ /* If any dimensions are combined, create a view which combines them */
+ if (combine) {
+ op[iop] = get_combined_dims_view(op_in[iop], iop, labels);
+ if (op[iop] == NULL) {
+ goto fail;
+ }
+ }
+ /* No combining needed */
+ else {
+ Py_INCREF(op_in[iop]);
+ op[iop] = op_in[iop];
+ }
+ }
+
+ /* Set the output op */
+ op[nop] = out;
+
+ /*
+ * Set up the labels for the iterator (output + combined labels).
+ * Can just share the output_labels memory, because iter_labels
+ * is output_labels with some more labels appended.
+ */
+ iter_labels = output_labels;
+ ndim_iter = ndim_output;
+ for (label = min_label; label <= max_label; ++label) {
+ if (label_counts[label] > 0 &&
+ memchr(output_labels, label, ndim_output) == NULL) {
+ if (ndim_iter >= NPY_MAXDIMS) {
+ PyErr_SetString(PyExc_ValueError,
+ "too many subscripts in einsum");
+ goto fail;
+ }
+ iter_labels[ndim_iter++] = label;
+ }
+ }
+
+ /* Set up the op_axes for the iterator */
+ for (iop = 0; iop < nop; ++iop) {
+ op_axes[iop] = op_axes_arrays[iop];
+
+ if (!prepare_op_axes(PyArray_NDIM(op[iop]), iop, op_labels[iop],
+ op_axes[iop], ndim_iter, iter_labels, broadcast[iop])) {
+ goto fail;
+ }
+ }
+
+ /* Set up the op_dtypes if dtype was provided */
+ if (dtype == NULL) {
+ op_dtypes = NULL;
+ }
+ else {
+ op_dtypes = op_dtypes_array;
+ for (iop = 0; iop <= nop; ++iop) {
+ op_dtypes[iop] = dtype;
+ }
+ }
+
+ /* Set the op_axes for the output */
+ op_axes[nop] = op_axes_arrays[nop];
+ for (idim = 0; idim < ndim_output; ++idim) {
+ op_axes[nop][idim] = idim;
+ }
+ for (idim = ndim_output; idim < ndim_iter; ++idim) {
+ op_axes[nop][idim] = -1;
+ }
+
+ /* Set the iterator per-op flags */
+
+ for (iop = 0; iop < nop; ++iop) {
+ op_flags[iop] = NPY_ITER_READONLY|
+ NPY_ITER_NBO|
+ NPY_ITER_ALIGNED;
+ }
+ op_flags[nop] = NPY_ITER_READWRITE|
+ NPY_ITER_NBO|
+ NPY_ITER_ALIGNED|
+ NPY_ITER_ALLOCATE|
+ NPY_ITER_NO_BROADCAST;
+
+ /* Allocate the iterator */
+ iter = NpyIter_MultiNew(nop+1, op, NPY_ITER_NO_INNER_ITERATION|
+ ((dtype != NULL) ? 0 : NPY_ITER_COMMON_DTYPE)|
+ NPY_ITER_BUFFERED|
+ NPY_ITER_DELAY_BUFALLOC|
+ NPY_ITER_GROWINNER|
+ NPY_ITER_REDUCE_OK|
+ NPY_ITER_REFS_OK|
+ NPY_ITER_ZEROSIZE_OK,
+ order, casting,
+ op_flags, op_dtypes,
+ ndim_iter, op_axes, 0);
+
+ if (iter == NULL) {
+ goto fail;
+ }
+
+ /* Initialize the output to all zeros and reset the iterator */
+ ret = NpyIter_GetOperandArray(iter)[nop];
+ Py_INCREF(ret);
+ PyArray_FillWithZero(ret);
+
+
+ /***************************/
+ /*
+ * Accceleration for some specific loop structures. Note
+ * that with axis coalescing, inputs with more dimensions can
+ * be reduced to fit into these patterns.
+ */
+ if (!NpyIter_RequiresBuffering(iter)) {
+ int ndim = NpyIter_GetNDim(iter);
+ switch (nop) {
+ case 1:
+ if (ndim == 2) {
+ if (unbuffered_loop_nop1_ndim2(iter) < 0) {
+ Py_DECREF(ret);
+ ret = NULL;
+ goto fail;
+ }
+ goto finish;
+ }
+ else if (ndim == 3) {
+ if (unbuffered_loop_nop1_ndim3(iter) < 0) {
+ Py_DECREF(ret);
+ ret = NULL;
+ goto fail;
+ }
+ goto finish;
+ }
+ break;
+ case 2:
+ if (ndim == 2) {
+ if (unbuffered_loop_nop2_ndim2(iter) < 0) {
+ Py_DECREF(ret);
+ ret = NULL;
+ goto fail;
+ }
+ goto finish;
+ }
+ else if (ndim == 3) {
+ if (unbuffered_loop_nop2_ndim3(iter) < 0) {
+ Py_DECREF(ret);
+ ret = NULL;
+ goto fail;
+ }
+ goto finish;
+ }
+ break;
+ }
+ }
+ /***************************/
+
+ if (NpyIter_Reset(iter, NULL) != NPY_SUCCEED) {
+ Py_DECREF(ret);
+ goto fail;
+ }
+
+ /*
+ * Get an inner loop function, specializing it based on
+ * the strides that are fixed for the whole loop.
+ */
+ NpyIter_GetInnerFixedStrideArray(iter, fixed_strides);
+ sop = get_sum_of_products_function(nop,
+ NpyIter_GetDescrArray(iter)[0]->type_num,
+ NpyIter_GetDescrArray(iter)[0]->elsize,
+ fixed_strides);
+
+#if NPY_EINSUM_DBG_TRACING
+ NpyIter_DebugPrint(iter);
+#endif
+
+ /* Finally, the main loop */
+ if (sop == NULL) {
+ PyErr_SetString(PyExc_TypeError,
+ "invalid data type for einsum");
+ Py_DECREF(ret);
+ ret = NULL;
+ }
+ else if (NpyIter_GetIterSize(iter) != 0) {
+ NpyIter_IterNextFunc *iternext;
+ char **dataptr;
+ npy_intp *stride;
+ npy_intp *countptr;
+ int needs_api = NpyIter_IterationNeedsAPI(iter);
+ NPY_BEGIN_THREADS_DEF;
+
+ iternext = NpyIter_GetIterNext(iter, NULL);
+ if (iternext == NULL) {
+ NpyIter_Deallocate(iter);
+ Py_DECREF(ret);
+ goto fail;
+ }
+ dataptr = NpyIter_GetDataPtrArray(iter);
+ stride = NpyIter_GetInnerStrideArray(iter);
+ countptr = NpyIter_GetInnerLoopSizePtr(iter);
+
+ if (!needs_api) {
+ NPY_BEGIN_THREADS;
+ }
+ NPY_EINSUM_DBG_PRINT("Einsum loop\n");
+ do {
+ sop(nop, dataptr, stride, *countptr);
+ } while(iternext(iter));
+ if (!needs_api) {
+ NPY_END_THREADS;
+ }
+
+ /* If the API was needed, it may have thrown an error */
+ if (needs_api && PyErr_Occurred()) {
+ Py_DECREF(ret);
+ ret = NULL;
+ }
+ }
+
+finish:
+ NpyIter_Deallocate(iter);
+ for (iop = 0; iop < nop; ++iop) {
+ Py_DECREF(op[iop]);
+ }
+
+ return ret;
+
+fail:
+ for (iop = 0; iop < nop; ++iop) {
+ Py_XDECREF(op[iop]);
+ }
+
+ return NULL;
+}
diff --git a/numpy/core/src/multiarray/flagsobject.c b/numpy/core/src/multiarray/flagsobject.c
index ca27ef083..7e7dc3e2d 100644
--- a/numpy/core/src/multiarray/flagsobject.c
+++ b/numpy/core/src/multiarray/flagsobject.c
@@ -576,13 +576,13 @@ arrayflags_richcompare(PyObject *self, PyObject *other, int cmp_op)
if (PyObject_TypeCheck(other, &PyArrayFlags_Type)) {
cmp = arrayflags_compare((PyArrayFlagsObject *)self,
(PyArrayFlagsObject *)other);
- }
- if (cmp_op == Py_EQ) {
- result = (cmp == 0) ? Py_True : Py_False;
- }
- else if (cmp_op == Py_NE) {
- result = (cmp != 0) ? Py_True : Py_False;
+ if (cmp_op == Py_EQ) {
+ result = (cmp == 0) ? Py_True : Py_False;
+ }
+ else if (cmp_op == Py_NE) {
+ result = (cmp != 0) ? Py_True : Py_False;
+ }
}
Py_INCREF(result);
diff --git a/numpy/core/src/multiarray/getset.c b/numpy/core/src/multiarray/getset.c
index a636383a6..3d2b6975e 100644
--- a/numpy/core/src/multiarray/getset.c
+++ b/numpy/core/src/multiarray/getset.c
@@ -418,10 +418,21 @@ array_descr_set(PyArrayObject *self, PyObject *arg)
}
if (newtype->elsize == 0) {
- PyErr_SetString(PyExc_TypeError,
- "data-type must not be 0-sized");
- Py_DECREF(newtype);
- return -1;
+ /* Allow a void view */
+ if (newtype->type_num == NPY_VOID) {
+ PyArray_DESCR_REPLACE(newtype);
+ if (newtype == NULL) {
+ return -1;
+ }
+ newtype->elsize = self->descr->elsize;
+ }
+ /* But no other flexible types */
+ else {
+ PyErr_SetString(PyExc_TypeError,
+ "data-type must not be 0-sized");
+ Py_DECREF(newtype);
+ return -1;
+ }
}
@@ -596,7 +607,7 @@ _get_part(PyArrayObject *self, int imag)
"Cannot convert complex type number %d to float",
self->descr->type_num);
return NULL;
-
+
}
type = PyArray_DescrFromType(float_type_num);
diff --git a/numpy/core/src/multiarray/item_selection.c b/numpy/core/src/multiarray/item_selection.c
index 660c6d9fd..4d1621534 100644
--- a/numpy/core/src/multiarray/item_selection.c
+++ b/numpy/core/src/multiarray/item_selection.c
@@ -15,6 +15,7 @@
#include "common.h"
#include "ctors.h"
+#include "lowlevel_strided_loops.h"
#define PyAO PyArrayObject
#define _check_axis PyArray_CheckAxis
@@ -621,7 +622,7 @@ PyArray_Choose(PyArrayObject *ip, PyObject *op, PyArrayObject *ret,
if (ap == NULL) {
goto fail;
}
- /* Broadcast all arrays to each other, index array at the end. */
+ /* Broadcast all arrays to each other, index array at the end. */
multi = (PyArrayMultiIterObject *)
PyArray_MultiIterFromObjects((PyObject **)mps, n, 1, ap);
if (multi == NULL) {
@@ -1460,16 +1461,16 @@ PyArray_SearchSorted(PyArrayObject *op1, PyObject *op2, NPY_SEARCHSIDE side)
dtype = PyArray_DescrFromObject((PyObject *)op2, op1->descr);
/* need ap1 as contiguous array and of right type */
Py_INCREF(dtype);
- ap1 = (PyArrayObject *)PyArray_FromAny((PyObject *)op1, dtype,
- 1, 1, NPY_DEFAULT, NULL);
+ ap1 = (PyArrayObject *)PyArray_CheckFromAny((PyObject *)op1, dtype,
+ 1, 1, NPY_DEFAULT | NPY_NOTSWAPPED, NULL);
if (ap1 == NULL) {
Py_DECREF(dtype);
return NULL;
}
/* need ap2 as contiguous array and of right type */
- ap2 = (PyArrayObject *)PyArray_FromAny(op2, dtype,
- 0, 0, NPY_DEFAULT, NULL);
+ ap2 = (PyArrayObject *)PyArray_CheckFromAny(op2, dtype,
+ 0, 0, NPY_DEFAULT | NPY_NOTSWAPPED, NULL);
if (ap2 == NULL) {
goto fail;
}
@@ -1605,11 +1606,13 @@ PyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2)
* my_diagonal.append (diagonal (a [i], offset))
* return array (my_diagonal)
*/
- PyObject *mydiagonal = NULL, *new = NULL, *ret = NULL, *sel = NULL;
- intp i, n1;
+ PyObject *mydiagonal = NULL, *ret = NULL, *sel = NULL;
+ intp n1;
int res;
PyArray_Descr *typecode;
+ new = NULL;
+
typecode = self->descr;
mydiagonal = PyList_New(0);
if (mydiagonal == NULL) {
@@ -1682,75 +1685,221 @@ PyArray_Compress(PyArrayObject *self, PyObject *condition, int axis,
}
/*NUMPY_API
+ * Counts the number of non-zero elements in the array
+ *
+ * Returns -1 on error.
+ */
+NPY_NO_EXPORT npy_intp
+PyArray_CountNonzero(PyArrayObject *self)
+{
+ PyArray_NonzeroFunc *nonzero = self->descr->f->nonzero;
+ char *data;
+ npy_intp stride, count;
+ npy_intp nonzero_count = 0;
+
+ NpyIter *iter;
+ NpyIter_IterNextFunc *iternext;
+ char **dataptr;
+ npy_intp *strideptr, *innersizeptr;
+
+ /* If it's a trivial one-dimensional loop, don't use an iterator */
+ if (PyArray_TRIVIALLY_ITERABLE(self)) {
+ PyArray_PREPARE_TRIVIAL_ITERATION(self, count, data, stride);
+
+ while (count--) {
+ if (nonzero(data, self)) {
+ ++nonzero_count;
+ }
+ data += stride;
+ }
+
+ return nonzero_count;
+ }
+
+ /*
+ * If the array has size zero, return zero (the iterator rejects
+ * size zero arrays)
+ */
+ if (PyArray_SIZE(self) == 0) {
+ return 0;
+ }
+
+ /* Otherwise create and use an iterator to count the nonzeros */
+ iter = NpyIter_New(self, NPY_ITER_READONLY|
+ NPY_ITER_NO_INNER_ITERATION|
+ NPY_ITER_REFS_OK,
+ NPY_KEEPORDER, NPY_NO_CASTING,
+ NULL, 0, NULL, 0);
+ if (iter == NULL) {
+ return -1;
+ }
+
+ /* Get the pointers for inner loop iteration */
+ iternext = NpyIter_GetIterNext(iter, NULL);
+ if (iternext == NULL) {
+ NpyIter_Deallocate(iter);
+ return -1;
+ }
+ dataptr = NpyIter_GetDataPtrArray(iter);
+ strideptr = NpyIter_GetInnerStrideArray(iter);
+ innersizeptr = NpyIter_GetInnerLoopSizePtr(iter);
+
+ /* Iterate over all the elements to count the nonzeros */
+ do {
+ data = *dataptr;
+ stride = *strideptr;
+ count = *innersizeptr;
+
+ while (count--) {
+ if (nonzero(data, self)) {
+ ++nonzero_count;
+ }
+ data += stride;
+ }
+
+ } while(iternext(iter));
+
+ NpyIter_Deallocate(iter);
+
+ return nonzero_count;
+}
+
+/*NUMPY_API
* Nonzero
+ *
+ * TODO: In NumPy 2.0, should make the iteration order a parameter.
*/
NPY_NO_EXPORT PyObject *
PyArray_Nonzero(PyArrayObject *self)
{
- int n = self->nd, j;
- intp count = 0, i, size;
- PyArrayIterObject *it = NULL;
- PyObject *ret = NULL, *item;
- intp *dptr[MAX_DIMS];
-
- it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);
- if (it == NULL) {
+ int i, ndim = PyArray_NDIM(self);
+ PyArrayObject *ret = NULL;
+ PyObject *ret_tuple;
+ npy_intp ret_dims[2];
+ PyArray_NonzeroFunc *nonzero = self->descr->f->nonzero;
+ char *data;
+ npy_intp stride, count;
+ npy_intp nonzero_count = PyArray_CountNonzero(self);
+ npy_intp *coords;
+
+ NpyIter *iter;
+ NpyIter_IterNextFunc *iternext;
+ NpyIter_GetCoordsFunc *getcoords;
+ char **dataptr;
+ npy_intp *innersizeptr;
+
+ /* Allocate the result as a 2D array */
+ ret_dims[0] = nonzero_count;
+ ret_dims[1] = (ndim == 0) ? 1 : ndim;
+ ret = (PyArrayObject *)PyArray_New(&PyArray_Type, 2, ret_dims,
+ NPY_INTP, NULL, NULL, 0, 0,
+ NULL);
+ if (ret == NULL) {
return NULL;
}
- /* One pass through 'self', counting the non-zero elements */
- size = it->size;
- for (i = 0; i < size; i++) {
- if (self->descr->f->nonzero(it->dataptr, self)) {
- count++;
+
+ /* If it's a one-dimensional result, don't use an iterator */
+ if (ndim <= 1) {
+ npy_intp j;
+
+ coords = (npy_intp *)PyArray_DATA(ret);
+ data = PyArray_BYTES(self);
+ stride = (ndim == 0) ? 0 : PyArray_STRIDE(self, 0);
+ count = (ndim == 0) ? 1 : PyArray_DIM(self, 0);
+
+ for (j = 0; j < count; ++j) {
+ if (nonzero(data, self)) {
+ *coords++ = j;
+ }
+ data += stride;
}
- PyArray_ITER_NEXT(it);
+
+ goto finish;
}
- PyArray_ITER_RESET(it);
- /* Allocate the tuple of coordinates */
- ret = PyTuple_New(n);
- if (ret == NULL) {
- goto fail;
+ /* Build an iterator with coordinates, in C order */
+ iter = NpyIter_New(self, NPY_ITER_READONLY|
+ NPY_ITER_COORDS|
+ NPY_ITER_ZEROSIZE_OK|
+ NPY_ITER_REFS_OK,
+ NPY_CORDER, NPY_NO_CASTING,
+ NULL, 0, NULL, 0);
+
+ if (iter == NULL) {
+ Py_DECREF(ret);
+ return NULL;
}
- for (j = 0; j < n; j++) {
- item = PyArray_New(Py_TYPE(self), 1, &count,
- PyArray_INTP, NULL, NULL, 0, 0,
- (PyObject *)self);
- if (item == NULL) {
- goto fail;
+
+ if (NpyIter_GetIterSize(iter) != 0) {
+ /* Get the pointers for inner loop iteration */
+ iternext = NpyIter_GetIterNext(iter, NULL);
+ if (iternext == NULL) {
+ NpyIter_Deallocate(iter);
+ Py_DECREF(ret);
+ return NULL;
}
- PyTuple_SET_ITEM(ret, j, item);
- dptr[j] = (intp *)PyArray_DATA(item);
- }
- /* A second pass through 'self', recording the indices */
- if (n == 1) {
- for (i = 0; i < size; i++) {
- if (self->descr->f->nonzero(it->dataptr, self)) {
- *(dptr[0])++ = i;
- }
- PyArray_ITER_NEXT(it);
+ getcoords = NpyIter_GetGetCoords(iter, NULL);
+ if (getcoords == NULL) {
+ NpyIter_Deallocate(iter);
+ Py_DECREF(ret);
+ return NULL;
}
+ dataptr = NpyIter_GetDataPtrArray(iter);
+ innersizeptr = NpyIter_GetInnerLoopSizePtr(iter);
+
+ coords = (npy_intp *)PyArray_DATA(ret);
+
+ /* Get the coordinates for each non-zero element */
+ do {
+ if (nonzero(*dataptr, self)) {
+ getcoords(iter, coords);
+ coords += ndim;
+ }
+ } while(iternext(iter));
+ }
+
+ NpyIter_Deallocate(iter);
+
+finish:
+ /* Treat zero-dimensional as shape (1,) */
+ if (ndim == 0) {
+ ndim = 1;
+ }
+
+ ret_tuple = PyTuple_New(ndim);
+ if (ret_tuple == NULL) {
+ Py_DECREF(ret);
+ return NULL;
+ }
+
+ /* Create views into ret, one for each dimension */
+ if (ndim == 1) {
+ /* Directly switch to one dimensions (dimension 1 is 1 anyway) */
+ ret->nd = 1;
+ PyTuple_SET_ITEM(ret_tuple, 0, (PyObject *)ret);
}
else {
- /* reset contiguous so that coordinates gets updated */
- it->contiguous = 0;
- for (i = 0; i < size; i++) {
- if (self->descr->f->nonzero(it->dataptr, self)) {
- for (j = 0; j < n; j++) {
- *(dptr[j])++ = it->coordinates[j];
- }
+ for (i = 0; i < ndim; ++i) {
+ PyArrayObject *view;
+ stride = ndim*NPY_SIZEOF_INTP;
+
+ view = (PyArrayObject *)PyArray_New(Py_TYPE(self), 1,
+ &nonzero_count,
+ NPY_INTP, &stride,
+ PyArray_BYTES(ret) + i*NPY_SIZEOF_INTP,
+ 0, 0, (PyObject *)self);
+ if (view == NULL) {
+ Py_DECREF(ret);
+ Py_DECREF(ret_tuple);
+ return NULL;
}
- PyArray_ITER_NEXT(it);
+ Py_INCREF(ret);
+ view->base = (PyObject *)ret;
+ PyTuple_SET_ITEM(ret_tuple, i, (PyObject *)view);
}
- }
- Py_DECREF(it);
- return ret;
-
- fail:
- Py_XDECREF(ret);
- Py_XDECREF(it);
- return NULL;
+ Py_DECREF(ret);
+ }
+ return ret_tuple;
}
-
diff --git a/numpy/core/src/multiarray/iterators.c b/numpy/core/src/multiarray/iterators.c
index f841006ec..cc2a0b6cd 100644
--- a/numpy/core/src/multiarray/iterators.c
+++ b/numpy/core/src/multiarray/iterators.c
@@ -20,10 +20,10 @@
#define RubberIndex -2
#define SingleIndex -3
-NPY_NO_EXPORT intp
-parse_subindex(PyObject *op, intp *step_size, intp *n_steps, intp max)
+NPY_NO_EXPORT npy_intp
+parse_subindex(PyObject *op, npy_intp *step_size, npy_intp *n_steps, npy_intp max)
{
- intp index;
+ npy_intp index;
if (op == Py_None) {
*n_steps = PseudoIndex;
@@ -34,7 +34,7 @@ parse_subindex(PyObject *op, intp *step_size, intp *n_steps, intp max)
index = 0;
}
else if (PySlice_Check(op)) {
- intp stop;
+ npy_intp stop;
if (slice_GetIndices((PySliceObject *)op, max,
&index, &stop, step_size, n_steps) < 0) {
if (!PyErr_Occurred()) {
@@ -77,11 +77,11 @@ parse_subindex(PyObject *op, intp *step_size, intp *n_steps, intp max)
NPY_NO_EXPORT int
parse_index(PyArrayObject *self, PyObject *op,
- intp *dimensions, intp *strides, intp *offset_ptr)
+ npy_intp *dimensions, npy_intp *strides, npy_intp *offset_ptr)
{
int i, j, n;
int nd_old, nd_new, n_add, n_pseudo;
- intp n_steps, start, offset, step_size;
+ npy_intp n_steps, start, offset, step_size;
PyObject *op1 = NULL;
int is_slice;
@@ -180,7 +180,7 @@ parse_index(PyArrayObject *self, PyObject *op,
}
static int
-slice_coerce_index(PyObject *o, intp *v)
+slice_coerce_index(PyObject *o, npy_intp *v)
{
*v = PyArray_PyIntAsIntp(o);
if (error_converting(*v)) {
@@ -193,11 +193,11 @@ slice_coerce_index(PyObject *o, intp *v)
/* This is basically PySlice_GetIndicesEx, but with our coercion
* of indices to integers (plus, that function is new in Python 2.3) */
NPY_NO_EXPORT int
-slice_GetIndices(PySliceObject *r, intp length,
- intp *start, intp *stop, intp *step,
- intp *slicelength)
+slice_GetIndices(PySliceObject *r, npy_intp length,
+ npy_intp *start, npy_intp *stop, npy_intp *step,
+ npy_intp *slicelength)
{
- intp defstop;
+ npy_intp defstop;
if (r->step == Py_None) {
*step = 1;
@@ -363,7 +363,7 @@ PyArray_IterNew(PyObject *obj)
* Get Iterator broadcast to a particular shape
*/
NPY_NO_EXPORT PyObject *
-PyArray_BroadcastToShape(PyObject *obj, intp *dims, int nd)
+PyArray_BroadcastToShape(PyObject *obj, npy_intp *dims, int nd)
{
PyArrayIterObject *it;
int i, diff, j, compat, k;
@@ -451,7 +451,7 @@ PyArray_IterAllButAxis(PyObject *obj, int *inaxis)
}
if (*inaxis < 0) {
int i, minaxis = 0;
- intp minstride = 0;
+ npy_intp minstride = 0;
i = 0;
while (minstride == 0 && i < PyArray_NDIM(obj)) {
minstride = PyArray_STRIDE(obj,i);
@@ -496,8 +496,8 @@ PyArray_RemoveSmallest(PyArrayMultiIterObject *multi)
PyArrayIterObject *it;
int i, j;
int axis;
- intp smallest;
- intp sumstrides[NPY_MAXDIMS];
+ npy_intp smallest;
+ npy_intp sumstrides[NPY_MAXDIMS];
if (multi->nd == 0) {
return -1;
@@ -562,9 +562,9 @@ iter_length(PyArrayIterObject *self)
static PyObject *
iter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)
{
- intp index, strides;
+ npy_intp index, strides;
int itemsize;
- intp count = 0;
+ npy_intp count = 0;
char *dptr, *optr;
PyObject *r;
int swap;
@@ -623,18 +623,18 @@ iter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)
static PyObject *
iter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)
{
- intp num;
+ npy_intp num;
PyObject *r;
PyArrayIterObject *ind_it;
int itemsize;
int swap;
char *optr;
- intp index;
+ npy_intp index;
PyArray_CopySwapFunc *copyswap;
itemsize = self->ao->descr->elsize;
if (ind->nd == 0) {
- num = *((intp *)ind->data);
+ num = *((npy_intp *)ind->data);
if (num < 0) {
num += self->size;
}
@@ -671,7 +671,7 @@ iter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)
copyswap = PyArray_DESCR(r)->f->copyswap;
swap = (PyArray_ISNOTSWAPPED(r) != PyArray_ISNOTSWAPPED(self->ao));
while (index--) {
- num = *((intp *)(ind_it->dataptr));
+ num = *((npy_intp *)(ind_it->dataptr));
if (num < 0) {
num += self->size;
}
@@ -700,8 +700,8 @@ NPY_NO_EXPORT PyObject *
iter_subscript(PyArrayIterObject *self, PyObject *ind)
{
PyArray_Descr *indtype = NULL;
- intp start, step_size;
- intp n_steps;
+ npy_intp start, step_size;
+ npy_intp n_steps;
PyObject *r;
char *dptr;
int size;
@@ -739,7 +739,7 @@ iter_subscript(PyArrayIterObject *self, PyObject *ind)
return PyArray_ToScalar(self->dataptr, self->ao);
}
else { /* empty array */
- intp ii = 0;
+ npy_intp ii = 0;
Py_INCREF(self->ao->descr);
r = PyArray_NewFromDescr(Py_TYPE(self->ao),
self->ao->descr,
@@ -848,7 +848,7 @@ static int
iter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,
PyArrayIterObject *val, int swap)
{
- intp index, strides;
+ npy_intp index, strides;
char *dptr;
PyArray_CopySwapFunc *copyswap;
@@ -890,15 +890,15 @@ iter_ass_sub_int(PyArrayIterObject *self, PyArrayObject *ind,
PyArrayIterObject *val, int swap)
{
PyArray_Descr *typecode;
- intp num;
+ npy_intp num;
PyArrayIterObject *ind_it;
- intp index;
+ npy_intp index;
PyArray_CopySwapFunc *copyswap;
typecode = self->ao->descr;
copyswap = self->ao->descr->f->copyswap;
if (ind->nd == 0) {
- num = *((intp *)ind->data);
+ num = *((npy_intp *)ind->data);
PyArray_ITER_GOTO1D(self, num);
copyswap(self->dataptr, val->dataptr, swap, self->ao);
return 0;
@@ -909,7 +909,7 @@ iter_ass_sub_int(PyArrayIterObject *self, PyArrayObject *ind,
}
index = ind_it->size;
while (index--) {
- num = *((intp *)(ind_it->dataptr));
+ num = *((npy_intp *)(ind_it->dataptr));
if (num < 0) {
num += self->size;
}
@@ -941,8 +941,8 @@ iter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val)
PyArray_Descr *type;
PyArray_Descr *indtype = NULL;
int swap, retval = -1;
- intp start, step_size;
- intp n_steps;
+ npy_intp start, step_size;
+ npy_intp n_steps;
PyObject *obj = NULL;
PyArray_CopySwapFunc *copyswap;
@@ -1122,7 +1122,7 @@ iter_array(PyArrayIterObject *it, PyObject *NPY_UNUSED(op))
{
PyObject *r;
- intp size;
+ npy_intp size;
/* Any argument ignored */
@@ -1155,8 +1155,7 @@ iter_array(PyArrayIterObject *it, PyObject *NPY_UNUSED(op))
if (r == NULL) {
return NULL;
}
- if (_flat_copyinto(r, (PyObject *)it->ao,
- PyArray_CORDER) < 0) {
+ if (PyArray_CopyAnyInto((PyArrayObject *)r, it->ao) < 0) {
Py_DECREF(r);
return NULL;
}
@@ -1226,7 +1225,7 @@ iter_coords_get(PyArrayIterObject *self)
* coordinates not kept track of ---
* need to generate from index
*/
- intp val;
+ npy_intp val;
int i;
val = self->index;
for (i = 0; i < nd; i++) {
@@ -1321,7 +1320,7 @@ NPY_NO_EXPORT int
PyArray_Broadcast(PyArrayMultiIterObject *mit)
{
int i, nd, k, j;
- intp tmp;
+ npy_intp tmp;
PyArrayIterObject *it;
/* Discover the broadcast number of dimensions */
@@ -1858,7 +1857,7 @@ get_ptr_constant(PyArrayIterObject* _iter, npy_intp *coordinates)
* value 2 3 3 2 1 1 2 3 3 2 1 1
*
* _npy_pos_index_mirror(4, 3) will return 1, because x[4] = x[1]*/
-static inline npy_intp
+NPY_INLINE static npy_intp
__npy_pos_remainder(npy_intp i, npy_intp n)
{
npy_intp k, l, j;
@@ -1904,7 +1903,7 @@ get_ptr_mirror(PyArrayIterObject* _iter, npy_intp *coordinates)
#undef _INF_SET_PTR_MIRROR
/* compute l such as i = k * n + l, 0 <= l < |k| */
-static inline npy_intp
+NPY_INLINE static npy_intp
__npy_euclidean_division(npy_intp i, npy_intp n)
{
npy_intp l;
@@ -1944,7 +1943,7 @@ get_ptr_circular(PyArrayIterObject* _iter, npy_intp *coordinates)
* A Neighborhood Iterator object.
*/
NPY_NO_EXPORT PyObject*
-PyArray_NeighborhoodIterNew(PyArrayIterObject *x, intp *bounds,
+PyArray_NeighborhoodIterNew(PyArrayIterObject *x, npy_intp *bounds,
int mode, PyArrayObject* fill)
{
int i;
diff --git a/numpy/core/src/multiarray/lowlevel_strided_loops.c.src b/numpy/core/src/multiarray/lowlevel_strided_loops.c.src
new file mode 100644
index 000000000..fc8d71f46
--- /dev/null
+++ b/numpy/core/src/multiarray/lowlevel_strided_loops.c.src
@@ -0,0 +1,1184 @@
+/*
+ * This file contains low-level loops for copying and byte-swapping
+ * strided data.
+ *
+ * Copyright (c) 2010 by Mark Wiebe (mwwiebe@gmail.com)
+ * The Univerity of British Columbia
+ *
+ * See LICENSE.txt for the license.
+ */
+
+#define PY_SSIZE_T_CLEAN
+#include "Python.h"
+#include "structmember.h"
+
+#define _MULTIARRAYMODULE
+#include <numpy/ndarrayobject.h>
+#include <numpy/ufuncobject.h>
+#include <numpy/npy_cpu.h>
+#include <numpy/halffloat.h>
+
+#include "lowlevel_strided_loops.h"
+
+/*
+ * x86 platform may work with unaligned access, except when the
+ * compiler uses aligned SSE instructions, which gcc does in some
+ * cases. This is disabled for the time being.
+ */
+#if (defined(NPY_CPU_X86) || defined(NPY_CPU_AMD64))
+# define NPY_USE_UNALIGNED_ACCESS 0
+#else
+# define NPY_USE_UNALIGNED_ACCESS 0
+#endif
+
+#define _NPY_NOP1(x) (x)
+#define _NPY_NOP2(x) (x)
+#define _NPY_NOP4(x) (x)
+#define _NPY_NOP8(x) (x)
+
+#define _NPY_SWAP2(x) (((((npy_uint16)x)&0xffu) << 8) | \
+ (((npy_uint16)x) >> 8))
+
+#define _NPY_SWAP4(x) (((((npy_uint32)x)&0xffu) << 24) | \
+ ((((npy_uint32)x)&0xff00u) << 8) | \
+ ((((npy_uint32)x)&0xff0000u) >> 8) | \
+ (((npy_uint32)x) >> 24))
+
+#define _NPY_SWAP_PAIR4(x) (((((npy_uint32)x)&0xffu) << 8) | \
+ ((((npy_uint32)x)&0xff00u) >> 8) | \
+ ((((npy_uint32)x)&0xff0000u) << 8) | \
+ ((((npy_uint32)x)&0xff000000u) >> 8))
+
+#define _NPY_SWAP8(x) (((((npy_uint64)x)&0xffULL) << 56) | \
+ ((((npy_uint64)x)&0xff00ULL) << 40) | \
+ ((((npy_uint64)x)&0xff0000ULL) << 24) | \
+ ((((npy_uint64)x)&0xff000000ULL) << 8) | \
+ ((((npy_uint64)x)&0xff00000000ULL) >> 8) | \
+ ((((npy_uint64)x)&0xff0000000000ULL) >> 24) | \
+ ((((npy_uint64)x)&0xff000000000000ULL) >> 40) | \
+ (((npy_uint64)x) >> 56))
+
+#define _NPY_SWAP_PAIR8(x) (((((npy_uint64)x)&0xffULL) << 24) | \
+ ((((npy_uint64)x)&0xff00ULL) << 8) | \
+ ((((npy_uint64)x)&0xff0000ULL) >> 8) | \
+ ((((npy_uint64)x)&0xff000000ULL) >> 24) | \
+ ((((npy_uint64)x)&0xff00000000ULL) << 24) | \
+ ((((npy_uint64)x)&0xff0000000000ULL) << 8) | \
+ ((((npy_uint64)x)&0xff000000000000ULL) >> 8) | \
+ ((((npy_uint64)x)&0xff00000000000000ULL) >> 24))
+
+#define _NPY_SWAP_INPLACE2(x) { \
+ char a = (x)[0]; (x)[0] = (x)[1]; (x)[1] = a; \
+ }
+
+#define _NPY_SWAP_INPLACE4(x) { \
+ char a = (x)[0]; (x)[0] = (x)[3]; (x)[3] = a; \
+ a = (x)[1]; (x)[1] = (x)[2]; (x)[2] = a; \
+ }
+
+#define _NPY_SWAP_INPLACE8(x) { \
+ char a = (x)[0]; (x)[0] = (x)[7]; (x)[7] = a; \
+ a = (x)[1]; (x)[1] = (x)[6]; (x)[6] = a; \
+ a = (x)[2]; (x)[2] = (x)[5]; (x)[5] = a; \
+ a = (x)[3]; (x)[3] = (x)[4]; (x)[4] = a; \
+ }
+
+#define _NPY_SWAP_INPLACE16(x) { \
+ char a = (x)[0]; (x)[0] = (x)[15]; (x)[15] = a; \
+ a = (x)[1]; (x)[1] = (x)[14]; (x)[14] = a; \
+ a = (x)[2]; (x)[2] = (x)[13]; (x)[13] = a; \
+ a = (x)[3]; (x)[3] = (x)[12]; (x)[12] = a; \
+ a = (x)[4]; (x)[4] = (x)[11]; (x)[11] = a; \
+ a = (x)[5]; (x)[5] = (x)[10]; (x)[10] = a; \
+ a = (x)[6]; (x)[6] = (x)[9]; (x)[9] = a; \
+ a = (x)[7]; (x)[7] = (x)[8]; (x)[8] = a; \
+ }
+
+/************* STRIDED COPYING/SWAPPING SPECIALIZED FUNCTIONS *************/
+
+/**begin repeat
+ * #elsize = 1, 2, 4, 8, 16#
+ * #elsize_half = 0, 1, 2, 4, 8#
+ * #type = npy_uint8, npy_uint16, npy_uint32, npy_uint64, npy_uint128#
+ */
+/**begin repeat1
+ * #oper = strided_to_strided, strided_to_contig,
+ * contig_to_strided, contig_to_contig#
+ * #src_contig = 0, 0, 1 ,1#
+ * #dst_contig = 0, 1, 0 ,1#
+ */
+/**begin repeat2
+ * #swap = _NPY_NOP, _NPY_NOP, _NPY_SWAP_INPLACE, _NPY_SWAP,
+ * _NPY_SWAP_INPLACE, _NPY_SWAP_PAIR#
+ * #prefix = , _aligned, _swap, _aligned_swap, _swap_pair, _aligned_swap_pair#
+ * #is_aligned = 0, 1, 0, 1, 0, 1#
+ * #minelsize = 1, 1, 2, 2, 4, 4#
+ * #is_swap = 0, 0, 1, 1, 2, 2#
+ */
+
+#if (@elsize@ >= @minelsize@) && \
+ (@elsize@ > 1 || @is_aligned@) && \
+ (!NPY_USE_UNALIGNED_ACCESS || @is_aligned@)
+
+
+#if @is_swap@ || @src_contig@ == 0 || @dst_contig@ == 0
+static void
+@prefix@_@oper@_size@elsize@(char *dst, npy_intp dst_stride,
+ char *src, npy_intp src_stride,
+ npy_intp N, npy_intp NPY_UNUSED(src_itemsize),
+ void *NPY_UNUSED(data))
+{
+ /*printf("fn @prefix@_@oper@_size@elsize@\n");*/
+ while (N > 0) {
+#if @is_aligned@
+
+ /* aligned copy and swap */
+# if @elsize@ != 16
+ (*((@type@ *)dst)) = @swap@@elsize@(*((@type@ *)src));
+# else
+# if @is_swap@ == 0
+ (*((npy_uint64 *)dst)) = (*((npy_uint64 *)src));
+ (*((npy_uint64 *)dst + 1)) = (*((npy_uint64 *)src + 1));
+# elif @is_swap@ == 1
+ (*((npy_uint64 *)dst)) = _NPY_SWAP8(*((npy_uint64 *)src + 1));
+ (*((npy_uint64 *)dst + 1)) = _NPY_SWAP8(*((npy_uint64 *)src));
+# elif @is_swap@ == 2
+ (*((npy_uint64 *)dst)) = _NPY_SWAP8(*((npy_uint64 *)src));
+ (*((npy_uint64 *)dst + 1)) = _NPY_SWAP8(*((npy_uint64 *)src + 1));
+# endif
+# endif
+
+#else
+
+ /* unaligned copy and swap */
+ memcpy(dst, src, @elsize@);
+# if @is_swap@ == 1
+ @swap@@elsize@(dst);
+# elif @is_swap@ == 2
+ @swap@@elsize_half@(dst);
+ @swap@@elsize_half@(dst + @elsize_half@);
+# endif
+
+#endif
+
+#if @dst_contig@
+ dst += @elsize@;
+#else
+ dst += dst_stride;
+#endif
+
+#if @src_contig@
+ src += @elsize@;
+#else
+ src += src_stride;
+#endif
+
+ --N;
+ }
+}
+#endif
+
+
+/* specialized copy and swap for source stride 0 */
+#if (@src_contig@ == 0) && @is_aligned@
+static void
+@prefix@_@oper@_size@elsize@_srcstride0(char *dst,
+ npy_intp dst_stride,
+ char *src, npy_intp NPY_UNUSED(src_stride),
+ npy_intp N, npy_intp NPY_UNUSED(src_itemsize),
+ void *NPY_UNUSED(data))
+{
+#if @elsize@ != 16
+ @type@ temp = @swap@@elsize@(*((@type@ *)src));
+#else
+ npy_uint64 temp0, temp1;
+# if @is_swap@ == 0
+ temp0 = (*((npy_uint64 *)src));
+ temp1 = (*((npy_uint64 *)src + 1));
+# elif @is_swap@ == 1
+ temp0 = _NPY_SWAP8(*((npy_uint64 *)src + 1));
+ temp1 = _NPY_SWAP8(*((npy_uint64 *)src));
+# elif @is_swap@ == 2
+ temp0 = _NPY_SWAP8(*((npy_uint64 *)src));
+ temp1 = _NPY_SWAP8(*((npy_uint64 *)src + 1));
+# endif
+#endif
+
+ while (N > 0) {
+#if @elsize@ != 16
+ *((@type@ *)dst) = temp;
+#else
+ *((npy_uint64 *)dst) = temp0;
+ *((npy_uint64 *)dst + 1) = temp1;
+#endif
+#if @dst_contig@
+ dst += @elsize@;
+#else
+ dst += dst_stride;
+#endif
+ --N;
+ }
+}
+#endif
+
+#endif/* @elsize@ >= @minelsize@ */
+
+/**end repeat2**/
+/**end repeat1**/
+/**end repeat**/
+
+static void
+_strided_to_strided(char *dst, npy_intp dst_stride,
+ char *src, npy_intp src_stride,
+ npy_intp N, npy_intp src_itemsize,
+ void *NPY_UNUSED(data))
+{
+ while (N > 0) {
+ memcpy(dst, src, src_itemsize);
+ dst += dst_stride;
+ src += src_stride;
+ --N;
+ }
+}
+
+static void
+_swap_strided_to_strided(char *dst, npy_intp dst_stride,
+ char *src, npy_intp src_stride,
+ npy_intp N, npy_intp src_itemsize,
+ void *NPY_UNUSED(data))
+{
+ char *a, *b, c;
+
+ while (N > 0) {
+ memcpy(dst, src, src_itemsize);
+ /* general in-place swap */
+ a = dst;
+ b = dst + src_itemsize - 1;
+ while (a < b) {
+ c = *a;
+ *a = *b;
+ *b = c;
+ ++a; --b;
+ }
+ dst += dst_stride;
+ src += src_stride;
+ --N;
+ }
+}
+
+static void
+_swap_pair_strided_to_strided(char *dst, npy_intp dst_stride,
+ char *src, npy_intp src_stride,
+ npy_intp N, npy_intp src_itemsize,
+ void *NPY_UNUSED(data))
+{
+ char *a, *b, c;
+ npy_intp itemsize_half = src_itemsize / 2;
+
+ while (N > 0) {
+ memcpy(dst, src, src_itemsize);
+ /* general in-place swap */
+ a = dst;
+ b = dst + itemsize_half - 1;
+ while (a < b) {
+ c = *a;
+ *a = *b;
+ *b = c;
+ ++a; --b;
+ }
+ /* general in-place swap */
+ a = dst + itemsize_half;
+ b = dst + 2*itemsize_half - 1;
+ while (a < b) {
+ c = *a;
+ *a = *b;
+ *b = c;
+ ++a; --b;
+ }
+ dst += dst_stride;
+ src += src_stride;
+ --N;
+ }
+}
+
+static void
+_contig_to_contig(char *dst, npy_intp NPY_UNUSED(dst_stride),
+ char *src, npy_intp NPY_UNUSED(src_stride),
+ npy_intp N, npy_intp src_itemsize,
+ void *NPY_UNUSED(data))
+{
+ memcpy(dst, src, src_itemsize*N);
+}
+
+
+NPY_NO_EXPORT PyArray_StridedTransferFn *
+PyArray_GetStridedCopyFn(npy_intp aligned, npy_intp src_stride,
+ npy_intp dst_stride, npy_intp itemsize)
+{
+/*
+ * Skip the "unaligned" versions on CPUs which support unaligned
+ * memory accesses.
+ */
+#if !NPY_USE_UNALIGNED_ACCESS
+ if (aligned) {
+#endif/*!NPY_USE_UNALIGNED_ACCESS*/
+
+ /* contiguous dst */
+ if (itemsize != 0 && dst_stride == itemsize) {
+ /* constant src */
+ if (src_stride == 0) {
+ switch (itemsize) {
+/**begin repeat
+ * #elsize = 1, 2, 4, 8, 16#
+ */
+ case @elsize@:
+ return
+ &_aligned_strided_to_contig_size@elsize@_srcstride0;
+/**end repeat**/
+ }
+ }
+ /* contiguous src */
+ else if (src_stride == itemsize) {
+ return &_contig_to_contig;
+ }
+ /* general src */
+ else {
+ switch (itemsize) {
+/**begin repeat
+ * #elsize = 1, 2, 4, 8, 16#
+ */
+ case @elsize@:
+ return &_aligned_strided_to_contig_size@elsize@;
+/**end repeat**/
+ }
+ }
+
+ return &_strided_to_strided;
+ }
+ /* general dst */
+ else {
+ /* constant src */
+ if (src_stride == 0) {
+ switch (itemsize) {
+/**begin repeat
+ * #elsize = 1, 2, 4, 8, 16#
+ */
+ case @elsize@:
+ return
+ &_aligned_strided_to_strided_size@elsize@_srcstride0;
+/**end repeat**/
+ }
+ }
+ /* contiguous src */
+ else if (src_stride == itemsize) {
+ switch (itemsize) {
+/**begin repeat
+ * #elsize = 1, 2, 4, 8, 16#
+ */
+ case @elsize@:
+ return &_aligned_contig_to_strided_size@elsize@;
+/**end repeat**/
+ }
+
+ return &_strided_to_strided;
+ }
+ else {
+ switch (itemsize) {
+/**begin repeat
+ * #elsize = 1, 2, 4, 8, 16#
+ */
+ case @elsize@:
+ return &_aligned_strided_to_strided_size@elsize@;
+/**end repeat**/
+ }
+ }
+ }
+
+#if !NPY_USE_UNALIGNED_ACCESS
+ }
+ else {
+ /* contiguous dst */
+ if (itemsize != 0 && dst_stride == itemsize) {
+ /* contiguous src */
+ if (itemsize != 0 && src_stride == itemsize) {
+ return &_contig_to_contig;
+ }
+ /* general src */
+ else {
+ switch (itemsize) {
+ case 1:
+ return &_aligned_strided_to_contig_size1;
+/**begin repeat
+ * #elsize = 2, 4, 8, 16#
+ */
+ case @elsize@:
+ return &_strided_to_contig_size@elsize@;
+/**end repeat**/
+ }
+ }
+
+ return &_strided_to_strided;
+ }
+ /* general dst */
+ else {
+ /* contiguous src */
+ if (itemsize != 0 && src_stride == itemsize) {
+ switch (itemsize) {
+ case 1:
+ return &_aligned_contig_to_strided_size1;
+/**begin repeat
+ * #elsize = 2, 4, 8, 16#
+ */
+ case @elsize@:
+ return &_contig_to_strided_size@elsize@;
+/**end repeat**/
+ }
+
+ return &_strided_to_strided;
+ }
+ /* general src */
+ else {
+ switch (itemsize) {
+ case 1:
+ return &_aligned_strided_to_strided_size1;
+/**begin repeat
+ * #elsize = 2, 4, 8, 16#
+ */
+ case @elsize@:
+ return &_strided_to_strided_size@elsize@;
+/**end repeat**/
+ }
+ }
+ }
+ }
+#endif/*!NPY_USE_UNALIGNED_ACCESS*/
+
+ return &_strided_to_strided;
+}
+
+/*
+ * PyArray_GetStridedCopySwapFn and PyArray_GetStridedCopySwapPairFn are
+ * nearly identical, so can do a repeat for them.
+ */
+/**begin repeat
+ * #function = PyArray_GetStridedCopySwapFn, PyArray_GetStridedCopySwapPairFn#
+ * #tag = , _pair#
+ * #not_pair = 1, 0#
+ */
+
+NPY_NO_EXPORT PyArray_StridedTransferFn *
+@function@(npy_intp aligned, npy_intp src_stride,
+ npy_intp dst_stride, npy_intp itemsize)
+{
+/*
+ * Skip the "unaligned" versions on CPUs which support unaligned
+ * memory accesses.
+ */
+#if !NPY_USE_UNALIGNED_ACCESS
+ if (aligned) {
+#endif/*!NPY_USE_UNALIGNED_ACCESS*/
+
+ /* contiguous dst */
+ if (itemsize != 0 && dst_stride == itemsize) {
+ /* constant src */
+ if (src_stride == 0) {
+ switch (itemsize) {
+/**begin repeat1
+ * #elsize = 2, 4, 8, 16#
+ */
+#if @not_pair@ || @elsize@ > 2
+ case @elsize@:
+ return
+ &_aligned_swap@tag@_strided_to_contig_size@elsize@_srcstride0;
+#endif
+/**end repeat1**/
+ }
+ }
+ /* contiguous src */
+ else if (src_stride == itemsize) {
+ switch (itemsize) {
+/**begin repeat1
+ * #elsize = 2, 4, 8, 16#
+ */
+#if @not_pair@ || @elsize@ > 2
+ case @elsize@:
+ return &_aligned_swap@tag@_contig_to_contig_size@elsize@;
+#endif
+/**end repeat1**/
+ }
+ }
+ /* general src */
+ else {
+ switch (itemsize) {
+/**begin repeat1
+ * #elsize = 2, 4, 8, 16#
+ */
+#if @not_pair@ || @elsize@ > 2
+ case @elsize@:
+ return &_aligned_swap@tag@_strided_to_contig_size@elsize@;
+#endif
+/**end repeat1**/
+ }
+ }
+ }
+ /* general dst */
+ else {
+ /* constant src */
+ if (src_stride == 0) {
+ switch (itemsize) {
+/**begin repeat1
+ * #elsize = 2, 4, 8, 16#
+ */
+#if @not_pair@ || @elsize@ > 2
+ case @elsize@:
+ return
+ &_aligned_swap@tag@_strided_to_strided_size@elsize@_srcstride0;
+#endif
+/**end repeat1**/
+ }
+ }
+ /* contiguous src */
+ else if (src_stride == itemsize) {
+ switch (itemsize) {
+/**begin repeat1
+ * #elsize = 2, 4, 8, 16#
+ */
+#if @not_pair@ || @elsize@ > 2
+ case @elsize@:
+ return &_aligned_swap@tag@_contig_to_strided_size@elsize@;
+#endif
+/**end repeat1**/
+ }
+
+ return &_strided_to_strided;
+ }
+ else {
+ switch (itemsize) {
+/**begin repeat1
+ * #elsize = 2, 4, 8, 16#
+ */
+#if @not_pair@ || @elsize@ > 2
+ case @elsize@:
+ return &_aligned_swap@tag@_strided_to_strided_size@elsize@;
+#endif
+/**end repeat1**/
+ }
+ }
+ }
+
+#if !NPY_USE_UNALIGNED_ACCESS
+ }
+ else {
+ /* contiguous dst */
+ if (itemsize != 0 && dst_stride == itemsize) {
+ /* contiguous src */
+ if (itemsize != 0 && src_stride == itemsize) {
+ switch (itemsize) {
+/**begin repeat1
+ * #elsize = 2, 4, 8, 16#
+ */
+#if @not_pair@ || @elsize@ > 2
+ case @elsize@:
+ return &_swap@tag@_contig_to_contig_size@elsize@;
+#endif
+/**end repeat1**/
+ }
+ }
+ /* general src */
+ else {
+ switch (itemsize) {
+/**begin repeat1
+ * #elsize = 2, 4, 8, 16#
+ */
+#if @not_pair@ || @elsize@ > 2
+ case @elsize@:
+ return &_swap@tag@_strided_to_contig_size@elsize@;
+#endif
+/**end repeat1**/
+ }
+ }
+
+ return &_strided_to_strided;
+ }
+ /* general dst */
+ else {
+ /* contiguous src */
+ if (itemsize != 0 && src_stride == itemsize) {
+ switch (itemsize) {
+/**begin repeat1
+ * #elsize = 2, 4, 8, 16#
+ */
+#if @not_pair@ || @elsize@ > 2
+ case @elsize@:
+ return &_swap@tag@_contig_to_strided_size@elsize@;
+#endif
+/**end repeat1**/
+ }
+
+ return &_strided_to_strided;
+ }
+ /* general src */
+ else {
+ switch (itemsize) {
+/**begin repeat1
+ * #elsize = 2, 4, 8, 16#
+ */
+#if @not_pair@ || @elsize@ > 2
+ case @elsize@:
+ return &_swap@tag@_strided_to_strided_size@elsize@;
+#endif
+/**end repeat1**/
+ }
+ }
+ }
+ }
+#endif/*!NPY_USE_UNALIGNED_ACCESS*/
+
+ return &_swap@tag@_strided_to_strided;
+}
+
+/**end repeat**/
+
+/************* STRIDED CASTING SPECIALIZED FUNCTIONS *************/
+
+/**begin repeat
+ *
+ * #NAME1 = BOOL,
+ * UBYTE, USHORT, UINT, ULONG, ULONGLONG,
+ * BYTE, SHORT, INT, LONG, LONGLONG,
+ * HALF, FLOAT, DOUBLE, LONGDOUBLE,
+ * CFLOAT, CDOUBLE, CLONGDOUBLE#
+ * #name1 = bool,
+ * ubyte, ushort, uint, ulong, ulonglong,
+ * byte, short, int, long, longlong,
+ * half, float, double, longdouble,
+ * cfloat, cdouble, clongdouble#
+ * #rname1 = bool,
+ * ubyte, ushort, uint, ulong, ulonglong,
+ * byte, short, int, long, longlong,
+ * half, float, double, longdouble,
+ * float, double, longdouble#
+ * #is_bool1 = 1, 0*17#
+ * #is_half1 = 0*11, 1, 0*6#
+ * #is_float1 = 0*12, 1, 0, 0, 1, 0, 0#
+ * #is_double1 = 0*13, 1, 0, 0, 1, 0#
+ * #is_complex1 = 0*15, 1*3#
+ */
+
+/**begin repeat1
+ *
+ * #NAME2 = BOOL,
+ * UBYTE, USHORT, UINT, ULONG, ULONGLONG,
+ * BYTE, SHORT, INT, LONG, LONGLONG,
+ * HALF, FLOAT, DOUBLE, LONGDOUBLE,
+ * CFLOAT, CDOUBLE, CLONGDOUBLE#
+ * #name2 = bool,
+ * ubyte, ushort, uint, ulong, ulonglong,
+ * byte, short, int, long, longlong,
+ * half, float, double, longdouble,
+ * cfloat, cdouble, clongdouble#
+ * #rname2 = bool,
+ * ubyte, ushort, uint, ulong, ulonglong,
+ * byte, short, int, long, longlong,
+ * half, float, double, longdouble,
+ * float, double, longdouble#
+ * #is_bool2 = 1, 0*17#
+ * #is_half2 = 0*11, 1, 0*6#
+ * #is_float2 = 0*12, 1, 0, 0, 1, 0, 0#
+ * #is_double2 = 0*13, 1, 0, 0, 1, 0#
+ * #is_complex2 = 0*15, 1*3#
+ */
+
+/**begin repeat2
+ * #prefix = _aligned,,_aligned_contig,_contig#
+ * #aligned = 1,0,1,0#
+ * #contig = 0,0,1,1#
+ */
+
+#if !(NPY_USE_UNALIGNED_ACCESS && !@aligned@)
+
+/* For half types, don't use actual double/float types in conversion */
+#if @is_half1@ || @is_half2@
+
+# if @is_float1@
+# define _TYPE1 npy_uint32
+# elif @is_double1@
+# define _TYPE1 npy_uint64
+# else
+# define _TYPE1 npy_@rname1@
+# endif
+
+# if @is_float2@
+# define _TYPE2 npy_uint32
+# elif @is_double2@
+# define _TYPE2 npy_uint64
+# else
+# define _TYPE2 npy_@rname2@
+# endif
+
+#else
+
+#define _TYPE1 npy_@rname1@
+#define _TYPE2 npy_@rname2@
+
+#endif
+
+/* Determine an appropriate casting conversion function */
+#if @is_half1@
+
+# if @is_float2@
+# define _CONVERT_FN(x) npy_halfbits_to_floatbits(x)
+# elif @is_double2@
+# define _CONVERT_FN(x) npy_halfbits_to_doublebits(x)
+# elif @is_half2@
+# define _CONVERT_FN(x) (x)
+# elif @is_bool2@
+# define _CONVERT_FN(x) ((npy_bool)!npy_half_iszero(x))
+# else
+# define _CONVERT_FN(x) ((_TYPE2)npy_half_to_float(x))
+# endif
+
+#elif @is_half2@
+
+# if @is_float1@
+# define _CONVERT_FN(x) npy_floatbits_to_halfbits(x)
+# elif @is_double1@
+# define _CONVERT_FN(x) npy_doublebits_to_halfbits(x)
+# else
+# define _CONVERT_FN(x) npy_float_to_half((float)x)
+# endif
+
+#else
+
+# if @is_bool2@
+# define _CONVERT_FN(x) ((npy_bool)(x != 0))
+# else
+# define _CONVERT_FN(x) ((_TYPE2)x)
+# endif
+
+#endif
+
+static void
+@prefix@_cast_@name1@_to_@name2@(
+ char *dst, npy_intp dst_stride,
+ char *src, npy_intp src_stride,
+ npy_intp N, npy_intp NPY_UNUSED(src_itemsize),
+ void *NPY_UNUSED(data))
+{
+#if @is_complex1@
+ _TYPE1 src_value[2];
+#elif !@aligned@
+ _TYPE1 src_value;
+#endif
+#if @is_complex2@
+ _TYPE2 dst_value[2];
+#elif !@aligned@
+ _TYPE2 dst_value;
+#endif
+
+ /*printf("@prefix@_cast_@name1@_to_@name2@\n");*/
+
+ while (N--) {
+#if @aligned@
+# if @is_complex1@
+ src_value[0] = ((_TYPE1 *)src)[0];
+ src_value[1] = ((_TYPE1 *)src)[1];
+# elif !@aligned@
+ src_value = *((_TYPE1 *)src);
+# endif
+#else
+ memcpy(&src_value, src, sizeof(src_value));
+#endif
+
+/* Do the cast */
+#if @is_complex1@
+# if @is_complex2@
+ dst_value[0] = _CONVERT_FN(src_value[0]);
+ dst_value[1] = _CONVERT_FN(src_value[1]);
+# elif !@aligned@
+ dst_value = _CONVERT_FN(src_value[0]);
+# else
+ *(_TYPE2 *)dst = _CONVERT_FN(src_value[0]);
+# endif
+#else
+# if @is_complex2@
+# if !@aligned@
+ dst_value[0] = _CONVERT_FN(src_value);
+# else
+ dst_value[0] = _CONVERT_FN(*(_TYPE1 *)src);
+# endif
+ dst_value[1] = 0;
+# elif !@aligned@
+ dst_value = _CONVERT_FN(src_value);
+# else
+ *(_TYPE2 *)dst = _CONVERT_FN(*(_TYPE1 *)src);
+# endif
+#endif
+
+#if @aligned@
+# if @is_complex2@
+ ((_TYPE2 *)dst)[0] = dst_value[0];
+ ((_TYPE2 *)dst)[1] = dst_value[1];
+# elif !@aligned@
+ *((_TYPE2 *)dst) = dst_value;
+# endif
+#else
+ memcpy(dst, &dst_value, sizeof(dst_value));
+#endif
+
+#if @contig@
+ dst += sizeof(npy_@name2@);
+ src += sizeof(npy_@name1@);
+#else
+ dst += dst_stride;
+ src += src_stride;
+#endif
+ }
+}
+
+#undef _CONVERT_FN
+#undef _TYPE2
+#undef _TYPE1
+
+#endif
+
+/**end repeat2**/
+
+/**end repeat1**/
+
+/**end repeat**/
+
+NPY_NO_EXPORT PyArray_StridedTransferFn *
+PyArray_GetStridedNumericCastFn(npy_intp aligned, npy_intp src_stride,
+ npy_intp dst_stride,
+ int src_type_num, int dst_type_num)
+{
+ switch (src_type_num) {
+/**begin repeat
+ *
+ * #NAME1 = BOOL,
+ * UBYTE, USHORT, UINT, ULONG, ULONGLONG,
+ * BYTE, SHORT, INT, LONG, LONGLONG,
+ * HALF, FLOAT, DOUBLE, LONGDOUBLE,
+ * CFLOAT, CDOUBLE, CLONGDOUBLE#
+ * #name1 = bool,
+ * ubyte, ushort, uint, ulong, ulonglong,
+ * byte, short, int, long, longlong,
+ * half, float, double, longdouble,
+ * cfloat, cdouble, clongdouble#
+ */
+
+ case NPY_@NAME1@:
+ /*printf("test fn %d - second %d\n", NPY_@NAME1@, dst_type_num);*/
+ switch (dst_type_num) {
+/**begin repeat1
+ *
+ * #NAME2 = BOOL,
+ * UBYTE, USHORT, UINT, ULONG, ULONGLONG,
+ * BYTE, SHORT, INT, LONG, LONGLONG,
+ * HALF, FLOAT, DOUBLE, LONGDOUBLE,
+ * CFLOAT, CDOUBLE, CLONGDOUBLE#
+ * #name2 = bool,
+ * ubyte, ushort, uint, ulong, ulonglong,
+ * byte, short, int, long, longlong,
+ * half, float, double, longdouble,
+ * cfloat, cdouble, clongdouble#
+ */
+
+ case NPY_@NAME2@:
+ /*printf("ret fn %d %d\n", NPY_@NAME1@, NPY_@NAME2@);*/
+# if NPY_USE_UNALIGNED_ACCESS
+ if (src_stride == sizeof(npy_@name1@) &&
+ dst_stride == sizeof(npy_@name2@)) {
+ return &_aligned_contig_cast_@name1@_to_@name2@;
+ }
+ else {
+ return &_aligned_cast_@name1@_to_@name2@;
+ }
+# else
+ if (src_stride == sizeof(npy_@name1@) &&
+ dst_stride == sizeof(npy_@name2@)) {
+ return aligned ?
+ &_aligned_contig_cast_@name1@_to_@name2@ :
+ &_contig_cast_@name1@_to_@name2@;
+ }
+ else {
+ return aligned ? &_aligned_cast_@name1@_to_@name2@ :
+ &_cast_@name1@_to_@name2@;
+ }
+# endif
+
+/**end repeat1**/
+ }
+ /*printf("switched test fn %d - second %d\n", NPY_@NAME1@, dst_type_num);*/
+
+/**end repeat**/
+ }
+
+ return NULL;
+}
+
+
+/************** STRIDED TRANSFER FUNCTION MEMORY MANAGEMENT **************/
+
+typedef void (*_npy_stridedtransfer_dealloc)(void *);
+NPY_NO_EXPORT void
+PyArray_FreeStridedTransferData(void *transferdata)
+{
+ if (transferdata != NULL) {
+ _npy_stridedtransfer_dealloc dealloc =
+ *((_npy_stridedtransfer_dealloc *)transferdata);
+ dealloc(transferdata);
+ }
+}
+
+typedef void *(*_npy_stridedtransfer_copy)(void *);
+NPY_NO_EXPORT void *
+PyArray_CopyStridedTransferData(void *transferdata)
+{
+ if (transferdata != NULL) {
+ _npy_stridedtransfer_copy copy =
+ *((_npy_stridedtransfer_copy *)transferdata + 1);
+ return copy(transferdata);
+ }
+
+ return NULL;
+}
+
+/****************** PRIMITIVE FLAT TO/FROM NDIM FUNCTIONS ******************/
+
+NPY_NO_EXPORT npy_intp
+PyArray_TransferNDimToStrided(npy_intp ndim,
+ char *dst, npy_intp dst_stride,
+ char *src, npy_intp *src_strides, npy_intp src_strides_inc,
+ npy_intp *coords, npy_intp coords_inc,
+ npy_intp *shape, npy_intp shape_inc,
+ npy_intp count, npy_intp src_itemsize,
+ PyArray_StridedTransferFn *stransfer,
+ void *data)
+{
+ npy_intp i, M, N, coord0, shape0, src_stride0, coord1, shape1, src_stride1;
+
+ /* Finish off dimension 0 */
+ coord0 = coords[0];
+ shape0 = shape[0];
+ src_stride0 = src_strides[0];
+ N = shape0 - coord0;
+ if (N >= count) {
+ stransfer(dst, dst_stride, src, src_stride0, count, src_itemsize, data);
+ return 0;
+ }
+ stransfer(dst, dst_stride, src, src_stride0, N, src_itemsize, data);
+ count -= N;
+
+ /* If it's 1-dimensional, there's no more to copy */
+ if (ndim == 1) {
+ return count;
+ }
+
+ /* Adjust the src and dst pointers */
+ coord1 = (coords + coords_inc)[0];
+ shape1 = (shape + shape_inc)[0];
+ src_stride1 = (src_strides + src_strides_inc)[0];
+ src = src - coord0*src_stride0 + src_stride1;
+ dst += N*dst_stride;
+
+ /* Finish off dimension 1 */
+ M = (shape1 - coord1 - 1);
+ N = shape0*M;
+ for (i = 0; i < M; ++i) {
+ if (shape0 >= count) {
+ stransfer(dst, dst_stride, src, src_stride0,
+ count, src_itemsize, data);
+ return 0;
+ }
+ else {
+ stransfer(dst, dst_stride, src, src_stride0,
+ shape0, src_itemsize, data);
+ }
+ count -= shape0;
+ src += src_stride1;
+ dst += shape0*dst_stride;
+ }
+
+ /* If it's 2-dimensional, there's no more to copy */
+ if (ndim == 2) {
+ return count;
+ }
+
+ /* General-case loop for everything else */
+ else {
+ /* Iteration structure for dimensions 2 and up */
+ struct {
+ npy_intp coord, shape, src_stride;
+ } it[NPY_MAXDIMS];
+
+ /* Copy the coordinates and shape */
+ coords += 2*coords_inc;
+ shape += 2*shape_inc;
+ src_strides += 2*src_strides_inc;
+ for (i = 0; i < ndim-2; ++i) {
+ it[i].coord = coords[0];
+ it[i].shape = shape[0];
+ it[i].src_stride = src_strides[0];
+ coords += coords_inc;
+ shape += shape_inc;
+ src_strides += src_strides_inc;
+ }
+
+ for (;;) {
+ /* Adjust the src pointer from the dimension 0 and 1 loop */
+ src = src - shape1*src_stride1;
+
+ /* Increment to the next coordinate */
+ for (i = 0; i < ndim-2; ++i) {
+ src += it[i].src_stride;
+ if (++it[i].coord >= it[i].shape) {
+ it[i].coord = 0;
+ src -= it[i].src_stride*it[i].shape;
+ }
+ else {
+ break;
+ }
+ }
+ /* If the last dimension rolled over, we're done */
+ if (i == ndim-2) {
+ return count;
+ }
+
+ /* A loop for dimensions 0 and 1 */
+ for (i = 0; i < shape1; ++i) {
+ if (shape0 >= count) {
+ stransfer(dst, dst_stride, src, src_stride0,
+ count, src_itemsize, data);
+ return 0;
+ }
+ else {
+ stransfer(dst, dst_stride, src, src_stride0,
+ shape0, src_itemsize, data);
+ }
+ count -= shape0;
+ src += src_stride1;
+ dst += shape0*dst_stride;
+ }
+ }
+ }
+}
+
+NPY_NO_EXPORT npy_intp
+PyArray_TransferStridedToNDim(npy_intp ndim,
+ char *dst, npy_intp *dst_strides, npy_intp dst_strides_inc,
+ char *src, npy_intp src_stride,
+ npy_intp *coords, npy_intp coords_inc,
+ npy_intp *shape, npy_intp shape_inc,
+ npy_intp count, npy_intp src_itemsize,
+ PyArray_StridedTransferFn *stransfer,
+ void *data)
+{
+ npy_intp i, M, N, coord0, shape0, dst_stride0, coord1, shape1, dst_stride1;
+
+ /* Finish off dimension 0 */
+ coord0 = coords[0];
+ shape0 = shape[0];
+ dst_stride0 = dst_strides[0];
+ N = shape0 - coord0;
+ if (N >= count) {
+ stransfer(dst, dst_stride0, src, src_stride, count, src_itemsize, data);
+ return 0;
+ }
+ stransfer(dst, dst_stride0, src, src_stride, N, src_itemsize, data);
+ count -= N;
+
+ /* If it's 1-dimensional, there's no more to copy */
+ if (ndim == 1) {
+ return count;
+ }
+
+ /* Adjust the src and dst pointers */
+ coord1 = (coords + coords_inc)[0];
+ shape1 = (shape + shape_inc)[0];
+ dst_stride1 = (dst_strides + dst_strides_inc)[0];
+ dst = dst - coord0*dst_stride0 + dst_stride1;
+ src += N*src_stride;
+
+ /* Finish off dimension 1 */
+ M = (shape1 - coord1 - 1);
+ N = shape0*M;
+ for (i = 0; i < M; ++i) {
+ if (shape0 >= count) {
+ stransfer(dst, dst_stride0, src, src_stride,
+ count, src_itemsize, data);
+ return 0;
+ }
+ else {
+ stransfer(dst, dst_stride0, src, src_stride,
+ shape0, src_itemsize, data);
+ }
+ count -= shape0;
+ dst += dst_stride1;
+ src += shape0*src_stride;
+ }
+
+ /* If it's 2-dimensional, there's no more to copy */
+ if (ndim == 2) {
+ return count;
+ }
+
+ /* General-case loop for everything else */
+ else {
+ /* Iteration structure for dimensions 2 and up */
+ struct {
+ npy_intp coord, shape, dst_stride;
+ } it[NPY_MAXDIMS];
+
+ /* Copy the coordinates and shape */
+ coords += 2*coords_inc;
+ shape += 2*shape_inc;
+ dst_strides += 2*dst_strides_inc;
+ for (i = 0; i < ndim-2; ++i) {
+ it[i].coord = coords[0];
+ it[i].shape = shape[0];
+ it[i].dst_stride = dst_strides[0];
+ coords += coords_inc;
+ shape += shape_inc;
+ dst_strides += dst_strides_inc;
+ }
+
+ for (;;) {
+ /* Adjust the dst pointer from the dimension 0 and 1 loop */
+ dst = dst - shape1*dst_stride1;
+
+ /* Increment to the next coordinate */
+ for (i = 0; i < ndim-2; ++i) {
+ dst += it[i].dst_stride;
+ if (++it[i].coord >= it[i].shape) {
+ it[i].coord = 0;
+ dst -= it[i].dst_stride*it[i].shape;
+ }
+ else {
+ break;
+ }
+ }
+ /* If the last dimension rolled over, we're done */
+ if (i == ndim-2) {
+ return count;
+ }
+
+ /* A loop for dimensions 0 and 1 */
+ for (i = 0; i < shape1; ++i) {
+ if (shape0 >= count) {
+ stransfer(dst, dst_stride0, src, src_stride,
+ count, src_itemsize, data);
+ return 0;
+ }
+ else {
+ stransfer(dst, dst_stride0, src, src_stride,
+ shape0, src_itemsize, data);
+ }
+ count -= shape0;
+ dst += dst_stride1;
+ src += shape0*src_stride;
+ }
+ }
+ }
+}
diff --git a/numpy/core/src/multiarray/mapping.c b/numpy/core/src/multiarray/mapping.c
index 21a630418..8db85bf8f 100644
--- a/numpy/core/src/multiarray/mapping.c
+++ b/numpy/core/src/multiarray/mapping.c
@@ -819,18 +819,31 @@ array_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op)
return -1;
}
+ if (index == Py_Ellipsis) {
+ /*
+ * Doing "a[...] += 1" triggers assigning an array to itself,
+ * so this check is needed.
+ */
+ if ((PyObject *)self == op) {
+ return 0;
+ }
+ else {
+ return PyArray_CopyObject(self, op);
+ }
+ }
+
if (self->nd == 0) {
/*
* Several different exceptions to the 0-d no-indexing rule
*
- * 1) ellipses
+ * 1) ellipses (handled above generally)
* 2) empty tuple
* 3) Using newaxis (None)
* 4) Boolean mask indexing
*/
- if (index == Py_Ellipsis || index == Py_None ||
- (PyTuple_Check(index) && (0 == PyTuple_GET_SIZE(index) ||
- count_new_axes_0d(index) > 0))) {
+ if (index == Py_None || (PyTuple_Check(index) &&
+ (0 == PyTuple_GET_SIZE(index) ||
+ count_new_axes_0d(index) > 0))) {
return self->descr->f->setitem(op, self->data, self);
}
if (PyBool_Check(index) || PyArray_IsScalar(index, Bool) ||
@@ -1690,5 +1703,3 @@ NPY_NO_EXPORT PyTypeObject PyArrayMapIter_Type = {
};
/** END of Subscript Iterator **/
-
-
diff --git a/numpy/core/src/multiarray/methods.c b/numpy/core/src/multiarray/methods.c
index 6ccac9f6e..ed86e208c 100644
--- a/numpy/core/src/multiarray/methods.c
+++ b/numpy/core/src/multiarray/methods.c
@@ -57,12 +57,10 @@ array_take(PyArrayObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"indices", "axis", "out", "mode", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O&O&O&", kwlist,
- &indices, PyArray_AxisConverter,
- &dimension,
- PyArray_OutputConverter,
- &out,
- PyArray_ClipmodeConverter,
- &mode))
+ &indices,
+ PyArray_AxisConverter, &dimension,
+ PyArray_OutputConverter, &out,
+ PyArray_ClipmodeConverter, &mode))
return NULL;
return _ARET(PyArray_TakeFrom(self, indices, dimension, out, mode));
@@ -90,9 +88,9 @@ array_put(PyArrayObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"indices", "values", "mode", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|O&", kwlist,
- &indices, &values,
- PyArray_ClipmodeConverter,
- &mode))
+ &indices,
+ &values,
+ PyArray_ClipmodeConverter, &mode))
return NULL;
return PyArray_PutTo(self, values, indices, mode);
}
@@ -203,10 +201,8 @@ array_argmax(PyArrayObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"axis", "out", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist,
- PyArray_AxisConverter,
- &axis,
- PyArray_OutputConverter,
- &out))
+ PyArray_AxisConverter, &axis,
+ PyArray_OutputConverter, &out))
return NULL;
return _ARET(PyArray_ArgMax(self, axis, out));
@@ -220,10 +216,8 @@ array_argmin(PyArrayObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"axis", "out", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist,
- PyArray_AxisConverter,
- &axis,
- PyArray_OutputConverter,
- &out))
+ PyArray_AxisConverter, &axis,
+ PyArray_OutputConverter, &out))
return NULL;
return _ARET(PyArray_ArgMin(self, axis, out));
@@ -237,10 +231,8 @@ array_max(PyArrayObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"axis", "out", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist,
- PyArray_AxisConverter,
- &axis,
- PyArray_OutputConverter,
- &out))
+ PyArray_AxisConverter, &axis,
+ PyArray_OutputConverter, &out))
return NULL;
return PyArray_Max(self, axis, out);
@@ -254,10 +246,8 @@ array_ptp(PyArrayObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"axis", "out", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist,
- PyArray_AxisConverter,
- &axis,
- PyArray_OutputConverter,
- &out))
+ PyArray_AxisConverter, &axis,
+ PyArray_OutputConverter, &out))
return NULL;
return PyArray_Ptp(self, axis, out);
@@ -272,10 +262,8 @@ array_min(PyArrayObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"axis", "out", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist,
- PyArray_AxisConverter,
- &axis,
- PyArray_OutputConverter,
- &out))
+ PyArray_AxisConverter, &axis,
+ PyArray_OutputConverter, &out))
return NULL;
return PyArray_Min(self, axis, out);
@@ -315,7 +303,8 @@ PyArray_GetField(PyArrayObject *self, PyArray_Descr *typed, int offset)
self->nd, self->dimensions,
self->strides,
self->data + offset,
- self->flags, (PyObject *)self);
+ self->flags&(~NPY_F_CONTIGUOUS),
+ (PyObject *)self);
if (ret == NULL) {
return NULL;
}
@@ -335,8 +324,8 @@ array_getfield(PyArrayObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"dtype", "offset", 0};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|i", kwlist,
- PyArray_DescrConverter,
- &dtype, &offset)) {
+ PyArray_DescrConverter, &dtype,
+ &offset)) {
Py_XDECREF(dtype);
return NULL;
}
@@ -388,12 +377,20 @@ array_setfield(PyArrayObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"value", "dtype", "offset", 0};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO&|i", kwlist,
- &value, PyArray_DescrConverter,
- &dtype, &offset)) {
+ &value,
+ PyArray_DescrConverter, &dtype,
+ &offset)) {
Py_XDECREF(dtype);
return NULL;
}
+ if (PyDataType_REFCHK(PyArray_DESCR(self))) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "cannot call setfield on an object array");
+ Py_DECREF(dtype);
+ return NULL;
+ }
+
if (PyArray_SetField(self, dtype, offset, value) < 0) {
return NULL;
}
@@ -459,7 +456,8 @@ array_byteswap(PyArrayObject *self, PyObject *args)
{
Bool inplace = FALSE;
- if (!PyArg_ParseTuple(args, "|O&", PyArray_BoolConverter, &inplace)) {
+ if (!PyArg_ParseTuple(args, "|O&",
+ PyArray_BoolConverter, &inplace)) {
return NULL;
}
return PyArray_Byteswap(self, inplace);
@@ -482,8 +480,7 @@ array_tostring(PyArrayObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"order", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&", kwlist,
- PyArray_OrderConverter,
- &order)) {
+ PyArray_OrderConverter, &order)) {
return NULL;
}
return PyArray_ToString(self, order);
@@ -504,7 +501,9 @@ array_tofile(PyArrayObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"file", "sep", "format", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|ss", kwlist,
- &file, &sep, &format)) {
+ &file,
+ &sep,
+ &format)) {
return NULL;
}
@@ -744,12 +743,35 @@ array_setscalar(PyArrayObject *self, PyObject *args) {
return Py_None;
}
+/* Sets the array values from another array as if they were flat */
+static PyObject *
+array_setasflat(PyArrayObject *self, PyObject *args)
+{
+ PyObject *arr_in;
+ PyArrayObject *arr;
+
+ if (!PyArg_ParseTuple(args, "O", &arr_in)) {
+ return NULL;
+ }
+
+ arr = (PyArrayObject *)PyArray_FromAny(arr_in, NULL, 0, 0, 0, NULL);
+ if (arr == NULL) {
+ return NULL;
+ }
+
+ if (PyArray_CopyAnyInto(self, arr) != 0) {
+ Py_DECREF(arr);
+ return NULL;
+ }
+
+ Py_DECREF(arr);
+ Py_RETURN_NONE;
+}
static PyObject *
-array_cast(PyArrayObject *self, PyObject *args)
+array_astype(PyArrayObject *self, PyObject *args)
{
PyArray_Descr *descr = NULL;
- PyObject *obj;
if (!PyArg_ParseTuple(args, "O&", PyArray_DescrConverter,
&descr)) {
@@ -757,19 +779,6 @@ array_cast(PyArrayObject *self, PyObject *args)
return NULL;
}
- if (PyArray_EquivTypes(descr, self->descr)) {
- obj = _ARET(PyArray_NewCopy(self,NPY_ANYORDER));
- Py_XDECREF(descr);
- return obj;
- }
- if (descr->names != NULL) {
- int flags;
- flags = NPY_FORCECAST;
- if (PyArray_ISFORTRAN(self)) {
- flags |= NPY_FORTRAN;
- }
- return PyArray_FromArray(self, descr, flags);
- }
return PyArray_CastToType(self, descr, PyArray_ISFORTRAN(self));
}
@@ -865,8 +874,8 @@ array_getarray(PyArrayObject *self, PyObject *args)
PyArray_Descr *newtype = NULL;
PyObject *ret;
- if (!PyArg_ParseTuple(args, "|O&", PyArray_DescrConverter,
- &newtype)) {
+ if (!PyArg_ParseTuple(args, "|O&",
+ PyArray_DescrConverter, &newtype)) {
Py_XDECREF(newtype);
return NULL;
}
@@ -914,15 +923,15 @@ array_getarray(PyArrayObject *self, PyObject *args)
static PyObject *
array_copy(PyArrayObject *self, PyObject *args, PyObject *kwds)
{
- PyArray_ORDER fortran=PyArray_CORDER;
+ PyArray_ORDER order = PyArray_CORDER;
static char *kwlist[] = {"order", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&", kwlist,
- PyArray_OrderConverter, &fortran)) {
+ PyArray_OrderConverter, &order)) {
return NULL;
}
- return PyArray_NewCopy(self, fortran);
+ return PyArray_NewCopy(self, order);
}
#include <stdio.h>
@@ -976,8 +985,8 @@ array_repeat(PyArrayObject *self, PyObject *args, PyObject *kwds) {
static char *kwlist[] = {"repeats", "axis", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O&", kwlist,
- &repeats, PyArray_AxisConverter,
- &axis)) {
+ &repeats,
+ PyArray_AxisConverter, &axis)) {
return NULL;
}
return _ARET(PyArray_Repeat(self, repeats, axis));
@@ -1015,15 +1024,16 @@ array_sort(PyArrayObject *self, PyObject *args, PyObject *kwds)
{
int axis=-1;
int val;
- PyArray_SORTKIND which = PyArray_QUICKSORT;
+ PyArray_SORTKIND sortkind = PyArray_QUICKSORT;
PyObject *order = NULL;
PyArray_Descr *saved = NULL;
PyArray_Descr *newd;
static char *kwlist[] = {"axis", "kind", "order", NULL};
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iO&O", kwlist, &axis,
- PyArray_SortkindConverter, &which,
- &order)) {
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iO&O", kwlist,
+ &axis,
+ PyArray_SortkindConverter, &sortkind,
+ &order)) {
return NULL;
}
if (order == Py_None) {
@@ -1053,7 +1063,7 @@ array_sort(PyArrayObject *self, PyObject *args, PyObject *kwds)
self->descr = newd;
}
- val = PyArray_Sort(self, axis, which);
+ val = PyArray_Sort(self, axis, sortkind);
if (order != NULL) {
Py_XDECREF(self->descr);
self->descr = saved;
@@ -1069,14 +1079,14 @@ static PyObject *
array_argsort(PyArrayObject *self, PyObject *args, PyObject *kwds)
{
int axis = -1;
- PyArray_SORTKIND which = PyArray_QUICKSORT;
+ PyArray_SORTKIND sortkind = PyArray_QUICKSORT;
PyObject *order = NULL, *res;
PyArray_Descr *newd, *saved=NULL;
static char *kwlist[] = {"axis", "kind", "order", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&O", kwlist,
PyArray_AxisConverter, &axis,
- PyArray_SortkindConverter, &which,
+ PyArray_SortkindConverter, &sortkind,
&order)) {
return NULL;
}
@@ -1107,7 +1117,7 @@ array_argsort(PyArrayObject *self, PyObject *args, PyObject *kwds)
self->descr = newd;
}
- res = PyArray_ArgSort(self, axis, which);
+ res = PyArray_ArgSort(self, axis, sortkind);
if (order != NULL) {
Py_XDECREF(self->descr);
self->descr = saved;
@@ -1355,14 +1365,19 @@ array_setstate(PyArrayObject *self, PyObject *args)
/* This will free any memory associated with a and
use the string in setstate as the (writeable) memory.
*/
- if (!PyArg_ParseTuple(args, "(iO!O!iO)", &version, &PyTuple_Type,
- &shape, &PyArrayDescr_Type, &typecode,
- &fortran, &rawdata)) {
+ if (!PyArg_ParseTuple(args, "(iO!O!iO)",
+ &version,
+ &PyTuple_Type, &shape,
+ &PyArrayDescr_Type, &typecode,
+ &fortran,
+ &rawdata)) {
PyErr_Clear();
version = 0;
- if (!PyArg_ParseTuple(args, "(O!O!iO)", &PyTuple_Type,
- &shape, &PyArrayDescr_Type, &typecode,
- &fortran, &rawdata)) {
+ if (!PyArg_ParseTuple(args, "(O!O!iO)",
+ &PyTuple_Type, &shape,
+ &PyArrayDescr_Type, &typecode,
+ &fortran,
+ &rawdata)) {
return NULL;
}
}
@@ -1675,11 +1690,9 @@ array_mean(PyArrayObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"axis", "dtype", "out", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&O&", kwlist,
- PyArray_AxisConverter,
- &axis, PyArray_DescrConverter2,
- &dtype,
- PyArray_OutputConverter,
- &out)) {
+ PyArray_AxisConverter, &axis,
+ PyArray_DescrConverter2, &dtype,
+ PyArray_OutputConverter, &out)) {
Py_XDECREF(dtype);
return NULL;
}
@@ -1699,11 +1712,9 @@ array_sum(PyArrayObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"axis", "dtype", "out", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&O&", kwlist,
- PyArray_AxisConverter,
- &axis, PyArray_DescrConverter2,
- &dtype,
- PyArray_OutputConverter,
- &out)) {
+ PyArray_AxisConverter, &axis,
+ PyArray_DescrConverter2, &dtype,
+ PyArray_OutputConverter, &out)) {
Py_XDECREF(dtype);
return NULL;
}
@@ -1724,11 +1735,9 @@ array_cumsum(PyArrayObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"axis", "dtype", "out", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&O&", kwlist,
- PyArray_AxisConverter,
- &axis, PyArray_DescrConverter2,
- &dtype,
- PyArray_OutputConverter,
- &out)) {
+ PyArray_AxisConverter, &axis,
+ PyArray_DescrConverter2, &dtype,
+ PyArray_OutputConverter, &out)) {
Py_XDECREF(dtype);
return NULL;
}
@@ -1748,11 +1757,9 @@ array_prod(PyArrayObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"axis", "dtype", "out", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&O&", kwlist,
- PyArray_AxisConverter,
- &axis, PyArray_DescrConverter2,
- &dtype,
- PyArray_OutputConverter,
- &out)) {
+ PyArray_AxisConverter, &axis,
+ PyArray_DescrConverter2, &dtype,
+ PyArray_OutputConverter, &out)) {
Py_XDECREF(dtype);
return NULL;
}
@@ -1772,11 +1779,9 @@ array_cumprod(PyArrayObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"axis", "dtype", "out", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&O&", kwlist,
- PyArray_AxisConverter,
- &axis, PyArray_DescrConverter2,
- &dtype,
- PyArray_OutputConverter,
- &out)) {
+ PyArray_AxisConverter, &axis,
+ PyArray_DescrConverter2, &dtype,
+ PyArray_OutputConverter, &out)) {
Py_XDECREF(dtype);
return NULL;
}
@@ -1818,10 +1823,8 @@ array_any(PyArrayObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"axis", "out", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist,
- PyArray_AxisConverter,
- &axis,
- PyArray_OutputConverter,
- &out))
+ PyArray_AxisConverter, &axis,
+ PyArray_OutputConverter, &out))
return NULL;
return PyArray_Any(self, axis, out);
@@ -1836,10 +1839,8 @@ array_all(PyArrayObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"axis", "out", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist,
- PyArray_AxisConverter,
- &axis,
- PyArray_OutputConverter,
- &out))
+ PyArray_AxisConverter, &axis,
+ PyArray_OutputConverter, &out))
return NULL;
return PyArray_All(self, axis, out);
@@ -1857,11 +1858,10 @@ array_stddev(PyArrayObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"axis", "dtype", "out", "ddof", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&O&i", kwlist,
- PyArray_AxisConverter,
- &axis, PyArray_DescrConverter2,
- &dtype,
- PyArray_OutputConverter,
- &out, &ddof)) {
+ PyArray_AxisConverter, &axis,
+ PyArray_DescrConverter2, &dtype,
+ PyArray_OutputConverter, &out,
+ &ddof)) {
Py_XDECREF(dtype);
return NULL;
}
@@ -1883,11 +1883,10 @@ array_variance(PyArrayObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"axis", "dtype", "out", "ddof", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&O&i", kwlist,
- PyArray_AxisConverter,
- &axis, PyArray_DescrConverter2,
- &dtype,
- PyArray_OutputConverter,
- &out, &ddof)) {
+ PyArray_AxisConverter, &axis,
+ PyArray_DescrConverter2, &dtype,
+ PyArray_OutputConverter, &out,
+ &ddof)) {
Py_XDECREF(dtype);
return NULL;
}
@@ -1907,10 +1906,9 @@ array_compress(PyArrayObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"condition", "axis", "out", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O&O&", kwlist,
- &condition, PyArray_AxisConverter,
- &axis,
- PyArray_OutputConverter,
- &out)) {
+ &condition,
+ PyArray_AxisConverter, &axis,
+ PyArray_OutputConverter, &out)) {
return NULL;
}
return _ARET(PyArray_Compress(self, condition, axis, out));
@@ -1937,7 +1935,9 @@ array_trace(PyArrayObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"offset", "axis1", "axis2", "dtype", "out", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iiiO&O&", kwlist,
- &offset, &axis1, &axis2,
+ &offset,
+ &axis1,
+ &axis2,
PyArray_DescrConverter2, &dtype,
PyArray_OutputConverter, &out)) {
Py_XDECREF(dtype);
@@ -1960,9 +1960,9 @@ array_clip(PyArrayObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"min", "max", "out", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO&", kwlist,
- &min, &max,
- PyArray_OutputConverter,
- &out)) {
+ &min,
+ &max,
+ PyArray_OutputConverter, &out)) {
return NULL;
}
if (max == NULL && min == NULL) {
@@ -1994,7 +1994,9 @@ array_diagonal(PyArrayObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"offset", "axis1", "axis2", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iii", kwlist,
- &offset, &axis1, &axis2)) {
+ &offset,
+ &axis1,
+ &axis2)) {
return NULL;
}
return _ARET(PyArray_Diagonal(self, offset, axis1, axis2));
@@ -2004,28 +2006,28 @@ array_diagonal(PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject *
array_flatten(PyArrayObject *self, PyObject *args, PyObject *kwds)
{
- PyArray_ORDER fortran = PyArray_CORDER;
+ PyArray_ORDER order = PyArray_CORDER;
static char *kwlist[] = {"order", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&", kwlist,
- PyArray_OrderConverter, &fortran)) {
+ PyArray_OrderConverter, &order)) {
return NULL;
}
- return PyArray_Flatten(self, fortran);
+ return PyArray_Flatten(self, order);
}
static PyObject *
array_ravel(PyArrayObject *self, PyObject *args, PyObject *kwds)
{
- PyArray_ORDER fortran = PyArray_CORDER;
+ PyArray_ORDER order = PyArray_CORDER;
static char *kwlist[] = {"order", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&", kwlist,
- PyArray_OrderConverter, &fortran)) {
+ PyArray_OrderConverter, &order)) {
return NULL;
}
- return PyArray_Ravel(self, fortran);
+ return PyArray_Ravel(self, order);
}
@@ -2037,8 +2039,8 @@ array_round(PyArrayObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"decimals", "out", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iO&", kwlist,
- &decimals, PyArray_OutputConverter,
- &out)) {
+ &decimals,
+ PyArray_OutputConverter, &out)) {
return NULL;
}
return _ARET(PyArray_Round(self, decimals, out));
@@ -2056,7 +2058,9 @@ array_setflags(PyArrayObject *self, PyObject *args, PyObject *kwds)
int flagback = self->flags;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", kwlist,
- &write, &align, &uic))
+ &write,
+ &align,
+ &uic))
return NULL;
if (align != Py_None) {
@@ -2181,7 +2185,7 @@ NPY_NO_EXPORT PyMethodDef array_methods[] = {
(PyCFunction)array_argsort,
METH_VARARGS | METH_KEYWORDS, NULL},
{"astype",
- (PyCFunction)array_cast,
+ (PyCFunction)array_astype,
METH_VARARGS, NULL},
{"byteswap",
(PyCFunction)array_byteswap,
@@ -2231,6 +2235,9 @@ NPY_NO_EXPORT PyMethodDef array_methods[] = {
{"itemset",
(PyCFunction) array_setscalar,
METH_VARARGS, NULL},
+ {"setasflat",
+ (PyCFunction) array_setasflat,
+ METH_VARARGS, NULL},
{"max",
(PyCFunction)array_max,
METH_VARARGS | METH_KEYWORDS, NULL},
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c
index d4dba719c..833c969b0 100644
--- a/numpy/core/src/multiarray/multiarraymodule.c
+++ b/numpy/core/src/multiarray/multiarraymodule.c
@@ -42,6 +42,11 @@ NPY_NO_EXPORT int NPY_NUMUSERTYPES = 0;
#include "number.h"
#include "scalartypes.h"
#include "numpymemoryview.h"
+#include "convert_datatype.h"
+#include "new_iterator_pywrap.h"
+
+/* Only here for API compatibility */
+NPY_NO_EXPORT PyTypeObject PyBigArray_Type;
/*NUMPY_API
* Get Priority from object
@@ -84,10 +89,10 @@ PyArray_MultiplyIntList(int *l1, int n)
/*NUMPY_API
* Multiply a List
*/
-NPY_NO_EXPORT intp
-PyArray_MultiplyList(intp *l1, int n)
+NPY_NO_EXPORT npy_intp
+PyArray_MultiplyList(npy_intp *l1, int n)
{
- intp s = 1;
+ npy_intp s = 1;
while (n--) {
s *= (*l1++);
@@ -98,15 +103,15 @@ PyArray_MultiplyList(intp *l1, int n)
/*NUMPY_API
* Multiply a List of Non-negative numbers with over-flow detection.
*/
-NPY_NO_EXPORT intp
-PyArray_OverflowMultiplyList(intp *l1, int n)
+NPY_NO_EXPORT npy_intp
+PyArray_OverflowMultiplyList(npy_intp *l1, int n)
{
- intp prod = 1;
- intp imax = NPY_MAX_INTP;
+ npy_intp prod = 1;
+ npy_intp imax = NPY_MAX_INTP;
int i;
for (i = 0; i < n; i++) {
- intp dim = l1[i];
+ npy_intp dim = l1[i];
if (dim == 0) {
return 0;
@@ -124,10 +129,10 @@ PyArray_OverflowMultiplyList(intp *l1, int n)
* Produce a pointer into array
*/
NPY_NO_EXPORT void *
-PyArray_GetPtr(PyArrayObject *obj, intp* ind)
+PyArray_GetPtr(PyArrayObject *obj, npy_intp* ind)
{
int n = obj->nd;
- intp *strides = obj->strides;
+ npy_intp *strides = obj->strides;
char *dptr = obj->data;
while (n--) {
@@ -140,7 +145,7 @@ PyArray_GetPtr(PyArrayObject *obj, intp* ind)
* Compare Lists
*/
NPY_NO_EXPORT int
-PyArray_CompareLists(intp *l1, intp *l2, int n)
+PyArray_CompareLists(npy_intp *l1, npy_intp *l2, int n)
{
int i;
@@ -167,11 +172,11 @@ PyArray_CompareLists(intp *l1, intp *l2, int n)
* steals a reference to typedescr -- can be NULL
*/
NPY_NO_EXPORT int
-PyArray_AsCArray(PyObject **op, void *ptr, intp *dims, int nd,
+PyArray_AsCArray(PyObject **op, void *ptr, npy_intp *dims, int nd,
PyArray_Descr* typedescr)
{
PyArrayObject *ap;
- intp n, m, i, j;
+ npy_intp n, m, i, j;
char **ptr2;
char ***ptr3;
@@ -215,7 +220,7 @@ PyArray_AsCArray(PyObject **op, void *ptr, intp *dims, int nd,
}
*((char ****)ptr) = ptr3;
}
- memcpy(dims, ap->dimensions, nd*sizeof(intp));
+ memcpy(dims, ap->dimensions, nd*sizeof(npy_intp));
*op = (PyObject *)ap;
return 0;
@@ -232,7 +237,7 @@ PyArray_AsCArray(PyObject **op, void *ptr, intp *dims, int nd,
NPY_NO_EXPORT int
PyArray_As1D(PyObject **op, char **ptr, int *d1, int typecode)
{
- intp newd1;
+ npy_intp newd1;
PyArray_Descr *descr;
char msg[] = "PyArray_As1D: use PyArray_AsCArray.";
@@ -253,7 +258,7 @@ PyArray_As1D(PyObject **op, char **ptr, int *d1, int typecode)
NPY_NO_EXPORT int
PyArray_As2D(PyObject **op, char ***ptr, int *d1, int *d2, int typecode)
{
- intp newdims[2];
+ npy_intp newdims[2];
PyArray_Descr *descr;
char msg[] = "PyArray_As1D: use PyArray_AsCArray.";
@@ -347,7 +352,7 @@ PyArray_Concatenate(PyObject *op, int axis)
char *data;
PyTypeObject *subtype;
double prior1, prior2;
- intp numbytes;
+ npy_intp numbytes;
n = PySequence_Length(op);
if (n == -1) {
@@ -547,7 +552,7 @@ PyArray_CanCoerceScalar(int thistype, int neededtype,
* so 1 is returned, but
* _npy_scalar_kinds_table[uint]==POSINT < NEGINT,
* so 0 is returned, as required.
- *
+ *
*/
neededscalar = _npy_scalar_kinds_table[neededtype];
if (neededscalar >= scalar) {
@@ -578,8 +583,8 @@ PyArray_CanCoerceScalar(int thistype, int neededtype,
* priority of ap1 and ap2 into account.
*/
static PyArrayObject *
-new_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2,
- int nd, intp dimensions[], int typenum)
+new_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2, PyArrayObject* out,
+ int nd, npy_intp dimensions[], int typenum)
{
PyArrayObject *ret;
PyTypeObject *subtype;
@@ -597,6 +602,28 @@ new_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2,
prior1 = prior2 = 0.0;
subtype = Py_TYPE(ap1);
}
+ if (out) {
+ int d;
+ /* verify that out is usable */
+ if (Py_TYPE(out) != subtype ||
+ PyArray_NDIM(out) != nd ||
+ PyArray_TYPE(out) != typenum ||
+ !PyArray_ISCARRAY(out)) {
+ PyErr_SetString(PyExc_ValueError,
+ "output array is not acceptable "
+ "(must have the right type, nr dimensions, and be a C-Array)");
+ return 0;
+ }
+ for (d = 0; d < nd; ++d) {
+ if (dimensions[d] != PyArray_DIM(out, d)) {
+ PyErr_SetString(PyExc_ValueError,
+ "output array has wrong dimensions");
+ return 0;
+ }
+ }
+ Py_INCREF(out);
+ return out;
+ }
ret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions,
typenum, NULL, NULL, 0, 0,
@@ -615,11 +642,11 @@ PyArray_InnerProduct(PyObject *op1, PyObject *op2)
{
PyArrayObject *ap1, *ap2, *ret = NULL;
PyArrayIterObject *it1, *it2;
- intp i, j, l;
+ npy_intp i, j, l;
int typenum, nd, axis;
- intp is1, is2, os;
+ npy_intp is1, is2, os;
char *op;
- intp dimensions[MAX_DIMS];
+ npy_intp dimensions[MAX_DIMS];
PyArray_DotFunc *dot;
PyArray_Descr *typec;
NPY_BEGIN_THREADS_DEF;
@@ -666,7 +693,7 @@ PyArray_InnerProduct(PyObject *op1, PyObject *op2)
* Need to choose an output array that can hold a sum
* -- use priority to determine which subtype.
*/
- ret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);
+ ret = new_array_for_sum(ap1, ap2, NULL, nd, dimensions, typenum);
if (ret == NULL) {
goto fail;
}
@@ -713,21 +740,20 @@ PyArray_InnerProduct(PyObject *op1, PyObject *op2)
return NULL;
}
-
/*NUMPY_API
- *Numeric.matrixproduct(a,v)
+ * Numeric.matrixproduct(a,v,out)
* just like inner product but does the swapaxes stuff on the fly
*/
NPY_NO_EXPORT PyObject *
-PyArray_MatrixProduct(PyObject *op1, PyObject *op2)
+PyArray_MatrixProduct2(PyObject *op1, PyObject *op2, PyObject* out)
{
PyArrayObject *ap1, *ap2, *ret = NULL;
PyArrayIterObject *it1, *it2;
- intp i, j, l;
+ npy_intp i, j, l;
int typenum, nd, axis, matchDim;
- intp is1, is2, os;
+ npy_intp is1, is2, os;
char *op;
- intp dimensions[MAX_DIMS];
+ npy_intp dimensions[MAX_DIMS];
PyArray_DotFunc *dot;
PyArray_Descr *typec;
NPY_BEGIN_THREADS_DEF;
@@ -735,6 +761,7 @@ PyArray_MatrixProduct(PyObject *op1, PyObject *op2)
typenum = PyArray_ObjectType(op1, 0);
typenum = PyArray_ObjectType(op2, typenum);
typec = PyArray_DescrFromType(typenum);
+
Py_INCREF(typec);
ap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, ALIGNED, NULL);
if (ap1 == NULL) {
@@ -788,7 +815,7 @@ PyArray_MatrixProduct(PyObject *op1, PyObject *op2)
is1 = ap1->strides[ap1->nd-1]; is2 = ap2->strides[matchDim];
/* Choose which subtype to return */
- ret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);
+ ret = new_array_for_sum(ap1, ap2, out, nd, dimensions, typenum);
if (ret == NULL) {
goto fail;
}
@@ -846,6 +873,16 @@ PyArray_MatrixProduct(PyObject *op1, PyObject *op2)
}
/*NUMPY_API
+ *Numeric.matrixproduct(a,v)
+ * just like inner product but does the swapaxes stuff on the fly
+ */
+NPY_NO_EXPORT PyObject *
+PyArray_MatrixProduct(PyObject *op1, PyObject *op2)
+{
+ return PyArray_MatrixProduct2(op1, op2, NULL);
+}
+
+/*NUMPY_API
* Fast Copy and Transpose
*/
NPY_NO_EXPORT PyObject *
@@ -853,8 +890,8 @@ PyArray_CopyAndTranspose(PyObject *op)
{
PyObject *ret, *arr;
int nd;
- intp dims[2];
- intp i,j;
+ npy_intp dims[2];
+ npy_intp i,j;
int elsize, str2;
char *iptr;
char *optr;
@@ -920,9 +957,9 @@ _pyarray_correlate(PyArrayObject *ap1, PyArrayObject *ap2, int typenum,
int mode, int *inverted)
{
PyArrayObject *ret;
- intp length;
- intp i, n1, n2, n, n_left, n_right;
- intp is1, is2, os;
+ npy_intp length;
+ npy_intp i, n1, n2, n, n_left, n_right;
+ npy_intp is1, is2, os;
char *ip1, *ip2, *op;
PyArray_DotFunc *dot;
@@ -951,7 +988,7 @@ _pyarray_correlate(PyArrayObject *ap1, PyArrayObject *ap2, int typenum,
n_left = n_right = 0;
break;
case 1:
- n_left = (intp)(n/2);
+ n_left = (npy_intp)(n/2);
n_right = n - n_left - 1;
break;
case 2:
@@ -968,7 +1005,7 @@ _pyarray_correlate(PyArrayObject *ap1, PyArrayObject *ap2, int typenum,
* Need to choose an output array that can hold a sum
* -- use priority to determine which subtype.
*/
- ret = new_array_for_sum(ap1, ap2, 1, &length, typenum);
+ ret = new_array_for_sum(ap1, ap2, NULL, 1, &length, typenum);
if (ret == NULL) {
return NULL;
}
@@ -1025,11 +1062,11 @@ clean_ret:
static int
_pyarray_revert(PyArrayObject *ret)
{
- intp length;
- intp i;
+ npy_intp length;
+ npy_intp i;
PyArray_CopySwapFunc *copyswap;
char *tmp = NULL, *sw1, *sw2;
- intp os;
+ npy_intp os;
char *op;
length = ret->dimensions[0];
@@ -1196,14 +1233,15 @@ array_putmask(PyObject *NPY_UNUSED(module), PyObject *args, PyObject *kwds)
}
/*NUMPY_API
- * Convert an object to FORTRAN / C / ANY
+ * Convert an object to FORTRAN / C / ANY / KEEP
*/
NPY_NO_EXPORT int
PyArray_OrderConverter(PyObject *object, NPY_ORDER *val)
{
char *str;
+ /* Leave the desired default from the caller for NULL/Py_None */
if (object == NULL || object == Py_None) {
- *val = PyArray_ANYORDER;
+ return PY_SUCCEED;
}
else if (PyUnicode_Check(object)) {
PyObject *tmp;
@@ -1215,10 +1253,10 @@ PyArray_OrderConverter(PyObject *object, NPY_ORDER *val)
}
else if (!PyBytes_Check(object) || PyBytes_GET_SIZE(object) < 1) {
if (PyObject_IsTrue(object)) {
- *val = PyArray_FORTRANORDER;
+ *val = NPY_FORTRANORDER;
}
else {
- *val = PyArray_CORDER;
+ *val = NPY_CORDER;
}
if (PyErr_Occurred()) {
return PY_FAIL;
@@ -1228,13 +1266,16 @@ PyArray_OrderConverter(PyObject *object, NPY_ORDER *val)
else {
str = PyBytes_AS_STRING(object);
if (str[0] == 'C' || str[0] == 'c') {
- *val = PyArray_CORDER;
+ *val = NPY_CORDER;
}
else if (str[0] == 'F' || str[0] == 'f') {
- *val = PyArray_FORTRANORDER;
+ *val = NPY_FORTRANORDER;
}
else if (str[0] == 'A' || str[0] == 'a') {
- *val = PyArray_ANYORDER;
+ *val = NPY_ANYORDER;
+ }
+ else if (str[0] == 'K' || str[0] == 'k') {
+ *val = NPY_KEEPORDER;
}
else {
PyErr_SetString(PyExc_TypeError,
@@ -1301,9 +1342,53 @@ PyArray_ClipmodeConverter(PyObject *object, NPY_CLIPMODE *val)
return PY_FAIL;
}
+/*NUMPY_API
+ * Convert an object to an array of n NPY_CLIPMODE values.
+ * This is intended to be used in functions where a different mode
+ * could be applied to each axis, like in ravel_coords.
+ */
+NPY_NO_EXPORT int
+PyArray_ConvertClipmodeSequence(PyObject *object, NPY_CLIPMODE *modes, int n)
+{
+ int i;
+ /* Get the clip mode(s) */
+ if (object && (PyTuple_Check(object) || PyList_Check(object))) {
+ if (PySequence_Size(object) != n) {
+ PyErr_Format(PyExc_ValueError,
+ "list of clipmodes has wrong length (%d instead of %d)",
+ (int)PySequence_Size(object), n);
+ return PY_FAIL;
+ }
+
+ for (i = 0; i < n; ++i) {
+ PyObject *item = PySequence_GetItem(object, i);
+ if(item == NULL) {
+ return PY_FAIL;
+ }
+
+ if(PyArray_ClipmodeConverter(item, &modes[i]) != PY_SUCCEED) {
+ Py_DECREF(item);
+ return PY_FAIL;
+ }
+
+ Py_DECREF(item);
+ }
+ }
+ else if (PyArray_ClipmodeConverter(object, &modes[0]) == PY_SUCCEED) {
+ for (i = 1; i < n; ++i) {
+ modes[i] = modes[0];
+ }
+ }
+ else {
+ return PY_FAIL;
+ }
+ return PY_SUCCEED;
+}
+
/*
- * compare the field dictionary for two types
- * return 1 if the same or 0 if not
+ * Compare the field dictionaries for two types.
+ *
+ * Return 1 if the contents are the same, 0 if not.
*/
static int
_equivalent_fields(PyObject *field1, PyObject *field2) {
@@ -1405,10 +1490,16 @@ _equivalent_subarrays(PyArray_ArrayDescr *sub1, PyArray_ArrayDescr *sub2)
NPY_NO_EXPORT unsigned char
PyArray_EquivTypes(PyArray_Descr *typ1, PyArray_Descr *typ2)
{
- int typenum1 = typ1->type_num;
- int typenum2 = typ2->type_num;
- int size1 = typ1->elsize;
- int size2 = typ2->elsize;
+ int typenum1, typenum2, size1, size2;
+
+ if (typ1 == typ2) {
+ return TRUE;
+ }
+
+ typenum1 = typ1->type_num;
+ typenum2 = typ2->type_num;
+ size1 = typ1->elsize;
+ size2 = typ2->elsize;
if (size1 != size2) {
return FALSE;
@@ -1455,8 +1546,8 @@ PyArray_EquivTypenums(int typenum1, int typenum2)
static PyObject *
_prepend_ones(PyArrayObject *arr, int nd, int ndmin)
{
- intp newdims[MAX_DIMS];
- intp newstrides[MAX_DIMS];
+ npy_intp newdims[MAX_DIMS];
+ npy_intp newstrides[MAX_DIMS];
int i, k, num;
PyObject *ret;
@@ -1481,10 +1572,10 @@ _prepend_ones(PyArrayObject *arr, int nd, int ndmin)
#define _ARET(x) PyArray_Return((PyArrayObject *)(x))
-#define STRIDING_OK(op, order) ((order) == PyArray_ANYORDER || \
- ((order) == PyArray_CORDER && \
+#define STRIDING_OK(op, order) ((order) == NPY_ANYORDER || \
+ ((order) == NPY_CORDER && \
PyArray_ISCONTIGUOUS(op)) || \
- ((order) == PyArray_FORTRANORDER && \
+ ((order) == NPY_FORTRANORDER && \
PyArray_ISFORTRAN(op)))
static PyObject *
@@ -1498,7 +1589,7 @@ _array_fromobject(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kws)
int ndmin = 0, nd;
PyArray_Descr *type = NULL;
PyArray_Descr *oldtype = NULL;
- NPY_ORDER order=PyArray_ANYORDER;
+ NPY_ORDER order = NPY_ANYORDER;
int flags = 0;
if (PyTuple_GET_SIZE(args) > 2) {
@@ -1559,11 +1650,11 @@ _array_fromobject(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kws)
if (copy) {
flags = ENSURECOPY;
}
- if (order == PyArray_CORDER) {
+ if (order == NPY_CORDER) {
flags |= CONTIGUOUS;
}
- else if ((order == PyArray_FORTRANORDER)
- /* order == PyArray_ANYORDER && */
+ else if ((order == NPY_FORTRANORDER)
+ /* order == NPY_ANYORDER && */
|| (PyArray_Check(op) && PyArray_ISFORTRAN(op))) {
flags |= FORTRAN;
}
@@ -1577,7 +1668,10 @@ _array_fromobject(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kws)
finish:
Py_XDECREF(type);
- if (!ret || (nd=PyArray_NDIM(ret)) >= ndmin) {
+ if (!ret) {
+ return ret;
+ }
+ else if ((nd=PyArray_NDIM(ret)) >= ndmin) {
return ret;
}
/*
@@ -1598,7 +1692,7 @@ array_empty(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kwds)
static char *kwlist[] = {"shape","dtype","order",NULL};
PyArray_Descr *typecode = NULL;
PyArray_Dims shape = {NULL, 0};
- NPY_ORDER order = PyArray_CORDER;
+ NPY_ORDER order = NPY_CORDER;
Bool fortran;
PyObject *ret = NULL;
@@ -1608,12 +1702,20 @@ array_empty(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kwds)
PyArray_OrderConverter, &order)) {
goto fail;
}
- if (order == PyArray_FORTRANORDER) {
- fortran = TRUE;
- }
- else {
- fortran = FALSE;
+
+ switch (order) {
+ case NPY_CORDER:
+ fortran = FALSE;
+ break;
+ case NPY_FORTRANORDER:
+ fortran = TRUE;
+ break;
+ default:
+ PyErr_SetString(PyExc_ValueError,
+ "only 'C' or 'F' order is permitted");
+ goto fail;
}
+
ret = PyArray_Empty(shape.len, shape.ptr, typecode, fortran);
PyDimMem_FREE(shape.ptr);
return ret;
@@ -1624,6 +1726,33 @@ array_empty(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kwds)
return NULL;
}
+static PyObject *
+array_empty_like(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kwds)
+{
+
+ static char *kwlist[] = {"prototype","dtype","order",NULL};
+ PyArrayObject *prototype = NULL;
+ PyArray_Descr *dtype = NULL;
+ NPY_ORDER order = NPY_KEEPORDER;
+ PyObject *ret = NULL;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|O&O&", kwlist,
+ PyArray_Converter, &prototype,
+ PyArray_DescrConverter2, &dtype,
+ PyArray_OrderConverter, &order)) {
+ goto fail;
+ }
+ /* steals the reference to dtype if it's not NULL */
+ ret = PyArray_NewLikeArray(prototype, order, dtype);
+ Py_DECREF(prototype);
+ return ret;
+
+ fail:
+ Py_XDECREF(prototype);
+ Py_XDECREF(dtype);
+ return NULL;
+}
+
/*
* This function is needed for supporting Pickles of
* numpy scalar objects.
@@ -1694,7 +1823,7 @@ array_zeros(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kwds)
static char *kwlist[] = {"shape","dtype","order",NULL}; /* XXX ? */
PyArray_Descr *typecode = NULL;
PyArray_Dims shape = {NULL, 0};
- NPY_ORDER order = PyArray_CORDER;
+ NPY_ORDER order = NPY_CORDER;
Bool fortran = FALSE;
PyObject *ret = NULL;
@@ -1704,12 +1833,20 @@ array_zeros(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kwds)
PyArray_OrderConverter, &order)) {
goto fail;
}
- if (order == PyArray_FORTRANORDER) {
- fortran = TRUE;
- }
- else {
- fortran = FALSE;
+
+ switch (order) {
+ case NPY_CORDER:
+ fortran = FALSE;
+ break;
+ case NPY_FORTRANORDER:
+ fortran = TRUE;
+ break;
+ default:
+ PyErr_SetString(PyExc_ValueError,
+ "only 'C' or 'F' order is permitted");
+ goto fail;
}
+
ret = PyArray_Zeros(shape.len, shape.ptr, typecode, (int) fortran);
PyDimMem_FREE(shape.ptr);
return ret;
@@ -1721,6 +1858,40 @@ array_zeros(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kwds)
}
static PyObject *
+array_count_nonzero(PyObject *NPY_UNUSED(self), PyObject *args)
+{
+ PyObject *array_in;
+ PyArrayObject *array;
+ npy_intp count;
+
+ if (!PyArg_ParseTuple(args, "O", &array_in)) {
+ return NULL;
+ }
+
+ array = (PyArrayObject *)PyArray_FromAny(array_in, NULL, 0, 0, 0, NULL);
+ if (array == NULL) {
+ return NULL;
+ }
+
+ count = PyArray_CountNonzero(array);
+
+ Py_DECREF(array);
+
+#if defined(NPY_PY3K)
+ return (count == -1) ? NULL : PyLong_FromSsize_t(count);
+#elif PY_VERSION_HEX >= 0x02050000
+ return (count == -1) ? NULL : PyInt_FromSsize_t(count);
+#else
+ if ((npy_intp)((long)count) == count) {
+ return (count == -1) ? NULL : PyInt_FromLong(count);
+ }
+ else {
+ return (count == -1) ? NULL : PyLong_FromVoidPtr((void*)count);
+ }
+#endif
+}
+
+static PyObject *
array_fromstring(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *keywds)
{
char *data;
@@ -1736,7 +1907,7 @@ array_fromstring(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *keywds
Py_XDECREF(descr);
return NULL;
}
- return PyArray_FromString(data, (intp)s, descr, (intp)nin, sep);
+ return PyArray_FromString(data, (npy_intp)s, descr, (npy_intp)nin, sep);
}
@@ -1777,7 +1948,7 @@ array_fromfile(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *keywds)
if (type == NULL) {
type = PyArray_DescrFromType(PyArray_DEFAULT);
}
- ret = PyArray_FromFile(fp, type, (intp) nin, sep);
+ ret = PyArray_FromFile(fp, type, (npy_intp) nin, sep);
ok = npy_PyFile_DupClose(file, fp);
Py_DECREF(file);
if (ok < 0) {
@@ -1801,7 +1972,7 @@ array_fromiter(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *keywds)
Py_XDECREF(descr);
return NULL;
}
- return PyArray_FromIter(iter, descr, (intp)nin);
+ return PyArray_FromIter(iter, descr, (npy_intp)nin);
}
static PyObject *
@@ -1821,7 +1992,7 @@ array_frombuffer(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *keywds
if (type == NULL) {
type = PyArray_DescrFromType(PyArray_DEFAULT);
}
- return PyArray_FromBuffer(obj, type, (intp)nin, (intp)offset);
+ return PyArray_FromBuffer(obj, type, (npy_intp)nin, (npy_intp)offset);
}
static PyObject *
@@ -1850,14 +2021,371 @@ array_innerproduct(PyObject *NPY_UNUSED(dummy), PyObject *args)
}
static PyObject *
-array_matrixproduct(PyObject *NPY_UNUSED(dummy), PyObject *args)
+array_matrixproduct(PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject* kwds)
+{
+ PyObject *v, *a, *o = NULL;
+ char* kwlist[] = {"a", "b", "out", NULL };
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|O", kwlist, &a, &v, &o)) {
+ return NULL;
+ }
+ if (o == Py_None) {
+ o = NULL;
+ }
+ return _ARET(PyArray_MatrixProduct2(a, v, o));
+}
+
+static int
+einsum_sub_op_from_str(PyObject *args, PyObject **str_obj, char **subscripts,
+ PyArrayObject **op)
+{
+ int i, nop;
+ PyObject *subscripts_str;
+
+ nop = PyTuple_GET_SIZE(args) - 1;
+ if (nop <= 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "must specify the einstein sum subscripts string "
+ "and at least one operand");
+ return -1;
+ }
+ else if (nop >= NPY_MAXARGS) {
+ PyErr_SetString(PyExc_ValueError, "too many operands");
+ return -1;
+ }
+
+ /* Get the subscripts string */
+ subscripts_str = PyTuple_GET_ITEM(args, 0);
+ if (PyUnicode_Check(subscripts_str)) {
+ *str_obj = PyUnicode_AsASCIIString(subscripts_str);
+ if (*str_obj == NULL) {
+ return -1;
+ }
+ subscripts_str = *str_obj;
+ }
+
+ *subscripts = PyBytes_AsString(subscripts_str);
+ if (subscripts == NULL) {
+ Py_XDECREF(*str_obj);
+ *str_obj = NULL;
+ return -1;
+ }
+
+ /* Set the operands to NULL */
+ for (i = 0; i < nop; ++i) {
+ op[i] = NULL;
+ }
+
+ /* Get the operands */
+ for (i = 0; i < nop; ++i) {
+ PyObject *obj = PyTuple_GET_ITEM(args, i+1);
+
+ op[i] = (PyArrayObject *)PyArray_FromAny(obj,
+ NULL, 0, 0, NPY_ENSUREARRAY, NULL);
+ if (op[i] == NULL) {
+ goto fail;
+ }
+ }
+
+ return nop;
+
+fail:
+ for (i = 0; i < nop; ++i) {
+ Py_XDECREF(op[i]);
+ op[i] = NULL;
+ }
+
+ return -1;
+}
+
+/*
+ * Converts a list of subscripts to a string.
+ *
+ * Returns -1 on error, the number of characters placed in subscripts
+ * otherwise.
+ */
+static int
+einsum_list_to_subscripts(PyObject *obj, char *subscripts, int subsize)
+{
+ int ellipsis = 0, subindex = 0;
+ npy_intp i, size;
+ PyObject *item;
+
+ obj = PySequence_Fast(obj, "the subscripts for each operand must "
+ "be a list or a tuple");
+ if (obj == NULL) {
+ return -1;
+ }
+ size = PySequence_Size(obj);
+
+
+ for (i = 0; i < size; ++i) {
+ item = PySequence_Fast_GET_ITEM(obj, i);
+ /* Ellipsis */
+ if (item == Py_Ellipsis) {
+ if (ellipsis) {
+ PyErr_SetString(PyExc_ValueError,
+ "each subscripts list may have only one ellipsis");
+ Py_DECREF(obj);
+ return -1;
+ }
+ if (subindex + 3 >= subsize) {
+ PyErr_SetString(PyExc_ValueError,
+ "subscripts list is too long");
+ Py_DECREF(obj);
+ return -1;
+ }
+ subscripts[subindex++] = '.';
+ subscripts[subindex++] = '.';
+ subscripts[subindex++] = '.';
+ ellipsis = 1;
+ }
+ /* Subscript */
+ else if (PyInt_Check(item) || PyLong_Check(item)) {
+ long s = PyInt_AsLong(item);
+ if ( s < 0 || s > 2*26) {
+ PyErr_SetString(PyExc_ValueError,
+ "subscript is not within the valid range [0, 52]");
+ Py_DECREF(obj);
+ return -1;
+ }
+ if (s < 26) {
+ subscripts[subindex++] = 'A' + s;
+ }
+ else {
+ subscripts[subindex++] = 'a' + s;
+ }
+ if (subindex >= subsize) {
+ PyErr_SetString(PyExc_ValueError,
+ "subscripts list is too long");
+ Py_DECREF(obj);
+ return -1;
+ }
+ }
+ /* Invalid */
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "each subscript must be either an integer "
+ "or an ellipsis");
+ Py_DECREF(obj);
+ return -1;
+ }
+ }
+
+ Py_DECREF(obj);
+
+ return subindex;
+}
+
+/*
+ * Fills in the subscripts, with maximum size subsize, and op,
+ * with the values in the tuple 'args'.
+ *
+ * Returns -1 on error, number of operands placed in op otherwise.
+ */
+static int
+einsum_sub_op_from_lists(PyObject *args,
+ char *subscripts, int subsize, PyArrayObject **op)
{
- PyObject *v, *a;
+ int subindex = 0;
+ npy_intp i, nop;
+
+ nop = PyTuple_Size(args)/2;
+
+ if (nop == 0) {
+ PyErr_SetString(PyExc_ValueError, "must provide at least an "
+ "operand and a subscripts list to einsum");
+ return -1;
+ }
+ else if(nop >= NPY_MAXARGS) {
+ PyErr_SetString(PyExc_ValueError, "too many operands");
+ return -1;
+ }
+
+ /* Set the operands to NULL */
+ for (i = 0; i < nop; ++i) {
+ op[nop] = NULL;
+ }
+
+ /* Get the operands and build the subscript string */
+ for (i = 0; i < nop; ++i) {
+ PyObject *obj = PyTuple_GET_ITEM(args, 2*i);
+ int n;
+
+ /* Comma between the subscripts for each operand */
+ if (i != 0) {
+ subscripts[subindex++] = ',';
+ if (subindex >= subsize) {
+ PyErr_SetString(PyExc_ValueError,
+ "subscripts list is too long");
+ goto fail;
+ }
+ }
+
+ op[i] = (PyArrayObject *)PyArray_FromAny(obj,
+ NULL, 0, 0, NPY_ENSUREARRAY, NULL);
+ if (op[i] == NULL) {
+ goto fail;
+ }
+
+ obj = PyTuple_GET_ITEM(args, 2*i+1);
+ n = einsum_list_to_subscripts(obj, subscripts+subindex,
+ subsize-subindex);
+ if (n < 0) {
+ goto fail;
+ }
+ subindex += n;
+ }
+
+ /* Add the '->' to the string if provided */
+ if (PyTuple_Size(args) == 2*nop+1) {
+ PyObject *obj;
+ int n;
+
+ if (subindex + 2 >= subsize) {
+ PyErr_SetString(PyExc_ValueError,
+ "subscripts list is too long");
+ goto fail;
+ }
+ subscripts[subindex++] = '-';
+ subscripts[subindex++] = '>';
+
+ obj = PyTuple_GET_ITEM(args, 2*nop);
+ n = einsum_list_to_subscripts(obj, subscripts+subindex,
+ subsize-subindex);
+ if (n < 0) {
+ goto fail;
+ }
+ subindex += n;
+ }
+
+ /* NULL-terminate the subscripts string */
+ subscripts[subindex] = '\0';
+
+ return nop;
+
+fail:
+ for (i = 0; i < nop; ++i) {
+ Py_XDECREF(op[i]);
+ op[i] = NULL;
+ }
+
+ return -1;
+}
+
+static PyObject *
+array_einsum(PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *kwds)
+{
+ char *subscripts = NULL, subscripts_buffer[256];
+ PyObject *str_obj = NULL, *str_key_obj = NULL;
+ PyObject *arg0;
+ int i, nop;
+ PyArrayObject *op[NPY_MAXARGS];
+ NPY_ORDER order = NPY_KEEPORDER;
+ NPY_CASTING casting = NPY_SAFE_CASTING;
+ PyArrayObject *out = NULL;
+ PyArray_Descr *dtype = NULL;
+ PyObject *ret = NULL;
- if (!PyArg_ParseTuple(args, "OO", &a, &v)) {
+ if (PyTuple_GET_SIZE(args) < 1) {
+ PyErr_SetString(PyExc_ValueError,
+ "must specify the einstein sum subscripts string "
+ "and at least one operand, or at least one operand "
+ "and its corresponding subscripts list");
return NULL;
}
- return _ARET(PyArray_MatrixProduct(a, v));
+ arg0 = PyTuple_GET_ITEM(args, 0);
+
+ /* einsum('i,j', a, b), einsum('i,j->ij', a, b) */
+ if (PyString_Check(arg0) || PyUnicode_Check(arg0)) {
+ nop = einsum_sub_op_from_str(args, &str_obj, &subscripts, op);
+ }
+ /* einsum(a, [0], b, [1]), einsum(a, [0], b, [1], [0,1]) */
+ else {
+ nop = einsum_sub_op_from_lists(args, subscripts_buffer,
+ sizeof(subscripts_buffer), op);
+ subscripts = subscripts_buffer;
+ }
+ if (nop <= 0) {
+ goto finish;
+ }
+
+ /* Get the keyword arguments */
+ if (kwds != NULL) {
+ PyObject *key, *value;
+ Py_ssize_t pos = 0;
+ while (PyDict_Next(kwds, &pos, &key, &value)) {
+ char *str = NULL;
+
+#if defined(NPY_PY3K)
+ Py_XDECREF(str_key_obj);
+ str_key_obj = PyUnicode_AsASCIIString(key);
+ if (str_key_obj != NULL) {
+ key = str_key_obj;
+ }
+#endif
+
+ str = PyBytes_AsString(key);
+
+ if (str == NULL) {
+ PyErr_Clear();
+ PyErr_SetString(PyExc_TypeError, "invalid keyword");
+ goto finish;
+ }
+
+ if (strcmp(str,"out") == 0) {
+ if (PyArray_Check(value)) {
+ out = (PyArrayObject *)value;
+ }
+ else {
+ PyErr_SetString(PyExc_TypeError,
+ "keyword parameter out must be an "
+ "array for einsum");
+ goto finish;
+ }
+ }
+ else if (strcmp(str,"order") == 0) {
+ if (!PyArray_OrderConverter(value, &order)) {
+ goto finish;
+ }
+ }
+ else if (strcmp(str,"casting") == 0) {
+ if (!PyArray_CastingConverter(value, &casting)) {
+ goto finish;
+ }
+ }
+ else if (strcmp(str,"dtype") == 0) {
+ if (!PyArray_DescrConverter2(value, &dtype)) {
+ goto finish;
+ }
+ }
+ else {
+ PyErr_Format(PyExc_TypeError,
+ "'%s' is an invalid keyword for einsum",
+ str);
+ goto finish;
+ }
+ }
+ }
+
+ ret = (PyObject *)PyArray_EinsteinSum(subscripts, nop, op, dtype,
+ order, casting, out);
+
+ /* If no output was supplied, possibly convert to a scalar */
+ if (ret != NULL && out == NULL) {
+ ret = _ARET(ret);
+ }
+
+finish:
+ for (i = 0; i < nop; ++i) {
+ Py_XDECREF(op[i]);
+ }
+ Py_XDECREF(dtype);
+ Py_XDECREF(str_obj);
+ Py_XDECREF(str_key_obj);
+ /* out is a borrowed reference */
+
+ return ret;
}
static PyObject *
@@ -1923,7 +2451,7 @@ array_arange(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kws) {
NPY_NO_EXPORT unsigned int
PyArray_GetNDArrayCVersion(void)
{
- return (unsigned int)NPY_VERSION;
+ return (unsigned int)NPY_ABI_VERSION;
}
/*NUMPY_API
@@ -1932,7 +2460,7 @@ PyArray_GetNDArrayCVersion(void)
NPY_NO_EXPORT unsigned int
PyArray_GetNDArrayCFeatureVersion(void)
{
- return (unsigned int)NPY_FEATURE_VERSION;
+ return (unsigned int)NPY_API_VERSION;
}
static PyObject *
@@ -2160,23 +2688,51 @@ static PyObject *
array_can_cast_safely(PyObject *NPY_UNUSED(self), PyObject *args,
PyObject *kwds)
{
+ PyObject *from_obj = NULL;
PyArray_Descr *d1 = NULL;
PyArray_Descr *d2 = NULL;
Bool ret;
PyObject *retobj = NULL;
- static char *kwlist[] = {"from", "to", NULL};
+ NPY_CASTING casting = NPY_SAFE_CASTING;
+ static char *kwlist[] = {"from", "to", "casting", NULL};
- if(!PyArg_ParseTupleAndKeywords(args, kwds, "O&O&", kwlist,
- PyArray_DescrConverter, &d1, PyArray_DescrConverter, &d2)) {
+ if(!PyArg_ParseTupleAndKeywords(args, kwds, "OO&|O&", kwlist,
+ &from_obj,
+ PyArray_DescrConverter2, &d2,
+ PyArray_CastingConverter, &casting)) {
goto finish;
}
- if (d1 == NULL || d2 == NULL) {
+ if (d2 == NULL) {
PyErr_SetString(PyExc_TypeError,
"did not understand one of the types; 'None' not accepted");
goto finish;
}
- ret = PyArray_CanCastTo(d1, d2);
+ /* If the first parameter is an object or scalar, use CanCastArrayTo */
+ if (PyArray_Check(from_obj)) {
+ ret = PyArray_CanCastArrayTo((PyArrayObject *)from_obj, d2, casting);
+ }
+ else if (PyArray_IsScalar(from_obj, Generic) ||
+ PyArray_IsPythonNumber(from_obj)) {
+ PyArrayObject *arr;
+ arr = (PyArrayObject *)PyArray_FromAny(from_obj,
+ NULL, 0, 0, 0, NULL);
+ if (arr == NULL) {
+ goto finish;
+ }
+ ret = PyArray_CanCastArrayTo(arr, d2, casting);
+ Py_DECREF(arr);
+ }
+ /* Otherwise use CanCastTypeTo */
+ else {
+ if (!PyArray_DescrConverter2(from_obj, &d1) || d1 == NULL) {
+ PyErr_SetString(PyExc_TypeError,
+ "did not understand one of the types; 'None' not accepted");
+ goto finish;
+ }
+ ret = PyArray_CanCastTypeTo(d1, d2, casting);
+ }
+
retobj = ret ? Py_True : Py_False;
Py_INCREF(retobj);
@@ -2186,6 +2742,118 @@ array_can_cast_safely(PyObject *NPY_UNUSED(self), PyObject *args,
return retobj;
}
+static PyObject *
+array_promote_types(PyObject *NPY_UNUSED(dummy), PyObject *args)
+{
+ PyArray_Descr *d1 = NULL;
+ PyArray_Descr *d2 = NULL;
+ PyObject *ret = NULL;
+ if(!PyArg_ParseTuple(args, "O&O&",
+ PyArray_DescrConverter2, &d1, PyArray_DescrConverter2, &d2)) {
+ goto finish;
+ }
+
+ if (d1 == NULL || d2 == NULL) {
+ PyErr_SetString(PyExc_TypeError,
+ "did not understand one of the types");
+ goto finish;
+ }
+
+ ret = (PyObject *)PyArray_PromoteTypes(d1, d2);
+
+ finish:
+ Py_XDECREF(d1);
+ Py_XDECREF(d2);
+ return ret;
+}
+
+static PyObject *
+array_min_scalar_type(PyObject *NPY_UNUSED(dummy), PyObject *args)
+{
+ PyObject *array_in = NULL;
+ PyArrayObject *array;
+ PyObject *ret = NULL;
+
+ if(!PyArg_ParseTuple(args, "O", &array_in)) {
+ return NULL;
+ }
+
+ array = (PyArrayObject *)PyArray_FromAny(array_in, NULL, 0, 0, 0, NULL);
+ if (array == NULL) {
+ return NULL;
+ }
+
+ ret = (PyObject *)PyArray_MinScalarType(array);
+ Py_DECREF(array);
+ return ret;
+}
+
+static PyObject *
+array_result_type(PyObject *NPY_UNUSED(dummy), PyObject *args)
+{
+ npy_intp i, len, narr = 0, ndtypes = 0;
+ PyArrayObject *arr[NPY_MAXARGS];
+ PyArray_Descr *dtypes[NPY_MAXARGS];
+ PyObject *ret = NULL;
+
+ len = PyTuple_GET_SIZE(args);
+ if (len == 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "at least one array or dtype is required");
+ goto finish;
+ }
+
+ for (i = 0; i < len; ++i) {
+ PyObject *obj = PyTuple_GET_ITEM(args, i);
+ if (PyArray_Check(obj)) {
+ if (narr == NPY_MAXARGS) {
+ PyErr_SetString(PyExc_ValueError,
+ "too many arguments");
+ goto finish;
+ }
+ Py_INCREF(obj);
+ arr[narr] = (PyArrayObject *)obj;
+ ++narr;
+ }
+ else if (PyArray_IsScalar(obj, Generic) ||
+ PyArray_IsPythonNumber(obj)) {
+ if (narr == NPY_MAXARGS) {
+ PyErr_SetString(PyExc_ValueError,
+ "too many arguments");
+ goto finish;
+ }
+ arr[narr] = (PyArrayObject *)PyArray_FromAny(obj,
+ NULL, 0, 0, 0, NULL);
+ if (arr[narr] == NULL) {
+ goto finish;
+ }
+ ++narr;
+ }
+ else {
+ if (ndtypes == NPY_MAXARGS) {
+ PyErr_SetString(PyExc_ValueError,
+ "too many arguments");
+ goto finish;
+ }
+ if (!PyArray_DescrConverter2(obj, &dtypes[ndtypes])) {
+ goto finish;
+ }
+ ++ndtypes;
+ }
+ }
+
+ ret = (PyObject *)PyArray_ResultType(narr, arr, ndtypes, dtypes);
+
+finish:
+ for (i = 0; i < narr; ++i) {
+ Py_DECREF(arr[i]);
+ }
+ for (i = 0; i < ndtypes; ++i) {
+ Py_DECREF(dtypes[i]);
+ }
+ return ret;
+}
+
#if !defined(NPY_PY3K)
static PyObject *
new_buffer(PyObject *NPY_UNUSED(dummy), PyObject *args)
@@ -2348,20 +3016,20 @@ compare_chararrays(PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *kwds)
int cmp_op;
Bool rstrip;
char *cmp_str;
- Py_ssize_t strlen;
+ Py_ssize_t strlength;
PyObject *res = NULL;
static char msg[] = "comparision must be '==', '!=', '<', '>', '<=', '>='";
static char *kwlist[] = {"a1", "a2", "cmp", "rstrip", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOs#O&", kwlist,
- &array, &other, &cmp_str, &strlen,
+ &array, &other, &cmp_str, &strlength,
PyArray_BoolConverter, &rstrip)) {
return NULL;
}
- if (strlen < 1 || strlen > 2) {
+ if (strlength < 1 || strlength > 2) {
goto err;
}
- if (strlen > 1) {
+ if (strlength > 1) {
if (cmp_str[1] != '=') {
goto err;
}
@@ -2731,15 +3399,24 @@ static struct PyMethodDef array_module_methods[] = {
{"array",
(PyCFunction)_array_fromobject,
METH_VARARGS|METH_KEYWORDS, NULL},
+ {"nested_iters",
+ (PyCFunction)NpyIter_NestedIters,
+ METH_VARARGS|METH_KEYWORDS, NULL},
{"arange",
(PyCFunction)array_arange,
METH_VARARGS|METH_KEYWORDS, NULL},
{"zeros",
(PyCFunction)array_zeros,
METH_VARARGS|METH_KEYWORDS, NULL},
+ {"count_nonzero",
+ (PyCFunction)array_count_nonzero,
+ METH_VARARGS, NULL},
{"empty",
(PyCFunction)array_empty,
METH_VARARGS|METH_KEYWORDS, NULL},
+ {"empty_like",
+ (PyCFunction)array_empty_like,
+ METH_VARARGS|METH_KEYWORDS, NULL},
{"scalar",
(PyCFunction)array_scalar,
METH_VARARGS|METH_KEYWORDS, NULL},
@@ -2766,7 +3443,10 @@ static struct PyMethodDef array_module_methods[] = {
METH_VARARGS, NULL},
{"dot",
(PyCFunction)array_matrixproduct,
- METH_VARARGS, NULL},
+ METH_VARARGS | METH_KEYWORDS, NULL},
+ {"einsum",
+ (PyCFunction)array_einsum,
+ METH_VARARGS|METH_KEYWORDS, NULL},
{"_fastCopyAndTranspose",
(PyCFunction)array_fastCopyAndTranspose,
METH_VARARGS, NULL},
@@ -2785,6 +3465,15 @@ static struct PyMethodDef array_module_methods[] = {
{"can_cast",
(PyCFunction)array_can_cast_safely,
METH_VARARGS | METH_KEYWORDS, NULL},
+ {"promote_types",
+ (PyCFunction)array_promote_types,
+ METH_VARARGS, NULL},
+ {"min_scalar_type",
+ (PyCFunction)array_min_scalar_type,
+ METH_VARARGS, NULL},
+ {"result_type",
+ (PyCFunction)array_result_type,
+ METH_VARARGS, NULL},
#if !defined(NPY_PY3K)
{"newbuffer",
(PyCFunction)new_buffer,
@@ -3067,6 +3756,7 @@ PyMODINIT_FUNC initmultiarray(void) {
goto err;
}
PyArrayIter_Type.tp_iter = PyObject_SelfIter;
+ NpyIter_Type.tp_iter = PyObject_SelfIter;
PyArrayMultiIter_Type.tp_iter = PyObject_SelfIter;
PyArrayMultiIter_Type.tp_free = _pya_free;
if (PyType_Ready(&PyArrayIter_Type) < 0) {
@@ -3082,6 +3772,9 @@ PyMODINIT_FUNC initmultiarray(void) {
if (PyType_Ready(&PyArrayNeighborhoodIter_Type) < 0) {
return RETVAL;
}
+ if (PyType_Ready(&NpyIter_Type) < 0) {
+ return RETVAL;
+ }
PyArrayDescr_Type.tp_hash = PyArray_DescrHash;
if (PyType_Ready(&PyArrayDescr_Type) < 0) {
@@ -3159,6 +3852,8 @@ PyMODINIT_FUNC initmultiarray(void) {
Py_INCREF(&PyArrayIter_Type);
PyDict_SetItemString(d, "flatiter", (PyObject *)&PyArrayIter_Type);
Py_INCREF(&PyArrayMultiIter_Type);
+ PyDict_SetItemString(d, "newiter", (PyObject *)&NpyIter_Type);
+ Py_INCREF(&NpyIter_Type);
PyDict_SetItemString(d, "broadcast",
(PyObject *)&PyArrayMultiIter_Type);
Py_INCREF(&PyArrayDescr_Type);
diff --git a/numpy/core/src/multiarray/multiarraymodule_onefile.c b/numpy/core/src/multiarray/multiarraymodule_onefile.c
index ab6b4cc80..ceef0a56e 100644
--- a/numpy/core/src/multiarray/multiarraymodule_onefile.c
+++ b/numpy/core/src/multiarray/multiarraymodule_onefile.c
@@ -35,6 +35,12 @@
#include "conversion_utils.c"
#include "buffer.c"
+#include "new_iterator.c"
+#include "new_iterator_pywrap.c"
+#include "lowlevel_strided_loops.c"
+#include "dtype_transfer.c"
+#include "einsum.c"
+
#ifndef Py_UNICODE_WIDE
#include "ucsnarrow.c"
diff --git a/numpy/core/src/multiarray/new_iterator.c.src b/numpy/core/src/multiarray/new_iterator.c.src
new file mode 100644
index 000000000..d80fc6edc
--- /dev/null
+++ b/numpy/core/src/multiarray/new_iterator.c.src
@@ -0,0 +1,6294 @@
+/*
+ * This file implements the new, highly flexible iterator for NumPy.
+ *
+ * Copyright (c) 2010-2011 by Mark Wiebe (mwwiebe@gmail.com)
+ * The Univerity of British Columbia
+ *
+ * See LICENSE.txt for the license.
+ */
+
+#define PY_SSIZE_T_CLEAN
+#include "Python.h"
+#include "structmember.h"
+
+#define _MULTIARRAYMODULE
+#include <numpy/ndarrayobject.h>
+#include <numpy/npy_3kcompat.h>
+#include "convert_datatype.h"
+
+#include "lowlevel_strided_loops.h"
+
+/********** ITERATOR CONSTRUCTION TIMING **************/
+#define NPY_IT_CONSTRUCTION_TIMING 0
+
+#if NPY_IT_CONSTRUCTION_TIMING
+#define NPY_IT_TIME_POINT(var) { \
+ unsigned int hi, lo; \
+ __asm__ __volatile__ ( \
+ "rdtsc" \
+ : "=d" (hi), "=a" (lo)); \
+ var = (((unsigned long long)hi) << 32) | lo; \
+ }
+#define NPY_IT_PRINT_TIME_START(var) { \
+ printf("%30s: start\n", #var); \
+ c_temp = var; \
+ }
+#define NPY_IT_PRINT_TIME_VAR(var) { \
+ printf("%30s: %6.0f clocks\n", #var, \
+ ((double)(var-c_temp))); \
+ c_temp = var; \
+ }
+#else
+#define NPY_IT_TIME_POINT(var)
+#endif
+
+/******************************************************/
+
+/********** PRINTF DEBUG TRACING **************/
+#define NPY_IT_DBG_TRACING 0
+
+#if NPY_IT_DBG_TRACING
+#define NPY_IT_DBG_PRINT(s) printf("%s", s)
+#define NPY_IT_DBG_PRINT1(s, p1) printf(s, p1)
+#define NPY_IT_DBG_PRINT2(s, p1, p2) printf(s, p1, p2)
+#define NPY_IT_DBG_PRINT3(s, p1, p2, p3) printf(s, p1, p2, p3)
+#else
+#define NPY_IT_DBG_PRINT(s)
+#define NPY_IT_DBG_PRINT1(s, p1)
+#define NPY_IT_DBG_PRINT2(s, p1, p2)
+#define NPY_IT_DBG_PRINT3(s, p1, p2, p3)
+#endif
+/**********************************************/
+
+/* Rounds up a number of bytes to be divisible by sizeof intp */
+#if NPY_SIZEOF_INTP == 4
+#define NPY_INTP_ALIGNED(size) ((size + 0x3)&(-0x4))
+#else
+#define NPY_INTP_ALIGNED(size) ((size + 0x7)&(-0x8))
+#endif
+
+/* Internal iterator flags */
+
+/* The perm is the identity */
+#define NPY_ITFLAG_IDENTPERM 0x0001
+/* The perm has negative entries (indicating flipped axes) */
+#define NPY_ITFLAG_NEGPERM 0x0002
+/* The iterator is tracking an index */
+#define NPY_ITFLAG_HASINDEX 0x0004
+/* The iterator is tracking coordinates */
+#define NPY_ITFLAG_HASCOORDS 0x0008
+/* The iteration order was forced on construction */
+#define NPY_ITFLAG_FORCEDORDER 0x0010
+/* The inner loop is handled outside the iterator */
+#define NPY_ITFLAG_NOINNER 0x0020
+/* The iterator is ranged */
+#define NPY_ITFLAG_RANGE 0x0040
+/* The iterator is buffered */
+#define NPY_ITFLAG_BUFFER 0x0080
+/* The iterator should grow the buffered inner loop when possible */
+#define NPY_ITFLAG_GROWINNER 0x0100
+/* There is just one iteration, can specialize iternext for that */
+#define NPY_ITFLAG_ONEITERATION 0x0200
+/* Delay buffer allocation until first Reset* call */
+#define NPY_ITFLAG_DELAYBUF 0x0400
+/* Iteration needs API access during iternext */
+#define NPY_ITFLAG_NEEDSAPI 0x0800
+/* Iteration includes one or more operands being reduced */
+#define NPY_ITFLAG_REDUCE 0x1000
+/* Reduce iteration doesn't need to recalculate reduce loops next time */
+#define NPY_ITFLAG_REUSE_REDUCE_LOOPS 0x2000
+
+/* Internal iterator per-operand iterator flags */
+
+/* The operand will be written to */
+#define NPY_OP_ITFLAG_WRITE 0x01
+/* The operand will be read from */
+#define NPY_OP_ITFLAG_READ 0x02
+/* The operand needs type conversion/byte swapping/alignment */
+#define NPY_OP_ITFLAG_CAST 0x04
+/* The operand never needs buffering */
+#define NPY_OP_ITFLAG_BUFNEVER 0x08
+/* The operand is aligned */
+#define NPY_OP_ITFLAG_ALIGNED 0x10
+/* The operand is being reduced */
+#define NPY_OP_ITFLAG_REDUCE 0x20
+
+/*
+ * The data layout of the iterator is fully specified by
+ * a triple (itflags, ndim, niter). These three variables
+ * are expected to exist in all functions calling these macros,
+ * either as true variables initialized to the correct values
+ * from the iterator, or as constants in the case of specialized
+ * functions such as the various iternext functions.
+ */
+
+struct NpyIter_InternalOnly {
+ /* Initial fixed position data */
+ npy_uint32 itflags;
+ npy_uint16 ndim, niter;
+ npy_intp itersize, iterstart, iterend;
+ /* iterindex is only used if RANGED or BUFFERED is set */
+ npy_intp iterindex;
+ /* The rest is variable */
+ char iter_flexdata;
+};
+
+typedef struct NpyIter_AD NpyIter_AxisData;
+typedef struct NpyIter_BD NpyIter_BufferData;
+
+/* Byte sizes of the iterator members */
+#define NIT_PERM_SIZEOF(itflags, ndim, niter) \
+ NPY_INTP_ALIGNED(NPY_MAXDIMS)
+#define NIT_DTYPES_SIZEOF(itflags, ndim, niter) \
+ ((NPY_SIZEOF_INTP)*(niter))
+#define NIT_RESETDATAPTR_SIZEOF(itflags, ndim, niter) \
+ ((NPY_SIZEOF_INTP)*(niter+1))
+#define NIT_BASEOFFSETS_SIZEOF(itflags, ndim, niter) \
+ ((NPY_SIZEOF_INTP)*(niter+1))
+#define NIT_OPERANDS_SIZEOF(itflags, ndim, niter) \
+ ((NPY_SIZEOF_INTP)*(niter))
+#define NIT_OPITFLAGS_SIZEOF(itflags, ndim, niter) \
+ (NPY_INTP_ALIGNED(niter))
+#define NIT_BUFFERDATA_SIZEOF(itflags, ndim, niter) \
+ ((itflags&NPY_ITFLAG_BUFFER) ? ((NPY_SIZEOF_INTP)*(6 + 9*niter)) : 0)
+
+/* Byte offsets of the iterator members starting from iter->iter_flexdata */
+#define NIT_PERM_OFFSET() \
+ (0)
+#define NIT_DTYPES_OFFSET(itflags, ndim, niter) \
+ (NIT_PERM_OFFSET() + \
+ NIT_PERM_SIZEOF(itflags, ndim, niter))
+#define NIT_RESETDATAPTR_OFFSET(itflags, ndim, niter) \
+ (NIT_DTYPES_OFFSET(itflags, ndim, niter) + \
+ NIT_DTYPES_SIZEOF(itflags, ndim, niter))
+#define NIT_BASEOFFSETS_OFFSET(itflags, ndim, niter) \
+ (NIT_RESETDATAPTR_OFFSET(itflags, ndim, niter) + \
+ NIT_RESETDATAPTR_SIZEOF(itflags, ndim, niter))
+#define NIT_OPERANDS_OFFSET(itflags, ndim, niter) \
+ (NIT_BASEOFFSETS_OFFSET(itflags, ndim, niter) + \
+ NIT_BASEOFFSETS_SIZEOF(itflags, ndim, niter))
+#define NIT_OPITFLAGS_OFFSET(itflags, ndim, niter) \
+ (NIT_OPERANDS_OFFSET(itflags, ndim, niter) + \
+ NIT_OPERANDS_SIZEOF(itflags, ndim, niter))
+#define NIT_BUFFERDATA_OFFSET(itflags, ndim, niter) \
+ (NIT_OPITFLAGS_OFFSET(itflags, ndim, niter) + \
+ NIT_OPITFLAGS_SIZEOF(itflags, ndim, niter))
+#define NIT_AXISDATA_OFFSET(itflags, ndim, niter) \
+ (NIT_BUFFERDATA_OFFSET(itflags, ndim, niter) + \
+ NIT_BUFFERDATA_SIZEOF(itflags, ndim, niter))
+
+/* Internal-only ITERATOR DATA MEMBER ACCESS */
+#define NIT_ITFLAGS(iter) \
+ ((iter)->itflags)
+#define NIT_NDIM(iter) \
+ ((iter)->ndim)
+#define NIT_NITER(iter) \
+ ((iter)->niter)
+#define NIT_ITERSIZE(iter) \
+ (iter->itersize)
+#define NIT_ITERSTART(iter) \
+ (iter->iterstart)
+#define NIT_ITEREND(iter) \
+ (iter->iterend)
+#define NIT_ITERINDEX(iter) \
+ (iter->iterindex)
+#define NIT_PERM(iter) ((char*)( \
+ &(iter)->iter_flexdata + NIT_PERM_OFFSET()))
+#define NIT_DTYPES(iter) ((PyArray_Descr **)( \
+ &(iter)->iter_flexdata + NIT_DTYPES_OFFSET(itflags, ndim, niter)))
+#define NIT_RESETDATAPTR(iter) ((char **)( \
+ &(iter)->iter_flexdata + NIT_RESETDATAPTR_OFFSET(itflags, ndim, niter)))
+#define NIT_BASEOFFSETS(iter) ((npy_intp *)( \
+ &(iter)->iter_flexdata + NIT_BASEOFFSETS_OFFSET(itflags, ndim, niter)))
+#define NIT_OPERANDS(iter) ((PyArrayObject **)( \
+ &(iter)->iter_flexdata + NIT_OPERANDS_OFFSET(itflags, ndim, niter)))
+#define NIT_OPITFLAGS(iter) ( \
+ &(iter)->iter_flexdata + NIT_OPITFLAGS_OFFSET(itflags, ndim, niter))
+#define NIT_BUFFERDATA(iter) ((NpyIter_BufferData *)( \
+ &(iter)->iter_flexdata + NIT_BUFFERDATA_OFFSET(itflags, ndim, niter)))
+#define NIT_AXISDATA(iter) ((NpyIter_AxisData *)( \
+ &(iter)->iter_flexdata + NIT_AXISDATA_OFFSET(itflags, ndim, niter)))
+
+/* Internal-only BUFFERDATA MEMBER ACCESS */
+struct NpyIter_BD {
+ npy_intp buffersize, size, bufiterend,
+ reduce_pos, reduce_outersize, reduce_outerdim;
+ npy_intp bd_flexdata;
+};
+#define NBF_BUFFERSIZE(bufferdata) ((bufferdata)->buffersize)
+#define NBF_SIZE(bufferdata) ((bufferdata)->size)
+#define NBF_BUFITEREND(bufferdata) ((bufferdata)->bufiterend)
+#define NBF_REDUCE_POS(bufferdata) ((bufferdata)->reduce_pos)
+#define NBF_REDUCE_OUTERSIZE(bufferdata) ((bufferdata)->reduce_outersize)
+#define NBF_REDUCE_OUTERDIM(bufferdata) ((bufferdata)->reduce_outerdim)
+#define NBF_STRIDES(bufferdata) ( \
+ &(bufferdata)->bd_flexdata + 0)
+#define NBF_PTRS(bufferdata) ((char **) \
+ (&(bufferdata)->bd_flexdata + 1*(niter)))
+#define NBF_REDUCE_OUTERSTRIDES(bufferdata) ( \
+ (&(bufferdata)->bd_flexdata + 2*(niter)))
+#define NBF_REDUCE_OUTERPTRS(bufferdata) ((char **) \
+ (&(bufferdata)->bd_flexdata + 3*(niter)))
+#define NBF_READTRANSFERFN(bufferdata) ((PyArray_StridedTransferFn **) \
+ (&(bufferdata)->bd_flexdata + 4*(niter)))
+#define NBF_READTRANSFERDATA(bufferdata) ((void **) \
+ (&(bufferdata)->bd_flexdata + 5*(niter)))
+#define NBF_WRITETRANSFERFN(bufferdata) ((PyArray_StridedTransferFn **) \
+ (&(bufferdata)->bd_flexdata + 6*(niter)))
+#define NBF_WRITETRANSFERDATA(bufferdata) ((void **) \
+ (&(bufferdata)->bd_flexdata + 7*(niter)))
+#define NBF_BUFFERS(bufferdata) ((char **) \
+ (&(bufferdata)->bd_flexdata + 8*(niter)))
+
+/* Internal-only AXISDATA MEMBER ACCESS. */
+struct NpyIter_AD {
+ npy_intp shape, coord;
+ npy_intp ad_flexdata;
+};
+#define NAD_SHAPE(axisdata) ((axisdata)->shape)
+#define NAD_COORD(axisdata) ((axisdata)->coord)
+#define NAD_STRIDES(axisdata) ( \
+ &(axisdata)->ad_flexdata + 0)
+#define NAD_PTRS(axisdata) ((char **) \
+ &(axisdata)->ad_flexdata + 1*(niter+1))
+
+#define NAD_NSTRIDES() \
+ ((niter) + ((itflags&NPY_ITFLAG_HASINDEX) ? 1 : 0))
+
+/* Size of one AXISDATA struct within the iterator */
+#define NIT_AXISDATA_SIZEOF(itflags, ndim, niter) (( \
+ /* intp shape */ \
+ 1 + \
+ /* intp coord */ \
+ 1 + \
+ /* intp stride[niter+1] AND char* ptr[niter+1] */ \
+ 2*((niter)+1) \
+ )*NPY_SIZEOF_INTP )
+
+/*
+ * Macro to advance an AXISDATA pointer by a specified count.
+ * Requires that sizeof_axisdata be previously initialized
+ * to NIT_AXISDATA_SIZEOF(itflags, ndim, niter).
+ */
+#define NIT_INDEX_AXISDATA(axisdata, index) ((NpyIter_AxisData *) \
+ (((char *)(axisdata)) + (index)*sizeof_axisdata))
+#define NIT_ADVANCE_AXISDATA(axisdata, count) \
+ axisdata = NIT_INDEX_AXISDATA(axisdata, count)
+
+/* Size of the whole iterator */
+#define NIT_SIZEOF_ITERATOR(itflags, ndim, niter) ( \
+ sizeof(struct NpyIter_InternalOnly) + \
+ NIT_AXISDATA_OFFSET(itflags, ndim, niter) + \
+ NIT_AXISDATA_SIZEOF(itflags, ndim, niter)*(ndim))
+
+/* Internal helper functions */
+static int
+npyiter_check_global_flags(npy_uint32 flags, npy_uint32* itflags);
+static int
+npyiter_check_op_axes(int niter, int oa_ndim, int **op_axes);
+static int
+npyiter_calculate_ndim(int niter, PyArrayObject **op_in,
+ int oa_ndim);
+static int
+npyiter_check_per_op_flags(npy_uint32 flags, char *op_itflags);
+static int
+npyiter_prepare_one_operand(PyArrayObject **op,
+ char **op_dataptr,
+ PyArray_Descr *op_request_dtype,
+ PyArray_Descr** op_dtype,
+ npy_uint32 flags,
+ npy_uint32 op_flags, char *op_itflags);
+static int
+npyiter_prepare_operands(int niter, PyArrayObject **op_in,
+ PyArrayObject **op,
+ char **op_dataptr,
+ PyArray_Descr **op_request_dtypes,
+ PyArray_Descr **op_dtype,
+ npy_uint32 flags,
+ npy_uint32 *op_flags, char *op_itflags);
+static int
+npyiter_check_casting(int niter, PyArrayObject **op,
+ PyArray_Descr **op_dtype,
+ NPY_CASTING casting,
+ char *op_itflags);
+static int
+npyiter_fill_axisdata(NpyIter *iter, npy_uint32 flags, char *op_itflags,
+ char **op_dataptr,
+ npy_uint32 *op_flags, int **op_axes,
+ int output_scalars);
+static void
+npyiter_replace_axisdata(NpyIter *iter, int iiter,
+ PyArrayObject *op,
+ int op_ndim, char *op_dataptr,
+ int *op_axes);
+static void
+npyiter_compute_index_strides(NpyIter *iter, npy_uint32 flags);
+static void
+npyiter_apply_forced_iteration_order(NpyIter *iter, NPY_ORDER order);
+
+static void
+npyiter_flip_negative_strides(NpyIter *iter);
+static void
+npyiter_reverse_axis_ordering(NpyIter *iter);
+static void
+npyiter_find_best_axis_ordering(NpyIter *iter);
+static void
+npyiter_coalesce_axes(NpyIter *iter);
+
+static PyArray_Descr *
+npyiter_get_common_dtype(int niter, PyArrayObject **op,
+ char *op_itflags, PyArray_Descr **op_dtype,
+ PyArray_Descr **op_request_dtypes,
+ int only_inputs, int output_scalars);
+
+static PyArrayObject *
+npyiter_new_temp_array(NpyIter *iter, PyTypeObject *subtype,
+ npy_uint32 flags, char *op_itflags,
+ int op_ndim, npy_intp *shape,
+ PyArray_Descr *op_dtype, int *op_axes);
+static int
+npyiter_allocate_arrays(NpyIter *iter,
+ npy_uint32 flags,
+ PyArray_Descr **op_dtype, PyTypeObject *subtype,
+ npy_uint32 *op_flags, char *op_itflags,
+ int **op_axes, int output_scalars);
+static void
+npyiter_get_priority_subtype(int niter, PyArrayObject **op,
+ char *op_itflags,
+ double *subtype_priority, PyTypeObject **subtype);
+
+static int
+npyiter_allocate_transfer_functions(NpyIter *iter);
+static int
+npyiter_allocate_buffers(NpyIter *iter, char **errmsg);
+static void npyiter_goto_iterindex(NpyIter *iter, npy_intp iterindex);
+static void
+npyiter_copy_from_buffers(NpyIter *iter);
+static void
+npyiter_copy_to_buffers(NpyIter *iter, char **prev_dataptrs);
+static npy_intp
+npyiter_checkreducesize(NpyIter *iter, npy_intp count,
+ npy_intp *reduce_innersize,
+ npy_intp *reduce_outerdim);
+
+/*NUMPY_API
+ * Allocate a new iterator for multiple array objects
+ */
+NPY_NO_EXPORT NpyIter *
+NpyIter_MultiNew(int niter, PyArrayObject **op_in, npy_uint32 flags,
+ NPY_ORDER order, NPY_CASTING casting,
+ npy_uint32 *op_flags,
+ PyArray_Descr **op_request_dtypes,
+ int oa_ndim, int **op_axes, npy_intp buffersize)
+{
+ npy_uint32 itflags = NPY_ITFLAG_IDENTPERM;
+ int idim, ndim;
+ int iiter;
+
+ /* The iterator being constructed */
+ NpyIter *iter;
+
+ /* Per-operand values */
+ PyArrayObject **op;
+ PyArray_Descr **op_dtype;
+ char *op_itflags;
+ char **op_dataptr;
+
+ char *perm;
+ NpyIter_BufferData *bufferdata = NULL;
+ int any_allocate = 0, any_missing_dtypes = 0,
+ output_scalars = 0, need_subtype = 0;
+
+ /* The subtype for automatically allocated outputs */
+ double subtype_priority = NPY_PRIORITY;
+ PyTypeObject *subtype = &PyArray_Type;
+
+#if NPY_IT_CONSTRUCTION_TIMING
+ npy_intp c_temp,
+ c_start,
+ c_check_op_axes,
+ c_check_global_flags,
+ c_calculate_ndim,
+ c_malloc,
+ c_prepare_operands,
+ c_fill_axisdata,
+ c_compute_index_strides,
+ c_apply_forced_iteration_order,
+ c_find_best_axis_ordering,
+ c_get_priority_subtype,
+ c_find_output_common_dtype,
+ c_check_casting,
+ c_allocate_arrays,
+ c_coalesce_axes,
+ c_prepare_buffers;
+#endif
+
+ NPY_IT_TIME_POINT(c_start);
+
+ if (niter > NPY_MAXARGS) {
+ PyErr_Format(PyExc_ValueError,
+ "Cannot construct an iterator with more than %d operands "
+ "(%d were requested)", (int)NPY_MAXARGS, (int)niter);
+ return NULL;
+ }
+
+ /* Error check 'oa_ndim' and 'op_axes', which must be used together */
+ if (!npyiter_check_op_axes(niter, oa_ndim, op_axes)) {
+ return NULL;
+ }
+
+ NPY_IT_TIME_POINT(c_check_op_axes);
+
+ /* Check the global iterator flags */
+ if (!npyiter_check_global_flags(flags, &itflags)) {
+ return NULL;
+ }
+
+ NPY_IT_TIME_POINT(c_check_global_flags);
+
+ /* Calculate how many dimensions the iterator should have */
+ ndim = npyiter_calculate_ndim(niter, op_in, oa_ndim);
+
+ /* If 'ndim' is zero, any outputs should be scalars */
+ if (ndim == 0) {
+ output_scalars = 1;
+ ndim = 1;
+ }
+
+ NPY_IT_TIME_POINT(c_calculate_ndim);
+
+ /* Allocate memory for the iterator */
+ iter = (NpyIter*)
+ PyArray_malloc(NIT_SIZEOF_ITERATOR(itflags, ndim, niter));
+
+ NPY_IT_TIME_POINT(c_malloc);
+
+ /* Fill in the basic data */
+ NIT_ITFLAGS(iter) = itflags;
+ NIT_NDIM(iter) = ndim;
+ NIT_NITER(iter) = niter;
+ NIT_ITERINDEX(iter) = 0;
+ memset(NIT_BASEOFFSETS(iter), 0, (niter+1)*NPY_SIZEOF_INTP);
+
+ op = NIT_OPERANDS(iter);
+ op_dtype = NIT_DTYPES(iter);
+ op_itflags = NIT_OPITFLAGS(iter);
+ op_dataptr = NIT_RESETDATAPTR(iter);
+
+ /* Prepare all the operands */
+ if (!npyiter_prepare_operands(niter, op_in, op, op_dataptr,
+ op_request_dtypes, op_dtype,
+ flags,
+ op_flags, op_itflags)) {
+ PyArray_free(iter);
+ return NULL;
+ }
+ /* Set resetindex to zero as well (it's just after the resetdataptr) */
+ op_dataptr[niter] = 0;
+
+ NPY_IT_TIME_POINT(c_prepare_operands);
+
+ /*
+ * Initialize buffer data (must set the buffers and transferdata
+ * to NULL before we might deallocate the iterator).
+ */
+ if (itflags&NPY_ITFLAG_BUFFER) {
+ bufferdata = NIT_BUFFERDATA(iter);
+ NBF_SIZE(bufferdata) = 0;
+ memset(NBF_BUFFERS(bufferdata), 0, niter*NPY_SIZEOF_INTP);
+ memset(NBF_READTRANSFERDATA(bufferdata), 0, niter*NPY_SIZEOF_INTP);
+ memset(NBF_WRITETRANSFERDATA(bufferdata), 0, niter*NPY_SIZEOF_INTP);
+ }
+
+ /* Fill in the AXISDATA arrays and set the ITERSIZE field */
+ if (!npyiter_fill_axisdata(iter, flags, op_itflags, op_dataptr,
+ op_flags, op_axes, output_scalars)) {
+ NpyIter_Deallocate(iter);
+ return NULL;
+ }
+
+ NPY_IT_TIME_POINT(c_fill_axisdata);
+
+ if (itflags&NPY_ITFLAG_BUFFER) {
+ /*
+ * If buffering is enabled and no buffersize was given, use a default
+ * chosen to be big enough to get some amortization benefits, but
+ * small enough to be cache-friendly.
+ */
+ if (buffersize <= 0) {
+ buffersize = 1 << 12;
+ }
+ /* No point in a buffer bigger than the iteration size */
+ if (buffersize > NIT_ITERSIZE(iter)) {
+ buffersize = NIT_ITERSIZE(iter);
+ }
+ NBF_BUFFERSIZE(bufferdata) = buffersize;
+ }
+
+ /*
+ * If an index was requested, compute the strides for it.
+ * Note that we must do this before changing the order of the
+ * axes
+ */
+ npyiter_compute_index_strides(iter, flags);
+
+ NPY_IT_TIME_POINT(c_compute_index_strides);
+
+ /* Initialize the perm to the identity */
+ perm = NIT_PERM(iter);
+ for(idim = 0; idim < ndim; ++idim) {
+ perm[idim] = (char)idim;
+ }
+
+ /*
+ * If an iteration order is being forced, apply it.
+ */
+ npyiter_apply_forced_iteration_order(iter, order);
+ itflags = NIT_ITFLAGS(iter);
+
+ NPY_IT_TIME_POINT(c_apply_forced_iteration_order);
+
+ /* Set some flags for allocated outputs */
+ for (iiter = 0; iiter < niter; ++iiter) {
+ if (op[iiter] == NULL) {
+ /* Flag this so later we can avoid flipping axes */
+ any_allocate = 1;
+ /* If a subtype may be used, indicate so */
+ if (!(op_flags[iiter]&NPY_ITER_NO_SUBTYPE)) {
+ need_subtype = 1;
+ }
+ /*
+ * If the data type wasn't provided, will need to
+ * calculate it.
+ */
+ if (op_dtype[iiter] == NULL) {
+ any_missing_dtypes = 1;
+ }
+ }
+ }
+
+ /*
+ * If the ordering was not forced, reorder the axes
+ * and flip negative strides to find the best one.
+ */
+ if (!(itflags&NPY_ITFLAG_FORCEDORDER)) {
+ if (ndim > 1) {
+ npyiter_find_best_axis_ordering(iter);
+ }
+ /*
+ * If there's an output being allocated, we must not negate
+ * any strides.
+ */
+ if (!any_allocate && !(flags&NPY_ITER_DONT_NEGATE_STRIDES)) {
+ npyiter_flip_negative_strides(iter);
+ }
+ itflags = NIT_ITFLAGS(iter);
+ }
+
+ NPY_IT_TIME_POINT(c_find_best_axis_ordering);
+
+ if (need_subtype) {
+ npyiter_get_priority_subtype(niter, op, op_itflags,
+ &subtype_priority, &subtype);
+ }
+
+ NPY_IT_TIME_POINT(c_get_priority_subtype);
+
+ /*
+ * If an automatically allocated output didn't have a specified
+ * dtype, we need to figure it out now, before allocating the outputs.
+ */
+ if (any_missing_dtypes || (flags&NPY_ITER_COMMON_DTYPE)) {
+ PyArray_Descr *dtype;
+ int only_inputs = !(flags&NPY_ITER_COMMON_DTYPE);
+
+ op = NIT_OPERANDS(iter);
+ op_dtype = NIT_DTYPES(iter);
+
+ dtype = npyiter_get_common_dtype(niter, op,
+ op_itflags, op_dtype,
+ op_request_dtypes,
+ only_inputs,
+ output_scalars);
+ if (dtype == NULL) {
+ NpyIter_Deallocate(iter);
+ return NULL;
+ }
+ if (flags&NPY_ITER_COMMON_DTYPE) {
+ NPY_IT_DBG_PRINT("Iterator: Replacing all data types\n");
+ /* Replace all the data types */
+ for (iiter = 0; iiter < niter; ++iiter) {
+ if (op_dtype[iiter] != dtype) {
+ Py_XDECREF(op_dtype[iiter]);
+ Py_INCREF(dtype);
+ op_dtype[iiter] = dtype;
+ }
+ }
+ }
+ else {
+ NPY_IT_DBG_PRINT("Iterator: Setting unset output data types\n");
+ /* Replace the NULL data types */
+ for (iiter = 0; iiter < niter; ++iiter) {
+ if (op_dtype[iiter] == NULL) {
+ Py_INCREF(dtype);
+ op_dtype[iiter] = dtype;
+ }
+ }
+ }
+ Py_DECREF(dtype);
+ }
+
+ NPY_IT_TIME_POINT(c_find_output_common_dtype);
+
+ /*
+ * All of the data types have been settled, so it's time
+ * to check that data type conversions are following the
+ * casting rules.
+ */
+ if (!npyiter_check_casting(niter, op, op_dtype, casting, op_itflags)) {
+ NpyIter_Deallocate(iter);
+ return NULL;
+ }
+
+ NPY_IT_TIME_POINT(c_check_casting);
+
+ /*
+ * At this point, the iteration order has been finalized. so
+ * any allocation of ops that were NULL, or any temporary
+ * copying due to casting/byte order/alignment can be
+ * done now using a memory layout matching the iterator.
+ */
+ if (!npyiter_allocate_arrays(iter, flags, op_dtype, subtype, op_flags,
+ op_itflags, op_axes, output_scalars)) {
+ NpyIter_Deallocate(iter);
+ return NULL;
+ }
+
+ NPY_IT_TIME_POINT(c_allocate_arrays);
+
+ /*
+ * Finally, if coords weren't requested,
+ * it may be possible to coalesce some axes together.
+ */
+ if (ndim > 1 && !(itflags&NPY_ITFLAG_HASCOORDS)) {
+ npyiter_coalesce_axes(iter);
+ /*
+ * The operation may have changed the layout, so we have to
+ * get the internal pointers again.
+ */
+ itflags = NIT_ITFLAGS(iter);
+ ndim = NIT_NDIM(iter);
+ op = NIT_OPERANDS(iter);
+ op_dtype = NIT_DTYPES(iter);
+ op_itflags = NIT_OPITFLAGS(iter);
+ op_dataptr = NIT_RESETDATAPTR(iter);
+ }
+
+ NPY_IT_TIME_POINT(c_coalesce_axes);
+
+ /*
+ * Now that the axes are finished, check whether we can apply
+ * the single iteration optimization to the iternext function.
+ */
+ if (!(itflags&NPY_ITFLAG_BUFFER)) {
+ NpyIter_AxisData *axisdata = NIT_AXISDATA(iter);
+ if (itflags&NPY_ITFLAG_NOINNER) {
+ if (NIT_ITERSIZE(iter) == NAD_SHAPE(axisdata)) {
+ NIT_ITFLAGS(iter) |= NPY_ITFLAG_ONEITERATION;
+ }
+ }
+ else if (NIT_ITERSIZE(iter) == 1) {
+ NIT_ITFLAGS(iter) |= NPY_ITFLAG_ONEITERATION;
+ }
+ }
+
+ /*
+ * If REFS_OK was specified, check whether there are any
+ * reference arrays and flag it if so.
+ */
+ if (flags&NPY_ITER_REFS_OK) {
+ for (iiter = 0; iiter < niter; ++iiter) {
+ PyArray_Descr *rdt = op_dtype[iiter];
+ if ((rdt->flags&(NPY_ITEM_REFCOUNT|
+ NPY_ITEM_IS_POINTER|
+ NPY_NEEDS_PYAPI)) != 0) {
+ /* Iteration needs API access */
+ NIT_ITFLAGS(iter) |= NPY_ITFLAG_NEEDSAPI;
+ }
+ }
+ }
+
+ /* If buffering is set without delayed allocation */
+ if (itflags&NPY_ITFLAG_BUFFER) {
+ if (!npyiter_allocate_transfer_functions(iter)) {
+ NpyIter_Deallocate(iter);
+ return NULL;
+ }
+ if (itflags&NPY_ITFLAG_DELAYBUF) {
+ bufferdata = NIT_BUFFERDATA(iter);
+ /* Make the data pointers NULL */
+ memset(NBF_PTRS(bufferdata), 0, niter*NPY_SIZEOF_INTP);
+ }
+ else {
+ /* Allocate the buffers */
+ if (!npyiter_allocate_buffers(iter, NULL)) {
+ NpyIter_Deallocate(iter);
+ return NULL;
+ }
+
+ /* Prepare the next buffers and set iterend/size */
+ npyiter_copy_to_buffers(iter, NULL);
+ }
+ }
+
+ NPY_IT_TIME_POINT(c_prepare_buffers);
+
+#if NPY_IT_CONSTRUCTION_TIMING
+ printf("\nIterator construction timing:\n");
+ NPY_IT_PRINT_TIME_START(c_start);
+ NPY_IT_PRINT_TIME_VAR(c_check_op_axes);
+ NPY_IT_PRINT_TIME_VAR(c_check_global_flags);
+ NPY_IT_PRINT_TIME_VAR(c_calculate_ndim);
+ NPY_IT_PRINT_TIME_VAR(c_malloc);
+ NPY_IT_PRINT_TIME_VAR(c_prepare_operands);
+ NPY_IT_PRINT_TIME_VAR(c_fill_axisdata);
+ NPY_IT_PRINT_TIME_VAR(c_compute_index_strides);
+ NPY_IT_PRINT_TIME_VAR(c_apply_forced_iteration_order);
+ NPY_IT_PRINT_TIME_VAR(c_find_best_axis_ordering);
+ NPY_IT_PRINT_TIME_VAR(c_get_priority_subtype);
+ NPY_IT_PRINT_TIME_VAR(c_find_output_common_dtype);
+ NPY_IT_PRINT_TIME_VAR(c_check_casting);
+ NPY_IT_PRINT_TIME_VAR(c_allocate_arrays);
+ NPY_IT_PRINT_TIME_VAR(c_coalesce_axes);
+ NPY_IT_PRINT_TIME_VAR(c_prepare_buffers);
+ printf("\n");
+#endif
+
+ return iter;
+}
+
+/*NUMPY_API
+ * Allocate a new iterator for one array object
+ */
+NPY_NO_EXPORT NpyIter *
+NpyIter_New(PyArrayObject *op, npy_uint32 flags,
+ NPY_ORDER order, NPY_CASTING casting,
+ PyArray_Descr* dtype,
+ int a_ndim, int *axes, npy_intp buffersize)
+{
+ /* Split the flags into separate global and op flags */
+ npy_uint32 op_flags = flags&NPY_ITER_PER_OP_FLAGS;
+ flags &= NPY_ITER_GLOBAL_FLAGS;
+
+ if (a_ndim > 0) {
+ return NpyIter_MultiNew(1, &op, flags, order, casting,
+ &op_flags, &dtype,
+ a_ndim, &axes, buffersize);
+ }
+ else {
+ return NpyIter_MultiNew(1, &op, flags, order, casting,
+ &op_flags, &dtype,
+ 0, NULL, buffersize);
+ }
+}
+
+/*NUMPY_API
+ * Makes a copy of the iterator
+ */
+NPY_NO_EXPORT NpyIter *
+NpyIter_Copy(NpyIter *iter)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int ndim = NIT_NDIM(iter);
+ int iiter, niter = NIT_NITER(iter);
+ int out_of_memory = 0;
+
+ npy_intp size;
+ NpyIter *newiter;
+ PyArrayObject **objects;
+ PyArray_Descr **dtypes;
+
+ /* Allocate memory for the new iterator */
+ size = NIT_SIZEOF_ITERATOR(itflags, ndim, niter);
+ newiter = (NpyIter*)PyArray_malloc(size);
+
+ /* Copy the raw values to the new iterator */
+ memcpy(newiter, iter, size);
+
+ /* Take ownership of references to the operands and dtypes */
+ objects = NIT_OPERANDS(newiter);
+ dtypes = NIT_DTYPES(newiter);
+ for (iiter = 0; iiter < niter; ++iiter) {
+ Py_INCREF(objects[iiter]);
+ Py_INCREF(dtypes[iiter]);
+ }
+
+ /* Allocate buffers and make copies of the transfer data if necessary */
+ if (itflags&NPY_ITFLAG_BUFFER) {
+ NpyIter_BufferData *bufferdata;
+ npy_intp buffersize, itemsize;
+ char **buffers;
+ void **readtransferdata, **writetransferdata;
+
+ bufferdata = NIT_BUFFERDATA(newiter);
+ buffers = NBF_BUFFERS(bufferdata);
+ readtransferdata = NBF_READTRANSFERDATA(bufferdata);
+ writetransferdata = NBF_WRITETRANSFERDATA(bufferdata);
+ buffersize = NBF_BUFFERSIZE(bufferdata);
+
+ for (iiter = 0; iiter < niter; ++iiter) {
+ if (buffers[iiter] != NULL) {
+ if (out_of_memory) {
+ buffers[iiter] = NULL;
+ }
+ else {
+ itemsize = dtypes[iiter]->elsize;
+ buffers[iiter] = PyArray_malloc(itemsize*buffersize);
+ if (buffers[iiter] == NULL) {
+ out_of_memory = 1;
+ }
+ }
+ }
+
+ if (readtransferdata[iiter] != NULL) {
+ if (out_of_memory) {
+ readtransferdata[iiter] = NULL;
+ }
+ else {
+ readtransferdata[iiter] =
+ PyArray_CopyStridedTransferData(readtransferdata[iiter]);
+ if (readtransferdata[iiter] == NULL) {
+ out_of_memory = 1;
+ }
+ }
+ }
+
+ if (writetransferdata[iiter] != NULL) {
+ if (out_of_memory) {
+ writetransferdata[iiter] = NULL;
+ }
+ else {
+ writetransferdata[iiter] =
+ PyArray_CopyStridedTransferData(writetransferdata[iiter]);
+ if (writetransferdata[iiter] == NULL) {
+ out_of_memory = 1;
+ }
+ }
+ }
+ }
+
+ /* Initialize the buffers to the current iterindex */
+ if (!out_of_memory && NBF_SIZE(bufferdata) > 0) {
+ npyiter_goto_iterindex(newiter, NIT_ITERINDEX(newiter));
+
+ /* Prepare the next buffers and set iterend/size */
+ npyiter_copy_to_buffers(newiter, NULL);
+ }
+ }
+
+ if (out_of_memory) {
+ NpyIter_Deallocate(newiter);
+ PyErr_NoMemory();
+ return NULL;
+ }
+
+ return newiter;
+}
+
+/*NUMPY_API
+ * Deallocate an iterator
+ */
+NPY_NO_EXPORT int
+NpyIter_Deallocate(NpyIter *iter)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ /*int ndim = NIT_NDIM(iter);*/
+ int iiter, niter = NIT_NITER(iter);
+
+ PyArray_Descr **dtype = NIT_DTYPES(iter);
+ PyArrayObject **object = NIT_OPERANDS(iter);
+
+ /* Deallocate any buffers and buffering data */
+ if (itflags&NPY_ITFLAG_BUFFER) {
+ NpyIter_BufferData *bufferdata = NIT_BUFFERDATA(iter);
+ char **buffers;
+ void **transferdata;
+
+ /* buffers */
+ buffers = NBF_BUFFERS(bufferdata);
+ for(iiter = 0; iiter < niter; ++iiter, ++buffers) {
+ if (*buffers) {
+ PyArray_free(*buffers);
+ }
+ }
+ /* read bufferdata */
+ transferdata = NBF_READTRANSFERDATA(bufferdata);
+ for(iiter = 0; iiter < niter; ++iiter, ++transferdata) {
+ if (*transferdata) {
+ PyArray_FreeStridedTransferData(*transferdata);
+ }
+ }
+ /* write bufferdata */
+ transferdata = NBF_WRITETRANSFERDATA(bufferdata);
+ for(iiter = 0; iiter < niter; ++iiter, ++transferdata) {
+ if (*transferdata) {
+ PyArray_FreeStridedTransferData(*transferdata);
+ }
+ }
+ }
+
+ /* Deallocate all the dtypes and objects that were iterated */
+ for(iiter = 0; iiter < niter; ++iiter, ++dtype, ++object) {
+ Py_XDECREF(*dtype);
+ Py_XDECREF(*object);
+ }
+
+ /* Deallocate the iterator memory */
+ PyArray_free(iter);
+
+ return NPY_SUCCEED;
+}
+
+/*NUMPY_API
+ * Removes an axis from iteration. This requires that NPY_ITER_COORDS
+ * was set for iterator creation, and does not work if buffering is
+ * enabled. This function also resets the iterator to its initial state.
+ *
+ * Returns NPY_SUCCEED or NPY_FAIL.
+ */
+NPY_NO_EXPORT int
+NpyIter_RemoveAxis(NpyIter *iter, int axis)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int idim, ndim = NIT_NDIM(iter);
+ int iiter, niter = NIT_NITER(iter);
+
+ int xdim = 0;
+ char *perm = NIT_PERM(iter);
+ NpyIter_AxisData *axisdata_del = NIT_AXISDATA(iter), *axisdata;
+ npy_intp sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
+
+ npy_intp *baseoffsets = NIT_BASEOFFSETS(iter);
+ char **resetdataptr = NIT_RESETDATAPTR(iter);
+
+ if (!(itflags&NPY_ITFLAG_HASCOORDS)) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Iterator RemoveAxis may only be called "
+ "if coordinates are being tracked");
+ return NPY_FAIL;
+ }
+ else if (itflags&NPY_ITFLAG_HASINDEX) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Iterator RemoveAxis may not be called on "
+ "an index is being tracked");
+ return NPY_FAIL;
+ }
+ else if (itflags&NPY_ITFLAG_BUFFER) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Iterator RemoveAxis may not be called on "
+ "a buffered iterator");
+ return NPY_FAIL;
+ }
+ else if (axis < 0 || axis >= ndim) {
+ PyErr_SetString(PyExc_ValueError,
+ "axis out of bounds in iterator RemoveAxis");
+ return NPY_FAIL;
+ }
+
+ /* Reverse axis, since the iterator treats them that way */
+ axis = ndim-1-axis;
+
+ /* First find the axis in question */
+ for (idim = 0; idim < ndim; ++idim) {
+ /* If this is it, and it's iterated forward, done */
+ if (perm[idim] == axis) {
+ xdim = idim;
+ break;
+ }
+ /* If this is it, but it's iterated backward, must reverse the axis */
+ else if (-1-perm[idim] == axis) {
+ npy_intp *strides = NAD_STRIDES(axisdata_del);
+ npy_intp shape = NAD_SHAPE(axisdata_del), offset;
+
+ xdim = idim;
+
+ /*
+ * Adjust baseoffsets and resetbaseptr back to the start of
+ * this axis.
+ */
+ for (iiter = 0; iiter < niter; ++iiter) {
+ offset = (shape-1)*strides[iiter];
+ baseoffsets[iiter] += offset;
+ resetdataptr[iiter] += offset;
+ }
+ break;
+ }
+
+ NIT_ADVANCE_AXISDATA(axisdata_del, 1);
+ }
+
+ if (idim == ndim) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "internal error in iterator perm");
+ return NPY_FAIL;
+ }
+
+ if (NAD_SHAPE(axisdata_del) == 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "cannot remove a zero-sized axis from an iterator");
+ return NPY_FAIL;
+ }
+
+ /* Adjust the permutation */
+ for (idim = 0; idim < ndim-1; ++idim) {
+ char p = (idim < xdim) ? perm[idim] : perm[idim+1];
+ if (p >= 0) {
+ if (p > axis) {
+ --p;
+ }
+ }
+ else if (p <= 0) {
+ if (p < -1-axis) {
+ ++p;
+ }
+ }
+ perm[idim] = p;
+ }
+
+ /* Adjust the iteration size */
+ NIT_ITERSIZE(iter) /= NAD_SHAPE(axisdata_del);
+
+ /* Shift all the axisdata structures by one */
+ axisdata = NIT_INDEX_AXISDATA(axisdata_del, 1);
+ memmove(axisdata_del, axisdata, (ndim-1-xdim)*sizeof_axisdata);
+
+ /* If there is more than one dimension, shrink the iterator */
+ if (ndim > 1) {
+ NIT_NDIM(iter) = ndim-1;
+ }
+ /* Otherwise convert it to a singleton dimension */
+ else {
+ npy_intp *strides = NAD_STRIDES(axisdata_del);
+ NAD_SHAPE(axisdata_del) = 1;
+ for (iiter = 0; iiter < niter; ++iiter) {
+ strides[iiter] = 0;
+ }
+ NIT_ITFLAGS(iter) |= NPY_ITFLAG_ONEITERATION;
+ }
+
+ return NpyIter_Reset(iter, NULL);
+}
+
+/*NUMPY_API
+ * Removes coords support from an iterator.
+ *
+ * Returns NPY_SUCCEED or NPY_FAIL.
+ */
+NPY_NO_EXPORT int
+NpyIter_RemoveCoords(NpyIter *iter)
+{
+ npy_uint32 itflags;
+
+ /* Make sure the iterator is reset */
+ if (NpyIter_Reset(iter, NULL) != NPY_SUCCEED) {
+ return NPY_FAIL;
+ }
+
+ itflags = NIT_ITFLAGS(iter);
+ if (itflags&NPY_ITFLAG_HASCOORDS) {
+ NIT_ITFLAGS(iter) = itflags & ~NPY_ITFLAG_HASCOORDS;
+ npyiter_coalesce_axes(iter);
+ }
+
+ return NPY_SUCCEED;
+}
+
+/*NUMPY_API
+ * Removes the inner loop handling (so HasInnerLoop returns false)
+ */
+NPY_NO_EXPORT int
+NpyIter_RemoveInnerLoop(NpyIter *iter)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ /*int ndim = NIT_NDIM(iter);*/
+ int niter = NIT_NITER(iter);
+
+ /* Check conditions under which this can be done */
+ if (itflags&(NPY_ITFLAG_HASINDEX|NPY_ITFLAG_HASCOORDS)) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator flag NO_INNER_ITERATION cannot be used "
+ "if coords or an index is being tracked");
+ return NPY_FAIL;
+ }
+ if ((itflags&(NPY_ITFLAG_BUFFER|NPY_ITFLAG_RANGE|NPY_ITFLAG_NOINNER))
+ == (NPY_ITFLAG_RANGE|NPY_ITFLAG_NOINNER)) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator flag NO_INNER_ITERATION cannot be used "
+ "with ranged iteration unless buffering is also enabled");
+ return NPY_FAIL;
+ }
+ /* Set the flag */
+ if (!(itflags&NPY_ITFLAG_NOINNER)) {
+ itflags |= NPY_ITFLAG_NOINNER;
+ NIT_ITFLAGS(iter) = itflags;
+
+ /*
+ * Check whether we can apply the single iteration
+ * optimization to the iternext function.
+ */
+ if (!(itflags&NPY_ITFLAG_BUFFER)) {
+ NpyIter_AxisData *axisdata = NIT_AXISDATA(iter);
+ if (NIT_ITERSIZE(iter) == NAD_SHAPE(axisdata)) {
+ NIT_ITFLAGS(iter) |= NPY_ITFLAG_ONEITERATION;
+ }
+ }
+ }
+
+ /* Reset the iterator */
+ return NpyIter_Reset(iter, NULL);
+}
+
+/*NUMPY_API
+ * Resets the iterator to its initial state
+ *
+ * If errmsg is non-NULL, it should point to a variable which will
+ * receive the error message, and no Python exception will be set.
+ * This is so that the function can be called from code not holding
+ * the GIL.
+ */
+NPY_NO_EXPORT int
+NpyIter_Reset(NpyIter *iter, char **errmsg)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ /*int ndim = NIT_NDIM(iter);*/
+ int niter = NIT_NITER(iter);
+
+ if (itflags&NPY_ITFLAG_BUFFER) {
+ NpyIter_BufferData *bufferdata;
+
+ /* If buffer allocation was delayed, do it now */
+ if (itflags&NPY_ITFLAG_DELAYBUF) {
+ if (!npyiter_allocate_buffers(iter, errmsg)) {
+ return NPY_FAIL;
+ }
+ NIT_ITFLAGS(iter) &= ~NPY_ITFLAG_DELAYBUF;
+ }
+ else {
+ /*
+ * If the iterindex is already right, no need to
+ * do anything
+ */
+ bufferdata = NIT_BUFFERDATA(iter);
+ if (NIT_ITERINDEX(iter) == NIT_ITERSTART(iter) &&
+ NBF_BUFITEREND(bufferdata) <= NIT_ITEREND(iter) &&
+ NBF_SIZE(bufferdata) > 0) {
+ return NPY_SUCCEED;
+ }
+
+ /* Copy any data from the buffers back to the arrays */
+ npyiter_copy_from_buffers(iter);
+ }
+ }
+
+ npyiter_goto_iterindex(iter, NIT_ITERSTART(iter));
+
+ if (itflags&NPY_ITFLAG_BUFFER) {
+ /* Prepare the next buffers and set iterend/size */
+ npyiter_copy_to_buffers(iter, NULL);
+ }
+
+ return NPY_SUCCEED;
+}
+
+/*NUMPY_API
+ * Resets the iterator to its initial state, with new base data pointers
+ *
+ * If errmsg is non-NULL, it should point to a variable which will
+ * receive the error message, and no Python exception will be set.
+ * This is so that the function can be called from code not holding
+ * the GIL.
+ */
+NPY_NO_EXPORT int
+NpyIter_ResetBasePointers(NpyIter *iter, char **baseptrs, char **errmsg)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ /*int ndim = NIT_NDIM(iter);*/
+ int iiter, niter = NIT_NITER(iter);
+
+ char **resetdataptr = NIT_RESETDATAPTR(iter);
+ npy_intp *baseoffsets = NIT_BASEOFFSETS(iter);
+
+ if (itflags&NPY_ITFLAG_BUFFER) {
+ /* If buffer allocation was delayed, do it now */
+ if (itflags&NPY_ITFLAG_DELAYBUF) {
+ if (!npyiter_allocate_buffers(iter, errmsg)) {
+ return NPY_FAIL;
+ }
+ NIT_ITFLAGS(iter) &= ~NPY_ITFLAG_DELAYBUF;
+ }
+ else {
+ /* Copy any data from the buffers back to the arrays */
+ npyiter_copy_from_buffers(iter);
+ }
+ }
+
+ /* The new data pointers for resetting */
+ for (iiter = 0; iiter < niter; ++iiter) {
+ resetdataptr[iiter] = baseptrs[iiter] + baseoffsets[iiter];
+ }
+
+ npyiter_goto_iterindex(iter, NIT_ITERSTART(iter));
+
+ if (itflags&NPY_ITFLAG_BUFFER) {
+ /* Prepare the next buffers and set iterend/size */
+ npyiter_copy_to_buffers(iter, NULL);
+ }
+
+ return NPY_SUCCEED;
+}
+
+/*NUMPY_API
+ * Resets the iterator to a new iterator index range
+ *
+ * If errmsg is non-NULL, it should point to a variable which will
+ * receive the error message, and no Python exception will be set.
+ * This is so that the function can be called from code not holding
+ * the GIL.
+ */
+NPY_NO_EXPORT int
+NpyIter_ResetToIterIndexRange(NpyIter *iter,
+ npy_intp istart, npy_intp iend, char **errmsg)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ /*int ndim = NIT_NDIM(iter);*/
+ /*int niter = NIT_NITER(iter);*/
+
+ if (!(itflags&NPY_ITFLAG_RANGE)) {
+ if (errmsg == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Cannot call ResetToIterIndexRange on an iterator without "
+ "requesting ranged iteration support in the constructor");
+ }
+ else {
+ *errmsg = "Cannot call ResetToIterIndexRange on an iterator "
+ "without requesting ranged iteration support in the "
+ "constructor";
+ }
+ return NPY_FAIL;
+ }
+
+ if (istart < 0 || iend > NIT_ITERSIZE(iter)) {
+ if (errmsg == NULL) {
+ PyErr_Format(PyExc_ValueError,
+ "Out-of-bounds range [%d, %d) passed to "
+ "ResetToIterIndexRange", (int)istart, (int)iend);
+ }
+ else {
+ *errmsg = "Out-of-bounds range passed to ResetToIterIndexRange";
+ }
+ return NPY_FAIL;
+ }
+ else if (iend < istart) {
+ if (errmsg == NULL) {
+ PyErr_Format(PyExc_ValueError,
+ "Invalid range [%d, %d) passed to ResetToIterIndexRange",
+ (int)istart, (int)iend);
+ }
+ else {
+ *errmsg = "Invalid range passed to ResetToIterIndexRange";
+ }
+ return NPY_FAIL;
+ }
+
+ NIT_ITERSTART(iter) = istart;
+ NIT_ITEREND(iter) = iend;
+
+ return NpyIter_Reset(iter, errmsg);
+}
+
+/*NUMPY_API
+ * Sets the iterator to the specified coordinates, which must have the
+ * correct number of entries for 'ndim'. It is only valid
+ * when NPY_ITER_COORDS was passed to the constructor. This operation
+ * fails if the coordinates are out of bounds.
+ *
+ * Returns NPY_SUCCEED on success, NPY_FAIL on failure.
+ */
+NPY_NO_EXPORT int
+NpyIter_GotoCoords(NpyIter *iter, npy_intp *coords)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int idim, ndim = NIT_NDIM(iter);
+ int niter = NIT_NITER(iter);
+
+ npy_intp iterindex, factor;
+ NpyIter_AxisData *axisdata;
+ npy_intp sizeof_axisdata;
+ char *perm;
+
+ if (!(itflags&NPY_ITFLAG_HASCOORDS)) {
+ PyErr_SetString(PyExc_ValueError,
+ "Cannot call GotoCoords on an iterator without "
+ "requesting coordinates in the constructor");
+ return NPY_FAIL;
+ }
+
+ if (itflags&NPY_ITFLAG_BUFFER) {
+ PyErr_SetString(PyExc_ValueError,
+ "Cannot call GotoCoords on an iterator which "
+ "is buffered");
+ return NPY_FAIL;
+ }
+
+ if (itflags&NPY_ITFLAG_NOINNER) {
+ PyErr_SetString(PyExc_ValueError,
+ "Cannot call GotoCoords on an iterator which "
+ "has the flag NO_INNER_ITERATION");
+ return NPY_FAIL;
+ }
+
+ perm = NIT_PERM(iter);
+ axisdata = NIT_AXISDATA(iter);
+ sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
+
+ /* Compute the iterindex corresponding to the coordinates */
+ iterindex = 0;
+ factor = 1;
+ for (idim = 0; idim < ndim; ++idim) {
+ char p = perm[idim];
+ npy_intp i, shape;
+
+ shape = NAD_SHAPE(axisdata);
+ if (p < 0) {
+ /* If the perm entry is negative, reverse the coordinate */
+ i = shape - coords[ndim+p] - 1;
+ }
+ else {
+ i = coords[ndim-p-1];
+ }
+
+ /* Bounds-check this coordinate */
+ if (i >= 0 && i < shape) {
+ iterindex += factor * i;
+ factor *= shape;
+ }
+ else {
+ PyErr_SetString(PyExc_IndexError,
+ "Iterator GotoCoords called with out-of-bounds "
+ "coordinates.");
+ return NPY_FAIL;
+ }
+
+ NIT_ADVANCE_AXISDATA(axisdata, 1);
+ }
+
+ if (iterindex < NIT_ITERSTART(iter) || iterindex >= NIT_ITEREND(iter)) {
+ PyErr_SetString(PyExc_IndexError,
+ "Iterator GotoCoords called with coordinates outside the "
+ "iteration range.");
+ return NPY_FAIL;
+ }
+
+ npyiter_goto_iterindex(iter, iterindex);
+
+ return NPY_SUCCEED;
+}
+
+/*NUMPY_API
+ * If the iterator is tracking an index, sets the iterator
+ * to the specified index.
+ *
+ * Returns NPY_SUCCEED on success, NPY_FAIL on failure.
+ */
+NPY_NO_EXPORT int
+NpyIter_GotoIndex(NpyIter *iter, npy_intp index)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int idim, ndim = NIT_NDIM(iter);
+ int niter = NIT_NITER(iter);
+
+ npy_intp iterindex, factor;
+ NpyIter_AxisData *axisdata;
+ npy_intp sizeof_axisdata;
+
+ if (!(itflags&NPY_ITFLAG_HASINDEX)) {
+ PyErr_SetString(PyExc_ValueError,
+ "Cannot call GotoIndex on an iterator without "
+ "requesting an index in the constructor");
+ return NPY_FAIL;
+ }
+
+ if (itflags&NPY_ITFLAG_BUFFER) {
+ PyErr_SetString(PyExc_ValueError,
+ "Cannot call GotoIndex on an iterator which "
+ "is buffered");
+ return NPY_FAIL;
+ }
+
+ if (itflags&NPY_ITFLAG_NOINNER) {
+ PyErr_SetString(PyExc_ValueError,
+ "Cannot call GotoIndex on an iterator which "
+ "has the flag NO_INNER_ITERATION");
+ return NPY_FAIL;
+ }
+
+ if (index < 0 || index >= NIT_ITERSIZE(iter)) {
+ PyErr_SetString(PyExc_IndexError,
+ "Iterator GotoIndex called with an out-of-bounds "
+ "index.");
+ return NPY_FAIL;
+ }
+
+ axisdata = NIT_AXISDATA(iter);
+ sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
+
+ /* Compute the iterindex corresponding to the index */
+ iterindex = 0;
+ factor = 1;
+ for (idim = 0; idim < ndim; ++idim) {
+ npy_intp i, shape, iterstride;
+
+ iterstride = NAD_STRIDES(axisdata)[niter];
+ shape = NAD_SHAPE(axisdata);
+
+ /* Extract the coordinate from the index */
+ if (iterstride == 0) {
+ i = 0;
+ }
+ else if (iterstride < 0) {
+ i = shape - (index/(-iterstride))%shape - 1;
+ }
+ else {
+ i = (index/iterstride)%shape;
+ }
+
+ /* Add its contribution to iterindex */
+ iterindex += factor * i;
+ factor *= shape;
+
+ NIT_ADVANCE_AXISDATA(axisdata, 1);
+ }
+
+
+ if (iterindex < NIT_ITERSTART(iter) || iterindex >= NIT_ITEREND(iter)) {
+ PyErr_SetString(PyExc_IndexError,
+ "Iterator GotoIndex called with an index outside the "
+ "iteration range.");
+ return NPY_FAIL;
+ }
+
+ npyiter_goto_iterindex(iter, iterindex);
+
+ return NPY_SUCCEED;
+}
+
+/*NUMPY_API
+ * Sets the iterator position to the specified iterindex,
+ * which matches the iteration order of the iterator.
+ *
+ * Returns NPY_SUCCEED on success, NPY_FAIL on failure.
+ */
+NPY_NO_EXPORT int
+NpyIter_GotoIterIndex(NpyIter *iter, npy_intp iterindex)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ /*int ndim = NIT_NDIM(iter);*/
+ int iiter, niter = NIT_NITER(iter);
+
+ if (itflags&NPY_ITFLAG_NOINNER) {
+ PyErr_SetString(PyExc_ValueError,
+ "Cannot call GotoIterIndex on an iterator which "
+ "has the flag NO_INNER_ITERATION");
+ return NPY_FAIL;
+ }
+
+ if (iterindex < NIT_ITERSTART(iter) || iterindex >= NIT_ITEREND(iter)) {
+ PyErr_SetString(PyExc_IndexError,
+ "Iterator GotoIterIndex called with an iterindex outside the "
+ "iteration range.");
+ return NPY_FAIL;
+ }
+
+ if (itflags&NPY_ITFLAG_BUFFER) {
+ NpyIter_BufferData *bufferdata = NIT_BUFFERDATA(iter);
+ npy_intp bufiterend, size;
+
+ size = NBF_SIZE(bufferdata);
+ bufiterend = NBF_BUFITEREND(bufferdata);
+ /* Check if the new iterindex is already within the buffer */
+ if (!(itflags&NPY_ITFLAG_REDUCE) && iterindex < bufiterend &&
+ iterindex >= bufiterend - size) {
+ npy_intp *strides, delta;
+ char **ptrs;
+
+ strides = NBF_STRIDES(bufferdata);
+ ptrs = NBF_PTRS(bufferdata);
+ delta = iterindex - NIT_ITERINDEX(iter);
+
+ for (iiter = 0; iiter < niter; ++iiter) {
+ ptrs[iiter] += delta * strides[iiter];
+ }
+
+ NIT_ITERINDEX(iter) = iterindex;
+ }
+ /* Start the buffer at the provided iterindex */
+ else {
+ /* Write back to the arrays */
+ npyiter_copy_from_buffers(iter);
+
+ npyiter_goto_iterindex(iter, iterindex);
+
+ /* Prepare the next buffers and set iterend/size */
+ npyiter_copy_to_buffers(iter, NULL);
+ }
+ }
+ else {
+ npyiter_goto_iterindex(iter, iterindex);
+ }
+
+ return NPY_SUCCEED;
+}
+
+/*NUMPY_API
+ * Gets the current iteration index
+ */
+NPY_NO_EXPORT npy_intp
+NpyIter_GetIterIndex(NpyIter *iter)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int idim, ndim = NIT_NDIM(iter);
+ int niter = NIT_NITER(iter);
+
+ /* iterindex is only used if NPY_ITER_RANGED or NPY_ITER_BUFFERED was set */
+ if (itflags&(NPY_ITFLAG_RANGE|NPY_ITFLAG_BUFFER)) {
+ return NIT_ITERINDEX(iter);
+ }
+ else {
+ npy_intp iterindex;
+ NpyIter_AxisData *axisdata;
+ npy_intp sizeof_axisdata;
+
+ iterindex = 0;
+ sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
+ axisdata = NIT_INDEX_AXISDATA(NIT_AXISDATA(iter), ndim-1);
+
+ for (idim = ndim-2; idim >= 0; --idim) {
+ iterindex += NAD_COORD(axisdata);
+ NIT_ADVANCE_AXISDATA(axisdata, -1);
+ iterindex *= NAD_SHAPE(axisdata);
+ }
+ iterindex += NAD_COORD(axisdata);
+
+ return iterindex;
+ }
+}
+
+/* SPECIALIZED iternext functions that handle the non-buffering part */
+
+/**begin repeat
+ * #const_itflags = 0,
+ * NPY_ITFLAG_HASINDEX,
+ * NPY_ITFLAG_NOINNER,
+ * NPY_ITFLAG_RANGE,
+ * NPY_ITFLAG_RANGE|NPY_ITFLAG_HASINDEX#
+ * #tag_itflags = 0, IND, NOINN, RNG, RNGuIND#
+ */
+/**begin repeat1
+ * #const_ndim = 1, 2, NPY_MAXDIMS#
+ * #tag_ndim = 1, 2, ANY#
+ */
+/**begin repeat2
+ * #const_niter = 1, 2, NPY_MAXDIMS#
+ * #tag_niter = 1, 2, ANY#
+ */
+
+/* Specialized iternext (@const_itflags@,@tag_ndim@,@tag_niter@) */
+static int
+npyiter_iternext_itflags@tag_itflags@_dims@tag_ndim@_iters@tag_niter@(
+ NpyIter *iter)
+{
+ const npy_uint32 itflags = @const_itflags@;
+#if @const_ndim@ >= NPY_MAXDIMS
+ int idim, ndim = NIT_NDIM(iter);
+#endif
+#if @const_niter@ < NPY_MAXDIMS
+ const int niter = @const_niter@;
+#else
+ int niter = NIT_NITER(iter);
+#endif
+
+ npy_intp istrides, nstrides, sizeof_axisdata;
+#if @const_ndim@ > 0
+ NpyIter_AxisData *axisdata0;
+#endif
+#if @const_ndim@ > 1
+ NpyIter_AxisData *axisdata1;
+#endif
+#if @const_ndim@ > 2
+ NpyIter_AxisData *axisdata2;
+#endif
+
+#if (@const_itflags@&NPY_ITFLAG_RANGE)
+ /* When ranged iteration is enabled, use the iterindex */
+ if (++NIT_ITERINDEX(iter) >= NIT_ITEREND(iter)) {
+ return 0;
+ }
+#endif
+
+ nstrides = NAD_NSTRIDES();
+ sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
+
+ axisdata0 = NIT_AXISDATA(iter);
+# if !(@const_itflags@&NPY_ITFLAG_NOINNER)
+ /* Increment coordinate 0 */
+ NAD_COORD(axisdata0)++;
+ /* Increment pointer 0 */
+ for (istrides = 0; istrides < nstrides; ++istrides) {
+ NAD_PTRS(axisdata0)[istrides] += NAD_STRIDES(axisdata0)[istrides];
+ }
+# endif
+
+#if @const_ndim@ == 1
+
+# if !(@const_itflags@&NPY_ITFLAG_NOINNER)
+ /* Finished when the coordinate equals the shape */
+ return NAD_COORD(axisdata0) < NAD_SHAPE(axisdata0);
+# else
+ /* Get rid of unused variable warning */
+ istrides = 0;
+
+ return 0;
+# endif
+
+#else
+
+# if !(@const_itflags@&NPY_ITFLAG_NOINNER)
+ if (NAD_COORD(axisdata0) < NAD_SHAPE(axisdata0)) {
+ return 1;
+ }
+# endif
+
+ axisdata1 = NIT_INDEX_AXISDATA(axisdata0, 1);
+ /* Increment coordinate 1 */
+ NAD_COORD(axisdata1)++;
+ /* Increment pointer 1 */
+ for (istrides = 0; istrides < nstrides; ++istrides) {
+ NAD_PTRS(axisdata1)[istrides] += NAD_STRIDES(axisdata1)[istrides];
+ }
+
+ if (NAD_COORD(axisdata1) < NAD_SHAPE(axisdata1)) {
+ /* Reset the 1st coordinate to 0 */
+ NAD_COORD(axisdata0) = 0;
+ /* Reset the 1st pointer to the value of the 2nd */
+ for (istrides = 0; istrides < nstrides; ++istrides) {
+ NAD_PTRS(axisdata0)[istrides] = NAD_PTRS(axisdata1)[istrides];
+ }
+ return 1;
+ }
+
+# if @const_ndim@ == 2
+ return 0;
+# else
+
+ axisdata2 = NIT_INDEX_AXISDATA(axisdata1, 1);
+ /* Increment coordinate 2 */
+ NAD_COORD(axisdata2)++;
+ /* Increment pointer 2 */
+ for (istrides = 0; istrides < nstrides; ++istrides) {
+ NAD_PTRS(axisdata2)[istrides] += NAD_STRIDES(axisdata2)[istrides];
+ }
+
+ if (NAD_COORD(axisdata2) < NAD_SHAPE(axisdata2)) {
+ /* Reset the 1st and 2nd coordinates to 0 */
+ NAD_COORD(axisdata0) = 0;
+ NAD_COORD(axisdata1) = 0;
+ /* Reset the 1st and 2nd pointers to the value of the 3nd */
+ for (istrides = 0; istrides < nstrides; ++istrides) {
+ NAD_PTRS(axisdata0)[istrides] = NAD_PTRS(axisdata2)[istrides];
+ NAD_PTRS(axisdata1)[istrides] = NAD_PTRS(axisdata2)[istrides];
+ }
+ return 1;
+ }
+
+ for (idim = 3; idim < ndim; ++idim) {
+ NIT_ADVANCE_AXISDATA(axisdata2, 1);
+ /* Increment the coordinate */
+ NAD_COORD(axisdata2)++;
+ /* Increment the pointer */
+ for (istrides = 0; istrides < nstrides; ++istrides) {
+ NAD_PTRS(axisdata2)[istrides] += NAD_STRIDES(axisdata2)[istrides];
+ }
+
+
+ if (NAD_COORD(axisdata2) < NAD_SHAPE(axisdata2)) {
+ /* Reset the coordinates and pointers of all previous axisdatas */
+ axisdata1 = axisdata2;
+ do {
+ NIT_ADVANCE_AXISDATA(axisdata1, -1);
+ /* Reset the coordinate to 0 */
+ NAD_COORD(axisdata1) = 0;
+ /* Reset the pointer to the updated value */
+ for (istrides = 0; istrides < nstrides; ++istrides) {
+ NAD_PTRS(axisdata1)[istrides] =
+ NAD_PTRS(axisdata2)[istrides];
+ }
+ } while (axisdata1 != axisdata0);
+
+ return 1;
+ }
+ }
+
+ return 0;
+
+# endif /* ndim != 2 */
+
+#endif /* ndim != 1 */
+}
+
+/**end repeat2**/
+/**end repeat1**/
+/**end repeat**/
+
+
+/**begin repeat
+ * #const_niter = 1, 2, 3, 4, NPY_MAXDIMS#
+ * #tag_niter = 1, 2, 3, 4, ANY#
+ */
+
+/*
+ * Iternext function that handles the reduction buffering part. This
+ * is done with a double loop to avoid frequent re-buffering.
+ */
+static int
+npyiter_buffered_reduce_iternext_iters@tag_niter@(NpyIter *iter)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ /*int ndim = NIT_NDIM(iter);*/
+#if @const_niter@ >= NPY_MAXDIMS
+ int niter = NIT_NITER(iter);
+#else
+ const int niter = @const_niter@;
+#endif
+
+ int iiter;
+
+ NpyIter_AxisData *axisdata;
+ NpyIter_BufferData *bufferdata = NIT_BUFFERDATA(iter);
+ char **ptrs;
+ char *prev_dataptrs[NPY_MAXARGS];
+
+ ptrs = NBF_PTRS(bufferdata);
+
+ /*
+ * If the iterator handles the inner loop, need to increment all
+ * the coordinates and pointers
+ */
+ if (!(itflags&NPY_ITFLAG_NOINNER)) {
+ /* Increment within the buffer */
+ if (++NIT_ITERINDEX(iter) < NBF_BUFITEREND(bufferdata)) {
+ npy_intp *strides;
+
+ strides = NBF_STRIDES(bufferdata);
+ for (iiter = 0; iiter < niter; ++iiter) {
+ ptrs[iiter] += strides[iiter];
+ }
+ return 1;
+ }
+ }
+ else {
+ NIT_ITERINDEX(iter) += NBF_SIZE(bufferdata);
+ }
+
+ NPY_IT_DBG_PRINT1("Iterator: Finished iteration %d of outer reduce loop\n",
+ (int)NBF_REDUCE_POS(bufferdata));
+ /* The outer increment for the reduce double loop */
+ if (++NBF_REDUCE_POS(bufferdata) < NBF_REDUCE_OUTERSIZE(bufferdata)) {
+ npy_intp *reduce_outerstrides = NBF_REDUCE_OUTERSTRIDES(bufferdata);
+ char **reduce_outerptrs = NBF_REDUCE_OUTERPTRS(bufferdata);
+ for (iiter = 0; iiter < niter; ++iiter) {
+ char *ptr = reduce_outerptrs[iiter] + reduce_outerstrides[iiter];
+ ptrs[iiter] = ptr;
+ reduce_outerptrs[iiter] = ptr;
+ }
+ NBF_BUFITEREND(bufferdata) = NIT_ITERINDEX(iter) + NBF_SIZE(bufferdata);
+ return 1;
+ }
+
+ /* Save the previously used data pointers */
+ axisdata = NIT_AXISDATA(iter);
+ memcpy(prev_dataptrs, NAD_PTRS(axisdata), NPY_SIZEOF_INTP*niter);
+
+ /* Write back to the arrays */
+ npyiter_copy_from_buffers(iter);
+
+ /* Check if we're past the end */
+ if (NIT_ITERINDEX(iter) >= NIT_ITEREND(iter)) {
+ NBF_SIZE(bufferdata) = 0;
+ return 0;
+ }
+ /* Increment to the next buffer */
+ else {
+ npyiter_goto_iterindex(iter, NIT_ITERINDEX(iter));
+ }
+
+ /* Prepare the next buffers and set iterend/size */
+ npyiter_copy_to_buffers(iter, prev_dataptrs);
+
+ return 1;
+}
+
+/**end repeat**/
+
+/* iternext function that handles the buffering part */
+static int
+npyiter_buffered_iternext(NpyIter *iter)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ /*int ndim = NIT_NDIM(iter);*/
+ int niter = NIT_NITER(iter);
+
+ NpyIter_BufferData *bufferdata = NIT_BUFFERDATA(iter);
+
+ /*
+ * If the iterator handles the inner loop, need to increment all
+ * the coordinates and pointers
+ */
+ if (!(itflags&NPY_ITFLAG_NOINNER)) {
+ /* Increment within the buffer */
+ if (++NIT_ITERINDEX(iter) < NBF_BUFITEREND(bufferdata)) {
+ int iiter;
+ npy_intp *strides;
+ char **ptrs;
+
+ strides = NBF_STRIDES(bufferdata);
+ ptrs = NBF_PTRS(bufferdata);
+ for (iiter = 0; iiter < niter; ++iiter) {
+ ptrs[iiter] += strides[iiter];
+ }
+ return 1;
+ }
+ }
+ else {
+ NIT_ITERINDEX(iter) += NBF_SIZE(bufferdata);
+ }
+
+ /* Write back to the arrays */
+ npyiter_copy_from_buffers(iter);
+
+ /* Check if we're past the end */
+ if (NIT_ITERINDEX(iter) >= NIT_ITEREND(iter)) {
+ NBF_SIZE(bufferdata) = 0;
+ return 0;
+ }
+ /* Increment to the next buffer */
+ else {
+ npyiter_goto_iterindex(iter, NIT_ITERINDEX(iter));
+ }
+
+ /* Prepare the next buffers and set iterend/size */
+ npyiter_copy_to_buffers(iter, NULL);
+
+ return 1;
+}
+
+/**end repeat2**/
+/**end repeat1**/
+/**end repeat**/
+
+/* Specialization of iternext for when the iteration size is 1 */
+static int
+npyiter_iternext_sizeone(NpyIter *iter)
+{
+ return 0;
+}
+
+/*NUMPY_API
+ * Compute the specialized iteration function for an iterator
+ *
+ * If errmsg is non-NULL, it should point to a variable which will
+ * receive the error message, and no Python exception will be set.
+ * This is so that the function can be called from code not holding
+ * the GIL.
+ */
+NPY_NO_EXPORT NpyIter_IterNextFunc *
+NpyIter_GetIterNext(NpyIter *iter, char **errmsg)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int ndim = NIT_NDIM(iter);
+ int niter = NIT_NITER(iter);
+
+ /*
+ * When there is just one iteration and buffering is disabled
+ * the iternext function is very simple.
+ */
+ if (itflags&NPY_ITFLAG_ONEITERATION) {
+ return &npyiter_iternext_sizeone;
+ }
+
+ /*
+ * If buffering is enabled.
+ */
+ if (itflags&NPY_ITFLAG_BUFFER) {
+ if (itflags&NPY_ITFLAG_REDUCE) {
+ switch (niter) {
+ case 1:
+ return &npyiter_buffered_reduce_iternext_iters1;
+ case 2:
+ return &npyiter_buffered_reduce_iternext_iters2;
+ case 3:
+ return &npyiter_buffered_reduce_iternext_iters3;
+ case 4:
+ return &npyiter_buffered_reduce_iternext_iters4;
+ default:
+ return &npyiter_buffered_reduce_iternext_itersANY;
+ }
+ }
+ else {
+ return &npyiter_buffered_iternext;
+ }
+ }
+
+ /*
+ * Ignore all the flags that don't affect the iterator memory
+ * layout or the iternext function. Currently only HASINDEX,
+ * NOINNER, and RANGE affect them here.
+ */
+ itflags &= (NPY_ITFLAG_HASINDEX|NPY_ITFLAG_NOINNER|NPY_ITFLAG_RANGE);
+
+ /* Switch statements let the compiler optimize this most effectively */
+ switch (itflags) {
+ /*
+ * The combinations HASINDEX|NOINNER and RANGE|NOINNER are excluded
+ * by the New functions
+ */
+/**begin repeat
+ * #const_itflags = 0,
+ * NPY_ITFLAG_HASINDEX,
+ * NPY_ITFLAG_NOINNER,
+ * NPY_ITFLAG_RANGE,
+ * NPY_ITFLAG_RANGE|NPY_ITFLAG_HASINDEX#
+ * #tag_itflags = 0, IND, NOINN, RNG, RNGuIND#
+ */
+ case @const_itflags@:
+ switch (ndim) {
+/**begin repeat1
+ * #const_ndim = 1, 2#
+ * #tag_ndim = 1, 2#
+ */
+ case @const_ndim@:
+ switch (niter) {
+/**begin repeat2
+ * #const_niter = 1, 2#
+ * #tag_niter = 1, 2#
+ */
+ case @const_niter@:
+ return &npyiter_iternext_itflags@tag_itflags@_dims@tag_ndim@_iters@tag_niter@;
+/**end repeat2**/
+ /* Not specialized on niter */
+ default:
+ return &npyiter_iternext_itflags@tag_itflags@_dims@tag_ndim@_itersANY;
+ }
+/**end repeat1**/
+ /* Not specialized on ndim */
+ default:
+ switch (niter) {
+/**begin repeat1
+ * #const_niter = 1, 2#
+ * #tag_niter = 1, 2#
+ */
+ case @const_niter@:
+ return &npyiter_iternext_itflags@tag_itflags@_dimsANY_iters@tag_niter@;
+/**end repeat1**/
+ /* Not specialized on niter */
+ default:
+ return &npyiter_iternext_itflags@tag_itflags@_dimsANY_itersANY;
+ }
+ }
+/**end repeat**/
+ }
+ /* The switch above should have caught all the possibilities. */
+ if (errmsg == NULL) {
+ PyErr_Format(PyExc_ValueError,
+ "GetIterNext internal iterator error - unexpected "
+ "itflags/ndim/niter combination (%04x/%d/%d)",
+ (int)itflags, (int)ndim, (int)niter);
+ }
+ else {
+ *errmsg = "GetIterNext internal iterator error - unexpected "
+ "itflags/ndim/niter combination";
+ }
+ return NULL;
+}
+
+
+/* SPECIALIZED getcoord functions */
+
+/**begin repeat
+ * #const_itflags = 0,
+ * NPY_ITFLAG_HASINDEX,
+ * NPY_ITFLAG_IDENTPERM,
+ * NPY_ITFLAG_HASINDEX|NPY_ITFLAG_IDENTPERM,
+ * NPY_ITFLAG_NEGPERM,
+ * NPY_ITFLAG_HASINDEX|NPY_ITFLAG_NEGPERM,
+ * NPY_ITFLAG_BUFFER,
+ * NPY_ITFLAG_HASINDEX|NPY_ITFLAG_BUFFER,
+ * NPY_ITFLAG_IDENTPERM|NPY_ITFLAG_BUFFER,
+ * NPY_ITFLAG_HASINDEX|NPY_ITFLAG_IDENTPERM|NPY_ITFLAG_BUFFER,
+ * NPY_ITFLAG_NEGPERM|NPY_ITFLAG_BUFFER,
+ * NPY_ITFLAG_HASINDEX|NPY_ITFLAG_NEGPERM|NPY_ITFLAG_BUFFER#
+ * #tag_itflags = 0, IND, IDP, INDuIDP, NEGP, INDuNEGP,
+ * BUF, INDuBUF, IDPuBUF, INDuIDPuBUF, NEGPuBUF, INDuNEGPuBUF#
+ */
+static void
+npyiter_getcoord_itflags@tag_itflags@(NpyIter *iter, npy_intp *outcoord)
+{
+ const npy_uint32 itflags = @const_itflags@;
+ int idim, ndim = NIT_NDIM(iter);
+ int niter = NIT_NITER(iter);
+
+ npy_intp sizeof_axisdata;
+ NpyIter_AxisData *axisdata;
+#if !((@const_itflags@)&NPY_ITFLAG_IDENTPERM)
+ char* perm = NIT_PERM(iter);
+#endif
+
+ axisdata = NIT_AXISDATA(iter);
+ sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
+#if ((@const_itflags@)&NPY_ITFLAG_IDENTPERM)
+ outcoord += ndim-1;
+ for(idim = 0; idim < ndim; ++idim, --outcoord,
+ NIT_ADVANCE_AXISDATA(axisdata, 1)) {
+ *outcoord = NAD_COORD(axisdata);
+ }
+#elif !((@const_itflags@)&NPY_ITFLAG_NEGPERM)
+ for(idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) {
+ char p = perm[idim];
+ outcoord[ndim-p-1] = NAD_COORD(axisdata);
+ }
+#else
+ for(idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) {
+ char p = perm[idim];
+ if (p < 0) {
+ /* If the perm entry is negative, reverse the coordinate */
+ outcoord[ndim+p] = NAD_SHAPE(axisdata) - NAD_COORD(axisdata) - 1;
+ }
+ else {
+ outcoord[ndim-p-1] = NAD_COORD(axisdata);
+ }
+ }
+#endif /* not ident perm */
+}
+/**end repeat**/
+
+/*NUMPY_API
+ * Compute a specialized getcoords function for the iterator
+ *
+ * If errmsg is non-NULL, it should point to a variable which will
+ * receive the error message, and no Python exception will be set.
+ * This is so that the function can be called from code not holding
+ * the GIL.
+ */
+NPY_NO_EXPORT NpyIter_GetCoordsFunc *
+NpyIter_GetGetCoords(NpyIter *iter, char **errmsg)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int ndim = NIT_NDIM(iter);
+ int niter = NIT_NITER(iter);
+
+ /* These flags must be correct */
+ if ((itflags&(NPY_ITFLAG_HASCOORDS|NPY_ITFLAG_DELAYBUF)) !=
+ NPY_ITFLAG_HASCOORDS) {
+ if (!(itflags&NPY_ITFLAG_HASCOORDS)) {
+ if (errmsg == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Cannot retrieve a GetCoords function for an iterator "
+ "that doesn't track coordinates.");
+ }
+ else {
+ *errmsg = "Cannot retrieve a GetCoords function for an "
+ "iterator that doesn't track coordinates.";
+ }
+ return NULL;
+ }
+ else {
+ if (errmsg == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Cannot retrieve a GetCoords function for an iterator "
+ "that used DELAY_BUFALLOC before a Reset call");
+ }
+ else {
+ *errmsg = "Cannot retrieve a GetCoords function for an "
+ "iterator that used DELAY_BUFALLOC before a "
+ "Reset call";
+ }
+ return NULL;
+ }
+ }
+
+ /*
+ * Only these flags affect the iterator memory layout or
+ * the getcoords behavior. IDENTPERM and NEGPERM are mutually
+ * exclusive, so that reduces the number of cases slightly.
+ */
+ itflags &= (NPY_ITFLAG_HASINDEX |
+ NPY_ITFLAG_IDENTPERM |
+ NPY_ITFLAG_NEGPERM |
+ NPY_ITFLAG_BUFFER);
+
+ switch (itflags) {
+/**begin repeat
+ * #const_itflags = 0,
+ * NPY_ITFLAG_HASINDEX,
+ * NPY_ITFLAG_IDENTPERM,
+ * NPY_ITFLAG_HASINDEX|NPY_ITFLAG_IDENTPERM,
+ * NPY_ITFLAG_NEGPERM,
+ * NPY_ITFLAG_HASINDEX|NPY_ITFLAG_NEGPERM,
+ * NPY_ITFLAG_BUFFER,
+ * NPY_ITFLAG_HASINDEX|NPY_ITFLAG_BUFFER,
+ * NPY_ITFLAG_IDENTPERM|NPY_ITFLAG_BUFFER,
+ * NPY_ITFLAG_HASINDEX|NPY_ITFLAG_IDENTPERM|NPY_ITFLAG_BUFFER,
+ * NPY_ITFLAG_NEGPERM|NPY_ITFLAG_BUFFER,
+ * NPY_ITFLAG_HASINDEX|NPY_ITFLAG_NEGPERM|NPY_ITFLAG_BUFFER#
+ * #tag_itflags = 0, IND, IDP, INDuIDP, NEGP, INDuNEGP,
+ * BUF, INDuBUF, IDPuBUF, INDuIDPuBUF, NEGPuBUF, INDuNEGPuBUF#
+ */
+ case @const_itflags@:
+ return npyiter_getcoord_itflags@tag_itflags@;
+/**end repeat**/
+ }
+ /* The switch above should have caught all the possibilities. */
+ if (errmsg == NULL) {
+ PyErr_Format(PyExc_ValueError,
+ "GetGetCoords internal iterator error - unexpected "
+ "itflags/ndim/niter combination (%04x/%d/%d)",
+ (int)itflags, (int)ndim, (int)niter);
+ }
+ else {
+ *errmsg = "GetGetCoords internal iterator error - unexpected "
+ "itflags/ndim/niter combination";
+ }
+ return NULL;
+
+}
+
+/*NUMPY_API
+ * Whether the buffer allocation is being delayed
+ */
+NPY_NO_EXPORT npy_bool
+NpyIter_HasDelayedBufAlloc(NpyIter *iter)
+{
+ return (NIT_ITFLAGS(iter)&NPY_ITFLAG_DELAYBUF) != 0;
+}
+
+/*NUMPY_API
+ * Whether the iterator handles the inner loop
+ */
+NPY_NO_EXPORT npy_bool
+NpyIter_HasInnerLoop(NpyIter *iter)
+{
+ return (NIT_ITFLAGS(iter)&NPY_ITFLAG_NOINNER) == 0;
+}
+
+/*NUMPY_API
+ * Whether the iterator is tracking coordinates
+ */
+NPY_NO_EXPORT npy_bool
+NpyIter_HasCoords(NpyIter *iter)
+{
+ return (NIT_ITFLAGS(iter)&NPY_ITFLAG_HASCOORDS) != 0;
+}
+
+/*NUMPY_API
+ * Whether the iterator is tracking an index
+ */
+NPY_NO_EXPORT npy_bool
+NpyIter_HasIndex(NpyIter *iter)
+{
+ return (NIT_ITFLAGS(iter)&NPY_ITFLAG_HASINDEX) != 0;
+}
+
+/*NUMPY_API
+ * Whether the iteration could be done with no buffering.
+ */
+NPY_NO_EXPORT npy_bool
+NpyIter_RequiresBuffering(NpyIter *iter)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ /*int ndim = NIT_NDIM(iter);*/
+ int iiter, niter = NIT_NITER(iter);
+
+ char *op_itflags;
+
+ if (!(itflags&NPY_ITFLAG_BUFFER)) {
+ return 0;
+ }
+
+ op_itflags = NIT_OPITFLAGS(iter);
+
+ /* If any operand requires a cast, buffering is mandatory */
+ for (iiter = 0; iiter < niter; ++iiter) {
+ if (op_itflags[iiter]&NPY_OP_ITFLAG_CAST) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+/*NUMPY_API
+ * Whether the iteration loop, and in particular the iternext()
+ * function, needs API access. If this is true, the GIL must
+ * be retained while iterating.
+ */
+NPY_NO_EXPORT npy_bool
+NpyIter_IterationNeedsAPI(NpyIter *iter)
+{
+ return (NIT_ITFLAGS(iter)&NPY_ITFLAG_NEEDSAPI) != 0;
+}
+
+/*NUMPY_API
+ * Gets the number of dimensions being iterated
+ */
+NPY_NO_EXPORT int
+NpyIter_GetNDim(NpyIter *iter)
+{
+ return NIT_NDIM(iter);
+}
+
+/*NUMPY_API
+ * Gets the number of operands being iterated
+ */
+NPY_NO_EXPORT int
+NpyIter_GetNIter(NpyIter *iter)
+{
+ return NIT_NITER(iter);
+}
+
+/*NUMPY_API
+ * Gets the number of elements being iterated
+ */
+NPY_NO_EXPORT npy_intp
+NpyIter_GetIterSize(NpyIter *iter)
+{
+ return NIT_ITERSIZE(iter);
+}
+
+/*NUMPY_API
+ * Whether the iterator is buffered
+ */
+NPY_NO_EXPORT npy_bool
+NpyIter_IsBuffered(NpyIter *iter)
+{
+ return (NIT_ITFLAGS(iter)&NPY_ITFLAG_BUFFER) != 0;
+}
+
+/*NUMPY_API
+ * Whether the inner loop can grow if buffering is unneeded
+ */
+NPY_NO_EXPORT npy_bool
+NpyIter_IsGrowInner(NpyIter *iter)
+{
+ return (NIT_ITFLAGS(iter)&NPY_ITFLAG_GROWINNER) != 0;
+}
+
+/*NUMPY_API
+ * Gets the size of the buffer, or 0 if buffering is not enabled
+ */
+NPY_NO_EXPORT npy_intp
+NpyIter_GetBufferSize(NpyIter *iter)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ /*int ndim = NIT_NDIM(iter);*/
+ int niter = NIT_NITER(iter);
+
+ if (itflags&NPY_ITFLAG_BUFFER) {
+ NpyIter_BufferData *bufferdata = NIT_BUFFERDATA(iter);
+ return NBF_BUFFERSIZE(bufferdata);
+ }
+ else {
+ return 0;
+ }
+
+}
+
+/*NUMPY_API
+ * Gets the range of iteration indices being iterated
+ */
+NPY_NO_EXPORT void
+NpyIter_GetIterIndexRange(NpyIter *iter,
+ npy_intp *istart, npy_intp *iend)
+{
+ *istart = NIT_ITERSTART(iter);
+ *iend = NIT_ITEREND(iter);
+}
+
+/*NUMPY_API
+ * Gets the broadcast shape if coords are being tracked by the iterator,
+ * otherwise gets the shape of the iteration as Fortran-order
+ * (fastest-changing coordinate first).
+ *
+ * The reason Fortran-order is returned when coords
+ * are not enabled is that this is providing a direct view into how
+ * the iterator traverses the n-dimensional space. The iterator organizes
+ * its memory from fastest coordinate to slowest coordinate, and when
+ * coords are enabled, it uses a permutation to recover the original
+ * order.
+ *
+ * Returns NPY_SUCCEED or NPY_FAIL.
+ */
+NPY_NO_EXPORT int
+NpyIter_GetShape(NpyIter *iter, npy_intp *outshape)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int ndim = NIT_NDIM(iter);
+ int niter = NIT_NITER(iter);
+
+ int idim, sizeof_axisdata;
+ NpyIter_AxisData *axisdata;
+ char *perm;
+
+ axisdata = NIT_AXISDATA(iter);
+ sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
+
+ if (itflags&NPY_ITFLAG_HASCOORDS) {
+ perm = NIT_PERM(iter);
+ for(idim = 0; idim < ndim; ++idim) {
+ char p = perm[idim];
+ if (p < 0) {
+ outshape[ndim+p] = NAD_SHAPE(axisdata);
+ }
+ else {
+ outshape[ndim-p-1] = NAD_SHAPE(axisdata);
+ }
+
+ NIT_ADVANCE_AXISDATA(axisdata, 1);
+ }
+ }
+ else {
+ for(idim = 0; idim < ndim; ++idim) {
+ outshape[idim] = NAD_SHAPE(axisdata);
+ NIT_ADVANCE_AXISDATA(axisdata, 1);
+ }
+ }
+
+ return NPY_SUCCEED;
+}
+
+/*NUMPY_API
+ * Builds a set of strides which are the same as the strides of an
+ * output array created using the NPY_ITER_ALLOCATE flag, where NULL
+ * was passed for op_axes. This is for data packed contiguously,
+ * but not necessarily in C or Fortran order. This should be used
+ * together with NpyIter_GetShape and NpyIter_GetNDim.
+ *
+ * A use case for this function is to match the shape and layout of
+ * the iterator and tack on one or more dimensions. For example,
+ * in order to generate a vector per input value for a numerical gradient,
+ * you pass in ndim*itemsize for itemsize, then add another dimension to
+ * the end with size ndim and stride itemsize. To do the Hessian matrix,
+ * you do the same thing but add two dimensions, or take advantage of
+ * the symmetry and pack it into 1 dimension with a particular encoding.
+ *
+ * This function may only be called if the iterator is tracking coordinates
+ * and if NPY_ITER_DONT_NEGATE_STRIDES was used to prevent an axis from
+ * being iterated in reverse order.
+ *
+ * If an array is created with this method, simply adding 'itemsize'
+ * for each iteration will traverse the new array matching the
+ * iterator.
+ *
+ * Returns NPY_SUCCEED or NPY_FAIL.
+ */
+NPY_NO_EXPORT int
+NpyIter_CreateCompatibleStrides(NpyIter *iter,
+ npy_intp itemsize, npy_intp *outstrides)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int idim, ndim = NIT_NDIM(iter);
+ int niter = NIT_NITER(iter);
+
+ npy_intp sizeof_axisdata;
+ NpyIter_AxisData *axisdata;
+ char *perm;
+
+ if (!(itflags&NPY_ITFLAG_HASCOORDS)) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Iterator CreateCompatibleStrides may only be called "
+ "if coordinates are being tracked");
+ return NPY_FAIL;
+ }
+
+ axisdata = NIT_AXISDATA(iter);
+ sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
+
+ perm = NIT_PERM(iter);
+ for(idim = 0; idim < ndim; ++idim) {
+ char p = perm[idim];
+ if (p < 0) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Iterator CreateCompatibleStrides may only be called "
+ "if DONT_NEGATE_STRIDES was used to prevent reverse "
+ "iteration of an axis");
+ return NPY_FAIL;
+ }
+ else {
+ outstrides[ndim-p-1] = itemsize;
+ }
+
+ itemsize *= NAD_SHAPE(axisdata);
+ NIT_ADVANCE_AXISDATA(axisdata, 1);
+ }
+
+ return NPY_SUCCEED;
+}
+
+/*NUMPY_API
+ * Get the array of data pointers (1 per object being iterated)
+ *
+ * This function may be safely called without holding the Python GIL.
+ */
+NPY_NO_EXPORT char **
+NpyIter_GetDataPtrArray(NpyIter *iter)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ /*int ndim = NIT_NDIM(iter);*/
+ int niter = NIT_NITER(iter);
+
+ if (itflags&NPY_ITFLAG_BUFFER) {
+ NpyIter_BufferData *bufferdata = NIT_BUFFERDATA(iter);
+ return NBF_PTRS(bufferdata);
+ }
+ else {
+ NpyIter_AxisData *axisdata = NIT_AXISDATA(iter);
+ return NAD_PTRS(axisdata);
+ }
+}
+
+/*NUMPY_API
+ * Get the array of data pointers (1 per object being iterated),
+ * directly into the arrays (never pointing to a buffer), for starting
+ * unbuffered iteration. This always returns the addresses for the
+ * iterator position as reset to iterator index 0.
+ *
+ * These pointers are different from the pointers accepted by
+ * NpyIter_ResetBasePointers, because the direction along some
+ * axes may have been reversed, requiring base offsets.
+ *
+ * This function may be safely called without holding the Python GIL.
+ */
+NPY_NO_EXPORT char **
+NpyIter_GetInitialDataPtrArray(NpyIter *iter)
+{
+ /*npy_uint32 itflags = NIT_ITFLAGS(iter);*/
+ /*int ndim = NIT_NDIM(iter);*/
+ int niter = NIT_NITER(iter);
+
+ return NIT_RESETDATAPTR(iter);
+}
+
+/*NUMPY_API
+ * Get the array of data type pointers (1 per object being iterated)
+ */
+NPY_NO_EXPORT PyArray_Descr **
+NpyIter_GetDescrArray(NpyIter *iter)
+{
+ /*npy_uint32 itflags = NIT_ITFLAGS(iter);*/
+ /*int ndim = NIT_NDIM(iter);*/
+ /*int niter = NIT_NITER(iter);*/
+
+ return NIT_DTYPES(iter);
+}
+
+/*NUMPY_API
+ * Get the array of objects being iterated
+ */
+NPY_NO_EXPORT PyArrayObject **
+NpyIter_GetOperandArray(NpyIter *iter)
+{
+ /*npy_uint32 itflags = NIT_ITFLAGS(iter);*/
+ /*int ndim = NIT_NDIM(iter);*/
+ int niter = NIT_NITER(iter);
+
+ return NIT_OPERANDS(iter);
+}
+
+/*NUMPY_API
+ * Returns a view to the i-th object with the iterator's internal axes
+ */
+NPY_NO_EXPORT PyArrayObject *
+NpyIter_GetIterView(NpyIter *iter, npy_intp i)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int idim, ndim = NIT_NDIM(iter);
+ int niter = NIT_NITER(iter);
+
+ npy_intp shape[NPY_MAXDIMS], strides[NPY_MAXDIMS];
+ PyArrayObject *obj, *view;
+ PyArray_Descr *dtype;
+ char *dataptr;
+ NpyIter_AxisData *axisdata;
+ npy_intp sizeof_axisdata;
+ int writeable;
+
+ if (i < 0 || i >= niter) {
+ PyErr_SetString(PyExc_IndexError,
+ "index provided for an iterator view was out of bounds");
+ return NULL;
+ }
+
+ /* Don't provide views if buffering is enabled */
+ if (itflags&NPY_ITFLAG_BUFFER) {
+ PyErr_SetString(PyExc_ValueError,
+ "cannot provide an iterator view when buffering is enabled");
+ return NULL;
+ }
+
+ obj = NIT_OPERANDS(iter)[i];
+ dtype = PyArray_DESCR(obj);
+ writeable = NIT_OPITFLAGS(iter)[i]&NPY_OP_ITFLAG_WRITE;
+ dataptr = NIT_RESETDATAPTR(iter)[i];
+ axisdata = NIT_AXISDATA(iter);
+ sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
+
+ /* Retrieve the shape and strides from the axisdata */
+ for (idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) {
+ shape[ndim-idim-1] = NAD_SHAPE(axisdata);
+ strides[ndim-idim-1] = NAD_STRIDES(axisdata)[i];
+ }
+
+ Py_INCREF(dtype);
+ view = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, dtype, ndim,
+ shape, strides, dataptr,
+ writeable ? NPY_WRITEABLE : 0,
+ NULL);
+ if (view == NULL) {
+ return NULL;
+ }
+ /* Tell the view who owns the data */
+ Py_INCREF(obj);
+ view->base = (PyObject *)obj;
+ /* Make sure all the flags are good */
+ PyArray_UpdateFlags(view, NPY_UPDATE_ALL);
+
+ return view;
+}
+
+/*NUMPY_API
+ * Get a pointer to the index, if it is being tracked
+ */
+NPY_NO_EXPORT npy_intp *
+NpyIter_GetIndexPtr(NpyIter *iter)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ /*int ndim = NIT_NDIM(iter);*/
+ int niter = NIT_NITER(iter);
+
+ NpyIter_AxisData *axisdata = NIT_AXISDATA(iter);
+
+ if (itflags&NPY_ITFLAG_HASINDEX) {
+ /* The index is just after the data pointers */
+ return (npy_intp*)NAD_PTRS(axisdata) + niter;
+ }
+ else {
+ return NULL;
+ }
+}
+
+/*NUMPY_API
+ * Gets an array of read flags (1 per object being iterated)
+ */
+NPY_NO_EXPORT void
+NpyIter_GetReadFlags(NpyIter *iter, char *outreadflags)
+{
+ /*npy_uint32 itflags = NIT_ITFLAGS(iter);*/
+ /*int ndim = NIT_NDIM(iter);*/
+ int iiter, niter = NIT_NITER(iter);
+
+ char *op_itflags = NIT_OPITFLAGS(iter);
+
+ for (iiter = 0; iiter < niter; ++iiter) {
+ outreadflags[iiter] = (op_itflags[iiter]&NPY_OP_ITFLAG_READ) != 0;
+ }
+}
+
+/*NUMPY_API
+ * Gets an array of write flags (1 per object being iterated)
+ */
+NPY_NO_EXPORT void
+NpyIter_GetWriteFlags(NpyIter *iter, char *outwriteflags)
+{
+ /*npy_uint32 itflags = NIT_ITFLAGS(iter);*/
+ /*int ndim = NIT_NDIM(iter);*/
+ int iiter, niter = NIT_NITER(iter);
+
+ char *op_itflags = NIT_OPITFLAGS(iter);
+
+ for (iiter = 0; iiter < niter; ++iiter) {
+ outwriteflags[iiter] = (op_itflags[iiter]&NPY_OP_ITFLAG_WRITE) != 0;
+ }
+}
+
+
+/*NUMPY_API
+ * Get the array of strides for the inner loop (when HasInnerLoop is false)
+ *
+ * This function may be safely called without holding the Python GIL.
+ */
+NPY_NO_EXPORT npy_intp *
+NpyIter_GetInnerStrideArray(NpyIter *iter)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ /*int ndim = NIT_NDIM(iter);*/
+ int niter = NIT_NITER(iter);
+
+ if (itflags&NPY_ITFLAG_BUFFER) {
+ NpyIter_BufferData *data = NIT_BUFFERDATA(iter);
+ return NBF_STRIDES(data);
+ }
+ else {
+ NpyIter_AxisData *axisdata = NIT_AXISDATA(iter);
+ return NAD_STRIDES(axisdata);
+ }
+}
+
+/*NUMPY_API
+ * Gets the array of strides for the specified axis.
+ * If the iterator is tracking coordinates, gets the strides
+ * for the axis specified, otherwise gets the strides for
+ * the iteration axis as Fortran order (fastest-changing axis first).
+ *
+ * Returns NULL if an error occurs.
+ */
+NPY_NO_EXPORT npy_intp *
+NpyIter_GetAxisStrideArray(NpyIter *iter, int axis)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int idim, ndim = NIT_NDIM(iter);
+ int niter = NIT_NITER(iter);
+
+ char *perm = NIT_PERM(iter);
+ NpyIter_AxisData *axisdata = NIT_AXISDATA(iter);
+ npy_intp sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
+
+ if (axis < 0 || axis >= ndim) {
+ PyErr_SetString(PyExc_ValueError,
+ "axis out of bounds in iterator GetStrideAxisArray");
+ return NULL;
+ }
+
+ if (itflags&NPY_ITFLAG_HASCOORDS) {
+ /* Reverse axis, since the iterator treats them that way */
+ axis = ndim-1-axis;
+
+ /* First find the axis in question */
+ for (idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) {
+ if (perm[idim] == axis || -1-perm[idim] == axis) {
+ return NAD_STRIDES(axisdata);
+ }
+ }
+ }
+ else {
+ return NAD_STRIDES(NIT_INDEX_AXISDATA(axisdata, axis));
+ }
+
+ PyErr_SetString(PyExc_RuntimeError,
+ "internal error in iterator perm");
+ return NULL;
+}
+
+/*NUMPY_API
+ * Get an array of strides which are fixed. Any strides which may
+ * change during iteration receive the value NPY_MAX_INTP. Once
+ * the iterator is ready to iterate, call this to get the strides
+ * which will always be fixed in the inner loop, then choose optimized
+ * inner loop functions which take advantage of those fixed strides.
+ *
+ * This function may be safely called without holding the Python GIL.
+ */
+NPY_NO_EXPORT void
+NpyIter_GetInnerFixedStrideArray(NpyIter *iter, npy_intp *out_strides)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int ndim = NIT_NDIM(iter);
+ int iiter, niter = NIT_NITER(iter);
+
+ NpyIter_AxisData *axisdata0 = NIT_AXISDATA(iter);
+ npy_intp sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
+
+ if (itflags&NPY_ITFLAG_BUFFER) {
+ NpyIter_BufferData *data = NIT_BUFFERDATA(iter);
+ char *op_itflags = NIT_OPITFLAGS(iter);
+ npy_intp stride, *strides = NBF_STRIDES(data),
+ *ad_strides = NAD_STRIDES(axisdata0);
+ PyArray_Descr **dtypes = NIT_DTYPES(iter);
+
+ for (iiter = 0; iiter < niter; ++iiter) {
+ stride = strides[iiter];
+ /*
+ * Operands which are always/never buffered have fixed strides,
+ * and everything has fixed strides when ndim is 0 or 1
+ */
+ if (ndim <= 1 || (op_itflags[iiter]&
+ (NPY_OP_ITFLAG_CAST|NPY_OP_ITFLAG_BUFNEVER))) {
+ out_strides[iiter] = stride;
+ }
+ /* If it's a reduction, 0-stride inner loop may have fixed stride */
+ else if (stride == 0 && (itflags&NPY_ITFLAG_REDUCE)) {
+ /* If it's a reduction operand, definitely fixed stride */
+ if (op_itflags[iiter]&NPY_OP_ITFLAG_REDUCE) {
+ out_strides[iiter] = stride;
+ }
+ /*
+ * Otherwise it's a fixed stride if the stride is 0
+ * for all inner dimensions of the reduction double loop
+ */
+ else {
+ NpyIter_AxisData *axisdata = axisdata0;
+ int idim,
+ reduce_outerdim = NBF_REDUCE_OUTERDIM(data);
+ for (idim = 0; idim < reduce_outerdim; ++idim) {
+ if (NAD_STRIDES(axisdata)[iiter] != 0) {
+ break;
+ }
+ NIT_ADVANCE_AXISDATA(axisdata, 1);
+ }
+ /* If all the strides were 0, the stride won't change */
+ if (idim == reduce_outerdim) {
+ out_strides[iiter] = stride;
+ }
+ else {
+ out_strides[iiter] = NPY_MAX_INTP;
+ }
+ }
+ }
+ /*
+ * Inner loop contiguous array means its stride won't change when
+ * switching between buffering and not buffering
+ */
+ else if (ad_strides[iiter] == dtypes[iiter]->elsize) {
+ out_strides[iiter] = ad_strides[iiter];
+ }
+ /*
+ * Otherwise the strides can change if the operand is sometimes
+ * buffered, sometimes not.
+ */
+ else {
+ out_strides[iiter] = NPY_MAX_INTP;
+ }
+ }
+ }
+ else {
+ /* If there's no buffering, the strides are always fixed */
+ memcpy(out_strides, NAD_STRIDES(axisdata0), niter*NPY_SIZEOF_INTP);
+ }
+}
+
+
+/*NUMPY_API
+ * Get a pointer to the size of the inner loop (when HasInnerLoop is false)
+ *
+ * This function may be safely called without holding the Python GIL.
+ */
+NPY_NO_EXPORT npy_intp *
+NpyIter_GetInnerLoopSizePtr(NpyIter *iter)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ /*int ndim = NIT_NDIM(iter);*/
+ int niter = NIT_NITER(iter);
+
+ if (itflags&NPY_ITFLAG_BUFFER) {
+ NpyIter_BufferData *data = NIT_BUFFERDATA(iter);
+ return &NBF_SIZE(data);
+ }
+ else {
+ NpyIter_AxisData *axisdata = NIT_AXISDATA(iter);
+ return &NAD_SHAPE(axisdata);
+ }
+}
+
+/* Checks 'flags' for (C|F)_ORDER_INDEX, COORDS, and NO_INNER_ITERATION,
+ * setting the appropriate internal flags in 'itflags'.
+ *
+ * Returns 1 on success, 0 on error.
+ */
+static int
+npyiter_check_global_flags(npy_uint32 flags, npy_uint32* itflags)
+{
+ if ((flags&NPY_ITER_PER_OP_FLAGS) != 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "A per-operand flag was passed as a global flag "
+ "to the iterator constructor");
+ return 0;
+ }
+
+ /* Check for an index */
+ if (flags&(NPY_ITER_C_INDEX | NPY_ITER_F_INDEX)) {
+ if ((flags&(NPY_ITER_C_INDEX | NPY_ITER_F_INDEX)) ==
+ (NPY_ITER_C_INDEX | NPY_ITER_F_INDEX)) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator flags C_INDEX and "
+ "F_INDEX cannot both be specified");
+ return 0;
+ }
+ (*itflags) |= NPY_ITFLAG_HASINDEX;
+ }
+ /* Check if coordinates were requested */
+ if (flags&NPY_ITER_COORDS) {
+ /*
+ * This flag primarily disables dimension manipulations that
+ * would produce a different set of coordinates.
+ */
+ (*itflags) |= NPY_ITFLAG_HASCOORDS;
+ }
+ /* Check if the caller wants to handle inner iteration */
+ if (flags&NPY_ITER_NO_INNER_ITERATION) {
+ if ((*itflags)&(NPY_ITFLAG_HASINDEX|NPY_ITFLAG_HASCOORDS)) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator flag NO_INNER_ITERATION cannot be used "
+ "if coords or an index is being tracked");
+ return 0;
+ }
+ (*itflags) |= NPY_ITFLAG_NOINNER;
+ }
+ /* Ranged */
+ if (flags&NPY_ITER_RANGED) {
+ (*itflags) |= NPY_ITFLAG_RANGE;
+ if ((flags&NPY_ITER_NO_INNER_ITERATION) &&
+ !(flags&NPY_ITER_BUFFERED)) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator flag RANGED cannot be used with "
+ "the flag NO_INNER_ITERATION unless "
+ "BUFFERED is also enabled");
+ return 0;
+ }
+ }
+ /* Buffering */
+ if (flags&NPY_ITER_BUFFERED) {
+ (*itflags) |= NPY_ITFLAG_BUFFER;
+ if (flags&NPY_ITER_GROWINNER) {
+ (*itflags) |= NPY_ITFLAG_GROWINNER;
+ }
+ if (flags&NPY_ITER_DELAY_BUFALLOC) {
+ (*itflags) |= NPY_ITFLAG_DELAYBUF;
+ }
+ }
+
+ return 1;
+}
+
+static int
+npyiter_calculate_ndim(int niter, PyArrayObject **op_in,
+ int oa_ndim)
+{
+ /* If 'op_axes' is being used, force 'ndim' */
+ if (oa_ndim > 0 ) {
+ return oa_ndim;
+ }
+ /* Otherwise it's the maximum 'ndim' from the operands */
+ else {
+ int ndim = 0, iiter;
+
+ for (iiter = 0; iiter < niter; ++iiter) {
+ if (op_in[iiter] != NULL) {
+ int ondim = PyArray_NDIM(op_in[iiter]);
+ if (ondim > ndim) {
+ ndim = ondim;
+ }
+ }
+
+ }
+
+ return ndim;
+ }
+}
+
+static int
+npyiter_check_op_axes(int niter, int oa_ndim, int **op_axes)
+{
+ char axes_dupcheck[NPY_MAXDIMS];
+ int iiter, idim;
+
+ if (oa_ndim == 0 && op_axes != NULL) {
+ PyErr_Format(PyExc_ValueError,
+ "If 'op_axes' is not NULL in the iterator constructor, "
+ "'oa_ndim' must be greater than zero");
+ return 0;
+ }
+ else if (oa_ndim > 0) {
+ if (oa_ndim > NPY_MAXDIMS) {
+ PyErr_Format(PyExc_ValueError,
+ "Cannot construct an iterator with more than %d dimensions "
+ "(%d were requested for op_axes)",
+ (int)NPY_MAXDIMS, oa_ndim);
+ return 0;
+ }
+ else if (op_axes == NULL) {
+ PyErr_Format(PyExc_ValueError,
+ "If 'oa_ndim' is greater than zero in the iterator "
+ "constructor, then op_axes cannot be NULL");
+ return 0;
+ }
+
+ /* Check that there are no duplicates in op_axes */
+ for (iiter = 0; iiter < niter; ++iiter) {
+ int *axes = op_axes[iiter];
+ if (axes != NULL) {
+ memset(axes_dupcheck, 0, NPY_MAXDIMS);
+ for (idim = 0; idim < oa_ndim; ++idim) {
+ npy_intp i = axes[idim];
+ if (i >= 0) {
+ if (i >= NPY_MAXDIMS) {
+ PyErr_Format(PyExc_ValueError,
+ "The 'op_axes' provided to the iterator "
+ "constructor for operand %d "
+ "contained invalid "
+ "values %d", (int)iiter, (int)i);
+ return 0;
+ } else if(axes_dupcheck[i] == 1) {
+ PyErr_Format(PyExc_ValueError,
+ "The 'op_axes' provided to the iterator "
+ "constructor for operand %d "
+ "contained duplicate "
+ "value %d", (int)iiter, (int)i);
+ return 0;
+ }
+ else {
+ axes_dupcheck[i] = 1;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return 1;
+}
+
+/*
+ * Checks the per-operand input flags, and fills in op_itflags.
+ *
+ * Returns 1 on success, 0 on failure.
+ */
+static int
+npyiter_check_per_op_flags(npy_uint32 op_flags, char *op_itflags)
+{
+ if ((op_flags&NPY_ITER_GLOBAL_FLAGS) != 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "A global iterator flag was passed as a per-operand flag "
+ "to the iterator constructor");
+ return 0;
+ }
+
+ /* Check the read/write flags */
+ if (op_flags&NPY_ITER_READONLY) {
+ /* The read/write flags are mutually exclusive */
+ if (op_flags&(NPY_ITER_READWRITE|NPY_ITER_WRITEONLY)) {
+ PyErr_SetString(PyExc_ValueError,
+ "Only one of the iterator flags READWRITE, "
+ "READONLY, and WRITEONLY may be "
+ "specified for an operand");
+ return 0;
+ }
+
+ *op_itflags = NPY_OP_ITFLAG_READ;
+ }
+ else if (op_flags&NPY_ITER_READWRITE) {
+ /* The read/write flags are mutually exclusive */
+ if (op_flags&NPY_ITER_WRITEONLY) {
+ PyErr_SetString(PyExc_ValueError,
+ "Only one of the iterator flags READWRITE, "
+ "READONLY, and WRITEONLY may be "
+ "specified for an operand");
+ return 0;
+ }
+
+ *op_itflags = NPY_OP_ITFLAG_READ|NPY_OP_ITFLAG_WRITE;
+ }
+ else if(op_flags&NPY_ITER_WRITEONLY) {
+ *op_itflags = NPY_OP_ITFLAG_WRITE;
+ }
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "None of the iterator flags READWRITE, "
+ "READONLY, or WRITEONLY were "
+ "specified for an operand");
+ return 0;
+ }
+
+ /* Check the flags for temporary copies */
+ if (((*op_itflags)&NPY_OP_ITFLAG_WRITE) &&
+ (op_flags&(NPY_ITER_COPY|
+ NPY_ITER_UPDATEIFCOPY)) == NPY_ITER_COPY) {
+ PyErr_SetString(PyExc_ValueError,
+ "If an iterator operand is writeable, must use "
+ "the flag UPDATEIFCOPY instead of "
+ "COPY");
+ return 0;
+ }
+
+ return 1;
+}
+
+/*
+ * Prepares a a constructor operand. Assumes a reference to 'op'
+ * is owned, and that 'op' may be replaced. Fills in 'op_dtype'
+ * and 'ndim'.
+ *
+ * Returns 1 on success, 0 on failure.
+ */
+static int
+npyiter_prepare_one_operand(PyArrayObject **op,
+ char **op_dataptr,
+ PyArray_Descr *op_request_dtype,
+ PyArray_Descr **op_dtype,
+ npy_uint32 flags,
+ npy_uint32 op_flags, char *op_itflags)
+{
+ /* NULL operands must be automatically allocated outputs */
+ if (*op == NULL) {
+ /* ALLOCATE should be enabled */
+ if (!(op_flags&NPY_ITER_ALLOCATE)) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator operand was NULL, but automatic allocation as an "
+ "output wasn't requested");
+ return 0;
+ }
+ /* Writing should be enabled */
+ if (!((*op_itflags)&NPY_OP_ITFLAG_WRITE)) {
+ PyErr_SetString(PyExc_ValueError,
+ "Automatic allocation was requested for an iterator "
+ "operand, but it wasn't flagged for writing");
+ return 0;
+ }
+ /*
+ * Reading should be disabled if buffering is enabled without
+ * also enabling NPY_ITER_DELAY_BUFALLOC. In all other cases,
+ * the caller may initialize the allocated operand to a value
+ * before beginning iteration.
+ */
+ if (((flags&(NPY_ITER_BUFFERED|
+ NPY_ITER_DELAY_BUFALLOC)) == NPY_ITER_BUFFERED) &&
+ ((*op_itflags)&NPY_OP_ITFLAG_READ)) {
+ PyErr_SetString(PyExc_ValueError,
+ "Automatic allocation was requested for an iterator "
+ "operand, and it was flagged as readable, but buffering "
+ " without delayed allocation was enabled");
+ return 0;
+ }
+ *op_dataptr = NULL;
+ /* If a requested dtype was provided, use it, otherwise NULL */
+ Py_XINCREF(op_request_dtype);
+ *op_dtype = op_request_dtype;
+
+ return 1;
+ }
+
+ if (PyArray_Check(*op)) {
+ if (((*op_itflags)&NPY_OP_ITFLAG_WRITE) &&
+ (!PyArray_CHKFLAGS(*op, NPY_WRITEABLE))) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator operand was a non-writeable array, but was "
+ "flagged as writeable");
+ return 0;
+ }
+ if (!(flags&NPY_ITER_ZEROSIZE_OK) && PyArray_SIZE(*op) == 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iteration of zero-sized operands is not enabled");
+ return 0;
+ }
+ *op_dataptr = PyArray_BYTES(*op);
+ /* PyArray_DESCR does not give us a reference */
+ *op_dtype = PyArray_DESCR(*op);
+ if (*op_dtype == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator input array object has no dtype descr");
+ return 0;
+ }
+ Py_INCREF(*op_dtype);
+ /*
+ * If references weren't specifically allowed, make sure there
+ * are no references in the inputs or requested dtypes.
+ */
+ if (!(flags&NPY_ITER_REFS_OK)) {
+ PyArray_Descr *dt = PyArray_DESCR(*op);
+ if (((dt->flags&(NPY_ITEM_REFCOUNT|
+ NPY_ITEM_IS_POINTER)) != 0) ||
+ (dt != *op_dtype &&
+ (((*op_dtype)->flags&(NPY_ITEM_REFCOUNT|
+ NPY_ITEM_IS_POINTER))) != 0)) {
+ PyErr_SetString(PyExc_TypeError,
+ "Iterator operand or requested dtype holds "
+ "references, but the REFS_OK flag was not enabled");
+ return 0;
+ }
+ }
+ /*
+ * Checking whether casts are valid is done later, once the
+ * final data types have been selected. For now, just store the
+ * requested type.
+ */
+ if (op_request_dtype != NULL) {
+ /* We just have a borrowed reference to op_request_dtype */
+ Py_INCREF(op_request_dtype);
+ /* If it's a data type without a size, set the size */
+ if (op_request_dtype->elsize == 0) {
+ PyArray_DESCR_REPLACE(op_request_dtype);
+ if (op_request_dtype == NULL) {
+ return 0;
+ }
+
+ if (op_request_dtype->type_num == NPY_STRING) {
+ switch((*op_dtype)->type_num) {
+ case NPY_STRING:
+ op_request_dtype->elsize = (*op_dtype)->elsize;
+ break;
+ case NPY_UNICODE:
+ op_request_dtype->elsize = (*op_dtype)->elsize >> 2;
+ break;
+ }
+ }
+ else if (op_request_dtype->type_num == NPY_UNICODE) {
+ switch((*op_dtype)->type_num) {
+ case NPY_STRING:
+ op_request_dtype->elsize = (*op_dtype)->elsize << 2;
+ break;
+ case NPY_UNICODE:
+ op_request_dtype->elsize = (*op_dtype)->elsize;
+ break;
+ }
+ }
+ else if (op_request_dtype->type_num == NPY_VOID) {
+ op_request_dtype->elsize = (*op_dtype)->elsize;
+ }
+ }
+ /* Store the requested dtype */
+ Py_DECREF(*op_dtype);
+ *op_dtype = op_request_dtype;
+ }
+
+ /* Check if the operand is in the byte order requested */
+ if (op_flags&NPY_ITER_NBO) {
+ /* Check byte order */
+ if (!PyArray_ISNBO((*op_dtype)->byteorder)) {
+ PyArray_Descr *nbo_dtype;
+
+ /* Replace with a new descr which is in native byte order */
+ nbo_dtype = PyArray_DescrNewByteorder(*op_dtype, NPY_NATIVE);
+ Py_DECREF(*op_dtype);
+ *op_dtype = nbo_dtype;
+
+ NPY_IT_DBG_PRINT("Iterator: Setting NPY_OP_ITFLAG_CAST "
+ "because of NPY_ITER_NBO\n");
+ /* Indicate that byte order or alignment needs fixing */
+ *op_itflags |= NPY_OP_ITFLAG_CAST;
+ }
+ }
+ /* Check if the operand is aligned */
+ if (op_flags&NPY_ITER_ALIGNED) {
+ /* Check alignment */
+ if (!PyArray_ISALIGNED(*op)) {
+ NPY_IT_DBG_PRINT("Iterator: Setting NPY_OP_ITFLAG_CAST "
+ "because of NPY_ITER_ALIGNED\n");
+ *op_itflags |= NPY_OP_ITFLAG_CAST;
+ }
+ }
+ /*
+ * The check for NPY_ITER_CONTIG can only be done later,
+ * once the final iteration order is settled.
+ */
+ }
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator inputs must be ndarrays");
+ return 0;
+ }
+
+ return 1;
+}
+
+/*
+ * Process all the operands, copying new references so further processing
+ * can replace the arrays if copying is necessary.
+ */
+static int
+npyiter_prepare_operands(int niter, PyArrayObject **op_in,
+ PyArrayObject **op,
+ char **op_dataptr,
+ PyArray_Descr **op_request_dtypes,
+ PyArray_Descr **op_dtype,
+ npy_uint32 flags,
+ npy_uint32 *op_flags, char *op_itflags)
+{
+ int iiter, i;
+
+ for (iiter = 0; iiter < niter; ++iiter) {
+ op[iiter] = op_in[iiter];
+ Py_XINCREF(op[iiter]);
+ op_dtype[iiter] = NULL;
+
+ /* Check the readonly/writeonly flags, and fill in op_itflags */
+ if (!npyiter_check_per_op_flags(op_flags[iiter], &op_itflags[iiter])) {
+ for (i = 0; i <= iiter; ++i) {
+ Py_XDECREF(op[i]);
+ Py_XDECREF(op_dtype[i]);
+ }
+ return 0;
+ }
+
+ /*
+ * Prepare the operand. This produces an op_dtype[iiter] reference
+ * on success.
+ */
+ if (!npyiter_prepare_one_operand(&op[iiter],
+ &op_dataptr[iiter],
+ op_request_dtypes ? op_request_dtypes[iiter] : NULL,
+ &op_dtype[iiter],
+ flags,
+ op_flags[iiter], &op_itflags[iiter])) {
+ for (i = 0; i <= iiter; ++i) {
+ Py_XDECREF(op[i]);
+ Py_XDECREF(op_dtype[i]);
+ }
+ return 0;
+ }
+ }
+
+
+ /* If all the operands were NULL, it's an error */
+ if (op[0] == NULL) {
+ int all_null = 1;
+ for (iiter = 1; iiter < niter; ++iiter) {
+ if (op[iiter] != NULL) {
+ all_null = 0;
+ break;
+ }
+ }
+ if (all_null) {
+ for (i = 0; i < niter; ++i) {
+ Py_XDECREF(op[i]);
+ Py_XDECREF(op_dtype[i]);
+ }
+ PyErr_SetString(PyExc_ValueError,
+ "At least one iterator input must be non-NULL");
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+static const char *
+npyiter_casting_to_string(NPY_CASTING casting)
+{
+ switch (casting) {
+ case NPY_NO_CASTING:
+ return "'no'";
+ case NPY_EQUIV_CASTING:
+ return "'equiv'";
+ case NPY_SAFE_CASTING:
+ return "'safe'";
+ case NPY_SAME_KIND_CASTING:
+ return "'same_kind'";
+ case NPY_UNSAFE_CASTING:
+ return "'unsafe'";
+ default:
+ return "<unknown>";
+ }
+}
+
+static int
+npyiter_check_casting(int niter, PyArrayObject **op,
+ PyArray_Descr **op_dtype,
+ NPY_CASTING casting,
+ char *op_itflags)
+{
+ int iiter;
+
+ for(iiter = 0; iiter < niter; ++iiter) {
+ NPY_IT_DBG_PRINT1("Iterator: Checking casting for operand %d\n",
+ (int)iiter);
+#if NPY_IT_DBG_TRACING
+ printf("op: ");
+ if (op[iiter] != NULL) {
+ PyObject_Print((PyObject *)PyArray_DESCR(op[iiter]), stdout, 0);
+ }
+ else {
+ printf("<null>");
+ }
+ printf(", iter: ");
+ PyObject_Print((PyObject *)op_dtype[iiter], stdout, 0);
+ printf("\n");
+#endif
+ /* If the types aren't equivalent, a cast is necessary */
+ if (op[iiter] != NULL && !PyArray_EquivTypes(PyArray_DESCR(op[iiter]),
+ op_dtype[iiter])) {
+ /* Check read (op -> temp) casting */
+ if ((op_itflags[iiter]&NPY_OP_ITFLAG_READ) &&
+ !PyArray_CanCastArrayTo(op[iiter],
+ op_dtype[iiter],
+ casting)) {
+ PyErr_Format(PyExc_TypeError,
+ "Iterator operand %d dtype could not be cast "
+ "to the requested dtype, according to "
+ "the casting rule given, %s", (int)iiter,
+ npyiter_casting_to_string(casting));
+ return 0;
+ }
+ /* Check write (temp -> op) casting */
+ if ((op_itflags[iiter]&NPY_OP_ITFLAG_WRITE) &&
+ !PyArray_CanCastTypeTo(op_dtype[iiter],
+ PyArray_DESCR(op[iiter]),
+ casting)) {
+ PyErr_Format(PyExc_TypeError,
+ "Iterator requested dtype could not be cast "
+ "to the operand %d dtype, according to "
+ "the casting rule given, %s", (int)iiter,
+ npyiter_casting_to_string(casting));
+ return 0;
+ }
+
+ NPY_IT_DBG_PRINT("Iterator: Setting NPY_OP_ITFLAG_CAST "
+ "because the types aren't equivalent\n");
+ /* Indicate that this operand needs casting */
+ op_itflags[iiter] |= NPY_OP_ITFLAG_CAST;
+ }
+ }
+
+ return 1;
+}
+
+static PyObject *
+npyiter_shape_string(npy_intp n, npy_intp *vals, char *ending)
+{
+ npy_intp i;
+ PyObject *ret, *tmp;
+
+ /*
+ * Negative dimension indicates "newaxis", which can
+ * be discarded for printing if its a leading dimension.
+ * Find the first non-"newaxis" dimension.
+ */
+ i = 0;
+ while (i < n && vals[i] < 0) {
+ ++i;
+ }
+
+ if (i == n) {
+ return PyUString_FromFormat("()%s", ending);
+ }
+ else {
+ ret = PyUString_FromFormat("(%zd", vals[i++]);
+ if (ret == NULL) {
+ return NULL;
+ }
+ }
+
+ for (; i < n; ++i) {
+ if (vals[i] < 0) {
+ tmp = PyUString_FromString(",newaxis");
+ }
+ else {
+ tmp = PyUString_FromFormat(",%zd", vals[i]);
+ }
+ if (tmp == NULL) {
+ Py_DECREF(ret);
+ return NULL;
+ }
+
+ PyUString_ConcatAndDel(&ret, tmp);
+ if (ret == NULL) {
+ return NULL;
+ }
+ }
+
+ tmp = PyUString_FromFormat(")%s", ending);
+ PyUString_ConcatAndDel(&ret, tmp);
+ return ret;
+}
+
+/*
+ * Fills in the AXISDATA for the 'niter' operands, broadcasting
+ * the dimensionas as necessary. Also fills
+ * in the ITERSIZE data member.
+ *
+ * If op_axes is not NULL, it should point to an array of ndim-sized
+ * arrays, one for each op.
+ *
+ * Returns 1 on success, 0 on failure.
+ */
+static int
+npyiter_fill_axisdata(NpyIter *iter, npy_uint32 flags, char *op_itflags,
+ char **op_dataptr,
+ npy_uint32 *op_flags, int **op_axes,
+ int output_scalars)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int idim, ndim = NIT_NDIM(iter);
+ int iiter, niter = NIT_NITER(iter);
+
+ int ondim;
+ NpyIter_AxisData *axisdata;
+ npy_intp sizeof_axisdata;
+ PyArrayObject **op = NIT_OPERANDS(iter), *op_cur;
+ npy_intp broadcast_shape[NPY_MAXDIMS];
+
+ /* First broadcast the shapes together */
+ for (idim = 0; idim < ndim; ++idim) {
+ broadcast_shape[idim] = 1;
+ }
+ for (iiter = 0; iiter < niter; ++iiter) {
+ op_cur = op[iiter];
+ if (op_cur != NULL) {
+ npy_intp *shape = PyArray_DIMS(op_cur);
+ ondim = PyArray_NDIM(op_cur);
+
+ if (op_axes == NULL || op_axes[iiter] == NULL) {
+ /*
+ * Possible if op_axes are being used, but
+ * op_axes[iiter] is NULL
+ */
+ if (ondim > ndim) {
+ PyErr_SetString(PyExc_ValueError,
+ "input operand has more dimensions than allowed "
+ "by the axis remapping");
+ return 0;
+ }
+ for (idim = 0; idim < ondim; ++idim) {
+ npy_intp bshape = broadcast_shape[idim+ndim-ondim],
+ op_shape = shape[idim];
+ if (bshape == 1) {
+ broadcast_shape[idim+ndim-ondim] = op_shape;
+ }
+ else if (bshape != op_shape && op_shape != 1) {
+ goto broadcast_error;
+ }
+ }
+ }
+ else {
+ int *axes = op_axes[iiter];
+ for (idim = 0; idim < ndim; ++idim) {
+ int i = axes[idim];
+ if (i >= 0) {
+ if (i < ondim) {
+ npy_intp bshape = broadcast_shape[idim],
+ op_shape = shape[i];
+ if (bshape == 1) {
+ broadcast_shape[idim] = op_shape;
+ }
+ else if (bshape != op_shape && op_shape != 1) {
+ goto broadcast_error;
+ }
+ }
+ else {
+ PyErr_Format(PyExc_ValueError,
+ "Iterator input op_axes[%d][%d] (==%d) "
+ "is not a valid axis of op[%d], which "
+ "has %d dimensions ",
+ (int)iiter, (int)(ndim-idim-1), (int)i,
+ (int)iiter, (int)ondim);
+ return 0;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ axisdata = NIT_AXISDATA(iter);
+ sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
+
+ /* Now process the operands, filling in the axisdata */
+ for (idim = 0; idim < ndim; ++idim) {
+ npy_intp bshape = broadcast_shape[ndim-idim-1];
+ npy_intp *strides = NAD_STRIDES(axisdata);
+
+ NAD_SHAPE(axisdata) = bshape;
+ NAD_COORD(axisdata) = 0;
+ memcpy(NAD_PTRS(axisdata), op_dataptr, NPY_SIZEOF_INTP*niter);
+
+ for (iiter = 0; iiter < niter; ++iiter) {
+ op_cur = op[iiter];
+
+ if (op_axes == NULL || op_axes[iiter] == NULL) {
+ if (op_cur == NULL) {
+ strides[iiter] = 0;
+ }
+ else {
+ ondim = PyArray_NDIM(op_cur);
+ if (bshape == 1) {
+ strides[iiter] = 0;
+ if (idim >= ondim && !output_scalars &&
+ (op_flags[iiter]&NPY_ITER_NO_BROADCAST)) {
+ goto operand_different_than_broadcast;
+ }
+ }
+ else if (idim >= ondim ||
+ PyArray_DIM(op_cur, ondim-idim-1) == 1) {
+ strides[iiter] = 0;
+ if (op_flags[iiter]&NPY_ITER_NO_BROADCAST) {
+ goto operand_different_than_broadcast;
+ }
+ /* If it's writeable, this means a reduction */
+ if (op_itflags[iiter]&NPY_OP_ITFLAG_WRITE) {
+ if (!(flags&NPY_ITER_REDUCE_OK)) {
+ PyErr_SetString(PyExc_ValueError,
+ "output operand requires a reduction, but "
+ "reduction is not enabled");
+ return 0;
+ }
+ if (!(op_itflags[iiter]&NPY_OP_ITFLAG_READ)) {
+ PyErr_SetString(PyExc_ValueError,
+ "output operand requires a reduction, but "
+ "is flagged as write-only, not "
+ "read-write");
+ return 0;
+ }
+ NIT_ITFLAGS(iter) |= NPY_ITFLAG_REDUCE;
+ op_itflags[iiter] |= NPY_OP_ITFLAG_REDUCE;
+ }
+ }
+ else {
+ strides[iiter] = PyArray_STRIDE(op_cur, ondim-idim-1);
+ }
+ }
+ }
+ else {
+ int *axes = op_axes[iiter];
+ int i = axes[ndim-idim-1];
+ if (i >= 0) {
+ if (bshape == 1 || op_cur == NULL) {
+ strides[iiter] = 0;
+ }
+ else if (PyArray_DIM(op_cur, i) == 1) {
+ strides[iiter] = 0;
+ if (op_flags[iiter]&NPY_ITER_NO_BROADCAST) {
+ goto operand_different_than_broadcast;
+ }
+ /* If it's writeable, this means a reduction */
+ if (op_itflags[iiter]&NPY_OP_ITFLAG_WRITE) {
+ if (!(flags&NPY_ITER_REDUCE_OK)) {
+ PyErr_SetString(PyExc_ValueError,
+ "output operand requires a reduction, but "
+ "reduction is not enabled");
+ return 0;
+ }
+ if (!(op_itflags[iiter]&NPY_OP_ITFLAG_READ)) {
+ PyErr_SetString(PyExc_ValueError,
+ "output operand requires a reduction, but "
+ "is flagged as write-only, not "
+ "read-write");
+ return 0;
+ }
+ NIT_ITFLAGS(iter) |= NPY_ITFLAG_REDUCE;
+ op_itflags[iiter] |= NPY_OP_ITFLAG_REDUCE;
+ }
+ }
+ else {
+ strides[iiter] = PyArray_STRIDE(op_cur, i);
+ }
+ }
+ else if (bshape == 1) {
+ strides[iiter] = 0;
+ }
+ else {
+ strides[iiter] = 0;
+ /* If it's writeable, this means a reduction */
+ if (op_itflags[iiter]&NPY_OP_ITFLAG_WRITE) {
+ if (!(flags&NPY_ITER_REDUCE_OK)) {
+ PyErr_SetString(PyExc_ValueError,
+ "output operand requires a reduction, but "
+ "reduction is not enabled");
+ return 0;
+ }
+ if (!(op_itflags[iiter]&NPY_OP_ITFLAG_READ)) {
+ PyErr_SetString(PyExc_ValueError,
+ "output operand requires a reduction, but "
+ "is flagged as write-only, not "
+ "read-write");
+ return 0;
+ }
+ NIT_ITFLAGS(iter) |= NPY_ITFLAG_REDUCE;
+ op_itflags[iiter] |= NPY_OP_ITFLAG_REDUCE;
+ }
+ }
+ }
+ }
+
+ NIT_ADVANCE_AXISDATA(axisdata, 1);
+ }
+
+ /* Now fill in the ITERSIZE member */
+ NIT_ITERSIZE(iter) = broadcast_shape[0];
+ for (idim = 1; idim < ndim; ++idim) {
+ NIT_ITERSIZE(iter) *= broadcast_shape[idim];
+ }
+ /* The range defaults to everything */
+ NIT_ITERSTART(iter) = 0;
+ NIT_ITEREND(iter) = NIT_ITERSIZE(iter);
+
+ return 1;
+
+broadcast_error: {
+ PyObject *errmsg, *tmp;
+ npy_intp remdims[NPY_MAXDIMS];
+ char *tmpstr;
+
+ if (op_axes == NULL) {
+ errmsg = PyUString_FromString("operands could not be broadcast "
+ "together with shapes ");
+ for (iiter = 0; iiter < niter; ++iiter) {
+ if (op[iiter] != NULL) {
+ tmp = npyiter_shape_string(PyArray_NDIM(op[iiter]),
+ PyArray_DIMS(op[iiter]),
+ " ");
+ if (tmp == NULL) {
+ return 0;
+ }
+ PyUString_ConcatAndDel(&errmsg, tmp);
+ if (errmsg == NULL) {
+ return 0;
+ }
+ }
+ }
+ PyErr_SetObject(PyExc_ValueError, errmsg);
+ }
+ else {
+ errmsg = PyUString_FromString("operands could not be broadcast "
+ "together with remapped shapes "
+ "[original->remapped]: ");
+ for (iiter = 0; iiter < niter; ++iiter) {
+ if (op[iiter] != NULL) {
+ int *axes = op_axes[iiter];
+
+ tmpstr = (axes == NULL) ? " " : "->";
+ tmp = npyiter_shape_string(PyArray_NDIM(op[iiter]),
+ PyArray_DIMS(op[iiter]),
+ tmpstr);
+ if (tmp == NULL) {
+ return 0;
+ }
+ PyUString_ConcatAndDel(&errmsg, tmp);
+ if (errmsg == NULL) {
+ return 0;
+ }
+
+ if (axes != NULL) {
+ for (idim = 0; idim < ndim; ++idim) {
+ npy_intp i = axes[ndim-idim-1];
+
+ if (i >= 0 && i < PyArray_NDIM(op[iiter])) {
+ remdims[idim] = PyArray_DIM(op[iiter], i);
+ }
+ else {
+ remdims[idim] = -1;
+ }
+ }
+ tmp = npyiter_shape_string(ndim, remdims, " ");
+ if (tmp == NULL) {
+ return 0;
+ }
+ PyUString_ConcatAndDel(&errmsg, tmp);
+ if (errmsg == NULL) {
+ return 0;
+ }
+ }
+ }
+ }
+ PyErr_SetObject(PyExc_ValueError, errmsg);
+ }
+
+ return 0;
+ }
+
+operand_different_than_broadcast: {
+ npy_intp remdims[NPY_MAXDIMS];
+ PyObject *errmsg, *tmp;
+
+ /* Start of error message */
+ if (op_flags[iiter]&NPY_ITER_READONLY) {
+ errmsg = PyUString_FromString("non-broadcastable operand "
+ "with shape ");
+ }
+ else {
+ errmsg = PyUString_FromString("non-broadcastable output "
+ "operand with shape ");
+ }
+ if (errmsg == NULL) {
+ return 0;
+ }
+
+ /* Operand shape */
+ tmp = npyiter_shape_string(PyArray_NDIM(op[iiter]),
+ PyArray_DIMS(op[iiter]), "");
+ if (tmp == NULL) {
+ return 0;
+ }
+ PyUString_ConcatAndDel(&errmsg, tmp);
+ if (errmsg == NULL) {
+ return 0;
+ }
+ /* Remapped operand shape */
+ if (op_axes != NULL && op_axes[iiter] != NULL) {
+ int *axes = op_axes[iiter];
+
+ for (idim = 0; idim < ndim; ++idim) {
+ npy_intp i = axes[ndim-idim-1];
+
+ if (i >= 0 && i < PyArray_NDIM(op[iiter])) {
+ remdims[idim] = PyArray_DIM(op[iiter], i);
+ }
+ else {
+ remdims[idim] = -1;
+ }
+ }
+
+ tmp = PyUString_FromString(" [remapped to ");
+ if (tmp == NULL) {
+ return 0;
+ }
+ PyUString_ConcatAndDel(&errmsg, tmp);
+ if (errmsg == NULL) {
+ return 0;
+ }
+
+ tmp = npyiter_shape_string(ndim, remdims, "]");
+ if (tmp == NULL) {
+ return 0;
+ }
+ PyUString_ConcatAndDel(&errmsg, tmp);
+ if (errmsg == NULL) {
+ return 0;
+ }
+ }
+
+ tmp = PyUString_FromString(" doesn't match the broadcast shape ");
+ if (tmp == NULL) {
+ return 0;
+ }
+ PyUString_ConcatAndDel(&errmsg, tmp);
+ if (errmsg == NULL) {
+ return 0;
+ }
+
+ /* Fill in the broadcast shape */
+ axisdata = NIT_AXISDATA(iter);
+ for (idim = 0; idim < ndim; ++idim) {
+ remdims[ndim-idim-1] = NAD_SHAPE(axisdata);
+
+ NIT_ADVANCE_AXISDATA(axisdata, 1);
+ }
+
+ /* Broadcast shape */
+ tmp = npyiter_shape_string(ndim, remdims, "");
+ if (tmp == NULL) {
+ return 0;
+ }
+ PyUString_ConcatAndDel(&errmsg, tmp);
+ if (errmsg == NULL) {
+ return 0;
+ }
+
+ PyErr_SetObject(PyExc_ValueError, errmsg);
+
+ return 0;
+ }
+}
+
+/*
+ * Replaces the AXISDATA for the iiter'th operand, broadcasting
+ * the dimensions as necessary. Assumes the replacement array is
+ * exactly the same shape as the original array used when
+ * npy_fill_axisdata was called.
+ *
+ * If op_axes is not NULL, it should point to an ndim-sized
+ * array.
+ */
+static void
+npyiter_replace_axisdata(NpyIter *iter, int iiter,
+ PyArrayObject *op,
+ int op_ndim, char *op_dataptr,
+ int *op_axes)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int idim, ndim = NIT_NDIM(iter);
+ int niter = NIT_NITER(iter);
+
+ NpyIter_AxisData *axisdata0, *axisdata;
+ npy_intp sizeof_axisdata;
+ char *perm;
+ npy_intp baseoffset = 0;
+
+ perm = NIT_PERM(iter);
+ axisdata0 = NIT_AXISDATA(iter);
+ sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
+
+ /*
+ * Replace just the strides which were non-zero, and compute
+ * the base data address.
+ */
+ axisdata = axisdata0;
+
+ if (op_axes != NULL) {
+ for (idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) {
+ char p;
+ int i;
+ npy_intp shape;
+
+ /* Apply the perm to get the original axis */
+ p = perm[idim];
+ if (p < 0) {
+ i = op_axes[ndim+p];
+ }
+ else {
+ i = op_axes[ndim-p-1];
+ }
+
+ if (0 <= i && i < op_ndim) {
+ shape = PyArray_DIM(op, i);
+ if (shape != 1) {
+ npy_intp stride = PyArray_STRIDE(op, i);
+ if (p < 0) {
+ /* If the perm entry is negative, flip the axis */
+ NAD_STRIDES(axisdata)[iiter] = -stride;
+ baseoffset += stride*(shape-1);
+ }
+ else {
+ NAD_STRIDES(axisdata)[iiter] = stride;
+ }
+ }
+ }
+ }
+ }
+ else {
+ for (idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) {
+ char p;
+ int i;
+ npy_intp shape;
+
+ /* Apply the perm to get the original axis */
+ p = perm[idim];
+ if (p < 0) {
+ i = op_ndim+p;
+ }
+ else {
+ i = op_ndim-p-1;
+ }
+
+ if (i >= 0) {
+ shape = PyArray_DIM(op, i);
+ if (shape != 1) {
+ npy_intp stride = PyArray_STRIDE(op, i);
+ if (p < 0) {
+ /* If the perm entry is negative, flip the axis */
+ NAD_STRIDES(axisdata)[iiter] = -stride;
+ baseoffset += stride*(shape-1);
+ }
+ else {
+ NAD_STRIDES(axisdata)[iiter] = stride;
+ }
+ }
+ }
+ }
+ }
+
+ op_dataptr += baseoffset;
+
+ /* Now the base data pointer is calculated, set it everywhere it's needed */
+ NIT_RESETDATAPTR(iter)[iiter] = op_dataptr;
+ NIT_BASEOFFSETS(iter)[iiter] = baseoffset;
+ axisdata = axisdata0;
+ for (idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) {
+ NAD_PTRS(axisdata)[iiter] = op_dataptr;
+ }
+}
+
+/*
+ * Computes the iterator's index strides and initializes the index values
+ * to zero.
+ *
+ * This must be called before the axes (i.e. the AXISDATA array) may
+ * be reordered.
+ */
+static void
+npyiter_compute_index_strides(NpyIter *iter, npy_uint32 flags)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int idim, ndim = NIT_NDIM(iter);
+ int niter = NIT_NITER(iter);
+
+ npy_intp indexstride;
+ NpyIter_AxisData *axisdata;
+ npy_intp sizeof_axisdata;
+
+ /*
+ * If there is only one element being iterated, we just have
+ * to touch the first AXISDATA because nothing will ever be
+ * incremented.
+ */
+ if (NIT_ITERSIZE(iter) == 1) {
+ if (itflags&NPY_ITFLAG_HASINDEX) {
+ axisdata = NIT_AXISDATA(iter);
+ NAD_PTRS(axisdata)[niter] = 0;
+ }
+ return;
+ }
+
+ if (flags&NPY_ITER_C_INDEX) {
+ sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
+ axisdata = NIT_AXISDATA(iter);
+ indexstride = 1;
+ for(idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) {
+ npy_intp shape = NAD_SHAPE(axisdata);
+
+ if (shape == 1) {
+ NAD_STRIDES(axisdata)[niter] = 0;
+ }
+ else {
+ NAD_STRIDES(axisdata)[niter] = indexstride;
+ }
+ NAD_PTRS(axisdata)[niter] = 0;
+ indexstride *= shape;
+ }
+ }
+ else if (flags&NPY_ITER_F_INDEX) {
+ sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
+ axisdata = NIT_INDEX_AXISDATA(NIT_AXISDATA(iter), ndim-1);
+ indexstride = 1;
+ for(idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, -1)) {
+ npy_intp shape = NAD_SHAPE(axisdata);
+
+ if (shape == 1) {
+ NAD_STRIDES(axisdata)[niter] = 0;
+ }
+ else {
+ NAD_STRIDES(axisdata)[niter] = indexstride;
+ }
+ NAD_PTRS(axisdata)[niter] = 0;
+ indexstride *= shape;
+ }
+ }
+}
+
+/*
+ * If the order is NPY_KEEPORDER, lets the iterator find the best
+ * iteration order, otherwise forces it. Indicates in the itflags that
+ * whether the iteration order was forced.
+ */
+static void
+npyiter_apply_forced_iteration_order(NpyIter *iter, NPY_ORDER order)
+{
+ /*npy_uint32 itflags = NIT_ITFLAGS(iter);*/
+ int ndim = NIT_NDIM(iter);
+ int iiter, niter = NIT_NITER(iter);
+
+ switch (order) {
+ case NPY_CORDER:
+ NIT_ITFLAGS(iter) |= NPY_ITFLAG_FORCEDORDER;
+ break;
+ case NPY_FORTRANORDER:
+ NIT_ITFLAGS(iter) |= NPY_ITFLAG_FORCEDORDER;
+ /* Only need to actually do something if there is more than 1 dim */
+ if (ndim > 1) {
+ npyiter_reverse_axis_ordering(iter);
+ }
+ break;
+ case NPY_ANYORDER:
+ NIT_ITFLAGS(iter) |= NPY_ITFLAG_FORCEDORDER;
+ /* Only need to actually do something if there is more than 1 dim */
+ if (ndim > 1) {
+ PyArrayObject **op = NIT_OPERANDS(iter);
+ int forder = 1;
+
+ /* Check that all the array inputs are fortran order */
+ for (iiter = 0; iiter < niter; ++iiter, ++op) {
+ if (*op && !PyArray_CHKFLAGS(*op, NPY_F_CONTIGUOUS)) {
+ forder = 0;
+ break;
+ }
+ }
+
+ if (forder) {
+ npyiter_reverse_axis_ordering(iter);
+ }
+ }
+ break;
+ case NPY_KEEPORDER:
+ /* Don't set the forced order flag here... */
+ break;
+ }
+}
+
+
+/*
+ * This function negates any strides in the iterator
+ * which are negative. When iterating more than one
+ * object, it only flips strides when they are all
+ * negative or zero.
+ */
+static void
+npyiter_flip_negative_strides(NpyIter *iter)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int idim, ndim = NIT_NDIM(iter);
+ int iiter, niter = NIT_NITER(iter);
+
+ npy_intp istrides, nstrides = NAD_NSTRIDES();
+ NpyIter_AxisData *axisdata, *axisdata0;
+ npy_intp *baseoffsets;
+ npy_intp sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
+ int any_flipped = 0;
+
+ axisdata0 = axisdata = NIT_AXISDATA(iter);
+ baseoffsets = NIT_BASEOFFSETS(iter);
+ for (idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) {
+ npy_intp *strides = NAD_STRIDES(axisdata);
+ int any_negative = 0;
+
+ /*
+ * Check the signs of all the strides, excluding
+ * the index stride at the end.
+ */
+ for (iiter = 0; iiter < niter; ++iiter) {
+ if (strides[iiter] < 0) {
+ any_negative = 1;
+ }
+ else if (strides[iiter] != 0) {
+ break;
+ }
+ }
+ /*
+ * If at least on stride is negative and none are positive,
+ * flip all the strides for this dimension.
+ */
+ if (any_negative && iiter == niter) {
+ npy_intp shapem1 = NAD_SHAPE(axisdata) - 1;
+
+ for (istrides = 0; istrides < nstrides; ++istrides) {
+ npy_intp stride = strides[istrides];
+
+ /* Adjust the base pointers to start at the end */
+ baseoffsets[istrides] += shapem1 * stride;
+ /* Flip the stride */
+ strides[istrides] = -stride;
+ }
+ /* Make the perm entry negative, so getcoords knows it's flipped */
+ NIT_PERM(iter)[idim] = -1-NIT_PERM(iter)[idim];
+
+ any_flipped = 1;
+ }
+ }
+
+ /*
+ * If any strides were flipped, the base pointers were adjusted
+ * in the first AXISDATA, and need to be copied to all the rest
+ */
+ if (any_flipped) {
+ char **resetdataptr = NIT_RESETDATAPTR(iter);
+
+ for (istrides = 0; istrides < nstrides; ++istrides) {
+ resetdataptr[istrides] += baseoffsets[istrides];
+ }
+ axisdata = axisdata0;
+ for (idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) {
+ char **ptrs = NAD_PTRS(axisdata);
+ for (istrides = 0; istrides < nstrides; ++istrides) {
+ ptrs[istrides] = resetdataptr[istrides];
+ }
+ }
+ /*
+ * Indicate that some of the perm entries are negative,
+ * and that it's not (strictly speaking) the identity perm.
+ */
+ NIT_ITFLAGS(iter) = (NIT_ITFLAGS(iter)|NPY_ITFLAG_NEGPERM) &
+ ~NPY_ITFLAG_IDENTPERM;
+ }
+}
+
+static void
+npyiter_reverse_axis_ordering(NpyIter *iter)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int ndim = NIT_NDIM(iter);
+ int niter = NIT_NITER(iter);
+
+ npy_intp i, temp, size;
+ npy_intp *first, *last;
+ char *perm;
+
+ size = NIT_AXISDATA_SIZEOF(itflags, ndim, niter)/NPY_SIZEOF_INTP;
+ first = (npy_intp*)NIT_AXISDATA(iter);
+ last = first + (ndim-1)*size;
+
+ /* This loop reverses the order of the AXISDATA array */
+ while (first < last) {
+ for (i = 0; i < size; ++i) {
+ temp = first[i];
+ first[i] = last[i];
+ last[i] = temp;
+ }
+ first += size;
+ last -= size;
+ }
+
+ /* Store the perm we applied */
+ perm = NIT_PERM(iter);
+ for(i = ndim-1; i >= 0; --i, ++perm) {
+ *perm = (char)i;
+ }
+
+ NIT_ITFLAGS(iter) &= ~NPY_ITFLAG_IDENTPERM;
+}
+
+static npy_intp intp_abs(npy_intp x)
+{
+ return (x < 0) ? -x : x;
+}
+
+static void
+npyiter_find_best_axis_ordering(NpyIter *iter)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int idim, ndim = NIT_NDIM(iter);
+ int iiter, niter = NIT_NITER(iter);
+
+ npy_intp ax_i0, ax_i1, ax_ipos;
+ char ax_j0, ax_j1;
+ char *perm;
+ NpyIter_AxisData *axisdata = NIT_AXISDATA(iter);
+ npy_intp sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
+ int permuted = 0;
+
+ perm = NIT_PERM(iter);
+
+ /*
+ * Do a custom stable insertion sort. Note that because
+ * the AXISDATA has been reversed from C order, this
+ * is sorting from smallest stride to biggest stride.
+ */
+ for (ax_i0 = 1; ax_i0 < ndim; ++ax_i0) {
+ npy_intp *strides0;
+
+ /* 'ax_ipos' is where perm[ax_i0] will get inserted */
+ ax_ipos = ax_i0;
+ ax_j0 = perm[ax_i0];
+
+ strides0 = NAD_STRIDES(NIT_INDEX_AXISDATA(axisdata, ax_j0));
+ for (ax_i1 = ax_i0-1; ax_i1 >= 0; --ax_i1) {
+ int ambig = 1, shouldswap = 0;
+ npy_intp *strides1;
+
+ ax_j1 = perm[ax_i1];
+
+ strides1 = NAD_STRIDES(NIT_INDEX_AXISDATA(axisdata, ax_j1));
+
+ for (iiter = 0; iiter < niter; ++iiter) {
+ if (strides0[iiter] != 0 && strides1[iiter] != 0) {
+ if (intp_abs(strides1[iiter]) <=
+ intp_abs(strides0[iiter])) {
+ /*
+ * Set swap even if it's not ambiguous already,
+ * because in the case of conflicts between
+ * different operands, C-order wins.
+ */
+ shouldswap = 0;
+ }
+ else {
+ /* Only set swap if it's still ambiguous */
+ if (ambig) {
+ shouldswap = 1;
+ }
+ }
+
+ /*
+ * A comparison has been done, so it's
+ * no longer ambiguous
+ */
+ ambig = 0;
+ }
+ }
+ /*
+ * If the comparison was unambiguous, either shift
+ * 'ax_ipos' to 'ax_i1' or stop looking for an insertion
+ * point
+ */
+ if (!ambig) {
+ if (shouldswap) {
+ ax_ipos = ax_i1;
+ }
+ else {
+ break;
+ }
+ }
+ }
+
+ /* Insert perm[ax_i0] into the right place */
+ if (ax_ipos != ax_i0) {
+ for (ax_i1 = ax_i0; ax_i1 > ax_ipos; --ax_i1) {
+ perm[ax_i1] = perm[ax_i1-1];
+ }
+ perm[ax_ipos] = ax_j0;
+ permuted = 1;
+ }
+ }
+
+ /* Apply the computed permutation to the AXISDATA array */
+ if (permuted == 1) {
+ npy_intp i, size = sizeof_axisdata/NPY_SIZEOF_INTP;
+ NpyIter_AxisData *ad_i;
+
+ /* Use the coord as a flag, set each to 1 */
+ ad_i = axisdata;
+ for (idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(ad_i, 1)) {
+ NAD_COORD(ad_i) = 1;
+ }
+ /* Apply the permutation by following the cycles */
+ for (idim = 0; idim < ndim; ++idim) {
+ ad_i = NIT_INDEX_AXISDATA(axisdata, idim);
+
+ /* If this axis hasn't been touched yet, process it */
+ if (NAD_COORD(ad_i) == 1) {
+ char pidim = perm[idim], qidim;
+ npy_intp tmp;
+ NpyIter_AxisData *ad_p, *ad_q;
+
+ if (pidim != idim) {
+ /* Follow the cycle, copying the data */
+ for (i = 0; i < size; ++i) {
+ qidim = (char)idim;
+ pidim = perm[idim];
+ ad_q = ad_i;
+ tmp = *((npy_intp*)ad_q + i);
+ while (pidim != idim) {
+ ad_p = NIT_INDEX_AXISDATA(axisdata, pidim);
+ *((npy_intp*)ad_q + i) = *((npy_intp*)ad_p + i);
+
+ qidim = pidim;
+ ad_q = ad_p;
+ pidim = perm[(int)pidim];
+ }
+ *((npy_intp*)ad_q + i) = tmp;
+ }
+ /* Follow the cycle again, marking it as done */
+ pidim = perm[idim];
+
+ while (pidim != idim) {
+ NAD_COORD(NIT_INDEX_AXISDATA(axisdata, pidim)) = 0;
+ pidim = perm[(int)pidim];
+ }
+ }
+ NAD_COORD(ad_i) = 0;
+ }
+ }
+ /* Clear the identity perm flag */
+ NIT_ITFLAGS(iter) &= ~NPY_ITFLAG_IDENTPERM;
+ }
+}
+
+static void
+npyiter_coalesce_axes(NpyIter *iter)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int idim, ndim = NIT_NDIM(iter);
+ int niter = NIT_NITER(iter);
+
+ npy_intp istrides, nstrides = NAD_NSTRIDES();
+ NpyIter_AxisData *axisdata = NIT_AXISDATA(iter);
+ npy_intp sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
+ NpyIter_AxisData *ad_compress;
+ npy_intp new_ndim = 1;
+
+ /* The HASCOORDS or IDENTPERM flags do not apply after coalescing */
+ NIT_ITFLAGS(iter) &= ~(NPY_ITFLAG_IDENTPERM|NPY_ITFLAG_HASCOORDS);
+
+ axisdata = NIT_AXISDATA(iter);
+ ad_compress = axisdata;
+
+ for (idim = 0; idim < ndim-1; ++idim) {
+ int can_coalesce = 1;
+ npy_intp shape0 = NAD_SHAPE(ad_compress);
+ npy_intp shape1 = NAD_SHAPE(NIT_INDEX_AXISDATA(axisdata, 1));
+ npy_intp *strides0 = NAD_STRIDES(ad_compress);
+ npy_intp *strides1 = NAD_STRIDES(NIT_INDEX_AXISDATA(axisdata, 1));
+
+ /* Check that all the axes can be coalesced */
+ for (istrides = 0; istrides < nstrides; ++istrides) {
+ if (!((shape0 == 1 && strides0[istrides] == 0) ||
+ (shape1 == 1 && strides1[istrides] == 0)) &&
+ (strides0[istrides]*shape0 != strides1[istrides])) {
+ can_coalesce = 0;
+ break;
+ }
+ }
+
+ if (can_coalesce) {
+ npy_intp *strides = NAD_STRIDES(ad_compress);
+
+ NIT_ADVANCE_AXISDATA(axisdata, 1);
+ NAD_SHAPE(ad_compress) *= NAD_SHAPE(axisdata);
+ for (istrides = 0; istrides < nstrides; ++istrides) {
+ if (strides[istrides] == 0) {
+ strides[istrides] = NAD_STRIDES(axisdata)[istrides];
+ }
+ }
+ }
+ else {
+ NIT_ADVANCE_AXISDATA(axisdata, 1);
+ NIT_ADVANCE_AXISDATA(ad_compress, 1);
+ if (ad_compress != axisdata) {
+ memcpy(ad_compress, axisdata, sizeof_axisdata);
+ }
+ ++new_ndim;
+ }
+ }
+
+ /*
+ * If the number of axes shrunk, reset the perm and
+ * compress the data into the new layout.
+ */
+ if (new_ndim < ndim) {
+ char *perm = NIT_PERM(iter);
+
+ /* Reset to an identity perm */
+ for (idim = 0; idim < new_ndim; ++idim) {
+ perm[idim] = (char)idim;
+ }
+ NIT_NDIM(iter) = new_ndim;
+ }
+}
+
+/*
+ * Allocates a temporary array which can be used to replace op
+ * in the iteration. Its dtype will be op_dtype.
+ *
+ * The result array has a memory ordering which matches the iterator,
+ * which may or may not match that of op. The parameter 'shape' may be
+ * NULL, in which case it is filled in from the iterator's shape.
+ *
+ * This function must be called before any axes are coalesced.
+ */
+static PyArrayObject *
+npyiter_new_temp_array(NpyIter *iter, PyTypeObject *subtype,
+ npy_uint32 flags, char *op_itflags,
+ int op_ndim, npy_intp *shape,
+ PyArray_Descr *op_dtype, int *op_axes)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int idim, ndim = NIT_NDIM(iter);
+ int niter = NIT_NITER(iter);
+
+ char *perm = NIT_PERM(iter);
+ npy_intp new_shape[NPY_MAXDIMS], strides[NPY_MAXDIMS],
+ stride = op_dtype->elsize;
+ char reversestride[NPY_MAXDIMS], anyreverse = 0;
+ NpyIter_AxisData *axisdata;
+ npy_intp sizeof_axisdata;
+ npy_intp i;
+
+ PyArrayObject *ret;
+
+ /* If it's a scalar, don't need to check the axes */
+ if (op_ndim == 0) {
+ Py_INCREF(op_dtype);
+ ret = (PyArrayObject *)PyArray_NewFromDescr(subtype, op_dtype, 0,
+ NULL, NULL, NULL, 0, NULL);
+
+ /* Double-check that the subtype didn't mess with the dimensions */
+ if (PyArray_NDIM(ret) != 0) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Iterator automatic output has an array subtype "
+ "which changed the dimensions of the output");
+ Py_DECREF(ret);
+ return NULL;
+ }
+
+ return ret;
+ }
+
+ axisdata = NIT_AXISDATA(iter);
+ sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
+
+ memset(reversestride, 0, NPY_MAXDIMS);
+ /* Initialize the strides to invalid values */
+ for (i = 0; i < NPY_MAXDIMS; ++i) {
+ strides[i] = NPY_MAX_INTP;
+ }
+
+ if (op_axes != NULL) {
+ for (idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) {
+ char p;
+
+ /* Apply the perm to get the original axis */
+ p = perm[idim];
+ if (p < 0) {
+ i = op_axes[ndim+p];
+ }
+ else {
+ i = op_axes[ndim-p-1];
+ }
+
+ if (i >= 0) {
+ NPY_IT_DBG_PRINT3("Iterator: Setting allocated stride %d "
+ "for iterator dimension %d to %d\n", (int)i,
+ (int)idim, (int)stride);
+ strides[i] = stride;
+ if (p < 0) {
+ reversestride[i] = 1;
+ anyreverse = 1;
+ }
+ else {
+ reversestride[i] = 0;
+ }
+ if (shape == NULL) {
+ new_shape[i] = NAD_SHAPE(axisdata);
+ stride *= new_shape[i];
+ if (i >= ndim) {
+ PyErr_SetString(PyExc_ValueError,
+ "automatically allocated output array "
+ "specified with an inconsistent axis mapping");
+ return NULL;
+ }
+ }
+ else {
+ stride *= shape[i];
+ }
+ }
+ else {
+ if (shape == NULL) {
+ /*
+ * If deleting this axis produces a reduction, but
+ * reduction wasn't enabled, throw an error
+ */
+ if (NAD_SHAPE(axisdata) != 1) {
+ if (!(flags&NPY_ITER_REDUCE_OK)) {
+ PyErr_SetString(PyExc_ValueError,
+ "output requires a reduction, but "
+ "reduction is not enabled");
+ return NULL;
+ }
+ if (!((*op_itflags)&NPY_OP_ITFLAG_READ)) {
+ PyErr_SetString(PyExc_ValueError,
+ "output requires a reduction, but "
+ "is flagged as write-only, not read-write");
+ return NULL;
+ }
+
+ NPY_IT_DBG_PRINT("Iterator: Indicating that a reduction "
+ "is occurring\n");
+ /* Indicate that a reduction is occurring */
+ NIT_ITFLAGS(iter) |= NPY_ITFLAG_REDUCE;
+ (*op_itflags) |= NPY_OP_ITFLAG_REDUCE;
+ }
+ }
+ }
+ }
+ }
+ else {
+ for (idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) {
+ char p;
+
+ /* Apply the perm to get the original axis */
+ p = perm[idim];
+ if (p < 0) {
+ i = op_ndim+p;
+ }
+ else {
+ i = op_ndim-p-1;
+ }
+
+ if (i >= 0) {
+ NPY_IT_DBG_PRINT3("Iterator: Setting allocated stride %d "
+ "for iterator dimension %d to %d\n", (int)i,
+ (int)idim, (int)stride);
+ strides[i] = stride;
+ if (p < 0) {
+ reversestride[i] = 1;
+ anyreverse = 1;
+ }
+ else {
+ reversestride[i] = 0;
+ }
+ if (shape == NULL) {
+ new_shape[i] = NAD_SHAPE(axisdata);
+ stride *= new_shape[i];
+ }
+ else {
+ stride *= shape[i];
+ }
+ }
+ }
+ }
+
+ /*
+ * If custom axes were specified, some dimensions may not have been used.
+ * Add the REDUCE itflag if this creates a reduction situation.
+ */
+ if (shape == NULL) {
+ /* Ensure there are no dimension gaps in op_axes, and find op_ndim */
+ op_ndim = ndim;
+ if (op_axes != NULL) {
+ for (i = 0; i < ndim; ++i) {
+ if (strides[i] == NPY_MAX_INTP) {
+ if (op_ndim == ndim) {
+ op_ndim = i;
+ }
+ }
+ /*
+ * If there's a gap in the array's dimensions, it's an error.
+ * For example, op_axes of [0,2] for the automatically
+ * allocated output.
+ */
+ else if (op_ndim != ndim) {
+ PyErr_SetString(PyExc_ValueError,
+ "automatically allocated output array "
+ "specified with an inconsistent axis mapping");
+ return NULL;
+ }
+ }
+ }
+ }
+ else {
+ for (i = 0; i < op_ndim; ++i) {
+ if (strides[i] == NPY_MAX_INTP) {
+ npy_intp factor, new_strides[NPY_MAXDIMS],
+ itemsize;
+
+ /* Fill in the missing strides in C order */
+ factor = 1;
+ itemsize = op_dtype->elsize;
+ for (i = op_ndim-1; i >= 0; --i) {
+ if (strides[i] == NPY_MAX_INTP) {
+ new_strides[i] = factor * itemsize;
+ factor *= shape[i];
+ }
+ }
+
+ /*
+ * Copy the missing strides, and multiply the existing strides
+ * by the calculated factor. This way, the missing strides
+ * are tighter together in memory, which is good for nested
+ * loops.
+ */
+ for (i = 0; i < op_ndim; ++i) {
+ if (strides[i] == NPY_MAX_INTP) {
+ strides[i] = new_strides[i];
+ }
+ else {
+ strides[i] *= factor;
+ }
+ }
+
+ break;
+ }
+ }
+ }
+
+ /* If shape was NULL, set it to the shape we calculated */
+ if (shape == NULL) {
+ shape = new_shape;
+ }
+
+ /* Allocate the temporary array */
+ Py_INCREF(op_dtype);
+ ret = (PyArrayObject *)PyArray_NewFromDescr(subtype, op_dtype, op_ndim,
+ shape, strides, NULL, 0, NULL);
+ if (ret == NULL) {
+ return NULL;
+ }
+
+ /* If there are any reversed axes, create a view that reverses them */
+ if (anyreverse) {
+ char *dataptr = PyArray_DATA(ret);
+ PyArrayObject *newret;
+
+ for (idim = 0; idim < op_ndim; ++idim) {
+ if (reversestride[idim]) {
+ dataptr += strides[idim]*(shape[idim]-1);
+ strides[idim] = -strides[idim];
+ }
+ }
+ Py_INCREF(op_dtype);
+ newret = (PyArrayObject *)PyArray_NewFromDescr(subtype,
+ op_dtype, op_ndim,
+ shape, strides, dataptr,
+ NPY_WRITEABLE, NULL);
+ if (newret == NULL) {
+ Py_DECREF(ret);
+ return NULL;
+ }
+ newret->base = (PyObject *)ret;
+ ret = newret;
+ }
+
+ /* Make sure all the flags are good */
+ PyArray_UpdateFlags(ret, NPY_UPDATE_ALL);
+
+ /* Double-check that the subtype didn't mess with the dimensions */
+ if (subtype != &PyArray_Type) {
+ if (PyArray_NDIM(ret) != op_ndim ||
+ !PyArray_CompareLists(shape, PyArray_DIMS(ret), op_ndim)) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Iterator automatic output has an array subtype "
+ "which changed the dimensions of the output");
+ Py_DECREF(ret);
+ return NULL;
+ }
+ }
+
+ return ret;
+}
+
+static int
+npyiter_allocate_arrays(NpyIter *iter,
+ npy_uint32 flags,
+ PyArray_Descr **op_dtype, PyTypeObject *subtype,
+ npy_uint32 *op_flags, char *op_itflags,
+ int **op_axes, int output_scalars)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int idim, ndim = NIT_NDIM(iter);
+ int iiter, niter = NIT_NITER(iter);
+
+ NpyIter_BufferData *bufferdata = NULL;
+ PyArrayObject **op = NIT_OPERANDS(iter);
+
+ if (itflags&NPY_ITFLAG_BUFFER) {
+ bufferdata = NIT_BUFFERDATA(iter);
+ }
+
+
+ for (iiter = 0; iiter < niter; ++iiter) {
+ /* NULL means an output the iterator should allocate */
+ if (op[iiter] == NULL) {
+ PyArrayObject *out;
+ PyTypeObject *op_subtype;
+ int ondim = output_scalars ? 0 : ndim;
+
+ /* Check whether the subtype was disabled */
+ op_subtype = (op_flags[iiter]&NPY_ITER_NO_SUBTYPE) ?
+ &PyArray_Type : subtype;
+
+ /* Allocate the output array */
+ out = npyiter_new_temp_array(iter, op_subtype,
+ flags, &op_itflags[iiter],
+ ondim,
+ NULL,
+ op_dtype[iiter],
+ op_axes ? op_axes[iiter] : NULL);
+ if (out == NULL) {
+ return 0;
+ }
+
+ op[iiter] = out;
+
+ /*
+ * Now we need to replace the pointers and strides with values
+ * from the new array.
+ */
+ npyiter_replace_axisdata(iter, iiter, op[iiter], ondim,
+ PyArray_DATA(op[iiter]), op_axes ? op_axes[iiter] : NULL);
+
+ /* New arrays are aligned and need no cast */
+ op_itflags[iiter] |= NPY_OP_ITFLAG_ALIGNED;
+ op_itflags[iiter] &= ~NPY_OP_ITFLAG_CAST;
+ }
+ /*
+ * If casting is required, the operand is read-only, and
+ * it's an array scalar, make a copy whether or not the
+ * copy flag is enabled.
+ */
+ else if ((op_itflags[iiter]&(NPY_OP_ITFLAG_CAST|
+ NPY_OP_ITFLAG_READ|
+ NPY_OP_ITFLAG_WRITE)) == (NPY_OP_ITFLAG_CAST|
+ NPY_OP_ITFLAG_READ) &&
+ PyArray_NDIM(op[iiter]) == 0) {
+ PyArrayObject *temp;
+ Py_INCREF(op_dtype[iiter]);
+ temp = (PyArrayObject *)PyArray_NewFromDescr(
+ &PyArray_Type, op_dtype[iiter],
+ 0, NULL, NULL, NULL, 0, NULL);
+ if (temp == NULL) {
+ return 0;
+ }
+ if (PyArray_CopyInto(temp, op[iiter]) != 0) {
+ Py_DECREF(temp);
+ return 0;
+ }
+ Py_DECREF(op[iiter]);
+ op[iiter] = temp;
+
+ /*
+ * Now we need to replace the pointers and strides with values
+ * from the temporary array.
+ */
+ npyiter_replace_axisdata(iter, iiter, op[iiter], 0,
+ PyArray_DATA(op[iiter]), NULL);
+
+ /*
+ * New arrays are aligned need no cast, and in the case
+ * of scalars, always have stride 0 so never need buffering
+ */
+ op_itflags[iiter] |= (NPY_OP_ITFLAG_ALIGNED|
+ NPY_OP_ITFLAG_BUFNEVER);
+ op_itflags[iiter] &= ~NPY_OP_ITFLAG_CAST;
+ if (itflags&NPY_ITFLAG_BUFFER) {
+ NBF_STRIDES(bufferdata)[iiter] = 0;
+ }
+ }
+ /* If casting is required and permitted */
+ else if ((op_itflags[iiter]&NPY_OP_ITFLAG_CAST) &&
+ (op_flags[iiter]&(NPY_ITER_COPY|NPY_ITER_UPDATEIFCOPY))) {
+ PyArrayObject *temp;
+ int ondim = PyArray_NDIM(op[iiter]);
+
+ /* Allocate the temporary array, if possible */
+ temp = npyiter_new_temp_array(iter, &PyArray_Type,
+ flags, &op_itflags[iiter],
+ ondim,
+ PyArray_DIMS(op[iiter]),
+ op_dtype[iiter],
+ op_axes ? op_axes[iiter] : NULL);
+ if (temp == NULL) {
+ return 0;
+ }
+
+ /* If the data will be read, copy it into temp */
+ if (op_itflags[iiter]&NPY_OP_ITFLAG_READ) {
+ if (PyArray_CopyInto(temp, op[iiter]) != 0) {
+ Py_DECREF(temp);
+ return 0;
+ }
+ }
+ /* If the data will be written to, set UPDATEIFCOPY */
+ if (op_itflags[iiter]&NPY_OP_ITFLAG_WRITE) {
+ PyArray_FLAGS(temp) |= NPY_UPDATEIFCOPY;
+ PyArray_FLAGS(op[iiter]) &= ~NPY_WRITEABLE;
+ Py_INCREF(op[iiter]);
+ temp->base = (PyObject *)op[iiter];
+ }
+
+ Py_DECREF(op[iiter]);
+ op[iiter] = temp;
+
+ /*
+ * Now we need to replace the pointers and strides with values
+ * from the temporary array.
+ */
+ npyiter_replace_axisdata(iter, iiter, op[iiter], ondim,
+ PyArray_DATA(op[iiter]), op_axes ? op_axes[iiter] : NULL);
+
+ /* The temporary copy is aligned and needs no cast */
+ op_itflags[iiter] |= NPY_OP_ITFLAG_ALIGNED;
+ op_itflags[iiter] &= ~NPY_OP_ITFLAG_CAST;
+ }
+ else {
+ /*
+ * Buffering must be enabled for casting/conversion if copy
+ * wasn't specified.
+ */
+ if ((op_itflags[iiter]&NPY_OP_ITFLAG_CAST) &&
+ !(itflags&NPY_ITFLAG_BUFFER)) {
+ PyErr_SetString(PyExc_TypeError,
+ "Iterator operand required copying or buffering, "
+ "but neither copying nor buffering was enabled");
+ return 0;
+ }
+
+ /*
+ * If the operand is aligned, any buffering can use aligned
+ * optimizations.
+ */
+ if (PyArray_ISALIGNED(op[iiter])) {
+ op_itflags[iiter] |= NPY_OP_ITFLAG_ALIGNED;
+ }
+ }
+
+ /* Here we can finally check for contiguous iteration */
+ if (op_flags[iiter]&NPY_ITER_CONTIG) {
+ NpyIter_AxisData *axisdata = NIT_AXISDATA(iter);
+ npy_intp stride = NAD_STRIDES(axisdata)[iiter];
+
+ if (stride != op_dtype[iiter]->elsize) {
+ NPY_IT_DBG_PRINT("Iterator: Setting NPY_OP_ITFLAG_CAST "
+ "because of NPY_ITER_CONTIG\n");
+ op_itflags[iiter] |= NPY_OP_ITFLAG_CAST;
+ if (!(itflags&NPY_ITFLAG_BUFFER)) {
+ PyErr_SetString(PyExc_TypeError,
+ "Iterator operand required buffering, "
+ "to be contiguous as requested, but "
+ "buffering is not enabled");
+ return 0;
+ }
+ }
+ }
+
+ /*
+ * If no alignment, byte swap, or casting is needed, and
+ * the inner stride of this operand works for the whole
+ * array, we can set NPY_OP_ITFLAG_BUFNEVER.
+ */
+ if ((itflags&NPY_ITFLAG_BUFFER) && !(op_itflags[iiter]&NPY_OP_ITFLAG_CAST)) {
+ NpyIter_AxisData *axisdata = NIT_AXISDATA(iter);
+ if (ndim == 1) {
+ op_itflags[iiter] |= NPY_OP_ITFLAG_BUFNEVER;
+ NBF_STRIDES(bufferdata)[iiter] = NAD_STRIDES(axisdata)[iiter];
+ }
+ else if (PyArray_NDIM(op[iiter]) > 0) {
+ npy_intp stride, shape, innerstride = 0, innershape;
+ npy_intp sizeof_axisdata =
+ NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
+ /* Find stride of the first non-empty shape */
+ for (idim = 0; idim < ndim; ++idim) {
+ innershape = NAD_SHAPE(axisdata);
+ if (innershape != 1) {
+ innerstride = NAD_STRIDES(axisdata)[iiter];
+ break;
+ }
+ NIT_ADVANCE_AXISDATA(axisdata, 1);
+ }
+ ++idim;
+ NIT_ADVANCE_AXISDATA(axisdata, 1);
+ /* Check that everything could have coalesced together */
+ for (; idim < ndim; ++idim) {
+ stride = NAD_STRIDES(axisdata)[iiter];
+ shape = NAD_SHAPE(axisdata);
+ if (shape != 1) {
+ /*
+ * If N times the inner stride doesn't equal this
+ * stride, the multi-dimensionality is needed.
+ */
+ if (innerstride*innershape != stride) {
+ break;
+ }
+ else {
+ innershape *= shape;
+ }
+ }
+ NIT_ADVANCE_AXISDATA(axisdata, 1);
+ }
+ /*
+ * If we looped all the way to the end, one stride works.
+ * Set that stride, because it may not belong to the first
+ * dimension.
+ */
+ if (idim == ndim) {
+ op_itflags[iiter] |= NPY_OP_ITFLAG_BUFNEVER;
+ NBF_STRIDES(bufferdata)[iiter] = innerstride;
+ }
+ }
+ }
+ }
+
+ return 1;
+}
+
+/*
+ * The __array_priority__ attribute of the inputs determines
+ * the subtype of any output arrays. This function finds the
+ * subtype of the input array with highest priority.
+ */
+static void
+npyiter_get_priority_subtype(int niter, PyArrayObject **op,
+ char *op_itflags,
+ double *subtype_priority,
+ PyTypeObject **subtype)
+{
+ int iiter;
+
+ for (iiter = 0; iiter < niter; ++iiter) {
+ if (op[iiter] != NULL && op_itflags[iiter]&NPY_OP_ITFLAG_READ) {
+ double priority = PyArray_GetPriority((PyObject *)op[iiter], 0.0);
+ if (priority > *subtype_priority) {
+ *subtype_priority = priority;
+ *subtype = Py_TYPE(op[iiter]);
+ }
+ }
+ }
+}
+
+/*
+ * Calculates a dtype that all the types can be promoted to, using the
+ * ufunc rules. If only_inputs is 1, it leaves any operands that
+ * are not read from out of the calculation.
+ */
+static PyArray_Descr *
+npyiter_get_common_dtype(int niter, PyArrayObject **op,
+ char *op_itflags, PyArray_Descr **op_dtype,
+ PyArray_Descr **op_request_dtypes,
+ int only_inputs, int output_scalars)
+{
+ int iiter;
+ npy_intp narrs = 0, ndtypes = 0;
+ PyArrayObject *arrs[NPY_MAXARGS];
+ PyArray_Descr *dtypes[NPY_MAXARGS];
+ PyArray_Descr *ret;
+
+ NPY_IT_DBG_PRINT("Iterator: Getting a common data type from operands\n");
+
+ for (iiter = 0; iiter < niter; ++iiter) {
+ if (op_dtype[iiter] != NULL &&
+ (!only_inputs || (op_itflags[iiter]&NPY_OP_ITFLAG_READ))) {
+ /* If no dtype was requested and the op is a scalar, pass the op */
+ if ((op_request_dtypes == NULL ||
+ op_request_dtypes[iiter] == NULL) &&
+ PyArray_NDIM(op[iiter]) == 0) {
+ arrs[narrs++] = op[iiter];
+ }
+ /* Otherwise just pass in the dtype */
+ else {
+ dtypes[ndtypes++] = op_dtype[iiter];
+ }
+ }
+ }
+
+ if (narrs == 0) {
+ npy_intp i;
+ ret = dtypes[0];
+ for (i = 1; i < ndtypes; ++i) {
+ if (ret != dtypes[i])
+ break;
+ }
+ if (i == ndtypes) {
+ if (ndtypes == 1 || PyArray_ISNBO(ret->byteorder)) {
+ Py_INCREF(ret);
+ }
+ else {
+ ret = PyArray_DescrNewByteorder(ret, NPY_NATIVE);
+ }
+ }
+ else {
+ ret = PyArray_ResultType(narrs, arrs, ndtypes, dtypes);
+ }
+ }
+ else {
+ ret = PyArray_ResultType(narrs, arrs, ndtypes, dtypes);
+ }
+
+ return ret;
+}
+
+static int
+npyiter_allocate_transfer_functions(NpyIter *iter)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ /*int ndim = NIT_NDIM(iter);*/
+ int iiter = 0, niter = NIT_NITER(iter);
+
+ npy_intp i;
+ char *op_itflags = NIT_OPITFLAGS(iter);
+ NpyIter_BufferData *bufferdata = NIT_BUFFERDATA(iter);
+ NpyIter_AxisData *axisdata = NIT_AXISDATA(iter);
+ PyArrayObject **op = NIT_OPERANDS(iter);
+ PyArray_Descr **op_dtype = NIT_DTYPES(iter);
+ npy_intp *strides = NAD_STRIDES(axisdata), op_stride;
+ PyArray_StridedTransferFn **readtransferfn = NBF_READTRANSFERFN(bufferdata),
+ **writetransferfn = NBF_WRITETRANSFERFN(bufferdata);
+ void **readtransferdata = NBF_READTRANSFERDATA(bufferdata),
+ **writetransferdata = NBF_WRITETRANSFERDATA(bufferdata);
+
+ PyArray_StridedTransferFn *stransfer = NULL;
+ void *transferdata = NULL;
+ int needs_api = 0;
+
+ for (iiter = 0; iiter < niter; ++iiter) {
+ char flags = op_itflags[iiter];
+ /*
+ * Reduction operands may be buffered with a different stride,
+ * so we must pass NPY_MAX_INTP to the transfer function factory.
+ */
+ op_stride = (flags&NPY_OP_ITFLAG_REDUCE) ? NPY_MAX_INTP :
+ strides[iiter];
+
+ /*
+ * If we have determined that a buffer may be needed,
+ * allocate the appropriate transfer functions
+ */
+ if (!(flags&NPY_OP_ITFLAG_BUFNEVER)) {
+ if (flags&NPY_OP_ITFLAG_READ) {
+ int move_references = 0;
+ if (PyArray_GetDTypeTransferFunction(
+ (flags&NPY_OP_ITFLAG_ALIGNED) != 0,
+ op_stride,
+ op_dtype[iiter]->elsize,
+ PyArray_DESCR(op[iiter]),
+ op_dtype[iiter],
+ move_references,
+ &stransfer,
+ &transferdata,
+ &needs_api) != NPY_SUCCEED) {
+ goto fail;
+ }
+ readtransferfn[iiter] = stransfer;
+ readtransferdata[iiter] = transferdata;
+ }
+ else {
+ readtransferfn[iiter] = NULL;
+ }
+ if (flags&NPY_OP_ITFLAG_WRITE) {
+ int move_references = 1;
+ if (PyArray_GetDTypeTransferFunction(
+ (flags&NPY_OP_ITFLAG_ALIGNED) != 0,
+ op_dtype[iiter]->elsize,
+ op_stride,
+ op_dtype[iiter],
+ PyArray_DESCR(op[iiter]),
+ move_references,
+ &stransfer,
+ &transferdata,
+ &needs_api) != NPY_SUCCEED) {
+ goto fail;
+ }
+ writetransferfn[iiter] = stransfer;
+ writetransferdata[iiter] = transferdata;
+ }
+ /* If no write back but there are references make a decref fn */
+ else if (PyDataType_REFCHK(op_dtype[iiter])) {
+ /*
+ * By passing NULL to dst_type and setting move_references
+ * to 1, we get back a function that just decrements the
+ * src references.
+ */
+ if (PyArray_GetDTypeTransferFunction(
+ (flags&NPY_OP_ITFLAG_ALIGNED) != 0,
+ op_dtype[iiter]->elsize, 0,
+ op_dtype[iiter], NULL,
+ 1,
+ &stransfer,
+ &transferdata,
+ &needs_api) != NPY_SUCCEED) {
+ goto fail;
+ }
+ writetransferfn[iiter] = stransfer;
+ writetransferdata[iiter] = transferdata;
+ }
+ else {
+ writetransferfn[iiter] = NULL;
+ }
+ }
+ else {
+ readtransferfn[iiter] = NULL;
+ writetransferfn[iiter] = NULL;
+ }
+ }
+
+ /* If any of the dtype transfer functions needed the API, flag it */
+ if (needs_api) {
+ NIT_ITFLAGS(iter) |= NPY_ITFLAG_NEEDSAPI;
+ }
+
+ return 1;
+
+fail:
+ for (i = 0; i < iiter; ++i) {
+ if (readtransferdata[iiter] != NULL) {
+ PyArray_FreeStridedTransferData(readtransferdata[iiter]);
+ readtransferdata[iiter] = NULL;
+ }
+ if (writetransferdata[iiter] != NULL) {
+ PyArray_FreeStridedTransferData(writetransferdata[iiter]);
+ writetransferdata[iiter] = NULL;
+ }
+ }
+ return 0;
+}
+
+/*
+ *
+ * If errmsg is non-NULL, it should point to a variable which will
+ * receive the error message, and no Python exception will be set.
+ * This is so that the function can be called from code not holding
+ * the GIL.
+ */
+static int
+npyiter_allocate_buffers(NpyIter *iter, char **errmsg)
+{
+ /*npy_uint32 itflags = NIT_ITFLAGS(iter);*/
+ /*int ndim = NIT_NDIM(iter);*/
+ int iiter = 0, niter = NIT_NITER(iter);
+
+ npy_intp i;
+ char *op_itflags = NIT_OPITFLAGS(iter);
+ NpyIter_BufferData *bufferdata = NIT_BUFFERDATA(iter);
+ PyArray_Descr **op_dtype = NIT_DTYPES(iter);
+ npy_intp buffersize = NBF_BUFFERSIZE(bufferdata);
+ char *buffer, **buffers = NBF_BUFFERS(bufferdata);
+
+ for (iiter = 0; iiter < niter; ++iiter) {
+ char flags = op_itflags[iiter];
+
+ /*
+ * If we have determined that a buffer may be needed,
+ * allocate one.
+ */
+ if (!(flags&NPY_OP_ITFLAG_BUFNEVER)) {
+ npy_intp itemsize = op_dtype[iiter]->elsize;
+ buffer = PyArray_malloc(itemsize*buffersize);
+ if (buffer == NULL) {
+ if (errmsg == NULL) {
+ PyErr_NoMemory();
+ }
+ else {
+ *errmsg = "out of memory";
+ }
+ goto fail;
+ }
+ buffers[iiter] = buffer;
+ }
+ }
+
+ return 1;
+
+fail:
+ for (i = 0; i < iiter; ++i) {
+ if (buffers[i] != NULL) {
+ PyArray_free(buffers[i]);
+ buffers[i] = NULL;
+ }
+ }
+ return 0;
+}
+
+/*
+ * This sets the AXISDATA portion of the iterator to the specified
+ * iterindex, updating the pointers as well. This function does
+ * no error checking.
+ */
+static void
+npyiter_goto_iterindex(NpyIter *iter, npy_intp iterindex)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int idim, ndim = NIT_NDIM(iter);
+ int niter = NIT_NITER(iter);
+
+ char **dataptr;
+ NpyIter_AxisData *axisdata;
+ npy_intp sizeof_axisdata;
+ npy_intp istrides, nstrides, i, shape;
+
+ axisdata = NIT_AXISDATA(iter);
+ sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
+ nstrides = NAD_NSTRIDES();
+
+ NIT_ITERINDEX(iter) = iterindex;
+
+ if (iterindex == 0) {
+ dataptr = NIT_RESETDATAPTR(iter);
+
+ for (idim = 0; idim < ndim; ++idim) {
+ char **ptrs;
+ NAD_COORD(axisdata) = 0;
+ ptrs = NAD_PTRS(axisdata);
+ for (istrides = 0; istrides < nstrides; ++istrides) {
+ ptrs[istrides] = dataptr[istrides];
+ }
+
+ NIT_ADVANCE_AXISDATA(axisdata, 1);
+ }
+ }
+ else {
+ /*
+ * Set the coordinates, from the fastest-changing to the
+ * slowest-changing.
+ */
+ axisdata = NIT_AXISDATA(iter);
+ shape = NAD_SHAPE(axisdata);
+ i = iterindex;
+ iterindex /= shape;
+ NAD_COORD(axisdata) = i - iterindex * shape;
+ for (idim = 0; idim < ndim-1; ++idim) {
+ NIT_ADVANCE_AXISDATA(axisdata, 1);
+
+ shape = NAD_SHAPE(axisdata);
+ i = iterindex;
+ iterindex /= shape;
+ NAD_COORD(axisdata) = i - iterindex * shape;
+ }
+
+ dataptr = NIT_RESETDATAPTR(iter);
+
+ /*
+ * Accumulate the successive pointers with their
+ * offsets in the opposite order, starting from the
+ * original data pointers.
+ */
+ for (idim = 0; idim < ndim; ++idim) {
+ npy_intp *strides;
+ char **ptrs;
+
+ strides = NAD_STRIDES(axisdata);
+ ptrs = NAD_PTRS(axisdata);
+
+ i = NAD_COORD(axisdata);
+
+ for (istrides = 0; istrides < nstrides; ++istrides) {
+ ptrs[istrides] = dataptr[istrides] + i*strides[istrides];
+ }
+
+ dataptr = ptrs;
+
+ NIT_ADVANCE_AXISDATA(axisdata, -1);
+ }
+ }
+}
+
+/*
+ * This gets called after the the buffers have been exhausted, and
+ * their data needs to be written back to the arrays. The coordinates
+ * must be positioned for the beginning of the buffer.
+ */
+static void
+npyiter_copy_from_buffers(NpyIter *iter)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int ndim = NIT_NDIM(iter);
+ int iiter, niter = NIT_NITER(iter);
+
+ char *op_itflags = NIT_OPITFLAGS(iter);
+ NpyIter_BufferData *bufferdata = NIT_BUFFERDATA(iter);
+ NpyIter_AxisData *axisdata = NIT_AXISDATA(iter),
+ *reduce_outeraxisdata = NULL;
+
+ PyArray_Descr **dtypes = NIT_DTYPES(iter);
+ npy_intp transfersize = NBF_SIZE(bufferdata),
+ buffersize = NBF_BUFFERSIZE(bufferdata);
+ npy_intp *strides = NBF_STRIDES(bufferdata),
+ *ad_strides = NAD_STRIDES(axisdata);
+ npy_intp sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
+ char **ptrs = NBF_PTRS(bufferdata), **ad_ptrs = NAD_PTRS(axisdata);
+ char **buffers = NBF_BUFFERS(bufferdata);
+ char *buffer;
+
+ npy_intp reduce_outerdim = 0;
+ npy_intp *reduce_outerstrides = NULL;
+ char **reduce_outerptrs = NULL;
+
+ PyArray_StridedTransferFn *stransfer = NULL;
+ void *transferdata = NULL;
+
+ npy_intp axisdata_incr = NIT_AXISDATA_SIZEOF(itflags, ndim, niter) /
+ NPY_SIZEOF_INTP;
+
+ /* If we're past the end, nothing to copy */
+ if (NBF_SIZE(bufferdata) == 0) {
+ return;
+ }
+
+ NPY_IT_DBG_PRINT("Iterator: Copying buffers to outputs\n");
+
+ if (itflags&NPY_ITFLAG_REDUCE) {
+ reduce_outerdim = NBF_REDUCE_OUTERDIM(bufferdata);
+ reduce_outerstrides = NBF_REDUCE_OUTERSTRIDES(bufferdata);
+ reduce_outerptrs = NBF_REDUCE_OUTERPTRS(bufferdata);
+ reduce_outeraxisdata = NIT_INDEX_AXISDATA(axisdata, reduce_outerdim);
+ transfersize *= NBF_REDUCE_OUTERSIZE(bufferdata);
+ }
+
+ for (iiter = 0; iiter < niter; ++iiter) {
+ stransfer = NBF_WRITETRANSFERFN(bufferdata)[iiter];
+ transferdata = NBF_WRITETRANSFERDATA(bufferdata)[iiter];
+ buffer = buffers[iiter];
+ /*
+ * Copy the data back to the arrays. If the type has refs,
+ * this function moves them so the buffer's refs are released.
+ */
+ if ((stransfer != NULL) && (op_itflags[iiter]&NPY_OP_ITFLAG_WRITE)) {
+ /* Copy back only if the pointer was pointing to the buffer */
+ npy_intp delta = (ptrs[iiter] - buffer);
+ if (0 <= delta && delta <= buffersize*dtypes[iiter]->elsize) {
+ npy_intp op_transfersize;
+
+ npy_intp src_stride, *dst_strides, *dst_coords, *dst_shape;
+ int ndim_transfer;
+
+ NPY_IT_DBG_PRINT1("Iterator: Operand %d was buffered\n",
+ (int)iiter);
+
+ /*
+ * If this operand is being reduced in the inner loop,
+ * its buffering stride was set to zero, and just
+ * one element was copied.
+ */
+ if (op_itflags[iiter]&NPY_OP_ITFLAG_REDUCE) {
+ if (strides[iiter] == 0) {
+ if (reduce_outerstrides[iiter] == 0) {
+ op_transfersize = 1;
+ src_stride = 0;
+ dst_strides = &src_stride;
+ dst_coords = &NAD_COORD(reduce_outeraxisdata);
+ dst_shape = &NAD_SHAPE(reduce_outeraxisdata);
+ ndim_transfer = 1;
+ }
+ else {
+ op_transfersize = NBF_REDUCE_OUTERSIZE(bufferdata);
+ src_stride = reduce_outerstrides[iiter];
+ dst_strides =
+ &NAD_STRIDES(reduce_outeraxisdata)[iiter];
+ dst_coords = &NAD_COORD(reduce_outeraxisdata);
+ dst_shape = &NAD_SHAPE(reduce_outeraxisdata);
+ ndim_transfer = ndim - reduce_outerdim;
+ }
+ }
+ else {
+ if (reduce_outerstrides[iiter] == 0) {
+ op_transfersize = NBF_SIZE(bufferdata);
+ src_stride = strides[iiter];
+ dst_strides = &ad_strides[iiter];
+ dst_coords = &NAD_COORD(axisdata);
+ dst_shape = &NAD_SHAPE(axisdata);
+ ndim_transfer = reduce_outerdim ?
+ reduce_outerdim : 1;
+ }
+ else {
+ op_transfersize = transfersize;
+ src_stride = strides[iiter];
+ dst_strides = &ad_strides[iiter];
+ dst_coords = &NAD_COORD(axisdata);
+ dst_shape = &NAD_SHAPE(axisdata);
+ ndim_transfer = ndim;
+ }
+ }
+ }
+ else {
+ op_transfersize = transfersize;
+ src_stride = strides[iiter];
+ dst_strides = &ad_strides[iiter];
+ dst_coords = &NAD_COORD(axisdata);
+ dst_shape = &NAD_SHAPE(axisdata);
+ ndim_transfer = ndim;
+ }
+
+ NPY_IT_DBG_PRINT2("Iterator: Copying buffer to "
+ "operand %d (%d items)\n",
+ (int)iiter, (int)op_transfersize);
+
+ PyArray_TransferStridedToNDim(ndim_transfer,
+ ad_ptrs[iiter], dst_strides, axisdata_incr,
+ buffer, src_stride,
+ dst_coords, axisdata_incr,
+ dst_shape, axisdata_incr,
+ op_transfersize, dtypes[iiter]->elsize,
+ stransfer,
+ transferdata);
+ }
+ }
+ /* If there's no copy back, we may have to decrement refs. In
+ * this case, the transfer function has a 'decsrcref' transfer
+ * function, so we can use it to do the decrement.
+ */
+ else if (stransfer != NULL) {
+ /* Decrement refs only if the pointer was pointing to the buffer */
+ npy_intp delta = (ptrs[iiter] - buffer);
+ if (0 <= delta && delta <= transfersize*dtypes[iiter]->elsize) {
+ NPY_IT_DBG_PRINT1("Iterator: Freeing refs and zeroing buffer "
+ "of operand %d\n", (int)iiter);
+ /* Decrement refs */
+ stransfer(NULL, 0, buffer, dtypes[iiter]->elsize,
+ transfersize, dtypes[iiter]->elsize,
+ transferdata);
+ /*
+ * Zero out the memory for safety. For instance,
+ * if during iteration some Python code copied an
+ * array pointing into the buffer, it will get None
+ * values for its references after this.
+ */
+ memset(buffer, 0, dtypes[iiter]->elsize*transfersize);
+ }
+ }
+ }
+
+ NPY_IT_DBG_PRINT("Iterator: Finished copying buffers to outputs\n");
+}
+
+/*
+ * This gets called after the iterator has been positioned to coordinates
+ * for the start of a buffer. It decides which operands need a buffer,
+ * and copies the data into the buffers.
+ */
+static void
+npyiter_copy_to_buffers(NpyIter *iter, char **prev_dataptrs)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int ndim = NIT_NDIM(iter);
+ int iiter, niter = NIT_NITER(iter);
+
+ char *op_itflags = NIT_OPITFLAGS(iter);
+ NpyIter_BufferData *bufferdata = NIT_BUFFERDATA(iter);
+ NpyIter_AxisData *axisdata = NIT_AXISDATA(iter),
+ *reduce_outeraxisdata = NULL;
+
+ PyArray_Descr **dtypes = NIT_DTYPES(iter);
+ PyArrayObject **operands = NIT_OPERANDS(iter);
+ npy_intp *strides = NBF_STRIDES(bufferdata),
+ *ad_strides = NAD_STRIDES(axisdata);
+ npy_intp sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
+ char **ptrs = NBF_PTRS(bufferdata), **ad_ptrs = NAD_PTRS(axisdata);
+ char **buffers = NBF_BUFFERS(bufferdata);
+ npy_intp iterindex, iterend, transfersize,
+ singlestridesize, reduce_innersize = 0, reduce_outerdim = 0;
+ int is_onestride = 0, any_buffered = 0;
+
+ npy_intp *reduce_outerstrides = NULL;
+ char **reduce_outerptrs = NULL;
+
+ PyArray_StridedTransferFn *stransfer = NULL;
+ void *transferdata = NULL;
+
+ /*
+ * Have to get this flag before npyiter_checkreducesize sets
+ * it for the next iteration.
+ */
+ npy_bool reuse_reduce_loops = (prev_dataptrs != NULL) &&
+ ((itflags&NPY_ITFLAG_REUSE_REDUCE_LOOPS) != 0);
+
+ npy_intp axisdata_incr = NIT_AXISDATA_SIZEOF(itflags, ndim, niter) /
+ NPY_SIZEOF_INTP;
+
+ NPY_IT_DBG_PRINT("Iterator: Copying inputs to buffers\n");
+
+ /* Calculate the size if using any buffers */
+ iterindex = NIT_ITERINDEX(iter);
+ iterend = NIT_ITEREND(iter);
+ transfersize = NBF_BUFFERSIZE(bufferdata);
+ if (transfersize > iterend - iterindex) {
+ transfersize = iterend - iterindex;
+ }
+
+ /* If last time around, the reduce loop structure was full, we reuse it */
+ if (reuse_reduce_loops) {
+ reduce_outerstrides = NBF_REDUCE_OUTERSTRIDES(bufferdata);
+ reduce_outerptrs = NBF_REDUCE_OUTERPTRS(bufferdata);
+ reduce_outerdim = NBF_REDUCE_OUTERDIM(bufferdata);
+ reduce_outeraxisdata = NIT_INDEX_AXISDATA(axisdata, reduce_outerdim);
+ reduce_innersize = NBF_SIZE(bufferdata);
+ NBF_REDUCE_POS(bufferdata) = 0;
+ transfersize = NBF_REDUCE_OUTERSIZE(bufferdata)*reduce_innersize;
+ NBF_BUFITEREND(bufferdata) = iterindex + reduce_innersize;
+
+ NPY_IT_DBG_PRINT3("Reused reduce transfersize: %d innersize: %d "
+ "itersize: %d\n",
+ (int)transfersize,
+ (int)reduce_innersize,
+ (int)NpyIter_GetIterSize(iter));
+ }
+ /*
+ * If there are any reduction operands, we may have to make
+ * the size smaller so we don't copy the same value into
+ * a buffer twice, as the buffering does not have a mechanism
+ * to combine values itself.
+ */
+ else if (itflags&NPY_ITFLAG_REDUCE) {
+ NPY_IT_DBG_PRINT("Iterator: Calculating reduce loops\n");
+ transfersize = npyiter_checkreducesize(iter, transfersize,
+ &reduce_innersize,
+ &reduce_outerdim);
+ NPY_IT_DBG_PRINT3("Reduce transfersize: %d innersize: %d "
+ "itersize: %d\n",
+ (int)transfersize,
+ (int)reduce_innersize,
+ (int)NpyIter_GetIterSize(iter));
+
+ reduce_outerstrides = NBF_REDUCE_OUTERSTRIDES(bufferdata);
+ reduce_outerptrs = NBF_REDUCE_OUTERPTRS(bufferdata);
+ reduce_outeraxisdata = NIT_INDEX_AXISDATA(axisdata, reduce_outerdim);
+ NBF_SIZE(bufferdata) = reduce_innersize;
+ NBF_REDUCE_POS(bufferdata) = 0;
+ NBF_REDUCE_OUTERDIM(bufferdata) = reduce_outerdim;
+ NBF_BUFITEREND(bufferdata) = iterindex + reduce_innersize;
+ if (reduce_innersize == 0) {
+ NBF_REDUCE_OUTERSIZE(bufferdata) = 0;
+ return;
+ }
+ else {
+ NBF_REDUCE_OUTERSIZE(bufferdata) = transfersize/reduce_innersize;
+ }
+ }
+ else {
+ NBF_SIZE(bufferdata) = transfersize;
+ NBF_BUFITEREND(bufferdata) = iterindex + transfersize;
+ }
+
+ /* Calculate the maximum size if using a single stride and no buffers */
+ singlestridesize = NAD_SHAPE(axisdata)-NAD_COORD(axisdata);
+ if (singlestridesize > iterend - iterindex) {
+ singlestridesize = iterend - iterindex;
+ }
+ if (singlestridesize >= transfersize) {
+ is_onestride = 1;
+ }
+
+ for (iiter = 0; iiter < niter; ++iiter) {
+ /*
+ * If the buffer is write-only, these two are NULL, and the buffer
+ * pointers will be set up but the read copy won't be done
+ */
+ stransfer = NBF_READTRANSFERFN(bufferdata)[iiter];
+ transferdata = NBF_READTRANSFERDATA(bufferdata)[iiter];
+ switch (op_itflags[iiter]&
+ (NPY_OP_ITFLAG_BUFNEVER|
+ NPY_OP_ITFLAG_CAST|
+ NPY_OP_ITFLAG_REDUCE)) {
+ /* Never need to buffer this operand */
+ case NPY_OP_ITFLAG_BUFNEVER:
+ ptrs[iiter] = ad_ptrs[iiter];
+ if (itflags&NPY_ITFLAG_REDUCE) {
+ reduce_outerstrides[iiter] = reduce_innersize *
+ strides[iiter];
+ reduce_outerptrs[iiter] = ptrs[iiter];
+ }
+ /*
+ * Should not adjust the stride - ad_strides[iiter]
+ * could be zero, but strides[iiter] was initialized
+ * to the first non-trivial stride.
+ */
+ stransfer = NULL;
+ break;
+ /* Never need to buffer this operand */
+ case NPY_OP_ITFLAG_BUFNEVER|NPY_OP_ITFLAG_REDUCE:
+ ptrs[iiter] = ad_ptrs[iiter];
+ reduce_outerptrs[iiter] = ptrs[iiter];
+ reduce_outerstrides[iiter] = 0;
+ /*
+ * Should not adjust the stride - ad_strides[iiter]
+ * could be zero, but strides[iiter] was initialized
+ * to the first non-trivial stride.
+ */
+ stransfer = NULL;
+ break;
+ /* Just a copy */
+ case 0:
+ /*
+ * No copyswap or cast was requested, so all we're
+ * doing is copying the data to fill the buffer and
+ * produce a single stride. If the underlying data
+ * already does that, no need to copy it.
+ */
+ if (is_onestride) {
+ ptrs[iiter] = ad_ptrs[iiter];
+ strides[iiter] = ad_strides[iiter];
+ stransfer = NULL;
+ }
+ /* If some other op is reduced, we have a double reduce loop */
+ else if ((itflags&NPY_ITFLAG_REDUCE) &&
+ (reduce_outerdim == 1) &&
+ (transfersize/reduce_innersize <=
+ NAD_SHAPE(reduce_outeraxisdata) -
+ NAD_COORD(reduce_outeraxisdata))) {
+ ptrs[iiter] = ad_ptrs[iiter];
+ reduce_outerptrs[iiter] = ptrs[iiter];
+ strides[iiter] = ad_strides[iiter];
+ reduce_outerstrides[iiter] =
+ NAD_STRIDES(reduce_outeraxisdata)[iiter];
+ stransfer = NULL;
+ }
+ else {
+ /* In this case, the buffer is being used */
+ ptrs[iiter] = buffers[iiter];
+ strides[iiter] = dtypes[iiter]->elsize;
+ if (itflags&NPY_ITFLAG_REDUCE) {
+ reduce_outerstrides[iiter] = reduce_innersize *
+ strides[iiter];
+ reduce_outerptrs[iiter] = ptrs[iiter];
+ }
+ }
+ break;
+ /* Just a copy, but with a reduction */
+ case NPY_OP_ITFLAG_REDUCE:
+ if (ad_strides[iiter] == 0) {
+ strides[iiter] = 0;
+ /* It's all in one stride in the inner loop dimension */
+ if (is_onestride) {
+ NPY_IT_DBG_PRINT1("reduce op %d all one stride\n", (int)iiter);
+ ptrs[iiter] = ad_ptrs[iiter];
+ reduce_outerstrides[iiter] = 0;
+ stransfer = NULL;
+ }
+ /* It's all in one stride in the reduce outer loop */
+ else if ((reduce_outerdim > 0) &&
+ (transfersize/reduce_innersize <=
+ NAD_SHAPE(reduce_outeraxisdata) -
+ NAD_COORD(reduce_outeraxisdata))) {
+ NPY_IT_DBG_PRINT1("reduce op %d all one outer stride\n",
+ (int)iiter);
+ ptrs[iiter] = ad_ptrs[iiter];
+ /* Outer reduce loop advances by one item */
+ reduce_outerstrides[iiter] =
+ NAD_STRIDES(reduce_outeraxisdata)[iiter];
+ stransfer = NULL;
+ }
+ /* In this case, the buffer is being used */
+ else {
+ NPY_IT_DBG_PRINT1("reduce op %d must buffer\n", (int)iiter);
+ ptrs[iiter] = buffers[iiter];
+ /* Both outer and inner reduce loops have stride 0 */
+ if (NAD_STRIDES(reduce_outeraxisdata)[iiter] == 0) {
+ reduce_outerstrides[iiter] = 0;
+ }
+ /* Outer reduce loop advances by one item */
+ else {
+ reduce_outerstrides[iiter] = dtypes[iiter]->elsize;
+ }
+ }
+
+ }
+ else if (is_onestride) {
+ NPY_IT_DBG_PRINT1("reduce op %d all one stride in dim 0\n", (int)iiter);
+ ptrs[iiter] = ad_ptrs[iiter];
+ strides[iiter] = ad_strides[iiter];
+ reduce_outerstrides[iiter] = 0;
+ stransfer = NULL;
+ }
+ else {
+ /* It's all in one stride in the reduce outer loop */
+ if ((reduce_outerdim > 0) &&
+ (transfersize/reduce_innersize <=
+ NAD_SHAPE(reduce_outeraxisdata) -
+ NAD_COORD(reduce_outeraxisdata))) {
+ ptrs[iiter] = ad_ptrs[iiter];
+ strides[iiter] = ad_strides[iiter];
+ /* Outer reduce loop advances by one item */
+ reduce_outerstrides[iiter] =
+ NAD_STRIDES(reduce_outeraxisdata)[iiter];
+ stransfer = NULL;
+ }
+ /* In this case, the buffer is being used */
+ else {
+ ptrs[iiter] = buffers[iiter];
+ strides[iiter] = dtypes[iiter]->elsize;
+
+ if (NAD_STRIDES(reduce_outeraxisdata)[iiter] == 0) {
+ /* Reduction in outer reduce loop */
+ reduce_outerstrides[iiter] = 0;
+ }
+ else {
+ /* Advance to next items in outer reduce loop */
+ reduce_outerstrides[iiter] = reduce_innersize *
+ dtypes[iiter]->elsize;
+ }
+ }
+ }
+ reduce_outerptrs[iiter] = ptrs[iiter];
+ break;
+ default:
+ /* In this case, the buffer is being used */
+ if (!(op_itflags[iiter]&NPY_OP_ITFLAG_REDUCE)) {
+ ptrs[iiter] = buffers[iiter];
+ strides[iiter] = dtypes[iiter]->elsize;
+ if (itflags&NPY_ITFLAG_REDUCE) {
+ reduce_outerstrides[iiter] = reduce_innersize *
+ strides[iiter];
+ reduce_outerptrs[iiter] = ptrs[iiter];
+ }
+ }
+ /* The buffer is being used with reduction */
+ else {
+ ptrs[iiter] = buffers[iiter];
+ if (ad_strides[iiter] == 0) {
+ NPY_IT_DBG_PRINT1("cast op %d has innermost stride 0\n", (int)iiter);
+ strides[iiter] = 0;
+ /* Both outer and inner reduce loops have stride 0 */
+ if (NAD_STRIDES(reduce_outeraxisdata)[iiter] == 0) {
+ NPY_IT_DBG_PRINT1("cast op %d has outermost stride 0\n", (int)iiter);
+ reduce_outerstrides[iiter] = 0;
+ }
+ /* Outer reduce loop advances by one item */
+ else {
+ NPY_IT_DBG_PRINT1("cast op %d has outermost stride !=0\n", (int)iiter);
+ reduce_outerstrides[iiter] = dtypes[iiter]->elsize;
+ }
+ }
+ else {
+ NPY_IT_DBG_PRINT1("cast op %d has innermost stride !=0\n", (int)iiter);
+ strides[iiter] = dtypes[iiter]->elsize;
+
+ if (NAD_STRIDES(reduce_outeraxisdata)[iiter] == 0) {
+ NPY_IT_DBG_PRINT1("cast op %d has outermost stride 0\n", (int)iiter);
+ /* Reduction in outer reduce loop */
+ reduce_outerstrides[iiter] = 0;
+ }
+ else {
+ NPY_IT_DBG_PRINT1("cast op %d has outermost stride !=0\n", (int)iiter);
+ /* Advance to next items in outer reduce loop */
+ reduce_outerstrides[iiter] = reduce_innersize *
+ dtypes[iiter]->elsize;
+ }
+ }
+ reduce_outerptrs[iiter] = ptrs[iiter];
+ }
+ break;
+ }
+
+ if (stransfer != NULL) {
+ npy_intp src_itemsize = PyArray_DESCR(operands[iiter])->elsize;
+ npy_intp op_transfersize;
+
+ npy_intp dst_stride, *src_strides, *src_coords, *src_shape;
+ int ndim_transfer;
+
+ npy_bool skip_transfer = 0;
+
+ any_buffered = 1;
+
+ /*
+ * If this operand is being reduced in the inner loop,
+ * set its buffering stride to zero, and just copy
+ * one element.
+ */
+ if (op_itflags[iiter]&NPY_OP_ITFLAG_REDUCE) {
+ if (ad_strides[iiter] == 0) {
+ strides[iiter] = 0;
+ if (reduce_outerstrides[iiter] == 0) {
+ op_transfersize = 1;
+ dst_stride = 0;
+ src_strides = &dst_stride;
+ src_coords = &NAD_COORD(reduce_outeraxisdata);
+ src_shape = &NAD_SHAPE(reduce_outeraxisdata);
+ ndim_transfer = 1;
+
+ /*
+ * When we're reducing a single element, and
+ * it's still the same element, don't overwrite
+ * it even when reuse reduce loops is unset.
+ * This preserves the precision of the
+ * intermediate calculation.
+ */
+ if (prev_dataptrs &&
+ prev_dataptrs[iiter] == ad_ptrs[iiter]) {
+ NPY_IT_DBG_PRINT1("Iterator: skipping operand %d"
+ " copy because it's a 1-element reduce\n",
+ (int)iiter);
+
+ skip_transfer = 1;
+ }
+ }
+ else {
+ op_transfersize = NBF_REDUCE_OUTERSIZE(bufferdata);
+ dst_stride = reduce_outerstrides[iiter];
+ src_strides = &NAD_STRIDES(reduce_outeraxisdata)[iiter];
+ src_coords = &NAD_COORD(reduce_outeraxisdata);
+ src_shape = &NAD_SHAPE(reduce_outeraxisdata);
+ ndim_transfer = ndim - reduce_outerdim;
+ }
+ }
+ else {
+ if (reduce_outerstrides[iiter] == 0) {
+ op_transfersize = NBF_SIZE(bufferdata);
+ dst_stride = strides[iiter];
+ src_strides = &ad_strides[iiter];
+ src_coords = &NAD_COORD(axisdata);
+ src_shape = &NAD_SHAPE(axisdata);
+ ndim_transfer = reduce_outerdim ? reduce_outerdim : 1;
+ }
+ else {
+ op_transfersize = transfersize;
+ dst_stride = strides[iiter];
+ src_strides = &ad_strides[iiter];
+ src_coords = &NAD_COORD(axisdata);
+ src_shape = &NAD_SHAPE(axisdata);
+ ndim_transfer = ndim;
+ }
+ }
+ }
+ else {
+ op_transfersize = transfersize;
+ dst_stride = strides[iiter];
+ src_strides = &ad_strides[iiter];
+ src_coords = &NAD_COORD(axisdata);
+ src_shape = &NAD_SHAPE(axisdata);
+ ndim_transfer = ndim;
+ }
+
+ /*
+ * If the whole buffered loop structure remains the same,
+ * and the source pointer for this data didn't change,
+ * we don't have to copy the data again.
+ */
+ if (reuse_reduce_loops && prev_dataptrs[iiter] == ad_ptrs[iiter]) {
+ NPY_IT_DBG_PRINT2("Iterator: skipping operands %d "
+ "copy (%d items) because loops are reused and the data "
+ "pointer didn't change\n",
+ (int)iiter, (int)op_transfersize);
+ skip_transfer = 1;
+ }
+
+ /* If the data type requires zero-inititialization */
+ if (PyDataType_FLAGCHK(dtypes[iiter], NPY_NEEDS_INIT)) {
+ NPY_IT_DBG_PRINT("Iterator: Buffer requires init, "
+ "memsetting to 0\n");
+ memset(ptrs[iiter], 0, dtypes[iiter]->elsize*op_transfersize);
+ /* Can't skip the transfer in this case */
+ skip_transfer = 0;
+ }
+
+ if (!skip_transfer) {
+ NPY_IT_DBG_PRINT2("Iterator: Copying operand %d to "
+ "buffer (%d items)\n",
+ (int)iiter, (int)op_transfersize);
+
+ PyArray_TransferNDimToStrided(ndim_transfer,
+ ptrs[iiter], dst_stride,
+ ad_ptrs[iiter], src_strides, axisdata_incr,
+ src_coords, axisdata_incr,
+ src_shape, axisdata_incr,
+ op_transfersize, src_itemsize,
+ stransfer,
+ transferdata);
+ }
+ }
+ else if (ptrs[iiter] == buffers[iiter]) {
+ /* If the data type requires zero-inititialization */
+ if (PyDataType_FLAGCHK(dtypes[iiter], NPY_NEEDS_INIT)) {
+ NPY_IT_DBG_PRINT1("Iterator: Write-only buffer for "
+ "operand %d requires init, "
+ "memsetting to 0\n", (int)iiter);
+ memset(ptrs[iiter], 0, dtypes[iiter]->elsize*transfersize);
+ }
+ }
+
+ }
+
+ /*
+ * If buffering wasn't needed, we can grow the inner
+ * loop to as large as possible.
+ *
+ * TODO: Could grow REDUCE loop too with some more logic above.
+ */
+ if (!any_buffered && (itflags&NPY_ITFLAG_GROWINNER) &&
+ !(itflags&NPY_ITFLAG_REDUCE)) {
+ if (singlestridesize > transfersize) {
+ NPY_IT_DBG_PRINT2("Iterator: Expanding inner loop size "
+ "from %d to %d since buffering wasn't needed\n",
+ (int)NBF_SIZE(bufferdata), (int)singlestridesize);
+ NBF_SIZE(bufferdata) = singlestridesize;
+ NBF_BUFITEREND(bufferdata) = iterindex + singlestridesize;
+ }
+ }
+
+ NPY_IT_DBG_PRINT1("Any buffering needed: %d\n", any_buffered);
+
+ NPY_IT_DBG_PRINT1("Iterator: Finished copying inputs to buffers "
+ "(buffered size is %d)\n", (int)NBF_SIZE(bufferdata));
+}
+
+/*
+ * This checks how much space can be buffered without encountering the
+ * same value twice, or for operands whose innermost stride is zero,
+ * without encountering a different value. By reducing the buffered
+ * amount to this size, reductions can be safely buffered.
+ *
+ * Reductions are buffered with two levels of looping, to avoid
+ * frequent copying to the buffers. The return value is the over-all
+ * buffer size, and when the flag NPY_ITFLAG_REDUCE is set, reduce_innersize
+ * receives the size of the inner of the two levels of looping.
+ *
+ * The value placed in reduce_outerdim is the index into the AXISDATA
+ * for where the second level of the double loop begins.
+ *
+ * The return value is always a multiple of the value placed in
+ * reduce_innersize.
+ */
+static npy_intp
+npyiter_checkreducesize(NpyIter *iter, npy_intp count,
+ npy_intp *reduce_innersize,
+ npy_intp *reduce_outerdim)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int idim, ndim = NIT_NDIM(iter);
+ int iiter, niter = NIT_NITER(iter);
+
+ NpyIter_AxisData *axisdata;
+ npy_intp sizeof_axisdata;
+ npy_intp coord, shape, *strides;
+ npy_intp reducespace = 1, factor;
+ npy_bool nonzerocoord = 0;
+
+ char *op_itflags = NIT_OPITFLAGS(iter);
+ char stride0op[NPY_MAXARGS];
+
+ /* Default to no outer axis */
+ *reduce_outerdim = 0;
+
+ /* If there's only one dimension, no need to calculate anything */
+ if (ndim == 1) {
+ *reduce_innersize = count;
+ return count;
+ }
+
+ sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
+ axisdata = NIT_AXISDATA(iter);
+
+ /* Indicate which REDUCE operands have stride 0 in the inner loop */
+ strides = NAD_STRIDES(axisdata);
+ for (iiter = 0; iiter < niter; ++iiter) {
+ stride0op[iiter] = (op_itflags[iiter]&NPY_OP_ITFLAG_REDUCE) &&
+ (strides[iiter] == 0);
+ }
+ shape = NAD_SHAPE(axisdata);
+ coord = NAD_COORD(axisdata);
+ reducespace += (shape-coord-1);
+ factor = shape;
+ NIT_ADVANCE_AXISDATA(axisdata, 1);
+
+ /* Go forward through axisdata, calculating the space available */
+ for (idim = 1; idim < ndim && reducespace < count;
+ ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) {
+ strides = NAD_STRIDES(axisdata);
+ for (iiter = 0; iiter < niter; ++iiter) {
+ /*
+ * If a reduce stride switched from zero to non-zero, or
+ * vice versa, that's the point where the data will stop
+ * being the same element or will repeat, and if the
+ * buffer starts with all zero coordinates up to this
+ * point, gives us the reduce_innersize.
+ */
+ if((stride0op[iiter] && (strides[iiter] != 0)) ||
+ (!stride0op[iiter] &&
+ (strides[iiter] == 0) &&
+ (op_itflags[iiter]&NPY_OP_ITFLAG_REDUCE))) {
+ NPY_IT_DBG_PRINT1("Iterator: Reduce operation limits "
+ "buffer to %d\n", (int)reducespace);
+ /*
+ * If we already found more elements than count, or
+ * the starting coordinate wasn't zero, the two-level
+ * looping is unnecessary/can't be done, so return.
+ */
+ if (count <= reducespace) {
+ *reduce_innersize = count;
+ return count;
+ }
+ else if (nonzerocoord) {
+ if (reducespace < count) {
+ count = reducespace;
+ }
+ *reduce_innersize = count;
+ return count;
+ }
+ else {
+ *reduce_innersize = reducespace;
+ break;
+ }
+ }
+ }
+ /* If we broke out of the loop early, we found reduce_innersize */
+ if (iiter != niter) {
+ break;
+ }
+
+ shape = NAD_SHAPE(axisdata);
+ coord = NAD_COORD(axisdata);
+ if (coord != 0) {
+ nonzerocoord = 1;
+ }
+ reducespace += (shape-coord-1) * factor;
+ factor *= shape;
+ }
+
+ /* If there was any non-zero coordinate, can't do the double loop */
+ if (nonzerocoord) {
+ if (reducespace < count) {
+ count = reducespace;
+ }
+ *reduce_innersize = count;
+ /* In this case, we can't reuse the reduce loops */
+ NIT_ITFLAGS(iter) &= ~NPY_ITFLAG_REUSE_REDUCE_LOOPS;
+ return count;
+ }
+
+ /* In this case, we can reuse the reduce loops */
+ NIT_ITFLAGS(iter) |= NPY_ITFLAG_REUSE_REDUCE_LOOPS;
+
+ *reduce_innersize = reducespace;
+ count /= reducespace;
+
+ /*
+ * Continue through the rest of the dimensions. If there are
+ * two separated reduction axes, we may have to cut the buffer
+ * short again.
+ */
+ *reduce_outerdim = idim;
+ reducespace = 1;
+ factor = 1;
+ /* Indicate which REDUCE operands have stride 0 at the current level */
+ strides = NAD_STRIDES(axisdata);
+ for (iiter = 0; iiter < niter; ++iiter) {
+ stride0op[iiter] = (op_itflags[iiter]&NPY_OP_ITFLAG_REDUCE) &&
+ (strides[iiter] == 0);
+ }
+ shape = NAD_SHAPE(axisdata);
+ coord = NAD_COORD(axisdata);
+ reducespace += (shape-coord-1) * factor;
+ factor *= shape;
+ NIT_ADVANCE_AXISDATA(axisdata, 1);
+ ++idim;
+
+ for (; idim < ndim && reducespace < count;
+ ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) {
+ strides = NAD_STRIDES(axisdata);
+ for (iiter = 0; iiter < niter; ++iiter) {
+ /*
+ * If a reduce stride switched from zero to non-zero, or
+ * vice versa, that's the point where the data will stop
+ * being the same element or will repeat, and if the
+ * buffer starts with all zero coordinates up to this
+ * point, gives us the reduce_innersize.
+ */
+ if((stride0op[iiter] && (strides[iiter] != 0)) ||
+ (!stride0op[iiter] &&
+ (strides[iiter] == 0) &&
+ (op_itflags[iiter]&NPY_OP_ITFLAG_REDUCE))) {
+ NPY_IT_DBG_PRINT1("Iterator: Reduce operation limits "
+ "buffer to %d\n", (int)reducespace);
+ /*
+ * This terminates the outer level of our double loop.
+ */
+ if (count <= reducespace) {
+ return count * (*reduce_innersize);
+ }
+ else {
+ return reducespace * (*reduce_innersize);
+ }
+ }
+ }
+
+ shape = NAD_SHAPE(axisdata);
+ coord = NAD_COORD(axisdata);
+ if (coord != 0) {
+ nonzerocoord = 1;
+ }
+ reducespace += (shape-coord-1) * factor;
+ factor *= shape;
+ }
+
+ if (reducespace < count) {
+ count = reducespace;
+ }
+ return count * (*reduce_innersize);
+}
+
+
+
+/*NUMPY_API
+ * For debugging
+ */
+NPY_NO_EXPORT void
+NpyIter_DebugPrint(NpyIter *iter)
+{
+ npy_uint32 itflags = NIT_ITFLAGS(iter);
+ int idim, ndim = NIT_NDIM(iter);
+ int iiter, niter = NIT_NITER(iter);
+
+ NpyIter_AxisData *axisdata;
+ npy_intp sizeof_axisdata;
+
+ PyGILState_STATE gilstate = PyGILState_Ensure();
+
+ printf("\n------ BEGIN ITERATOR DUMP ------\n");
+ printf("| Iterator Address: %p\n", (void *)iter);
+ printf("| ItFlags: ");
+ if (itflags&NPY_ITFLAG_IDENTPERM)
+ printf("IDENTPERM ");
+ if (itflags&NPY_ITFLAG_NEGPERM)
+ printf("NEGPERM ");
+ if (itflags&NPY_ITFLAG_HASINDEX)
+ printf("HASINDEX ");
+ if (itflags&NPY_ITFLAG_HASCOORDS)
+ printf("HASCOORDS ");
+ if (itflags&NPY_ITFLAG_FORCEDORDER)
+ printf("FORCEDORDER ");
+ if (itflags&NPY_ITFLAG_NOINNER)
+ printf("NOINNER ");
+ if (itflags&NPY_ITFLAG_RANGE)
+ printf("RANGE ");
+ if (itflags&NPY_ITFLAG_BUFFER)
+ printf("BUFFER ");
+ if (itflags&NPY_ITFLAG_GROWINNER)
+ printf("GROWINNER ");
+ if (itflags&NPY_ITFLAG_ONEITERATION)
+ printf("ONEITERATION ");
+ if (itflags&NPY_ITFLAG_DELAYBUF)
+ printf("DELAYBUF ");
+ if (itflags&NPY_ITFLAG_NEEDSAPI)
+ printf("NEEDSAPI ");
+ if (itflags&NPY_ITFLAG_REDUCE)
+ printf("REDUCE ");
+ if (itflags&NPY_ITFLAG_REUSE_REDUCE_LOOPS)
+ printf("REUSE_REDUCE_LOOPS ");
+ printf("\n");
+ printf("| NDim: %d\n", (int)ndim);
+ printf("| NIter: %d\n", (int)niter);
+ printf("| IterSize: %d\n", (int)NIT_ITERSIZE(iter));
+ printf("| IterStart: %d\n", (int)NIT_ITERSTART(iter));
+ printf("| IterEnd: %d\n", (int)NIT_ITEREND(iter));
+ printf("| IterIndex: %d\n", (int)NIT_ITERINDEX(iter));
+ printf("| Iterator SizeOf: %d\n",
+ (int)NIT_SIZEOF_ITERATOR(itflags, ndim, niter));
+ printf("| BufferData SizeOf: %d\n",
+ (int)NIT_BUFFERDATA_SIZEOF(itflags, ndim, niter));
+ printf("| AxisData SizeOf: %d\n",
+ (int)NIT_AXISDATA_SIZEOF(itflags, ndim, niter));
+ printf("|\n");
+
+ printf("| Perm: ");
+ for (idim = 0; idim < ndim; ++idim) {
+ printf("%d ", (int)NIT_PERM(iter)[idim]);
+ }
+ printf("\n");
+ printf("| DTypes: ");
+ for (iiter = 0; iiter < niter; ++iiter) {
+ printf("%p ", (void *)NIT_DTYPES(iter)[iiter]);
+ }
+ printf("\n");
+ printf("| DTypes: ");
+ for (iiter = 0; iiter < niter; ++iiter) {
+ if (NIT_DTYPES(iter)[iiter] != NULL)
+ PyObject_Print((PyObject*)NIT_DTYPES(iter)[iiter], stdout, 0);
+ else
+ printf("(nil) ");
+ printf(" ");
+ }
+ printf("\n");
+ printf("| InitDataPtrs: ");
+ for (iiter = 0; iiter < niter; ++iiter) {
+ printf("%p ", (void *)NIT_RESETDATAPTR(iter)[iiter]);
+ }
+ printf("\n");
+ printf("| BaseOffsets: ");
+ for (iiter = 0; iiter < niter; ++iiter) {
+ printf("%i ", (int)NIT_BASEOFFSETS(iter)[iiter]);
+ }
+ printf("\n");
+ if (itflags&NPY_ITFLAG_HASINDEX) {
+ printf("| InitIndex: %d\n",
+ (int)(npy_intp)NIT_RESETDATAPTR(iter)[niter]);
+ }
+ printf("| Operands: ");
+ for (iiter = 0; iiter < niter; ++iiter) {
+ printf("%p ", (void *)NIT_OPERANDS(iter)[iiter]);
+ }
+ printf("\n");
+ printf("| Operand DTypes: ");
+ for (iiter = 0; iiter < niter; ++iiter) {
+ PyArray_Descr *dtype;
+ if (NIT_OPERANDS(iter)[iiter] != NULL) {
+ dtype = PyArray_DESCR(NIT_OPERANDS(iter)[iiter]);
+ if (dtype != NULL)
+ PyObject_Print((PyObject *)dtype, stdout, 0);
+ else
+ printf("(nil) ");
+ }
+ else {
+ printf("(op nil) ");
+ }
+ printf(" ");
+ }
+ printf("\n");
+ printf("| OpItFlags:\n");
+ for (iiter = 0; iiter < niter; ++iiter) {
+ printf("| Flags[%d]: ", (int)iiter);
+ if ((NIT_OPITFLAGS(iter)[iiter])&NPY_OP_ITFLAG_READ)
+ printf("READ ");
+ if ((NIT_OPITFLAGS(iter)[iiter])&NPY_OP_ITFLAG_WRITE)
+ printf("WRITE ");
+ if ((NIT_OPITFLAGS(iter)[iiter])&NPY_OP_ITFLAG_CAST)
+ printf("CAST ");
+ if ((NIT_OPITFLAGS(iter)[iiter])&NPY_OP_ITFLAG_BUFNEVER)
+ printf("BUFNEVER ");
+ if ((NIT_OPITFLAGS(iter)[iiter])&NPY_OP_ITFLAG_ALIGNED)
+ printf("ALIGNED ");
+ if ((NIT_OPITFLAGS(iter)[iiter])&NPY_OP_ITFLAG_REDUCE)
+ printf("REDUCE ");
+ printf("\n");
+ }
+ printf("|\n");
+
+ if (itflags&NPY_ITFLAG_BUFFER) {
+ NpyIter_BufferData *bufferdata = NIT_BUFFERDATA(iter);
+ printf("| BufferData:\n");
+ printf("| BufferSize: %d\n", (int)NBF_BUFFERSIZE(bufferdata));
+ printf("| Size: %d\n", (int)NBF_SIZE(bufferdata));
+ printf("| BufIterEnd: %d\n", (int)NBF_BUFITEREND(bufferdata));
+ if (itflags&NPY_ITFLAG_REDUCE) {
+ printf("| REDUCE Pos: %d\n",
+ (int)NBF_REDUCE_POS(bufferdata));
+ printf("| REDUCE OuterSize: %d\n",
+ (int)NBF_REDUCE_OUTERSIZE(bufferdata));
+ printf("| REDUCE OuterDim: %d\n",
+ (int)NBF_REDUCE_OUTERDIM(bufferdata));
+ }
+ printf("| Strides: ");
+ for (iiter = 0; iiter < niter; ++iiter)
+ printf("%d ", (int)NBF_STRIDES(bufferdata)[iiter]);
+ printf("\n");
+ /* Print the fixed strides when there's no inner loop */
+ if (itflags&NPY_ITFLAG_NOINNER) {
+ npy_intp fixedstrides[NPY_MAXDIMS];
+ printf("| Fixed Strides: ");
+ NpyIter_GetInnerFixedStrideArray(iter, fixedstrides);
+ for (iiter = 0; iiter < niter; ++iiter)
+ printf("%d ", (int)fixedstrides[iiter]);
+ printf("\n");
+ }
+ printf("| Ptrs: ");
+ for (iiter = 0; iiter < niter; ++iiter)
+ printf("%p ", (void *)NBF_PTRS(bufferdata)[iiter]);
+ printf("\n");
+ if (itflags&NPY_ITFLAG_REDUCE) {
+ printf("| REDUCE Outer Strides: ");
+ for (iiter = 0; iiter < niter; ++iiter)
+ printf("%d ", (int)NBF_REDUCE_OUTERSTRIDES(bufferdata)[iiter]);
+ printf("\n");
+ printf("| REDUCE Outer Ptrs: ");
+ for (iiter = 0; iiter < niter; ++iiter)
+ printf("%p ", (void *)NBF_REDUCE_OUTERPTRS(bufferdata)[iiter]);
+ printf("\n");
+ }
+ printf("| ReadTransferFn: ");
+ for (iiter = 0; iiter < niter; ++iiter)
+ printf("%p ", (void *)NBF_READTRANSFERFN(bufferdata)[iiter]);
+ printf("\n");
+ printf("| ReadTransferData: ");
+ for (iiter = 0; iiter < niter; ++iiter)
+ printf("%p ", (void *)NBF_READTRANSFERDATA(bufferdata)[iiter]);
+ printf("\n");
+ printf("| WriteTransferFn: ");
+ for (iiter = 0; iiter < niter; ++iiter)
+ printf("%p ", (void *)NBF_WRITETRANSFERFN(bufferdata)[iiter]);
+ printf("\n");
+ printf("| WriteTransferData: ");
+ for (iiter = 0; iiter < niter; ++iiter)
+ printf("%p ", (void *)NBF_WRITETRANSFERDATA(bufferdata)[iiter]);
+ printf("\n");
+ printf("| Buffers: ");
+ for (iiter = 0; iiter < niter; ++iiter)
+ printf("%p ", (void *)NBF_BUFFERS(bufferdata)[iiter]);
+ printf("\n");
+ printf("|\n");
+ }
+
+ axisdata = NIT_AXISDATA(iter);
+ sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
+ for (idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) {
+ printf("| AxisData[%d]:\n", (int)idim);
+ printf("| Shape: %d\n", (int)NAD_SHAPE(axisdata));
+ printf("| Coord: %d\n", (int)NAD_COORD(axisdata));
+ printf("| Strides: ");
+ for (iiter = 0; iiter < niter; ++iiter) {
+ printf("%d ", (int)NAD_STRIDES(axisdata)[iiter]);
+ }
+ printf("\n");
+ if (itflags&NPY_ITFLAG_HASINDEX) {
+ printf("| Index Stride: %d\n", (int)NAD_STRIDES(axisdata)[niter]);
+ }
+ printf("| Ptrs: ");
+ for (iiter = 0; iiter < niter; ++iiter) {
+ printf("%p ", (void *)NAD_PTRS(axisdata)[iiter]);
+ }
+ printf("\n");
+ if (itflags&NPY_ITFLAG_HASINDEX) {
+ printf("| Index Value: %d\n",
+ (int)((npy_intp*)NAD_PTRS(axisdata))[niter]);
+ }
+ }
+
+ printf("------- END ITERATOR DUMP -------\n");
+
+ PyGILState_Release(gilstate);
+}
diff --git a/numpy/core/src/multiarray/new_iterator_pywrap.c b/numpy/core/src/multiarray/new_iterator_pywrap.c
new file mode 100644
index 000000000..8e3231d40
--- /dev/null
+++ b/numpy/core/src/multiarray/new_iterator_pywrap.c
@@ -0,0 +1,2471 @@
+/*
+ * This file implements the CPython wrapper of the new NumPy iterator.
+ *
+ * Copyright (c) 2010 by Mark Wiebe (mwwiebe@gmail.com)
+ * The Univerity of British Columbia
+ *
+ * See LICENSE.txt for the license.
+ */
+#define PY_SSIZE_T_CLEAN
+#include "Python.h"
+#include "structmember.h"
+
+#define _MULTIARRAYMODULE
+#include <numpy/ndarrayobject.h>
+#include <numpy/npy_3kcompat.h>
+
+#include "npy_config.h"
+
+#include "numpy/npy_3kcompat.h"
+
+typedef struct NewNpyArrayIterObject_tag NewNpyArrayIterObject;
+
+struct NewNpyArrayIterObject_tag {
+ PyObject_HEAD
+ /* The iterator */
+ NpyIter *iter;
+ /* Flag indicating iteration started/stopped */
+ char started, finished;
+ /* Child to update for nested iteration */
+ NewNpyArrayIterObject *nested_child;
+ /* Cached values from the iterator */
+ NpyIter_IterNextFunc *iternext;
+ NpyIter_GetCoordsFunc *getcoords;
+ char **dataptrs;
+ PyArray_Descr **dtypes;
+ PyArrayObject **operands;
+ npy_intp *innerstrides, *innerloopsizeptr;
+ char readflags[NPY_MAXARGS];
+ char writeflags[NPY_MAXARGS];
+};
+
+void npyiter_cache_values(NewNpyArrayIterObject *self)
+{
+ NpyIter *iter = self->iter;
+
+ /* iternext and getcoords functions */
+ self->iternext = NpyIter_GetIterNext(iter, NULL);
+ if (NpyIter_HasCoords(iter) && !NpyIter_HasDelayedBufAlloc(iter)) {
+ self->getcoords = NpyIter_GetGetCoords(iter, NULL);
+ }
+ else {
+ self->getcoords = NULL;
+ }
+
+ /* Internal data pointers */
+ self->dataptrs = NpyIter_GetDataPtrArray(iter);
+ self->dtypes = NpyIter_GetDescrArray(iter);
+ self->operands = NpyIter_GetOperandArray(iter);
+
+ if (NpyIter_HasInnerLoop(iter)) {
+ self->innerstrides = NULL;
+ self->innerloopsizeptr = NULL;
+ }
+ else {
+ self->innerstrides = NpyIter_GetInnerStrideArray(iter);
+ self->innerloopsizeptr = NpyIter_GetInnerLoopSizePtr(iter);
+ }
+
+ /* The read/write settings */
+ NpyIter_GetReadFlags(iter, self->readflags);
+ NpyIter_GetWriteFlags(iter, self->writeflags);
+}
+
+static PyObject *
+npyiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
+{
+ NewNpyArrayIterObject *self;
+
+ self = (NewNpyArrayIterObject *)subtype->tp_alloc(subtype, 0);
+ if (self != NULL) {
+ self->iter = NULL;
+ self->nested_child = NULL;
+ }
+
+ return (PyObject *)self;
+}
+
+static int
+NpyIter_GlobalFlagsConverter(PyObject *flags_in, npy_uint32 *flags)
+{
+ npy_uint32 tmpflags = 0;
+ int iflags, nflags;
+
+ PyObject *f;
+ char *str = NULL;
+ Py_ssize_t length = 0;
+ npy_uint32 flag;
+
+ if (flags_in == NULL || flags_in == Py_None) {
+ *flags = 0;
+ return 1;
+ }
+
+ if (!PyTuple_Check(flags_in) && !PyList_Check(flags_in)) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator global flags must be a list or tuple of strings");
+ return 0;
+ }
+
+ nflags = PySequence_Size(flags_in);
+
+ for (iflags = 0; iflags < nflags; ++iflags) {
+ f = PySequence_GetItem(flags_in, iflags);
+ if (f == NULL) {
+ return 0;
+ }
+
+ if (PyUnicode_Check(f)) {
+ /* accept unicode input */
+ PyObject *f_str;
+ f_str = PyUnicode_AsASCIIString(f);
+ if (f_str == NULL) {
+ Py_DECREF(f);
+ return 0;
+ }
+ Py_DECREF(f);
+ f = f_str;
+ }
+
+ if (PyBytes_AsStringAndSize(f, &str, &length) == -1) {
+ Py_DECREF(f);
+ return 0;
+ }
+ /* Use switch statements to quickly isolate the right flag */
+ flag = 0;
+ switch (str[0]) {
+ case 'b':
+ if (strcmp(str, "buffered") == 0) {
+ flag = NPY_ITER_BUFFERED;
+ }
+ break;
+ case 'c':
+ if (length >= 6) switch (str[5]) {
+ case 'e':
+ if (strcmp(str, "c_index") == 0) {
+ flag = NPY_ITER_C_INDEX;
+ }
+ break;
+ case 's':
+ if (strcmp(str, "coords") == 0) {
+ flag = NPY_ITER_COORDS;
+ }
+ break;
+ case 'n':
+ if (strcmp(str, "common_dtype") == 0) {
+ flag = NPY_ITER_COMMON_DTYPE;
+ }
+ break;
+ }
+ break;
+ case 'd':
+ if (strcmp(str, "delay_bufalloc") == 0) {
+ flag = NPY_ITER_DELAY_BUFALLOC;
+ }
+ break;
+ case 'f':
+ if (strcmp(str, "f_index") == 0) {
+ flag = NPY_ITER_F_INDEX;
+ }
+ break;
+ case 'g':
+ if (strcmp(str, "growinner") == 0) {
+ flag = NPY_ITER_GROWINNER;
+ }
+ break;
+ case 'n':
+ if (strcmp(str, "no_inner_iteration") == 0) {
+ flag = NPY_ITER_NO_INNER_ITERATION;
+ }
+ break;
+ case 'r':
+ if (strcmp(str, "ranged") == 0) {
+ flag = NPY_ITER_RANGED;
+ }
+ else if (strcmp(str, "refs_ok") == 0) {
+ flag = NPY_ITER_REFS_OK;
+ }
+ else if (strcmp(str, "reduce_ok") == 0) {
+ flag = NPY_ITER_REDUCE_OK;
+ }
+ break;
+ case 'z':
+ if (strcmp(str, "zerosize_ok") == 0) {
+ flag = NPY_ITER_ZEROSIZE_OK;
+ }
+ break;
+ }
+ if (flag == 0) {
+ PyErr_Format(PyExc_ValueError,
+ "Unexpected iterator global flag \"%s\"", str);
+ Py_DECREF(f);
+ return 0;
+ }
+ else {
+ tmpflags |= flag;
+ }
+ Py_DECREF(f);
+ }
+
+ *flags |= tmpflags;
+ return 1;
+}
+
+/* TODO: Use PyArray_OrderConverter once 'K' is added there */
+static int
+npyiter_order_converter(PyObject *order_in, NPY_ORDER *order)
+{
+ char *str = NULL;
+ Py_ssize_t length = 0;
+
+ if (PyUnicode_Check(order_in)) {
+ /* accept unicode input */
+ PyObject *str_obj;
+ int ret;
+ str_obj = PyUnicode_AsASCIIString(order_in);
+ if (str_obj == NULL) {
+ return 0;
+ }
+ ret = npyiter_order_converter(str_obj, order);
+ Py_DECREF(str_obj);
+ return ret;
+ }
+
+ if (PyBytes_AsStringAndSize(order_in, &str, &length) == -1) {
+ return 0;
+ }
+
+ if (length == 1) switch (str[0]) {
+ case 'C':
+ *order = NPY_CORDER;
+ return 1;
+ case 'F':
+ *order = NPY_FORTRANORDER;
+ return 1;
+ case 'A':
+ *order = NPY_ANYORDER;
+ return 1;
+ case 'K':
+ *order = NPY_KEEPORDER;
+ return 1;
+ }
+
+ PyErr_SetString(PyExc_ValueError,
+ "order must be one of 'C', 'F', 'A', or 'K'");
+ return 0;
+}
+
+/*NUMPY_API
+ * Convert any Python object, *obj*, to an NPY_CASTING enum.
+ * TODO: Move elsewhere
+ */
+NPY_NO_EXPORT int
+PyArray_CastingConverter(PyObject *obj, NPY_CASTING *casting)
+{
+ char *str = NULL;
+ Py_ssize_t length = 0;
+
+ if (PyUnicode_Check(obj)) {
+ PyObject *str_obj;
+ int ret;
+ str_obj = PyUnicode_AsASCIIString(obj);
+ if (str_obj == NULL) {
+ return 0;
+ }
+ ret = PyArray_CastingConverter(str_obj, casting);
+ Py_DECREF(str_obj);
+ return ret;
+ }
+
+ if (PyBytes_AsStringAndSize(obj, &str, &length) == -1) {
+ return 0;
+ }
+
+ if (length >= 2) switch (str[2]) {
+ case 0:
+ if (strcmp(str, "no") == 0) {
+ *casting = NPY_NO_CASTING;
+ return 1;
+ }
+ break;
+ case 'u':
+ if (strcmp(str, "equiv") == 0) {
+ *casting = NPY_EQUIV_CASTING;
+ return 1;
+ }
+ break;
+ case 'f':
+ if (strcmp(str, "safe") == 0) {
+ *casting = NPY_SAFE_CASTING;
+ return 1;
+ }
+ break;
+ case 'm':
+ if (strcmp(str, "same_kind") == 0) {
+ *casting = NPY_SAME_KIND_CASTING;
+ return 1;
+ }
+ break;
+ case 's':
+ if (strcmp(str, "unsafe") == 0) {
+ *casting = NPY_UNSAFE_CASTING;
+ return 1;
+ }
+ break;
+ }
+
+ PyErr_SetString(PyExc_ValueError,
+ "casting must be one of 'no', 'equiv', 'safe', "
+ "'same_kind', or 'unsafe'");
+ return 0;
+}
+
+static int
+NpyIter_OpFlagsConverter(PyObject *op_flags_in,
+ npy_uint32 *op_flags)
+{
+ int iflags, nflags;
+ npy_uint32 flag;
+
+ if (!PyTuple_Check(op_flags_in) && !PyList_Check(op_flags_in)) {
+ PyErr_SetString(PyExc_ValueError,
+ "op_flags must be a tuple or array of per-op flag-tuples");
+ return 0;
+ }
+
+ nflags = PySequence_Size(op_flags_in);
+
+ *op_flags = 0;
+ for (iflags = 0; iflags < nflags; ++iflags) {
+ PyObject *f;
+ char *str = NULL;
+ Py_ssize_t length = 0;
+
+ f = PySequence_GetItem(op_flags_in, iflags);
+ if (f == NULL) {
+ return 0;
+ }
+
+ if (PyUnicode_Check(f)) {
+ /* accept unicode input */
+ PyObject *f_str;
+ f_str = PyUnicode_AsASCIIString(f);
+ if (f_str == NULL) {
+ Py_DECREF(f);
+ return 0;
+ }
+ Py_DECREF(f);
+ f = f_str;
+ }
+
+ if (PyBytes_AsStringAndSize(f, &str, &length) == -1) {
+ Py_DECREF(f);
+ PyErr_SetString(PyExc_ValueError,
+ "op_flags must be a tuple or array of per-op flag-tuples");
+ return 0;
+ }
+
+ /* Use switch statements to quickly isolate the right flag */
+ flag = 0;
+ switch (str[0]) {
+ case 'a':
+ if (strcmp(str, "allocate") == 0) {
+ flag = NPY_ITER_ALLOCATE;
+ }
+ if (strcmp(str, "aligned") == 0) {
+ flag = NPY_ITER_ALIGNED;
+ }
+ break;
+ case 'c':
+ if (strcmp(str, "copy") == 0) {
+ flag = NPY_ITER_COPY;
+ }
+ if (strcmp(str, "contig") == 0) {
+ flag = NPY_ITER_CONTIG;
+ }
+ break;
+ case 'n':
+ switch (str[1]) {
+ case 'b':
+ if (strcmp(str, "nbo") == 0) {
+ flag = NPY_ITER_NBO;
+ }
+ break;
+ case 'o':
+ if (strcmp(str, "no_subtype") == 0) {
+ flag = NPY_ITER_NO_SUBTYPE;
+ }
+ else if (strcmp(str, "no_broadcast") == 0) {
+ flag = NPY_ITER_NO_BROADCAST;
+ }
+ break;
+ }
+ break;
+ case 'r':
+ if (length > 4) switch (str[4]) {
+ case 'o':
+ if (strcmp(str, "readonly") == 0) {
+ flag = NPY_ITER_READONLY;
+ }
+ break;
+ case 'w':
+ if (strcmp(str, "readwrite") == 0) {
+ flag = NPY_ITER_READWRITE;
+ }
+ break;
+ }
+ break;
+ case 'u':
+ if (strcmp(str, "updateifcopy") == 0) {
+ flag = NPY_ITER_UPDATEIFCOPY;
+ }
+ break;
+ case 'w':
+ if (strcmp(str, "writeonly") == 0) {
+ flag = NPY_ITER_WRITEONLY;
+ }
+ break;
+ }
+ if (flag == 0) {
+ PyErr_Format(PyExc_ValueError,
+ "Unexpected per-op iterator flag \"%s\"", str);
+ Py_DECREF(f);
+ return 0;
+ }
+ else {
+ *op_flags |= flag;
+ }
+ Py_DECREF(f);
+ }
+
+ return 1;
+}
+
+static int
+npyiter_convert_op_flags_array(PyObject *op_flags_in,
+ npy_uint32 *op_flags_array, npy_intp niter)
+{
+ npy_intp iiter;
+
+ if (!PyTuple_Check(op_flags_in) && !PyList_Check(op_flags_in)) {
+ PyErr_SetString(PyExc_ValueError,
+ "op_flags must be a tuple or array of per-op flag-tuples");
+ return 0;
+ }
+
+ if (PySequence_Size(op_flags_in) != niter) {
+ goto try_single_flags;
+ }
+
+ for (iiter = 0; iiter < niter; ++iiter) {
+ PyObject *f = PySequence_GetItem(op_flags_in, iiter);
+ if (f == NULL) {
+ return 0;
+ }
+ /* If the first item is a string, try as one set of flags */
+ if (iiter == 0 && (PyBytes_Check(f) || PyUnicode_Check(f))) {
+ Py_DECREF(f);
+ goto try_single_flags;
+ }
+ if (NpyIter_OpFlagsConverter(f,
+ &op_flags_array[iiter]) != 1) {
+ Py_DECREF(f);
+ return 0;
+ }
+
+ Py_DECREF(f);
+ }
+
+ return 1;
+
+try_single_flags:
+ if (NpyIter_OpFlagsConverter(op_flags_in,
+ &op_flags_array[0]) != 1) {
+ return 0;
+ }
+
+ for (iiter = 1; iiter < niter; ++iiter) {
+ op_flags_array[iiter] = op_flags_array[0];
+ }
+
+ return 1;
+}
+
+static int
+npyiter_convert_dtypes(PyObject *op_dtypes_in,
+ PyArray_Descr **op_dtypes,
+ npy_intp niter)
+{
+ npy_intp iiter;
+
+ /*
+ * If the input isn't a tuple of dtypes, try converting it as-is
+ * to a dtype, and replicating to all operands.
+ */
+ if ((!PyTuple_Check(op_dtypes_in) && !PyList_Check(op_dtypes_in)) ||
+ PySequence_Size(op_dtypes_in) != niter) {
+ goto try_single_dtype;
+ }
+
+ for (iiter = 0; iiter < niter; ++iiter) {
+ PyObject *dtype = PySequence_GetItem(op_dtypes_in, iiter);
+ if (dtype == NULL) {
+ npy_intp i;
+ for (i = 0; i < iiter; ++i ) {
+ Py_XDECREF(op_dtypes[i]);
+ }
+ return 0;
+ }
+
+ /* Try converting the object to a descr */
+ if (PyArray_DescrConverter2(dtype, &op_dtypes[iiter]) != 1) {
+ npy_intp i;
+ for (i = 0; i < iiter; ++i ) {
+ Py_XDECREF(op_dtypes[i]);
+ }
+ Py_DECREF(dtype);
+ PyErr_Clear();
+ goto try_single_dtype;
+ }
+
+ Py_DECREF(dtype);
+ }
+
+ return 1;
+
+try_single_dtype:
+ if (PyArray_DescrConverter2(op_dtypes_in, &op_dtypes[0]) == 1) {
+ for (iiter = 1; iiter < niter; ++iiter) {
+ op_dtypes[iiter] = op_dtypes[0];
+ Py_XINCREF(op_dtypes[iiter]);
+ }
+ return 1;
+ }
+
+ return 0;
+}
+
+static int
+npyiter_convert_op_axes(PyObject *op_axes_in, npy_intp niter,
+ int **op_axes, int *oa_ndim)
+{
+ PyObject *a;
+ int iiter;
+
+ if ((!PyTuple_Check(op_axes_in) && !PyList_Check(op_axes_in)) ||
+ PySequence_Size(op_axes_in) != niter) {
+ PyErr_SetString(PyExc_ValueError,
+ "op_axes must be a tuple/list matching the number of ops");
+ return 0;
+ }
+
+ *oa_ndim = 0;
+
+ /* Copy the tuples into op_axes */
+ for (iiter = 0; iiter < niter; ++iiter) {
+ int idim;
+ a = PySequence_GetItem(op_axes_in, iiter);
+ if (a == NULL) {
+ return 0;
+ }
+ if (a == Py_None) {
+ op_axes[iiter] = NULL;
+ } else {
+ if (!PyTuple_Check(a) && !PyList_Check(a)) {
+ PyErr_SetString(PyExc_ValueError,
+ "Each entry of op_axes must be None "
+ "or a tuple/list");
+ Py_DECREF(a);
+ return 0;
+ }
+ if (*oa_ndim == 0) {
+ *oa_ndim = PySequence_Size(a);
+ if (*oa_ndim == 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "op_axes must have at least one dimension");
+ return 0;
+ }
+ if (*oa_ndim > NPY_MAXDIMS) {
+ PyErr_SetString(PyExc_ValueError,
+ "Too many dimensions in op_axes");
+ return 0;
+ }
+ }
+ if (PySequence_Size(a) != *oa_ndim) {
+ PyErr_SetString(PyExc_ValueError,
+ "Each entry of op_axes must have the same size");
+ Py_DECREF(a);
+ return 0;
+ }
+ for (idim = 0; idim < *oa_ndim; ++idim) {
+ PyObject *v = PySequence_GetItem(a, idim);
+ if (v == NULL) {
+ Py_DECREF(a);
+ return 0;
+ }
+ /* numpy.newaxis is None */
+ if (v == Py_None) {
+ op_axes[iiter][idim] = -1;
+ }
+ else {
+ op_axes[iiter][idim] = PyInt_AsLong(v);
+ if (op_axes[iiter][idim]==-1 &&
+ PyErr_Occurred()) {
+ Py_DECREF(a);
+ Py_DECREF(v);
+ return 0;
+ }
+ }
+ Py_DECREF(v);
+ }
+ Py_DECREF(a);
+ }
+ }
+
+ if (*oa_ndim == 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "If op_axes is provided, at least one list of axes "
+ "must be contained within it");
+ return 0;
+ }
+
+ return 1;
+}
+
+/*
+ * Converts the operand array and op_flags array into the form NpyIter_MultiNew
+ * needs. Sets niter, and on success, each op[i] owns a reference
+ * to an array object.
+ */
+static int
+npyiter_convert_ops(PyObject *op_in, PyObject *op_flags_in,
+ PyArrayObject **op, npy_uint32 *op_flags,
+ int *niter_out)
+{
+ int iiter, niter;
+
+ /* niter and op */
+ if (PyTuple_Check(op_in) || PyList_Check(op_in)) {
+ niter = PySequence_Size(op_in);
+ if (niter == 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "Must provide at least one operand");
+ return 0;
+ }
+ if (niter > NPY_MAXARGS) {
+ PyErr_SetString(PyExc_ValueError, "Too many operands");
+ return 0;
+ }
+
+ for (iiter = 0; iiter < niter; ++iiter) {
+ PyObject *item = PySequence_GetItem(op_in, iiter);
+ if (item == NULL) {
+ npy_intp i;
+ for (i = 0; i < iiter; ++i) {
+ Py_XDECREF(op[i]);
+ }
+ return 0;
+ }
+ else if (item == Py_None) {
+ Py_DECREF(item);
+ item = NULL;
+ }
+ /* This is converted to an array after op flags are retrieved */
+ op[iiter] = (PyArrayObject *)item;
+ }
+ }
+ else {
+ niter = 1;
+ /* Is converted to an array after op flags are retrieved */
+ Py_INCREF(op_in);
+ op[0] = (PyArrayObject *)op_in;
+ }
+
+ *niter_out = niter;
+
+ /* op_flags */
+ if (op_flags_in == NULL || op_flags_in == Py_None) {
+ for (iiter = 0; iiter < niter; ++iiter) {
+ /*
+ * By default, make NULL operands writeonly and flagged for
+ * allocation, and everything else readonly. To write
+ * to a provided operand, you must specify the write flag manually.
+ */
+ if (op[iiter] == NULL) {
+ op_flags[iiter] = NPY_ITER_WRITEONLY | NPY_ITER_ALLOCATE;
+ }
+ else {
+ op_flags[iiter] = NPY_ITER_READONLY;
+ }
+ }
+ }
+ else if (npyiter_convert_op_flags_array(op_flags_in,
+ op_flags, niter) != 1) {
+ for (iiter = 0; iiter < niter; ++iiter) {
+ Py_XDECREF(op[iiter]);
+ }
+ return 0;
+ }
+
+ /* Now that we have the flags - convert all the ops to arrays */
+ for (iiter = 0; iiter < niter; ++iiter) {
+ if (op[iiter] != NULL) {
+ PyArrayObject *ao;
+ int fromanyflags = 0;
+
+ if (op_flags[iiter]&(NPY_ITER_READWRITE|NPY_ITER_WRITEONLY)) {
+ fromanyflags = NPY_UPDATEIFCOPY;
+ }
+ ao = (PyArrayObject *)PyArray_FromAny((PyObject *)op[iiter],
+ NULL, 0, 0, fromanyflags, NULL);
+ if (ao == NULL) {
+ if (PyErr_Occurred() &&
+ PyErr_ExceptionMatches(PyExc_TypeError)) {
+ PyErr_SetString(PyExc_TypeError,
+ "Iterator operand is flagged as writeable, "
+ "but is an object which cannot be written "
+ "back to via UPDATEIFCOPY");
+ }
+ for (iiter = 0; iiter < niter; ++iiter) {
+ Py_DECREF(op[iiter]);
+ }
+ return 0;
+ }
+ Py_DECREF(op[iiter]);
+ op[iiter] = ao;
+ }
+ }
+
+ return 1;
+}
+
+static int
+npyiter_init(NewNpyArrayIterObject *self, PyObject *args, PyObject *kwds)
+{
+ static char *kwlist[] = {"op", "flags", "op_flags", "op_dtypes",
+ "order", "casting", "op_axes", "buffersize",
+ NULL};
+
+ PyObject *op_in = NULL, *op_flags_in = NULL,
+ *op_dtypes_in = NULL, *op_axes_in = NULL;
+
+ int iiter, niter = 0;
+ PyArrayObject *op[NPY_MAXARGS];
+ npy_uint32 flags = 0;
+ NPY_ORDER order = NPY_KEEPORDER;
+ NPY_CASTING casting = NPY_SAFE_CASTING;
+ npy_uint32 op_flags[NPY_MAXARGS];
+ PyArray_Descr *op_request_dtypes[NPY_MAXARGS];
+ int oa_ndim = 0;
+ int op_axes_arrays[NPY_MAXARGS][NPY_MAXDIMS];
+ int *op_axes[NPY_MAXARGS];
+ int buffersize = 0;
+
+ if (self->iter != NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator was already initialized");
+ return -1;
+ }
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O&OOO&O&Oi", kwlist,
+ &op_in,
+ NpyIter_GlobalFlagsConverter, &flags,
+ &op_flags_in,
+ &op_dtypes_in,
+ npyiter_order_converter, &order,
+ PyArray_CastingConverter, &casting,
+ &op_axes_in,
+ &buffersize)) {
+ return -1;
+ }
+
+ /* op and op_flags */
+ if (npyiter_convert_ops(op_in, op_flags_in, op, op_flags, &niter)
+ != 1) {
+ return -1;
+ }
+
+ /* Set the dtypes to all NULL to start as well */
+ memset(op_request_dtypes, 0, sizeof(op_request_dtypes[0])*niter);
+
+ /* op_request_dtypes */
+ if (op_dtypes_in != NULL && op_dtypes_in != Py_None &&
+ npyiter_convert_dtypes(op_dtypes_in,
+ op_request_dtypes, niter) != 1) {
+ goto fail;
+ }
+
+ /* op_axes */
+ if (op_axes_in != NULL && op_axes_in != Py_None) {
+ /* Initialize to point to the op_axes arrays */
+ for (iiter = 0; iiter < niter; ++iiter) {
+ op_axes[iiter] = op_axes_arrays[iiter];
+ }
+
+ if (npyiter_convert_op_axes(op_axes_in, niter,
+ op_axes, &oa_ndim) != 1) {
+ goto fail;
+ }
+ }
+
+ self->iter = NpyIter_MultiNew(niter, op, flags, order, casting, op_flags,
+ op_request_dtypes,
+ oa_ndim, oa_ndim > 0 ? op_axes : NULL,
+ buffersize);
+
+ if (self->iter == NULL) {
+ goto fail;
+ }
+
+ /* Cache some values for the member functions to use */
+ npyiter_cache_values(self);
+
+ if (NpyIter_GetIterSize(self->iter) == 0) {
+ self->started = 1;
+ self->finished = 1;
+ }
+ else {
+ self->started = 0;
+ self->finished = 0;
+ }
+
+ /* Release the references we got to the ops and dtypes */
+ for (iiter = 0; iiter < niter; ++iiter) {
+ Py_XDECREF(op[iiter]);
+ Py_XDECREF(op_request_dtypes[iiter]);
+ }
+
+ return 0;
+
+fail:
+ for (iiter = 0; iiter < niter; ++iiter) {
+ Py_XDECREF(op[iiter]);
+ Py_XDECREF(op_request_dtypes[iiter]);
+ }
+ return -1;
+}
+
+NPY_NO_EXPORT PyObject *
+NpyIter_NestedIters(PyObject *NPY_UNUSED(self),
+ PyObject *args, PyObject *kwds)
+{
+ static char *kwlist[] = {"op", "axes", "flags", "op_flags",
+ "op_dtypes", "order",
+ "casting", "buffersize",
+ NULL};
+
+ PyObject *op_in = NULL, *axes_in = NULL,
+ *op_flags_in = NULL, *op_dtypes_in = NULL;
+
+ int iiter, niter = 0, inest, nnest = 0;
+ PyArrayObject *op[NPY_MAXARGS];
+ npy_uint32 flags = 0, flags_inner = 0;
+ NPY_ORDER order = NPY_KEEPORDER;
+ NPY_CASTING casting = NPY_SAFE_CASTING;
+ npy_uint32 op_flags[NPY_MAXARGS], op_flags_inner[NPY_MAXARGS];
+ PyArray_Descr *op_request_dtypes[NPY_MAXARGS],
+ *op_request_dtypes_inner[NPY_MAXARGS];
+ int op_axes_data[NPY_MAXDIMS];
+ int *nested_op_axes[NPY_MAXDIMS];
+ int nested_naxes[NPY_MAXDIMS], iaxes, naxes;
+ int negones[NPY_MAXDIMS];
+ char used_axes[NPY_MAXDIMS];
+ int buffersize = 0;
+
+ PyObject *ret = NULL;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|O&OOO&O&i", kwlist,
+ &op_in,
+ &axes_in,
+ NpyIter_GlobalFlagsConverter, &flags,
+ &op_flags_in,
+ &op_dtypes_in,
+ npyiter_order_converter, &order,
+ PyArray_CastingConverter, &casting,
+ &buffersize)) {
+ return NULL;
+ }
+
+ /* axes */
+ if (!PyTuple_Check(axes_in) && !PyList_Check(axes_in)) {
+ PyErr_SetString(PyExc_ValueError,
+ "axes must be a tuple of axis arrays");
+ return NULL;
+ }
+ nnest = PySequence_Size(axes_in);
+ if (nnest < 2) {
+ PyErr_SetString(PyExc_ValueError,
+ "axes must have at least 2 entries for nested iteration");
+ return NULL;
+ }
+ naxes = 0;
+ memset(used_axes, 0, NPY_MAXDIMS);
+ for (inest = 0; inest < nnest; ++inest) {
+ PyObject *item = PySequence_GetItem(axes_in, inest);
+ npy_intp i;
+ if (item == NULL) {
+ return NULL;
+ }
+ if (!PyTuple_Check(item) && !PyList_Check(item)) {
+ PyErr_SetString(PyExc_ValueError,
+ "Each item in axes must be a an integer tuple");
+ Py_DECREF(item);
+ return NULL;
+ }
+ nested_naxes[inest] = PySequence_Size(item);
+ if (naxes + nested_naxes[inest] > NPY_MAXDIMS) {
+ PyErr_SetString(PyExc_ValueError,
+ "Too many axes given");
+ Py_DECREF(item);
+ return NULL;
+ }
+ for (i = 0; i < nested_naxes[inest]; ++i) {
+ PyObject *v = PySequence_GetItem(item, i);
+ npy_intp axis;
+ if (v == NULL) {
+ Py_DECREF(item);
+ return NULL;
+ }
+ axis = PyInt_AsLong(v);
+ Py_DECREF(v);
+ if (axis < 0 || axis >= NPY_MAXDIMS) {
+ PyErr_SetString(PyExc_ValueError,
+ "An axis is out of bounds");
+ Py_DECREF(item);
+ return NULL;
+ }
+ /*
+ * This check is very important, without it out of bounds
+ * data accesses are possible.
+ */
+ if (used_axes[axis] != 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "An axis is used more than once");
+ Py_DECREF(item);
+ return NULL;
+ }
+ used_axes[axis] = 1;
+ op_axes_data[naxes+i] = axis;
+ }
+ nested_op_axes[inest] = &op_axes_data[naxes];
+ naxes += nested_naxes[inest];
+ Py_DECREF(item);
+ }
+
+ /* op and op_flags */
+ if (npyiter_convert_ops(op_in, op_flags_in, op, op_flags, &niter)
+ != 1) {
+ return NULL;
+ }
+
+ /* Set the dtypes to all NULL to start as well */
+ memset(op_request_dtypes, 0, sizeof(op_request_dtypes[0])*niter);
+ memset(op_request_dtypes_inner, 0,
+ sizeof(op_request_dtypes_inner[0])*niter);
+
+ /* op_request_dtypes */
+ if (op_dtypes_in != NULL && op_dtypes_in != Py_None &&
+ npyiter_convert_dtypes(op_dtypes_in,
+ op_request_dtypes, niter) != 1) {
+ goto fail;
+ }
+
+ ret = PyTuple_New(nnest);
+ if (ret == NULL) {
+ goto fail;
+ }
+
+ /* For broadcasting allocated arrays */
+ for (iaxes = 0; iaxes < naxes; ++iaxes) {
+ negones[iaxes] = -1;
+ }
+
+ /*
+ * Clear any unnecessary ALLOCATE flags, so we can use them
+ * to indicate exactly the allocated outputs. Also, separate
+ * the inner loop flags.
+ */
+ for (iiter = 0; iiter < niter; ++iiter) {
+ if ((op_flags[iiter]&NPY_ITER_ALLOCATE) && op[iiter] != NULL) {
+ op_flags[iiter] &= ~NPY_ITER_ALLOCATE;
+ }
+
+ /*
+ * Clear any flags allowing copies or output allocation for
+ * the inner loop.
+ */
+ op_flags_inner[iiter] = op_flags[iiter] & ~(NPY_ITER_COPY|
+ NPY_ITER_UPDATEIFCOPY|
+ NPY_ITER_ALLOCATE);
+ /*
+ * If buffering is enabled and copying is not,
+ * clear the nbo_aligned flag and strip the data type
+ * for the outer loops.
+ */
+ if ((flags&(NPY_ITER_BUFFERED)) &&
+ !(op_flags[iiter]&(NPY_ITER_COPY|
+ NPY_ITER_UPDATEIFCOPY|
+ NPY_ITER_ALLOCATE))) {
+ op_flags[iiter] &= ~(NPY_ITER_NBO|NPY_ITER_ALIGNED|NPY_ITER_CONTIG);
+ op_request_dtypes_inner[iiter] = op_request_dtypes[iiter];
+ op_request_dtypes[iiter] = NULL;
+ }
+ }
+
+ /* Only the inner loop gets the buffering and no inner flags */
+ flags_inner = flags&~NPY_ITER_COMMON_DTYPE;
+ flags &= ~(NPY_ITER_NO_INNER_ITERATION|
+ NPY_ITER_BUFFERED);
+
+ for (inest = 0; inest < nnest; ++inest) {
+ NewNpyArrayIterObject *iter;
+ int *op_axes_niter[NPY_MAXARGS];
+
+ /*
+ * All the operands' op_axes are the same, except for
+ * allocated outputs.
+ */
+ for (iiter = 0; iiter < niter; ++iiter) {
+ if (op_flags[iiter]&NPY_ITER_ALLOCATE) {
+ if (inest == 0) {
+ op_axes_niter[iiter] = NULL;
+ }
+ else {
+ op_axes_niter[iiter] = negones;
+ }
+ }
+ else {
+ op_axes_niter[iiter] = nested_op_axes[inest];
+ }
+ }
+
+ /*
+ printf("\n");
+ for (iiter = 0; iiter < niter; ++iiter) {
+ npy_intp i;
+
+ for (i = 0; i < nested_naxes[inest]; ++i) {
+ printf("%d ", (int)op_axes_niter[iiter][i]);
+ }
+ printf("\n");
+ }
+ */
+
+ /* Allocate the iterator */
+ iter = (NewNpyArrayIterObject *)npyiter_new(&NpyIter_Type, NULL, NULL);
+ if (iter == NULL) {
+ Py_DECREF(ret);
+ goto fail;
+ }
+
+ if (inest < nnest-1) {
+ iter->iter = NpyIter_MultiNew(niter, op, flags, order,
+ casting, op_flags, op_request_dtypes,
+ nested_naxes[inest], op_axes_niter,
+ 0);
+ }
+ else {
+ iter->iter = NpyIter_MultiNew(niter, op, flags_inner, order,
+ casting, op_flags_inner,
+ op_request_dtypes_inner,
+ nested_naxes[inest], op_axes_niter,
+ buffersize);
+ }
+
+ if (iter->iter == NULL) {
+ Py_DECREF(ret);
+ goto fail;
+ }
+
+ /* Cache some values for the member functions to use */
+ npyiter_cache_values(iter);
+
+ if (NpyIter_GetIterSize(iter->iter) == 0) {
+ iter->started = 1;
+ iter->finished = 1;
+ }
+ else {
+ iter->started = 0;
+ iter->finished = 0;
+ }
+
+ /*
+ * If there are any allocated outputs or any copies were made,
+ * adjust op so that the other iterators use the same ones.
+ */
+ if (inest == 0) {
+ PyArrayObject **operands = NpyIter_GetOperandArray(iter->iter);
+ for (iiter = 0; iiter < niter; ++iiter) {
+ if (op[iiter] != operands[iiter]) {
+ Py_XDECREF(op[iiter]);
+ op[iiter] = operands[iiter];
+ Py_INCREF(op[iiter]);
+ }
+
+ /*
+ * Clear any flags allowing copies for
+ * the rest of the iterators
+ */
+ op_flags[iiter] &= ~(NPY_ITER_COPY|
+ NPY_ITER_UPDATEIFCOPY);
+ }
+ /* Clear the common dtype flag for the rest of the iterators */
+ flags &= ~NPY_ITER_COMMON_DTYPE;
+ }
+
+ PyTuple_SET_ITEM(ret, inest, (PyObject *)iter);
+ }
+
+ /* Release our references to the ops and dtypes */
+ for (iiter = 0; iiter < niter; ++iiter) {
+ Py_XDECREF(op[iiter]);
+ Py_XDECREF(op_request_dtypes[iiter]);
+ Py_XDECREF(op_request_dtypes_inner[iiter]);
+ }
+
+ /* Set up the nested child references */
+ for (inest = 0; inest < nnest-1; ++inest) {
+ NewNpyArrayIterObject *iter;
+ iter = (NewNpyArrayIterObject *)PyTuple_GET_ITEM(ret, inest);
+ /*
+ * Indicates which iterator to reset with new base pointers
+ * each iteration step.
+ */
+ iter->nested_child =
+ (NewNpyArrayIterObject *)PyTuple_GET_ITEM(ret, inest+1);
+ Py_INCREF(iter->nested_child);
+ /*
+ * Need to do a nested reset so all the iterators point
+ * at the right data
+ */
+ if (NpyIter_ResetBasePointers(iter->nested_child->iter,
+ iter->dataptrs, NULL) != NPY_SUCCEED) {
+ Py_DECREF(ret);
+ return NULL;
+ }
+ }
+
+ return ret;
+
+fail:
+ for (iiter = 0; iiter < niter; ++iiter) {
+ Py_XDECREF(op[iiter]);
+ Py_XDECREF(op_request_dtypes[iiter]);
+ Py_XDECREF(op_request_dtypes_inner[iiter]);
+ }
+ return NULL;
+}
+
+static void
+npyiter_dealloc(NewNpyArrayIterObject *self)
+{
+ if (self->iter) {
+ NpyIter_Deallocate(self->iter);
+ self->iter = NULL;
+ Py_XDECREF(self->nested_child);
+ self->nested_child = NULL;
+ }
+ Py_TYPE(self)->tp_free((PyObject*)self);
+}
+
+static int
+npyiter_resetbasepointers(NewNpyArrayIterObject *self)
+{
+ while (self->nested_child) {
+ if (NpyIter_ResetBasePointers(self->nested_child->iter,
+ self->dataptrs, NULL) != NPY_SUCCEED) {
+ return NPY_FAIL;
+ }
+ self = self->nested_child;
+ if (NpyIter_GetIterSize(self->iter) == 0) {
+ self->started = 1;
+ self->finished = 1;
+ }
+ else {
+ self->started = 0;
+ self->finished = 0;
+ }
+ }
+
+ return NPY_SUCCEED;
+}
+
+static PyObject *
+npyiter_reset(NewNpyArrayIterObject *self)
+{
+ if (self->iter == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is invalid");
+ return NULL;
+ }
+
+ if (NpyIter_Reset(self->iter, NULL) != NPY_SUCCEED) {
+ return NULL;
+ }
+ if (NpyIter_GetIterSize(self->iter) == 0) {
+ self->started = 1;
+ self->finished = 1;
+ }
+ else {
+ self->started = 0;
+ self->finished = 0;
+ }
+
+ if (self->getcoords == NULL && NpyIter_HasCoords(self->iter)) {
+ self->getcoords = NpyIter_GetGetCoords(self->iter, NULL);
+ }
+
+ /* If there is nesting, the nested iterators should be reset */
+ if (npyiter_resetbasepointers(self) != NPY_SUCCEED) {
+ return NULL;
+ }
+
+ Py_RETURN_NONE;
+}
+
+/*
+ * Makes a copy of the iterator. Note that the nesting is not
+ * copied.
+ */
+static PyObject *
+npyiter_copy(NewNpyArrayIterObject *self)
+{
+ NewNpyArrayIterObject *iter;
+
+ if (self->iter == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is invalid");
+ return NULL;
+ }
+
+ /* Allocate the iterator */
+ iter = (NewNpyArrayIterObject *)npyiter_new(&NpyIter_Type, NULL, NULL);
+ if (iter == NULL) {
+ return NULL;
+ }
+
+ /* Copy the C iterator */
+ iter->iter = NpyIter_Copy(self->iter);
+ if (iter->iter == NULL) {
+ Py_DECREF(iter);
+ return NULL;
+ }
+
+ /* Cache some values for the member functions to use */
+ npyiter_cache_values(iter);
+
+ iter->started = self->started;
+ iter->finished = self->finished;
+
+ return (PyObject *)iter;
+}
+
+static PyObject *
+npyiter_iternext(NewNpyArrayIterObject *self)
+{
+ if (self->iter != NULL && self->iternext != NULL &&
+ !self->finished && self->iternext(self->iter)) {
+ /* If there is nesting, the nested iterators should be reset */
+ if (npyiter_resetbasepointers(self) != NPY_SUCCEED) {
+ return NULL;
+ }
+
+ Py_RETURN_TRUE;
+ }
+ else {
+ self->finished = 1;
+ Py_RETURN_FALSE;
+ }
+}
+
+static PyObject *
+npyiter_remove_axis(NewNpyArrayIterObject *self, PyObject *args)
+{
+ int axis = 0;
+
+ if (self->iter == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is invalid");
+ return NULL;
+ }
+
+ if (!PyArg_ParseTuple(args, "i", &axis)) {
+ return NULL;
+ }
+
+ if (NpyIter_RemoveAxis(self->iter, axis) != NPY_SUCCEED) {
+ return NULL;
+ }
+ /* RemoveAxis invalidates cached values */
+ npyiter_cache_values(self);
+ /* RemoveAxis also resets the iterator */
+ if (NpyIter_GetIterSize(self->iter) == 0) {
+ self->started = 1;
+ self->finished = 1;
+ }
+ else {
+ self->started = 0;
+ self->finished = 0;
+ }
+
+ Py_RETURN_NONE;
+}
+
+static PyObject *
+npyiter_remove_coords(NewNpyArrayIterObject *self)
+{
+ if (self->iter == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is invalid");
+ return NULL;
+ }
+
+ NpyIter_RemoveCoords(self->iter);
+ /* RemoveCoords invalidates cached values */
+ npyiter_cache_values(self);
+ /* RemoveCoords also resets the iterator */
+ if (NpyIter_GetIterSize(self->iter) == 0) {
+ self->started = 1;
+ self->finished = 1;
+ }
+ else {
+ self->started = 0;
+ self->finished = 0;
+ }
+
+ Py_RETURN_NONE;
+}
+
+static PyObject *
+npyiter_remove_inner_loop(NewNpyArrayIterObject *self)
+{
+ if (self->iter == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is invalid");
+ return NULL;
+ }
+
+ NpyIter_RemoveInnerLoop(self->iter);
+ /* RemoveInnerLoop invalidates cached values */
+ npyiter_cache_values(self);
+ /* RemoveInnerLoop also resets the iterator */
+ if (NpyIter_GetIterSize(self->iter) == 0) {
+ self->started = 1;
+ self->finished = 1;
+ }
+ else {
+ self->started = 0;
+ self->finished = 0;
+ }
+
+ Py_RETURN_NONE;
+}
+
+static PyObject *
+npyiter_debug_print(NewNpyArrayIterObject *self)
+{
+ if (self->iter != NULL) {
+ NpyIter_DebugPrint(self->iter);
+ }
+ else {
+ printf("Iterator: (nil)\n");
+ }
+
+ Py_RETURN_NONE;
+}
+
+NPY_NO_EXPORT PyObject *
+npyiter_seq_item(NewNpyArrayIterObject *self, Py_ssize_t i);
+
+static PyObject *npyiter_value_get(NewNpyArrayIterObject *self)
+{
+ PyObject *ret;
+
+ npy_intp iiter, niter;
+ PyArray_Descr **dtypes;
+ char **dataptrs;
+
+ if (self->iter == NULL || self->finished) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is past the end");
+ return NULL;
+ }
+
+ niter = NpyIter_GetNIter(self->iter);
+ dtypes = self->dtypes;
+ dataptrs = self->dataptrs;
+
+ /* Return an array or tuple of arrays with the values */
+ if (niter == 1) {
+ ret = npyiter_seq_item(self, 0);
+ }
+ else {
+ ret = PyTuple_New(niter);
+ if (ret == NULL) {
+ return NULL;
+ }
+ for (iiter = 0; iiter < niter; ++iiter) {
+ PyObject *a = npyiter_seq_item(self, iiter);
+ if (a == NULL) {
+ Py_DECREF(ret);
+ return NULL;
+ }
+ PyTuple_SET_ITEM(ret, iiter, a);
+ }
+ }
+
+ return ret;
+}
+
+static PyObject *npyiter_operands_get(NewNpyArrayIterObject *self)
+{
+ PyObject *ret;
+
+ npy_intp iiter, niter;
+ PyArrayObject **operands;
+
+ if (self->iter == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is invalid");
+ return NULL;
+ }
+
+ niter = NpyIter_GetNIter(self->iter);
+ operands = self->operands;
+
+ ret = PyTuple_New(niter);
+ if (ret == NULL) {
+ return NULL;
+ }
+ for (iiter = 0; iiter < niter; ++iiter) {
+ PyObject *operand = (PyObject *)operands[iiter];
+
+ Py_INCREF(operand);
+ PyTuple_SET_ITEM(ret, iiter, operand);
+ }
+
+ return ret;
+}
+
+static PyObject *npyiter_itviews_get(NewNpyArrayIterObject *self)
+{
+ PyObject *ret;
+
+ npy_intp iiter, niter;
+
+ if (self->iter == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is invalid");
+ return NULL;
+ }
+
+ niter = NpyIter_GetNIter(self->iter);
+
+ ret = PyTuple_New(niter);
+ if (ret == NULL) {
+ return NULL;
+ }
+ for (iiter = 0; iiter < niter; ++iiter) {
+ PyArrayObject *view = NpyIter_GetIterView(self->iter, iiter);
+
+ if (view == NULL) {
+ Py_DECREF(ret);
+ return NULL;
+ }
+ PyTuple_SET_ITEM(ret, iiter, (PyObject *)view);
+ }
+
+ return ret;
+}
+
+static PyObject *
+npyiter_next(NewNpyArrayIterObject *self)
+{
+ if (self->iter == NULL || self->iternext == NULL || self->finished) {
+ return NULL;
+ }
+
+ /*
+ * Use the started flag for the Python iteration protocol to work
+ * when buffering is enabled.
+ */
+ if (self->started) {
+ if (!self->iternext(self->iter)) {
+ self->finished = 1;
+ return NULL;
+ }
+
+ /* If there is nesting, the nested iterators should be reset */
+ if (npyiter_resetbasepointers(self) != NPY_SUCCEED) {
+ return NULL;
+ }
+ }
+ self->started = 1;
+
+ return npyiter_value_get(self);
+};
+
+static PyObject *npyiter_shape_get(NewNpyArrayIterObject *self)
+{
+ PyObject *ret;
+ npy_intp idim, ndim, shape[NPY_MAXDIMS];
+
+ if (self->iter == NULL || self->finished) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is past the end");
+ return NULL;
+ }
+
+ if (NpyIter_GetShape(self->iter, shape) == NPY_SUCCEED) {
+ ndim = NpyIter_GetNDim(self->iter);
+ ret = PyTuple_New(ndim);
+ if (ret != NULL) {
+ for (idim = 0; idim < ndim; ++idim) {
+ PyTuple_SET_ITEM(ret, idim,
+ PyInt_FromLong(shape[idim]));
+ }
+ return ret;
+ }
+ }
+
+ return NULL;
+}
+
+static PyObject *npyiter_coords_get(NewNpyArrayIterObject *self)
+{
+ PyObject *ret;
+ npy_intp idim, ndim, coords[NPY_MAXDIMS];
+
+ if (self->iter == NULL || self->finished) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is past the end");
+ return NULL;
+ }
+
+ if (self->getcoords != NULL) {
+ ndim = NpyIter_GetNDim(self->iter);
+ self->getcoords(self->iter, coords);
+ ret = PyTuple_New(ndim);
+ for (idim = 0; idim < ndim; ++idim) {
+ PyTuple_SET_ITEM(ret, idim,
+ PyInt_FromLong(coords[idim]));
+ }
+ return ret;
+ }
+ else {
+ if (!NpyIter_HasCoords(self->iter)) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator does not have coordinates");
+ return NULL;
+ }
+ else if (NpyIter_HasDelayedBufAlloc(self->iter)) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator construction used delayed buffer allocation, "
+ "and no reset has been done yet");
+ return NULL;
+ }
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is in an invalid state");
+ return NULL;
+ }
+ }
+}
+
+static int npyiter_coords_set(NewNpyArrayIterObject *self, PyObject *value)
+{
+ npy_intp idim, ndim, coords[NPY_MAXDIMS];
+
+ if (self->iter == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is invalid");
+ return -1;
+ }
+
+ if (value == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Cannot delete coordinates");
+ return -1;
+ }
+
+ if (NpyIter_HasCoords(self->iter)) {
+ ndim = NpyIter_GetNDim(self->iter);
+ if (!PySequence_Check(value)) {
+ PyErr_SetString(PyExc_ValueError,
+ "Coordinates must be set with a sequence");
+ return -1;
+ }
+ if (PySequence_Size(value) != ndim) {
+ PyErr_SetString(PyExc_ValueError,
+ "Wrong number of coordinates");
+ return -1;
+ }
+ for (idim = 0; idim < ndim; ++idim) {
+ PyObject *v = PySequence_GetItem(value, idim);
+ coords[idim] = PyInt_AsLong(v);
+ if (coords[idim]==-1 && PyErr_Occurred()) {
+ return -1;
+ }
+ }
+ if (NpyIter_GotoCoords(self->iter, coords) != NPY_SUCCEED) {
+ return -1;
+ }
+ self->started = 0;
+ self->finished = 0;
+
+ /* If there is nesting, the nested iterators should be reset */
+ if (npyiter_resetbasepointers(self) != NPY_SUCCEED) {
+ return -1;
+ }
+
+ return 0;
+ }
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator does not have coordinates");
+ return -1;
+ }
+}
+
+static PyObject *npyiter_index_get(NewNpyArrayIterObject *self)
+{
+ if (self->iter == NULL || self->finished) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is past the end");
+ return NULL;
+ }
+
+ if (NpyIter_HasIndex(self->iter)) {
+ npy_intp ind = *NpyIter_GetIndexPtr(self->iter);
+ return PyInt_FromLong(ind);
+ }
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator does not have an index");
+ return NULL;
+ }
+}
+
+static int npyiter_index_set(NewNpyArrayIterObject *self, PyObject *value)
+{
+ if (self->iter == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is invalid");
+ return -1;
+ }
+
+ if (value == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Cannot delete index");
+ return -1;
+ }
+
+ if (NpyIter_HasIndex(self->iter)) {
+ npy_intp ind;
+ ind = PyInt_AsLong(value);
+ if (ind==-1 && PyErr_Occurred()) {
+ return -1;
+ }
+ if (NpyIter_GotoIndex(self->iter, ind) != NPY_SUCCEED) {
+ return -1;
+ }
+ self->started = 0;
+ self->finished = 0;
+
+ /* If there is nesting, the nested iterators should be reset */
+ if (npyiter_resetbasepointers(self) != NPY_SUCCEED) {
+ return -1;
+ }
+
+ return 0;
+ }
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator does not have an index");
+ return -1;
+ }
+}
+
+static PyObject *npyiter_iterindex_get(NewNpyArrayIterObject *self)
+{
+ if (self->iter == NULL || self->finished) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is past the end");
+ return NULL;
+ }
+
+ return PyInt_FromLong(NpyIter_GetIterIndex(self->iter));
+}
+
+static int npyiter_iterindex_set(NewNpyArrayIterObject *self, PyObject *value)
+{
+ npy_intp iterindex;
+
+ if (self->iter == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is invalid");
+ return -1;
+ }
+
+ if (value == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Cannot delete iterindex");
+ return -1;
+ }
+
+ iterindex = PyInt_AsLong(value);
+ if (iterindex==-1 && PyErr_Occurred()) {
+ return -1;
+ }
+ if (NpyIter_GotoIterIndex(self->iter, iterindex) != NPY_SUCCEED) {
+ return -1;
+ }
+ self->started = 0;
+ self->finished = 0;
+
+ /* If there is nesting, the nested iterators should be reset */
+ if (npyiter_resetbasepointers(self) != NPY_SUCCEED) {
+ return -1;
+ }
+
+ return 0;
+}
+
+static PyObject *npyiter_iterrange_get(NewNpyArrayIterObject *self)
+{
+ npy_intp istart = 0, iend = 0;
+ PyObject *ret;
+
+ if (self->iter == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is invalid");
+ return NULL;
+ }
+
+ NpyIter_GetIterIndexRange(self->iter, &istart, &iend);
+
+ ret = PyTuple_New(2);
+ if (ret == NULL) {
+ return NULL;
+ }
+
+ PyTuple_SET_ITEM(ret, 0, PyInt_FromLong(istart));
+ PyTuple_SET_ITEM(ret, 1, PyInt_FromLong(iend));
+
+ return ret;
+}
+
+static int npyiter_iterrange_set(NewNpyArrayIterObject *self, PyObject *value)
+{
+#if PY_VERSION_HEX >= 0x02050000
+ npy_intp istart = 0, iend = 0;
+#else
+ long istart = 0, iend = 0;
+#endif
+
+ if (self->iter == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is invalid");
+ return -1;
+ }
+
+ if (value == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Cannot delete iterrange");
+ return -1;
+ }
+
+#if PY_VERSION_HEX >= 0x02050000
+ if (!PyArg_ParseTuple(value, "nn", &istart, &iend)) {
+#else
+ if (!PyArg_ParseTuple(value, "ll", &istart, &iend)) {
+#endif
+ return -1;
+ }
+
+ if (NpyIter_ResetToIterIndexRange(self->iter, istart, iend, NULL)
+ != NPY_SUCCEED) {
+ return -1;
+ }
+ if (istart < iend) {
+ self->started = self->finished = 0;
+ }
+ else {
+ self->started = self->finished = 1;
+ }
+
+ if (self->getcoords == NULL && NpyIter_HasCoords(self->iter)) {
+ self->getcoords = NpyIter_GetGetCoords(self->iter, NULL);
+ }
+
+ /* If there is nesting, the nested iterators should be reset */
+ if (npyiter_resetbasepointers(self) != NPY_SUCCEED) {
+ return -1;
+ }
+
+ return 0;
+}
+
+static PyObject *npyiter_hasdelayedbufalloc_get(NewNpyArrayIterObject *self)
+{
+ if (self->iter == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is invalid");
+ return NULL;
+ }
+
+ if (NpyIter_HasDelayedBufAlloc(self->iter)) {
+ Py_RETURN_TRUE;
+ }
+ else {
+ Py_RETURN_FALSE;
+ }
+}
+
+static PyObject *npyiter_iterationneedsapi_get(NewNpyArrayIterObject *self)
+{
+ if (self->iter == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is invalid");
+ return NULL;
+ }
+
+ if (NpyIter_IterationNeedsAPI(self->iter)) {
+ Py_RETURN_TRUE;
+ }
+ else {
+ Py_RETURN_FALSE;
+ }
+}
+
+static PyObject *npyiter_hascoords_get(NewNpyArrayIterObject *self)
+{
+ if (self->iter == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is invalid");
+ return NULL;
+ }
+
+ if (NpyIter_HasCoords(self->iter)) {
+ Py_RETURN_TRUE;
+ }
+ else {
+ Py_RETURN_FALSE;
+ }
+}
+
+static PyObject *npyiter_hasindex_get(NewNpyArrayIterObject *self)
+{
+ if (self->iter == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is invalid");
+ return NULL;
+ }
+
+ if (NpyIter_HasIndex(self->iter)) {
+ Py_RETURN_TRUE;
+ }
+ else {
+ Py_RETURN_FALSE;
+ }
+}
+
+static PyObject *npyiter_dtypes_get(NewNpyArrayIterObject *self)
+{
+ PyObject *ret;
+
+ npy_intp iiter, niter;
+ PyArray_Descr **dtypes;
+
+ if (self->iter == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is invalid");
+ return NULL;
+ }
+
+ niter = NpyIter_GetNIter(self->iter);
+
+ ret = PyTuple_New(niter);
+ if (ret == NULL) {
+ return NULL;
+ }
+ dtypes = self->dtypes;
+ for (iiter = 0; iiter < niter; ++iiter) {
+ PyArray_Descr *dtype = dtypes[iiter];
+
+ Py_INCREF(dtype);
+ PyTuple_SET_ITEM(ret, iiter, (PyObject *)dtype);
+ }
+
+ return ret;
+}
+
+static PyObject *npyiter_ndim_get(NewNpyArrayIterObject *self)
+{
+ if (self->iter == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is invalid");
+ return NULL;
+ }
+
+ return PyInt_FromLong(NpyIter_GetNDim(self->iter));
+}
+
+static PyObject *npyiter_niter_get(NewNpyArrayIterObject *self)
+{
+ if (self->iter == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is invalid");
+ return NULL;
+ }
+
+ return PyInt_FromLong(NpyIter_GetNIter(self->iter));
+}
+
+static PyObject *npyiter_itersize_get(NewNpyArrayIterObject *self)
+{
+ if (self->iter == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is invalid");
+ return NULL;
+ }
+
+ return PyInt_FromLong(NpyIter_GetIterSize(self->iter));
+}
+
+static PyObject *npyiter_finished_get(NewNpyArrayIterObject *self)
+{
+ if (self->iter == NULL || !self->finished) {
+ Py_RETURN_FALSE;
+ }
+ else {
+ Py_RETURN_TRUE;
+ }
+}
+
+NPY_NO_EXPORT Py_ssize_t
+npyiter_seq_length(NewNpyArrayIterObject *self)
+{
+ if (self->iter == NULL) {
+ return 0;
+ }
+ else {
+ return NpyIter_GetNIter(self->iter);
+ }
+}
+
+NPY_NO_EXPORT PyObject *
+npyiter_seq_item(NewNpyArrayIterObject *self, Py_ssize_t i)
+{
+ PyObject *ret;
+
+ npy_intp ret_ndim;
+ npy_intp niter, innerloopsize, innerstride;
+ char *dataptr;
+ PyArray_Descr *dtype;
+
+ if (self->iter == NULL || self->finished) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is past the end");
+ return NULL;
+ }
+
+ if (NpyIter_HasDelayedBufAlloc(self->iter)) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator construction used delayed buffer allocation, "
+ "and no reset has been done yet");
+ return NULL;
+ }
+
+ niter = NpyIter_GetNIter(self->iter);
+ if (i < 0 || i >= niter) {
+ PyErr_Format(PyExc_IndexError,
+ "Iterator operand index %d is out of bounds", (int)i);
+ return NULL;
+ }
+
+#if 0
+ /*
+ * This check is disabled because it prevents things like
+ * np.add(it[0], it[1], it[2]), where it[2] is a write-only
+ * parameter. When write-only, the value of it[i] is
+ * likely random junk, as if it were allocated with an
+ * np.empty(...) call.
+ */
+ if (!self->readflags[i]) {
+ PyErr_Format(PyExc_RuntimeError,
+ "Iterator operand %d is write-only", (int)i);
+ return NULL;
+ }
+#endif
+
+ dataptr = self->dataptrs[i];
+ dtype = self->dtypes[i];
+
+ if (NpyIter_HasInnerLoop(self->iter)) {
+ innerloopsize = 1;
+ innerstride = 0;
+ /* If the iterator is going over every element, return array scalars */
+ ret_ndim = 0;
+ }
+ else {
+ innerloopsize = *self->innerloopsizeptr;
+ innerstride = self->innerstrides[i];
+ ret_ndim = 1;
+ }
+
+ Py_INCREF(dtype);
+ ret = (PyObject *)PyArray_NewFromDescr(&PyArray_Type, dtype,
+ ret_ndim, &innerloopsize,
+ &innerstride, dataptr,
+ self->writeflags[i] ? NPY_WRITEABLE : 0, NULL);
+ Py_INCREF(self);
+ ((PyArrayObject *)ret)->base = (PyObject *)self;
+
+ PyArray_UpdateFlags((PyArrayObject *)ret, NPY_UPDATE_ALL);
+
+ return ret;
+}
+
+NPY_NO_EXPORT PyObject *
+npyiter_seq_slice(NewNpyArrayIterObject *self,
+ Py_ssize_t ilow, Py_ssize_t ihigh)
+{
+ PyObject *ret;
+ npy_intp niter;
+ Py_ssize_t i;
+
+ if (self->iter == NULL || self->finished) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is past the end");
+ return NULL;
+ }
+
+ if (NpyIter_HasDelayedBufAlloc(self->iter)) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator construction used delayed buffer allocation, "
+ "and no reset has been done yet");
+ return NULL;
+ }
+
+ niter = NpyIter_GetNIter(self->iter);
+ if (ilow < 0) {
+ ilow = 0;
+ }
+ else if (ilow >= niter) {
+ ilow = niter-1;
+ }
+ if (ihigh < ilow) {
+ ihigh = ilow;
+ }
+ else if (ihigh > niter) {
+ ihigh = niter;
+ }
+
+ ret = PyTuple_New(ihigh-ilow);
+ if (ret == NULL) {
+ return NULL;
+ }
+ for (i = ilow; i < ihigh ; ++i) {
+ PyObject *item = npyiter_seq_item(self, i);
+ if (item == NULL) {
+ Py_DECREF(ret);
+ return NULL;
+ }
+ PyTuple_SET_ITEM(ret, i-ilow, item);
+ }
+ return ret;
+}
+
+NPY_NO_EXPORT int
+npyiter_seq_ass_item(NewNpyArrayIterObject *self, Py_ssize_t i, PyObject *v)
+{
+
+ npy_intp niter, innerloopsize, innerstride;
+ char *dataptr;
+ PyArray_Descr *dtype;
+ PyArrayObject *tmp;
+ int ret;
+
+ if (v == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "can't delete iterator operands");
+ return -1;
+ }
+
+ if (self->iter == NULL || self->finished) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is past the end");
+ return -1;
+ }
+
+ if (NpyIter_HasDelayedBufAlloc(self->iter)) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator construction used delayed buffer allocation, "
+ "and no reset has been done yet");
+ return -1;
+ }
+
+ niter = NpyIter_GetNIter(self->iter);
+ if (i < 0 || i >= niter) {
+ PyErr_Format(PyExc_IndexError,
+ "Iterator operand index %d is out of bounds", (int)i);
+ return -1;
+ }
+ if (!self->writeflags[i]) {
+ PyErr_Format(PyExc_RuntimeError,
+ "Iterator operand %d is not writeable", (int)i);
+ return -1;
+ }
+
+ dataptr = self->dataptrs[i];
+ dtype = self->dtypes[i];
+
+ if (NpyIter_HasInnerLoop(self->iter)) {
+ innerloopsize = 1;
+ innerstride = 0;
+ }
+ else {
+ innerloopsize = *self->innerloopsizeptr;
+ innerstride = self->innerstrides[i];
+ }
+
+ /* TODO - there should be a better way than this... */
+ Py_INCREF(dtype);
+ tmp = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, dtype,
+ 1, &innerloopsize,
+ &innerstride, dataptr,
+ NPY_WRITEABLE, NULL);
+ if (tmp == NULL) {
+ return -1;
+ }
+ PyArray_UpdateFlags(tmp, NPY_UPDATE_ALL);
+ ret = PyArray_CopyObject(tmp, v);
+ Py_DECREF(tmp);
+ return ret;
+}
+
+static int
+npyiter_seq_ass_slice(NewNpyArrayIterObject *self, Py_ssize_t ilow,
+ Py_ssize_t ihigh, PyObject *v)
+{
+ npy_intp niter;
+ Py_ssize_t i;
+
+ if (v == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "cannot delete iterator elements");
+ return -1;
+ }
+
+ if (self->iter == NULL || self->finished) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is past the end");
+ return -1;
+ }
+
+ if (NpyIter_HasDelayedBufAlloc(self->iter)) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator construction used delayed buffer allocation, "
+ "and no reset has been done yet");
+ return -1;
+ }
+
+ niter = NpyIter_GetNIter(self->iter);
+ if (ilow < 0) {
+ ilow = 0;
+ }
+ else if (ilow >= niter) {
+ ilow = niter-1;
+ }
+ if (ihigh < ilow) {
+ ihigh = ilow;
+ }
+ else if (ihigh > niter) {
+ ihigh = niter;
+ }
+
+ if (!PySequence_Check(v) || PySequence_Size(v) != ihigh-ilow) {
+ PyErr_SetString(PyExc_ValueError,
+ "Wrong size to assign to iterator slice");
+ return -1;
+ }
+
+ for (i = ilow; i < ihigh ; ++i) {
+ PyObject *item = PySequence_GetItem(v, i-ilow);
+ if (item == NULL) {
+ return -1;
+ }
+ if (npyiter_seq_ass_item(self, i, item) < 0) {
+ Py_DECREF(item);
+ return -1;
+ }
+ Py_DECREF(item);
+ }
+
+ return 0;
+}
+
+static PyObject *
+npyiter_subscript(NewNpyArrayIterObject *self, PyObject *op)
+{
+ if (self->iter == NULL || self->finished) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is past the end");
+ return NULL;
+ }
+
+ if (NpyIter_HasDelayedBufAlloc(self->iter)) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator construction used delayed buffer allocation, "
+ "and no reset has been done yet");
+ return NULL;
+ }
+
+ if (PyInt_Check(op) || PyLong_Check(op) ||
+ (PyIndex_Check(op) && !PySequence_Check(op))) {
+ npy_intp i = PyArray_PyIntAsIntp(op);
+ if (i == -1 && PyErr_Occurred()) {
+ return NULL;
+ }
+ return npyiter_seq_item(self, i);
+ }
+ else if (PySlice_Check(op)) {
+ Py_ssize_t istart = 0, iend = 0, istep = 0;
+ if (PySlice_GetIndices((PySliceObject *)op,
+ NpyIter_GetNIter(self->iter),
+ &istart, &iend, &istep) < 0) {
+ return NULL;
+ }
+ if (istep != 1) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator slicing only supports a step of 1");
+ return NULL;
+ }
+ return npyiter_seq_slice(self, istart, iend);
+ }
+
+ PyErr_SetString(PyExc_TypeError,
+ "invalid index type for iterator indexing");
+ return NULL;
+}
+
+static int
+npyiter_ass_subscript(NewNpyArrayIterObject *self, PyObject *op,
+ PyObject *value)
+{
+ if (self->iter == NULL || self->finished) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator is past the end");
+ return -1;
+ }
+
+ if (NpyIter_HasDelayedBufAlloc(self->iter)) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator construction used delayed buffer allocation, "
+ "and no reset has been done yet");
+ return -1;
+ }
+
+ if (PyInt_Check(op) || PyLong_Check(op) ||
+ (PyIndex_Check(op) && !PySequence_Check(op))) {
+ npy_intp i = PyArray_PyIntAsIntp(op);
+ if (i == -1 && PyErr_Occurred()) {
+ return -1;
+ }
+ return npyiter_seq_ass_item(self, i, value);
+ }
+ else if (PySlice_Check(op)) {
+ Py_ssize_t istart = 0, iend = 0, istep = 0;
+ if (PySlice_GetIndices((PySliceObject *)op,
+ NpyIter_GetNIter(self->iter),
+ &istart, &iend, &istep) < 0) {
+ return -1;
+ }
+ if (istep != 1) {
+ PyErr_SetString(PyExc_ValueError,
+ "Iterator slice assignment only supports a step of 1");
+ return -1;
+ }
+ return npyiter_seq_ass_slice(self, istart, iend, value);
+ }
+
+ PyErr_SetString(PyExc_TypeError,
+ "invalid index type for iterator indexing");
+ return -1;
+}
+
+static PyMethodDef npyiter_methods[] = {
+ {"reset", (PyCFunction)npyiter_reset, METH_NOARGS, NULL},
+ {"copy", (PyCFunction)npyiter_copy, METH_NOARGS, NULL},
+ {"__copy__", (PyCFunction)npyiter_copy, METH_NOARGS, NULL},
+ {"iternext", (PyCFunction)npyiter_iternext, METH_NOARGS, NULL},
+ {"remove_axis", (PyCFunction)npyiter_remove_axis, METH_VARARGS, NULL},
+ {"remove_coords", (PyCFunction)npyiter_remove_coords, METH_NOARGS, NULL},
+ {"remove_inner_loop", (PyCFunction)npyiter_remove_inner_loop,
+ METH_NOARGS, NULL},
+ {"debug_print", (PyCFunction)npyiter_debug_print, METH_NOARGS, NULL},
+ {NULL, NULL, 0, NULL},
+};
+
+static PyMemberDef npyiter_members[] = {
+ {NULL, 0, 0, 0, NULL},
+};
+
+static PyGetSetDef npyiter_getsets[] = {
+ {"value",
+ (getter)npyiter_value_get,
+ NULL, NULL, NULL},
+ {"shape",
+ (getter)npyiter_shape_get,
+ NULL, NULL, NULL},
+ {"coords",
+ (getter)npyiter_coords_get,
+ (setter)npyiter_coords_set,
+ NULL, NULL},
+ {"index",
+ (getter)npyiter_index_get,
+ (setter)npyiter_index_set,
+ NULL, NULL},
+ {"iterindex",
+ (getter)npyiter_iterindex_get,
+ (setter)npyiter_iterindex_set,
+ NULL, NULL},
+ {"iterrange",
+ (getter)npyiter_iterrange_get,
+ (setter)npyiter_iterrange_set,
+ NULL, NULL},
+ {"operands",
+ (getter)npyiter_operands_get,
+ NULL, NULL, NULL},
+ {"itviews",
+ (getter)npyiter_itviews_get,
+ NULL, NULL, NULL},
+ {"hasdelayedbufalloc",
+ (getter)npyiter_hasdelayedbufalloc_get,
+ NULL, NULL, NULL},
+ {"iterationneedsapi",
+ (getter)npyiter_iterationneedsapi_get,
+ NULL, NULL, NULL},
+ {"hascoords",
+ (getter)npyiter_hascoords_get,
+ NULL, NULL, NULL},
+ {"hasindex",
+ (getter)npyiter_hasindex_get,
+ NULL, NULL, NULL},
+ {"dtypes",
+ (getter)npyiter_dtypes_get,
+ NULL, NULL, NULL},
+ {"ndim",
+ (getter)npyiter_ndim_get,
+ NULL, NULL, NULL},
+ {"niter",
+ (getter)npyiter_niter_get,
+ NULL, NULL, NULL},
+ {"itersize",
+ (getter)npyiter_itersize_get,
+ NULL, NULL, NULL},
+ {"finished",
+ (getter)npyiter_finished_get,
+ NULL, NULL, NULL},
+
+ {NULL, NULL, NULL, NULL, NULL},
+};
+
+NPY_NO_EXPORT PySequenceMethods npyiter_as_sequence = {
+#if PY_VERSION_HEX >= 0x02050000
+ (lenfunc)npyiter_seq_length, /*sq_length*/
+ (binaryfunc)NULL, /*sq_concat*/
+ (ssizeargfunc)NULL, /*sq_repeat*/
+ (ssizeargfunc)npyiter_seq_item, /*sq_item*/
+ (ssizessizeargfunc)npyiter_seq_slice, /*sq_slice*/
+ (ssizeobjargproc)npyiter_seq_ass_item, /*sq_ass_item*/
+ (ssizessizeobjargproc)npyiter_seq_ass_slice,/*sq_ass_slice*/
+ (objobjproc)NULL, /*sq_contains */
+ (binaryfunc)NULL, /*sq_inplace_concat */
+ (ssizeargfunc)NULL, /*sq_inplace_repeat */
+#else
+ (inquiry)npyiter_seq_length, /*sq_length*/
+ (binaryfunc)NULL, /*sq_concat is handled by nb_add*/
+ (intargfunc)NULL, /*sq_repeat is handled nb_multiply*/
+ (intargfunc)npyiter_seq_item, /*sq_item*/
+ (intintargfunc)npyiter_seq_slice, /*sq_slice*/
+ (intobjargproc)npyiter_seq_ass_item, /*sq_ass_item*/
+ (intintobjargproc)npyiter_seq_ass_slice,/*sq_ass_slice*/
+ (objobjproc)NULL, /*sq_contains */
+ (binaryfunc)NULL, /*sg_inplace_concat */
+ (intargfunc)NULL /*sg_inplace_repeat */
+#endif
+};
+
+NPY_NO_EXPORT PyMappingMethods npyiter_as_mapping = {
+#if PY_VERSION_HEX >= 0x02050000
+ (lenfunc)npyiter_seq_length, /*mp_length*/
+#else
+ (inquiry)npyiter_seq_length, /*mp_length*/
+#endif
+ (binaryfunc)npyiter_subscript, /*mp_subscript*/
+ (objobjargproc)npyiter_ass_subscript, /*mp_ass_subscript*/
+};
+
+NPY_NO_EXPORT PyTypeObject NpyIter_Type = {
+#if defined(NPY_PY3K)
+ PyVarObject_HEAD_INIT(NULL, 0)
+#else
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+#endif
+ "numpy.newiter", /* tp_name */
+ sizeof(NewNpyArrayIterObject), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ /* methods */
+ (destructor)npyiter_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+#if defined(NPY_PY3K)
+ 0, /* tp_reserved */
+#else
+ 0, /* tp_compare */
+#endif
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ &npyiter_as_sequence, /* tp_as_sequence */
+ &npyiter_as_mapping, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ (iternextfunc)npyiter_next, /* tp_iternext */
+ npyiter_methods, /* tp_methods */
+ npyiter_members, /* tp_members */
+ npyiter_getsets, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)npyiter_init, /* tp_init */
+ 0, /* tp_alloc */
+ npyiter_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
+ 0, /* tp_mro */
+ 0, /* tp_cache */
+ 0, /* tp_subclasses */
+ 0, /* tp_weaklist */
+ 0, /* tp_del */
+#if PY_VERSION_HEX >= 0x02060000
+ 0, /* tp_version_tag */
+#endif
+};
diff --git a/numpy/core/src/multiarray/new_iterator_pywrap.h b/numpy/core/src/multiarray/new_iterator_pywrap.h
new file mode 100644
index 000000000..35e322541
--- /dev/null
+++ b/numpy/core/src/multiarray/new_iterator_pywrap.h
@@ -0,0 +1,8 @@
+#ifndef __NEW_ITERATOR_PYWRAP_H
+#define __NEW_ITERATOR_PYWRAP_H
+
+NPY_NO_EXPORT PyObject *
+NpyIter_NestedIters(PyObject *NPY_UNUSED(self),
+ PyObject *args, PyObject *kwds);
+
+#endif
diff --git a/numpy/core/src/multiarray/number.c b/numpy/core/src/multiarray/number.c
index ee9bf27a4..fc2928a4e 100644
--- a/numpy/core/src/multiarray/number.c
+++ b/numpy/core/src/multiarray/number.c
@@ -608,6 +608,15 @@ array_int(PyArrayObject *v)
Py_DECREF(pv);
return NULL;
}
+ /*
+ * If we still got an array which can hold references, stop
+ * because it could point back at 'v'.
+ */
+ if (PyArray_Check(pv) && PyDataType_REFCHK(PyArray_DESCR(pv))) {
+ PyErr_SetString(PyExc_TypeError,
+ "object array may be self-referencing");
+ return NULL;
+ }
pv2 = Py_TYPE(pv)->tp_as_number->nb_int(pv);
Py_DECREF(pv);
@@ -639,6 +648,15 @@ array_float(PyArrayObject *v)
Py_DECREF(pv);
return NULL;
}
+ /*
+ * If we still got an array which can hold references, stop
+ * because it could point back at 'v'.
+ */
+ if (PyArray_Check(pv) && PyDataType_REFCHK(PyArray_DESCR(pv))) {
+ PyErr_SetString(PyExc_TypeError,
+ "object array may be self-referencing");
+ return NULL;
+ }
pv2 = Py_TYPE(pv)->tp_as_number->nb_float(pv);
Py_DECREF(pv);
return pv2;
@@ -666,6 +684,15 @@ array_long(PyArrayObject *v)
"scalar number to long");
return NULL;
}
+ /*
+ * If we still got an array which can hold references, stop
+ * because it could point back at 'v'.
+ */
+ if (PyArray_Check(pv) && PyDataType_REFCHK(PyArray_DESCR(pv))) {
+ PyErr_SetString(PyExc_TypeError,
+ "object array may be self-referencing");
+ return NULL;
+ }
pv2 = Py_TYPE(pv)->tp_as_number->nb_long(pv);
Py_DECREF(pv);
return pv2;
@@ -691,6 +718,15 @@ array_oct(PyArrayObject *v)
"scalar number to oct");
return NULL;
}
+ /*
+ * If we still got an array which can hold references, stop
+ * because it could point back at 'v'.
+ */
+ if (PyArray_Check(pv) && PyDataType_REFCHK(PyArray_DESCR(pv))) {
+ PyErr_SetString(PyExc_TypeError,
+ "object array may be self-referencing");
+ return NULL;
+ }
pv2 = Py_TYPE(pv)->tp_as_number->nb_oct(pv);
Py_DECREF(pv);
return pv2;
@@ -716,6 +752,15 @@ array_hex(PyArrayObject *v)
"scalar number to hex");
return NULL;
}
+ /*
+ * If we still got an array which can hold references, stop
+ * because it could point back at 'v'.
+ */
+ if (PyArray_Check(pv) && PyDataType_REFCHK(PyArray_DESCR(pv))) {
+ PyErr_SetString(PyExc_TypeError,
+ "object array may be self-referencing");
+ return NULL;
+ }
pv2 = Py_TYPE(pv)->tp_as_number->nb_hex(pv);
Py_DECREF(pv);
return pv2;
diff --git a/numpy/core/src/multiarray/numpyos.c b/numpy/core/src/multiarray/numpyos.c
index b37e03942..d7f23cfaf 100644
--- a/numpy/core/src/multiarray/numpyos.c
+++ b/numpy/core/src/multiarray/numpyos.c
@@ -422,7 +422,7 @@ NumPyOS_ascii_strncasecmp(const char* s1, const char* s2, size_t len)
/*
* _NumPyOS_ascii_strtod_plain:
- *
+ *
* PyOS_ascii_strtod work-alike, with no enhanced features,
* for forward compatibility with Python >= 2.7
*/
diff --git a/numpy/core/src/multiarray/refcount.c b/numpy/core/src/multiarray/refcount.c
index 9fb4a901f..c9024a083 100644
--- a/numpy/core/src/multiarray/refcount.c
+++ b/numpy/core/src/multiarray/refcount.c
@@ -280,4 +280,3 @@ _fillobject(char *optr, PyObject *obj, PyArray_Descr *dtype)
return;
}
}
-
diff --git a/numpy/core/src/multiarray/scalarapi.c b/numpy/core/src/multiarray/scalarapi.c
index 87e140c4e..3d2fae39c 100644
--- a/numpy/core/src/multiarray/scalarapi.c
+++ b/numpy/core/src/multiarray/scalarapi.c
@@ -354,7 +354,19 @@ PyArray_ScalarFromObject(PyObject *object)
if (PyArray_IsZeroDim(object)) {
return PyArray_ToScalar(PyArray_DATA(object), object);
}
- if (PyInt_Check(object)) {
+ /*
+ * Booleans in Python are implemented as a subclass of integers,
+ * so PyBool_Check must be called before PyInt_Check.
+ */
+ if (PyBool_Check(object)) {
+ if (object == Py_True) {
+ PyArrayScalar_RETURN_TRUE;
+ }
+ else {
+ PyArrayScalar_RETURN_FALSE;
+ }
+ }
+ else if (PyInt_Check(object)) {
ret = PyArrayScalar_New(Long);
if (ret == NULL) {
return NULL;
@@ -389,14 +401,6 @@ PyArray_ScalarFromObject(PyObject *object)
}
PyArrayScalar_VAL(ret, LongLong) = val;
}
- else if (PyBool_Check(object)) {
- if (object == Py_True) {
- PyArrayScalar_RETURN_TRUE;
- }
- else {
- PyArrayScalar_RETURN_FALSE;
- }
- }
return ret;
}
diff --git a/numpy/core/src/multiarray/scalartypes.c.src b/numpy/core/src/multiarray/scalartypes.c.src
index c66337602..eff71d12d 100644
--- a/numpy/core/src/multiarray/scalartypes.c.src
+++ b/numpy/core/src/multiarray/scalartypes.c.src
@@ -3277,32 +3277,69 @@ NPY_NO_EXPORT PyTypeObject Py@NAME@ArrType_Type = {
*/
NPY_NO_EXPORT char
_npy_scalar_kinds_table[NPY_NTYPES];
+
+/*
+ * This table maps a scalar kind (excluding NPY_NOSCALAR)
+ * to the smallest type number of that kind.
+ */
+NPY_NO_EXPORT char
+_npy_smallest_type_of_kind_table[NPY_NSCALARKINDS];
+
+/*
+ * This table gives the type of the same kind, but next in the sequence
+ * of sizes.
+ */
+NPY_NO_EXPORT char
+_npy_next_larger_type_table[NPY_NTYPES];
+
/*
* This table describes safe casting for small type numbers,
* and is used by PyArray_CanCastSafely.
*/
NPY_NO_EXPORT unsigned char
_npy_can_cast_safely_table[NPY_NTYPES][NPY_NTYPES];
+
+/*
+ * This table gives the smallest-size and smallest-kind type to which
+ * the input types may be safely cast, according to _npy_can_cast_safely.
+ */
+NPY_NO_EXPORT char
+_npy_type_promotion_table[NPY_NTYPES][NPY_NTYPES];
#endif
NPY_NO_EXPORT void
initialize_casting_tables(void)
{
- int i;
+ int i, j;
+
+ _npy_smallest_type_of_kind_table[NPY_BOOL_SCALAR] = NPY_BOOL;
+ _npy_smallest_type_of_kind_table[NPY_INTPOS_SCALAR] = NPY_UBYTE;
+ _npy_smallest_type_of_kind_table[NPY_INTNEG_SCALAR] = NPY_BYTE;
+ _npy_smallest_type_of_kind_table[NPY_FLOAT_SCALAR] = NPY_HALF;
+ _npy_smallest_type_of_kind_table[NPY_COMPLEX_SCALAR] = NPY_CFLOAT;
+ _npy_smallest_type_of_kind_table[NPY_OBJECT_SCALAR] = NPY_OBJECT;
/* Default for built-in types is object scalar */
memset(_npy_scalar_kinds_table, PyArray_OBJECT_SCALAR,
sizeof(_npy_scalar_kinds_table));
+ /* Default for next largest type is -1, signalling no bigger */
+ memset(_npy_next_larger_type_table, -1,
+ sizeof(_npy_next_larger_type_table));
/* Compile-time loop of scalar kinds */
/**begin repeat
* #NAME = BOOL, BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG,
* LONGLONG, ULONGLONG, HALF, FLOAT, DOUBLE, LONGDOUBLE,
* CFLOAT, CDOUBLE, CLONGDOUBLE#
+ * #BIGGERTYPE = -1, NPY_SHORT, NPY_USHORT, NPY_INT, NPY_UINT,
+ * NPY_LONG, NPY_ULONG, NPY_LONGLONG, NPY_ULONGLONG,
+ * -1, -1, NPY_FLOAT, NPY_DOUBLE, NPY_LONGDOUBLE, -1,
+ * NPY_CDOUBLE, NPY_CLONGDOUBLE, -1#
* #SCKIND = BOOL, (INTNEG, INTPOS)*5, FLOAT*4,
* COMPLEX*3#
*/
- _npy_scalar_kinds_table[PyArray_@NAME@] = PyArray_@SCKIND@_SCALAR;
+ _npy_scalar_kinds_table[NPY_@NAME@] = PyArray_@SCKIND@_SCALAR;
+ _npy_next_larger_type_table[NPY_@NAME@] = @BIGGERTYPE@;
/**end repeat**/
memset(_npy_can_cast_safely_table, 0, sizeof(_npy_can_cast_safely_table));
@@ -3311,17 +3348,17 @@ initialize_casting_tables(void)
/* Identity */
_npy_can_cast_safely_table[i][i] = 1;
/* Bool -> <Anything> */
- _npy_can_cast_safely_table[PyArray_BOOL][i] = 1;
+ _npy_can_cast_safely_table[NPY_BOOL][i] = 1;
/* DateTime sits out for these... */
if (i != PyArray_DATETIME && i != PyArray_TIMEDELTA) {
/* <Anything> -> Object */
- _npy_can_cast_safely_table[i][PyArray_OBJECT] = 1;
+ _npy_can_cast_safely_table[i][NPY_OBJECT] = 1;
/* <Anything> -> Void */
- _npy_can_cast_safely_table[i][PyArray_VOID] = 1;
+ _npy_can_cast_safely_table[i][NPY_VOID] = 1;
}
}
- _npy_can_cast_safely_table[PyArray_STRING][PyArray_UNICODE] = 1;
+ _npy_can_cast_safely_table[NPY_STRING][NPY_UNICODE] = 1;
#ifndef NPY_SIZEOF_BYTE
#define NPY_SIZEOF_BYTE 1
@@ -3349,7 +3386,7 @@ initialize_casting_tables(void)
* 1, 1, 1#
*/
#define _FROM_BSIZE NPY_SIZEOF_@FROM_BASENAME@
-#define _FROM_NUM (PyArray_@FROM_NAME@)
+#define _FROM_NUM (NPY_@FROM_NAME@)
_npy_can_cast_safely_table[_FROM_NUM][PyArray_STRING] = 1;
_npy_can_cast_safely_table[_FROM_NUM][PyArray_UNICODE] = 1;
@@ -3375,7 +3412,7 @@ initialize_casting_tables(void)
* 1, 1, 1#
*/
#define _TO_BSIZE NPY_SIZEOF_@TO_BASENAME@
-#define _TO_NUM (PyArray_@TO_NAME@)
+#define _TO_NUM (NPY_@TO_NAME@)
/*
* NOTE: _FROM_BSIZE and _TO_BSIZE are the sizes of the "base type"
@@ -3454,6 +3491,89 @@ initialize_casting_tables(void)
/**end repeat**/
+ /*
+ * Now that the _can_cast_safely table is finished, we can
+ * use it to build the _type_promotion table
+ */
+ for (i = 0; i < NPY_NTYPES; ++i) {
+ _npy_type_promotion_table[i][i] = i;
+ /* Don't let number promote to string/unicode/void */
+ if (i == NPY_STRING || i == NPY_UNICODE || i == NPY_VOID) {
+ /* Promoting these types requires examining their contents */
+ _npy_type_promotion_table[i][i] = -1;
+ for (j = i+1; j < NPY_NTYPES; ++j) {
+ _npy_type_promotion_table[i][j] = -1;
+ _npy_type_promotion_table[j][i] = -1;
+ }
+ /* Except they can convert to OBJECT */
+ _npy_type_promotion_table[i][NPY_OBJECT] = NPY_OBJECT;
+ _npy_type_promotion_table[NPY_OBJECT][i] = NPY_OBJECT;
+ }
+ else {
+ for (j = i+1; j < NPY_NTYPES; ++j) {
+ /* Don't let number promote to string/unicode/void */
+ if (j == NPY_STRING || j == NPY_UNICODE || j == NPY_VOID) {
+ _npy_type_promotion_table[i][j] = -1;
+ _npy_type_promotion_table[j][i] = -1;
+ }
+ else if (_npy_can_cast_safely_table[i][j]) {
+ _npy_type_promotion_table[i][j] = j;
+ _npy_type_promotion_table[j][i] = j;
+ }
+ else if (_npy_can_cast_safely_table[j][i]) {
+ _npy_type_promotion_table[i][j] = i;
+ _npy_type_promotion_table[j][i] = i;
+ }
+ else {
+ int k, iskind, jskind, skind;
+ iskind = _npy_scalar_kinds_table[i];
+ jskind = _npy_scalar_kinds_table[j];
+ /* If there's no kind (void/string/etc) */
+ if (iskind == NPY_NOSCALAR || jskind == NPY_NOSCALAR) {
+ k = -1;
+ }
+ else {
+ /* Start with the type of larger kind */
+ if (iskind > jskind) {
+ skind = iskind;
+ k = i;
+ }
+ else {
+ skind = jskind;
+ k = j;
+ }
+ for (;;) {
+ /* Try the next larger type of this kind */
+ k = _npy_next_larger_type_table[k];
+
+ /* If there is no larger, try a larger kind */
+ if (k < 0) {
+ ++skind;
+ /* Use -1 to signal no promoted type found */
+ if (skind < NPY_NSCALARKINDS) {
+ k = _npy_smallest_type_of_kind_table[skind];
+ }
+ else {
+ k = -1;
+ break;
+ }
+ }
+
+ if (_npy_can_cast_safely_table[i][k] &&
+ _npy_can_cast_safely_table[j][k]) {
+ break;
+ }
+ }
+ }
+ _npy_type_promotion_table[i][j] = k;
+ _npy_type_promotion_table[j][i] = k;
+ }
+ }
+ }
+ }
+ /* Special case date-time */
+ _npy_type_promotion_table[NPY_DATETIME][NPY_TIMEDELTA] = NPY_DATETIME;
+ _npy_type_promotion_table[NPY_TIMEDELTA][NPY_DATETIME] = NPY_DATETIME;
}
@@ -3634,19 +3754,19 @@ static PyTypeObject *typeobjects[] = {
&PyULongArrType_Type,
&PyLongLongArrType_Type,
&PyULongLongArrType_Type,
- &PyHalfArrType_Type,
&PyFloatArrType_Type,
&PyDoubleArrType_Type,
&PyLongDoubleArrType_Type,
&PyCFloatArrType_Type,
&PyCDoubleArrType_Type,
&PyCLongDoubleArrType_Type,
- &PyDatetimeArrType_Type,
- &PyTimedeltaArrType_Type,
&PyObjectArrType_Type,
&PyStringArrType_Type,
&PyUnicodeArrType_Type,
- &PyVoidArrType_Type
+ &PyVoidArrType_Type,
+ &PyDatetimeArrType_Type,
+ &PyTimedeltaArrType_Type,
+ &PyHalfArrType_Type
};
NPY_NO_EXPORT int
diff --git a/numpy/core/src/multiarray/scalartypes.h b/numpy/core/src/multiarray/scalartypes.h
index c60f61dfb..53850947a 100644
--- a/numpy/core/src/multiarray/scalartypes.h
+++ b/numpy/core/src/multiarray/scalartypes.h
@@ -7,11 +7,23 @@ extern NPY_NO_EXPORT unsigned char
_npy_can_cast_safely_table[NPY_NTYPES][NPY_NTYPES];
extern NPY_NO_EXPORT char
_npy_scalar_kinds_table[NPY_NTYPES];
+extern NPY_NO_EXPORT char
+_npy_type_promotion_table[NPY_NTYPES][NPY_NTYPES];
+extern NPY_NO_EXPORT char
+_npy_smallest_type_of_kind_table[NPY_NSCALARKINDS];
+extern NPY_NO_EXPORT char
+_npy_next_larger_type_table[NPY_NTYPES];
#else
NPY_NO_EXPORT unsigned char
_npy_can_cast_safely_table[NPY_NTYPES][NPY_NTYPES];
NPY_NO_EXPORT char
_npy_scalar_kinds_table[NPY_NTYPES];
+NPY_NO_EXPORT char
+_npy_type_promotion_table[NPY_NTYPES][NPY_NTYPES];
+NPY_NO_EXPORT char
+_npy_smallest_type_of_kind_table[NPY_NSCALARKINDS];
+NPY_NO_EXPORT char
+_npy_next_larger_type_table[NPY_NTYPES];
#endif
NPY_NO_EXPORT void
diff --git a/numpy/core/src/multiarray/sequence.c b/numpy/core/src/multiarray/sequence.c
index e3fff56c6..dd2ea48eb 100644
--- a/numpy/core/src/multiarray/sequence.c
+++ b/numpy/core/src/multiarray/sequence.c
@@ -182,4 +182,3 @@ array_any_nonzero(PyArrayObject *mp)
Py_DECREF(it);
return anyTRUE;
}
-
diff --git a/numpy/core/src/multiarray/shape.c b/numpy/core/src/multiarray/shape.c
index 671dc1538..1672ce394 100644
--- a/numpy/core/src/multiarray/shape.c
+++ b/numpy/core/src/multiarray/shape.c
@@ -174,7 +174,7 @@ PyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck,
*/
NPY_NO_EXPORT PyObject *
PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims,
- NPY_ORDER fortran)
+ NPY_ORDER order)
{
intp i;
intp *dimensions = newdims->ptr;
@@ -185,8 +185,8 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims,
intp newstrides[MAX_DIMS];
int flags;
- if (fortran == PyArray_ANYORDER) {
- fortran = PyArray_ISFORTRAN(self);
+ if (order == PyArray_ANYORDER) {
+ order = PyArray_ISFORTRAN(self);
}
/* Quick check to make sure anything actually needs to be done */
if (n == self->nd) {
@@ -233,12 +233,12 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims,
*/
if (!(PyArray_ISONESEGMENT(self)) ||
(((PyArray_CHKFLAGS(self, NPY_CONTIGUOUS) &&
- fortran == NPY_FORTRANORDER) ||
+ order == NPY_FORTRANORDER) ||
(PyArray_CHKFLAGS(self, NPY_FORTRAN) &&
- fortran == NPY_CORDER)) && (self->nd > 1))) {
+ order == NPY_CORDER)) && (self->nd > 1))) {
int success = 0;
success = _attempt_nocopy_reshape(self,n,dimensions,
- newstrides,fortran);
+ newstrides,order);
if (success) {
/* no need to copy the array after all */
strides = newstrides;
@@ -246,7 +246,7 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims,
}
else {
PyObject *new;
- new = PyArray_NewCopy(self, fortran);
+ new = PyArray_NewCopy(self, order);
if (new == NULL) {
return NULL;
}
@@ -260,7 +260,7 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims,
/* Make sure the flags argument is set. */
if (n > 1) {
- if (fortran == NPY_FORTRANORDER) {
+ if (order == NPY_FORTRANORDER) {
flags &= ~NPY_CONTIGUOUS;
flags |= NPY_FORTRAN;
}
@@ -275,7 +275,7 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims,
* replace any 0-valued strides with
* appropriate value to preserve contiguousness
*/
- if (fortran == PyArray_FORTRANORDER) {
+ if (order == NPY_FORTRANORDER) {
if (strides[0] == 0) {
strides[0] = self->descr->elsize;
}
@@ -760,29 +760,137 @@ PyArray_Transpose(PyArrayObject *ap, PyArray_Dims *permute)
return (PyObject *)ret;
}
+/*
+ * Sorts items so stride is descending, because C-order
+ * is the default in the face of ambiguity.
+ */
+int _npy_stride_sort_item_comparator(const void *a, const void *b)
+{
+ npy_intp astride = ((_npy_stride_sort_item *)a)->stride,
+ bstride = ((_npy_stride_sort_item *)b)->stride;
+
+ /* Sort the absolute value of the strides */
+ if (astride < 0) {
+ astride = -astride;
+ }
+ if (bstride < 0) {
+ bstride = -bstride;
+ }
+
+ if (astride > bstride) {
+ return -1;
+ }
+ else if (astride == bstride) {
+ /*
+ * Make the qsort stable by next comparing the perm order.
+ * (Note that two perm entries will never be equal)
+ */
+ npy_intp aperm = ((_npy_stride_sort_item *)a)->perm,
+ bperm = ((_npy_stride_sort_item *)b)->perm;
+ return (aperm < bperm) ? -1 : 1;
+ }
+ else {
+ return 1;
+ }
+}
+
+/*
+ * This function populates the first PyArray_NDIM(arr) elements
+ * of strideperm with sorted descending by their absolute values.
+ * For example, the stride array (4, -2, 12) becomes
+ * [(2, 12), (0, 4), (1, -2)].
+ */
+NPY_NO_EXPORT void
+PyArray_CreateSortedStridePerm(PyArrayObject *arr,
+ _npy_stride_sort_item *strideperm)
+{
+ int i, ndim = PyArray_NDIM(arr);
+
+ /* Set up the strideperm values */
+ for (i = 0; i < ndim; ++i) {
+ strideperm[i].perm = i;
+ strideperm[i].stride = PyArray_STRIDE(arr, i);
+ }
+
+ /* Sort them */
+ qsort(strideperm, ndim, sizeof(_npy_stride_sort_item),
+ &_npy_stride_sort_item_comparator);
+}
+
/*NUMPY_API
* Ravel
* Returns a contiguous array
*/
NPY_NO_EXPORT PyObject *
-PyArray_Ravel(PyArrayObject *a, NPY_ORDER fortran)
+PyArray_Ravel(PyArrayObject *a, NPY_ORDER order)
{
PyArray_Dims newdim = {NULL,1};
intp val[1] = {-1};
- if (fortran == PyArray_ANYORDER) {
- fortran = PyArray_ISFORTRAN(a);
- }
newdim.ptr = val;
- if (!fortran && PyArray_ISCONTIGUOUS(a)) {
- return PyArray_Newshape(a, &newdim, PyArray_CORDER);
+
+ if (order == NPY_ANYORDER) {
+ order = PyArray_ISFORTRAN(a) ? NPY_FORTRANORDER : NPY_CORDER;
}
- else if (fortran && PyArray_ISFORTRAN(a)) {
- return PyArray_Newshape(a, &newdim, PyArray_FORTRANORDER);
+ else if (order == NPY_KEEPORDER) {
+ if (PyArray_IS_C_CONTIGUOUS(a)) {
+ order = NPY_CORDER;
+ }
+ else if (PyArray_IS_F_CONTIGUOUS(a)) {
+ order = NPY_FORTRANORDER;
+ }
}
- else {
- return PyArray_Flatten(a, fortran);
+
+ if (order == NPY_CORDER && PyArray_ISCONTIGUOUS(a)) {
+ return PyArray_Newshape(a, &newdim, NPY_CORDER);
+ }
+ else if (order == NPY_FORTRANORDER && PyArray_ISFORTRAN(a)) {
+ return PyArray_Newshape(a, &newdim, NPY_FORTRANORDER);
+ }
+ /* For KEEPORDER, check if we can make a flattened view */
+ else if (order == NPY_KEEPORDER) {
+ _npy_stride_sort_item strideperm[NPY_MAXDIMS];
+ npy_intp stride;
+ int i, ndim = PyArray_NDIM(a);
+
+ PyArray_CreateSortedStridePerm(a, strideperm);
+
+ stride = PyArray_DESCR(a)->elsize;
+ for (i = ndim-1; i >= 0; --i) {
+ if (strideperm[i].stride != stride) {
+ break;
+ }
+ stride *= PyArray_DIM(a, strideperm[i].perm);
+ }
+
+ /* If all the strides matched a contiguous layout, return a view */
+ if (i < 0) {
+ PyObject *ret;
+ npy_intp stride = PyArray_DESCR(a)->elsize;
+
+ val[0] = PyArray_SIZE(a);
+
+ Py_INCREF(PyArray_DESCR(a));
+ ret = PyArray_NewFromDescr(Py_TYPE(a),
+ PyArray_DESCR(a),
+ 1, val,
+ &stride,
+ PyArray_BYTES(a),
+ PyArray_FLAGS(a),
+ (PyObject *)a);
+
+ if (ret != NULL) {
+ PyArray_UpdateFlags((PyArrayObject *)ret,
+ NPY_CONTIGUOUS|NPY_FORTRAN);
+ Py_INCREF(a);
+ PyArray_BASE(ret) = (PyObject *)a;
+ }
+ return ret;
+ }
+
}
+
+ return PyArray_Flatten(a, order);
}
/*NUMPY_API
@@ -791,15 +899,16 @@ PyArray_Ravel(PyArrayObject *a, NPY_ORDER fortran)
NPY_NO_EXPORT PyObject *
PyArray_Flatten(PyArrayObject *a, NPY_ORDER order)
{
- PyObject *ret;
+ PyArrayObject *ret;
intp size;
- if (order == PyArray_ANYORDER) {
- order = PyArray_ISFORTRAN(a);
+ if (order == NPY_ANYORDER) {
+ order = PyArray_ISFORTRAN(a) ? NPY_FORTRANORDER : NPY_CORDER;
}
+
size = PyArray_SIZE(a);
Py_INCREF(a->descr);
- ret = PyArray_NewFromDescr(Py_TYPE(a),
+ ret = (PyArrayObject *)PyArray_NewFromDescr(Py_TYPE(a),
a->descr,
1, &size,
NULL,
@@ -809,11 +918,9 @@ PyArray_Flatten(PyArrayObject *a, NPY_ORDER order)
if (ret == NULL) {
return NULL;
}
- if (_flat_copyinto(ret, (PyObject *)a, order) < 0) {
+ if (PyArray_CopyAnyIntoOrdered(ret, a, order) < 0) {
Py_DECREF(ret);
return NULL;
}
- return ret;
+ return (PyObject *)ret;
}
-
-
diff --git a/numpy/core/src/multiarray/shape.h b/numpy/core/src/multiarray/shape.h
index 1a5991a50..8038a9f25 100644
--- a/numpy/core/src/multiarray/shape.h
+++ b/numpy/core/src/multiarray/shape.h
@@ -1,4 +1,18 @@
#ifndef _NPY_ARRAY_SHAPE_H_
#define _NPY_ARRAY_SHAPE_H_
+typedef struct {
+ npy_intp perm, stride;
+} _npy_stride_sort_item;
+
+/*
+ * This function populates the first PyArray_NDIM(arr) elements
+ * of strideperm with sorted descending by their absolute values.
+ * For example, the stride array (4, -2, 12) becomes
+ * [(2, 12), (0, 4), (1, -2)].
+ */
+NPY_NO_EXPORT void
+PyArray_CreateSortedStridePerm(PyArrayObject *arr,
+ _npy_stride_sort_item *strideperm);
+
#endif
diff --git a/numpy/core/src/multiarray/testcalcs.py b/numpy/core/src/multiarray/testcalcs.py
index 599e1d58e..d7ea67faf 100644
--- a/numpy/core/src/multiarray/testcalcs.py
+++ b/numpy/core/src/multiarray/testcalcs.py
@@ -4,7 +4,7 @@ class YMD(object):
year = 0
month = 0
days = 0
-
+
month_offset = [
[ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 ],
@@ -30,7 +30,7 @@ def year_offset(year):
return_val = year*365 + year/4 - year/100 + year/400;
else
return_val = year*365 + (year-3)/4 - (year-99)/100 + (year-399)/400;
- """
+ """
return weave.inline(code,['year'])
@@ -53,7 +53,7 @@ def days_from_ymd(year, month, day):
#
yearoffset = year_offset(year);
- # Calculate the number of days using yearoffset */
+ # Calculate the number of days using yearoffset */
# Jan 1, 1970 is day 0 and thus Dec. 31, 1969 is day -1 */
absdate = day-1 + month_offset[leap][month - 1] + yearoffset;
@@ -64,8 +64,3 @@ def ymd_from_days(days):
ymd = YMD()
year = 1970 + days / 365.2425
-
-
-
-
-
diff --git a/numpy/core/src/multiarray/usertypes.c b/numpy/core/src/multiarray/usertypes.c
index 594722695..2b2db39b8 100644
--- a/numpy/core/src/multiarray/usertypes.c
+++ b/numpy/core/src/multiarray/usertypes.c
@@ -94,7 +94,7 @@ PyArray_InitArrFuncs(PyArray_ArrFuncs *f)
{
int i;
- for(i = 0; i < PyArray_NTYPES; i++) {
+ for(i = 0; i < NPY_NTYPES_ABI_COMPATIBLE; i++) {
f->cast[i] = NULL;
}
f->getitem = NULL;
@@ -188,11 +188,11 @@ PyArray_RegisterCastFunc(PyArray_Descr *descr, int totype,
PyObject *cobj, *key;
int ret;
- if (totype < PyArray_NTYPES) {
+ if (totype < NPY_NTYPES_ABI_COMPATIBLE) {
descr->f->cast[totype] = castfunc;
return 0;
}
- if (!PyTypeNum_ISUSERDEF(totype)) {
+ if (totype >= NPY_NTYPES && !PyTypeNum_ISUSERDEF(totype)) {
PyErr_SetString(PyExc_TypeError, "invalid type number.");
return -1;
}
@@ -272,4 +272,3 @@ PyArray_RegisterCanCast(PyArray_Descr *descr, int totype,
}
return 0;
}
-
diff --git a/numpy/core/src/npymath/halffloat.c b/numpy/core/src/npymath/halffloat.c
index da92d3e12..a49e3b02e 100644
--- a/numpy/core/src/npymath/halffloat.c
+++ b/numpy/core/src/npymath/halffloat.c
@@ -1,5 +1,4 @@
#include "numpy/halffloat.h"
-#include "numpy/ufuncobject.h"
/*
* This chooses between 'ties to even' and 'ties away from zero'.
@@ -77,11 +76,16 @@ npy_half npy_half_spacing(npy_half h)
npy_half ret;
npy_uint16 h_exp = h&0x7c00u;
npy_uint16 h_sig = h&0x03ffu;
- if (h_exp == 0x7c00u || h == 0x7bffu) {
+ if (h_exp == 0x7c00u) {
#if NPY_HALF_GENERATE_INVALID
- generate_invalid_error();
+ npy_set_floatstatus_invalid();
#endif
ret = NPY_HALF_NAN;
+ } else if (h == 0x7bffu) {
+#if NPY_HALF_GENERATE_OVERFLOW
+ npy_set_floatstatus_overflow();
+#endif
+ ret = NPY_HALF_PINF;
} else if ((h&0x8000u) && h_sig == 0) { /* Negative boundary case */
if (h_exp > 0x2c00u) { /* If result is normalized */
ret = h_exp - 0x2c00u;
@@ -112,7 +116,7 @@ npy_half npy_half_nextafter(npy_half x, npy_half y)
if (!npy_half_isfinite(x) || npy_half_isnan(y)) {
#if NPY_HALF_GENERATE_INVALID
- generate_invalid_error();
+ npy_set_floatstatus_invalid();
#endif
ret = NPY_HALF_NAN;
} else if (npy_half_eq_nonan(x, y)) {
@@ -134,7 +138,7 @@ npy_half npy_half_nextafter(npy_half x, npy_half y)
}
#ifdef NPY_HALF_GENERATE_OVERFLOW
if (npy_half_isinf(ret)) {
- generate_overflow_error();
+ npy_set_floatstatus_overflow();
}
#endif
@@ -255,7 +259,7 @@ npy_uint16 npy_floatbits_to_halfbits(npy_uint32 f)
} else {
/* overflow to signed inf */
#if NPY_HALF_GENERATE_OVERFLOW
- generate_overflow_error();
+ npy_set_floatstatus_overflow();
#endif
return (npy_uint16) (h_sgn + 0x7c00u);
}
@@ -271,7 +275,7 @@ npy_uint16 npy_floatbits_to_halfbits(npy_uint32 f)
#if NPY_HALF_GENERATE_UNDERFLOW
/* If f != 0, it underflowed to 0 */
if ((f&0x7fffffff) != 0) {
- generate_underflow_error();
+ npy_set_floatstatus_underflow();
}
#endif
return h_sgn;
@@ -282,7 +286,7 @@ npy_uint16 npy_floatbits_to_halfbits(npy_uint32 f)
#if NPY_HALF_GENERATE_UNDERFLOW
/* If it's not exactly represented, it underflowed */
if ((f_sig&(((npy_uint32)1 << (126 - f_exp)) - 1)) != 0) {
- generate_underflow_error();
+ npy_set_floatstatus_underflow();
}
#endif
f_sig >>= (113 - f_exp);
@@ -334,7 +338,7 @@ npy_uint16 npy_floatbits_to_halfbits(npy_uint32 f)
#if NPY_HALF_GENERATE_OVERFLOW
h_sig += h_exp;
if (h_sig == 0x7c00u) {
- generate_overflow_error();
+ npy_set_floatstatus_overflow();
}
return h_sgn + h_sig;
#else
@@ -347,14 +351,14 @@ npy_uint16 npy_doublebits_to_halfbits(npy_uint64 d)
npy_uint64 d_exp, d_sig;
npy_uint16 h_sgn, h_exp, h_sig;
- h_sgn = (d&0x8000000000000000u) >> 48;
- d_exp = (d&0x7ff0000000000000u);
+ h_sgn = (d&0x8000000000000000ULL) >> 48;
+ d_exp = (d&0x7ff0000000000000ULL);
/* Exponent overflow/NaN converts to signed inf/NaN */
- if (d_exp >= 0x40f0000000000000u) {
- if (d_exp == 0x7ff0000000000000u) {
+ if (d_exp >= 0x40f0000000000000ULL) {
+ if (d_exp == 0x7ff0000000000000ULL) {
/* Inf or NaN */
- d_sig = (d&0x000fffffffffffffu);
+ d_sig = (d&0x000fffffffffffffULL);
if (d_sig != 0) {
/* NaN - propagate the flag in the significand... */
npy_uint16 ret = (npy_uint16) (0x7c00u + (d_sig >> 42));
@@ -370,34 +374,34 @@ npy_uint16 npy_doublebits_to_halfbits(npy_uint64 d)
} else {
/* overflow to signed inf */
#if NPY_HALF_GENERATE_OVERFLOW
- generate_overflow_error();
+ npy_set_floatstatus_overflow();
#endif
return h_sgn + 0x7c00u;
}
}
/* Exponent underflow converts to subnormal half or signed zero */
- if (d_exp <= 0x3f00000000000000u) {
+ if (d_exp <= 0x3f00000000000000ULL) {
/*
* Signed zeros, subnormal floats, and floats with small
* exponents all convert to signed zero halfs.
*/
- if (d_exp < 0x3e60000000000000u) {
+ if (d_exp < 0x3e60000000000000ULL) {
#if NPY_HALF_GENERATE_UNDERFLOW
/* If d != 0, it underflowed to 0 */
- if ((d&0x7fffffffffffffff) != 0) {
- generate_underflow_error();
+ if ((d&0x7fffffffffffffffULL) != 0) {
+ npy_set_floatstatus_underflow();
}
#endif
return h_sgn;
}
/* Make the subnormal significand */
d_exp >>= 52;
- d_sig = (0x0010000000000000u + (d&0x000fffffffffffffu));
+ d_sig = (0x0010000000000000ULL + (d&0x000fffffffffffffULL));
#if NPY_HALF_GENERATE_UNDERFLOW
/* If it's not exactly represented, it underflowed */
if ((d_sig&(((npy_uint64)1 << (1051 - d_exp)) - 1)) != 0) {
- generate_underflow_error();
+ npy_set_floatstatus_underflow();
}
#endif
d_sig >>= (1009 - d_exp);
@@ -408,11 +412,11 @@ npy_uint16 npy_doublebits_to_halfbits(npy_uint64 d)
* the remaining bit pattern is 1000...0, then we do not add one
* to the bit after the half significand. In all other cases, we do.
*/
- if ((d_sig&0x000007ffffffffffu) != 0x0000020000000000u) {
- d_sig += 0x0000020000000000u;
+ if ((d_sig&0x000007ffffffffffULL) != 0x0000020000000000ULL) {
+ d_sig += 0x0000020000000000ULL;
}
#else
- d_sig += 0x0000020000000000u;
+ d_sig += 0x0000020000000000ULL;
#endif
h_sig = (npy_uint16) (d_sig >> 42);
/*
@@ -424,20 +428,20 @@ npy_uint16 npy_doublebits_to_halfbits(npy_uint64 d)
}
/* Regular case with no overflow or underflow */
- h_exp = (npy_uint16) ((d_exp - 0x3f00000000000000u) >> 42);
+ h_exp = (npy_uint16) ((d_exp - 0x3f00000000000000ULL) >> 42);
/* Handle rounding by adding 1 to the bit beyond half precision */
- d_sig = (d&0x000fffffffffffffu);
+ d_sig = (d&0x000fffffffffffffULL);
#if NPY_HALF_ROUND_TIES_TO_EVEN
/*
* If the last bit in the half significand is 0 (already even), and
* the remaining bit pattern is 1000...0, then we do not add one
* to the bit after the half significand. In all other cases, we do.
*/
- if ((d_sig&0x000007ffffffffffu) != 0x0000020000000000u) {
- d_sig += 0x0000020000000000u;
+ if ((d_sig&0x000007ffffffffffULL) != 0x0000020000000000ULL) {
+ d_sig += 0x0000020000000000ULL;
}
#else
- d_sig += 0x0000020000000000u;
+ d_sig += 0x0000020000000000ULL;
#endif
h_sig = (npy_uint16) (d_sig >> 42);
@@ -450,7 +454,7 @@ npy_uint16 npy_doublebits_to_halfbits(npy_uint64 d)
#if NPY_HALF_GENERATE_OVERFLOW
h_sig += h_exp;
if (h_sig == 0x7c00u) {
- generate_overflow_error();
+ npy_set_floatstatus_overflow();
}
return h_sgn + h_sig;
#else
@@ -515,7 +519,7 @@ npy_uint64 npy_halfbits_to_doublebits(npy_uint16 h)
return d_sgn + d_exp + d_sig;
case 0x7c00u: /* inf or NaN */
/* All-ones exponent and a copy of the significand */
- return d_sgn + 0x7ff0000000000000u +
+ return d_sgn + 0x7ff0000000000000ULL +
(((npy_uint64)(h&0x03ffu)) << 42);
default: /* normalized */
/* Just need to adjust the exponent and shift */
diff --git a/numpy/core/src/npymath/ieee754.c.src b/numpy/core/src/npymath/ieee754.c.src
index 8df903b2b..71be7b8ce 100644
--- a/numpy/core/src/npymath/ieee754.c.src
+++ b/numpy/core/src/npymath/ieee754.c.src
@@ -548,3 +548,127 @@ npy_longdouble npy_nextafterl(npy_longdouble x, npy_longdouble y)
return nextafterl(x, y);
}
#endif
+
+/*
+ * Functions to set the floating point status word.
+ */
+
+#if defined(sun) || defined(__BSD__) || defined(__OpenBSD__) || \
+ (defined(__FreeBSD__) && (__FreeBSD_version < 502114)) || \
+ defined(__NetBSD__)
+#include <ieeefp.h>
+
+void npy_set_floatstatus_divbyzero(void)
+{
+ fpsetsticky(FP_X_DZ);
+}
+
+void npy_set_floatstatus_overflow(void)
+{
+ fpsetsticky(FP_X_OFL);
+}
+
+void npy_set_floatstatus_underflow(void)
+{
+ fpsetsticky(FP_X_UFL);
+}
+
+void npy_set_floatstatus_invalid(void)
+{
+ fpsetsticky(FP_X_INV);
+}
+
+
+#elif defined(__GLIBC__) || defined(__APPLE__) || \
+ defined(__CYGWIN__) || defined(__MINGW32__) || \
+ (defined(__FreeBSD__) && (__FreeBSD_version >= 502114))
+
+# if defined(__GLIBC__) || defined(__APPLE__) || \
+ defined(__MINGW32__) || defined(__FreeBSD__)
+# include <fenv.h>
+# elif defined(__CYGWIN__)
+# include "fenv/fenv.c"
+# endif
+
+void npy_set_floatstatus_divbyzero(void)
+{
+ feraiseexcept(FE_DIVBYZERO);
+}
+
+void npy_set_floatstatus_overflow(void)
+{
+ feraiseexcept(FE_OVERFLOW);
+}
+
+void npy_set_floatstatus_underflow(void)
+{
+ feraiseexcept(FE_UNDERFLOW);
+}
+
+void npy_set_floatstatus_invalid(void)
+{
+ feraiseexcept(FE_INVALID);
+}
+
+#elif defined(_AIX)
+#include <float.h>
+#include <fpxcp.h>
+
+void npy_set_floatstatus_divbyzero(void)
+{
+ fp_raise_xcp(FP_DIV_BY_ZERO);
+}
+
+void npy_set_floatstatus_overflow(void)
+{
+ fp_raise_xcp(FP_OVERFLOW);
+}
+
+void npy_set_floatstatus_underflow(void)
+{
+ fp_raise_xcp(FP_UNDERFLOW);
+}
+
+void npy_set_floatstatus_invalid(void)
+{
+ fp_raise_xcp(FP_INVALID);
+}
+
+#else
+
+/*
+ * By using a volatile floating point value,
+ * the compiler is forced to actually do the requested
+ * operations because of potential concurrency.
+ *
+ * We shouldn't write multiple values to a single
+ * global here, because that would cause
+ * a race condition.
+ */
+static volatile double _npy_floatstatus_x,
+ _npy_floatstatus_zero = 0.0, _npy_floatstatus_big = 1e300,
+ _npy_floatstatus_small = 1e-300, _npy_floatstatus_inf;
+
+void npy_set_floatstatus_divbyzero(void)
+{
+ _npy_floatstatus_x = 1.0 / _npy_floatstatus_zero;
+}
+
+void npy_set_floatstatus_overflow(void)
+{
+ _npy_floatstatus_x = _npy_floatstatus_big * 1e300;
+}
+
+void npy_set_floatstatus_underflow(void)
+{
+ _npy_floatstatus_x = _npy_floatstatus_small * 1e-300;
+}
+
+void npy_set_floatstatus_invalid(void)
+{
+ _npy_floatstatus_inf = NPY_INFINITY;
+ _npy_floatstatus_x = _npy_floatstatus_inf - NPY_INFINITY;
+}
+
+#endif
+
diff --git a/numpy/core/src/npymath/npy_math_complex.c.src b/numpy/core/src/npymath/npy_math_complex.c.src
index 68cfa6ea1..718de5b6c 100644
--- a/numpy/core/src/npymath/npy_math_complex.c.src
+++ b/numpy/core/src/npymath/npy_math_complex.c.src
@@ -275,10 +275,10 @@
#ifdef HAVE_@KIND@@C@
@ctype@ npy_@kind@@c@(@ctype@ x, @ctype@ y)
{
- __@ctype@_to_c99_cast x1 = {x};
- __@ctype@_to_c99_cast y1 = {y};
+ __@ctype@_to_c99_cast xcast = {x};
+ __@ctype@_to_c99_cast ycast = {y};
__@ctype@_to_c99_cast ret;
- ret.c99_z = @kind@@c@(x1.c99_z, y1.c99_z);
+ ret.c99_z = @kind@@c@(xcast.c99_z, ycast.c99_z);
return ret.npy_z;
}
#endif
diff --git a/numpy/core/src/private/lowlevel_strided_loops.h b/numpy/core/src/private/lowlevel_strided_loops.h
new file mode 100644
index 000000000..5fc42bc40
--- /dev/null
+++ b/numpy/core/src/private/lowlevel_strided_loops.h
@@ -0,0 +1,397 @@
+#ifndef __LOWLEVEL_STRIDED_LOOPS_H
+#define __LOWLEVEL_STRIDED_LOOPS_H
+
+/*
+ * NOTE: This API should remain private for the time being, to allow
+ * for further refinement. I think the 'aligned' mechanism
+ * needs changing, for example.
+ */
+
+/*
+ * This function pointer is for functions that transfer an arbitrarily strided
+ * input to a an arbitrarily strided output. It may be a fully general
+ * function, or a specialized function when the strides or item size
+ * have special values.
+ *
+ * Examples of transfer functions are a straight copy, a byte-swap,
+ * and a casting operation,
+ *
+ * The 'transferdata' parameter is slightly special, and must always contain
+ * pointer to deallocation and copying routines at its beginning. The function
+ * PyArray_FreeStridedTransferData should be used to deallocate such
+ * pointers, and calls the first function pointer, while the function
+ * PyArray_CopyStridedTransferData should be used to copy it.
+ *
+ */
+typedef void (PyArray_StridedTransferFn)(char *dst, npy_intp dst_stride,
+ char *src, npy_intp src_stride,
+ npy_intp N, npy_intp src_itemsize,
+ void *transferdata);
+
+/*
+ * Deallocates a PyArray_StridedTransferFunction data object. See
+ * the comment with the function typedef for more details.
+ */
+NPY_NO_EXPORT void
+PyArray_FreeStridedTransferData(void *transferdata);
+
+/*
+ * Copies a PyArray_StridedTransferFunction data object. See
+ * the comment with the function typedef for more details.
+ */
+NPY_NO_EXPORT void *
+PyArray_CopyStridedTransferData(void *transferdata);
+
+/*
+ * Gives back a function pointer to a specialized function for copying
+ * strided memory. Returns NULL if there is a problem with the inputs.
+ *
+ * aligned:
+ * Should be 1 if the src and dst pointers are always aligned,
+ * 0 otherwise.
+ * src_stride:
+ * Should be the src stride if it will always be the same,
+ * NPY_MAX_INTP otherwise.
+ * dst_stride:
+ * Should be the dst stride if it will always be the same,
+ * NPY_MAX_INTP otherwise.
+ * itemsize:
+ * Should be the item size if it will always be the same, 0 otherwise.
+ *
+ */
+NPY_NO_EXPORT PyArray_StridedTransferFn *
+PyArray_GetStridedCopyFn(npy_intp aligned, npy_intp src_stride,
+ npy_intp dst_stride, npy_intp itemsize);
+
+/*
+ * Gives back a function pointer to a specialized function for copying
+ * and swapping strided memory. This assumes each element is a single
+ * value to be swapped.
+ *
+ * For information on the 'aligned', 'src_stride' and 'dst_stride' parameters
+ * see above.
+ *
+ * Parameters are as for PyArray_GetStridedCopyFn.
+ */
+NPY_NO_EXPORT PyArray_StridedTransferFn *
+PyArray_GetStridedCopySwapFn(npy_intp aligned, npy_intp src_stride,
+ npy_intp dst_stride, npy_intp itemsize);
+
+/*
+ * Gives back a function pointer to a specialized function for copying
+ * and swapping strided memory. This assumes each element is a pair
+ * of values, each of which needs to be swapped.
+ *
+ * For information on the 'aligned', 'src_stride' and 'dst_stride' parameters
+ * see above.
+ *
+ * Parameters are as for PyArray_GetStridedCopyFn.
+ */
+NPY_NO_EXPORT PyArray_StridedTransferFn *
+PyArray_GetStridedCopySwapPairFn(npy_intp aligned, npy_intp src_stride,
+ npy_intp dst_stride, npy_intp itemsize);
+
+/*
+ * Gives back a transfer function and transfer data pair which copies
+ * the data from source to dest, truncating it if the data doesn't
+ * fit, and padding with zero bytes if there's too much space.
+ *
+ * For information on the 'aligned', 'src_stride' and 'dst_stride' parameters
+ * see above.
+ *
+ * Returns NPY_SUCCEED or NPY_FAIL
+ */
+NPY_NO_EXPORT int
+PyArray_GetStridedZeroPadCopyFn(int aligned,
+ npy_intp src_stride, npy_intp dst_stride,
+ npy_intp src_itemsize, npy_intp dst_itemsize,
+ PyArray_StridedTransferFn **outstransfer,
+ void **outtransferdata);
+
+/*
+ * For casts between built-in numeric types,
+ * this produces a function pointer for casting from src_type_num
+ * to dst_type_num. If a conversion is unsupported, returns NULL
+ * without setting a Python exception.
+ */
+NPY_NO_EXPORT PyArray_StridedTransferFn *
+PyArray_GetStridedNumericCastFn(npy_intp aligned, npy_intp src_stride,
+ npy_intp dst_stride,
+ int src_type_num, int dst_type_num);
+
+/*
+ * If it's possible, gives back a transfer function which casts and/or
+ * byte swaps data with the dtype 'src_dtype' into data with the dtype
+ * 'dst_dtype'. If the outtransferdata is populated with a non-NULL value,
+ * it must be deallocated with the ``PyArray_FreeStridedTransferData``
+ * function when the transfer function is no longer required.
+ *
+ * aligned:
+ * Should be 1 if the src and dst pointers are always aligned,
+ * 0 otherwise.
+ * src_stride:
+ * Should be the src stride if it will always be the same,
+ * NPY_MAX_INTP otherwise.
+ * dst_stride:
+ * Should be the dst stride if it will always be the same,
+ * NPY_MAX_INTP otherwise.
+ * src_dtype:
+ * The data type of source data. If this is NULL, a transfer
+ * function which sets the destination to zeros is produced.
+ * dst_dtype:
+ * The data type of destination data. If this is NULL and
+ * move_references is 1, a transfer function which decrements
+ * source data references is produced.
+ * move_references:
+ * If 0, the destination data gets new reference ownership.
+ * If 1, the references from the source data are moved to
+ * the destination data.
+ * out_stransfer:
+ * The resulting transfer function is placed here.
+ * out_transferdata:
+ * The auxiliary data for the transfer function is placed here.
+ * When finished with the transfer function, the caller must call
+ * ``PyArray_FreeStridedTransferData`` on this data.
+ * out_needs_api:
+ * If this is non-NULL, and the transfer function produced needs
+ * to call into the (Python) API, this gets set to 1. This
+ * remains untouched if no API access is required.
+ *
+ * WARNING: If you set move_references to 1, it is best that src_stride is
+ * never zero when calling the transfer function. Otherwise, the
+ * first destination reference will get the value and all the rest
+ * will get NULL.
+ *
+ * Returns NPY_SUCCEED or NPY_FAIL.
+ */
+NPY_NO_EXPORT int
+PyArray_GetDTypeTransferFunction(int aligned,
+ npy_intp src_stride, npy_intp dst_stride,
+ PyArray_Descr *src_dtype, PyArray_Descr *dst_dtype,
+ int move_references,
+ PyArray_StridedTransferFn **out_stransfer,
+ void **out_transferdata,
+ int *out_needs_api);
+
+/*
+ * These two functions copy or convert the data of an n-dimensional array
+ * to/from a 1-dimensional strided buffer. These functions will only call
+ * 'stransfer' with the provided dst_stride/src_stride and
+ * dst_strides[0]/src_strides[0], so the caller can use those values to
+ * specialize the function.
+ *
+ * The return value is the number of elements it couldn't copy. A return value
+ * of 0 means all elements were copied, a larger value means the end of
+ * the n-dimensional array was reached before 'count' elements were copied.
+ *
+ * ndim:
+ * The number of dimensions of the n-dimensional array.
+ * dst/src:
+ * The destination or src starting pointer.
+ * dst_stride/src_stride:
+ * The stride of the 1-dimensional strided buffer
+ * dst_strides/src_strides:
+ * The strides of the n-dimensional array.
+ * dst_strides_inc/src_strides_inc:
+ * How much to add to the ..._strides pointer to get to the next stride.
+ * coords:
+ * The starting coordinates in the n-dimensional array.
+ * coords_inc:
+ * How much to add to the coords pointer to get to the next coordinate.
+ * shape:
+ * The shape of the n-dimensional array.
+ * shape_inc:
+ * How much to add to the shape pointer to get to the next shape entry.
+ * count:
+ * How many elements to transfer
+ * src_itemsize:
+ * How big each element is. If transfering between elements of different
+ * sizes, for example a casting operation, the 'stransfer' function
+ * should be specialized for that, in which case 'stransfer' will use
+ * this parameter as the source item size.
+ * stransfer:
+ * The strided transfer function.
+ * transferdata:
+ * An auxiliary data pointer passed to the strided transfer function.
+ * If a non-NULL value is returned, it must be deallocated with the
+ * function PyArray_FreeStridedTransferData.
+ */
+NPY_NO_EXPORT npy_intp
+PyArray_TransferNDimToStrided(npy_intp ndim,
+ char *dst, npy_intp dst_stride,
+ char *src, npy_intp *src_strides, npy_intp src_strides_inc,
+ npy_intp *coords, npy_intp coords_inc,
+ npy_intp *shape, npy_intp shape_inc,
+ npy_intp count, npy_intp src_itemsize,
+ PyArray_StridedTransferFn *stransfer,
+ void *transferdata);
+
+NPY_NO_EXPORT npy_intp
+PyArray_TransferStridedToNDim(npy_intp ndim,
+ char *dst, npy_intp *dst_strides, npy_intp dst_strides_inc,
+ char *src, npy_intp src_stride,
+ npy_intp *coords, npy_intp coords_inc,
+ npy_intp *shape, npy_intp shape_inc,
+ npy_intp count, npy_intp src_itemsize,
+ PyArray_StridedTransferFn *stransfer,
+ void *transferdata);
+
+/*
+ * TRIVIAL ITERATION
+ *
+ * In some cases when the iteration order isn't important, iteration over
+ * arrays is trivial. This is the case when:
+ * * The array has 0 or 1 dimensions.
+ * * The array is C or Fortran contiguous.
+ * Use of an iterator can be skipped when this occurs. These macros assist
+ * in detecting and taking advantage of the situation. Note that it may
+ * be worthwhile to further check if the stride is a contiguous stride
+ * and take advantage of that.
+ *
+ * Here is example code for a single array:
+ *
+ * if (PyArray_TRIVIALLY_ITERABLE(self) {
+ * char *data;
+ * npy_intp count, stride;
+ *
+ * PyArray_PREPARE_TRIVIAL_ITERATION(self, count, data, stride);
+ *
+ * while (count--) {
+ * // Use the data pointer
+ *
+ * data += stride;
+ * }
+ * }
+ * else {
+ * // Create iterator, etc...
+ * }
+ *
+ * Here is example code for a pair of arrays:
+ *
+ * if (PyArray_TRIVIALLY_ITERABLE_PAIR(a1, a2) {
+ * char *data1, *data2;
+ * npy_intp count, stride1, stride2;
+ *
+ * PyArray_PREPARE_TRIVIAL_PAIR_ITERATION(a1, a2, count,
+ * data1, data2, stride1, stride2);
+ *
+ * while (count--) {
+ * // Use the data1 and data2 pointers
+ *
+ * data1 += stride1;
+ * data2 += stride2;
+ * }
+ * }
+ * else {
+ * // Create iterator, etc...
+ * }
+ */
+
+/*
+ * Note: Equivalently iterable macro requires one of arr1 or arr2 be
+ * trivially iterable to be valid.
+ */
+#define PyArray_EQUIVALENTLY_ITERABLE(arr1, arr2) ( \
+ PyArray_NDIM(arr1) == PyArray_NDIM(arr2) && \
+ PyArray_CompareLists(PyArray_DIMS(arr1), \
+ PyArray_DIMS(arr2), \
+ PyArray_NDIM(arr1)) && \
+ (arr1->flags&(NPY_CONTIGUOUS|NPY_FORTRAN)) == \
+ (arr2->flags&(NPY_CONTIGUOUS|NPY_FORTRAN)) \
+ )
+
+#define PyArray_TRIVIALLY_ITERABLE(arr) ( \
+ PyArray_NDIM(arr) <= 1 || \
+ PyArray_CHKFLAGS(arr, NPY_CONTIGUOUS) || \
+ PyArray_CHKFLAGS(arr, NPY_FORTRAN) \
+ )
+#define PyArray_PREPARE_TRIVIAL_ITERATION(arr, count, data, stride) \
+ count = PyArray_SIZE(arr), \
+ data = PyArray_BYTES(arr), \
+ stride = ((PyArray_NDIM(arr) == 0) ? 0 : \
+ (PyArray_CHKFLAGS(arr, NPY_FORTRAN) ? \
+ PyArray_STRIDE(arr, 0) : \
+ PyArray_STRIDE(arr, \
+ PyArray_NDIM(arr)-1)))
+
+#define PyArray_TRIVIALLY_ITERABLE_PAIR(arr1, arr2) (\
+ PyArray_TRIVIALLY_ITERABLE(arr1) && \
+ (PyArray_NDIM(arr2) == 0 || \
+ PyArray_EQUIVALENTLY_ITERABLE(arr1, arr2) || \
+ (PyArray_NDIM(arr1) == 0 && \
+ PyArray_TRIVIALLY_ITERABLE(arr2) \
+ ) \
+ ) \
+ )
+#define PyArray_PREPARE_TRIVIAL_PAIR_ITERATION(arr1, arr2, \
+ count, \
+ data1, data2, \
+ stride1, stride2) { \
+ npy_intp size1 = PyArray_SIZE(arr1); \
+ npy_intp size2 = PyArray_SIZE(arr2); \
+ count = ((size1 > size2) || size1 == 0) ? size1 : size2; \
+ data1 = PyArray_BYTES(arr1); \
+ data2 = PyArray_BYTES(arr2); \
+ stride1 = (size1 == 1 ? 0 : \
+ (PyArray_CHKFLAGS(arr1, NPY_FORTRAN) ? \
+ PyArray_STRIDE(arr1, 0) : \
+ PyArray_STRIDE(arr1, \
+ PyArray_NDIM(arr1)-1))); \
+ stride2 = (size2 == 1 ? 0 : \
+ (PyArray_CHKFLAGS(arr2, NPY_FORTRAN) ? \
+ PyArray_STRIDE(arr2, 0) : \
+ PyArray_STRIDE(arr2, \
+ PyArray_NDIM(arr2)-1))); \
+ }
+
+#define PyArray_TRIVIALLY_ITERABLE_TRIPLE(arr1, arr2, arr3) (\
+ PyArray_TRIVIALLY_ITERABLE(arr1) && \
+ ((PyArray_NDIM(arr2) == 0 && \
+ (PyArray_NDIM(arr3) == 0 || \
+ PyArray_EQUIVALENTLY_ITERABLE(arr1, arr3) \
+ ) \
+ ) || \
+ (PyArray_EQUIVALENTLY_ITERABLE(arr1, arr2) && \
+ (PyArray_NDIM(arr3) == 0 || \
+ PyArray_EQUIVALENTLY_ITERABLE(arr1, arr3) \
+ ) \
+ ) || \
+ (PyArray_NDIM(arr1) == 0 && \
+ PyArray_TRIVIALLY_ITERABLE(arr2) && \
+ (PyArray_NDIM(arr3) == 0 || \
+ PyArray_EQUIVALENTLY_ITERABLE(arr2, arr3) \
+ ) \
+ ) \
+ ) \
+ )
+
+#define PyArray_PREPARE_TRIVIAL_TRIPLE_ITERATION(arr1, arr2, arr3, \
+ count, \
+ data1, data2, data3, \
+ stride1, stride2, stride3) { \
+ npy_intp size1 = PyArray_SIZE(arr1); \
+ npy_intp size2 = PyArray_SIZE(arr2); \
+ npy_intp size3 = PyArray_SIZE(arr3); \
+ count = ((size1 > size2) || size1 == 0) ? size1 : size2; \
+ count = ((size3 > count) || size3 == 0) ? size3 : count; \
+ data1 = PyArray_BYTES(arr1); \
+ data2 = PyArray_BYTES(arr2); \
+ data3 = PyArray_BYTES(arr3); \
+ stride1 = (size1 == 1 ? 0 : \
+ (PyArray_CHKFLAGS(arr1, NPY_FORTRAN) ? \
+ PyArray_STRIDE(arr1, 0) : \
+ PyArray_STRIDE(arr1, \
+ PyArray_NDIM(arr1)-1))); \
+ stride2 = (size2 == 1 ? 0 : \
+ (PyArray_CHKFLAGS(arr2, NPY_FORTRAN) ? \
+ PyArray_STRIDE(arr2, 0) : \
+ PyArray_STRIDE(arr2, \
+ PyArray_NDIM(arr2)-1))); \
+ stride3 = (size3 == 1 ? 0 : \
+ (PyArray_CHKFLAGS(arr3, NPY_FORTRAN) ? \
+ PyArray_STRIDE(arr3, 0) : \
+ PyArray_STRIDE(arr3, \
+ PyArray_NDIM(arr3)-1))); \
+ }
+
+#endif
diff --git a/numpy/core/src/scalarmathmodule.c.src b/numpy/core/src/scalarmathmodule.c.src
index 712932958..2bcc516b1 100644
--- a/numpy/core/src/scalarmathmodule.c.src
+++ b/numpy/core/src/scalarmathmodule.c.src
@@ -145,7 +145,7 @@ static void
if ((*out^a) >= 0 || (*out^b) >= 0) {
return;
}
- generate_overflow_error();
+ npy_set_floatstatus_overflow();
return;
}
static void
@@ -154,7 +154,7 @@ static void
if ((*out^a) >= 0 || (*out^~b) >= 0) {
return;
}
- generate_overflow_error();
+ npy_set_floatstatus_overflow();
return;
}
/**end repeat**/
@@ -168,7 +168,7 @@ static void
if (*out >= a && *out >= b) {
return;
}
- generate_overflow_error();
+ npy_set_floatstatus_overflow();
return;
}
static void
@@ -177,7 +177,7 @@ static void
if (a >= b) {
return;
}
- generate_overflow_error();
+ npy_set_floatstatus_overflow();
return;
}
/**end repeat**/
@@ -206,7 +206,7 @@ static void
#else
if (temp > MAX_@NAME@)
#endif
- generate_overflow_error();
+ npy_set_floatstatus_overflow();
return;
}
#endif
@@ -223,7 +223,7 @@ static void
@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {
*out = a * b;
if (@char@longlong_overflow(a, b)) {
- generate_overflow_error();
+ npy_set_floatstatus_overflow();
}
return;
}
@@ -239,12 +239,12 @@ static void
static void
@name@_ctype_divide(@name@ a, @name@ b, @name@ *out) {
if (b == 0) {
- generate_divbyzero_error();
+ npy_set_floatstatus_divbyzero();
*out = 0;
}
#if @neg@
else if (b == -1 && a < 0 && a == -a) {
- generate_overflow_error();
+ npy_set_floatstatus_overflow();
*out = a / b;
}
#endif
@@ -266,7 +266,7 @@ static void
static void
@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) {
if (a == 0 || b == 0) {
- if (b == 0) generate_divbyzero_error();
+ if (b == 0) npy_set_floatstatus_divbyzero();
*out = 0;
return;
}
@@ -450,7 +450,7 @@ static void
@name@_ctype_negative(npy_@name@ a, npy_@name@ *out)
{
#if @uns@
- generate_overflow_error();
+ npy_set_floatstatus_overflow();
#endif
*out = -a;
}
@@ -704,10 +704,12 @@ static PyObject *
PyObject *ret;
npy_@name@ arg1, arg2;
/*
- * NOTE: In gcc >= 4.1, the compiler will reorder floating point operations and
- * floating point error state checks. In particular, the arithmetic operations
- * were being reordered so that the errors weren't caught. Declaring this output
- * variable volatile was the minimal fix for the issue. (Ticket #1671)
+ * NOTE: In gcc >= 4.1, the compiler will reorder floating point
+ * operations and floating point error state checks. In
+ * particular, the arithmetic operations were being reordered
+ * so that the errors weren't caught. Declaring this output
+ * variable volatile was the minimal fix for the issue.
+ * (Ticket #1671)
*/
volatile npy_@otyp@ out;
#if @twoout@
@@ -1005,9 +1007,9 @@ static PyObject *
/**end repeat**/
#if defined(NPY_PY3K)
-#define NONZERO_NAME(prefix, suffix) prefix##bool##suffix
+#define NONZERO_NAME(prefix) prefix##bool
#else
-#define NONZERO_NAME(prefix, suffix) prefix##nonzero##suffix
+#define NONZERO_NAME(prefix) prefix##nonzero
#endif
#define _IS_NONZERO(x) (x != 0)
@@ -1018,7 +1020,7 @@ static PyObject *
* #nonzero=_IS_NONZERO*10, !npy_half_iszero, _IS_NONZERO*6#
*/
static int
-NONZERO_NAME(@name@_,)(PyObject *a)
+NONZERO_NAME(@name@_)(PyObject *a)
{
int ret;
npy_@name@ arg1;
@@ -1027,7 +1029,7 @@ NONZERO_NAME(@name@_,)(PyObject *a)
if (PyErr_Occurred()) {
return -1;
}
- return PyGenericArrType_Type.tp_as_number->NONZERO_NAME(nb_,)(a);
+ return PyGenericArrType_Type.tp_as_number->NONZERO_NAME(nb_)(a);
}
/*
diff --git a/numpy/core/src/umath/loops.c.src b/numpy/core/src/umath/loops.c.src
index 0c777e464..5212207da 100644
--- a/numpy/core/src/umath/loops.c.src
+++ b/numpy/core/src/umath/loops.c.src
@@ -64,7 +64,7 @@
intp n = dimensions[0]; \
intp i; \
for(i = 0; i < n; i++, ip2 += is2)
-
+
#define BINARY_REDUCE_LOOP(TYPE)\
char *iop1 = args[0]; \
TYPE io1 = *(TYPE *)iop1; \
@@ -388,8 +388,8 @@ PyUFunc_O_O(char **args, intp *dimensions, intp *steps, void *func)
UNARY_LOOP {
PyObject *in1 = *(PyObject **)ip1;
PyObject **out = (PyObject **)op1;
- PyObject *ret = f(in1);
- if ((ret == NULL) || PyErr_Occurred()) {
+ PyObject *ret = f(in1 ? in1 : Py_None);
+ if (ret == NULL) {
return;
}
Py_XDECREF(*out);
@@ -405,7 +405,7 @@ PyUFunc_O_O_method(char **args, intp *dimensions, intp *steps, void *func)
UNARY_LOOP {
PyObject *in1 = *(PyObject **)ip1;
PyObject **out = (PyObject **)op1;
- PyObject *ret = PyObject_CallMethod(in1, meth, NULL);
+ PyObject *ret = PyObject_CallMethod(in1 ? in1 : Py_None, meth, NULL);
if (ret == NULL) {
return;
}
@@ -423,8 +423,8 @@ PyUFunc_OO_O(char **args, intp *dimensions, intp *steps, void *func)
PyObject *in1 = *(PyObject **)ip1;
PyObject *in2 = *(PyObject **)ip2;
PyObject **out = (PyObject **)op1;
- PyObject *ret = f(in1, in2);
- if (PyErr_Occurred()) {
+ PyObject *ret = f(in1 ? in1 : Py_None, in2 ? in2 : Py_None);
+ if (ret == NULL) {
return;
}
Py_XDECREF(*out);
@@ -441,7 +441,8 @@ PyUFunc_OO_O_method(char **args, intp *dimensions, intp *steps, void *func)
PyObject *in1 = *(PyObject **)ip1;
PyObject *in2 = *(PyObject **)ip2;
PyObject **out = (PyObject **)op1;
- PyObject *ret = PyObject_CallMethod(in1, meth, "(O)", in2);
+ PyObject *ret = PyObject_CallMethod(in1 ? in1 : Py_None,
+ meth, "(O)", in2);
if (ret == NULL) {
return;
}
@@ -482,8 +483,7 @@ PyUFunc_On_Om(char **args, intp *dimensions, intp *steps, void *func)
for(j = 0; j < nin; j++) {
in = *((PyObject **)ptrs[j]);
if (in == NULL) {
- Py_DECREF(arglist);
- return;
+ in = Py_None;
}
PyTuple_SET_ITEM(arglist, j, in);
Py_INCREF(in);
@@ -760,10 +760,19 @@ NPY_NO_EXPORT void
NPY_NO_EXPORT void
@S@@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
{
- BINARY_LOOP {
- const @s@@type@ in1 = *(@s@@type@ *)ip1;
- const @s@@type@ in2 = *(@s@@type@ *)ip2;
- *((@s@@type@ *)op1) = (in1 @OP@ in2) ? in1 : in2;
+ if (IS_BINARY_REDUCE) {
+ BINARY_REDUCE_LOOP(@s@@type@) {
+ const @s@@type@ in2 = *(@type@ *)ip2;
+ io1 = (io1 @OP@ in2) ? io1 : in2;
+ }
+ *((@s@@type@ *)iop1) = io1;
+ }
+ else {
+ BINARY_LOOP {
+ const @s@@type@ in1 = *(@s@@type@ *)ip1;
+ const @s@@type@ in2 = *(@s@@type@ *)ip2;
+ *((@s@@type@ *)op1) = (in1 @OP@ in2) ? in1 : in2;
+ }
}
}
/**end repeat2**/
@@ -795,7 +804,7 @@ NPY_NO_EXPORT void
const @s@@type@ in1 = *(@s@@type@ *)ip1;
const @s@@type@ in2 = *(@s@@type@ *)ip2;
if (in2 == 0) {
- generate_divbyzero_error();
+ npy_set_floatstatus_divbyzero();
*((@s@@type@ *)op1) = 0;
}
else {
@@ -854,10 +863,10 @@ NPY_NO_EXPORT void
* by -1 causes a SIFGPE (division overflow). We treat this case here
* (to avoid a SIGFPE crash at python level), but a good solution would
* be to treat integer division problems separately from FPU exceptions
- * (i.e. fixing generate_divbyzero_error()).
+ * (i.e. a different approach than npy_set_floatstatus_divbyzero()).
*/
if (in2 == 0 || (in1 == NPY_MIN_@TYPE@ && in2 == -1)) {
- generate_divbyzero_error();
+ npy_set_floatstatus_divbyzero();
*((@type@ *)op1) = 0;
}
else if (((in1 > 0) != (in2 > 0)) && (in1 % in2 != 0)) {
@@ -876,7 +885,7 @@ U@TYPE@_divide(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func
const u@type@ in1 = *(u@type@ *)ip1;
const u@type@ in2 = *(u@type@ *)ip2;
if (in2 == 0) {
- generate_divbyzero_error();
+ npy_set_floatstatus_divbyzero();
*((u@type@ *)op1) = 0;
}
else {
@@ -892,7 +901,7 @@ NPY_NO_EXPORT void
const @type@ in1 = *(@type@ *)ip1;
const @type@ in2 = *(@type@ *)ip2;
if (in2 == 0) {
- generate_divbyzero_error();
+ npy_set_floatstatus_divbyzero();
*((@type@ *)op1) = 0;
}
else {
@@ -915,7 +924,7 @@ U@TYPE@_remainder(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(f
const u@type@ in1 = *(u@type@ *)ip1;
const u@type@ in2 = *(u@type@ *)ip2;
if (in2 == 0) {
- generate_divbyzero_error();
+ npy_set_floatstatus_divbyzero();
*((@type@ *)op1) = 0;
}
else {
@@ -998,11 +1007,20 @@ NPY_NO_EXPORT void
NPY_NO_EXPORT void
@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
{
+ if (IS_BINARY_REDUCE) {
+ BINARY_REDUCE_LOOP(@type@) {
+ const @type@ in2 = *(@type@ *)ip2;
+ io1 = (io1 @OP@ in2) ? io1 : in2;
+ }
+ *((@type@ *)iop1) = io1;
+ }
+ else {
BINARY_LOOP {
const @type@ in1 = *(@type@ *)ip1;
const @type@ in2 = *(@type@ *)ip2;
*((@type@ *)op1) = (in1 @OP@ in2) ? in1 : in2;
}
+ }
}
/**end repeat1**/
@@ -1026,7 +1044,7 @@ NPY_NO_EXPORT void
/**end repeat**/
-/* FIXME: implement the following correctly using the metadata: data is the
+/* FIXME: implement the following correctly using the metadata: data is the
sequence of ndarrays in the same order as args.
*/
NPY_NO_EXPORT void
@@ -1216,10 +1234,19 @@ NPY_NO_EXPORT void
@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
{
/* */
- BINARY_LOOP {
- const @type@ in1 = *(@type@ *)ip1;
- const @type@ in2 = *(@type@ *)ip2;
- *((@type@ *)op1) = (in1 @OP@ in2 || npy_isnan(in1)) ? in1 : in2;
+ if (IS_BINARY_REDUCE) {
+ BINARY_REDUCE_LOOP(@type@) {
+ const @type@ in2 = *(@type@ *)ip2;
+ io1 = (io1 @OP@ in2 || npy_isnan(io1)) ? io1 : in2;
+ }
+ *((@type@ *)iop1) = io1;
+ }
+ else {
+ BINARY_LOOP {
+ const @type@ in1 = *(@type@ *)ip1;
+ const @type@ in2 = *(@type@ *)ip2;
+ *((@type@ *)op1) = (in1 @OP@ in2 || npy_isnan(in1)) ? in1 : in2;
+ }
}
}
/**end repeat1**/
@@ -1232,10 +1259,19 @@ NPY_NO_EXPORT void
@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
{
/* */
- BINARY_LOOP {
- const @type@ in1 = *(@type@ *)ip1;
- const @type@ in2 = *(@type@ *)ip2;
- *((@type@ *)op1) = (in1 @OP@ in2 || npy_isnan(in2)) ? in1 : in2;
+ if (IS_BINARY_REDUCE) {
+ BINARY_REDUCE_LOOP(@type@) {
+ const @type@ in2 = *(@type@ *)ip2;
+ io1 = (io1 @OP@ in2 || npy_isnan(in2)) ? io1 : in2;
+ }
+ *((@type@ *)iop1) = io1;
+ }
+ else {
+ BINARY_LOOP {
+ const @type@ in1 = *(@type@ *)ip1;
+ const @type@ in2 = *(@type@ *)ip2;
+ *((@type@ *)op1) = (in1 @OP@ in2 || npy_isnan(in2)) ? in1 : in2;
+ }
}
}
/**end repeat1**/
@@ -2037,7 +2073,9 @@ OBJECT_@kind@(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func)
BINARY_LOOP {
PyObject *in1 = *(PyObject **)ip1;
PyObject *in2 = *(PyObject **)ip2;
- int ret = PyObject_RichCompareBool(in1, in2, Py_@OP@);
+ int ret = PyObject_RichCompareBool(
+ in1 ? in1 : Py_None,
+ in2 ? in2 : Py_None, Py_@OP@);
if (ret == -1) {
return;
}
@@ -2056,7 +2094,7 @@ OBJECT_sign(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
PyObject **out = (PyObject **)op1;
int v;
PyObject *ret;
- PyObject_Cmp(in1, zero, &v);
+ PyObject_Cmp(in1 ? in1 : Py_None, zero, &v);
ret = PyLong_FromLong(v);
if (PyErr_Occurred()) {
return;
@@ -2070,7 +2108,8 @@ OBJECT_sign(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
UNARY_LOOP {
PyObject *in1 = *(PyObject **)ip1;
PyObject **out = (PyObject **)op1;
- PyObject *ret = PyInt_FromLong(PyObject_Compare(in1, zero));
+ PyObject *ret = PyInt_FromLong(
+ PyObject_Compare(in1 ? in1 : Py_None, zero));
if (PyErr_Occurred()) {
return;
}
@@ -2086,5 +2125,3 @@ OBJECT_sign(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
** END LOOPS **
*****************************************************************************
*/
-
-
diff --git a/numpy/core/src/umath/loops.h b/numpy/core/src/umath/loops.h
index 2d8343b47..abd8de23e 100644
--- a/numpy/core/src/umath/loops.h
+++ b/numpy/core/src/umath/loops.h
@@ -22,7 +22,7 @@
* command line as follows:
*
* $ cd <NumPy source root directory>
- * $ python numpy/distutils/conv_template.py numpy/core/src/umath/loops.h.src
+ * $ python numpy/distutils/conv_template.py numpy/core/src/umath/loops.h.src
* $
*/
@@ -2716,4 +2716,3 @@ OBJECT_sign(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func));
*/
#endif
-
diff --git a/numpy/core/src/umath/loops.h.src b/numpy/core/src/umath/loops.h.src
index d4ec0a78d..1def8ba0f 100644
--- a/numpy/core/src/umath/loops.h.src
+++ b/numpy/core/src/umath/loops.h.src
@@ -13,7 +13,7 @@
* command line as follows:
*
* $ cd <NumPy source root directory>
- * $ python numpy/distutils/conv_template.py numpy/core/src/umath/loops.h.src
+ * $ python numpy/distutils/conv_template.py numpy/core/src/umath/loops.h.src
* $
*/
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
index 39b04db73..b35b57d86 100644
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -37,10 +37,31 @@
#include "numpy/noprefix.h"
#include "numpy/ufuncobject.h"
+#include "lowlevel_strided_loops.h"
#include "ufunc_object.h"
+/********** PRINTF DEBUG TRACING **************/
+#define NPY_UF_DBG_TRACING 0
+
+#if NPY_UF_DBG_TRACING
+#define NPY_UF_DBG_PRINT(s) printf("%s", s)
+#define NPY_UF_DBG_PRINT1(s, p1) printf(s, p1)
+#define NPY_UF_DBG_PRINT2(s, p1, p2) printf(s, p1, p2)
+#define NPY_UF_DBG_PRINT3(s, p1, p2, p3) printf(s, p1, p2, p3)
+#else
+#define NPY_UF_DBG_PRINT(s)
+#define NPY_UF_DBG_PRINT1(s, p1)
+#define NPY_UF_DBG_PRINT2(s, p1, p2)
+#define NPY_UF_DBG_PRINT3(s, p1, p2, p3)
+#endif
+/**********************************************/
+
+
+/********************/
#define USE_USE_DEFAULTS 1
+#define USE_NEW_ITERATOR_GENFUNC 1
+/********************/
/* ---------------------------------------------------------------- */
@@ -206,65 +227,31 @@ PyUFunc_clearfperr()
#define SIGNATURE_NOBUFFER_UFUNCLOOP 4
-static char
-_lowest_type(char intype)
-{
- switch(intype) {
- /* case PyArray_BYTE */
- case PyArray_SHORT:
- case PyArray_INT:
- case PyArray_LONG:
- case PyArray_LONGLONG:
- case PyArray_DATETIME:
- case PyArray_TIMEDELTA:
- return PyArray_BYTE;
- /* case PyArray_UBYTE */
- case PyArray_USHORT:
- case PyArray_UINT:
- case PyArray_ULONG:
- case PyArray_ULONGLONG:
- return PyArray_UBYTE;
- /* case PyArray_HALF: */
- case PyArray_FLOAT:
- case PyArray_DOUBLE:
- case PyArray_LONGDOUBLE:
- return PyArray_HALF;
- /* case PyArray_CFLOAT:*/
- case PyArray_CDOUBLE:
- case PyArray_CLONGDOUBLE:
- return PyArray_CFLOAT;
- default:
- return intype;
- }
-}
-
-static char *_types_msg = "function not supported for these types, " \
- "and can't coerce safely to supported types";
-
/*
* This function analyzes the input arguments
* and determines an appropriate __array_prepare__ function to call
* for the outputs.
*
- * If an output argument is provided, then it is wrapped
+ * If an output argument is provided, then it is prepped
* with its own __array_prepare__ not with the one determined by
* the input arguments.
*
* if the provided output argument is already an ndarray,
- * the wrapping function is None (which means no wrapping will
+ * the prepping function is None (which means no prepping will
* be done --- not even PyArray_Return).
*
- * A NULL is placed in output_wrap for outputs that
+ * A NULL is placed in output_prep for outputs that
* should just have PyArray_Return called.
*/
static void
-_find_array_prepare(PyObject *args, PyObject **output_wrap, int nin, int nout)
+_find_array_prepare(PyObject *args, PyObject *kwds,
+ PyObject **output_prep, int nin, int nout)
{
Py_ssize_t nargs;
int i;
int np = 0;
- PyObject *with_wrap[NPY_MAXARGS], *wraps[NPY_MAXARGS];
- PyObject *obj, *wrap = NULL;
+ PyObject *with_prep[NPY_MAXARGS], *preps[NPY_MAXARGS];
+ PyObject *obj, *prep = NULL;
nargs = PyTuple_GET_SIZE(args);
for (i = 0; i < nin; i++) {
@@ -272,16 +259,16 @@ _find_array_prepare(PyObject *args, PyObject **output_wrap, int nin, int nout)
if (PyArray_CheckExact(obj) || PyArray_IsAnyScalar(obj)) {
continue;
}
- wrap = PyObject_GetAttrString(obj, "__array_prepare__");
- if (wrap) {
- if (PyCallable_Check(wrap)) {
- with_wrap[np] = obj;
- wraps[np] = wrap;
+ prep = PyObject_GetAttrString(obj, "__array_prepare__");
+ if (prep) {
+ if (PyCallable_Check(prep)) {
+ with_prep[np] = obj;
+ preps[np] = prep;
++np;
}
else {
- Py_DECREF(wrap);
- wrap = NULL;
+ Py_DECREF(prep);
+ prep = NULL;
}
}
else {
@@ -289,33 +276,33 @@ _find_array_prepare(PyObject *args, PyObject **output_wrap, int nin, int nout)
}
}
if (np > 0) {
- /* If we have some wraps defined, find the one of highest priority */
- wrap = wraps[0];
+ /* If we have some preps defined, find the one of highest priority */
+ prep = preps[0];
if (np > 1) {
- double maxpriority = PyArray_GetPriority(with_wrap[0],
+ double maxpriority = PyArray_GetPriority(with_prep[0],
PyArray_SUBTYPE_PRIORITY);
for (i = 1; i < np; ++i) {
- double priority = PyArray_GetPriority(with_wrap[i],
+ double priority = PyArray_GetPriority(with_prep[i],
PyArray_SUBTYPE_PRIORITY);
if (priority > maxpriority) {
maxpriority = priority;
- Py_DECREF(wrap);
- wrap = wraps[i];
+ Py_DECREF(prep);
+ prep = preps[i];
}
else {
- Py_DECREF(wraps[i]);
+ Py_DECREF(preps[i]);
}
}
}
}
/*
- * Here wrap is the wrapping function determined from the
+ * Here prep is the prepping function determined from the
* input arrays (could be NULL).
*
* For all the output arrays decide what to do.
*
- * 1) Use the wrap function determined from the input arrays
+ * 1) Use the prep function determined from the input arrays
* This is the default if the output array is not
* passed in.
*
@@ -327,381 +314,62 @@ _find_array_prepare(PyObject *args, PyObject **output_wrap, int nin, int nout)
for (i = 0; i < nout; i++) {
int j = nin + i;
int incref = 1;
- output_wrap[i] = wrap;
+ output_prep[i] = prep;
+ obj = NULL;
if (j < nargs) {
obj = PyTuple_GET_ITEM(args, j);
- if (obj == Py_None) {
- continue;
+ /* Output argument one may also be in a keyword argument */
+ if (i == 0 && obj == Py_None && kwds != NULL) {
+ obj = PyDict_GetItemString(kwds, "out");
}
+ }
+ /* Output argument one may also be in a keyword argument */
+ else if (i == 0 && kwds != NULL) {
+ obj = PyDict_GetItemString(kwds, "out");
+ }
+
+ if (obj != Py_None && obj != NULL) {
if (PyArray_CheckExact(obj)) {
- output_wrap[i] = Py_None;
+ /* None signals to not call any wrapping */
+ output_prep[i] = Py_None;
}
else {
- PyObject *owrap = PyObject_GetAttrString(obj,
+ PyObject *oprep = PyObject_GetAttrString(obj,
"__array_prepare__");
incref = 0;
- if (!(owrap) || !(PyCallable_Check(owrap))) {
- Py_XDECREF(owrap);
- owrap = wrap;
+ if (!(oprep) || !(PyCallable_Check(oprep))) {
+ Py_XDECREF(oprep);
+ oprep = prep;
incref = 1;
PyErr_Clear();
}
- output_wrap[i] = owrap;
+ output_prep[i] = oprep;
}
}
+
if (incref) {
- Py_XINCREF(output_wrap[i]);
+ Py_XINCREF(output_prep[i]);
}
}
- Py_XDECREF(wrap);
+ Py_XDECREF(prep);
return;
}
-/*
- * Called for non-NULL user-defined functions.
- * The object should be a CObject pointing to a linked-list of functions
- * storing the function, data, and signature of all user-defined functions.
- * There must be a match with the input argument types or an error
- * will occur.
- */
-static int
-_find_matching_userloop(PyObject *obj, int *arg_types,
- PyArray_SCALARKIND *scalars,
- PyUFuncGenericFunction *function, void **data,
- int nargs, int nin)
-{
- PyUFunc_Loop1d *funcdata;
- int i;
-
- funcdata = (PyUFunc_Loop1d *)NpyCapsule_AsVoidPtr(obj);
- while (funcdata != NULL) {
- for (i = 0; i < nin; i++) {
- if (!PyArray_CanCoerceScalar(arg_types[i],
- funcdata->arg_types[i],
- scalars[i]))
- break;
- }
- if (i == nin) {
- /* match found */
- *function = funcdata->func;
- *data = funcdata->data;
- /* Make sure actual arg_types supported by the loop are used */
- for (i = 0; i < nargs; i++) {
- arg_types[i] = funcdata->arg_types[i];
- }
- return 0;
- }
- funcdata = funcdata->next;
- }
- return -1;
-}
-
-/*
- * if only one type is specified then it is the "first" output data-type
- * and the first signature matching this output data-type is returned.
- *
- * if a tuple of types is specified then an exact match to the signature
- * is searched and it much match exactly or an error occurs
- */
-static int
-extract_specified_loop(PyUFuncObject *self, int *arg_types,
- PyUFuncGenericFunction *function, void **data,
- PyObject *type_tup, int userdef)
-{
- Py_ssize_t n = 1;
- int *rtypenums;
- static char msg[] = "loop written to specified type(s) not found";
- PyArray_Descr *dtype;
- int nargs;
- int i, j;
- int strtype = 0;
-
- nargs = self->nargs;
- if (PyTuple_Check(type_tup)) {
- n = PyTuple_GET_SIZE(type_tup);
- if (n != 1 && n != nargs) {
- PyErr_Format(PyExc_ValueError,
- "a type-tuple must be specified " \
- "of length 1 or %d for %s", nargs,
- self->name ? self->name : "(unknown)");
- return -1;
- }
- }
- else if (PyString_Check(type_tup)) {
- Py_ssize_t slen;
- char *thestr;
-
- slen = PyString_GET_SIZE(type_tup);
- thestr = PyString_AS_STRING(type_tup);
- for (i = 0; i < slen - 2; i++) {
- if (thestr[i] == '-' && thestr[i+1] == '>') {
- break;
- }
- }
- if (i < slen-2) {
- strtype = 1;
- n = slen - 2;
- if (i != self->nin
- || slen - 2 - i != self->nout) {
- PyErr_Format(PyExc_ValueError,
- "a type-string for %s, " \
- "requires %d typecode(s) before " \
- "and %d after the -> sign",
- self->name ? self->name : "(unknown)",
- self->nin, self->nout);
- return -1;
- }
- }
- }
- rtypenums = (int *)_pya_malloc(n*sizeof(int));
- if (rtypenums == NULL) {
- PyErr_NoMemory();
- return -1;
- }
-
- if (strtype) {
- char *ptr;
- ptr = PyString_AS_STRING(type_tup);
- i = 0;
- while (i < n) {
- if (*ptr == '-' || *ptr == '>') {
- ptr++;
- continue;
- }
- dtype = PyArray_DescrFromType((int) *ptr);
- if (dtype == NULL) {
- goto fail;
- }
- rtypenums[i] = dtype->type_num;
- Py_DECREF(dtype);
- ptr++;
- i++;
- }
- }
- else if (PyTuple_Check(type_tup)) {
- for (i = 0; i < n; i++) {
- if (PyArray_DescrConverter(PyTuple_GET_ITEM(type_tup, i),
- &dtype) == NPY_FAIL) {
- goto fail;
- }
- rtypenums[i] = dtype->type_num;
- Py_DECREF(dtype);
- }
- }
- else {
- if (PyArray_DescrConverter(type_tup, &dtype) == NPY_FAIL) {
- goto fail;
- }
- rtypenums[0] = dtype->type_num;
- Py_DECREF(dtype);
- }
-
- if (userdef > 0) {
- /* search in the user-defined functions */
- PyObject *key, *obj;
- PyUFunc_Loop1d *funcdata;
-
- obj = NULL;
- key = PyInt_FromLong((long) userdef);
- if (key == NULL) {
- goto fail;
- }
- obj = PyDict_GetItem(self->userloops, key);
- Py_DECREF(key);
- if (obj == NULL) {
- PyErr_SetString(PyExc_TypeError,
- "user-defined type used in ufunc" \
- " with no registered loops");
- goto fail;
- }
- /*
- * extract the correct function
- * data and argtypes
- */
- funcdata = (PyUFunc_Loop1d *)NpyCapsule_AsVoidPtr(obj);
- while (funcdata != NULL) {
- if (n != 1) {
- for (i = 0; i < nargs; i++) {
- if (rtypenums[i] != funcdata->arg_types[i]) {
- break;
- }
- }
- }
- else if (rtypenums[0] == funcdata->arg_types[self->nin]) {
- i = nargs;
- }
- else {
- i = -1;
- }
- if (i == nargs) {
- *function = funcdata->func;
- *data = funcdata->data;
- for(i = 0; i < nargs; i++) {
- arg_types[i] = funcdata->arg_types[i];
- }
- Py_DECREF(obj);
- goto finish;
- }
- funcdata = funcdata->next;
- }
- PyErr_SetString(PyExc_TypeError, msg);
- goto fail;
- }
-
- /* look for match in self->functions */
- for (j = 0; j < self->ntypes; j++) {
- if (n != 1) {
- for(i = 0; i < nargs; i++) {
- if (rtypenums[i] != self->types[j*nargs + i]) {
- break;
- }
- }
- }
- else if (rtypenums[0] == self->types[j*nargs+self->nin]) {
- i = nargs;
- }
- else {
- i = -1;
- }
- if (i == nargs) {
- *function = self->functions[j];
- *data = self->data[j];
- for (i = 0; i < nargs; i++) {
- arg_types[i] = self->types[j*nargs+i];
- }
- goto finish;
- }
- }
- PyErr_SetString(PyExc_TypeError, msg);
-
- fail:
- _pya_free(rtypenums);
- return -1;
-
- finish:
- _pya_free(rtypenums);
- return 0;
-}
-
-
-/*
- * Called to determine coercion
- * Can change arg_types.
- */
-static int
-select_types(PyUFuncObject *self, int *arg_types,
- PyUFuncGenericFunction *function, void **data,
- PyArray_SCALARKIND *scalars,
- PyObject *typetup)
-{
- int i, j;
- char start_type;
- int userdef = -1;
- int userdef_ind = -1;
-
- if (self->userloops) {
- for(i = 0; i < self->nin; i++) {
- if (PyTypeNum_ISUSERDEF(arg_types[i])) {
- userdef = arg_types[i];
- userdef_ind = i;
- break;
- }
- }
- }
-
- if (typetup != NULL)
- return extract_specified_loop(self, arg_types, function, data,
- typetup, userdef);
-
- if (userdef > 0) {
- PyObject *key, *obj;
- int ret = -1;
- obj = NULL;
-
- /*
- * Look through all the registered loops for all the user-defined
- * types to find a match.
- */
- while (ret == -1) {
- if (userdef_ind >= self->nin) {
- break;
- }
- userdef = arg_types[userdef_ind++];
- if (!(PyTypeNum_ISUSERDEF(userdef))) {
- continue;
- }
- key = PyInt_FromLong((long) userdef);
- if (key == NULL) {
- return -1;
- }
- obj = PyDict_GetItem(self->userloops, key);
- Py_DECREF(key);
- if (obj == NULL) {
- continue;
- }
- /*
- * extract the correct function
- * data and argtypes for this user-defined type.
- */
- ret = _find_matching_userloop(obj, arg_types, scalars,
- function, data, self->nargs,
- self->nin);
- }
- if (ret == 0) {
- return ret;
- }
- PyErr_SetString(PyExc_TypeError, _types_msg);
- return ret;
- }
-
- start_type = arg_types[0];
- /*
- * If the first argument is a scalar we need to place
- * the start type as the lowest type in the class
- */
- if (scalars[0] != PyArray_NOSCALAR) {
- start_type = _lowest_type(start_type);
- }
-
- i = 0;
- while (i < self->ntypes && start_type > self->types[i*self->nargs]) {
- i++;
- }
- for (; i < self->ntypes; i++) {
- for (j = 0; j < self->nin; j++) {
- if (!PyArray_CanCoerceScalar(arg_types[j],
- self->types[i*self->nargs + j],
- scalars[j]))
- break;
- }
- if (j == self->nin) {
- break;
- }
- }
- if (i >= self->ntypes) {
- PyErr_SetString(PyExc_TypeError, _types_msg);
- return -1;
- }
- for (j = 0; j < self->nargs; j++) {
- arg_types[j] = self->types[i*self->nargs+j];
- }
- if (self->data) {
- *data = self->data[i];
- }
- else {
- *data = NULL;
- }
- *function = self->functions[i];
-
- return 0;
-}
-
#if USE_USE_DEFAULTS==1
static int PyUFunc_NUM_NODEFAULTS = 0;
#endif
static PyObject *PyUFunc_PYVALS_NAME = NULL;
+/*
+ * Extracts some values from the global pyvals tuple.
+ * ref - should hold the global tuple
+ * name - is the name of the ufunc (ufuncobj->name)
+ * bufsize - receives the buffer size to use
+ * errmask - receives the bitmask for error handling
+ * errobj - receives the python object to call with the error,
+ * if an error handling method is 'call'
+ */
static int
_extract_pyvals(PyObject *ref, char *name, int *bufsize,
int *errmask, PyObject **errobj)
@@ -794,53 +462,6 @@ PyUFunc_GetPyValues(char *name, int *bufsize, int *errmask, PyObject **errobj)
return _extract_pyvals(ref, name, bufsize, errmask, errobj);
}
-/*
- * Create copies for any arrays that are less than loop->bufsize
- * in total size (or core_enabled) and are mis-behaved or in need
- * of casting.
- */
-static int
-_create_copies(PyUFuncLoopObject *loop, int *arg_types, PyArrayObject **mps)
-{
- int nin = loop->ufunc->nin;
- int i;
- intp size;
- PyObject *new;
- PyArray_Descr *ntype;
- PyArray_Descr *atype;
-
- for (i = 0; i < nin; i++) {
- size = PyArray_SIZE(mps[i]);
- /*
- * if the type of mps[i] is equivalent to arg_types[i]
- * then set arg_types[i] equal to type of mps[i] for later checking....
- */
- if (PyArray_TYPE(mps[i]) != arg_types[i]) {
- ntype = mps[i]->descr;
- atype = PyArray_DescrFromType(arg_types[i]);
- if (PyArray_EquivTypes(atype, ntype)) {
- arg_types[i] = ntype->type_num;
- }
- Py_DECREF(atype);
- }
- if (size < loop->bufsize || loop->ufunc->core_enabled) {
- if (!(PyArray_ISBEHAVED_RO(mps[i]))
- || PyArray_TYPE(mps[i]) != arg_types[i]) {
- ntype = PyArray_DescrFromType(arg_types[i]);
- new = PyArray_FromAny((PyObject *)mps[i],
- ntype, 0, 0,
- FORCECAST | ALIGNED, NULL);
- if (new == NULL) {
- return -1;
- }
- Py_DECREF(mps[i]);
- mps[i] = (PyArrayObject *)new;
- }
- }
- }
- return 0;
-}
-
#define _GETATTR_(str, rstr) do {if (strcmp(name, #str) == 0) \
return PyObject_HasAttrString(op, "__" #rstr "__");} while (0);
@@ -1068,1964 +689,2719 @@ fail:
return -1;
}
-/*
- * Concatenate the loop and core dimensions of
- * PyArrayMultiIterObject's iarg-th argument, to recover a full
- * dimension array (used for output arguments).
- */
-static npy_intp*
-_compute_output_dims(PyUFuncLoopObject *loop, int iarg,
- int *out_nd, npy_intp *tmp_dims)
-{
- int i;
- PyUFuncObject *ufunc = loop->ufunc;
- if (ufunc->core_enabled == 0) {
- /* case of ufunc with trivial core-signature */
- *out_nd = loop->nd;
- return loop->dimensions;
- }
- *out_nd = loop->nd + ufunc->core_num_dims[iarg];
- if (*out_nd > NPY_MAXARGS) {
- PyErr_SetString(PyExc_ValueError,
- "dimension of output variable exceeds limit");
- return NULL;
- }
-
- /* copy loop dimensions */
- memcpy(tmp_dims, loop->dimensions, sizeof(npy_intp) * loop->nd);
-
- /* copy core dimension */
- for (i = 0; i < ufunc->core_num_dims[iarg]; i++) {
- tmp_dims[loop->nd + i] = loop->core_dim_sizes[1 +
- ufunc->core_dim_ixs[ufunc->core_offsets[iarg] + i]];
- }
- return tmp_dims;
-}
+/********* GENERIC UFUNC USING ITERATOR *********/
-/* Check and set core_dim_sizes and core_strides for the i-th argument. */
-static int
-_compute_dimension_size(PyUFuncLoopObject *loop, PyArrayObject **mps, int i)
-{
- PyUFuncObject *ufunc = loop->ufunc;
- int j = ufunc->core_offsets[i];
- int k = PyArray_NDIM(mps[i]) - ufunc->core_num_dims[i];
- int ind;
- for (ind = 0; ind < ufunc->core_num_dims[i]; ind++, j++, k++) {
- npy_intp dim = k < 0 ? 1 : PyArray_DIM(mps[i], k);
- /* First element of core_dim_sizes will be used for looping */
- int dim_ix = ufunc->core_dim_ixs[j] + 1;
- if (loop->core_dim_sizes[dim_ix] == 1) {
- /* broadcast core dimension */
- loop->core_dim_sizes[dim_ix] = dim;
- }
- else if (dim != 1 && dim != loop->core_dim_sizes[dim_ix]) {
- PyErr_SetString(PyExc_ValueError, "core dimensions mismatch");
- return -1;
- }
- /* First ufunc->nargs elements will be used for looping */
- loop->core_strides[ufunc->nargs + j] =
- dim == 1 ? 0 : PyArray_STRIDE(mps[i], k);
- }
- return 0;
-}
-
-/* Return a view of array "ap" with "core_nd" dimensions cut from tail. */
-static PyArrayObject *
-_trunc_coredim(PyArrayObject *ap, int core_nd)
+/*
+ * Parses the positional and keyword arguments for a generic ufunc call.
+ *
+ * Note that if an error is returned, the caller must free the
+ * non-zero references in out_op. This
+ * function does not do its own clean-up.
+ */
+static int get_ufunc_arguments(PyUFuncObject *self,
+ PyObject *args, PyObject *kwds,
+ PyArrayObject **out_op,
+ NPY_ORDER *out_order,
+ NPY_CASTING *out_casting,
+ PyObject **out_extobj,
+ PyObject **out_typetup,
+ int *out_any_object)
{
- PyArrayObject *ret;
- int nd = ap->nd - core_nd;
+ npy_intp i, nargs, nin = self->nin;
+ PyObject *obj, *context;
+ PyObject *str_key_obj = NULL;
+ char *ufunc_name;
- if (nd < 0) {
- nd = 0;
- }
- /* The following code is basically taken from PyArray_Transpose */
- /* NewFromDescr will steal this reference */
- Py_INCREF(ap->descr);
- ret = (PyArrayObject *)
- PyArray_NewFromDescr(Py_TYPE(ap), ap->descr,
- nd, ap->dimensions,
- ap->strides, ap->data, ap->flags,
- (PyObject *)ap);
- if (ret == NULL) {
- return NULL;
- }
- /* point at true owner of memory: */
- ret->base = (PyObject *)ap;
- Py_INCREF(ap);
- PyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);
- return ret;
-}
+ int any_flexible = 0, any_object = 0;
-static Py_ssize_t
-construct_arrays(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps,
- PyObject *typetup)
-{
- Py_ssize_t nargs;
- int i;
- int arg_types[NPY_MAXARGS];
- PyArray_SCALARKIND scalars[NPY_MAXARGS];
- PyArray_SCALARKIND maxarrkind, maxsckind, new;
- PyUFuncObject *self = loop->ufunc;
- Bool allscalars = TRUE;
- PyTypeObject *subtype = &PyArray_Type;
- PyObject *context = NULL;
- PyObject *obj;
- int flexible = 0;
- int object = 0;
-
- npy_intp temp_dims[NPY_MAXDIMS];
- npy_intp *out_dims;
- int out_nd;
- PyObject *wraparr[NPY_MAXARGS];
+ ufunc_name = self->name ? self->name : "<unnamed ufunc>";
/* Check number of arguments */
nargs = PyTuple_Size(args);
- if ((nargs < self->nin) || (nargs > self->nargs)) {
+ if ((nargs < nin) || (nargs > self->nargs)) {
PyErr_SetString(PyExc_ValueError, "invalid number of arguments");
return -1;
}
- /* Get each input argument */
- maxarrkind = PyArray_NOSCALAR;
- maxsckind = PyArray_NOSCALAR;
- for(i = 0; i < self->nin; i++) {
- obj = PyTuple_GET_ITEM(args,i);
+ /* Get input arguments */
+ for(i = 0; i < nin; ++i) {
+ obj = PyTuple_GET_ITEM(args, i);
if (!PyArray_Check(obj) && !PyArray_IsScalar(obj, Generic)) {
+ /*
+ * TODO: There should be a comment here explaining what
+ * context does.
+ */
context = Py_BuildValue("OOi", self, args, i);
+ if (context == NULL) {
+ return -1;
+ }
}
else {
context = NULL;
}
- mps[i] = (PyArrayObject *)PyArray_FromAny(obj, NULL, 0, 0, 0, context);
+ out_op[i] = (PyArrayObject *)PyArray_FromAny(obj,
+ NULL, 0, 0, 0, context);
Py_XDECREF(context);
- if (mps[i] == NULL) {
+ if (out_op[i] == NULL) {
return -1;
}
- arg_types[i] = PyArray_TYPE(mps[i]);
- if (!flexible && PyTypeNum_ISFLEXIBLE(arg_types[i])) {
- flexible = 1;
+ if (!any_flexible &&
+ PyTypeNum_ISFLEXIBLE(PyArray_DESCR(out_op[i])->type_num)) {
+ any_flexible = 1;
}
- if (!object && PyTypeNum_ISOBJECT(arg_types[i])) {
- object = 1;
+ if (!any_object &&
+ PyTypeNum_ISOBJECT(PyArray_DESCR(out_op[i])->type_num)) {
+ any_object = 1;
}
- /*
- * debug
- * fprintf(stderr, "array %d has reference %d\n", i,
- * (mps[i])->ob_refcnt);
- */
+ }
- /*
- * Scalars are 0-dimensional arrays at this point
- */
+ /*
+ * Indicate not implemented if there are flexible objects (structured
+ * type or string) but no object types.
+ *
+ * Not sure - adding this increased to 246 errors, 150 failures.
+ */
+ if (any_flexible && !any_object) {
+ return -2;
- /*
- * We need to keep track of whether or not scalars
- * are mixed with arrays of different kinds.
- */
+ }
- if (mps[i]->nd > 0) {
- scalars[i] = PyArray_NOSCALAR;
- allscalars = FALSE;
- new = PyArray_ScalarKind(arg_types[i], NULL);
- maxarrkind = NPY_MAX(new, maxarrkind);
+ /* Get positional output arguments */
+ for (i = nin; i < nargs; ++i) {
+ obj = PyTuple_GET_ITEM(args, i);
+ /* Translate None to NULL */
+ if (obj == Py_None) {
+ continue;
+ }
+ /* If it's an array, can use it */
+ if (PyArray_Check(obj)) {
+ if (!PyArray_ISWRITEABLE(obj)) {
+ PyErr_SetString(PyExc_ValueError,
+ "return array is not writeable");
+ return -1;
+ }
+ Py_INCREF(obj);
+ out_op[i] = (PyArrayObject *)obj;
}
else {
- scalars[i] = PyArray_ScalarKind(arg_types[i], &(mps[i]));
- maxsckind = NPY_MAX(scalars[i], maxsckind);
+ PyErr_SetString(PyExc_TypeError,
+ "return arrays must be "
+ "of ArrayType");
+ return -1;
}
}
- /* We don't do strings */
- if (flexible && !object) {
- loop->notimplemented = 1;
- return nargs;
- }
-
/*
- * If everything is a scalar, or scalars mixed with arrays of
- * different kinds of lesser kinds then use normal coercion rules
+ * Get keyword output and other arguments.
+ * Raise an error if anything else is present in the
+ * keyword dictionary.
*/
- if (allscalars || (maxsckind > maxarrkind)) {
- for (i = 0; i < self->nin; i++) {
- scalars[i] = PyArray_NOSCALAR;
+ if (kwds != NULL) {
+ PyObject *key, *value;
+ Py_ssize_t pos = 0;
+ while (PyDict_Next(kwds, &pos, &key, &value)) {
+ Py_ssize_t length = 0;
+ char *str = NULL;
+ int bad_arg = 1;
+
+#if defined(NPY_PY3K)
+ Py_XDECREF(str_key_obj);
+ str_key_obj = PyUnicode_AsASCIIString(key);
+ if (str_key_obj != NULL) {
+ key = str_key_obj;
+ }
+#endif
+
+ if (PyBytes_AsStringAndSize(key, &str, &length) == -1) {
+ PyErr_SetString(PyExc_TypeError, "invalid keyword argument");
+ goto fail;
+ }
+
+ switch (str[0]) {
+ case 'c':
+ /* Provides a policy for allowed casting */
+ if (strncmp(str,"casting",7) == 0) {
+ if (!PyArray_CastingConverter(value, out_casting)) {
+ goto fail;
+ }
+ bad_arg = 0;
+ }
+ break;
+ case 'e':
+ /*
+ * Overrides the global parameters buffer size,
+ * error mask, and error object
+ */
+ if (strncmp(str,"extobj",6) == 0) {
+ *out_extobj = value;
+ bad_arg = 0;
+ }
+ break;
+ case 'o':
+ /* First output may be specified as a keyword parameter */
+ if (strncmp(str,"out",3) == 0) {
+ if (out_op[nin] != NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "cannot specify 'out' as both a "
+ "positional and keyword argument");
+ goto fail;
+ }
+
+ if (PyArray_Check(value)) {
+ if (!PyArray_ISWRITEABLE(value)) {
+ PyErr_SetString(PyExc_ValueError,
+ "return array is not writeable");
+ goto fail;
+ }
+ Py_INCREF(value);
+ out_op[nin] = (PyArrayObject *)value;
+ }
+ else {
+ PyErr_SetString(PyExc_TypeError,
+ "return arrays must be "
+ "of ArrayType");
+ goto fail;
+ }
+ bad_arg = 0;
+ }
+ /* Allows the default output layout to be overridden */
+ else if (strncmp(str,"order",5) == 0) {
+ if (!PyArray_OrderConverter(value, out_order)) {
+ goto fail;
+ }
+ bad_arg = 0;
+ }
+ break;
+ case 's':
+ /* Allows a specific function inner loop to be selected */
+ if (strncmp(str,"sig",3) == 0) {
+ if (*out_typetup != NULL) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "cannot specify both 'sig' and 'dtype'");
+ goto fail;
+ }
+ *out_typetup = value;
+ Py_INCREF(value);
+ bad_arg = 0;
+ }
+ break;
+ case 'd':
+ /* Another way to specify 'sig' */
+ if (strncmp(str,"dtype",5) == 0) {
+ /* Allow this parameter to be None */
+ PyArray_Descr *dtype;
+ if (!PyArray_DescrConverter2(value, &dtype)) {
+ goto fail;
+ }
+ if (dtype != NULL) {
+ if (*out_typetup != NULL) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "cannot specify both 'sig' and 'dtype'");
+ goto fail;
+ }
+ *out_typetup = Py_BuildValue("(N)", dtype);
+ }
+ bad_arg = 0;
+ }
+ }
+
+ if (bad_arg) {
+ char *format = "'%s' is an invalid keyword to ufunc '%s'";
+ PyErr_Format(PyExc_TypeError, format, str, ufunc_name);
+ goto fail;
+ }
}
}
- /* Select an appropriate function for these argument types. */
- if (select_types(loop->ufunc, arg_types, &(loop->function),
- &(loop->funcdata), scalars, typetup) == -1) {
- return -1;
+ *out_any_object = any_object;
+
+ Py_XDECREF(str_key_obj);
+ return 0;
+
+fail:
+ Py_XDECREF(str_key_obj);
+ return -1;
+}
+
+static const char *
+_casting_to_string(NPY_CASTING casting)
+{
+ switch (casting) {
+ case NPY_NO_CASTING:
+ return "no";
+ case NPY_EQUIV_CASTING:
+ return "equiv";
+ case NPY_SAFE_CASTING:
+ return "safe";
+ case NPY_SAME_KIND_CASTING:
+ return "same_kind";
+ case NPY_UNSAFE_CASTING:
+ return "unsafe";
+ default:
+ return "<unknown>";
}
+}
+
+
+static int
+ufunc_loop_matches(PyUFuncObject *self,
+ PyArrayObject **op,
+ NPY_CASTING input_casting,
+ NPY_CASTING output_casting,
+ int any_object,
+ int all_inputs_scalar,
+ int *types,
+ int *out_no_castable_output,
+ char *out_err_src_typecode,
+ char *out_err_dst_typecode)
+{
+ npy_intp i, nin = self->nin, niter = nin + self->nout;
+
/*
- * FAIL with NotImplemented if the other object has
- * the __r<op>__ method and has __array_priority__ as
- * an attribute (signalling it can handle ndarray's)
- * and is not already an ndarray or a subtype of the same type.
+ * First check if all the inputs can be safely cast
+ * to the types for this function
*/
- if ((arg_types[1] == PyArray_OBJECT)
- && (loop->ufunc->nin==2) && (loop->ufunc->nout == 1)) {
- PyObject *_obj = PyTuple_GET_ITEM(args, 1);
- if (!PyArray_CheckExact(_obj)
- /* If both are same subtype of object arrays, then proceed */
- && !(Py_TYPE(_obj) == Py_TYPE(PyTuple_GET_ITEM(args, 0)))
- && PyObject_HasAttrString(_obj, "__array_priority__")
- && _has_reflected_op(_obj, loop->ufunc->name)) {
- loop->notimplemented = 1;
- return nargs;
+ for (i = 0; i < nin; ++i) {
+ PyArray_Descr *tmp;
+
+ /*
+ * If no inputs are objects and there are more than one
+ * loop, don't allow conversion to object. The rationale
+ * behind this is mostly performance. Except for custom
+ * ufuncs built with just one object-parametered inner loop,
+ * only the types that are supported are implemented. Trying
+ * the object version of logical_or on float arguments doesn't
+ * seem right.
+ */
+ if (types[i] == NPY_OBJECT && !any_object && self->ntypes > 1) {
+ return 0;
}
- }
- /*
- * Create copies for some of the arrays if they are small
- * enough and not already contiguous
- */
- if (_create_copies(loop, arg_types, mps) < 0) {
- return -1;
+ tmp = PyArray_DescrFromType(types[i]);
+ if (tmp == NULL) {
+ return -1;
+ }
+
+#if NPY_UF_DBG_TRACING
+ printf("Checking type for op %d, type %d: ", (int)i, (int)types[i]);
+ PyObject_Print((PyObject *)tmp, stdout, 0);
+ printf(", operand type: ");
+ PyObject_Print((PyObject *)PyArray_DESCR(op[i]), stdout, 0);
+ printf("\n");
+#endif
+ /*
+ * If all the inputs are scalars, use the regular
+ * promotion rules, not the special value-checking ones.
+ */
+ if (all_inputs_scalar) {
+ if (!PyArray_CanCastTypeTo(PyArray_DESCR(op[i]), tmp,
+ input_casting)) {
+ Py_DECREF(tmp);
+ return 0;
+ }
+ }
+ else {
+ if (!PyArray_CanCastArrayTo(op[i], tmp, input_casting)) {
+ Py_DECREF(tmp);
+ return 0;
+ }
+ }
+ Py_DECREF(tmp);
}
+ NPY_UF_DBG_PRINT("The inputs all worked\n");
/*
- * Only use loop dimensions when constructing Iterator:
- * temporarily replace mps[i] (will be recovered below).
+ * If all the inputs were ok, then check casting back to the
+ * outputs.
*/
- if (self->core_enabled) {
- for (i = 0; i < self->nin; i++) {
- PyArrayObject *ao;
-
- if (_compute_dimension_size(loop, mps, i) < 0) {
+ for (i = nin; i < niter; ++i) {
+ if (op[i] != NULL) {
+ PyArray_Descr *tmp = PyArray_DescrFromType(types[i]);
+ if (tmp == NULL) {
return -1;
}
- ao = _trunc_coredim(mps[i], self->core_num_dims[i]);
- if (ao == NULL) {
- return -1;
+ if (!PyArray_CanCastTypeTo(tmp, PyArray_DESCR(op[i]),
+ output_casting)) {
+ if (!(*out_no_castable_output)) {
+ *out_no_castable_output = 1;
+ *out_err_src_typecode = tmp->type;
+ *out_err_dst_typecode = PyArray_DESCR(op[i])->type;
+ }
+ Py_DECREF(tmp);
+ return 0;
}
- mps[i] = ao;
+ Py_DECREF(tmp);
}
}
+ NPY_UF_DBG_PRINT("The outputs all worked\n");
- /* Create Iterators for the Inputs */
- for (i = 0; i < self->nin; i++) {
- loop->iters[i] = (PyArrayIterObject *)
- PyArray_IterNew((PyObject *)mps[i]);
- if (loop->iters[i] == NULL) {
- return -1;
- }
- }
-
- /* Recover mps[i]. */
- if (self->core_enabled) {
- for (i = 0; i < self->nin; i++) {
- PyArrayObject *ao = mps[i];
- mps[i] = (PyArrayObject *)mps[i]->base;
- Py_DECREF(ao);
- }
- }
+ return 1;
+}
- /* Broadcast the result */
- loop->numiter = self->nin;
- if (PyArray_Broadcast((PyArrayMultiIterObject *)loop) < 0) {
- return -1;
- }
+static int
+set_ufunc_loop_data_types(PyUFuncObject *self, PyArrayObject **op,
+ PyArray_Descr **out_dtype,
+ int *types,
+ npy_intp buffersize, int *out_trivial_loop_ok)
+{
+ npy_intp i, nin = self->nin, niter = nin + self->nout;
- /* Get any return arguments */
- for (i = self->nin; i < nargs; i++) {
- mps[i] = (PyArrayObject *)PyTuple_GET_ITEM(args, i);
- if (((PyObject *)mps[i])==Py_None) {
- mps[i] = NULL;
- continue;
+ *out_trivial_loop_ok = 1;
+ /* Fill the dtypes array */
+ for (i = 0; i < niter; ++i) {
+ out_dtype[i] = PyArray_DescrFromType(types[i]);
+ if (out_dtype[i] == NULL) {
+ return -1;
}
- Py_INCREF(mps[i]);
- if (!PyArray_Check((PyObject *)mps[i])) {
- PyObject *new;
- if (PyArrayIter_Check(mps[i])) {
- new = PyObject_CallMethod((PyObject *)mps[i],
- "__array__", NULL);
- Py_DECREF(mps[i]);
- mps[i] = (PyArrayObject *)new;
+ /*
+ * If the dtype doesn't match, or the array isn't aligned,
+ * indicate that the trivial loop can't be done.
+ */
+ if (*out_trivial_loop_ok && op[i] != NULL &&
+ (!PyArray_ISALIGNED(op[i]) ||
+ !PyArray_EquivTypes(out_dtype[i], PyArray_DESCR(op[i]))
+ )) {
+ /*
+ * If op[j] is a scalar or small one dimensional
+ * array input, make a copy to keep the opportunity
+ * for a trivial loop.
+ */
+ if (i < nin && (PyArray_NDIM(op[i]) == 0 ||
+ (PyArray_NDIM(op[i]) == 1 &&
+ PyArray_DIM(op[i],0) <= buffersize))) {
+ PyArrayObject *tmp;
+ Py_INCREF(out_dtype[i]);
+ tmp = (PyArrayObject *)
+ PyArray_CastToType(op[i], out_dtype[i], 0);
+ if (tmp == NULL) {
+ return -1;
+ }
+ Py_DECREF(op[i]);
+ op[i] = tmp;
}
else {
- PyErr_SetString(PyExc_TypeError,
- "return arrays must be "\
- "of ArrayType");
- Py_DECREF(mps[i]);
- mps[i] = NULL;
- return -1;
+ *out_trivial_loop_ok = 0;
}
}
+ }
+
+ return 0;
+}
+
+/*
+ * Does a search through the arguments and the loops
+ */
+static int
+find_ufunc_matching_userloop(PyUFuncObject *self,
+ PyArrayObject **op,
+ NPY_CASTING input_casting,
+ NPY_CASTING output_casting,
+ npy_intp buffersize,
+ int any_object,
+ int all_inputs_scalar,
+ PyArray_Descr **out_dtype,
+ PyUFuncGenericFunction *out_innerloop,
+ void **out_innerloopdata,
+ int *out_trivial_loop_ok,
+ int *out_no_castable_output,
+ char *out_err_src_typecode,
+ char *out_err_dst_typecode)
+{
+ npy_intp i, nin = self->nin;
+ PyUFunc_Loop1d *funcdata;
+
+ /* Use this to try to avoid repeating the same userdef loop search */
+ int last_userdef = -1;
- if (self->core_enabled) {
- if (_compute_dimension_size(loop, mps, i) < 0) {
+ for (i = 0; i < nin; ++i) {
+ int type_num = PyArray_DESCR(op[i])->type_num;
+ if (type_num != last_userdef && PyTypeNum_ISUSERDEF(type_num)) {
+ PyObject *key, *obj;
+
+ last_userdef = type_num;
+
+ key = PyInt_FromLong(type_num);
+ if (key == NULL) {
return -1;
}
- }
- out_dims = _compute_output_dims(loop, i, &out_nd, temp_dims);
- if (!out_dims) {
- return -1;
- }
- if (mps[i]->nd != out_nd
- || !PyArray_CompareLists(mps[i]->dimensions, out_dims, out_nd)) {
- PyErr_SetString(PyExc_ValueError, "invalid return array shape");
- Py_DECREF(mps[i]);
- mps[i] = NULL;
- return -1;
- }
- if (!PyArray_ISWRITEABLE(mps[i])) {
- PyErr_SetString(PyExc_ValueError, "return array is not writeable");
- Py_DECREF(mps[i]);
- mps[i] = NULL;
- return -1;
+ obj = PyDict_GetItem(self->userloops, key);
+ Py_DECREF(key);
+ if (obj == NULL) {
+ continue;
+ }
+ funcdata = (PyUFunc_Loop1d *)NpyCapsule_AsVoidPtr(obj);
+ while (funcdata != NULL) {
+ int *types = funcdata->arg_types;
+ switch (ufunc_loop_matches(self, op,
+ input_casting, output_casting,
+ any_object, all_inputs_scalar,
+ types,
+ out_no_castable_output, out_err_src_typecode,
+ out_err_dst_typecode)) {
+ /* Error */
+ case -1:
+ return -1;
+ /* Found a match */
+ case 1:
+ set_ufunc_loop_data_types(self, op, out_dtype, types,
+ buffersize, out_trivial_loop_ok);
+
+ /* Save the inner loop and its data */
+ *out_innerloop = funcdata->func;
+ *out_innerloopdata = funcdata->data;
+
+ NPY_UF_DBG_PRINT("Returning userdef inner "
+ "loop successfully\n");
+
+ return 0;
+ }
+
+ funcdata = funcdata->next;
+ }
}
}
- /* construct any missing return arrays and make output iterators */
- for(i = self->nin; i < self->nargs; i++) {
- PyArray_Descr *ntype;
+ /* Didn't find a match */
+ return 0;
+}
+
+/*
+ * Does a search through the arguments and the loops
+ */
+static int
+find_ufunc_specified_userloop(PyUFuncObject *self,
+ int n_specified,
+ int *specified_types,
+ PyArrayObject **op,
+ NPY_CASTING casting,
+ npy_intp buffersize,
+ int any_object,
+ int all_inputs_scalar,
+ PyArray_Descr **out_dtype,
+ PyUFuncGenericFunction *out_innerloop,
+ void **out_innerloopdata,
+ int *out_trivial_loop_ok)
+{
+ npy_intp i, j, nin = self->nin, niter = nin + self->nout;
+ PyUFunc_Loop1d *funcdata;
+
+ /* Use this to try to avoid repeating the same userdef loop search */
+ int last_userdef = -1;
+
+ int no_castable_output = 0;
+ char err_src_typecode = '-', err_dst_typecode = '-';
- if (mps[i] == NULL) {
- out_dims = _compute_output_dims(loop, i, &out_nd, temp_dims);
- if (!out_dims) {
+ for (i = 0; i < nin; ++i) {
+ int type_num = PyArray_DESCR(op[i])->type_num;
+ if (type_num != last_userdef && PyTypeNum_ISUSERDEF(type_num)) {
+ PyObject *key, *obj;
+
+ last_userdef = type_num;
+
+ key = PyInt_FromLong(type_num);
+ if (key == NULL) {
return -1;
}
- mps[i] = (PyArrayObject *)PyArray_New(subtype,
- out_nd,
- out_dims,
- arg_types[i],
- NULL, NULL,
- 0, 0, NULL);
- if (mps[i] == NULL) {
- return -1;
+ obj = PyDict_GetItem(self->userloops, key);
+ Py_DECREF(key);
+ if (obj == NULL) {
+ continue;
}
- }
-
- /*
- * reset types for outputs that are equivalent
- * -- no sense casting uselessly
- */
- else {
- if (mps[i]->descr->type_num != arg_types[i]) {
- PyArray_Descr *atype;
- ntype = mps[i]->descr;
- atype = PyArray_DescrFromType(arg_types[i]);
- if (PyArray_EquivTypes(atype, ntype)) {
- arg_types[i] = ntype->type_num;
+ funcdata = (PyUFunc_Loop1d *)NpyCapsule_AsVoidPtr(obj);
+ while (funcdata != NULL) {
+ int *types = funcdata->arg_types;
+ int matched = 1;
+
+ if (n_specified == niter) {
+ for (j = 0; j < niter; ++j) {
+ if (types[j] != specified_types[j]) {
+ matched = 0;
+ break;
+ }
+ }
+ } else {
+ if (types[nin] != specified_types[0]) {
+ matched = 0;
+ }
+ }
+ if (!matched) {
+ continue;
}
- Py_DECREF(atype);
- }
- /* still not the same -- or will we have to use buffers?*/
- if (mps[i]->descr->type_num != arg_types[i]
- || !PyArray_ISBEHAVED_RO(mps[i])) {
- if (loop->size < loop->bufsize || self->core_enabled) {
- PyObject *new;
- /*
- * Copy the array to a temporary copy
- * and set the UPDATEIFCOPY flag
- */
- ntype = PyArray_DescrFromType(arg_types[i]);
- new = PyArray_FromAny((PyObject *)mps[i],
- ntype, 0, 0,
- FORCECAST | ALIGNED |
- UPDATEIFCOPY, NULL);
- if (new == NULL) {
+ switch (ufunc_loop_matches(self, op,
+ casting, casting,
+ any_object, all_inputs_scalar,
+ types,
+ &no_castable_output, &err_src_typecode,
+ &err_dst_typecode)) {
+ /* It works */
+ case 1:
+ set_ufunc_loop_data_types(self, op, out_dtype, types,
+ buffersize, out_trivial_loop_ok);
+
+ /* Save the inner loop and its data */
+ *out_innerloop = funcdata->func;
+ *out_innerloopdata = funcdata->data;
+
+ NPY_UF_DBG_PRINT("Returning userdef inner "
+ "loop successfully\n");
+
+ return 0;
+ /* Didn't match */
+ case 0:
+ PyErr_Format(PyExc_TypeError,
+ "found a user loop for ufunc '%s' "
+ "matching the type-tuple, "
+ "but the inputs and/or outputs could not be "
+ "cast according to the casting rule",
+ self->name ? self->name : "(unknown)");
+ return -1;
+ /* Error */
+ case -1:
return -1;
- }
- Py_DECREF(mps[i]);
- mps[i] = (PyArrayObject *)new;
}
+
+ funcdata = funcdata->next;
}
}
+ }
- if (self->core_enabled) {
- PyArrayObject *ao;
+ /* Didn't find a match */
+ return 0;
+}
- /* computer for all output arguments, and set strides in "loop" */
- if (_compute_dimension_size(loop, mps, i) < 0) {
- return -1;
- }
- ao = _trunc_coredim(mps[i], self->core_num_dims[i]);
- if (ao == NULL) {
- return -1;
- }
- /* Temporarily modify mps[i] for constructing iterator. */
- mps[i] = ao;
- }
+/*
+ * Does a linear search for the best inner loop of the ufunc.
+ * When op[i] is a scalar or a one dimensional array smaller than
+ * the buffersize, and needs a dtype conversion, this function
+ * may substitute op[i] with a version cast to the correct type. This way,
+ * the later trivial loop detection has a higher chance of being triggered.
+ *
+ * Note that if an error is returned, the caller must free the non-zero
+ * references in out_dtype. This function does not do its own clean-up.
+ */
+static int
+find_best_ufunc_inner_loop(PyUFuncObject *self,
+ PyArrayObject **op,
+ NPY_CASTING input_casting,
+ NPY_CASTING output_casting,
+ npy_intp buffersize,
+ int any_object,
+ PyArray_Descr **out_dtype,
+ PyUFuncGenericFunction *out_innerloop,
+ void **out_innerloopdata,
+ int *out_trivial_loop_ok)
+{
+ npy_intp i, j, nin = self->nin, niter = nin + self->nout;
+ int types[NPY_MAXARGS];
+ char *ufunc_name;
+ int no_castable_output, all_inputs_scalar;
- loop->iters[i] = (PyArrayIterObject *)
- PyArray_IterNew((PyObject *)mps[i]);
- if (loop->iters[i] == NULL) {
- return -1;
- }
+ /* For making a better error message on coercion error */
+ char err_dst_typecode = '-', err_src_typecode = '-';
- /* Recover mps[i]. */
- if (self->core_enabled) {
- PyArrayObject *ao = mps[i];
- mps[i] = (PyArrayObject *)mps[i]->base;
- Py_DECREF(ao);
+ ufunc_name = self->name ? self->name : "(unknown)";
+
+ /* Check whether all the inputs are scalar */
+ all_inputs_scalar = 1;
+ for(i = 0; i < nin; ++i) {
+ if (PyArray_NDIM(op[i]) > 0) {
+ all_inputs_scalar = 0;
}
+ }
+ /* If the ufunc has userloops, search for them. */
+ if (self->userloops) {
+ switch (find_ufunc_matching_userloop(self, op,
+ input_casting, output_casting,
+ buffersize, any_object, all_inputs_scalar,
+ out_dtype, out_innerloop, out_innerloopdata,
+ out_trivial_loop_ok,
+ &no_castable_output, &err_src_typecode,
+ &err_dst_typecode)) {
+ /* Error */
+ case -1:
+ return -1;
+ /* A loop was found */
+ case 1:
+ return 0;
+ }
}
/*
- * Use __array_prepare__ on all outputs
- * if present on one of the input arguments.
- * If present for multiple inputs:
- * use __array_prepare__ of input object with largest
- * __array_priority__ (default = 0.0)
+ * Determine the UFunc loop. This could in general be *much* faster,
+ * and a better way to implement it might be for the ufunc to
+ * provide a function which gives back the result type and inner
+ * loop function.
*
- * Exception: we should not wrap outputs for items already
- * passed in as output-arguments. These items should either
- * be left unwrapped or wrapped by calling their own __array_prepare__
- * routine.
+ * A default fast mechanism could be provided for functions which
+ * follow the most typical pattern, when all functions have signatures
+ * "xx...x -> x" for some built-in data type x, as follows.
+ * - Use PyArray_ResultType to get the output type
+ * - Look up the inner loop in a table based on the output type_num
*
- * For each output argument, wrap will be either
- * NULL --- call PyArray_Return() -- default if no output arguments given
- * None --- array-object passed in don't call PyArray_Return
- * method --- the __array_prepare__ method to call.
+ * The method for finding the loop in the previous code did not
+ * appear consistent (as noted by some asymmetry in the generated
+ * coercion tables for np.add).
*/
- _find_array_prepare(args, wraparr, loop->ufunc->nin, loop->ufunc->nout);
+ no_castable_output = 0;
+ for (i = 0; i < self->ntypes; ++i) {
+ char *orig_types = self->types + i*self->nargs;
+
+ /* Copy the types into an int array for matching */
+ for (j = 0; j < niter; ++j) {
+ types[j] = orig_types[j];
+ }
+
+ NPY_UF_DBG_PRINT1("Trying function loop %d\n", (int)i);
+ switch (ufunc_loop_matches(self, op,
+ input_casting, output_casting,
+ any_object, all_inputs_scalar,
+ types,
+ &no_castable_output, &err_src_typecode,
+ &err_dst_typecode)) {
+ /* Error */
+ case -1:
+ return -1;
+ /* Found a match */
+ case 1:
+ set_ufunc_loop_data_types(self, op, out_dtype, types,
+ buffersize, out_trivial_loop_ok);
- /* wrap outputs */
- for (i = 0; i < loop->ufunc->nout; i++) {
- int j = loop->ufunc->nin+i;
- PyObject *wrap;
- PyObject *res;
- wrap = wraparr[i];
- if (wrap != NULL) {
- if (wrap == Py_None) {
- Py_DECREF(wrap);
- continue;
- }
- res = PyObject_CallFunction(wrap, "O(OOi)",
- mps[j], loop->ufunc, args, i);
- Py_DECREF(wrap);
- if ((res == NULL) || (res == Py_None)) {
- if (!PyErr_Occurred()){
- PyErr_SetString(PyExc_TypeError,
- "__array_prepare__ must return an ndarray or subclass thereof");
- }
+ /* Save the inner loop and its data */
+ *out_innerloop = self->functions[i];
+ *out_innerloopdata = self->data[i];
+
+ NPY_UF_DBG_PRINT("Returning inner loop successfully\n");
+
+ return 0;
+ }
+
+ }
+
+ /* If no function was found, throw an error */
+ NPY_UF_DBG_PRINT("No loop was found\n");
+ if (no_castable_output) {
+ PyErr_Format(PyExc_TypeError,
+ "ufunc '%s' output (typecode '%c') could not be coerced to "
+ "provided output parameter (typecode '%c') according "
+ "to the casting rule '%s'",
+ ufunc_name, err_src_typecode, err_dst_typecode,
+ _casting_to_string(output_casting));
+ }
+ else {
+ /*
+ * TODO: We should try again if the casting rule is same_kind
+ * or unsafe, and look for a function more liberally.
+ */
+ PyErr_Format(PyExc_TypeError,
+ "ufunc '%s' not supported for the input types, and the "
+ "inputs could not be safely coerced to any supported "
+ "types according to the casting rule '%s'",
+ ufunc_name,
+ _casting_to_string(input_casting));
+ }
+
+ return -1;
+}
+
+/*
+ * Does a linear search for the inner loop of the ufunc specified by type_tup.
+ * When op[i] is a scalar or a one dimensional array smaller than
+ * the buffersize, and needs a dtype conversion, this function
+ * may substitute op[i] with a version cast to the correct type. This way,
+ * the later trivial loop detection has a higher chance of being triggered.
+ *
+ * Note that if an error is returned, the caller must free the non-zero
+ * references in out_dtype. This function does not do its own clean-up.
+ */
+static int
+find_specified_ufunc_inner_loop(PyUFuncObject *self,
+ PyObject *type_tup,
+ PyArrayObject **op,
+ NPY_CASTING casting,
+ npy_intp buffersize,
+ int any_object,
+ PyArray_Descr **out_dtype,
+ PyUFuncGenericFunction *out_innerloop,
+ void **out_innerloopdata,
+ int *out_trivial_loop_ok)
+{
+ npy_intp i, j, n, nin = self->nin, niter = nin + self->nout;
+ int n_specified = 0;
+ int specified_types[NPY_MAXARGS], types[NPY_MAXARGS];
+ char *ufunc_name;
+ int no_castable_output, all_inputs_scalar;
+
+ /* For making a better error message on coercion error */
+ char err_dst_typecode = '-', err_src_typecode = '-';
+
+ ufunc_name = self->name ? self->name : "(unknown)";
+
+ /* Check whether all the inputs are scalar */
+ all_inputs_scalar = 1;
+ for(i = 0; i < nin; ++i) {
+ if (PyArray_NDIM(op[i]) > 0) {
+ all_inputs_scalar = 0;
+ }
+ }
+
+ /* Fill in specified_types from the tuple or string */
+ if (PyTuple_Check(type_tup)) {
+ n = PyTuple_GET_SIZE(type_tup);
+ if (n != 1 && n != niter) {
+ PyErr_Format(PyExc_ValueError,
+ "a type-tuple must be specified " \
+ "of length 1 or %d for ufunc '%s'", (int)niter,
+ self->name ? self->name : "(unknown)");
+ return -1;
+ }
+
+ for (i = 0; i < n; ++i) {
+ PyArray_Descr *dtype = NULL;
+ if (!PyArray_DescrConverter(PyTuple_GET_ITEM(type_tup, i),
+ &dtype)) {
return -1;
}
- Py_DECREF(mps[j]);
- mps[j] = (PyArrayObject *)res;
+ specified_types[i] = dtype->type_num;
+ Py_DECREF(dtype);
}
- }
- /*
- * If any of different type, or misaligned or swapped
- * then must use buffers
- */
- loop->bufcnt = 0;
- loop->obj = 0;
- /* Determine looping method needed */
- loop->meth = NO_UFUNCLOOP;
- if (loop->size == 0) {
- return nargs;
+ n_specified = n;
}
- if (self->core_enabled) {
- loop->meth = SIGNATURE_NOBUFFER_UFUNCLOOP;
- }
- for (i = 0; i < self->nargs; i++) {
- loop->needbuffer[i] = 0;
- if (arg_types[i] != mps[i]->descr->type_num
- || !PyArray_ISBEHAVED_RO(mps[i])) {
- if (self->core_enabled) {
- PyErr_SetString(PyExc_RuntimeError,
- "never reached; copy should have been made");
+ else if (PyBytes_Check(type_tup) || PyUnicode_Check(type_tup)) {
+ Py_ssize_t length;
+ char *str;
+ PyObject *str_obj = NULL;
+
+ if (PyUnicode_Check(type_tup)) {
+ str_obj = PyUnicode_AsASCIIString(type_tup);
+ if (str_obj == NULL) {
return -1;
}
- loop->meth = BUFFER_UFUNCLOOP;
- loop->needbuffer[i] = 1;
+ type_tup = str_obj;
}
- if (!(loop->obj & UFUNC_OBJ_ISOBJECT)
- && ((mps[i]->descr->type_num == PyArray_OBJECT)
- || (arg_types[i] == PyArray_OBJECT))) {
- loop->obj = UFUNC_OBJ_ISOBJECT|UFUNC_OBJ_NEEDS_API;
+
+ if (!PyBytes_AsStringAndSize(type_tup, &str, &length) < 0) {
+ Py_XDECREF(str_obj);
+ return -1;
}
- if (!(loop->obj & UFUNC_OBJ_NEEDS_API)
- && ((mps[i]->descr->type_num == PyArray_DATETIME)
- || (mps[i]->descr->type_num == PyArray_TIMEDELTA)
- || (arg_types[i] == PyArray_DATETIME)
- || (arg_types[i] == PyArray_TIMEDELTA))) {
- loop->obj = UFUNC_OBJ_NEEDS_API;
+ if (length != 1 && (length != niter + 2 ||
+ str[nin] != '-' || str[nin+1] != '>')) {
+ PyErr_Format(PyExc_ValueError,
+ "a type-string for %s, " \
+ "requires 1 typecode, or "
+ "%d typecode(s) before " \
+ "and %d after the -> sign",
+ self->name ? self->name : "(unknown)",
+ self->nin, self->nout);
+ Py_XDECREF(str_obj);
+ return -1;
}
+ if (length == 1) {
+ PyArray_Descr *dtype;
+ n_specified = 1;
+ dtype = PyArray_DescrFromType(str[0]);
+ if (dtype == NULL) {
+ Py_XDECREF(str_obj);
+ return -1;
+ }
+ NPY_UF_DBG_PRINT2("signature character '%c', type num %d\n",
+ str[0], dtype->type_num);
+ specified_types[0] = dtype->type_num;
+ Py_DECREF(dtype);
+ }
+ else {
+ PyArray_Descr *dtype;
+ n_specified = (int)niter;
+
+ for (i = 0; i < niter; ++i) {
+ npy_intp istr = i < nin ? i : i+2;
+
+ dtype = PyArray_DescrFromType(str[istr]);
+ if (dtype == NULL) {
+ Py_XDECREF(str_obj);
+ return -1;
+ }
+ NPY_UF_DBG_PRINT2("signature character '%c', type num %d\n",
+ str[istr], dtype->type_num);
+ specified_types[i] = dtype->type_num;
+ Py_DECREF(dtype);
+ }
+ }
+ Py_XDECREF(str_obj);
}
- if (self->core_enabled && (loop->obj & UFUNC_OBJ_ISOBJECT)) {
- PyErr_SetString(PyExc_TypeError,
- "Object type not allowed in ufunc with signature");
- return -1;
+ /* If the ufunc has userloops, search for them. */
+ if (self->userloops) {
+ NPY_UF_DBG_PRINT("Searching user loops for specified sig\n");
+ switch (find_ufunc_specified_userloop(self,
+ n_specified, specified_types,
+ op, casting,
+ buffersize, any_object, all_inputs_scalar,
+ out_dtype, out_innerloop, out_innerloopdata,
+ out_trivial_loop_ok)) {
+ /* Error */
+ case -1:
+ return -1;
+ /* Found matching loop */
+ case 1:
+ return 0;
+ }
}
- if (loop->meth == NO_UFUNCLOOP) {
- loop->meth = ONE_UFUNCLOOP;
- /* All correct type and BEHAVED */
- /* Check for non-uniform stridedness */
- for (i = 0; i < self->nargs; i++) {
- if (!(loop->iters[i]->contiguous)) {
- /*
- * May still have uniform stride
- * if (broadcast result) <= 1-d
- */
- if (mps[i]->nd != 0 && \
- (loop->iters[i]->nd_m1 > 0)) {
- loop->meth = NOBUFFER_UFUNCLOOP;
+ NPY_UF_DBG_PRINT("Searching loops for specified sig\n");
+ for (i = 0; i < self->ntypes; ++i) {
+ char *orig_types = self->types + i*self->nargs;
+ int matched = 1;
+
+ NPY_UF_DBG_PRINT1("Trying function loop %d\n", (int)i);
+
+ /* Copy the types into an int array for matching */
+ for (j = 0; j < niter; ++j) {
+ types[j] = orig_types[j];
+ }
+
+ if (n_specified == niter) {
+ for (j = 0; j < niter; ++j) {
+ if (types[j] != specified_types[j]) {
+ matched = 0;
break;
}
}
- }
- if (loop->meth == ONE_UFUNCLOOP) {
- for (i = 0; i < self->nargs; i++) {
- loop->bufptr[i] = mps[i]->data;
+ } else {
+ NPY_UF_DBG_PRINT2("Specified type: %d, first output type: %d\n",
+ specified_types[0], types[nin]);
+ if (types[nin] != specified_types[0]) {
+ matched = 0;
}
}
+ if (!matched) {
+ continue;
+ }
+
+ NPY_UF_DBG_PRINT("It matches, confirming type casting\n");
+ switch (ufunc_loop_matches(self, op,
+ casting, casting,
+ any_object, all_inputs_scalar,
+ types,
+ &no_castable_output, &err_src_typecode,
+ &err_dst_typecode)) {
+ /* Error */
+ case -1:
+ return -1;
+ /* It worked */
+ case 1:
+ set_ufunc_loop_data_types(self, op, out_dtype, types,
+ buffersize, out_trivial_loop_ok);
+
+ /* Save the inner loop and its data */
+ *out_innerloop = self->functions[i];
+ *out_innerloopdata = self->data[i];
+
+ NPY_UF_DBG_PRINT("Returning specified inner loop successfully\n");
+
+ return 0;
+ /* Didn't work */
+ case 0:
+ PyErr_Format(PyExc_TypeError,
+ "found a loop for ufunc '%s' "
+ "matching the type-tuple, "
+ "but the inputs and/or outputs could not be "
+ "cast according to the casting rule",
+ ufunc_name);
+ return -1;
+ }
+
}
- loop->numiter = self->nargs;
+ /* If no function was found, throw an error */
+ NPY_UF_DBG_PRINT("No specified loop was found\n");
+
+ PyErr_Format(PyExc_TypeError,
+ "No loop matching the specified signature was found "
+ "for ufunc %s", ufunc_name);
+
+ return -1;
+}
+
+static void
+trivial_two_operand_loop(PyArrayObject **op,
+ PyUFuncGenericFunction innerloop,
+ void *innerloopdata)
+{
+ char *data[2];
+ npy_intp count[2], stride[2];
+ int needs_api;
+ NPY_BEGIN_THREADS_DEF;
+
+ needs_api = PyDataType_REFCHK(PyArray_DESCR(op[0])) ||
+ PyDataType_REFCHK(PyArray_DESCR(op[1]));
+
+ PyArray_PREPARE_TRIVIAL_PAIR_ITERATION(op[0], op[1],
+ count[0],
+ data[0], data[1],
+ stride[0], stride[1]);
+ count[1] = count[0];
+ NPY_UF_DBG_PRINT1("two operand loop count %d\n", (int)count[0]);
- /* Fill in steps */
- if (loop->meth == SIGNATURE_NOBUFFER_UFUNCLOOP && loop->nd == 0) {
- /* Use default core_strides */
+ if (!needs_api) {
+ NPY_BEGIN_THREADS;
}
- else if (loop->meth != ONE_UFUNCLOOP) {
- int ldim;
- intp minsum;
- intp maxdim;
- PyArrayIterObject *it;
- intp stride_sum[NPY_MAXDIMS];
- int j;
- /* Fix iterators */
+ innerloop(data, count, stride, innerloopdata);
- /*
- * Optimize axis the iteration takes place over
- *
- * The first thought was to have the loop go
- * over the largest dimension to minimize the number of loops
- *
- * However, on processors with slow memory bus and cache,
- * the slowest loops occur when the memory access occurs for
- * large strides.
- *
- * Thus, choose the axis for which strides of the last iterator is
- * smallest but non-zero.
- */
- for (i = 0; i < loop->nd; i++) {
- stride_sum[i] = 0;
- for (j = 0; j < loop->numiter; j++) {
- stride_sum[i] += loop->iters[j]->strides[i];
+ if (!needs_api) {
+ NPY_END_THREADS;
+ }
+}
+
+static void
+trivial_three_operand_loop(PyArrayObject **op,
+ PyUFuncGenericFunction innerloop,
+ void *innerloopdata)
+{
+ char *data[3];
+ npy_intp count[3], stride[3];
+ int needs_api;
+ NPY_BEGIN_THREADS_DEF;
+
+ needs_api = PyDataType_REFCHK(PyArray_DESCR(op[0])) ||
+ PyDataType_REFCHK(PyArray_DESCR(op[1])) ||
+ PyDataType_REFCHK(PyArray_DESCR(op[2]));
+
+ PyArray_PREPARE_TRIVIAL_TRIPLE_ITERATION(op[0], op[1], op[2],
+ count[0],
+ data[0], data[1], data[2],
+ stride[0], stride[1], stride[2]);
+ count[1] = count[0];
+ count[2] = count[0];
+ NPY_UF_DBG_PRINT1("three operand loop count %d\n", (int)count[0]);
+
+ if (!needs_api) {
+ NPY_BEGIN_THREADS;
+ }
+
+ innerloop(data, count, stride, innerloopdata);
+
+ if (!needs_api) {
+ NPY_END_THREADS;
+ }
+}
+
+/*
+ * Calls the given __array_prepare__ function on the operand *op,
+ * substituting it in place if a new array is returned and matches
+ * the old one.
+ *
+ * This requires that the dimensions, strides and data type remain
+ * exactly the same, which may be more strict than before.
+ */
+static int
+prepare_ufunc_output(PyUFuncObject *self,
+ PyArrayObject **op,
+ PyObject *arr_prep,
+ PyObject *arr_prep_args,
+ int i)
+{
+ if (arr_prep != NULL && arr_prep != Py_None) {
+ PyObject *res;
+
+ res = PyObject_CallFunction(arr_prep, "O(OOi)",
+ *op, self, arr_prep_args, i);
+ if ((res == NULL) || (res == Py_None) || !PyArray_Check(res)) {
+ if (!PyErr_Occurred()){
+ PyErr_SetString(PyExc_TypeError,
+ "__array_prepare__ must return an "
+ "ndarray or subclass thereof");
}
+ Py_XDECREF(res);
+ return -1;
}
- ldim = loop->nd - 1;
- minsum = stride_sum[loop->nd - 1];
- for (i = loop->nd - 2; i >= 0; i--) {
- if (stride_sum[i] < minsum ) {
- ldim = i;
- minsum = stride_sum[i];
- }
+ /* If the same object was returned, nothing to do */
+ if (res == (PyObject *)*op) {
+ Py_DECREF(res);
}
- maxdim = loop->dimensions[ldim];
- loop->size /= maxdim;
- loop->bufcnt = maxdim;
- loop->lastdim = ldim;
+ /* If the result doesn't match, throw an error */
+ else if (PyArray_NDIM(res) != PyArray_NDIM(*op) ||
+ !PyArray_CompareLists(PyArray_DIMS(res),
+ PyArray_DIMS(*op),
+ PyArray_NDIM(res)) ||
+ !PyArray_CompareLists(PyArray_STRIDES(res),
+ PyArray_STRIDES(*op),
+ PyArray_NDIM(res)) ||
+ !PyArray_EquivTypes(PyArray_DESCR(res),
+ PyArray_DESCR(*op))) {
+ PyErr_SetString(PyExc_TypeError,
+ "__array_prepare__ must return an "
+ "ndarray or subclass thereof which is "
+ "otherwise identical to its input");
+ Py_DECREF(res);
+ return -1;
+ }
+ /* Replace the op value */
+ else {
+ Py_DECREF(*op);
+ *op = (PyArrayObject *)res;
+ }
+ }
- /*
- * Fix the iterators so the inner loop occurs over the
- * largest dimensions -- This can be done by
- * setting the size to 1 in that dimension
- * (just in the iterators)
- */
- for (i = 0; i < loop->numiter; i++) {
- it = loop->iters[i];
- it->contiguous = 0;
- it->size /= (it->dims_m1[ldim] + 1);
- it->dims_m1[ldim] = 0;
- it->backstrides[ldim] = 0;
+ return 0;
+}
- /*
- * (won't fix factors because we
- * don't use PyArray_ITER_GOTO1D
- * so don't change them)
- *
- * Set the steps to the strides in that dimension
- */
- loop->steps[i] = it->strides[ldim];
- }
+static int
+iterator_loop(PyUFuncObject *self,
+ PyArrayObject **op,
+ PyArray_Descr **dtype,
+ NPY_ORDER order,
+ npy_intp buffersize,
+ PyObject **arr_prep,
+ PyObject *arr_prep_args,
+ PyUFuncGenericFunction innerloop,
+ void *innerloopdata)
+{
+ npy_intp i, nin = self->nin, nout = self->nout;
+ npy_intp niter = nin + nout;
+ npy_uint32 op_flags[NPY_MAXARGS];
+ NpyIter *iter;
+ char *baseptrs[NPY_MAXARGS];
+ int needs_api;
- /*
- * Set looping part of core_dim_sizes and core_strides.
- */
- if (loop->meth == SIGNATURE_NOBUFFER_UFUNCLOOP) {
- loop->core_dim_sizes[0] = maxdim;
- for (i = 0; i < self->nargs; i++) {
- loop->core_strides[i] = loop->steps[i];
- }
+ NpyIter_IterNextFunc *iternext;
+ char **dataptr;
+ npy_intp *stride;
+ npy_intp *count_ptr;
+
+ PyArrayObject **op_it;
+
+ NPY_BEGIN_THREADS_DEF;
+
+ /* Set up the flags */
+ for (i = 0; i < nin; ++i) {
+ op_flags[i] = NPY_ITER_READONLY|
+ NPY_ITER_ALIGNED;
+ }
+ for (i = nin; i < niter; ++i) {
+ op_flags[i] = NPY_ITER_WRITEONLY|
+ NPY_ITER_ALIGNED|
+ NPY_ITER_ALLOCATE|
+ NPY_ITER_NO_BROADCAST|
+ NPY_ITER_NO_SUBTYPE;
+ }
+
+ /*
+ * Allocate the iterator. Because the types of the inputs
+ * were already checked, we use the casting rule 'unsafe' which
+ * is faster to calculate.
+ */
+ iter = NpyIter_MultiNew(niter, op,
+ NPY_ITER_NO_INNER_ITERATION|
+ NPY_ITER_REFS_OK|
+ NPY_ITER_ZEROSIZE_OK|
+ NPY_ITER_BUFFERED|
+ NPY_ITER_GROWINNER|
+ NPY_ITER_DELAY_BUFALLOC,
+ order, NPY_UNSAFE_CASTING,
+ op_flags, dtype,
+ 0, NULL, buffersize);
+ if (iter == NULL) {
+ return -1;
+ }
+
+ needs_api = NpyIter_IterationNeedsAPI(iter);
+
+ /* Copy any allocated outputs */
+ op_it = NpyIter_GetOperandArray(iter);
+ for (i = nin; i < niter; ++i) {
+ if (op[i] == NULL) {
+ op[i] = op_it[i];
+ Py_INCREF(op[i]);
}
+ }
- /*
- * fix up steps where we will be copying data to
- * buffers and calculate the ninnerloops and leftover
- * values -- if step size is already zero that is not changed...
- */
- if (loop->meth == BUFFER_UFUNCLOOP) {
- loop->leftover = maxdim % loop->bufsize;
- loop->ninnerloops = (maxdim / loop->bufsize) + 1;
- for (i = 0; i < self->nargs; i++) {
- if (loop->needbuffer[i] && loop->steps[i]) {
- loop->steps[i] = mps[i]->descr->elsize;
- }
- /* These are changed later if casting is needed */
- }
+ /* Call the __array_prepare__ functions where necessary */
+ for (i = 0; i < nout; ++i) {
+ if (prepare_ufunc_output(self, &op[nin+i],
+ arr_prep[i], arr_prep_args, i) < 0) {
+ NpyIter_Deallocate(iter);
+ return -1;
}
}
- else if (loop->meth == ONE_UFUNCLOOP) {
- /* uniformly-strided case */
- for (i = 0; i < self->nargs; i++) {
- if (PyArray_SIZE(mps[i]) == 1) {
- loop->steps[i] = 0;
- }
- else {
- loop->steps[i] = mps[i]->strides[mps[i]->nd - 1];
- }
+
+ /* Only do the loop if the iteration size is non-zero */
+ if (NpyIter_GetIterSize(iter) != 0) {
+
+ /* Reset the iterator with the base pointers from the wrapped outputs */
+ for (i = 0; i < nin; ++i) {
+ baseptrs[i] = PyArray_BYTES(op_it[i]);
+ }
+ for (i = nin; i < niter; ++i) {
+ baseptrs[i] = PyArray_BYTES(op[i]);
+ }
+ if (NpyIter_ResetBasePointers(iter, baseptrs, NULL) != NPY_SUCCEED) {
+ NpyIter_Deallocate(iter);
+ return -1;
+ }
+
+ /* Get the variables needed for the loop */
+ iternext = NpyIter_GetIterNext(iter, NULL);
+ if (iternext == NULL) {
+ NpyIter_Deallocate(iter);
+ return -1;
+ }
+ dataptr = NpyIter_GetDataPtrArray(iter);
+ stride = NpyIter_GetInnerStrideArray(iter);
+ count_ptr = NpyIter_GetInnerLoopSizePtr(iter);
+
+ if (!needs_api) {
+ NPY_BEGIN_THREADS;
+ }
+
+ /* Execute the loop */
+ do {
+ NPY_UF_DBG_PRINT1("iterator loop count %d\n", (int)*count_ptr);
+ innerloop(dataptr, count_ptr, stride, innerloopdata);
+ } while (iternext(iter));
+
+ if (!needs_api) {
+ NPY_END_THREADS;
}
}
+ NpyIter_Deallocate(iter);
+ return 0;
+}
+
+/*
+ * trivial_loop_ok - 1 if no alignment, data conversion, etc required
+ * nin - number of inputs
+ * nout - number of outputs
+ * op - the operands (nin + nout of them)
+ * order - the loop execution order/output memory order
+ * buffersize - how big of a buffer to use
+ * arr_prep - the __array_prepare__ functions for the outputs
+ * innerloop - the inner loop function
+ * innerloopdata - data to pass to the inner loop
+ */
+static int
+execute_ufunc_loop(PyUFuncObject *self,
+ int trivial_loop_ok,
+ PyArrayObject **op,
+ PyArray_Descr **dtype,
+ NPY_ORDER order,
+ npy_intp buffersize,
+ PyObject **arr_prep,
+ PyObject *arr_prep_args,
+ PyUFuncGenericFunction innerloop,
+ void *innerloopdata)
+{
+ npy_intp nin = self->nin, nout = self->nout;
+
+ /* First check for the trivial cases that don't need an iterator */
+ if (trivial_loop_ok) {
+ if (nin == 1 && nout == 1) {
+ if (op[1] == NULL &&
+ (order == NPY_ANYORDER || order == NPY_KEEPORDER) &&
+ PyArray_TRIVIALLY_ITERABLE(op[0])) {
+ Py_INCREF(dtype[1]);
+ op[1] = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type,
+ dtype[1],
+ PyArray_NDIM(op[0]),
+ PyArray_DIMS(op[0]),
+ NULL, NULL,
+ PyArray_ISFORTRAN(op[0]) ? NPY_F_CONTIGUOUS : 0,
+ NULL);
+
+ /* Call the __prepare_array__ if necessary */
+ if (prepare_ufunc_output(self, &op[1],
+ arr_prep[0], arr_prep_args, 0) < 0) {
+ return -1;
+ }
- /* Finally, create memory for buffers if we need them */
+ NPY_UF_DBG_PRINT("trivial 1 input with allocated output\n");
+ trivial_two_operand_loop(op, innerloop, innerloopdata);
- /*
- * Buffers for scalars are specially made small -- scalars are
- * not copied multiple times
- */
- if (loop->meth == BUFFER_UFUNCLOOP) {
- int cnt = 0, cntcast = 0;
- int scnt = 0, scntcast = 0;
- char *castptr;
- char *bufptr;
- int last_was_scalar = 0;
- int last_cast_was_scalar = 0;
- int oldbufsize = 0;
- int oldsize = 0;
- int scbufsize = 4*sizeof(double);
- int memsize;
- PyArray_Descr *descr;
-
- /* compute the element size */
- for (i = 0; i < self->nargs; i++) {
- if (!loop->needbuffer[i]) {
- continue;
+ return 0;
}
- if (arg_types[i] != mps[i]->descr->type_num) {
- descr = PyArray_DescrFromType(arg_types[i]);
- if (loop->steps[i]) {
- cntcast += descr->elsize;
- }
- else {
- scntcast += descr->elsize;
+ else if (op[1] != NULL &&
+ PyArray_NDIM(op[1]) >= PyArray_NDIM(op[0]) &&
+ PyArray_TRIVIALLY_ITERABLE_PAIR(op[0], op[1])) {
+
+ /* Call the __prepare_array__ if necessary */
+ if (prepare_ufunc_output(self, &op[1],
+ arr_prep[0], arr_prep_args, 0) < 0) {
+ return -1;
}
- if (i < self->nin) {
- loop->cast[i] = PyArray_GetCastFunc(mps[i]->descr,
- arg_types[i]);
+
+ NPY_UF_DBG_PRINT("trivial 1 input\n");
+ trivial_two_operand_loop(op, innerloop, innerloopdata);
+
+ return 0;
+ }
+ }
+ else if (nin == 2 && nout == 1) {
+ if (op[2] == NULL &&
+ (order == NPY_ANYORDER || order == NPY_KEEPORDER) &&
+ PyArray_TRIVIALLY_ITERABLE_PAIR(op[0], op[1])) {
+ PyArrayObject *tmp;
+ /*
+ * Have to choose the input with more dimensions to clone, as
+ * one of them could be a scalar.
+ */
+ if (PyArray_NDIM(op[0]) >= PyArray_NDIM(op[1])) {
+ tmp = op[0];
}
else {
- loop->cast[i] = PyArray_GetCastFunc \
- (descr, mps[i]->descr->type_num);
+ tmp = op[1];
}
- Py_DECREF(descr);
- if (!loop->cast[i]) {
+ Py_INCREF(dtype[2]);
+ op[2] = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type,
+ dtype[2],
+ PyArray_NDIM(tmp),
+ PyArray_DIMS(tmp),
+ NULL, NULL,
+ PyArray_ISFORTRAN(tmp) ? NPY_F_CONTIGUOUS : 0,
+ NULL);
+
+ /* Call the __prepare_array__ if necessary */
+ if (prepare_ufunc_output(self, &op[2],
+ arr_prep[0], arr_prep_args, 0) < 0) {
return -1;
}
- }
- loop->swap[i] = !(PyArray_ISNOTSWAPPED(mps[i]));
- if (loop->steps[i]) {
- cnt += mps[i]->descr->elsize;
- }
- else {
- scnt += mps[i]->descr->elsize;
- }
- }
- memsize = loop->bufsize*(cnt+cntcast) + scbufsize*(scnt+scntcast);
- loop->buffer[0] = PyDataMem_NEW(memsize);
- /*
- * debug
- * fprintf(stderr, "Allocated buffer at %p of size %d, cnt=%d, cntcast=%d\n",
- * loop->buffer[0], loop->bufsize * (cnt + cntcast), cnt, cntcast);
- */
- if (loop->buffer[0] == NULL) {
- PyErr_NoMemory();
- return -1;
- }
- if (loop->obj & UFUNC_OBJ_ISOBJECT) {
- memset(loop->buffer[0], 0, memsize);
- }
- castptr = loop->buffer[0] + loop->bufsize*cnt + scbufsize*scnt;
- bufptr = loop->buffer[0];
- loop->objfunc = 0;
- for (i = 0; i < self->nargs; i++) {
- if (!loop->needbuffer[i]) {
- continue;
- }
- loop->buffer[i] = bufptr + (last_was_scalar ? scbufsize :
- loop->bufsize)*oldbufsize;
- last_was_scalar = (loop->steps[i] == 0);
- bufptr = loop->buffer[i];
- oldbufsize = mps[i]->descr->elsize;
- /* fprintf(stderr, "buffer[%d] = %p\n", i, loop->buffer[i]); */
- if (loop->cast[i]) {
- PyArray_Descr *descr;
- loop->castbuf[i] = castptr + (last_cast_was_scalar ? scbufsize :
- loop->bufsize)*oldsize;
- last_cast_was_scalar = last_was_scalar;
- /* fprintf(stderr, "castbuf[%d] = %p\n", i, loop->castbuf[i]); */
- descr = PyArray_DescrFromType(arg_types[i]);
- oldsize = descr->elsize;
- Py_DECREF(descr);
- loop->bufptr[i] = loop->castbuf[i];
- castptr = loop->castbuf[i];
- if (loop->steps[i]) {
- loop->steps[i] = oldsize;
- }
- }
- else {
- loop->bufptr[i] = loop->buffer[i];
+ NPY_UF_DBG_PRINT("trivial 2 input with allocated output\n");
+ trivial_three_operand_loop(op, innerloop, innerloopdata);
+
+ return 0;
}
- if (!loop->objfunc && (loop->obj & UFUNC_OBJ_ISOBJECT)) {
- if (arg_types[i] == PyArray_OBJECT) {
- loop->objfunc = 1;
+ else if (op[2] != NULL &&
+ PyArray_NDIM(op[2]) >= PyArray_NDIM(op[0]) &&
+ PyArray_NDIM(op[2]) >= PyArray_NDIM(op[1]) &&
+ PyArray_TRIVIALLY_ITERABLE_TRIPLE(op[0], op[1], op[2])) {
+
+ /* Call the __prepare_array__ if necessary */
+ if (prepare_ufunc_output(self, &op[2],
+ arr_prep[0], arr_prep_args, 0) < 0) {
+ return -1;
}
+
+ NPY_UF_DBG_PRINT("trivial 2 input\n");
+ trivial_three_operand_loop(op, innerloop, innerloopdata);
+
+ return 0;
}
}
}
- if (_does_loop_use_arrays(loop->funcdata)) {
- loop->funcdata = (void*)mps;
- }
-
- return nargs;
-}
+ /*
+ * If no trivial loop matched, an iterator is required to
+ * resolve broadcasting, etc
+ */
-static void
-ufuncreduce_dealloc(PyUFuncReduceObject *self)
-{
- if (self->ufunc) {
- Py_XDECREF(self->it);
- Py_XDECREF(self->rit);
- Py_XDECREF(self->ret);
- Py_XDECREF(self->errobj);
- Py_XDECREF(self->decref);
- if (self->buffer) {
- PyDataMem_FREE(self->buffer);
- }
- Py_DECREF(self->ufunc);
+ NPY_UF_DBG_PRINT("iterator loop\n");
+ if (iterator_loop(self, op, dtype, order,
+ buffersize, arr_prep, arr_prep_args,
+ innerloop, innerloopdata) < 0) {
+ return -1;
}
- _pya_free(self);
+
+ return 0;
}
-static void
-ufuncloop_dealloc(PyUFuncLoopObject *self)
+static PyObject *
+make_arr_prep_args(npy_intp nin, PyObject *args, PyObject *kwds)
{
- int i;
+ PyObject *out = kwds ? PyDict_GetItemString(kwds, "out") : NULL;
+ PyObject *arr_prep_args;
- if (self->ufunc != NULL) {
- if (self->core_dim_sizes) {
- _pya_free(self->core_dim_sizes);
+ if (out == NULL) {
+ Py_INCREF(args);
+ return args;
+ }
+ else {
+ npy_intp i, nargs = PyTuple_GET_SIZE(args), n;
+ n = nargs;
+ if (n < nin + 1) {
+ n = nin + 1;
}
- if (self->core_strides) {
- _pya_free(self->core_strides);
+ arr_prep_args = PyTuple_New(n);
+ if (arr_prep_args == NULL) {
+ return NULL;
}
- for (i = 0; i < self->ufunc->nargs; i++) {
- Py_XDECREF(self->iters[i]);
+ /* Copy the tuple, but set the nin-th item to the keyword arg */
+ for (i = 0; i < nin; ++i) {
+ PyObject *item = PyTuple_GET_ITEM(args, i);
+ Py_INCREF(item);
+ PyTuple_SET_ITEM(arr_prep_args, i, item);
}
- if (self->buffer[0]) {
- PyDataMem_FREE(self->buffer[0]);
+ Py_INCREF(out);
+ PyTuple_SET_ITEM(arr_prep_args, nin, out);
+ for (i = nin+1; i < n; ++i) {
+ PyObject *item = PyTuple_GET_ITEM(args, i);
+ Py_INCREF(item);
+ PyTuple_SET_ITEM(arr_prep_args, i, item);
}
- Py_XDECREF(self->errobj);
- Py_DECREF(self->ufunc);
+
+ return arr_prep_args;
}
- _pya_free(self);
}
-static PyUFuncLoopObject *
-construct_loop(PyUFuncObject *self, PyObject *args, PyObject *kwds, PyArrayObject **mps)
+static int
+PyUFunc_GeneralizedFunction(PyUFuncObject *self,
+ PyObject *args, PyObject *kwds,
+ PyArrayObject **op)
{
- PyUFuncLoopObject *loop;
- int i;
- PyObject *typetup = NULL;
- PyObject *extobj = NULL;
- char *name;
+ int nin, nout;
+ int i, idim, niter;
+ char *ufunc_name;
+ int retval = -1, any_object = 0;
+ NPY_CASTING input_casting;
+
+ PyArray_Descr *dtype[NPY_MAXARGS];
+
+ /* Use remapped axes for generalized ufunc */
+ int broadcast_ndim, op_ndim;
+ int op_axes_arrays[NPY_MAXARGS][NPY_MAXDIMS];
+ int *op_axes[NPY_MAXARGS];
+
+ npy_uint32 op_flags[NPY_MAXARGS];
+
+ NpyIter *iter = NULL;
+
+ /* These parameters come from extobj= or from a TLS global */
+ int buffersize = 0, errormask = 0;
+ PyObject *errobj = NULL;
+ int first_error = 1;
+
+ /* The selected inner loop */
+ PyUFuncGenericFunction innerloop = NULL;
+ void *innerloopdata = NULL;
+ /* The dimensions which get passed to the inner loop */
+ npy_intp inner_dimensions[NPY_MAXDIMS+1];
+ /* The strides which get passed to the inner loop */
+ npy_intp *inner_strides = NULL;
+
+ npy_intp *inner_strides_tmp, *ax_strides_tmp[NPY_MAXDIMS];
+ int core_dim_ixs_size, *core_dim_ixs;
+
+ /* The __array_prepare__ function to call for each output */
+ PyObject *arr_prep[NPY_MAXARGS];
+ /*
+ * This is either args, or args with the out= parameter from
+ * kwds added appropriately.
+ */
+ PyObject *arr_prep_args = NULL;
+
+ int trivial_loop_ok = 0;
+
+ /* TODO: For 1.6, the default should probably be NPY_CORDER */
+ NPY_ORDER order = NPY_KEEPORDER;
+ /*
+ * Many things in NumPy do unsafe casting (doing int += float, etc).
+ * The strictness should probably become a state parameter, similar
+ * to the seterr/geterr.
+ */
+ NPY_CASTING casting = NPY_UNSAFE_CASTING;
+ /* When provided, extobj and typetup contain borrowed references */
+ PyObject *extobj = NULL, *type_tup = NULL;
if (self == NULL) {
PyErr_SetString(PyExc_ValueError, "function not supported");
- return NULL;
+ return -1;
}
- if ((loop = _pya_malloc(sizeof(PyUFuncLoopObject))) == NULL) {
- PyErr_NoMemory();
- return loop;
+
+ nin = self->nin;
+ nout = self->nout;
+ niter = nin + nout;
+
+ ufunc_name = self->name ? self->name : "<unnamed ufunc>";
+
+ NPY_UF_DBG_PRINT1("\nEvaluating ufunc %s\n", ufunc_name);
+
+ /* Initialize all the operands and dtypes to NULL */
+ for (i = 0; i < niter; ++i) {
+ op[i] = NULL;
+ dtype[i] = NULL;
+ arr_prep[i] = NULL;
}
- loop->index = 0;
- loop->ufunc = self;
- Py_INCREF(self);
- loop->buffer[0] = NULL;
- for (i = 0; i < self->nargs; i++) {
- loop->iters[i] = NULL;
- loop->cast[i] = NULL;
+ NPY_UF_DBG_PRINT("Getting arguments\n");
+
+ /* Get all the arguments */
+ retval = get_ufunc_arguments(self, args, kwds,
+ op, &order, &casting, &extobj, &type_tup, &any_object);
+ if (retval < 0) {
+ goto fail;
}
- loop->errobj = NULL;
- loop->notimplemented = 0;
- loop->first = 1;
- loop->core_dim_sizes = NULL;
- loop->core_strides = NULL;
- if (self->core_enabled) {
- int num_dim_ix = 1 + self->core_num_dim_ix;
- int nstrides = self->nargs + self->core_offsets[self->nargs - 1]
- + self->core_num_dims[self->nargs - 1];
- loop->core_dim_sizes = _pya_malloc(sizeof(npy_intp)*num_dim_ix);
- loop->core_strides = _pya_malloc(sizeof(npy_intp)*nstrides);
- if (loop->core_dim_sizes == NULL || loop->core_strides == NULL) {
- PyErr_NoMemory();
- goto fail;
- }
- memset(loop->core_strides, 0, sizeof(npy_intp) * nstrides);
- for (i = 0; i < num_dim_ix; i++) {
- loop->core_dim_sizes[i] = 1;
+ /* Figure out the number of dimensions needed by the iterator */
+ broadcast_ndim = 0;
+ for (i = 0; i < nin; ++i) {
+ int n = PyArray_NDIM(op[i]) - self->core_num_dims[i];
+ if (n > broadcast_ndim) {
+ broadcast_ndim = n;
}
}
- name = self->name ? self->name : "";
-
- /*
- * Extract sig= keyword and extobj= keyword if present.
- * Raise an error if anything else is present in the
- * keyword dictionary
- */
- if (kwds != NULL) {
- PyObject *key, *value;
- Py_ssize_t pos = 0;
- while (PyDict_Next(kwds, &pos, &key, &value)) {
- char *keystring = PyString_AsString(key);
+ op_ndim = broadcast_ndim + self->core_num_dim_ix;
+ if (op_ndim > NPY_MAXDIMS) {
+ PyErr_Format(PyExc_ValueError,
+ "too many dimensions for generalized ufunc %s",
+ ufunc_name);
+ retval = -1;
+ goto fail;
+ }
- if (keystring == NULL) {
- PyErr_Clear();
- PyErr_SetString(PyExc_TypeError, "invalid keyword");
- goto fail;
+ /* Fill in op_axes for all the operands */
+ core_dim_ixs_size = 0;
+ core_dim_ixs = self->core_dim_ixs;
+ for (i = 0; i < niter; ++i) {
+ int n;
+ if (op[i]) {
+ /*
+ * Note that n may be negative if broadcasting
+ * extends into the core dimensions.
+ */
+ n = PyArray_NDIM(op[i]) - self->core_num_dims[i];
+ }
+ else {
+ n = broadcast_ndim;
+ }
+ /* Broadcast all the unspecified dimensions normally */
+ for (idim = 0; idim < broadcast_ndim; ++idim) {
+ if (idim >= broadcast_ndim - n) {
+ op_axes_arrays[i][idim] = idim - (broadcast_ndim - n);
}
- if (strncmp(keystring,"extobj",6) == 0) {
- extobj = value;
+ else {
+ op_axes_arrays[i][idim] = -1;
}
- else if (strncmp(keystring,"sig",3) == 0) {
- typetup = value;
+ }
+ /* Use the signature information for the rest */
+ for (idim = broadcast_ndim; idim < op_ndim; ++idim) {
+ op_axes_arrays[i][idim] = -1;
+ }
+ for (idim = 0; idim < self->core_num_dims[i]; ++idim) {
+ if (n + idim >= 0) {
+ op_axes_arrays[i][broadcast_ndim + core_dim_ixs[idim]] =
+ n + idim;
}
else {
- char *format = "'%s' is an invalid keyword to %s";
- PyErr_Format(PyExc_TypeError,format,keystring, name);
- goto fail;
+ op_axes_arrays[i][broadcast_ndim + core_dim_ixs[idim]] = -1;
}
}
+ core_dim_ixs_size += self->core_num_dims[i];
+ core_dim_ixs += self->core_num_dims[i];
+ op_axes[i] = op_axes_arrays[i];
}
+ /* Get the buffersize, errormask, and error object globals */
if (extobj == NULL) {
- if (PyUFunc_GetPyValues(name,
- &(loop->bufsize), &(loop->errormask),
- &(loop->errobj)) < 0) {
+ if (PyUFunc_GetPyValues(ufunc_name,
+ &buffersize, &errormask, &errobj) < 0) {
+ retval = -1;
goto fail;
}
}
else {
- if (_extract_pyvals(extobj, name,
- &(loop->bufsize), &(loop->errormask),
- &(loop->errobj)) < 0) {
+ if (_extract_pyvals(extobj, ufunc_name,
+ &buffersize, &errormask, &errobj) < 0) {
+ retval = -1;
goto fail;
}
}
- /* Setup the arrays */
- if (construct_arrays(loop, args, mps, typetup) < 0) {
+ NPY_UF_DBG_PRINT("Finding inner loop\n");
+
+ /*
+ * Decide the casting rules for inputs and outputs. We want
+ * NPY_SAFE_CASTING or stricter, so that the loop selection code
+ * doesn't choose an integer loop for float inputs, for example.
+ */
+ input_casting = (casting > NPY_SAFE_CASTING) ? NPY_SAFE_CASTING : casting;
+
+ if (type_tup == NULL) {
+ /* Find the best ufunc inner loop, and fill in the dtypes */
+ retval = find_best_ufunc_inner_loop(self, op, input_casting, casting,
+ buffersize, any_object, dtype,
+ &innerloop, &innerloopdata, &trivial_loop_ok);
+ } else {
+ /* Find the specified ufunc inner loop, and fill in the dtypes */
+ retval = find_specified_ufunc_inner_loop(self, type_tup,
+ op, casting,
+ buffersize, any_object, dtype,
+ &innerloop, &innerloopdata, &trivial_loop_ok);
+ }
+ if (retval < 0) {
goto fail;
}
- PyUFunc_clearfperr();
- return loop;
-fail:
- ufuncloop_dealloc(loop);
- return NULL;
-}
+ /*
+ * FAIL with NotImplemented if the other object has
+ * the __r<op>__ method and has __array_priority__ as
+ * an attribute (signalling it can handle ndarray's)
+ * and is not already an ndarray or a subtype of the same type.
+ */
+ if (nin == 2 && nout == 1 && dtype[1]->type_num == NPY_OBJECT) {
+ PyObject *_obj = PyTuple_GET_ITEM(args, 1);
+ if (!PyArray_CheckExact(_obj)
+ /* If both are same subtype of object arrays, then proceed */
+ && !(Py_TYPE(_obj) == Py_TYPE(PyTuple_GET_ITEM(args, 0)))
+ && PyObject_HasAttrString(_obj, "__array_priority__")
+ && _has_reflected_op(_obj, ufunc_name)) {
+ retval = -2;
+ goto fail;
+ }
+ }
+#if NPY_UF_DBG_TRACING
+ printf("input types:\n");
+ for (i = 0; i < nin; ++i) {
+ PyObject_Print((PyObject *)dtype[i], stdout, 0);
+ printf(" ");
+ }
+ printf("\noutput types:\n");
+ for (i = nin; i < niter; ++i) {
+ PyObject_Print((PyObject *)dtype[i], stdout, 0);
+ printf(" ");
+ }
+ printf("\n");
+#endif
-/*
- static void
- _printbytebuf(PyUFuncLoopObject *loop, int bufnum)
- {
- int i;
-
- fprintf(stderr, "Printing byte buffer %d\n", bufnum);
- for(i=0; i<loop->bufcnt; i++) {
- fprintf(stderr, " %d\n", *(((byte *)(loop->buffer[bufnum]))+i));
- }
- }
-
- static void
- _printlongbuf(PyUFuncLoopObject *loop, int bufnum)
- {
- int i;
-
- fprintf(stderr, "Printing long buffer %d\n", bufnum);
- for(i=0; i<loop->bufcnt; i++) {
- fprintf(stderr, " %ld\n", *(((long *)(loop->buffer[bufnum]))+i));
- }
- }
-
- static void
- _printlongbufptr(PyUFuncLoopObject *loop, int bufnum)
- {
- int i;
-
- fprintf(stderr, "Printing long buffer %d\n", bufnum);
- for(i=0; i<loop->bufcnt; i++) {
- fprintf(stderr, " %ld\n", *(((long *)(loop->bufptr[bufnum]))+i));
- }
- }
-
-
-
- static void
- _printcastbuf(PyUFuncLoopObject *loop, int bufnum)
- {
- int i;
-
- fprintf(stderr, "Printing long buffer %d\n", bufnum);
- for(i=0; i<loop->bufcnt; i++) {
- fprintf(stderr, " %ld\n", *(((long *)(loop->castbuf[bufnum]))+i));
- }
- }
+ /*
+ * Get the appropriate __array_prepare__ function to call
+ * for each output
+ */
+ _find_array_prepare(args, kwds, arr_prep, nin, nout);
-*/
+ /* Set up arr_prep_args if a prep function was needed */
+ for (i = 0; i < nout; ++i) {
+ if (arr_prep[i] != NULL && arr_prep[i] != Py_None) {
+ arr_prep_args = make_arr_prep_args(nin, args, kwds);
+ break;
+ }
+ }
+ /* If the loop wants the arrays, provide them */
+ if (_does_loop_use_arrays(innerloopdata)) {
+ innerloopdata = (void*)op;
+ }
+ /*
+ * Set up the iterator per-op flags. For generalized ufuncs, we
+ * can't do buffering, so must COPY or UPDATEIFCOPY.
+ */
+ for (i = 0; i < nin; ++i) {
+ op_flags[i] = NPY_ITER_READONLY|
+ NPY_ITER_COPY|
+ NPY_ITER_ALIGNED;
+ }
+ for (i = nin; i < niter; ++i) {
+ op_flags[i] = NPY_ITER_READWRITE|
+ NPY_ITER_UPDATEIFCOPY|
+ NPY_ITER_ALIGNED|
+ NPY_ITER_ALLOCATE|
+ NPY_ITER_NO_BROADCAST;
+ }
+
+ /* Create the iterator */
+ iter = NpyIter_MultiNew(niter, op, NPY_ITER_COORDS|
+ NPY_ITER_REFS_OK|
+ NPY_ITER_REDUCE_OK,
+ order, NPY_UNSAFE_CASTING, op_flags,
+ dtype, op_ndim, op_axes, 0);
+ if (iter == NULL) {
+ retval = -1;
+ goto fail;
+ }
+ /* Fill in any allocated outputs */
+ for (i = nin; i < niter; ++i) {
+ if (op[i] == NULL) {
+ op[i] = NpyIter_GetOperandArray(iter)[i];
+ Py_INCREF(op[i]);
+ }
+ }
-/*
- * currently generic ufuncs cannot be built for use on flexible arrays.
- *
- * The cast functions in the generic loop would need to be fixed to pass
- * in something besides NULL, NULL.
- *
- * Also the underlying ufunc loops would not know the element-size unless
- * that was passed in as data (which could be arranged).
- *
- */
+ /*
+ * Set up the inner strides array. Because we're not doing
+ * buffering, the strides are fixed throughout the looping.
+ */
+ inner_strides = (npy_intp *)_pya_malloc(
+ NPY_SIZEOF_INTP * (niter+core_dim_ixs_size));
+ /* The strides after the first niter match core_dim_ixs */
+ core_dim_ixs = self->core_dim_ixs;
+ inner_strides_tmp = inner_strides + niter;
+ for (idim = 0; idim < self->core_num_dim_ix; ++idim) {
+ ax_strides_tmp[idim] = NpyIter_GetAxisStrideArray(iter,
+ broadcast_ndim+idim);
+ if (ax_strides_tmp[idim] == NULL) {
+ retval = -1;
+ goto fail;
+ }
+ }
+ for (i = 0; i < niter; ++i) {
+ for (idim = 0; idim < self->core_num_dims[i]; ++idim) {
+ inner_strides_tmp[idim] = ax_strides_tmp[core_dim_ixs[idim]][i];
+ }
-/*UFUNC_API
- *
- * This generic function is called with the ufunc object, the arguments to it,
- * and an array of (pointers to) PyArrayObjects which are NULL. The
- * arguments are parsed and placed in mps in construct_loop (construct_arrays)
- */
-NPY_NO_EXPORT int
-PyUFunc_GenericFunction(PyUFuncObject *self, PyObject *args, PyObject *kwds,
- PyArrayObject **mps)
-{
- PyUFuncLoopObject *loop;
- int i;
- NPY_BEGIN_THREADS_DEF;
+ core_dim_ixs += self->core_num_dims[i];
+ inner_strides_tmp += self->core_num_dims[i];
+ }
- if (!(loop = construct_loop(self, args, kwds, mps))) {
- return -1;
+ /* Set up the inner dimensions array */
+ if (NpyIter_GetShape(iter, inner_dimensions) != NPY_SUCCEED) {
+ retval = -1;
+ goto fail;
}
- if (loop->notimplemented) {
- ufuncloop_dealloc(loop);
- return -2;
+ /* Move the core dimensions to start at the second element */
+ memmove(&inner_dimensions[1], &inner_dimensions[broadcast_ndim],
+ NPY_SIZEOF_INTP * self->core_num_dim_ix);
+
+ /* Remove all the core dimensions from the iterator */
+ for (i = 0; i < self->core_num_dim_ix; ++i) {
+ if (NpyIter_RemoveAxis(iter, broadcast_ndim) != NPY_SUCCEED) {
+ retval = -1;
+ goto fail;
+ }
}
- if (self->core_enabled && loop->meth != SIGNATURE_NOBUFFER_UFUNCLOOP) {
- PyErr_SetString(PyExc_RuntimeError,
- "illegal loop method for ufunc with signature");
+ if (NpyIter_RemoveCoords(iter) != NPY_SUCCEED) {
+ retval = -1;
+ goto fail;
+ }
+ if (NpyIter_RemoveInnerLoop(iter) != NPY_SUCCEED) {
+ retval = -1;
goto fail;
}
- NPY_LOOP_BEGIN_THREADS;
- switch(loop->meth) {
- case ONE_UFUNCLOOP:
- /*
- * Everything is contiguous, notswapped, aligned,
- * and of the right type. -- Fastest.
- * Or if not contiguous, then a single-stride
- * increment moves through the entire array.
- */
- /*fprintf(stderr, "ONE...%d\n", loop->size);*/
- loop->function((char **)loop->bufptr, &(loop->size),
- loop->steps, loop->funcdata);
- UFUNC_CHECK_ERROR(loop);
- break;
- case NOBUFFER_UFUNCLOOP:
- /*
- * Everything is notswapped, aligned and of the
- * right type but not contiguous. -- Almost as fast.
- */
- /*fprintf(stderr, "NOBUFFER...%d\n", loop->size);*/
- while (loop->index < loop->size) {
- for (i = 0; i < self->nargs; i++) {
- loop->bufptr[i] = loop->iters[i]->dataptr;
- }
- loop->function((char **)loop->bufptr, &(loop->bufcnt),
- loop->steps, loop->funcdata);
- UFUNC_CHECK_ERROR(loop);
+ /*
+ * The first niter strides are for the inner loop (but only can
+ * copy them after removing the core axes
+ */
+ memcpy(inner_strides, NpyIter_GetInnerStrideArray(iter),
+ NPY_SIZEOF_INTP * niter);
- /* Adjust loop pointers */
- for (i = 0; i < self->nargs; i++) {
- PyArray_ITER_NEXT(loop->iters[i]);
- }
- loop->index++;
- }
- break;
- case SIGNATURE_NOBUFFER_UFUNCLOOP:
- while (loop->index < loop->size) {
- for (i = 0; i < self->nargs; i++) {
- loop->bufptr[i] = loop->iters[i]->dataptr;
- }
- loop->function((char **)loop->bufptr, loop->core_dim_sizes,
- loop->core_strides, loop->funcdata);
- UFUNC_CHECK_ERROR(loop);
+#if 0
+ printf("strides: ");
+ for (i = 0; i < niter+core_dim_ixs_size; ++i) {
+ printf("%d ", (int)inner_strides[i]);
+ }
+ printf("\n");
+#endif
- /* Adjust loop pointers */
- for (i = 0; i < self->nargs; i++) {
- PyArray_ITER_NEXT(loop->iters[i]);
- }
- loop->index++;
- }
- break;
- case BUFFER_UFUNCLOOP: {
- /* This should be a function */
- PyArray_CopySwapNFunc *copyswapn[NPY_MAXARGS];
- PyArrayIterObject **iters=loop->iters;
- int *swap=loop->swap;
- char **dptr=loop->dptr;
- int mpselsize[NPY_MAXARGS];
- intp laststrides[NPY_MAXARGS];
- int fastmemcpy[NPY_MAXARGS];
- int *needbuffer = loop->needbuffer;
- intp index=loop->index, size=loop->size;
- int bufsize;
- intp bufcnt;
- int copysizes[NPY_MAXARGS];
- char **bufptr = loop->bufptr;
- char **buffer = loop->buffer;
- char **castbuf = loop->castbuf;
- intp *steps = loop->steps;
- char *tptr[NPY_MAXARGS];
- int ninnerloops = loop->ninnerloops;
- Bool pyobject[NPY_MAXARGS];
- int datasize[NPY_MAXARGS];
- int j, k, stopcondition;
- char *myptr1, *myptr2;
-
- for (i = 0; i <self->nargs; i++) {
- copyswapn[i] = mps[i]->descr->f->copyswapn;
- mpselsize[i] = mps[i]->descr->elsize;
- pyobject[i] = ((loop->obj & UFUNC_OBJ_ISOBJECT)
- && (mps[i]->descr->type_num == PyArray_OBJECT));
- laststrides[i] = iters[i]->strides[loop->lastdim];
- if (steps[i] && laststrides[i] != mpselsize[i]) {
- fastmemcpy[i] = 0;
- }
- else {
- fastmemcpy[i] = 1;
- }
- }
- /* Do generic buffered looping here (works for any kind of
- * arrays -- some need buffers, some don't.
- *
- *
- * New algorithm: N is the largest dimension. B is the buffer-size.
- * quotient is loop->ninnerloops-1
- * remainder is loop->leftover
- *
- * Compute N = quotient * B + remainder.
- * quotient = N / B # integer math
- * (store quotient + 1) as the number of innerloops
- * remainder = N % B # integer remainder
- *
- * On the inner-dimension we will have (quotient + 1) loops where
- * the size of the inner function is B for all but the last when the niter size is
- * remainder.
- *
- * So, the code looks very similar to NOBUFFER_LOOP except the inner-most loop is
- * replaced with...
- *
- * for(i=0; i<quotient+1; i++) {
- * if (i==quotient+1) make itersize remainder size
- * copy only needed items to buffer.
- * swap input buffers if needed
- * cast input buffers if needed
- * call loop_function()
- * cast outputs in buffers if needed
- * swap outputs in buffers if needed
- * copy only needed items back to output arrays.
- * update all data-pointers by strides*niter
- * }
- */
+ /* Start with the floating-point exception flags cleared */
+ PyUFunc_clearfperr();
+ NPY_UF_DBG_PRINT("Executing inner loop\n");
- /*
- * fprintf(stderr, "BUFFER...%d,%d,%d\n", loop->size,
- * loop->ninnerloops, loop->leftover);
- */
- /*
- * for(i=0; i<self->nargs; i++) {
- * fprintf(stderr, "iters[%d]->dataptr = %p, %p of size %d\n", i,
- * iters[i], iters[i]->ao->data, PyArray_NBYTES(iters[i]->ao));
- * }
- */
- stopcondition = ninnerloops;
- if (loop->leftover == 0) {
- stopcondition--;
- }
- while (index < size) {
- bufsize=loop->bufsize;
- for(i = 0; i<self->nargs; i++) {
- tptr[i] = loop->iters[i]->dataptr;
- if (needbuffer[i]) {
- dptr[i] = bufptr[i];
- datasize[i] = (steps[i] ? bufsize : 1);
- copysizes[i] = datasize[i] * mpselsize[i];
- }
- else {
- dptr[i] = tptr[i];
- }
- }
+ /* Do the ufunc loop */
+ if (NpyIter_GetIterSize(iter) != 0) {
+ NpyIter_IterNextFunc *iternext;
+ char **dataptr;
+ npy_intp *count_ptr;
- /* This is the inner function over the last dimension */
- for (k = 1; k<=stopcondition; k++) {
- if (k == ninnerloops) {
- bufsize = loop->leftover;
- for (i=0; i<self->nargs;i++) {
- if (!needbuffer[i]) {
- continue;
- }
- datasize[i] = (steps[i] ? bufsize : 1);
- copysizes[i] = datasize[i] * mpselsize[i];
- }
- }
- for (i = 0; i < self->nin; i++) {
- if (!needbuffer[i]) {
- continue;
- }
- if (fastmemcpy[i]) {
- memcpy(buffer[i], tptr[i], copysizes[i]);
- }
- else {
- myptr1 = buffer[i];
- myptr2 = tptr[i];
- for (j = 0; j < bufsize; j++) {
- memcpy(myptr1, myptr2, mpselsize[i]);
- myptr1 += mpselsize[i];
- myptr2 += laststrides[i];
- }
- }
-
- /* swap the buffer if necessary */
- if (swap[i]) {
- /* fprintf(stderr, "swapping...\n");*/
- copyswapn[i](buffer[i], mpselsize[i], NULL, -1,
- (intp) datasize[i], 1,
- mps[i]);
- }
- /* cast to the other buffer if necessary */
- if (loop->cast[i]) {
- /* fprintf(stderr, "casting... %d, %p %p\n", i, buffer[i]); */
- loop->cast[i](buffer[i], castbuf[i],
- (intp) datasize[i],
- NULL, NULL);
- }
- }
-
- bufcnt = (intp) bufsize;
- loop->function((char **)dptr, &bufcnt, steps, loop->funcdata);
- UFUNC_CHECK_ERROR(loop);
+ /* Get the variables needed for the loop */
+ iternext = NpyIter_GetIterNext(iter, NULL);
+ if (iternext == NULL) {
+ NpyIter_Deallocate(iter);
+ retval = -1;
+ goto fail;
+ }
+ dataptr = NpyIter_GetDataPtrArray(iter);
+ count_ptr = NpyIter_GetInnerLoopSizePtr(iter);
- for (i = self->nin; i < self->nargs; i++) {
- if (!needbuffer[i]) {
- continue;
- }
- if (loop->cast[i]) {
- /* fprintf(stderr, "casting back... %d, %p", i, castbuf[i]); */
- loop->cast[i](castbuf[i],
- buffer[i],
- (intp) datasize[i],
- NULL, NULL);
- }
- if (swap[i]) {
- copyswapn[i](buffer[i], mpselsize[i], NULL, -1,
- (intp) datasize[i], 1,
- mps[i]);
- }
- /*
- * copy back to output arrays
- * decref what's already there for object arrays
- */
- if (pyobject[i]) {
- myptr1 = tptr[i];
- for (j = 0; j < datasize[i]; j++) {
- Py_XDECREF(*((PyObject **)myptr1));
- myptr1 += laststrides[i];
- }
- }
- if (fastmemcpy[i]) {
- memcpy(tptr[i], buffer[i], copysizes[i]);
- }
- else {
- myptr2 = buffer[i];
- myptr1 = tptr[i];
- for (j = 0; j < bufsize; j++) {
- memcpy(myptr1, myptr2, mpselsize[i]);
- myptr1 += laststrides[i];
- myptr2 += mpselsize[i];
- }
- }
- }
- if (k == stopcondition) {
- continue;
- }
- for (i = 0; i < self->nargs; i++) {
- tptr[i] += bufsize * laststrides[i];
- if (!needbuffer[i]) {
- dptr[i] = tptr[i];
- }
- }
- }
- /* end inner function over last dimension */
+ do {
+ inner_dimensions[0] = *count_ptr;
+ innerloop(dataptr, inner_dimensions, inner_strides, innerloopdata);
+ } while (iternext(iter));
+ }
- if (loop->objfunc) {
- /*
- * DECREF castbuf when underlying function used
- * object arrays and casting was needed to get
- * to object arrays
- */
- for (i = 0; i < self->nargs; i++) {
- if (loop->cast[i]) {
- if (steps[i] == 0) {
- Py_XDECREF(*((PyObject **)castbuf[i]));
- }
- else {
- int size = loop->bufsize;
-
- PyObject **objptr = (PyObject **)castbuf[i];
- /*
- * size is loop->bufsize unless there
- * was only one loop
- */
- if (ninnerloops == 1) {
- size = loop->leftover;
- }
- for (j = 0; j < size; j++) {
- Py_XDECREF(*objptr);
- *objptr = NULL;
- objptr += 1;
- }
- }
- }
- }
- }
- /* fixme -- probably not needed here*/
- UFUNC_CHECK_ERROR(loop);
+ /* Check whether any errors occurred during the loop */
+ if (PyErr_Occurred() || (errormask &&
+ PyUFunc_checkfperr(errormask, errobj, &first_error))) {
+ retval = -1;
+ goto fail;
+ }
- for (i = 0; i < self->nargs; i++) {
- PyArray_ITER_NEXT(loop->iters[i]);
- }
- index++;
- }
- } /* end of last case statement */
+ _pya_free(inner_strides);
+ NpyIter_Deallocate(iter);
+ /* The caller takes ownership of all the references in op */
+ for (i = 0; i < niter; ++i) {
+ Py_XDECREF(dtype[i]);
+ Py_XDECREF(arr_prep[i]);
}
+ Py_XDECREF(errobj);
+ Py_XDECREF(type_tup);
+ Py_XDECREF(arr_prep_args);
+
+ NPY_UF_DBG_PRINT("Returning Success\n");
- NPY_LOOP_END_THREADS;
- ufuncloop_dealloc(loop);
return 0;
fail:
- NPY_LOOP_END_THREADS;
- if (loop) {
- ufuncloop_dealloc(loop);
+ NPY_UF_DBG_PRINT1("Returning failure code %d\n", retval);
+ if (inner_strides) {
+ _pya_free(inner_strides);
}
- return -1;
+ if (iter != NULL) {
+ NpyIter_Deallocate(iter);
+ }
+ for (i = 0; i < niter; ++i) {
+ Py_XDECREF(op[i]);
+ op[i] = NULL;
+ Py_XDECREF(dtype[i]);
+ Py_XDECREF(arr_prep[i]);
+ }
+ Py_XDECREF(errobj);
+ Py_XDECREF(type_tup);
+ Py_XDECREF(arr_prep_args);
+
+ return retval;
}
-static PyArrayObject *
-_getidentity(PyUFuncObject *self, int otype, char *str)
+/*UFUNC_API
+ *
+ * This generic function is called with the ufunc object, the arguments to it,
+ * and an array of (pointers to) PyArrayObjects which are NULL.
+ */
+NPY_NO_EXPORT int
+PyUFunc_GenericFunction(PyUFuncObject *self,
+ PyObject *args, PyObject *kwds,
+ PyArrayObject **op)
{
- PyObject *obj, *arr;
- PyArray_Descr *typecode;
+ int nin, nout;
+ int i, niter;
+ char *ufunc_name;
+ int retval = -1, any_object = 0;
+ NPY_CASTING input_casting;
- if (self->identity == PyUFunc_None) {
- PyErr_Format(PyExc_ValueError,
- "zero-size array to ufunc.%s " \
- "without identity", str);
- return NULL;
+ PyArray_Descr *dtype[NPY_MAXARGS];
+
+ /* These parameters come from extobj= or from a TLS global */
+ int buffersize = 0, errormask = 0;
+ PyObject *errobj = NULL;
+ int first_error = 1;
+
+ /* The selected inner loop */
+ PyUFuncGenericFunction innerloop = NULL;
+ void *innerloopdata = NULL;
+
+ /* The __array_prepare__ function to call for each output */
+ PyObject *arr_prep[NPY_MAXARGS];
+ /*
+ * This is either args, or args with the out= parameter from
+ * kwds added appropriately.
+ */
+ PyObject *arr_prep_args = NULL;
+
+ int trivial_loop_ok = 0;
+
+ /* TODO: For 1.6, the default should probably be NPY_CORDER */
+ NPY_ORDER order = NPY_KEEPORDER;
+ /*
+ * Many things in NumPy do unsafe casting (doing int += float, etc).
+ * The strictness should probably become a state parameter, similar
+ * to the seterr/geterr.
+ */
+ NPY_CASTING casting = NPY_UNSAFE_CASTING;
+ /* When provided, extobj and typetup contain borrowed references */
+ PyObject *extobj = NULL, *type_tup = NULL;
+
+ if (self == NULL) {
+ PyErr_SetString(PyExc_ValueError, "function not supported");
+ return -1;
}
- if (self->identity == PyUFunc_One) {
- obj = PyInt_FromLong((long) 1);
- } else {
- obj = PyInt_FromLong((long) 0);
+
+ /* TODO: support generalized ufunc */
+ if (self->core_enabled) {
+ return PyUFunc_GeneralizedFunction(self, args, kwds, op);
}
- typecode = PyArray_DescrFromType(otype);
- arr = PyArray_FromAny(obj, typecode, 0, 0, CARRAY, NULL);
- Py_DECREF(obj);
- return (PyArrayObject *)arr;
-}
+ nin = self->nin;
+ nout = self->nout;
+ niter = nin + nout;
-static int
-_create_reduce_copy(PyUFuncReduceObject *loop, PyArrayObject **arr, int rtype)
-{
- intp maxsize;
- PyObject *new;
- PyArray_Descr *ntype;
-
- maxsize = PyArray_SIZE(*arr);
-
- if (maxsize < loop->bufsize) {
- if (!(PyArray_ISBEHAVED_RO(*arr))
- || PyArray_TYPE(*arr) != rtype) {
- ntype = PyArray_DescrFromType(rtype);
- new = PyArray_FromAny((PyObject *)(*arr),
- ntype, 0, 0,
- FORCECAST | ALIGNED, NULL);
- if (new == NULL) {
- return -1;
- }
- *arr = (PyArrayObject *)new;
- loop->decref = new;
+ ufunc_name = self->name ? self->name : "<unnamed ufunc>";
+
+ NPY_UF_DBG_PRINT1("\nEvaluating ufunc %s\n", ufunc_name);
+
+ /* Initialize all the operands and dtypes to NULL */
+ for (i = 0; i < niter; ++i) {
+ op[i] = NULL;
+ dtype[i] = NULL;
+ arr_prep[i] = NULL;
+ }
+
+ NPY_UF_DBG_PRINT("Getting arguments\n");
+
+ /* Get all the arguments */
+ retval = get_ufunc_arguments(self, args, kwds,
+ op, &order, &casting, &extobj, &type_tup, &any_object);
+ if (retval < 0) {
+ goto fail;
+ }
+
+ /* Get the buffersize, errormask, and error object globals */
+ if (extobj == NULL) {
+ if (PyUFunc_GetPyValues(ufunc_name,
+ &buffersize, &errormask, &errobj) < 0) {
+ retval = -1;
+ goto fail;
}
}
+ else {
+ if (_extract_pyvals(extobj, ufunc_name,
+ &buffersize, &errormask, &errobj) < 0) {
+ retval = -1;
+ goto fail;
+ }
+ }
+
+ NPY_UF_DBG_PRINT("Finding inner loop\n");
/*
- * Don't decref *arr before re-assigning
- * because it was not going to be DECREF'd anyway.
- *
- * If a copy is made, then the copy will be removed
- * on deallocation of the loop structure by setting
- * loop->decref.
+ * Decide the casting rules for inputs and outputs. We want
+ * NPY_SAFE_CASTING or stricter, so that the loop selection code
+ * doesn't choose an integer loop for float inputs, for example.
*/
- return 0;
-}
+ input_casting = (casting > NPY_SAFE_CASTING) ? NPY_SAFE_CASTING : casting;
-static PyUFuncReduceObject *
-construct_reduce(PyUFuncObject *self, PyArrayObject **arr, PyArrayObject *out,
- int axis, int otype, int operation, intp ind_size, char *str)
-{
- PyUFuncReduceObject *loop;
- PyArrayObject *idarr;
- PyArrayObject *aar;
- intp loop_i[MAX_DIMS], outsize = 0;
- int arg_types[3];
- PyArray_SCALARKIND scalars[3] = {PyArray_NOSCALAR, PyArray_NOSCALAR,
- PyArray_NOSCALAR};
- int i, j, nd;
- int flags;
-
- /* Reduce type is the type requested of the input during reduction */
- if (self->core_enabled) {
- PyErr_Format(PyExc_RuntimeError,
- "construct_reduce not allowed on ufunc with signature");
- return NULL;
+ if (type_tup == NULL) {
+ /* Find the best ufunc inner loop, and fill in the dtypes */
+ retval = find_best_ufunc_inner_loop(self, op, input_casting, casting,
+ buffersize, any_object, dtype,
+ &innerloop, &innerloopdata, &trivial_loop_ok);
+ } else {
+ /* Find the specified ufunc inner loop, and fill in the dtypes */
+ retval = find_specified_ufunc_inner_loop(self, type_tup,
+ op, casting,
+ buffersize, any_object, dtype,
+ &innerloop, &innerloopdata, &trivial_loop_ok);
}
- nd = (*arr)->nd;
- arg_types[0] = otype;
- arg_types[1] = otype;
- arg_types[2] = otype;
- if ((loop = _pya_malloc(sizeof(PyUFuncReduceObject))) == NULL) {
- PyErr_NoMemory();
- return loop;
- }
-
- loop->retbase = 0;
- loop->swap = 0;
- loop->index = 0;
- loop->ufunc = self;
- Py_INCREF(self);
- loop->cast = NULL;
- loop->buffer = NULL;
- loop->ret = NULL;
- loop->it = NULL;
- loop->rit = NULL;
- loop->errobj = NULL;
- loop->first = 1;
- loop->decref = NULL;
- loop->N = (*arr)->dimensions[axis];
- loop->instrides = (*arr)->strides[axis];
- if (select_types(loop->ufunc, arg_types, &(loop->function),
- &(loop->funcdata), scalars, NULL) == -1) {
+ if (retval < 0) {
goto fail;
}
+
/*
- * output type may change -- if it does
- * reduction is forced into that type
- * and we need to select the reduction function again
- */
- if (otype != arg_types[2]) {
- otype = arg_types[2];
- arg_types[0] = otype;
- arg_types[1] = otype;
- if (select_types(loop->ufunc, arg_types, &(loop->function),
- &(loop->funcdata), scalars, NULL) == -1) {
+ * FAIL with NotImplemented if the other object has
+ * the __r<op>__ method and has __array_priority__ as
+ * an attribute (signalling it can handle ndarray's)
+ * and is not already an ndarray or a subtype of the same type.
+ */
+ if (nin == 2 && nout == 1 && dtype[1]->type_num == NPY_OBJECT) {
+ PyObject *_obj = PyTuple_GET_ITEM(args, 1);
+ if (!PyArray_CheckExact(_obj)
+ /* If both are same subtype of object arrays, then proceed */
+ && !(Py_TYPE(_obj) == Py_TYPE(PyTuple_GET_ITEM(args, 0)))
+ && PyObject_HasAttrString(_obj, "__array_priority__")
+ && _has_reflected_op(_obj, ufunc_name)) {
+ retval = -2;
goto fail;
}
}
- /* get looping parameters from Python */
- if (PyUFunc_GetPyValues(str, &(loop->bufsize), &(loop->errormask),
- &(loop->errobj)) < 0) {
- goto fail;
+#if NPY_UF_DBG_TRACING
+ printf("input types:\n");
+ for (i = 0; i < nin; ++i) {
+ PyObject_Print((PyObject *)dtype[i], stdout, 0);
+ printf(" ");
}
- /* Make copy if misbehaved or not otype for small arrays */
- if (_create_reduce_copy(loop, arr, otype) < 0) {
- goto fail;
+ printf("\noutput types:\n");
+ for (i = nin; i < niter; ++i) {
+ PyObject_Print((PyObject *)dtype[i], stdout, 0);
+ printf(" ");
}
- aar = *arr;
+ printf("\n");
+#endif
- if (loop->N == 0) {
- loop->meth = ZERO_EL_REDUCELOOP;
- }
- else if (PyArray_ISBEHAVED_RO(aar) && (otype == (aar)->descr->type_num)) {
- if (loop->N == 1) {
- loop->meth = ONE_EL_REDUCELOOP;
- }
- else {
- loop->meth = NOBUFFER_UFUNCLOOP;
- loop->steps[1] = (aar)->strides[axis];
- loop->N -= 1;
+ /*
+ * Get the appropriate __array_prepare__ function to call
+ * for each output
+ */
+ _find_array_prepare(args, kwds, arr_prep, nin, nout);
+
+ /* Set up arr_prep_args if a prep function was needed */
+ for (i = 0; i < nout; ++i) {
+ if (arr_prep[i] != NULL && arr_prep[i] != Py_None) {
+ arr_prep_args = make_arr_prep_args(nin, args, kwds);
+ break;
}
}
- else {
- loop->meth = BUFFER_UFUNCLOOP;
- loop->swap = !(PyArray_ISNOTSWAPPED(aar));
+
+ /* If the loop wants the arrays, provide them */
+ if (_does_loop_use_arrays(innerloopdata)) {
+ innerloopdata = (void*)op;
+ }
+
+ /* Start with the floating-point exception flags cleared */
+ PyUFunc_clearfperr();
+
+ NPY_UF_DBG_PRINT("Executing inner loop\n");
+
+ /* Do the ufunc loop */
+ retval = execute_ufunc_loop(self, trivial_loop_ok, op, dtype, order,
+ buffersize, arr_prep, arr_prep_args,
+ innerloop, innerloopdata);
+ if (retval < 0) {
+ goto fail;
}
- /* Determine if object arrays are involved */
- if (otype == PyArray_OBJECT || aar->descr->type_num == PyArray_OBJECT) {
- loop->obj = UFUNC_OBJ_ISOBJECT | UFUNC_OBJ_NEEDS_API;
+ /* Check whether any errors occurred during the loop */
+ if (PyErr_Occurred() || (errormask &&
+ PyUFunc_checkfperr(errormask, errobj, &first_error))) {
+ retval = -1;
+ goto fail;
}
- else if ((otype == PyArray_DATETIME)
- || (aar->descr->type_num == PyArray_DATETIME)
- || (otype == PyArray_TIMEDELTA)
- || (aar->descr->type_num == PyArray_TIMEDELTA))
- {
- loop->obj = UFUNC_OBJ_NEEDS_API;
+
+ /* The caller takes ownership of all the references in op */
+ for (i = 0; i < niter; ++i) {
+ Py_XDECREF(dtype[i]);
+ Py_XDECREF(arr_prep[i]);
}
- else {
- loop->obj = 0;
+ Py_XDECREF(errobj);
+ Py_XDECREF(type_tup);
+ Py_XDECREF(arr_prep_args);
+
+ NPY_UF_DBG_PRINT("Returning Success\n");
+
+ return 0;
+
+fail:
+ NPY_UF_DBG_PRINT1("Returning failure code %d\n", retval);
+ for (i = 0; i < niter; ++i) {
+ Py_XDECREF(op[i]);
+ op[i] = NULL;
+ Py_XDECREF(dtype[i]);
+ Py_XDECREF(arr_prep[i]);
}
- if ((loop->meth == ZERO_EL_REDUCELOOP)
- || ((operation == UFUNC_REDUCEAT)
- && (loop->meth == BUFFER_UFUNCLOOP))) {
- idarr = _getidentity(self, otype, str);
- if (idarr == NULL) {
- goto fail;
+ Py_XDECREF(errobj);
+ Py_XDECREF(type_tup);
+ Py_XDECREF(arr_prep_args);
+
+ return retval;
+}
+
+/*
+ * Given the output type, finds the specified binary op. The
+ * ufunc must have nin==2 and nout==1. The function may modify
+ * otype if the given type isn't found.
+ *
+ * Returns 0 on success, -1 on failure.
+ */
+static int
+get_binary_op_function(PyUFuncObject *self, int *otype,
+ PyUFuncGenericFunction *out_innerloop,
+ void **out_innerloopdata)
+{
+ int i;
+ PyUFunc_Loop1d *funcdata;
+
+ NPY_UF_DBG_PRINT1("Getting binary op function for type number %d\n",
+ *otype);
+
+ /* If the type is custom and there are userloops, search for it here */
+ if (self->userloops != NULL && PyTypeNum_ISUSERDEF(*otype)) {
+ PyObject *key, *obj;
+ key = PyInt_FromLong(*otype);
+ if (key == NULL) {
+ return -1;
}
- if (idarr->descr->elsize > UFUNC_MAXIDENTITY) {
- PyErr_Format(PyExc_RuntimeError,
- "UFUNC_MAXIDENTITY (%d) is too small"\
- "(needs to be at least %d)",
- UFUNC_MAXIDENTITY, idarr->descr->elsize);
- Py_DECREF(idarr);
- goto fail;
+ obj = PyDict_GetItem(self->userloops, key);
+ Py_DECREF(key);
+ if (obj != NULL) {
+ funcdata = (PyUFunc_Loop1d *)NpyCapsule_AsVoidPtr(obj);
+ while (funcdata != NULL) {
+ int *types = funcdata->arg_types;
+
+ if (types[0] == *otype && types[1] == *otype &&
+ types[2] == *otype) {
+ *out_innerloop = funcdata->func;
+ *out_innerloopdata = funcdata->data;
+ return 0;
+ }
+
+ funcdata = funcdata->next;
+ }
}
- memcpy(loop->idptr, idarr->data, idarr->descr->elsize);
- Py_DECREF(idarr);
}
- /* Construct return array */
- flags = NPY_CARRAY | NPY_UPDATEIFCOPY | NPY_FORCECAST;
- switch(operation) {
- case UFUNC_REDUCE:
- for (j = 0, i = 0; i < nd; i++) {
- if (i != axis) {
- loop_i[j++] = (aar)->dimensions[i];
+ /* Search for a function with compatible inputs */
+ for (i = 0; i < self->ntypes; ++i) {
+ char *types = self->types + i*self->nargs;
+
+ NPY_UF_DBG_PRINT3("Trying loop with signature %d %d -> %d\n",
+ types[0], types[1], types[2]);
+
+ if (PyArray_CanCastSafely(*otype, types[0]) &&
+ types[0] == types[1] &&
+ (*otype == NPY_OBJECT || types[0] != NPY_OBJECT)) {
+ /* If the signature is "xx->x", we found the loop */
+ if (types[2] == types[0]) {
+ *out_innerloop = self->functions[i];
+ *out_innerloopdata = self->data[i];
+ *otype = types[0];
+ return 0;
+ }
+ /*
+ * Otherwise, we found the natural type of the reduction,
+ * replace otype and search again
+ */
+ else {
+ *otype = types[2];
+ break;
}
}
- if (out == NULL) {
- loop->ret = (PyArrayObject *)
- PyArray_New(Py_TYPE(aar), aar->nd-1, loop_i,
- otype, NULL, NULL, 0, 0,
- (PyObject *)aar);
- }
- else {
- outsize = PyArray_MultiplyList(loop_i, aar->nd - 1);
- }
- break;
- case UFUNC_ACCUMULATE:
- if (out == NULL) {
- loop->ret = (PyArrayObject *)
- PyArray_New(Py_TYPE(aar), aar->nd, aar->dimensions,
- otype, NULL, NULL, 0, 0, (PyObject *)aar);
- }
- else {
- outsize = PyArray_MultiplyList(aar->dimensions, aar->nd);
- }
- break;
- case UFUNC_REDUCEAT:
- memcpy(loop_i, aar->dimensions, nd*sizeof(intp));
- /* Index is 1-d array */
- loop_i[axis] = ind_size;
- if (out == NULL) {
- loop->ret = (PyArrayObject *)
- PyArray_New(Py_TYPE(aar), aar->nd, loop_i, otype,
- NULL, NULL, 0, 0, (PyObject *)aar);
- }
- else {
- outsize = PyArray_MultiplyList(loop_i, aar->nd);
- }
- if (ind_size == 0) {
- loop->meth = ZERO_EL_REDUCELOOP;
- return loop;
- }
- if (loop->meth == ONE_EL_REDUCELOOP) {
- loop->meth = NOBUFFER_REDUCELOOP;
- }
- break;
}
- if (out) {
- if (PyArray_SIZE(out) != outsize) {
- PyErr_SetString(PyExc_ValueError,
- "wrong shape for output");
- goto fail;
- }
- loop->ret = (PyArrayObject *)
- PyArray_FromArray(out, PyArray_DescrFromType(otype), flags);
- if (loop->ret && loop->ret != out) {
- loop->retbase = 1;
+
+ /* Search for the exact function */
+ for (i = 0; i < self->ntypes; ++i) {
+ char *types = self->types + i*self->nargs;
+
+ if (PyArray_CanCastSafely(*otype, types[0]) &&
+ types[0] == types[1] &&
+ types[1] == types[2] &&
+ (*otype == NPY_OBJECT || types[0] != NPY_OBJECT)) {
+ /* Since the signature is "xx->x", we found the loop */
+ *out_innerloop = self->functions[i];
+ *out_innerloopdata = self->data[i];
+ *otype = types[0];
+ return 0;
}
}
- if (loop->ret == NULL) {
- goto fail;
- }
- loop->insize = aar->descr->elsize;
- loop->outsize = loop->ret->descr->elsize;
- loop->bufptr[0] = loop->ret->data;
- if (loop->meth == ZERO_EL_REDUCELOOP) {
- loop->size = PyArray_SIZE(loop->ret);
- return loop;
- }
+ return -1;
+}
- loop->it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)aar);
- if (loop->it == NULL) {
+/*
+ * The implementation of the reduction operators with the new iterator
+ * turned into a bit of a long function here, but I think the design
+ * of this part needs to be changed to be more like einsum, so it may
+ * not be worth refactoring it too much. Consider this timing:
+ *
+ * >>> a = arange(10000)
+ *
+ * >>> timeit sum(a)
+ * 10000 loops, best of 3: 17 us per loop
+ *
+ * >>> timeit einsum("i->",a)
+ * 100000 loops, best of 3: 13.5 us per loop
+ *
+ */
+static PyObject *
+PyUFunc_ReductionOp(PyUFuncObject *self, PyArrayObject *arr,
+ PyArrayObject *out,
+ int axis, int otype, int operation, char *opname)
+{
+ PyArrayObject *op[2];
+ PyArray_Descr *op_dtypes[2] = {NULL, NULL};
+ int op_axes_arrays[2][NPY_MAXDIMS];
+ int *op_axes[2] = {op_axes_arrays[0], op_axes_arrays[1]};
+ npy_uint32 op_flags[2];
+ int i, idim, ndim, otype_final;
+ int needs_api, need_outer_iterator;
+
+ NpyIter *iter = NULL, *iter_inner = NULL;
+
+ /* The selected inner loop */
+ PyUFuncGenericFunction innerloop = NULL;
+ void *innerloopdata = NULL;
+
+ char *ufunc_name = self->name ? self->name : "(unknown)";
+
+ /* These parameters come from extobj= or from a TLS global */
+ int buffersize = 0, errormask = 0;
+ PyObject *errobj = NULL;
+
+ NPY_BEGIN_THREADS_DEF;
+
+ NPY_UF_DBG_PRINT2("\nEvaluating ufunc %s.%s\n", ufunc_name, opname);
+
+#if 0
+ printf("Doing %s.%s on array with dtype : ", ufunc_name, opname);
+ PyObject_Print((PyObject *)PyArray_DESCR(arr), stdout, 0);
+ printf("\n");
+#endif
+
+ if (PyUFunc_GetPyValues(opname, &buffersize, &errormask, &errobj) < 0) {
return NULL;
}
- if (loop->meth == ONE_EL_REDUCELOOP) {
- loop->size = loop->it->size;
- return loop;
+
+ /* Take a reference to out for later returning */
+ Py_XINCREF(out);
+
+ otype_final = otype;
+ if (get_binary_op_function(self, &otype_final,
+ &innerloop, &innerloopdata) < 0) {
+ PyArray_Descr *dtype = PyArray_DescrFromType(otype);
+ PyErr_Format(PyExc_ValueError,
+ "could not find a matching type for %s.%s, "
+ "requested type has type code '%c'",
+ ufunc_name, opname, dtype ? dtype->type : '-');
+ Py_XDECREF(dtype);
+ goto fail;
}
- /*
- * Fix iterator to loop over correct dimension
- * Set size in axis dimension to 1
- */
- loop->it->contiguous = 0;
- loop->it->size /= (loop->it->dims_m1[axis]+1);
- loop->it->dims_m1[axis] = 0;
- loop->it->backstrides[axis] = 0;
- loop->size = loop->it->size;
+ ndim = PyArray_NDIM(arr);
+
+ /* Set up the output data type */
+ op_dtypes[0] = PyArray_DescrFromType(otype_final);
+ if (op_dtypes[0] == NULL) {
+ goto fail;
+ }
+
+#if NPY_UF_DBG_TRACING
+ printf("Found %s.%s inner loop with dtype : ", ufunc_name, opname);
+ PyObject_Print((PyObject *)op_dtypes[0], stdout, 0);
+ printf("\n");
+#endif
+
+ /* Set up the op_axes for the outer loop */
if (operation == UFUNC_REDUCE) {
- loop->steps[0] = 0;
+ for (i = 0, idim = 0; idim < ndim; ++idim) {
+ if (idim != axis) {
+ op_axes_arrays[0][i] = i;
+ op_axes_arrays[1][i] = idim;
+ i++;
+ }
+ }
+ }
+ else if (operation == UFUNC_ACCUMULATE) {
+ for (idim = 0; idim < ndim; ++idim) {
+ op_axes_arrays[0][idim] = idim;
+ op_axes_arrays[1][idim] = idim;
+ }
}
else {
- loop->rit = (PyArrayIterObject *) \
- PyArray_IterNew((PyObject *)(loop->ret));
- if (loop->rit == NULL) {
- return NULL;
+ PyErr_Format(PyExc_RuntimeError,
+ "invalid reduction operation %s.%s", ufunc_name, opname);
+ goto fail;
+ }
+
+ /* The per-operand flags for the outer loop */
+ op_flags[0] = NPY_ITER_READWRITE|
+ NPY_ITER_NO_BROADCAST|
+ NPY_ITER_ALLOCATE|
+ NPY_ITER_NO_SUBTYPE;
+ op_flags[1] = NPY_ITER_READONLY;
+
+ op[0] = out;
+ op[1] = arr;
+
+ need_outer_iterator = (ndim > 1);
+ if (operation == UFUNC_ACCUMULATE) {
+ /* This is because we can't buffer, so must do UPDATEIFCOPY */
+ if (!PyArray_ISALIGNED(arr) || (out && !PyArray_ISALIGNED(out)) ||
+ !PyArray_EquivTypes(op_dtypes[0], PyArray_DESCR(arr)) ||
+ (out &&
+ !PyArray_EquivTypes(op_dtypes[0], PyArray_DESCR(out)))) {
+ need_outer_iterator = 1;
}
- /*
- * Fix iterator to loop over correct dimension
- * Set size in axis dimension to 1
- */
- loop->rit->contiguous = 0;
- loop->rit->size /= (loop->rit->dims_m1[axis] + 1);
- loop->rit->dims_m1[axis] = 0;
- loop->rit->backstrides[axis] = 0;
+ }
- if (operation == UFUNC_ACCUMULATE) {
- loop->steps[0] = loop->ret->strides[axis];
+ if (need_outer_iterator) {
+ int ndim_iter = 0;
+ npy_uint32 flags = NPY_ITER_ZEROSIZE_OK|
+ NPY_ITER_REFS_OK;
+ PyArray_Descr **op_dtypes_param = NULL;
+
+ if (operation == UFUNC_REDUCE) {
+ ndim_iter = ndim - 1;
+ if (out == NULL) {
+ op_dtypes_param = op_dtypes;
+ }
}
- else {
- loop->steps[0] = 0;
+ else if (operation == UFUNC_ACCUMULATE) {
+ /*
+ * The way accumulate is set up, we can't do buffering,
+ * so make a copy instead when necessary.
+ */
+ ndim_iter = ndim;
+ flags |= NPY_ITER_COORDS;
+ /* Add some more flags */
+ op_flags[0] |= NPY_ITER_UPDATEIFCOPY|NPY_ITER_ALIGNED;
+ op_flags[1] |= NPY_ITER_COPY|NPY_ITER_ALIGNED;
+ op_dtypes_param = op_dtypes;
+ op_dtypes[1] = op_dtypes[0];
+ }
+ NPY_UF_DBG_PRINT("Allocating outer iterator\n");
+ iter = NpyIter_MultiNew(2, op, flags,
+ NPY_KEEPORDER, NPY_UNSAFE_CASTING,
+ op_flags,
+ op_dtypes_param,
+ ndim_iter, op_axes, 0);
+ if (iter == NULL) {
+ goto fail;
}
- }
- loop->steps[2] = loop->steps[0];
- loop->bufptr[2] = loop->bufptr[0] + loop->steps[2];
- if (loop->meth == BUFFER_UFUNCLOOP) {
- int _size;
- loop->steps[1] = loop->outsize;
- if (otype != aar->descr->type_num) {
- _size=loop->bufsize*(loop->outsize + aar->descr->elsize);
- loop->buffer = PyDataMem_NEW(_size);
- if (loop->buffer == NULL) {
- goto fail;
+ if (operation == UFUNC_ACCUMULATE) {
+ /* In case COPY or UPDATEIFCOPY occurred */
+ op[0] = NpyIter_GetOperandArray(iter)[0];
+ op[1] = NpyIter_GetOperandArray(iter)[1];
+
+ if (PyArray_SIZE(op[0]) == 0) {
+ if (out == NULL) {
+ out = op[0];
+ Py_INCREF(out);
+ }
+ goto finish;
}
- if (loop->obj & UFUNC_OBJ_ISOBJECT) {
- memset(loop->buffer, 0, _size);
+
+ if (NpyIter_RemoveAxis(iter, axis) != NPY_SUCCEED) {
+ goto fail;
}
- loop->castbuf = loop->buffer + loop->bufsize*aar->descr->elsize;
- loop->bufptr[1] = loop->castbuf;
- loop->cast = PyArray_GetCastFunc(aar->descr, otype);
- if (loop->cast == NULL) {
+ if (NpyIter_RemoveCoords(iter) != NPY_SUCCEED) {
goto fail;
}
}
+ }
+
+ /* Get the output */
+ if (out == NULL) {
+ if (iter) {
+ op[0] = out = NpyIter_GetOperandArray(iter)[0];
+ Py_INCREF(out);
+ }
else {
- _size = loop->bufsize * loop->outsize;
- loop->buffer = PyDataMem_NEW(_size);
- if (loop->buffer == NULL) {
+ PyArray_Descr *dtype = op_dtypes[0];
+ Py_INCREF(dtype);
+ if (operation == UFUNC_REDUCE) {
+ op[0] = out = (PyArrayObject *)PyArray_NewFromDescr(
+ &PyArray_Type, dtype,
+ 0, NULL, NULL, NULL,
+ 0, NULL);
+ }
+ else if (operation == UFUNC_ACCUMULATE) {
+ op[0] = out = (PyArrayObject *)PyArray_NewFromDescr(
+ &PyArray_Type, dtype,
+ ndim, PyArray_DIMS(op[1]), NULL, NULL,
+ 0, NULL);
+ }
+ if (out == NULL) {
goto fail;
}
- if (loop->obj & UFUNC_OBJ_ISOBJECT) {
- memset(loop->buffer, 0, _size);
+ }
+ }
+
+ /*
+ * If the reduction unit has size zero, either return the reduction
+ * unit for UFUNC_REDUCE, or return the zero-sized output array
+ * for UFUNC_ACCUMULATE.
+ */
+ if (PyArray_DIM(op[1], axis) == 0) {
+ if (operation == UFUNC_REDUCE) {
+ if (self->identity == PyUFunc_None) {
+ PyErr_Format(PyExc_ValueError,
+ "zero-size array to %s.%s "
+ "without identity", ufunc_name, opname);
+ goto fail;
+ }
+ if (self->identity == PyUFunc_One) {
+ PyObject *obj = PyInt_FromLong((long) 1);
+ if (obj == NULL) {
+ goto fail;
+ }
+ PyArray_FillWithScalar(op[0], obj);
+ Py_DECREF(obj);
+ } else {
+ PyObject *obj = PyInt_FromLong((long) 0);
+ if (obj == NULL) {
+ goto fail;
+ }
+ PyArray_FillWithScalar(op[0], obj);
+ Py_DECREF(obj);
}
- loop->bufptr[1] = loop->buffer;
}
+
+ goto finish;
+ }
+ else if (PyArray_SIZE(op[0]) == 0) {
+ goto finish;
}
- PyUFunc_clearfperr();
- return loop;
- fail:
- ufuncreduce_dealloc(loop);
- return NULL;
-}
+ /* Only allocate an inner iterator if it's necessary */
+ if (!PyArray_ISALIGNED(op[1]) || !PyArray_ISALIGNED(op[0]) ||
+ !PyArray_EquivTypes(op_dtypes[0], PyArray_DESCR(op[1])) ||
+ !PyArray_EquivTypes(op_dtypes[0], PyArray_DESCR(op[0]))) {
+ /* Also set the dtype for buffering arr */
+ op_dtypes[1] = op_dtypes[0];
+ NPY_UF_DBG_PRINT("Allocating inner iterator\n");
+ if (operation == UFUNC_REDUCE) {
+ /* The per-operand flags for the inner loop */
+ op_flags[0] = NPY_ITER_READWRITE|
+ NPY_ITER_ALIGNED;
+ op_flags[1] = NPY_ITER_READONLY|
+ NPY_ITER_ALIGNED;
-/*
- * We have two basic kinds of loops. One is used when arr is not-swapped
- * and aligned and output type is the same as input type. The other uses
- * buffers when one of these is not satisfied.
- *
- * Zero-length and one-length axes-to-be-reduced are handled separately.
- */
-static PyObject *
-PyUFunc_Reduce(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *out,
- int axis, int otype)
-{
- PyArrayObject *ret = NULL;
- PyUFuncReduceObject *loop;
- intp i, n;
- char *dptr;
- NPY_BEGIN_THREADS_DEF;
+ op_axes[0][0] = -1;
+ op_axes[1][0] = axis;
- /* Construct loop object */
- loop = construct_reduce(self, &arr, out, axis, otype, UFUNC_REDUCE, 0,
- "reduce");
- if (!loop) {
- return NULL;
+ iter_inner = NpyIter_MultiNew(2, op, NPY_ITER_NO_INNER_ITERATION|
+ NPY_ITER_BUFFERED|
+ NPY_ITER_DELAY_BUFALLOC|
+ NPY_ITER_GROWINNER|
+ NPY_ITER_REDUCE_OK|
+ NPY_ITER_REFS_OK,
+ NPY_CORDER, NPY_UNSAFE_CASTING,
+ op_flags, op_dtypes,
+ 1, op_axes, buffersize);
+ }
+ /* Should never get an inner iterator for ACCUMULATE */
+ else {
+ PyErr_SetString(PyExc_RuntimeError,
+ "internal ufunc reduce error, should not need inner iterator");
+ goto fail;
+ }
+ if (iter_inner == NULL) {
+ goto fail;
+ }
}
- NPY_LOOP_BEGIN_THREADS;
- switch(loop->meth) {
- case ZERO_EL_REDUCELOOP:
- /* fprintf(stderr, "ZERO..%d\n", loop->size); */
- for (i = 0; i < loop->size; i++) {
- if (loop->obj & UFUNC_OBJ_ISOBJECT) {
- Py_INCREF(*((PyObject **)loop->idptr));
- }
- memmove(loop->bufptr[0], loop->idptr, loop->outsize);
- loop->bufptr[0] += loop->outsize;
+ if (iter && NpyIter_GetIterSize(iter) != 0) {
+ char *dataptr_copy[3];
+ npy_intp stride_copy[3];
+
+ NpyIter_IterNextFunc *iternext;
+ char **dataptr;
+ npy_intp *stride;
+ npy_intp *count_ptr;
+
+ int itemsize = op_dtypes[0]->elsize;
+
+ /* Get the variables needed for the loop */
+ iternext = NpyIter_GetIterNext(iter, NULL);
+ if (iternext == NULL) {
+ goto fail;
}
- break;
- case ONE_EL_REDUCELOOP:
- /*fprintf(stderr, "ONEDIM..%d\n", loop->size); */
- while (loop->index < loop->size) {
- if (loop->obj & UFUNC_OBJ_ISOBJECT) {
- Py_INCREF(*((PyObject **)loop->it->dataptr));
+ dataptr = NpyIter_GetDataPtrArray(iter);
+ stride = NpyIter_GetInnerStrideArray(iter);
+ count_ptr = NpyIter_GetInnerLoopSizePtr(iter);
+
+
+ /* Execute the loop with two nested iterators */
+ if (iter_inner) {
+ /* Only UFUNC_REDUCE uses iter_inner */
+ NpyIter_IterNextFunc *iternext_inner;
+ char **dataptr_inner;
+ npy_intp *stride_inner;
+ npy_intp count, *count_ptr_inner;
+
+ NPY_UF_DBG_PRINT("UFunc: Reduce loop with two nested iterators\n");
+ iternext_inner = NpyIter_GetIterNext(iter_inner, NULL);
+ if (iternext_inner == NULL) {
+ goto fail;
}
- memmove(loop->bufptr[0], loop->it->dataptr, loop->outsize);
- PyArray_ITER_NEXT(loop->it);
- loop->bufptr[0] += loop->outsize;
- loop->index++;
- }
- break;
- case NOBUFFER_UFUNCLOOP:
- /*fprintf(stderr, "NOBUFFER..%d\n", loop->size); */
- while (loop->index < loop->size) {
- /* Copy first element to output */
- if (loop->obj & UFUNC_OBJ_ISOBJECT) {
- Py_INCREF(*((PyObject **)loop->it->dataptr));
+ dataptr_inner = NpyIter_GetDataPtrArray(iter_inner);
+ stride_inner = NpyIter_GetInnerStrideArray(iter_inner);
+ count_ptr_inner = NpyIter_GetInnerLoopSizePtr(iter_inner);
+
+ needs_api = NpyIter_IterationNeedsAPI(iter) ||
+ NpyIter_IterationNeedsAPI(iter_inner);
+
+ if (!needs_api) {
+ NPY_BEGIN_THREADS;
}
- memmove(loop->bufptr[0], loop->it->dataptr, loop->outsize);
- /* Adjust input pointer */
- loop->bufptr[1] = loop->it->dataptr+loop->steps[1];
- loop->function((char **)loop->bufptr, &(loop->N),
- loop->steps, loop->funcdata);
- UFUNC_CHECK_ERROR(loop);
- PyArray_ITER_NEXT(loop->it);
- loop->bufptr[0] += loop->outsize;
- loop->bufptr[2] = loop->bufptr[0];
- loop->index++;
- }
- break;
- case BUFFER_UFUNCLOOP:
- /*
- * use buffer for arr
- *
- * For each row to reduce
- * 1. copy first item over to output (casting if necessary)
- * 2. Fill inner buffer
- * 3. When buffer is filled or end of row
- * a. Cast input buffers if needed
- * b. Call inner function.
- * 4. Repeat 2 until row is done.
- */
- /* fprintf(stderr, "BUFFERED..%d %d\n", loop->size, loop->swap); */
- while(loop->index < loop->size) {
- loop->inptr = loop->it->dataptr;
- /* Copy (cast) First term over to output */
- if (loop->cast) {
- /* A little tricky because we need to cast it first */
- arr->descr->f->copyswap(loop->buffer, loop->inptr,
- loop->swap, NULL);
- loop->cast(loop->buffer, loop->castbuf, 1, NULL, NULL);
- if (loop->obj & UFUNC_OBJ_ISOBJECT) {
- Py_XINCREF(*((PyObject **)loop->castbuf));
+
+ do {
+ int first = 1;
+
+ /* Reset the inner iterator to the outer's data */
+ if (NpyIter_ResetBasePointers(iter_inner, dataptr, NULL)
+ != NPY_SUCCEED) {
+ goto fail;
}
- memcpy(loop->bufptr[0], loop->castbuf, loop->outsize);
- }
- else {
- /* Simple copy */
- arr->descr->f->copyswap(loop->bufptr[0], loop->inptr,
- loop->swap, NULL);
- }
- loop->inptr += loop->instrides;
- n = 1;
- while(n < loop->N) {
- /* Copy up to loop->bufsize elements to buffer */
- dptr = loop->buffer;
- for (i = 0; i < loop->bufsize; i++, n++) {
- if (n == loop->N) {
- break;
- }
- arr->descr->f->copyswap(dptr, loop->inptr,
- loop->swap, NULL);
- loop->inptr += loop->instrides;
- dptr += loop->insize;
+
+ /* Copy the first element to start the reduction */
+ if (otype == NPY_OBJECT) {
+ Py_XDECREF(*(PyObject **)dataptr_inner[0]);
+ *(PyObject **)dataptr_inner[0] =
+ *(PyObject **)dataptr_inner[1];
+ Py_XINCREF(*(PyObject **)dataptr_inner[0]);
}
- if (loop->cast) {
- loop->cast(loop->buffer, loop->castbuf, i, NULL, NULL);
+ else {
+ memcpy(dataptr_inner[0], dataptr_inner[1], itemsize);
}
- loop->function((char **)loop->bufptr, &i,
- loop->steps, loop->funcdata);
- loop->bufptr[0] += loop->steps[0]*i;
- loop->bufptr[2] += loop->steps[2]*i;
- UFUNC_CHECK_ERROR(loop);
+
+ stride_copy[0] = 0;
+ stride_copy[2] = 0;
+ do {
+ count = *count_ptr_inner;
+ /* Turn the two items into three for the inner loop */
+ dataptr_copy[0] = dataptr_inner[0];
+ dataptr_copy[1] = dataptr_inner[1];
+ dataptr_copy[2] = dataptr_inner[0];
+ if (first) {
+ --count;
+ dataptr_copy[1] += stride_inner[1];
+ first = 0;
+ }
+ stride_copy[1] = stride_inner[1];
+ NPY_UF_DBG_PRINT1("iterator loop count %d\n", (int)count);
+ innerloop(dataptr_copy, &count,
+ stride_copy, innerloopdata);
+ } while(iternext_inner(iter_inner));
+ } while (iternext(iter));
+
+ if (!needs_api) {
+ NPY_END_THREADS;
}
- PyArray_ITER_NEXT(loop->it);
- loop->bufptr[0] += loop->outsize;
- loop->bufptr[2] = loop->bufptr[0];
- loop->index++;
}
+ /* Execute the loop with just the outer iterator */
+ else {
+ npy_intp count_m1 = PyArray_DIM(op[1], axis)-1;
+ npy_intp stride0 = 0, stride1 = PyArray_STRIDE(op[1], axis);
- /*
- * DECREF left-over objects if buffering was used.
- * It is needed when casting created new objects in
- * castbuf. Intermediate copying into castbuf (via
- * loop->function) decref'd what was already there.
+ NPY_UF_DBG_PRINT("UFunc: Reduce loop with just outer iterator\n");
- * It's the final copy into the castbuf that needs a DECREF.
- */
+ if (operation == UFUNC_ACCUMULATE) {
+ stride0 = PyArray_STRIDE(op[0], axis);
+ }
+
+ stride_copy[0] = stride0;
+ stride_copy[1] = stride1;
+ stride_copy[2] = stride0;
- /* Only when casting needed and it is from a non-object array */
- if ((loop->obj & UFUNC_OBJ_ISOBJECT) && loop->cast &&
- (!PyArray_ISOBJECT(arr))) {
- for (i=0; i<loop->bufsize; i++) {
- Py_CLEAR(((PyObject **)loop->castbuf)[i]);
+ needs_api = NpyIter_IterationNeedsAPI(iter);
+
+ if (!needs_api) {
+ NPY_BEGIN_THREADS;
}
- }
- }
- NPY_LOOP_END_THREADS;
- /* Hang on to this reference -- will be decref'd with loop */
- if (loop->retbase) {
- ret = (PyArrayObject *)loop->ret->base;
- }
- else {
- ret = loop->ret;
- }
- Py_INCREF(ret);
- ufuncreduce_dealloc(loop);
- return (PyObject *)ret;
+ do {
-fail:
- NPY_LOOP_END_THREADS;
- if (loop) {
- ufuncreduce_dealloc(loop);
- }
- return NULL;
-}
+ dataptr_copy[0] = dataptr[0];
+ dataptr_copy[1] = dataptr[1];
+ dataptr_copy[2] = dataptr[0];
+ /* Copy the first element to start the reduction */
+ if (otype == NPY_OBJECT) {
+ Py_XDECREF(*(PyObject **)dataptr_copy[0]);
+ *(PyObject **)dataptr_copy[0] =
+ *(PyObject **)dataptr_copy[1];
+ Py_XINCREF(*(PyObject **)dataptr_copy[0]);
+ }
+ else {
+ memcpy(dataptr_copy[0], dataptr_copy[1], itemsize);
+ }
-static PyObject *
-PyUFunc_Accumulate(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *out,
- int axis, int otype)
-{
- PyArrayObject *ret = NULL;
- PyUFuncReduceObject *loop;
- intp i, n;
- char *dptr;
- NPY_BEGIN_THREADS_DEF;
+ if (count_m1 > 0) {
+ /* Turn the two items into three for the inner loop */
+ if (operation == UFUNC_REDUCE) {
+ dataptr_copy[1] += stride1;
+ }
+ else if (operation == UFUNC_ACCUMULATE) {
+ dataptr_copy[1] += stride1;
+ dataptr_copy[2] += stride0;
+ }
+ NPY_UF_DBG_PRINT1("iterator loop count %d\n",
+ (int)count_m1);
+ innerloop(dataptr_copy, &count_m1,
+ stride_copy, innerloopdata);
+ }
+ } while (iternext(iter));
- /* Construct loop object */
- loop = construct_reduce(self, &arr, out, axis, otype,
- UFUNC_ACCUMULATE, 0, "accumulate");
- if (!loop) {
- return NULL;
+ if (!needs_api) {
+ NPY_END_THREADS;
+ }
+ }
}
+ else if (iter == NULL) {
+ char *dataptr_copy[3];
+ npy_intp stride_copy[3];
+
+ int itemsize = op_dtypes[0]->elsize;
+
+ /* Execute the loop with just the inner iterator */
+ if (iter_inner) {
+ /* Only UFUNC_REDUCE uses iter_inner */
+ NpyIter_IterNextFunc *iternext_inner;
+ char **dataptr_inner;
+ npy_intp *stride_inner;
+ npy_intp count, *count_ptr_inner;
+ int first = 1;
+
+ NPY_UF_DBG_PRINT("UFunc: Reduce loop with just inner iterator\n");
- NPY_LOOP_BEGIN_THREADS;
- switch(loop->meth) {
- case ZERO_EL_REDUCELOOP:
- /* Accumulate */
- /* fprintf(stderr, "ZERO..%d\n", loop->size); */
- for (i = 0; i < loop->size; i++) {
- if (loop->obj & UFUNC_OBJ_ISOBJECT) {
- Py_INCREF(*((PyObject **)loop->idptr));
+ iternext_inner = NpyIter_GetIterNext(iter_inner, NULL);
+ if (iternext_inner == NULL) {
+ goto fail;
}
- memcpy(loop->bufptr[0], loop->idptr, loop->outsize);
- loop->bufptr[0] += loop->outsize;
- }
- break;
- case ONE_EL_REDUCELOOP:
- /* Accumulate */
- /* fprintf(stderr, "ONEDIM..%d\n", loop->size); */
- while (loop->index < loop->size) {
- if (loop->obj & UFUNC_OBJ_ISOBJECT) {
- Py_INCREF(*((PyObject **)loop->it->dataptr));
+ dataptr_inner = NpyIter_GetDataPtrArray(iter_inner);
+ stride_inner = NpyIter_GetInnerStrideArray(iter_inner);
+ count_ptr_inner = NpyIter_GetInnerLoopSizePtr(iter_inner);
+
+ /* Reset the inner iterator to prepare the buffers */
+ if (NpyIter_Reset(iter_inner, NULL) != NPY_SUCCEED) {
+ goto fail;
}
- memmove(loop->bufptr[0], loop->it->dataptr, loop->outsize);
- PyArray_ITER_NEXT(loop->it);
- loop->bufptr[0] += loop->outsize;
- loop->index++;
- }
- break;
- case NOBUFFER_UFUNCLOOP:
- /* Accumulate */
- /* fprintf(stderr, "NOBUFFER..%d\n", loop->size); */
- while (loop->index < loop->size) {
- /* Copy first element to output */
- if (loop->obj & UFUNC_OBJ_ISOBJECT) {
- Py_INCREF(*((PyObject **)loop->it->dataptr));
+
+ needs_api = NpyIter_IterationNeedsAPI(iter_inner);
+
+ if (!needs_api) {
+ NPY_BEGIN_THREADS;
+ }
+
+ /* Copy the first element to start the reduction */
+ if (otype == NPY_OBJECT) {
+ Py_XDECREF(*(PyObject **)dataptr_inner[0]);
+ *(PyObject **)dataptr_inner[0] =
+ *(PyObject **)dataptr_inner[1];
+ Py_XINCREF(*(PyObject **)dataptr_inner[0]);
+ }
+ else {
+ memcpy(dataptr_inner[0], dataptr_inner[1], itemsize);
+ }
+
+ stride_copy[0] = 0;
+ stride_copy[2] = 0;
+ do {
+ count = *count_ptr_inner;
+ /* Turn the two items into three for the inner loop */
+ dataptr_copy[0] = dataptr_inner[0];
+ dataptr_copy[1] = dataptr_inner[1];
+ dataptr_copy[2] = dataptr_inner[0];
+ if (first) {
+ --count;
+ dataptr_copy[1] += stride_inner[1];
+ first = 0;
+ }
+ stride_copy[1] = stride_inner[1];
+ NPY_UF_DBG_PRINT1("iterator loop count %d\n", (int)count);
+ innerloop(dataptr_copy, &count,
+ stride_copy, innerloopdata);
+ } while(iternext_inner(iter_inner));
+
+ if (!needs_api) {
+ NPY_END_THREADS;
}
- memmove(loop->bufptr[0], loop->it->dataptr, loop->outsize);
- /* Adjust input pointer */
- loop->bufptr[1] = loop->it->dataptr + loop->steps[1];
- loop->function((char **)loop->bufptr, &(loop->N),
- loop->steps, loop->funcdata);
- UFUNC_CHECK_ERROR(loop);
- PyArray_ITER_NEXT(loop->it);
- PyArray_ITER_NEXT(loop->rit);
- loop->bufptr[0] = loop->rit->dataptr;
- loop->bufptr[2] = loop->bufptr[0] + loop->steps[0];
- loop->index++;
}
- break;
- case BUFFER_UFUNCLOOP:
- /* Accumulate
- *
- * use buffer for arr
- *
- * For each row to reduce
- * 1. copy identity over to output (casting if necessary)
- * 2. Fill inner buffer
- * 3. When buffer is filled or end of row
- * a. Cast input buffers if needed
- * b. Call inner function.
- * 4. Repeat 2 until row is done.
- */
- /* fprintf(stderr, "BUFFERED..%d %p\n", loop->size, loop->cast); */
- while (loop->index < loop->size) {
- loop->inptr = loop->it->dataptr;
- /* Copy (cast) First term over to output */
- if (loop->cast) {
- /* A little tricky because we need to
- cast it first */
- arr->descr->f->copyswap(loop->buffer, loop->inptr,
- loop->swap, NULL);
- loop->cast(loop->buffer, loop->castbuf, 1, NULL, NULL);
- if (loop->obj & UFUNC_OBJ_ISOBJECT) {
- Py_XINCREF(*((PyObject **)loop->castbuf));
+ /* Execute the loop with no iterators */
+ else {
+ npy_intp count = PyArray_DIM(op[1], axis);
+ npy_intp stride0 = 0, stride1 = PyArray_STRIDE(op[1], axis);
+
+ NPY_UF_DBG_PRINT("UFunc: Reduce loop with no iterators\n");
+
+ if (operation == UFUNC_REDUCE) {
+ if (PyArray_NDIM(op[0]) != 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "provided out is the wrong size "
+ "for the reduction");
+ goto fail;
}
- memcpy(loop->bufptr[0], loop->castbuf, loop->outsize);
+ }
+ else if (operation == UFUNC_ACCUMULATE) {
+ if (PyArray_NDIM(op[0]) != PyArray_NDIM(op[1]) ||
+ !PyArray_CompareLists(PyArray_DIMS(op[0]),
+ PyArray_DIMS(op[1]),
+ PyArray_NDIM(op[0]))) {
+ PyErr_SetString(PyExc_ValueError,
+ "provided out is the wrong size "
+ "for the reduction");
+ goto fail;
+ }
+ stride0 = PyArray_STRIDE(op[0], axis);
+ }
+
+ stride_copy[0] = stride0;
+ stride_copy[1] = stride1;
+ stride_copy[2] = stride0;
+
+ /* Turn the two items into three for the inner loop */
+ dataptr_copy[0] = PyArray_BYTES(op[0]);
+ dataptr_copy[1] = PyArray_BYTES(op[1]);
+ dataptr_copy[2] = PyArray_BYTES(op[0]);
+
+ /* Copy the first element to start the reduction */
+ if (otype == NPY_OBJECT) {
+ Py_XDECREF(*(PyObject **)dataptr_copy[0]);
+ *(PyObject **)dataptr_copy[0] =
+ *(PyObject **)dataptr_copy[1];
+ Py_XINCREF(*(PyObject **)dataptr_copy[0]);
}
else {
- /* Simple copy */
- arr->descr->f->copyswap(loop->bufptr[0], loop->inptr,
- loop->swap, NULL);
+ memcpy(dataptr_copy[0], dataptr_copy[1], itemsize);
}
- loop->inptr += loop->instrides;
- n = 1;
- while (n < loop->N) {
- /* Copy up to loop->bufsize elements to buffer */
- dptr = loop->buffer;
- for (i = 0; i < loop->bufsize; i++, n++) {
- if (n == loop->N) {
- break;
- }
- arr->descr->f->copyswap(dptr, loop->inptr,
- loop->swap, NULL);
- loop->inptr += loop->instrides;
- dptr += loop->insize;
+
+ if (count > 1) {
+ --count;
+ if (operation == UFUNC_REDUCE) {
+ dataptr_copy[1] += stride1;
}
- if (loop->cast) {
- loop->cast(loop->buffer, loop->castbuf, i, NULL, NULL);
+ else if (operation == UFUNC_ACCUMULATE) {
+ dataptr_copy[1] += stride1;
+ dataptr_copy[2] += stride0;
}
- loop->function((char **)loop->bufptr, &i,
- loop->steps, loop->funcdata);
- loop->bufptr[0] += loop->steps[0]*i;
- loop->bufptr[2] += loop->steps[2]*i;
- UFUNC_CHECK_ERROR(loop);
- }
- PyArray_ITER_NEXT(loop->it);
- PyArray_ITER_NEXT(loop->rit);
- loop->bufptr[0] = loop->rit->dataptr;
- loop->bufptr[2] = loop->bufptr[0] + loop->steps[0];
- loop->index++;
- }
- /*
- * DECREF left-over objects if buffering was used.
- * It is needed when casting created new objects in
- * castbuf. Intermediate copying into castbuf (via
- * loop->function) decref'd what was already there.
+ NPY_UF_DBG_PRINT1("iterator loop count %d\n", (int)count);
- * It's the final copy into the castbuf that needs a DECREF.
- */
+ needs_api = PyDataType_REFCHK(op_dtypes[0]);
+
+ if (!needs_api) {
+ NPY_BEGIN_THREADS;
+ }
+
+ innerloop(dataptr_copy, &count,
+ stride_copy, innerloopdata);
- /* Only when casting needed and it is from a non-object array */
- if ((loop->obj & UFUNC_OBJ_ISOBJECT) && loop->cast &&
- (!PyArray_ISOBJECT(arr))) {
- for (i=0; i<loop->bufsize; i++) {
- Py_CLEAR(((PyObject **)loop->castbuf)[i]);
+ if (!needs_api) {
+ NPY_END_THREADS;
+ }
}
}
-
}
- NPY_LOOP_END_THREADS;
- /* Hang on to this reference -- will be decref'd with loop */
- if (loop->retbase) {
- ret = (PyArrayObject *)loop->ret->base;
+
+finish:
+ Py_XDECREF(op_dtypes[0]);
+ if (iter != NULL) {
+ NpyIter_Deallocate(iter);
}
- else {
- ret = loop->ret;
+ if (iter_inner != NULL) {
+ NpyIter_Deallocate(iter_inner);
}
- Py_INCREF(ret);
- ufuncreduce_dealloc(loop);
- return (PyObject *)ret;
+ return (PyObject *)out;
- fail:
- NPY_LOOP_END_THREADS;
- if (loop) {
- ufuncreduce_dealloc(loop);
+fail:
+ Py_XDECREF(out);
+ Py_XDECREF(op_dtypes[0]);
+
+ if (iter != NULL) {
+ NpyIter_Deallocate(iter);
}
+ if (iter_inner != NULL) {
+ NpyIter_Deallocate(iter_inner);
+ }
+
+ Py_XDECREF(errobj);
+
return NULL;
}
/*
+ * We have two basic kinds of loops. One is used when arr is not-swapped
+ * and aligned and output type is the same as input type. The other uses
+ * buffers when one of these is not satisfied.
+ *
+ * Zero-length and one-length axes-to-be-reduced are handled separately.
+ */
+static PyObject *
+PyUFunc_Reduce(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *out,
+ int axis, int otype)
+{
+ return PyUFunc_ReductionOp(self, arr, out, axis, otype,
+ UFUNC_REDUCE, "reduce");
+}
+
+
+static PyObject *
+PyUFunc_Accumulate(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *out,
+ int axis, int otype)
+{
+ return PyUFunc_ReductionOp(self, arr, out, axis, otype,
+ UFUNC_ACCUMULATE, "accumulate");
+}
+
+/*
* Reduceat performs a reduce over an axis using the indices as a guide
*
* op.reduceat(array,indices) computes
@@ -3048,156 +3424,341 @@ static PyObject *
PyUFunc_Reduceat(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *ind,
PyArrayObject *out, int axis, int otype)
{
- PyArrayObject *ret;
- PyUFuncReduceObject *loop;
- intp *ptr = (intp *)ind->data;
- intp nn = ind->dimensions[0];
- intp mm = arr->dimensions[axis] - 1;
- intp n, i, j;
- char *dptr;
+ PyArrayObject *op[3];
+ PyArray_Descr *op_dtypes[3] = {NULL, NULL, NULL};
+ int op_axes_arrays[3][NPY_MAXDIMS];
+ int *op_axes[3] = {op_axes_arrays[0], op_axes_arrays[1],
+ op_axes_arrays[2]};
+ npy_uint32 op_flags[3];
+ int i, idim, ndim, otype_final;
+ int needs_api, need_outer_iterator;
+
+ NpyIter *iter = NULL;
+
+ /* The reduceat indices - ind must be validated outside this call */
+ npy_intp *reduceat_ind;
+ npy_intp ind_size, red_axis_size;
+ /* The selected inner loop */
+ PyUFuncGenericFunction innerloop = NULL;
+ void *innerloopdata = NULL;
+
+ char *ufunc_name = self->name ? self->name : "(unknown)";
+ char *opname = "reduceat";
+
+ /* These parameters come from extobj= or from a TLS global */
+ int buffersize = 0, errormask = 0;
+ PyObject *errobj = NULL;
+
NPY_BEGIN_THREADS_DEF;
+ reduceat_ind = (npy_intp *)PyArray_DATA(ind);
+ ind_size = PyArray_DIM(ind, 0);
+ red_axis_size = PyArray_DIM(arr, axis);
+
/* Check for out-of-bounds values in indices array */
- for (i = 0; i<nn; i++) {
- if ((*ptr < 0) || (*ptr > mm)) {
+ for (i = 0; i < ind_size; ++i) {
+ if (reduceat_ind[i] < 0 || reduceat_ind[i] >= red_axis_size) {
PyErr_Format(PyExc_IndexError,
- "index out-of-bounds (0, %d)", (int) mm);
+ "index %d out-of-bounds in %s.%s [0, %d)",
+ (int)reduceat_ind[i], ufunc_name, opname, (int)red_axis_size);
return NULL;
}
- ptr++;
}
- ptr = (intp *)ind->data;
- /* Construct loop object */
- loop = construct_reduce(self, &arr, out, axis, otype,
- UFUNC_REDUCEAT, nn, "reduceat");
- if (!loop) {
+ NPY_UF_DBG_PRINT2("\nEvaluating ufunc %s.%s\n", ufunc_name, opname);
+
+#if 0
+ printf("Doing %s.%s on array with dtype : ", ufunc_name, opname);
+ PyObject_Print((PyObject *)PyArray_DESCR(arr), stdout, 0);
+ printf("\n");
+ printf("Index size is %d\n", (int)ind_size);
+#endif
+
+ if (PyUFunc_GetPyValues(opname, &buffersize, &errormask, &errobj) < 0) {
return NULL;
}
- NPY_LOOP_BEGIN_THREADS;
- switch(loop->meth) {
- case ZERO_EL_REDUCELOOP:
- /* zero-length index -- return array immediately */
- /* fprintf(stderr, "ZERO..\n"); */
- break;
- case NOBUFFER_UFUNCLOOP:
- /* Reduceat
- * NOBUFFER -- behaved array and same type
- */
- /* fprintf(stderr, "NOBUFFER..%d\n", loop->size); */
- while (loop->index < loop->size) {
- ptr = (intp *)ind->data;
- for (i = 0; i < nn; i++) {
- loop->bufptr[1] = loop->it->dataptr + (*ptr)*loop->steps[1];
- if (loop->obj & UFUNC_OBJ_ISOBJECT) {
- Py_XINCREF(*((PyObject **)loop->bufptr[1]));
- }
- memcpy(loop->bufptr[0], loop->bufptr[1], loop->outsize);
- mm = (i == nn - 1 ? arr->dimensions[axis] - *ptr :
- *(ptr + 1) - *ptr) - 1;
- if (mm > 0) {
- loop->bufptr[1] += loop->steps[1];
- loop->bufptr[2] = loop->bufptr[0];
- loop->function((char **)loop->bufptr, &mm,
- loop->steps, loop->funcdata);
- UFUNC_CHECK_ERROR(loop);
- }
- loop->bufptr[0] += loop->ret->strides[axis];
- ptr++;
- }
- PyArray_ITER_NEXT(loop->it);
- PyArray_ITER_NEXT(loop->rit);
- loop->bufptr[0] = loop->rit->dataptr;
- loop->index++;
+ /* Take a reference to out for later returning */
+ Py_XINCREF(out);
+
+ otype_final = otype;
+ if (get_binary_op_function(self, &otype_final,
+ &innerloop, &innerloopdata) < 0) {
+ PyArray_Descr *dtype = PyArray_DescrFromType(otype);
+ PyErr_Format(PyExc_ValueError,
+ "could not find a matching type for %s.%s, "
+ "requested type has type code '%c'",
+ ufunc_name, opname, dtype ? dtype->type : '-');
+ Py_XDECREF(dtype);
+ goto fail;
+ }
+
+ ndim = PyArray_NDIM(arr);
+
+ /* Set up the output data type */
+ op_dtypes[0] = PyArray_DescrFromType(otype_final);
+ if (op_dtypes[0] == NULL) {
+ goto fail;
+ }
+
+#if NPY_UF_DBG_TRACING
+ printf("Found %s.%s inner loop with dtype : ", ufunc_name, opname);
+ PyObject_Print((PyObject *)op_dtypes[0], stdout, 0);
+ printf("\n");
+#endif
+
+ /* Set up the op_axes for the outer loop */
+ for (i = 0, idim = 0; idim < ndim; ++idim) {
+ /* Use the i-th iteration dimension to match up ind */
+ if (idim == axis) {
+ op_axes_arrays[0][idim] = axis;
+ op_axes_arrays[1][idim] = -1;
+ op_axes_arrays[2][idim] = 0;
}
- break;
+ else {
+ op_axes_arrays[0][idim] = idim;
+ op_axes_arrays[1][idim] = idim;
+ op_axes_arrays[2][idim] = -1;
+ }
+ }
+
+ op[0] = out;
+ op[1] = arr;
+ op[2] = ind;
+
+ /* Likewise with accumulate, must do UPDATEIFCOPY */
+ if (out != NULL || ndim > 1 || !PyArray_ISALIGNED(arr) ||
+ !PyArray_EquivTypes(op_dtypes[0], PyArray_DESCR(arr))) {
+ need_outer_iterator = 1;
+ }
- case BUFFER_UFUNCLOOP:
- /* Reduceat
- * BUFFER -- misbehaved array or different types
+ if (need_outer_iterator) {
+ npy_uint32 flags = NPY_ITER_ZEROSIZE_OK|
+ NPY_ITER_REFS_OK|
+ NPY_ITER_COORDS;
+
+ /*
+ * The way reduceat is set up, we can't do buffering,
+ * so make a copy instead when necessary.
*/
- /* fprintf(stderr, "BUFFERED..%d\n", loop->size); */
- while (loop->index < loop->size) {
- ptr = (intp *)ind->data;
- for (i = 0; i < nn; i++) {
- if (loop->obj & UFUNC_OBJ_ISOBJECT) {
- Py_XINCREF(*((PyObject **)loop->idptr));
+
+ /* The per-operand flags for the outer loop */
+ op_flags[0] = NPY_ITER_READWRITE|
+ NPY_ITER_NO_BROADCAST|
+ NPY_ITER_ALLOCATE|
+ NPY_ITER_NO_SUBTYPE|
+ NPY_ITER_UPDATEIFCOPY|
+ NPY_ITER_ALIGNED;
+ op_flags[1] = NPY_ITER_READONLY|
+ NPY_ITER_COPY|
+ NPY_ITER_ALIGNED;
+ op_flags[2] = NPY_ITER_READONLY;
+
+ op_dtypes[1] = op_dtypes[0];
+
+ NPY_UF_DBG_PRINT("Allocating outer iterator\n");
+ iter = NpyIter_MultiNew(3, op, flags,
+ NPY_KEEPORDER, NPY_UNSAFE_CASTING,
+ op_flags,
+ op_dtypes,
+ ndim, op_axes, 0);
+ if (iter == NULL) {
+ goto fail;
+ }
+
+ /* Remove the inner loop axis from the outer iterator */
+ if (NpyIter_RemoveAxis(iter, axis) != NPY_SUCCEED) {
+ goto fail;
+ }
+ if (NpyIter_RemoveCoords(iter) != NPY_SUCCEED) {
+ goto fail;
+ }
+
+ /* In case COPY or UPDATEIFCOPY occurred */
+ op[0] = NpyIter_GetOperandArray(iter)[0];
+ op[1] = NpyIter_GetOperandArray(iter)[1];
+
+ if (out == NULL) {
+ out = op[0];
+ Py_INCREF(out);
+ }
+ }
+ /* Allocate the output for when there's no outer iterator */
+ else if (out == NULL) {
+ Py_INCREF(op_dtypes[0]);
+ op[0] = out = (PyArrayObject *)PyArray_NewFromDescr(
+ &PyArray_Type, op_dtypes[0],
+ 1, &ind_size, NULL, NULL,
+ 0, NULL);
+ if (out == NULL) {
+ goto fail;
+ }
+ }
+
+ /*
+ * If the output has zero elements, return now.
+ */
+ if (PyArray_SIZE(op[0]) == 0) {
+ goto finish;
+ }
+
+ if (iter && NpyIter_GetIterSize(iter) != 0) {
+ char *dataptr_copy[3];
+ npy_intp stride_copy[3];
+
+ NpyIter_IterNextFunc *iternext;
+ char **dataptr;
+ npy_intp count_m1;
+ npy_intp stride0, stride1;
+ npy_intp *stride;
+ npy_intp *count_ptr;
+ npy_intp stride0_ind = PyArray_STRIDE(op[0], axis);
+
+ int itemsize = op_dtypes[0]->elsize;
+
+ /* Get the variables needed for the loop */
+ iternext = NpyIter_GetIterNext(iter, NULL);
+ if (iternext == NULL) {
+ goto fail;
+ }
+ dataptr = NpyIter_GetDataPtrArray(iter);
+ stride = NpyIter_GetInnerStrideArray(iter);
+ count_ptr = NpyIter_GetInnerLoopSizePtr(iter);
+
+
+ /* Execute the loop with just the outer iterator */
+ count_m1 = PyArray_DIM(op[1], axis)-1;
+ stride0 = 0;
+ stride1 = PyArray_STRIDE(op[1], axis);
+
+ NPY_UF_DBG_PRINT("UFunc: Reduce loop with just outer iterator\n");
+
+ stride_copy[0] = stride0;
+ stride_copy[1] = stride1;
+ stride_copy[2] = stride0;
+
+ needs_api = NpyIter_IterationNeedsAPI(iter);
+
+ if (!needs_api) {
+ NPY_BEGIN_THREADS;
+ }
+
+ do {
+
+ for (i = 0; i < ind_size; ++i) {
+ npy_intp start = reduceat_ind[i],
+ end = (i == ind_size-1) ? count_m1+1 :
+ reduceat_ind[i+1];
+ npy_intp count = end - start;
+
+ dataptr_copy[0] = dataptr[0] + stride0_ind*i;
+ dataptr_copy[1] = dataptr[1] + stride1*start;
+ dataptr_copy[2] = dataptr[0] + stride0_ind*i;
+
+ /* Copy the first element to start the reduction */
+ if (otype == NPY_OBJECT) {
+ Py_XDECREF(*(PyObject **)dataptr_copy[0]);
+ *(PyObject **)dataptr_copy[0] =
+ *(PyObject **)dataptr_copy[1];
+ Py_XINCREF(*(PyObject **)dataptr_copy[0]);
}
- memcpy(loop->bufptr[0], loop->idptr, loop->outsize);
- n = 0;
- mm = (i == nn - 1 ? arr->dimensions[axis] - *ptr :
- *(ptr + 1) - *ptr);
- if (mm < 1) {
- mm = 1;
+ else {
+ memcpy(dataptr_copy[0], dataptr_copy[1], itemsize);
}
- loop->inptr = loop->it->dataptr + (*ptr)*loop->instrides;
- while (n < mm) {
- /* Copy up to loop->bufsize elements to buffer */
- dptr = loop->buffer;
- for (j = 0; j < loop->bufsize; j++, n++) {
- if (n == mm) {
- break;
- }
- arr->descr->f->copyswap(dptr, loop->inptr,
- loop->swap, NULL);
- loop->inptr += loop->instrides;
- dptr += loop->insize;
- }
- if (loop->cast) {
- loop->cast(loop->buffer, loop->castbuf, j, NULL, NULL);
- }
- loop->bufptr[2] = loop->bufptr[0];
- loop->function((char **)loop->bufptr, &j,
- loop->steps, loop->funcdata);
- UFUNC_CHECK_ERROR(loop);
- loop->bufptr[0] += j*loop->steps[0];
+
+ if (count > 1) {
+ /* Inner loop like REDUCE */
+ --count;
+ dataptr_copy[1] += stride1;
+ NPY_UF_DBG_PRINT1("iterator loop count %d\n",
+ (int)count);
+ innerloop(dataptr_copy, &count,
+ stride_copy, innerloopdata);
}
- loop->bufptr[0] += loop->ret->strides[axis];
- ptr++;
}
- PyArray_ITER_NEXT(loop->it);
- PyArray_ITER_NEXT(loop->rit);
- loop->bufptr[0] = loop->rit->dataptr;
- loop->index++;
+ } while (iternext(iter));
+
+ if (!needs_api) {
+ NPY_END_THREADS;
}
+ }
+ else if (iter == NULL) {
+ char *dataptr_copy[3];
+ npy_intp stride_copy[3];
- /*
- * DECREF left-over objects if buffering was used.
- * It is needed when casting created new objects in
- * castbuf. Intermediate copying into castbuf (via
- * loop->function) decref'd what was already there.
+ int itemsize = op_dtypes[0]->elsize;
- * It's the final copy into the castbuf that needs a DECREF.
- */
+ npy_intp stride0_ind = PyArray_STRIDE(op[0], axis);
+
+ /* Execute the loop with no iterators */
+ npy_intp stride0 = 0, stride1 = PyArray_STRIDE(op[1], axis);
+
+ needs_api = PyDataType_REFCHK(op_dtypes[0]);
+
+ NPY_UF_DBG_PRINT("UFunc: Reduce loop with no iterators\n");
+
+ stride_copy[0] = stride0;
+ stride_copy[1] = stride1;
+ stride_copy[2] = stride0;
+
+ if (!needs_api) {
+ NPY_BEGIN_THREADS;
+ }
+
+ for (i = 0; i < ind_size; ++i) {
+ npy_intp start = reduceat_ind[i],
+ end = (i == ind_size-1) ? PyArray_DIM(arr,axis) :
+ reduceat_ind[i+1];
+ npy_intp count = end - start;
+
+ dataptr_copy[0] = PyArray_BYTES(op[0]) + stride0_ind*i;
+ dataptr_copy[1] = PyArray_BYTES(op[1]) + stride1*start;
+ dataptr_copy[2] = PyArray_BYTES(op[0]) + stride0_ind*i;
+
+ /* Copy the first element to start the reduction */
+ if (otype == NPY_OBJECT) {
+ Py_XDECREF(*(PyObject **)dataptr_copy[0]);
+ *(PyObject **)dataptr_copy[0] =
+ *(PyObject **)dataptr_copy[1];
+ Py_XINCREF(*(PyObject **)dataptr_copy[0]);
+ }
+ else {
+ memcpy(dataptr_copy[0], dataptr_copy[1], itemsize);
+ }
- /* Only when casting needed and it is from a non-object array */
- if ((loop->obj & UFUNC_OBJ_ISOBJECT) && loop->cast &&
- (!PyArray_ISOBJECT(arr))) {
- for (i=0; i<loop->bufsize; i++) {
- Py_CLEAR(((PyObject **)loop->castbuf)[i]);
+ if (count > 1) {
+ /* Inner loop like REDUCE */
+ --count;
+ dataptr_copy[1] += stride1;
+ NPY_UF_DBG_PRINT1("iterator loop count %d\n",
+ (int)count);
+ innerloop(dataptr_copy, &count,
+ stride_copy, innerloopdata);
}
}
- break;
- }
- NPY_LOOP_END_THREADS;
- /* Hang on to this reference -- will be decref'd with loop */
- if (loop->retbase) {
- ret = (PyArrayObject *)loop->ret->base;
+ if (!needs_api) {
+ NPY_END_THREADS;
+ }
}
- else {
- ret = loop->ret;
+
+finish:
+ Py_XDECREF(op_dtypes[0]);
+ if (iter != NULL) {
+ NpyIter_Deallocate(iter);
}
- Py_INCREF(ret);
- ufuncreduce_dealloc(loop);
- return (PyObject *)ret;
+ return (PyObject *)out;
fail:
- NPY_LOOP_END_THREADS;
- if (loop) {
- ufuncreduce_dealloc(loop);
+ Py_XDECREF(out);
+ Py_XDECREF(op_dtypes[0]);
+
+ if (iter != NULL) {
+ NpyIter_Deallocate(iter);
}
+
+ Py_XDECREF(errobj);
+
return NULL;
}
@@ -3250,10 +3811,8 @@ PyUFunc_GenericReduction(PyUFuncObject *self, PyObject *args,
indtype = PyArray_DescrFromType(PyArray_INTP);
if(!PyArg_ParseTupleAndKeywords(args, kwds, "OO|iO&O&", kwlist2,
&op, &obj_ind, &axis,
- PyArray_DescrConverter2,
- &otype,
- PyArray_OutputConverter,
- &out)) {
+ PyArray_DescrConverter2, &otype,
+ PyArray_OutputConverter, &out)) {
Py_XDECREF(otype);
return NULL;
}
@@ -3267,10 +3826,8 @@ PyUFunc_GenericReduction(PyUFuncObject *self, PyObject *args,
else {
if(!PyArg_ParseTupleAndKeywords(args, kwds, "O|iO&O&", kwlist1,
&op, &axis,
- PyArray_DescrConverter2,
- &otype,
- PyArray_OutputConverter,
- &out)) {
+ PyArray_DescrConverter2, &otype,
+ PyArray_OutputConverter, &out)) {
Py_XDECREF(otype);
return NULL;
}
@@ -3329,7 +3886,7 @@ PyUFunc_GenericReduction(PyUFuncObject *self, PyObject *args,
* is used for add and multiply reduction to avoid overflow
*/
int typenum = PyArray_TYPE(mp);
- if ((typenum < NPY_HALF)
+ if ((PyTypeNum_ISBOOL(typenum) || PyTypeNum_ISINTEGER(typenum))
&& ((strcmp(self->name,"add") == 0)
|| (strcmp(self->name,"multiply") == 0))) {
if (PyTypeNum_ISBOOL(typenum)) {
@@ -3401,7 +3958,8 @@ PyUFunc_GenericReduction(PyUFuncObject *self, PyObject *args,
* should just have PyArray_Return called.
*/
static void
-_find_array_wrap(PyObject *args, PyObject **output_wrap, int nin, int nout)
+_find_array_wrap(PyObject *args, PyObject *kwds,
+ PyObject **output_wrap, int nin, int nout)
{
Py_ssize_t nargs;
int i;
@@ -3471,12 +4029,22 @@ _find_array_wrap(PyObject *args, PyObject **output_wrap, int nin, int nout)
int j = nin + i;
int incref = 1;
output_wrap[i] = wrap;
+ obj = NULL;
if (j < nargs) {
obj = PyTuple_GET_ITEM(args, j);
- if (obj == Py_None) {
- continue;
+ /* Output argument one may also be in a keyword argument */
+ if (i == 0 && obj == Py_None && kwds != NULL) {
+ obj = PyDict_GetItemString(kwds, "out");
}
+ }
+ /* Output argument one may also be in a keyword argument */
+ else if (i == 0 && kwds != NULL) {
+ obj = PyDict_GetItemString(kwds, "out");
+ }
+
+ if (obj != Py_None && obj != NULL) {
if (PyArray_CheckExact(obj)) {
+ /* None signals to not call any wrapping */
output_wrap[i] = Py_None;
}
else {
@@ -3491,6 +4059,7 @@ _find_array_wrap(PyObject *args, PyObject **output_wrap, int nin, int nout)
output_wrap[i] = owrap;
}
}
+
if (incref) {
Py_XINCREF(output_wrap[i]);
}
@@ -3499,6 +4068,7 @@ _find_array_wrap(PyObject *args, PyObject **output_wrap, int nin, int nout)
return;
}
+
static PyObject *
ufunc_generic_call(PyUFuncObject *self, PyObject *args, PyObject *kwds)
{
@@ -3531,13 +4101,17 @@ ufunc_generic_call(PyUFuncObject *self, PyObject *args, PyObject *kwds)
return Py_NotImplemented;
}
else {
- PyErr_SetString(PyExc_NotImplementedError, "Not implemented for this type");
+ PyErr_SetString(PyExc_NotImplementedError,
+ "Not implemented for this type");
return NULL;
}
}
+
+ /* Free the input references */
for (i = 0; i < self->nin; i++) {
Py_DECREF(mps[i]);
}
+
/*
* Use __array_wrap__ on all outputs
* if present on one of the input arguments.
@@ -3555,25 +4129,13 @@ ufunc_generic_call(PyUFuncObject *self, PyObject *args, PyObject *kwds)
* None --- array-object passed in don't call PyArray_Return
* method --- the __array_wrap__ method to call.
*/
- _find_array_wrap(args, wraparr, self->nin, self->nout);
+ _find_array_wrap(args, kwds, wraparr, self->nin, self->nout);
/* wrap outputs */
for (i = 0; i < self->nout; i++) {
int j = self->nin+i;
- PyObject *wrap;
- /*
- * check to see if any UPDATEIFCOPY flags are set
- * which meant that a temporary output was generated
- */
- if (mps[j]->flags & UPDATEIFCOPY) {
- PyObject *old = mps[j]->base;
- /* we want to hang on to this */
- Py_INCREF(old);
- /* should trigger the copyback into old */
- Py_DECREF(mps[j]);
- mps[j] = (PyArrayObject *)old;
- }
- wrap = wraparr[i];
+ PyObject *wrap = wraparr[i];
+
if (wrap != NULL) {
if (wrap == Py_None) {
Py_DECREF(wrap);
diff --git a/numpy/core/src/umath/umath_tests.c.src b/numpy/core/src/umath/umath_tests.c.src
index 1fd27a296..829422090 100644
--- a/numpy/core/src/umath/umath_tests.c.src
+++ b/numpy/core/src/umath/umath_tests.c.src
@@ -313,7 +313,7 @@ initumath_tests(void)
#if defined(NPY_PY3K)
m = PyModule_Create(&moduledef);
-#else
+#else
m = Py_InitModule("umath_tests", UMath_TestsMethods);
#endif
if (m == NULL)
diff --git a/numpy/core/tests/test_blasdot.py b/numpy/core/tests/test_blasdot.py
index 3c04759d5..73c3c4a05 100644
--- a/numpy/core/tests/test_blasdot.py
+++ b/numpy/core/tests/test_blasdot.py
@@ -1,5 +1,8 @@
+import numpy as np
+import sys
from numpy.core import zeros, float64
-from numpy.testing import dec, TestCase, assert_almost_equal, assert_
+from numpy.testing import dec, TestCase, assert_almost_equal, assert_, \
+ assert_raises, assert_array_equal, assert_allclose, assert_equal
from numpy.core.multiarray import inner as inner_
DECPREC = 14
@@ -26,3 +29,63 @@ def test_blasdot_used():
assert_(inner is _dotblas.inner)
assert_(alterdot is _dotblas.alterdot)
assert_(restoredot is _dotblas.restoredot)
+
+
+def test_dot_2args():
+ from numpy.core import dot
+
+ a = np.array([[1, 2], [3, 4]], dtype=float)
+ b = np.array([[1, 0], [1, 1]], dtype=float)
+ c = np.array([[3, 2], [7, 4]], dtype=float)
+
+ d = dot(a, b)
+ assert_allclose(c, d)
+
+def test_dot_3args():
+ np.random.seed(22)
+ f = np.random.random_sample((1024, 16))
+ v = np.random.random_sample((16, 32))
+
+ r = np.empty((1024, 32))
+ for i in xrange(12):
+ np.dot(f,v,r)
+ assert_equal(sys.getrefcount(r), 2)
+ r2 = np.dot(f,v,out=None)
+ assert_array_equal(r2, r)
+ assert_(r is np.dot(f,v,out=r))
+
+ v = v[:,0].copy() # v.shape == (16,)
+ r = r[:,0].copy() # r.shape == (1024,)
+ r2 = np.dot(f,v)
+ assert_(r is np.dot(f,v,r))
+ assert_array_equal(r2, r)
+
+def test_dot_3args_errors():
+ np.random.seed(22)
+ f = np.random.random_sample((1024, 16))
+ v = np.random.random_sample((16, 32))
+
+ r = np.empty((1024, 31))
+ assert_raises(ValueError, np.dot, f, v, r)
+
+ r = np.empty((1024,))
+ assert_raises(ValueError, np.dot, f, v, r)
+
+ r = np.empty((32,))
+ assert_raises(ValueError, np.dot, f, v, r)
+
+ r = np.empty((32, 1024))
+ assert_raises(ValueError, np.dot, f, v, r)
+ assert_raises(ValueError, np.dot, f, v, r.T)
+
+ r = np.empty((1024, 64))
+ assert_raises(ValueError, np.dot, f, v, r[:,::2])
+ assert_raises(ValueError, np.dot, f, v, r[:,:32])
+
+ r = np.empty((1024, 32), dtype=np.float32)
+ assert_raises(ValueError, np.dot, f, v, r)
+
+ r = np.empty((1024, 32), dtype=int)
+ assert_raises(ValueError, np.dot, f, v, r)
+
+
diff --git a/numpy/core/tests/test_datetime.py b/numpy/core/tests/test_datetime.py
index 02131fa3d..9cbfde134 100644
--- a/numpy/core/tests/test_datetime.py
+++ b/numpy/core/tests/test_datetime.py
@@ -12,6 +12,12 @@ class TestDateTime(TestCase):
dt2 = np.dtype('m8[%s]' % unit)
assert dt2 == np.dtype('timedelta64[%s]' % unit)
+
+ def test_hours(self):
+ t = np.ones(3, dtype='M8[s]')
+ t[0] = 60*60*24 + 60*60*10
+ assert t[0].item().hour == 10
+
def test_divisor_conversion_year(self):
assert np.dtype('M8[Y/4]') == np.dtype('M8[3M]')
assert np.dtype('M8[Y/13]') == np.dtype('M8[4W]')
diff --git a/numpy/core/tests/test_einsum.py b/numpy/core/tests/test_einsum.py
new file mode 100644
index 000000000..7f29889c2
--- /dev/null
+++ b/numpy/core/tests/test_einsum.py
@@ -0,0 +1,470 @@
+import sys
+from decimal import Decimal
+
+import numpy as np
+from numpy.testing import *
+from numpy.testing.utils import WarningManager
+import warnings
+
+class TestEinSum(TestCase):
+ def test_einsum_errors(self):
+ # Need enough arguments
+ assert_raises(ValueError, np.einsum)
+ assert_raises(ValueError, np.einsum, "")
+
+ # subscripts must be a string
+ assert_raises(TypeError, np.einsum, 0, 0)
+
+ # out parameter must be an array
+ assert_raises(TypeError, np.einsum, "", 0, out='test')
+
+ # order parameter must be a valid order
+ assert_raises(TypeError, np.einsum, "", 0, order='W')
+
+ # casting parameter must be a valid casting
+ assert_raises(ValueError, np.einsum, "", 0, casting='blah')
+
+ # dtype parameter must be a valid dtype
+ assert_raises(TypeError, np.einsum, "", 0, dtype='bad_data_type')
+
+ # other keyword arguments are rejected
+ assert_raises(TypeError, np.einsum, "", 0, bad_arg=0)
+
+ # number of operands must match count in subscripts string
+ assert_raises(ValueError, np.einsum, "", 0, 0)
+ assert_raises(ValueError, np.einsum, ",", 0, [0], [0])
+ assert_raises(ValueError, np.einsum, ",", [0])
+
+ # can't have more subscripts than dimensions in the operand
+ assert_raises(ValueError, np.einsum, "i", 0)
+ assert_raises(ValueError, np.einsum, "ij", [0,0])
+ assert_raises(ValueError, np.einsum, "...i", 0)
+ assert_raises(ValueError, np.einsum, "i...j", [0,0])
+ assert_raises(ValueError, np.einsum, "i...", 0)
+ assert_raises(ValueError, np.einsum, "ij...", [0,0])
+
+ # invalid ellipsis
+ assert_raises(ValueError, np.einsum, "i..", [0,0])
+ assert_raises(ValueError, np.einsum, ".i...", [0,0])
+ assert_raises(ValueError, np.einsum, "j->..j", [0,0])
+ assert_raises(ValueError, np.einsum, "j->.j...", [0,0])
+
+ # invalid subscript character
+ assert_raises(ValueError, np.einsum, "i%...", [0,0])
+ assert_raises(ValueError, np.einsum, "...j$", [0,0])
+ assert_raises(ValueError, np.einsum, "i->&", [0,0])
+
+ # output subscripts must appear in input
+ assert_raises(ValueError, np.einsum, "i->ij", [0,0])
+
+ # output subscripts may only be specified once
+ assert_raises(ValueError, np.einsum, "ij->jij", [[0,0],[0,0]])
+
+ # dimensions much match when being collapsed
+ assert_raises(ValueError, np.einsum, "ii", np.arange(6).reshape(2,3))
+ assert_raises(ValueError, np.einsum, "ii->i", np.arange(6).reshape(2,3))
+
+ # broadcasting to new dimensions must be enabled explicitly
+ assert_raises(ValueError, np.einsum, "i", np.arange(6).reshape(2,3))
+ assert_raises(ValueError, np.einsum, "i->i", [[0,1],[0,1]],
+ out=np.arange(4).reshape(2,2))
+
+ def test_einsum_views(self):
+ # pass-through
+ a = np.arange(6).reshape(2,3)
+
+ b = np.einsum("...", a)
+ assert_(b.base is a)
+
+ b = np.einsum(a, [Ellipsis])
+ assert_(b.base is a)
+
+ b = np.einsum("ij", a)
+ assert_(b.base is a)
+ assert_equal(b, a)
+
+ b = np.einsum(a, [0,1])
+ assert_(b.base is a)
+ assert_equal(b, a)
+
+ # transpose
+ a = np.arange(6).reshape(2,3)
+
+ b = np.einsum("ji", a)
+ assert_(b.base is a)
+ assert_equal(b, a.T)
+
+ b = np.einsum(a, [1,0])
+ assert_(b.base is a)
+ assert_equal(b, a.T)
+
+ # diagonal
+ a = np.arange(9).reshape(3,3)
+
+ b = np.einsum("ii->i", a)
+ assert_(b.base is a)
+ assert_equal(b, [a[i,i] for i in range(3)])
+
+ b = np.einsum(a, [0,0], [0])
+ assert_(b.base is a)
+ assert_equal(b, [a[i,i] for i in range(3)])
+
+ # diagonal with various ways of broadcasting an additional dimension
+ a = np.arange(27).reshape(3,3,3)
+
+ b = np.einsum("...ii->...i", a)
+ assert_(b.base is a)
+ assert_equal(b, [[x[i,i] for i in range(3)] for x in a])
+
+ b = np.einsum(a, [Ellipsis,0,0], [Ellipsis,0])
+ assert_(b.base is a)
+ assert_equal(b, [[x[i,i] for i in range(3)] for x in a])
+
+ b = np.einsum("ii...->...i", a)
+ assert_(b.base is a)
+ assert_equal(b, [[x[i,i] for i in range(3)]
+ for x in a.transpose(2,0,1)])
+
+ b = np.einsum(a, [0,0,Ellipsis], [Ellipsis,0])
+ assert_(b.base is a)
+ assert_equal(b, [[x[i,i] for i in range(3)]
+ for x in a.transpose(2,0,1)])
+
+ b = np.einsum("...ii->i...", a)
+ assert_(b.base is a)
+ assert_equal(b, [a[:,i,i] for i in range(3)])
+
+ b = np.einsum(a, [Ellipsis,0,0], [0,Ellipsis])
+ assert_(b.base is a)
+ assert_equal(b, [a[:,i,i] for i in range(3)])
+
+ b = np.einsum("jii->ij", a)
+ assert_(b.base is a)
+ assert_equal(b, [a[:,i,i] for i in range(3)])
+
+ b = np.einsum(a, [1,0,0], [0,1])
+ assert_(b.base is a)
+ assert_equal(b, [a[:,i,i] for i in range(3)])
+
+ b = np.einsum("ii...->i...", a)
+ assert_(b.base is a)
+ assert_equal(b, [a.transpose(2,0,1)[:,i,i] for i in range(3)])
+
+ b = np.einsum(a, [0,0,Ellipsis], [0,Ellipsis])
+ assert_(b.base is a)
+ assert_equal(b, [a.transpose(2,0,1)[:,i,i] for i in range(3)])
+
+ b = np.einsum("i...i->i...", a)
+ assert_(b.base is a)
+ assert_equal(b, [a.transpose(1,0,2)[:,i,i] for i in range(3)])
+
+ b = np.einsum(a, [0,Ellipsis,0], [0,Ellipsis])
+ assert_(b.base is a)
+ assert_equal(b, [a.transpose(1,0,2)[:,i,i] for i in range(3)])
+
+ b = np.einsum("i...i->...i", a)
+ assert_(b.base is a)
+ assert_equal(b, [[x[i,i] for i in range(3)]
+ for x in a.transpose(1,0,2)])
+
+ b = np.einsum(a, [0,Ellipsis,0], [Ellipsis,0])
+ assert_(b.base is a)
+ assert_equal(b, [[x[i,i] for i in range(3)]
+ for x in a.transpose(1,0,2)])
+
+ # triple diagonal
+ a = np.arange(27).reshape(3,3,3)
+
+ b = np.einsum("iii->i", a)
+ assert_(b.base is a)
+ assert_equal(b, [a[i,i,i] for i in range(3)])
+
+ b = np.einsum(a, [0,0,0], [0])
+ assert_(b.base is a)
+ assert_equal(b, [a[i,i,i] for i in range(3)])
+
+ # swap axes
+ a = np.arange(24).reshape(2,3,4)
+
+ b = np.einsum("ijk->jik", a)
+ assert_(b.base is a)
+ assert_equal(b, a.swapaxes(0,1))
+
+ b = np.einsum(a, [0,1,2], [1,0,2])
+ assert_(b.base is a)
+ assert_equal(b, a.swapaxes(0,1))
+
+ def check_einsum_sums(self, dtype):
+ # Check various sums. Does many sizes to exercise unrolled loops.
+
+ # sum(a, axis=-1)
+ for n in range(1,17):
+ a = np.arange(n, dtype=dtype)
+ assert_equal(np.einsum("i->", a), np.sum(a, axis=-1).astype(dtype))
+ assert_equal(np.einsum(a, [0], []),
+ np.sum(a, axis=-1).astype(dtype))
+
+ for n in range(1,17):
+ a = np.arange(2*3*n, dtype=dtype).reshape(2,3,n)
+ assert_equal(np.einsum("...i->...", a),
+ np.sum(a, axis=-1).astype(dtype))
+ assert_equal(np.einsum(a, [Ellipsis,0], [Ellipsis]),
+ np.sum(a, axis=-1).astype(dtype))
+
+ # sum(a, axis=0)
+ for n in range(1,17):
+ a = np.arange(2*n, dtype=dtype).reshape(2,n)
+ assert_equal(np.einsum("i...->...", a),
+ np.sum(a, axis=0).astype(dtype))
+ assert_equal(np.einsum(a, [0,Ellipsis], [Ellipsis]),
+ np.sum(a, axis=0).astype(dtype))
+
+ for n in range(1,17):
+ a = np.arange(2*3*n, dtype=dtype).reshape(2,3,n)
+ assert_equal(np.einsum("i...->...", a),
+ np.sum(a, axis=0).astype(dtype))
+ assert_equal(np.einsum(a, [0,Ellipsis], [Ellipsis]),
+ np.sum(a, axis=0).astype(dtype))
+
+ # trace(a)
+ for n in range(1,17):
+ a = np.arange(n*n, dtype=dtype).reshape(n,n)
+ assert_equal(np.einsum("ii", a), np.trace(a).astype(dtype))
+ assert_equal(np.einsum(a, [0,0]), np.trace(a).astype(dtype))
+
+ # multiply(a, b)
+ for n in range(1,17):
+ a = np.arange(3*n, dtype=dtype).reshape(3,n)
+ b = np.arange(2*3*n, dtype=dtype).reshape(2,3,n)
+ assert_equal(np.einsum("..., ...", a, b), np.multiply(a, b))
+ assert_equal(np.einsum(a, [Ellipsis], b, [Ellipsis]),
+ np.multiply(a, b))
+
+ # inner(a,b)
+ for n in range(1,17):
+ a = np.arange(2*3*n, dtype=dtype).reshape(2,3,n)
+ b = np.arange(n, dtype=dtype)
+ assert_equal(np.einsum("...i, ...i", a, b), np.inner(a, b))
+ assert_equal(np.einsum(a, [Ellipsis,0], b, [Ellipsis,0]),
+ np.inner(a, b))
+
+ for n in range(1,11):
+ a = np.arange(n*3*2, dtype=dtype).reshape(n,3,2)
+ b = np.arange(n, dtype=dtype)
+ assert_equal(np.einsum("i..., i...", a, b), np.inner(a.T, b.T).T)
+ assert_equal(np.einsum(a, [0,Ellipsis], b, [0,Ellipsis]),
+ np.inner(a.T, b.T).T)
+
+ # outer(a,b)
+ for n in range(1,17):
+ a = np.arange(3, dtype=dtype)+1
+ b = np.arange(n, dtype=dtype)+1
+ assert_equal(np.einsum("i,j", a, b), np.outer(a, b))
+ assert_equal(np.einsum(a, [0], b, [1]), np.outer(a, b))
+
+ # Suppress the complex warnings for the 'as f8' tests
+ ctx = WarningManager()
+ ctx.__enter__()
+ try:
+ warnings.simplefilter('ignore', np.ComplexWarning)
+
+ # matvec(a,b) / a.dot(b) where a is matrix, b is vector
+ for n in range(1,17):
+ a = np.arange(4*n, dtype=dtype).reshape(4,n)
+ b = np.arange(n, dtype=dtype)
+ assert_equal(np.einsum("ij, j", a, b), np.dot(a, b))
+ assert_equal(np.einsum(a, [0,1], b, [1]), np.dot(a, b))
+
+ c = np.arange(4, dtype=dtype)
+ np.einsum("ij,j", a, b, out=c,
+ dtype='f8', casting='unsafe')
+ assert_equal(c,
+ np.dot(a.astype('f8'),
+ b.astype('f8')).astype(dtype))
+ c[...] = 0
+ np.einsum(a, [0,1], b, [1], out=c,
+ dtype='f8', casting='unsafe')
+ assert_equal(c,
+ np.dot(a.astype('f8'),
+ b.astype('f8')).astype(dtype))
+
+ for n in range(1,17):
+ a = np.arange(4*n, dtype=dtype).reshape(4,n)
+ b = np.arange(n, dtype=dtype)
+ assert_equal(np.einsum("ji,j", a.T, b.T), np.dot(b.T, a.T))
+ assert_equal(np.einsum(a.T, [1,0], b.T, [1]), np.dot(b.T, a.T))
+
+ c = np.arange(4, dtype=dtype)
+ np.einsum("ji,j", a.T, b.T, out=c, dtype='f8', casting='unsafe')
+ assert_equal(c,
+ np.dot(b.T.astype('f8'),
+ a.T.astype('f8')).astype(dtype))
+ c[...] = 0
+ np.einsum(a.T, [1,0], b.T, [1], out=c,
+ dtype='f8', casting='unsafe')
+ assert_equal(c,
+ np.dot(b.T.astype('f8'),
+ a.T.astype('f8')).astype(dtype))
+
+ # matmat(a,b) / a.dot(b) where a is matrix, b is matrix
+ for n in range(1,17):
+ if n < 8 or dtype != 'f2':
+ a = np.arange(4*n, dtype=dtype).reshape(4,n)
+ b = np.arange(n*6, dtype=dtype).reshape(n,6)
+ assert_equal(np.einsum("ij,jk", a, b), np.dot(a, b))
+ assert_equal(np.einsum(a, [0,1], b, [1,2]), np.dot(a, b))
+
+ for n in range(1,17):
+ a = np.arange(4*n, dtype=dtype).reshape(4,n)
+ b = np.arange(n*6, dtype=dtype).reshape(n,6)
+ c = np.arange(24, dtype=dtype).reshape(4,6)
+ np.einsum("ij,jk", a, b, out=c, dtype='f8', casting='unsafe')
+ assert_equal(c,
+ np.dot(a.astype('f8'),
+ b.astype('f8')).astype(dtype))
+ c[...] = 0
+ np.einsum(a, [0,1], b, [1,2], out=c,
+ dtype='f8', casting='unsafe')
+ assert_equal(c,
+ np.dot(a.astype('f8'),
+ b.astype('f8')).astype(dtype))
+
+ # matrix triple product (note this is not currently an efficient
+ # way to multiply 3 matrices)
+ a = np.arange(12, dtype=dtype).reshape(3,4)
+ b = np.arange(20, dtype=dtype).reshape(4,5)
+ c = np.arange(30, dtype=dtype).reshape(5,6)
+ if dtype != 'f2':
+ assert_equal(np.einsum("ij,jk,kl", a, b, c),
+ a.dot(b).dot(c))
+ assert_equal(np.einsum(a, [0,1], b, [1,2], c, [2,3]),
+ a.dot(b).dot(c))
+
+ d = np.arange(18, dtype=dtype).reshape(3,6)
+ np.einsum("ij,jk,kl", a, b, c, out=d,
+ dtype='f8', casting='unsafe')
+ assert_equal(d, a.astype('f8').dot(b.astype('f8')
+ ).dot(c.astype('f8')).astype(dtype))
+ d[...] = 0
+ np.einsum(a, [0,1], b, [1,2], c, [2,3], out=d,
+ dtype='f8', casting='unsafe')
+ assert_equal(d, a.astype('f8').dot(b.astype('f8')
+ ).dot(c.astype('f8')).astype(dtype))
+
+ # tensordot(a, b)
+ if np.dtype(dtype) != np.dtype('f2'):
+ a = np.arange(60, dtype=dtype).reshape(3,4,5)
+ b = np.arange(24, dtype=dtype).reshape(4,3,2)
+ assert_equal(np.einsum("ijk, jil -> kl", a, b),
+ np.tensordot(a,b, axes=([1,0],[0,1])))
+ assert_equal(np.einsum(a, [0,1,2], b, [1,0,3], [2,3]),
+ np.tensordot(a,b, axes=([1,0],[0,1])))
+
+ c = np.arange(10, dtype=dtype).reshape(5,2)
+ np.einsum("ijk,jil->kl", a, b, out=c,
+ dtype='f8', casting='unsafe')
+ assert_equal(c, np.tensordot(a.astype('f8'), b.astype('f8'),
+ axes=([1,0],[0,1])).astype(dtype))
+ c[...] = 0
+ np.einsum(a, [0,1,2], b, [1,0,3], [2,3], out=c,
+ dtype='f8', casting='unsafe')
+ assert_equal(c, np.tensordot(a.astype('f8'), b.astype('f8'),
+ axes=([1,0],[0,1])).astype(dtype))
+ finally:
+ ctx.__exit__()
+
+ # logical_and(logical_and(a!=0, b!=0), c!=0)
+ a = np.array([1, 3, -2, 0, 12, 13, 0, 1], dtype=dtype)
+ b = np.array([0, 3.5, 0., -2, 0, 1, 3, 12], dtype=dtype)
+ c = np.array([True,True,False,True,True,False,True,True])
+ assert_equal(np.einsum("i,i,i->i", a, b, c,
+ dtype='?', casting='unsafe'),
+ np.logical_and(np.logical_and(a!=0, b!=0), c!=0))
+ assert_equal(np.einsum(a, [0], b, [0], c, [0], [0],
+ dtype='?', casting='unsafe'),
+ np.logical_and(np.logical_and(a!=0, b!=0), c!=0))
+
+ a = np.arange(9, dtype=dtype)
+ assert_equal(np.einsum(",i->", 3, a), 3*np.sum(a))
+ assert_equal(np.einsum(3, [], a, [0], []), 3*np.sum(a))
+ assert_equal(np.einsum("i,->", a, 3), 3*np.sum(a))
+ assert_equal(np.einsum(a, [0], 3, [], []), 3*np.sum(a))
+
+ # Various stride0, contiguous, and SSE aligned variants
+ for n in range(1,25):
+ a = np.arange(n, dtype=dtype)
+ if np.dtype(dtype).itemsize > 1:
+ assert_equal(np.einsum("...,...",a,a), np.multiply(a,a))
+ assert_equal(np.einsum("i,i", a, a), np.dot(a,a))
+ assert_equal(np.einsum("i,->i", a, 2), 2*a)
+ assert_equal(np.einsum(",i->i", 2, a), 2*a)
+ assert_equal(np.einsum("i,->", a, 2), 2*np.sum(a))
+ assert_equal(np.einsum(",i->", 2, a), 2*np.sum(a))
+
+ assert_equal(np.einsum("...,...",a[1:],a[:-1]),
+ np.multiply(a[1:],a[:-1]))
+ assert_equal(np.einsum("i,i", a[1:], a[:-1]),
+ np.dot(a[1:],a[:-1]))
+ assert_equal(np.einsum("i,->i", a[1:], 2), 2*a[1:])
+ assert_equal(np.einsum(",i->i", 2, a[1:]), 2*a[1:])
+ assert_equal(np.einsum("i,->", a[1:], 2), 2*np.sum(a[1:]))
+ assert_equal(np.einsum(",i->", 2, a[1:]), 2*np.sum(a[1:]))
+
+ # An object array, summed as the data type
+ a = np.arange(9, dtype=object)
+
+ b = np.einsum("i->", a, dtype=dtype, casting='unsafe')
+ assert_equal(b, np.sum(a))
+ assert_equal(b.dtype, np.dtype(dtype))
+
+ b = np.einsum(a, [0], [], dtype=dtype, casting='unsafe')
+ assert_equal(b, np.sum(a))
+ assert_equal(b.dtype, np.dtype(dtype))
+
+ def test_einsum_sums_int8(self):
+ self.check_einsum_sums('i1');
+
+ def test_einsum_sums_uint8(self):
+ self.check_einsum_sums('u1');
+
+ def test_einsum_sums_int16(self):
+ self.check_einsum_sums('i2');
+
+ def test_einsum_sums_uint16(self):
+ self.check_einsum_sums('u2');
+
+ def test_einsum_sums_int32(self):
+ self.check_einsum_sums('i4');
+
+ def test_einsum_sums_uint32(self):
+ self.check_einsum_sums('u4');
+
+ def test_einsum_sums_int64(self):
+ self.check_einsum_sums('i8');
+
+ def test_einsum_sums_uint64(self):
+ self.check_einsum_sums('u8');
+
+ def test_einsum_sums_float16(self):
+ self.check_einsum_sums('f2');
+
+ def test_einsum_sums_float32(self):
+ self.check_einsum_sums('f4');
+
+ def test_einsum_sums_float64(self):
+ self.check_einsum_sums('f8');
+
+ def test_einsum_sums_longdouble(self):
+ self.check_einsum_sums(np.longdouble);
+
+ def test_einsum_sums_cfloat64(self):
+ self.check_einsum_sums('c8');
+
+ def test_einsum_sums_cfloat128(self):
+ self.check_einsum_sums('c16');
+
+ def test_einsum_sums_clongdouble(self):
+ self.check_einsum_sums(np.clongdouble);
+
+if __name__ == "__main__":
+ run_module_suite()
diff --git a/numpy/core/tests/test_errstate.py b/numpy/core/tests/test_errstate.py
index c8e2b708f..732bb3e93 100644
--- a/numpy/core/tests/test_errstate.py
+++ b/numpy/core/tests/test_errstate.py
@@ -25,7 +25,7 @@ class TestErrstate(TestCase):
except FloatingPointError:
pass
else:
- self.fail()
+ self.fail("Did not raise an invalid error")
def test_divide(self):
with errstate(all='raise', under='ignore'):
@@ -39,7 +39,7 @@ class TestErrstate(TestCase):
except FloatingPointError:
pass
else:
- self.fail()
+ self.fail("Did not raise divide by zero error")
def test_errcall(self):
def foo(*args):
diff --git a/numpy/core/tests/test_half.py b/numpy/core/tests/test_half.py
index 409e50e92..37fce6460 100644
--- a/numpy/core/tests/test_half.py
+++ b/numpy/core/tests/test_half.py
@@ -67,32 +67,37 @@ class TestHalf(TestCase):
assert_equal(i_int,j)
def test_nans_infs(self):
- # Check some of the ufuncs
- assert_equal(np.isnan(self.all_f16), np.isnan(self.all_f32))
- assert_equal(np.isinf(self.all_f16), np.isinf(self.all_f32))
- assert_equal(np.isfinite(self.all_f16), np.isfinite(self.all_f32))
- assert_equal(np.signbit(self.all_f16), np.signbit(self.all_f32))
+ oldsettings = np.seterr(all='ignore')
+ try:
+ # Check some of the ufuncs
+ assert_equal(np.isnan(self.all_f16), np.isnan(self.all_f32))
+ assert_equal(np.isinf(self.all_f16), np.isinf(self.all_f32))
+ assert_equal(np.isfinite(self.all_f16), np.isfinite(self.all_f32))
+ assert_equal(np.signbit(self.all_f16), np.signbit(self.all_f32))
+ assert_equal(np.spacing(float16(65504)), np.inf)
- # Check comparisons of all values with NaN
- nan = float16(np.nan)
+ # Check comparisons of all values with NaN
+ nan = float16(np.nan)
- assert_(not (self.all_f16 == nan).any())
- assert_(not (nan == self.all_f16).any())
+ assert_(not (self.all_f16 == nan).any())
+ assert_(not (nan == self.all_f16).any())
- assert_((self.all_f16 != nan).all())
- assert_((nan != self.all_f16).all())
+ assert_((self.all_f16 != nan).all())
+ assert_((nan != self.all_f16).all())
- assert_(not (self.all_f16 < nan).any())
- assert_(not (nan < self.all_f16).any())
+ assert_(not (self.all_f16 < nan).any())
+ assert_(not (nan < self.all_f16).any())
- assert_(not (self.all_f16 <= nan).any())
- assert_(not (nan <= self.all_f16).any())
+ assert_(not (self.all_f16 <= nan).any())
+ assert_(not (nan <= self.all_f16).any())
- assert_(not (self.all_f16 > nan).any())
- assert_(not (nan > self.all_f16).any())
+ assert_(not (self.all_f16 > nan).any())
+ assert_(not (nan > self.all_f16).any())
- assert_(not (self.all_f16 >= nan).any())
- assert_(not (nan >= self.all_f16).any())
+ assert_(not (self.all_f16 >= nan).any())
+ assert_(not (nan >= self.all_f16).any())
+ finally:
+ np.seterr(**oldsettings)
def test_half_values(self):
@@ -396,10 +401,10 @@ class TestHalf(TestCase):
float16(-65504), float16(17))
assert_raises_fpe('overflow', np.nextafter, float16(65504), float16(np.inf))
assert_raises_fpe('overflow', np.nextafter, float16(-65504), float16(-np.inf))
+ assert_raises_fpe('overflow', np.spacing, float16(65504))
# Invalid value errors
assert_raises_fpe('invalid', np.divide, float16(np.inf), float16(np.inf))
- assert_raises_fpe('invalid', np.spacing, float16(65504))
assert_raises_fpe('invalid', np.spacing, float16(np.inf))
assert_raises_fpe('invalid', np.spacing, float16(np.nan))
assert_raises_fpe('invalid', np.nextafter, float16(np.inf), float16(0))
diff --git a/numpy/core/tests/test_memmap.py b/numpy/core/tests/test_memmap.py
index 9e3cf2039..18b356ce2 100644
--- a/numpy/core/tests/test_memmap.py
+++ b/numpy/core/tests/test_memmap.py
@@ -4,7 +4,7 @@ import warnings
from numpy import memmap
from numpy import arange, allclose
-from numpy.testing import *
+from numpy.testing import TestCase, assert_, assert_array_equal
class TestMemmap(TestCase):
def setUp(self):
@@ -27,7 +27,7 @@ class TestMemmap(TestCase):
# Read data back from file
newfp = memmap(self.tmpfp, dtype=self.dtype, mode='r',
shape=self.shape)
- assert allclose(self.data, newfp)
+ assert_(allclose(self.data, newfp))
assert_array_equal(self.data, newfp)
def test_open_with_filename(self):
@@ -71,10 +71,6 @@ class TestMemmap(TestCase):
fp[:] = self.data[:]
fp.flush()
- warnings.simplefilter('ignore', DeprecationWarning)
- fp.sync()
- warnings.simplefilter('default', DeprecationWarning)
-
def test_del(self):
# Make sure a view does not delete the underlying mmap
fp_base = memmap(self.tmpfp, dtype=self.dtype, mode='w+',
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index b3bf209a1..2f3575649 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -239,6 +239,53 @@ class TestScalarIndexing(TestCase):
self.assertRaises(IndexError, subscript, a, (newaxis, 0))
self.assertRaises(IndexError, subscript, a, (newaxis,)*50)
+ def test_overlapping_assignment(self):
+ # With positive strides
+ a = np.arange(4)
+ a[:-1] = a[1:]
+ assert_equal(a, [1,2,3,3])
+
+ a = np.arange(4)
+ a[1:] = a[:-1]
+ assert_equal(a, [0,0,1,2])
+
+ # With positive and negative strides
+ a = np.arange(4)
+ a[:] = a[::-1]
+ assert_equal(a, [3,2,1,0])
+
+ a = np.arange(6).reshape(2,3)
+ a[::-1,:] = a[:,::-1]
+ assert_equal(a, [[5,4,3],[2,1,0]])
+
+ a = np.arange(6).reshape(2,3)
+ a[::-1,::-1] = a[:,::-1]
+ assert_equal(a, [[3,4,5],[0,1,2]])
+
+ # With just one element overlapping
+ a = np.arange(5)
+ a[:3] = a[2:]
+ assert_equal(a, [2,3,4,3,4])
+
+ a = np.arange(5)
+ a[2:] = a[:3]
+ assert_equal(a, [0,1,0,1,2])
+
+ a = np.arange(5)
+ a[2::-1] = a[2:]
+ assert_equal(a, [4,3,2,3,4])
+
+ a = np.arange(5)
+ a[2:] = a[2::-1]
+ assert_equal(a, [0,1,2,1,0])
+
+ a = np.arange(5)
+ a[2::-1] = a[:1:-1]
+ assert_equal(a, [2,3,4,3,4])
+
+ a = np.arange(5)
+ a[:1:-1] = a[2::-1]
+ assert_equal(a, [0,1,0,1,2])
class TestCreation(TestCase):
def test_from_attribute(self):
@@ -255,6 +302,35 @@ class TestCreation(TestCase):
msg = 'String conversion for %s' % type
assert_equal(array(nstr, dtype=type), result, err_msg=msg)
+ def test_non_sequence_sequence(self):
+ """Should not segfault.
+
+ Class Fail breaks the sequence protocol for new style classes, i.e.,
+ those derived from object. Class Map is a mapping type indicated by
+ raising a ValueError. At some point we may raise a warning instead
+ of an error in the Fail case.
+
+ """
+ class Fail(object):
+ def __len__(self):
+ return 1
+
+ def __getitem__(self, index):
+ raise ValueError()
+
+ class Map(object):
+ def __len__(self):
+ return 1
+
+ def __getitem__(self, index):
+ raise KeyError()
+
+ a = np.array([Map()])
+ assert_(a.shape == (1,))
+ assert_(a.dtype == np.dtype(object))
+ assert_raises(ValueError, np.array, [Fail()])
+
+
class TestStructured(TestCase):
def test_subarray_field_access(self):
a = np.zeros((3, 5), dtype=[('a', ('i4', (2, 2)))])
@@ -594,6 +670,14 @@ class TestMethods(TestCase):
msg = "Test complex searchsorted with nans, side='r'"
b = a.searchsorted(a, side='r')
assert_equal(b, np.arange(1,10), msg)
+ msg = "Test searchsorted with little endian, side='l'"
+ a = np.array([0,128],dtype='<i4')
+ b = a.searchsorted(np.array(128,dtype='<i4'))
+ assert_equal(b, 1, msg)
+ msg = "Test searchsorted with big endian, side='l'"
+ a = np.array([0,128],dtype='>i4')
+ b = a.searchsorted(np.array(128,dtype='>i4'))
+ assert_equal(b, 1, msg)
def test_flatten(self):
x0 = np.array([[1,2,3],[4,5,6]], np.int32)
@@ -620,18 +704,51 @@ class TestMethods(TestCase):
def test_ravel(self):
a = np.array([[0,1],[2,3]])
assert_equal(a.ravel(), [0,1,2,3])
+ assert_(not a.ravel().flags.owndata)
assert_equal(a.ravel('F'), [0,2,1,3])
assert_equal(a.ravel(order='C'), [0,1,2,3])
assert_equal(a.ravel(order='F'), [0,2,1,3])
assert_equal(a.ravel(order='A'), [0,1,2,3])
+ assert_(not a.ravel(order='A').flags.owndata)
+ assert_equal(a.ravel(order='K'), [0,1,2,3])
+ assert_(not a.ravel(order='K').flags.owndata)
assert_equal(a.ravel(), a.reshape(-1))
a = np.array([[0,1],[2,3]], order='F')
assert_equal(a.ravel(), [0,1,2,3])
assert_equal(a.ravel(order='A'), [0,2,1,3])
+ assert_equal(a.ravel(order='K'), [0,2,1,3])
+ assert_(not a.ravel(order='A').flags.owndata)
+ assert_(not a.ravel(order='K').flags.owndata)
assert_equal(a.ravel(), a.reshape(-1))
assert_equal(a.ravel(order='A'), a.reshape(-1, order='A'))
+ a = np.array([[0,1],[2,3]])[::-1,:]
+ assert_equal(a.ravel(), [2,3,0,1])
+ assert_equal(a.ravel(order='C'), [2,3,0,1])
+ assert_equal(a.ravel(order='F'), [2,0,3,1])
+ assert_equal(a.ravel(order='A'), [2,3,0,1])
+ # 'K' doesn't reverse the axes of negative strides
+ assert_equal(a.ravel(order='K'), [2,3,0,1])
+ assert_(a.ravel(order='K').flags.owndata)
+
+ def test_setasflat(self):
+ # In this case, setasflat can treat a as a flat array,
+ # and must treat b in chunks of 3
+ a = np.arange(3*3*4).reshape(3,3,4)
+ b = np.arange(3*4*3, dtype='f4').reshape(3,4,3).T
+
+ assert_(not np.all(a.ravel() == b.ravel()))
+ a.setasflat(b)
+ assert_equal(a.ravel(), b.ravel())
+
+ # A case where the strides of neither a nor b can be collapsed
+ a = np.arange(3*2*4).reshape(3,2,4)[:,:,:-1]
+ b = np.arange(3*3*3, dtype='f4').reshape(3,3,3).T[:,:,:-1]
+
+ assert_(not np.all(a.ravel() == b.ravel()))
+ a.setasflat(b)
+ assert_equal(a.ravel(), b.ravel())
class TestSubscripting(TestCase):
def test_test_zero_rank(self):
@@ -1088,6 +1205,31 @@ class TestIO(object):
array([1,2,3,4]),
dtype='<f4')
+ @dec.slow # takes > 1 minute on mechanical hard drive
+ def test_big_binary(self):
+ """Test workarounds for 32-bit limited fwrite, fseek, and ftell
+ calls in windows. These normally would hang doing something like this.
+ See http://projects.scipy.org/numpy/ticket/1660"""
+ if sys.platform != 'win32':
+ return
+ try:
+ # before workarounds, only up to 2**32-1 worked
+ fourgbplus = 2**32 + 2**16
+ testbytes = np.arange(8, dtype=np.int8)
+ n = len(testbytes)
+ flike = tempfile.NamedTemporaryFile()
+ f = flike.file
+ np.tile(testbytes, fourgbplus // testbytes.nbytes).tofile(f)
+ flike.seek(0)
+ a = np.fromfile(f, dtype=np.int8)
+ flike.close()
+ assert_(len(a) == fourgbplus)
+ # check only start and end for speed:
+ assert_((a[:n] == testbytes).all())
+ assert_((a[-n:] == testbytes).all())
+ except MemoryError:
+ pass
+
def test_string(self):
self._check_from('1,2,3,4', [1., 2., 3., 4.], sep=',')
@@ -1117,6 +1259,17 @@ class TestIO(object):
v = np.array([1,2,3,4], dtype=np.int_)
self._check_from('1,2,3,4', v, sep=',', dtype=np.int_)
+ def test_dtype_bool(self):
+ # can't use _check_from because fromstring can't handle True/False
+ v = np.array([True, False, True, False], dtype=np.bool_)
+ s = '1,0,-2.3,0'
+ f = open(self.filename, 'wb')
+ f.write(asbytes(s))
+ f.close()
+ y = np.fromfile(self.filename, sep=',', dtype=np.bool_)
+ assert_(y.dtype == '?')
+ assert_array_equal(y, v)
+
def test_tofile_sep(self):
x = np.array([1.51, 2, 3.51, 4], dtype=float)
f = open(self.filename, 'w')
@@ -1274,6 +1427,68 @@ class TestStats(TestCase):
res = dat.var(1)
assert res.info == dat.info
+class TestDot(TestCase):
+ def test_dot_2args(self):
+ from numpy.core.multiarray import dot
+
+ a = np.array([[1, 2], [3, 4]], dtype=float)
+ b = np.array([[1, 0], [1, 1]], dtype=float)
+ c = np.array([[3, 2], [7, 4]], dtype=float)
+
+ d = dot(a, b)
+ assert_allclose(c, d)
+
+ def test_dot_3args(self):
+ from numpy.core.multiarray import dot
+
+ np.random.seed(22)
+ f = np.random.random_sample((1024, 16))
+ v = np.random.random_sample((16, 32))
+
+ r = np.empty((1024, 32))
+ for i in xrange(12):
+ dot(f,v,r)
+ assert_equal(sys.getrefcount(r), 2)
+ r2 = dot(f,v,out=None)
+ assert_array_equal(r2, r)
+ assert_(r is dot(f,v,out=r))
+
+ v = v[:,0].copy() # v.shape == (16,)
+ r = r[:,0].copy() # r.shape == (1024,)
+ r2 = dot(f,v)
+ assert_(r is dot(f,v,r))
+ assert_array_equal(r2, r)
+
+ def test_dot_3args_errors(self):
+ from numpy.core.multiarray import dot
+
+ np.random.seed(22)
+ f = np.random.random_sample((1024, 16))
+ v = np.random.random_sample((16, 32))
+
+ r = np.empty((1024, 31))
+ assert_raises(ValueError, dot, f, v, r)
+
+ r = np.empty((1024,))
+ assert_raises(ValueError, dot, f, v, r)
+
+ r = np.empty((32,))
+ assert_raises(ValueError, dot, f, v, r)
+
+ r = np.empty((32, 1024))
+ assert_raises(ValueError, dot, f, v, r)
+ assert_raises(ValueError, dot, f, v, r.T)
+
+ r = np.empty((1024, 64))
+ assert_raises(ValueError, dot, f, v, r[:,::2])
+ assert_raises(ValueError, dot, f, v, r[:,:32])
+
+ r = np.empty((1024, 32), dtype=np.float32)
+ assert_raises(ValueError, dot, f, v, r)
+
+ r = np.empty((1024, 32), dtype=int)
+ assert_raises(ValueError, dot, f, v, r)
+
class TestSummarization(TestCase):
def test_1d(self):
@@ -1329,23 +1544,23 @@ class TestNeighborhoodIter(TestCase):
def _test_simple2d(self, dt):
# Test zero and one padding for simple data type
x = np.array([[0, 1], [2, 3]], dtype=dt)
- r = [np.array([[0, 0, 0], [0, 0, 1]], dtype=dt),
- np.array([[0, 0, 0], [0, 1, 0]], dtype=dt),
- np.array([[0, 0, 1], [0, 2, 3]], dtype=dt),
+ r = [np.array([[0, 0, 0], [0, 0, 1]], dtype=dt),
+ np.array([[0, 0, 0], [0, 1, 0]], dtype=dt),
+ np.array([[0, 0, 1], [0, 2, 3]], dtype=dt),
np.array([[0, 1, 0], [2, 3, 0]], dtype=dt)]
l = test_neighborhood_iterator(x, [-1, 0, -1, 1], x[0], NEIGH_MODE['zero'])
assert_array_equal(l, r)
- r = [np.array([[1, 1, 1], [1, 0, 1]], dtype=dt),
- np.array([[1, 1, 1], [0, 1, 1]], dtype=dt),
- np.array([[1, 0, 1], [1, 2, 3]], dtype=dt),
+ r = [np.array([[1, 1, 1], [1, 0, 1]], dtype=dt),
+ np.array([[1, 1, 1], [0, 1, 1]], dtype=dt),
+ np.array([[1, 0, 1], [1, 2, 3]], dtype=dt),
np.array([[0, 1, 1], [2, 3, 1]], dtype=dt)]
l = test_neighborhood_iterator(x, [-1, 0, -1, 1], x[0], NEIGH_MODE['one'])
assert_array_equal(l, r)
- r = [np.array([[4, 4, 4], [4, 0, 1]], dtype=dt),
- np.array([[4, 4, 4], [0, 1, 4]], dtype=dt),
- np.array([[4, 0, 1], [4, 2, 3]], dtype=dt),
+ r = [np.array([[4, 4, 4], [4, 0, 1]], dtype=dt),
+ np.array([[4, 4, 4], [0, 1, 4]], dtype=dt),
+ np.array([[4, 0, 1], [4, 2, 3]], dtype=dt),
np.array([[0, 1, 4], [2, 3, 4]], dtype=dt)]
l = test_neighborhood_iterator(x, [-1, 0, -1, 1], 4, NEIGH_MODE['constant'])
assert_array_equal(l, r)
@@ -1362,9 +1577,9 @@ class TestNeighborhoodIter(TestCase):
def _test_mirror2d(self, dt):
x = np.array([[0, 1], [2, 3]], dtype=dt)
- r = [np.array([[0, 0, 1], [0, 0, 1]], dtype=dt),
- np.array([[0, 1, 1], [0, 1, 1]], dtype=dt),
- np.array([[0, 0, 1], [2, 2, 3]], dtype=dt),
+ r = [np.array([[0, 0, 1], [0, 0, 1]], dtype=dt),
+ np.array([[0, 1, 1], [0, 1, 1]], dtype=dt),
+ np.array([[0, 0, 1], [2, 2, 3]], dtype=dt),
np.array([[0, 1, 1], [2, 3, 3]], dtype=dt)]
l = test_neighborhood_iterator(x, [-1, 0, -1, 1], x[0], NEIGH_MODE['mirror'])
assert_array_equal(l, r)
diff --git a/numpy/core/tests/test_new_iterator.py b/numpy/core/tests/test_new_iterator.py
new file mode 100644
index 000000000..404735223
--- /dev/null
+++ b/numpy/core/tests/test_new_iterator.py
@@ -0,0 +1,2206 @@
+import numpy as np
+from numpy import array, arange, newiter, all
+from numpy.compat import asbytes
+from numpy.testing import *
+import sys, warnings
+
+import warnings
+
+def iter_coords(i):
+ ret = []
+ while not i.finished:
+ ret.append(i.coords)
+ i.iternext()
+ return ret
+
+def iter_indices(i):
+ ret = []
+ while not i.finished:
+ ret.append(i.index)
+ i.iternext()
+ return ret
+
+def iter_iterindices(i):
+ ret = []
+ while not i.finished:
+ ret.append(i.iterindex)
+ i.iternext()
+ return ret
+
+def test_iter_refcount():
+ # Make sure the iterator doesn't leak
+
+ # Basic
+ a = arange(6)
+ dt = np.dtype('f4').newbyteorder()
+ rc_a = sys.getrefcount(a)
+ rc_dt = sys.getrefcount(dt)
+ it = newiter(a, [],
+ [['readwrite','updateifcopy']],
+ casting='unsafe',
+ op_dtypes=[dt])
+ assert_(not it.iterationneedsapi)
+ assert_(sys.getrefcount(a) > rc_a)
+ assert_(sys.getrefcount(dt) > rc_dt)
+ it = None
+ assert_equal(sys.getrefcount(a), rc_a)
+ assert_equal(sys.getrefcount(dt), rc_dt)
+
+ # With a copy
+ a = arange(6, dtype='f4')
+ dt = np.dtype('f4')
+ rc_a = sys.getrefcount(a)
+ rc_dt = sys.getrefcount(dt)
+ it = newiter(a, [],
+ [['readwrite']],
+ op_dtypes=[dt])
+ rc2_a = sys.getrefcount(a)
+ rc2_dt = sys.getrefcount(dt)
+ it2 = it.copy()
+ assert_(sys.getrefcount(a) > rc2_a)
+ assert_(sys.getrefcount(dt) > rc2_dt)
+ it = None
+ assert_equal(sys.getrefcount(a), rc2_a)
+ assert_equal(sys.getrefcount(dt), rc2_dt)
+ it2 = None
+ assert_equal(sys.getrefcount(a), rc_a)
+ assert_equal(sys.getrefcount(dt), rc_dt)
+
+def test_iter_best_order():
+ # The iterator should always find the iteration order
+ # with increasing memory addresses
+
+ # Test the ordering for 1-D to 5-D shapes
+ for shape in [(5,), (3,4), (2,3,4), (2,3,4,3), (2,3,2,2,3)]:
+ a = arange(np.prod(shape))
+ # Test each combination of positive and negative strides
+ for dirs in range(2**len(shape)):
+ dirs_index = [slice(None)]*len(shape)
+ for bit in range(len(shape)):
+ if ((2**bit)&dirs):
+ dirs_index[bit] = slice(None,None,-1)
+ dirs_index = tuple(dirs_index)
+
+ aview = a.reshape(shape)[dirs_index]
+ # C-order
+ i = newiter(aview, [], [['readonly']])
+ assert_equal([x for x in i], a)
+ # Fortran-order
+ i = newiter(aview.T, [], [['readonly']])
+ assert_equal([x for x in i], a)
+ # Other order
+ if len(shape) > 2:
+ i = newiter(aview.swapaxes(0,1), [], [['readonly']])
+ assert_equal([x for x in i], a)
+
+def test_iter_c_order():
+ # Test forcing C order
+
+ # Test the ordering for 1-D to 5-D shapes
+ for shape in [(5,), (3,4), (2,3,4), (2,3,4,3), (2,3,2,2,3)]:
+ a = arange(np.prod(shape))
+ # Test each combination of positive and negative strides
+ for dirs in range(2**len(shape)):
+ dirs_index = [slice(None)]*len(shape)
+ for bit in range(len(shape)):
+ if ((2**bit)&dirs):
+ dirs_index[bit] = slice(None,None,-1)
+ dirs_index = tuple(dirs_index)
+
+ aview = a.reshape(shape)[dirs_index]
+ # C-order
+ i = newiter(aview, order='C')
+ assert_equal([x for x in i], aview.ravel(order='C'))
+ # Fortran-order
+ i = newiter(aview.T, order='C')
+ assert_equal([x for x in i], aview.T.ravel(order='C'))
+ # Other order
+ if len(shape) > 2:
+ i = newiter(aview.swapaxes(0,1), order='C')
+ assert_equal([x for x in i],
+ aview.swapaxes(0,1).ravel(order='C'))
+
+def test_iter_f_order():
+ # Test forcing F order
+
+ # Test the ordering for 1-D to 5-D shapes
+ for shape in [(5,), (3,4), (2,3,4), (2,3,4,3), (2,3,2,2,3)]:
+ a = arange(np.prod(shape))
+ # Test each combination of positive and negative strides
+ for dirs in range(2**len(shape)):
+ dirs_index = [slice(None)]*len(shape)
+ for bit in range(len(shape)):
+ if ((2**bit)&dirs):
+ dirs_index[bit] = slice(None,None,-1)
+ dirs_index = tuple(dirs_index)
+
+ aview = a.reshape(shape)[dirs_index]
+ # C-order
+ i = newiter(aview, order='F')
+ assert_equal([x for x in i], aview.ravel(order='F'))
+ # Fortran-order
+ i = newiter(aview.T, order='F')
+ assert_equal([x for x in i], aview.T.ravel(order='F'))
+ # Other order
+ if len(shape) > 2:
+ i = newiter(aview.swapaxes(0,1), order='F')
+ assert_equal([x for x in i],
+ aview.swapaxes(0,1).ravel(order='F'))
+
+def test_iter_c_or_f_order():
+ # Test forcing any contiguous (C or F) order
+
+ # Test the ordering for 1-D to 5-D shapes
+ for shape in [(5,), (3,4), (2,3,4), (2,3,4,3), (2,3,2,2,3)]:
+ a = arange(np.prod(shape))
+ # Test each combination of positive and negative strides
+ for dirs in range(2**len(shape)):
+ dirs_index = [slice(None)]*len(shape)
+ for bit in range(len(shape)):
+ if ((2**bit)&dirs):
+ dirs_index[bit] = slice(None,None,-1)
+ dirs_index = tuple(dirs_index)
+
+ aview = a.reshape(shape)[dirs_index]
+ # C-order
+ i = newiter(aview, order='A')
+ assert_equal([x for x in i], aview.ravel(order='A'))
+ # Fortran-order
+ i = newiter(aview.T, order='A')
+ assert_equal([x for x in i], aview.T.ravel(order='A'))
+ # Other order
+ if len(shape) > 2:
+ i = newiter(aview.swapaxes(0,1), order='A')
+ assert_equal([x for x in i],
+ aview.swapaxes(0,1).ravel(order='A'))
+
+def test_iter_best_order_coords_1d():
+ # The coords should be correct with any reordering
+
+ a = arange(4)
+ # 1D order
+ i = newiter(a,['coords'],[['readonly']])
+ assert_equal(iter_coords(i), [(0,),(1,),(2,),(3,)])
+ # 1D reversed order
+ i = newiter(a[::-1],['coords'],[['readonly']])
+ assert_equal(iter_coords(i), [(3,),(2,),(1,),(0,)])
+
+def test_iter_best_order_coords_2d():
+ # The coords should be correct with any reordering
+
+ a = arange(6)
+ # 2D C-order
+ i = newiter(a.reshape(2,3),['coords'],[['readonly']])
+ assert_equal(iter_coords(i), [(0,0),(0,1),(0,2),(1,0),(1,1),(1,2)])
+ # 2D Fortran-order
+ i = newiter(a.reshape(2,3).copy(order='F'),['coords'],[['readonly']])
+ assert_equal(iter_coords(i), [(0,0),(1,0),(0,1),(1,1),(0,2),(1,2)])
+ # 2D reversed C-order
+ i = newiter(a.reshape(2,3)[::-1],['coords'],[['readonly']])
+ assert_equal(iter_coords(i), [(1,0),(1,1),(1,2),(0,0),(0,1),(0,2)])
+ i = newiter(a.reshape(2,3)[:,::-1],['coords'],[['readonly']])
+ assert_equal(iter_coords(i), [(0,2),(0,1),(0,0),(1,2),(1,1),(1,0)])
+ i = newiter(a.reshape(2,3)[::-1,::-1],['coords'],[['readonly']])
+ assert_equal(iter_coords(i), [(1,2),(1,1),(1,0),(0,2),(0,1),(0,0)])
+ # 2D reversed Fortran-order
+ i = newiter(a.reshape(2,3).copy(order='F')[::-1],['coords'],[['readonly']])
+ assert_equal(iter_coords(i), [(1,0),(0,0),(1,1),(0,1),(1,2),(0,2)])
+ i = newiter(a.reshape(2,3).copy(order='F')[:,::-1],
+ ['coords'],[['readonly']])
+ assert_equal(iter_coords(i), [(0,2),(1,2),(0,1),(1,1),(0,0),(1,0)])
+ i = newiter(a.reshape(2,3).copy(order='F')[::-1,::-1],
+ ['coords'],[['readonly']])
+ assert_equal(iter_coords(i), [(1,2),(0,2),(1,1),(0,1),(1,0),(0,0)])
+
+def test_iter_best_order_coords_3d():
+ # The coords should be correct with any reordering
+
+ a = arange(12)
+ # 3D C-order
+ i = newiter(a.reshape(2,3,2),['coords'],[['readonly']])
+ assert_equal(iter_coords(i),
+ [(0,0,0),(0,0,1),(0,1,0),(0,1,1),(0,2,0),(0,2,1),
+ (1,0,0),(1,0,1),(1,1,0),(1,1,1),(1,2,0),(1,2,1)])
+ # 3D Fortran-order
+ i = newiter(a.reshape(2,3,2).copy(order='F'),['coords'],[['readonly']])
+ assert_equal(iter_coords(i),
+ [(0,0,0),(1,0,0),(0,1,0),(1,1,0),(0,2,0),(1,2,0),
+ (0,0,1),(1,0,1),(0,1,1),(1,1,1),(0,2,1),(1,2,1)])
+ # 3D reversed C-order
+ i = newiter(a.reshape(2,3,2)[::-1],['coords'],[['readonly']])
+ assert_equal(iter_coords(i),
+ [(1,0,0),(1,0,1),(1,1,0),(1,1,1),(1,2,0),(1,2,1),
+ (0,0,0),(0,0,1),(0,1,0),(0,1,1),(0,2,0),(0,2,1)])
+ i = newiter(a.reshape(2,3,2)[:,::-1],['coords'],[['readonly']])
+ assert_equal(iter_coords(i),
+ [(0,2,0),(0,2,1),(0,1,0),(0,1,1),(0,0,0),(0,0,1),
+ (1,2,0),(1,2,1),(1,1,0),(1,1,1),(1,0,0),(1,0,1)])
+ i = newiter(a.reshape(2,3,2)[:,:,::-1],['coords'],[['readonly']])
+ assert_equal(iter_coords(i),
+ [(0,0,1),(0,0,0),(0,1,1),(0,1,0),(0,2,1),(0,2,0),
+ (1,0,1),(1,0,0),(1,1,1),(1,1,0),(1,2,1),(1,2,0)])
+ # 3D reversed Fortran-order
+ i = newiter(a.reshape(2,3,2).copy(order='F')[::-1],
+ ['coords'],[['readonly']])
+ assert_equal(iter_coords(i),
+ [(1,0,0),(0,0,0),(1,1,0),(0,1,0),(1,2,0),(0,2,0),
+ (1,0,1),(0,0,1),(1,1,1),(0,1,1),(1,2,1),(0,2,1)])
+ i = newiter(a.reshape(2,3,2).copy(order='F')[:,::-1],
+ ['coords'],[['readonly']])
+ assert_equal(iter_coords(i),
+ [(0,2,0),(1,2,0),(0,1,0),(1,1,0),(0,0,0),(1,0,0),
+ (0,2,1),(1,2,1),(0,1,1),(1,1,1),(0,0,1),(1,0,1)])
+ i = newiter(a.reshape(2,3,2).copy(order='F')[:,:,::-1],
+ ['coords'],[['readonly']])
+ assert_equal(iter_coords(i),
+ [(0,0,1),(1,0,1),(0,1,1),(1,1,1),(0,2,1),(1,2,1),
+ (0,0,0),(1,0,0),(0,1,0),(1,1,0),(0,2,0),(1,2,0)])
+
+def test_iter_best_order_c_index_1d():
+ # The C index should be correct with any reordering
+
+ a = arange(4)
+ # 1D order
+ i = newiter(a,['c_index'],[['readonly']])
+ assert_equal(iter_indices(i), [0,1,2,3])
+ # 1D reversed order
+ i = newiter(a[::-1],['c_index'],[['readonly']])
+ assert_equal(iter_indices(i), [3,2,1,0])
+
+def test_iter_best_order_c_index_2d():
+ # The C index should be correct with any reordering
+
+ a = arange(6)
+ # 2D C-order
+ i = newiter(a.reshape(2,3),['c_index'],[['readonly']])
+ assert_equal(iter_indices(i), [0,1,2,3,4,5])
+ # 2D Fortran-order
+ i = newiter(a.reshape(2,3).copy(order='F'),
+ ['c_index'],[['readonly']])
+ assert_equal(iter_indices(i), [0,3,1,4,2,5])
+ # 2D reversed C-order
+ i = newiter(a.reshape(2,3)[::-1],['c_index'],[['readonly']])
+ assert_equal(iter_indices(i), [3,4,5,0,1,2])
+ i = newiter(a.reshape(2,3)[:,::-1],['c_index'],[['readonly']])
+ assert_equal(iter_indices(i), [2,1,0,5,4,3])
+ i = newiter(a.reshape(2,3)[::-1,::-1],['c_index'],[['readonly']])
+ assert_equal(iter_indices(i), [5,4,3,2,1,0])
+ # 2D reversed Fortran-order
+ i = newiter(a.reshape(2,3).copy(order='F')[::-1],
+ ['c_index'],[['readonly']])
+ assert_equal(iter_indices(i), [3,0,4,1,5,2])
+ i = newiter(a.reshape(2,3).copy(order='F')[:,::-1],
+ ['c_index'],[['readonly']])
+ assert_equal(iter_indices(i), [2,5,1,4,0,3])
+ i = newiter(a.reshape(2,3).copy(order='F')[::-1,::-1],
+ ['c_index'],[['readonly']])
+ assert_equal(iter_indices(i), [5,2,4,1,3,0])
+
+def test_iter_best_order_c_index_3d():
+ # The C index should be correct with any reordering
+
+ a = arange(12)
+ # 3D C-order
+ i = newiter(a.reshape(2,3,2),['c_index'],[['readonly']])
+ assert_equal(iter_indices(i),
+ [0,1,2,3,4,5,6,7,8,9,10,11])
+ # 3D Fortran-order
+ i = newiter(a.reshape(2,3,2).copy(order='F'),
+ ['c_index'],[['readonly']])
+ assert_equal(iter_indices(i),
+ [0,6,2,8,4,10,1,7,3,9,5,11])
+ # 3D reversed C-order
+ i = newiter(a.reshape(2,3,2)[::-1],['c_index'],[['readonly']])
+ assert_equal(iter_indices(i),
+ [6,7,8,9,10,11,0,1,2,3,4,5])
+ i = newiter(a.reshape(2,3,2)[:,::-1],['c_index'],[['readonly']])
+ assert_equal(iter_indices(i),
+ [4,5,2,3,0,1,10,11,8,9,6,7])
+ i = newiter(a.reshape(2,3,2)[:,:,::-1],['c_index'],[['readonly']])
+ assert_equal(iter_indices(i),
+ [1,0,3,2,5,4,7,6,9,8,11,10])
+ # 3D reversed Fortran-order
+ i = newiter(a.reshape(2,3,2).copy(order='F')[::-1],
+ ['c_index'],[['readonly']])
+ assert_equal(iter_indices(i),
+ [6,0,8,2,10,4,7,1,9,3,11,5])
+ i = newiter(a.reshape(2,3,2).copy(order='F')[:,::-1],
+ ['c_index'],[['readonly']])
+ assert_equal(iter_indices(i),
+ [4,10,2,8,0,6,5,11,3,9,1,7])
+ i = newiter(a.reshape(2,3,2).copy(order='F')[:,:,::-1],
+ ['c_index'],[['readonly']])
+ assert_equal(iter_indices(i),
+ [1,7,3,9,5,11,0,6,2,8,4,10])
+
+def test_iter_best_order_f_index_1d():
+ # The Fortran index should be correct with any reordering
+
+ a = arange(4)
+ # 1D order
+ i = newiter(a,['f_index'],[['readonly']])
+ assert_equal(iter_indices(i), [0,1,2,3])
+ # 1D reversed order
+ i = newiter(a[::-1],['f_index'],[['readonly']])
+ assert_equal(iter_indices(i), [3,2,1,0])
+
+def test_iter_best_order_f_index_2d():
+ # The Fortran index should be correct with any reordering
+
+ a = arange(6)
+ # 2D C-order
+ i = newiter(a.reshape(2,3),['f_index'],[['readonly']])
+ assert_equal(iter_indices(i), [0,2,4,1,3,5])
+ # 2D Fortran-order
+ i = newiter(a.reshape(2,3).copy(order='F'),
+ ['f_index'],[['readonly']])
+ assert_equal(iter_indices(i), [0,1,2,3,4,5])
+ # 2D reversed C-order
+ i = newiter(a.reshape(2,3)[::-1],['f_index'],[['readonly']])
+ assert_equal(iter_indices(i), [1,3,5,0,2,4])
+ i = newiter(a.reshape(2,3)[:,::-1],['f_index'],[['readonly']])
+ assert_equal(iter_indices(i), [4,2,0,5,3,1])
+ i = newiter(a.reshape(2,3)[::-1,::-1],['f_index'],[['readonly']])
+ assert_equal(iter_indices(i), [5,3,1,4,2,0])
+ # 2D reversed Fortran-order
+ i = newiter(a.reshape(2,3).copy(order='F')[::-1],
+ ['f_index'],[['readonly']])
+ assert_equal(iter_indices(i), [1,0,3,2,5,4])
+ i = newiter(a.reshape(2,3).copy(order='F')[:,::-1],
+ ['f_index'],[['readonly']])
+ assert_equal(iter_indices(i), [4,5,2,3,0,1])
+ i = newiter(a.reshape(2,3).copy(order='F')[::-1,::-1],
+ ['f_index'],[['readonly']])
+ assert_equal(iter_indices(i), [5,4,3,2,1,0])
+
+def test_iter_best_order_f_index_3d():
+ # The Fortran index should be correct with any reordering
+
+ a = arange(12)
+ # 3D C-order
+ i = newiter(a.reshape(2,3,2),['f_index'],[['readonly']])
+ assert_equal(iter_indices(i),
+ [0,6,2,8,4,10,1,7,3,9,5,11])
+ # 3D Fortran-order
+ i = newiter(a.reshape(2,3,2).copy(order='F'),
+ ['f_index'],[['readonly']])
+ assert_equal(iter_indices(i),
+ [0,1,2,3,4,5,6,7,8,9,10,11])
+ # 3D reversed C-order
+ i = newiter(a.reshape(2,3,2)[::-1],['f_index'],[['readonly']])
+ assert_equal(iter_indices(i),
+ [1,7,3,9,5,11,0,6,2,8,4,10])
+ i = newiter(a.reshape(2,3,2)[:,::-1],['f_index'],[['readonly']])
+ assert_equal(iter_indices(i),
+ [4,10,2,8,0,6,5,11,3,9,1,7])
+ i = newiter(a.reshape(2,3,2)[:,:,::-1],['f_index'],[['readonly']])
+ assert_equal(iter_indices(i),
+ [6,0,8,2,10,4,7,1,9,3,11,5])
+ # 3D reversed Fortran-order
+ i = newiter(a.reshape(2,3,2).copy(order='F')[::-1],
+ ['f_index'],[['readonly']])
+ assert_equal(iter_indices(i),
+ [1,0,3,2,5,4,7,6,9,8,11,10])
+ i = newiter(a.reshape(2,3,2).copy(order='F')[:,::-1],
+ ['f_index'],[['readonly']])
+ assert_equal(iter_indices(i),
+ [4,5,2,3,0,1,10,11,8,9,6,7])
+ i = newiter(a.reshape(2,3,2).copy(order='F')[:,:,::-1],
+ ['f_index'],[['readonly']])
+ assert_equal(iter_indices(i),
+ [6,7,8,9,10,11,0,1,2,3,4,5])
+
+def test_iter_no_inner_full_coalesce():
+ # Check no_inner iterators which coalesce into a single inner loop
+
+ for shape in [(5,), (3,4), (2,3,4), (2,3,4,3), (2,3,2,2,3)]:
+ size = np.prod(shape)
+ a = arange(size)
+ # Test each combination of forward and backwards indexing
+ for dirs in range(2**len(shape)):
+ dirs_index = [slice(None)]*len(shape)
+ for bit in range(len(shape)):
+ if ((2**bit)&dirs):
+ dirs_index[bit] = slice(None,None,-1)
+ dirs_index = tuple(dirs_index)
+
+ aview = a.reshape(shape)[dirs_index]
+ # C-order
+ i = newiter(aview, ['no_inner_iteration'], [['readonly']])
+ assert_equal(i.ndim, 1)
+ assert_equal(i[0].shape, (size,))
+ # Fortran-order
+ i = newiter(aview.T, ['no_inner_iteration'], [['readonly']])
+ assert_equal(i.ndim, 1)
+ assert_equal(i[0].shape, (size,))
+ # Other order
+ if len(shape) > 2:
+ i = newiter(aview.swapaxes(0,1),
+ ['no_inner_iteration'], [['readonly']])
+ assert_equal(i.ndim, 1)
+ assert_equal(i[0].shape, (size,))
+
+def test_iter_no_inner_dim_coalescing():
+ # Check no_inner iterators whose dimensions may not coalesce completely
+
+ # Skipping the last element in a dimension prevents coalescing
+ # with the next-bigger dimension
+ a = arange(24).reshape(2,3,4)[:,:,:-1]
+ i = newiter(a, ['no_inner_iteration'], [['readonly']])
+ assert_equal(i.ndim, 2)
+ assert_equal(i[0].shape, (3,))
+ a = arange(24).reshape(2,3,4)[:,:-1,:]
+ i = newiter(a, ['no_inner_iteration'], [['readonly']])
+ assert_equal(i.ndim, 2)
+ assert_equal(i[0].shape, (8,))
+ a = arange(24).reshape(2,3,4)[:-1,:,:]
+ i = newiter(a, ['no_inner_iteration'], [['readonly']])
+ assert_equal(i.ndim, 1)
+ assert_equal(i[0].shape, (12,))
+
+ # Even with lots of 1-sized dimensions, should still coalesce
+ a = arange(24).reshape(1,1,2,1,1,3,1,1,4,1,1)
+ i = newiter(a, ['no_inner_iteration'], [['readonly']])
+ assert_equal(i.ndim, 1)
+ assert_equal(i[0].shape, (24,))
+
+def test_iter_dim_coalescing():
+ # Check that the correct number of dimensions are coalesced
+
+ # Tracking coordinates disables coalescing
+ a = arange(24).reshape(2,3,4)
+ i = newiter(a, ['coords'], [['readonly']])
+ assert_equal(i.ndim, 3)
+
+ # A tracked index can allow coalescing if it's compatible with the array
+ a3d = arange(24).reshape(2,3,4)
+ i = newiter(a3d, ['c_index'], [['readonly']])
+ assert_equal(i.ndim, 1)
+ i = newiter(a3d.swapaxes(0,1), ['c_index'], [['readonly']])
+ assert_equal(i.ndim, 3)
+ i = newiter(a3d.T, ['c_index'], [['readonly']])
+ assert_equal(i.ndim, 3)
+ i = newiter(a3d.T, ['f_index'], [['readonly']])
+ assert_equal(i.ndim, 1)
+ i = newiter(a3d.T.swapaxes(0,1), ['f_index'], [['readonly']])
+ assert_equal(i.ndim, 3)
+
+ # When C or F order is forced, coalescing may still occur
+ a3d = arange(24).reshape(2,3,4)
+ i = newiter(a3d, order='C')
+ assert_equal(i.ndim, 1)
+ i = newiter(a3d.T, order='C')
+ assert_equal(i.ndim, 3)
+ i = newiter(a3d, order='F')
+ assert_equal(i.ndim, 3)
+ i = newiter(a3d.T, order='F')
+ assert_equal(i.ndim, 1)
+ i = newiter(a3d, order='A')
+ assert_equal(i.ndim, 1)
+ i = newiter(a3d.T, order='A')
+ assert_equal(i.ndim, 1)
+
+def test_iter_broadcasting():
+ # Standard NumPy broadcasting rules
+
+ # 1D with scalar
+ i = newiter([arange(6), np.int32(2)], ['coords'], [['readonly']]*2)
+ assert_equal(i.itersize, 6)
+ assert_equal(i.shape, (6,))
+
+ # 2D with scalar
+ i = newiter([arange(6).reshape(2,3), np.int32(2)],
+ ['coords'], [['readonly']]*2)
+ assert_equal(i.itersize, 6)
+ assert_equal(i.shape, (2,3))
+ # 2D with 1D
+ i = newiter([arange(6).reshape(2,3), arange(3)],
+ ['coords'], [['readonly']]*2)
+ assert_equal(i.itersize, 6)
+ assert_equal(i.shape, (2,3))
+ i = newiter([arange(2).reshape(2,1), arange(3)],
+ ['coords'], [['readonly']]*2)
+ assert_equal(i.itersize, 6)
+ assert_equal(i.shape, (2,3))
+ # 2D with 2D
+ i = newiter([arange(2).reshape(2,1), arange(3).reshape(1,3)],
+ ['coords'], [['readonly']]*2)
+ assert_equal(i.itersize, 6)
+ assert_equal(i.shape, (2,3))
+
+ # 3D with scalar
+ i = newiter([np.int32(2), arange(24).reshape(4,2,3)],
+ ['coords'], [['readonly']]*2)
+ assert_equal(i.itersize, 24)
+ assert_equal(i.shape, (4,2,3))
+ # 3D with 1D
+ i = newiter([arange(3), arange(24).reshape(4,2,3)],
+ ['coords'], [['readonly']]*2)
+ assert_equal(i.itersize, 24)
+ assert_equal(i.shape, (4,2,3))
+ i = newiter([arange(3), arange(8).reshape(4,2,1)],
+ ['coords'], [['readonly']]*2)
+ assert_equal(i.itersize, 24)
+ assert_equal(i.shape, (4,2,3))
+ # 3D with 2D
+ i = newiter([arange(6).reshape(2,3), arange(24).reshape(4,2,3)],
+ ['coords'], [['readonly']]*2)
+ assert_equal(i.itersize, 24)
+ assert_equal(i.shape, (4,2,3))
+ i = newiter([arange(2).reshape(2,1), arange(24).reshape(4,2,3)],
+ ['coords'], [['readonly']]*2)
+ assert_equal(i.itersize, 24)
+ assert_equal(i.shape, (4,2,3))
+ i = newiter([arange(3).reshape(1,3), arange(8).reshape(4,2,1)],
+ ['coords'], [['readonly']]*2)
+ assert_equal(i.itersize, 24)
+ assert_equal(i.shape, (4,2,3))
+ # 3D with 3D
+ i = newiter([arange(2).reshape(1,2,1), arange(3).reshape(1,1,3),
+ arange(4).reshape(4,1,1)],
+ ['coords'], [['readonly']]*3)
+ assert_equal(i.itersize, 24)
+ assert_equal(i.shape, (4,2,3))
+ i = newiter([arange(6).reshape(1,2,3), arange(4).reshape(4,1,1)],
+ ['coords'], [['readonly']]*2)
+ assert_equal(i.itersize, 24)
+ assert_equal(i.shape, (4,2,3))
+ i = newiter([arange(24).reshape(4,2,3), arange(12).reshape(4,1,3)],
+ ['coords'], [['readonly']]*2)
+ assert_equal(i.itersize, 24)
+ assert_equal(i.shape, (4,2,3))
+
+def test_iter_broadcasting_errors():
+ # Check that errors are thrown for bad broadcasting shapes
+
+ # 1D with 1D
+ assert_raises(ValueError, newiter, [arange(2), arange(3)],
+ [], [['readonly']]*2)
+ # 2D with 1D
+ assert_raises(ValueError, newiter,
+ [arange(6).reshape(2,3), arange(2)],
+ [], [['readonly']]*2)
+ # 2D with 2D
+ assert_raises(ValueError, newiter,
+ [arange(6).reshape(2,3), arange(9).reshape(3,3)],
+ [], [['readonly']]*2)
+ assert_raises(ValueError, newiter,
+ [arange(6).reshape(2,3), arange(4).reshape(2,2)],
+ [], [['readonly']]*2)
+ # 3D with 3D
+ assert_raises(ValueError, newiter,
+ [arange(36).reshape(3,3,4), arange(24).reshape(2,3,4)],
+ [], [['readonly']]*2)
+ assert_raises(ValueError, newiter,
+ [arange(8).reshape(2,4,1), arange(24).reshape(2,3,4)],
+ [], [['readonly']]*2)
+
+ # Verify that the error message mentions the right shapes
+ try:
+ i = newiter([arange(2).reshape(1,2,1),
+ arange(3).reshape(1,3),
+ arange(6).reshape(2,3)],
+ [],
+ [['readonly'], ['readonly'], ['writeonly','no_broadcast']])
+ assert_(False, 'Should have raised a broadcast error')
+ except ValueError, e:
+ msg = str(e)
+ # The message should contain the shape of the 3rd operand
+ assert_(msg.find('(2,3)') >= 0,
+ 'Message "%s" doesn\'t contain operand shape (2,3)' % msg)
+ # The message should contain the broadcast shape
+ assert_(msg.find('(1,2,3)') >= 0,
+ 'Message "%s" doesn\'t contain broadcast shape (1,2,3)' % msg)
+
+
+def test_iter_flags_errors():
+ # Check that bad combinations of flags produce errors
+
+ a = arange(6)
+
+ # Not enough operands
+ assert_raises(ValueError, newiter, [], [], [])
+ # Too many operands
+ assert_raises(ValueError, newiter, [a]*100, [], [['readonly']]*100)
+ # Bad global flag
+ assert_raises(ValueError, newiter, [a], ['bad flag'], [['readonly']])
+ # Bad op flag
+ assert_raises(ValueError, newiter, [a], [], [['readonly','bad flag']])
+ # Bad order parameter
+ assert_raises(ValueError, newiter, [a], [], [['readonly']], order='G')
+ # Bad casting parameter
+ assert_raises(ValueError, newiter, [a], [], [['readonly']], casting='noon')
+ # op_flags must match ops
+ assert_raises(ValueError, newiter, [a]*3, [], [['readonly']]*2)
+ # Cannot track both a C and an F index
+ assert_raises(ValueError, newiter, a,
+ ['c_index','f_index'], [['readonly']])
+ # Inner iteration and coords/indices are incompatible
+ assert_raises(ValueError, newiter, a,
+ ['no_inner_iteration','coords'], [['readonly']])
+ assert_raises(ValueError, newiter, a,
+ ['no_inner_iteration','c_index'], [['readonly']])
+ assert_raises(ValueError, newiter, a,
+ ['no_inner_iteration','f_index'], [['readonly']])
+ # Must specify exactly one of readwrite/readonly/writeonly per operand
+ assert_raises(ValueError, newiter, a, [], [[]])
+ assert_raises(ValueError, newiter, a, [], [['readonly','writeonly']])
+ assert_raises(ValueError, newiter, a, [], [['readonly','readwrite']])
+ assert_raises(ValueError, newiter, a, [], [['writeonly','readwrite']])
+ assert_raises(ValueError, newiter, a,
+ [], [['readonly','writeonly','readwrite']])
+ # Python scalars are always readonly
+ assert_raises(TypeError, newiter, 1.5, [], [['writeonly']])
+ assert_raises(TypeError, newiter, 1.5, [], [['readwrite']])
+ # Array scalars are always readonly
+ assert_raises(TypeError, newiter, np.int32(1), [], [['writeonly']])
+ assert_raises(TypeError, newiter, np.int32(1), [], [['readwrite']])
+ # Check readonly array
+ a.flags.writeable = False
+ assert_raises(ValueError, newiter, a, [], [['writeonly']])
+ assert_raises(ValueError, newiter, a, [], [['readwrite']])
+ a.flags.writeable = True
+ # Coords available only with the coords flag
+ i = newiter(arange(6), [], [['readonly']])
+ assert_raises(ValueError, lambda i:i.coords, i)
+ # Index available only with an index flag
+ assert_raises(ValueError, lambda i:i.index, i)
+ # GotoCoords and GotoIndex incompatible with buffering or no_inner
+ def assign_coords(i):
+ i.coords = (0,)
+ def assign_index(i):
+ i.index = 0
+ def assign_iterindex(i):
+ i.iterindex = 0;
+ def assign_iterrange(i):
+ i.iterrange = (0,1);
+ i = newiter(arange(6), ['no_inner_iteration'])
+ assert_raises(ValueError, assign_coords, i)
+ assert_raises(ValueError, assign_index, i)
+ assert_raises(ValueError, assign_iterindex, i)
+ assert_raises(ValueError, assign_iterrange, i)
+ i = newiter(arange(6), ['buffered'])
+ assert_raises(ValueError, assign_coords, i)
+ assert_raises(ValueError, assign_index, i)
+ assert_raises(ValueError, assign_iterrange, i)
+ # Can't iterate if size is zero
+ assert_raises(ValueError, newiter, np.array([]))
+
+def test_iter_slice():
+ a, b, c = np.arange(3), np.arange(3), np.arange(3.)
+ i = newiter([a,b,c], [], ['readwrite'])
+ i[0:2] = (3,3)
+ assert_equal(a, [3,1,2])
+ assert_equal(b, [3,1,2])
+ assert_equal(c, [0,1,2])
+ i[1] = 12
+ assert_equal(i[0:2], [3,12])
+
+def test_iter_nbo_align_contig():
+ # Check that byte order, alignment, and contig changes work
+
+ # Byte order change by requesting a specific dtype
+ a = np.arange(6, dtype='f4')
+ au = a.byteswap().newbyteorder()
+ assert_(a.dtype.byteorder != au.dtype.byteorder)
+ i = newiter(au, [], [['readwrite','updateifcopy']],
+ casting='equiv',
+ op_dtypes=[np.dtype('f4')])
+ assert_equal(i.dtypes[0].byteorder, a.dtype.byteorder)
+ assert_equal(i.operands[0].dtype.byteorder, a.dtype.byteorder)
+ assert_equal(i.operands[0], a)
+ i.operands[0][:] = 2
+ i = None
+ assert_equal(au, [2]*6)
+
+ # Byte order change by requesting NBO
+ a = np.arange(6, dtype='f4')
+ au = a.byteswap().newbyteorder()
+ assert_(a.dtype.byteorder != au.dtype.byteorder)
+ i = newiter(au, [], [['readwrite','updateifcopy','nbo']], casting='equiv')
+ assert_equal(i.dtypes[0].byteorder, a.dtype.byteorder)
+ assert_equal(i.operands[0].dtype.byteorder, a.dtype.byteorder)
+ assert_equal(i.operands[0], a)
+ i.operands[0][:] = 2
+ i = None
+ assert_equal(au, [2]*6)
+
+ # Unaligned input
+ a = np.zeros((6*4+1,), dtype='i1')[1:]
+ a.dtype = 'f4'
+ a[:] = np.arange(6, dtype='f4')
+ assert_(not a.flags.aligned)
+ # Without 'aligned', shouldn't copy
+ i = newiter(a, [], [['readonly']])
+ assert_(not i.operands[0].flags.aligned)
+ assert_equal(i.operands[0], a);
+ # With 'aligned', should make a copy
+ i = newiter(a, [], [['readwrite','updateifcopy','aligned']])
+ assert_(i.operands[0].flags.aligned)
+ assert_equal(i.operands[0], a);
+ i.operands[0][:] = 3
+ i = None
+ assert_equal(a, [3]*6)
+
+ # Discontiguous input
+ a = arange(12)
+ # If it is contiguous, shouldn't copy
+ i = newiter(a[:6], [], [['readonly']])
+ assert_(i.operands[0].flags.contiguous)
+ assert_equal(i.operands[0], a[:6]);
+ # If it isn't contiguous, should buffer
+ i = newiter(a[::2], ['buffered','no_inner_iteration'],
+ [['readonly','contig']],
+ buffersize=10)
+ assert_(i[0].flags.contiguous)
+ assert_equal(i[0], a[::2])
+
+def test_iter_array_cast():
+ # Check that arrays are cast as requested
+
+ # No cast 'f4' -> 'f4'
+ a = np.arange(6, dtype='f4').reshape(2,3)
+ i = newiter(a, [], [['readwrite']], op_dtypes=[np.dtype('f4')])
+ assert_equal(i.operands[0], a)
+ assert_equal(i.operands[0].dtype, np.dtype('f4'))
+
+ # Byte-order cast '<f4' -> '>f4'
+ a = np.arange(6, dtype='<f4').reshape(2,3)
+ i = newiter(a, [], [['readwrite','updateifcopy']],
+ casting='equiv',
+ op_dtypes=[np.dtype('>f4')])
+ assert_equal(i.operands[0], a)
+ assert_equal(i.operands[0].dtype, np.dtype('>f4'))
+
+ # Safe case 'f4' -> 'f8'
+ a = np.arange(24, dtype='f4').reshape(2,3,4).swapaxes(1,2)
+ i = newiter(a, [], [['readonly','copy']],
+ casting='safe',
+ op_dtypes=[np.dtype('f8')])
+ assert_equal(i.operands[0], a)
+ assert_equal(i.operands[0].dtype, np.dtype('f8'))
+ # The memory layout of the temporary should match a (a is (48,4,16))
+ assert_equal(i.operands[0].strides, (96,8,32))
+ a = a[::-1,:,::-1]
+ i = newiter(a, [], [['readonly','copy']],
+ casting='safe',
+ op_dtypes=[np.dtype('f8')])
+ assert_equal(i.operands[0], a)
+ assert_equal(i.operands[0].dtype, np.dtype('f8'))
+ assert_equal(i.operands[0].strides, (-96,8,-32))
+
+ # Same-kind cast 'f8' -> 'f4' -> 'f8'
+ a = np.arange(24, dtype='f8').reshape(2,3,4).T
+ i = newiter(a, [],
+ [['readwrite','updateifcopy']],
+ casting='same_kind',
+ op_dtypes=[np.dtype('f4')])
+ assert_equal(i.operands[0], a)
+ assert_equal(i.operands[0].dtype, np.dtype('f4'))
+ assert_equal(i.operands[0].strides, (4, 16, 48))
+ # Check that UPDATEIFCOPY is activated
+ i.operands[0][2,1,1] = -12.5
+ assert_(a[2,1,1] != -12.5)
+ i = None
+ assert_equal(a[2,1,1], -12.5)
+
+ # Unsafe cast 'f4' -> 'i4'
+ a = np.arange(6, dtype='i4')[::-2]
+ i = newiter(a, [],
+ [['writeonly','updateifcopy']],
+ casting='unsafe',
+ op_dtypes=[np.dtype('f4')])
+ assert_equal(i.operands[0].dtype, np.dtype('f4'))
+ assert_equal(i.operands[0].strides, (-4,))
+ i.operands[0][:] = 1
+ i = None
+ assert_equal(a, [1,1,1])
+
+def test_iter_array_cast_errors():
+ # Check that invalid casts are caught
+
+ # Need to enable copying for casts to occur
+ assert_raises(TypeError, newiter, arange(2,dtype='f4'), [],
+ [['readonly']], op_dtypes=[np.dtype('f8')])
+ # Also need to allow casting for casts to occur
+ assert_raises(TypeError, newiter, arange(2,dtype='f4'), [],
+ [['readonly','copy']], casting='no',
+ op_dtypes=[np.dtype('f8')])
+ assert_raises(TypeError, newiter, arange(2,dtype='f4'), [],
+ [['readonly','copy']], casting='equiv',
+ op_dtypes=[np.dtype('f8')])
+ assert_raises(TypeError, newiter, arange(2,dtype='f8'), [],
+ [['writeonly','updateifcopy']],
+ casting='no',
+ op_dtypes=[np.dtype('f4')])
+ assert_raises(TypeError, newiter, arange(2,dtype='f8'), [],
+ [['writeonly','updateifcopy']],
+ casting='equiv',
+ op_dtypes=[np.dtype('f4')])
+ # '<f4' -> '>f4' should not work with casting='no'
+ assert_raises(TypeError, newiter, arange(2,dtype='<f4'), [],
+ [['readonly','copy']], casting='no',
+ op_dtypes=[np.dtype('>f4')])
+ # 'f4' -> 'f8' is a safe cast, but 'f8' -> 'f4' isn't
+ assert_raises(TypeError, newiter, arange(2,dtype='f4'), [],
+ [['readwrite','updateifcopy']],
+ casting='safe',
+ op_dtypes=[np.dtype('f8')])
+ assert_raises(TypeError, newiter, arange(2,dtype='f8'), [],
+ [['readwrite','updateifcopy']],
+ casting='safe',
+ op_dtypes=[np.dtype('f4')])
+ # 'f4' -> 'i4' is neither a safe nor a same-kind cast
+ assert_raises(TypeError, newiter, arange(2,dtype='f4'), [],
+ [['readonly','copy']],
+ casting='same_kind',
+ op_dtypes=[np.dtype('i4')])
+ assert_raises(TypeError, newiter, arange(2,dtype='i4'), [],
+ [['writeonly','updateifcopy']],
+ casting='same_kind',
+ op_dtypes=[np.dtype('f4')])
+
+def test_iter_scalar_cast():
+ # Check that scalars are cast as requested
+
+ # No cast 'f4' -> 'f4'
+ i = newiter(np.float32(2.5), [], [['readonly']],
+ op_dtypes=[np.dtype('f4')])
+ assert_equal(i.dtypes[0], np.dtype('f4'))
+ assert_equal(i.value.dtype, np.dtype('f4'))
+ assert_equal(i.value, 2.5)
+ # Safe cast 'f4' -> 'f8'
+ i = newiter(np.float32(2.5), [],
+ [['readonly','copy']],
+ casting='safe',
+ op_dtypes=[np.dtype('f8')])
+ assert_equal(i.dtypes[0], np.dtype('f8'))
+ assert_equal(i.value.dtype, np.dtype('f8'))
+ assert_equal(i.value, 2.5)
+ # Same-kind cast 'f8' -> 'f4'
+ i = newiter(np.float64(2.5), [],
+ [['readonly','copy']],
+ casting='same_kind',
+ op_dtypes=[np.dtype('f4')])
+ assert_equal(i.dtypes[0], np.dtype('f4'))
+ assert_equal(i.value.dtype, np.dtype('f4'))
+ assert_equal(i.value, 2.5)
+ # Unsafe cast 'f8' -> 'i4'
+ i = newiter(np.float64(3.0), [],
+ [['readonly','copy']],
+ casting='unsafe',
+ op_dtypes=[np.dtype('i4')])
+ assert_equal(i.dtypes[0], np.dtype('i4'))
+ assert_equal(i.value.dtype, np.dtype('i4'))
+ assert_equal(i.value, 3)
+ # Readonly scalars may be cast even without setting COPY or BUFFERED
+ i = newiter(3, [], [['readonly']], op_dtypes=[np.dtype('f8')])
+ assert_equal(i[0].dtype, np.dtype('f8'))
+ assert_equal(i[0], 3.)
+
+def test_iter_scalar_cast_errors():
+ # Check that invalid casts are caught
+
+ # Need to allow copying/buffering for write casts of scalars to occur
+ assert_raises(TypeError, newiter, np.float32(2), [],
+ [['readwrite']], op_dtypes=[np.dtype('f8')])
+ assert_raises(TypeError, newiter, 2.5, [],
+ [['readwrite']], op_dtypes=[np.dtype('f4')])
+ # 'f8' -> 'f4' isn't a safe cast if the value would overflow
+ assert_raises(TypeError, newiter, np.float64(1e60), [],
+ [['readonly']],
+ casting='safe',
+ op_dtypes=[np.dtype('f4')])
+ # 'f4' -> 'i4' is neither a safe nor a same-kind cast
+ assert_raises(TypeError, newiter, np.float32(2), [],
+ [['readonly']],
+ casting='same_kind',
+ op_dtypes=[np.dtype('i4')])
+
+def test_iter_object_arrays_basic():
+ # Check that object arrays work
+
+ obj = {'a':3,'b':'d'}
+ a = np.array([[1,2,3], None, obj, None], dtype='O')
+ rc = sys.getrefcount(obj)
+
+ # Need to allow references for object arrays
+ assert_raises(TypeError, newiter, a)
+ assert_equal(sys.getrefcount(obj), rc)
+
+ i = newiter(a, ['refs_ok'], ['readonly'])
+ vals = [x[()] for x in i]
+ assert_equal(np.array(vals, dtype='O'), a)
+ vals, i, x = [None]*3
+ assert_equal(sys.getrefcount(obj), rc)
+
+ i = newiter(a.reshape(2,2).T, ['refs_ok','buffered'],
+ ['readonly'], order='C')
+ assert_(i.iterationneedsapi)
+ vals = [x[()] for x in i]
+ assert_equal(np.array(vals, dtype='O'), a.reshape(2,2).ravel(order='F'))
+ vals, i, x = [None]*3
+ assert_equal(sys.getrefcount(obj), rc)
+
+ i = newiter(a.reshape(2,2).T, ['refs_ok','buffered'],
+ ['readwrite'], order='C')
+ for x in i:
+ x[...] = None
+ vals, i, x = [None]*3
+ assert_equal(sys.getrefcount(obj), rc-1)
+ assert_equal(a, np.array([None]*4, dtype='O'))
+
+def test_iter_object_arrays_conversions():
+ # Conversions to/from objects
+ a = np.arange(6, dtype='O')
+ i = newiter(a, ['refs_ok','buffered'], ['readwrite'],
+ casting='unsafe', op_dtypes='i4')
+ for x in i:
+ x[...] += 1
+ assert_equal(a, np.arange(6)+1)
+
+ a = np.arange(6, dtype='i4')
+ i = newiter(a, ['refs_ok','buffered'], ['readwrite'],
+ casting='unsafe', op_dtypes='O')
+ for x in i:
+ x[...] += 1
+ assert_equal(a, np.arange(6)+1)
+
+ # Non-contiguous object array
+ a = np.zeros((6,), dtype=[('p','i1'),('a','O')])
+ a = a['a']
+ a[:] = np.arange(6)
+ i = newiter(a, ['refs_ok','buffered'], ['readwrite'],
+ casting='unsafe', op_dtypes='i4')
+ for x in i:
+ x[...] += 1
+ assert_equal(a, np.arange(6)+1)
+
+ #Non-contiguous value array
+ a = np.zeros((6,), dtype=[('p','i1'),('a','i4')])
+ a = a['a']
+ a[:] = np.arange(6) + 98172488
+ i = newiter(a, ['refs_ok','buffered'], ['readwrite'],
+ casting='unsafe', op_dtypes='O')
+ ob = i[0][()]
+ rc = sys.getrefcount(ob)
+ for x in i:
+ x[...] += 1
+ assert_equal(sys.getrefcount(ob), rc-1)
+ assert_equal(a, np.arange(6)+98172489)
+
+def test_iter_common_dtype():
+ # Check that the iterator finds a common data type correctly
+
+ i = newiter([array([3],dtype='f4'),array([0],dtype='f8')],
+ ['common_dtype'],
+ [['readonly','copy']]*2,
+ casting='safe')
+ assert_equal(i.dtypes[0], np.dtype('f8'));
+ assert_equal(i.dtypes[1], np.dtype('f8'));
+ i = newiter([array([3],dtype='i4'),array([0],dtype='f4')],
+ ['common_dtype'],
+ [['readonly','copy']]*2,
+ casting='safe')
+ assert_equal(i.dtypes[0], np.dtype('f8'));
+ assert_equal(i.dtypes[1], np.dtype('f8'));
+ i = newiter([array([3],dtype='f4'),array(0,dtype='f8')],
+ ['common_dtype'],
+ [['readonly','copy']]*2,
+ casting='same_kind')
+ assert_equal(i.dtypes[0], np.dtype('f4'));
+ assert_equal(i.dtypes[1], np.dtype('f4'));
+ i = newiter([array([3],dtype='u4'),array(0,dtype='i4')],
+ ['common_dtype'],
+ [['readonly','copy']]*2,
+ casting='safe')
+ assert_equal(i.dtypes[0], np.dtype('u4'));
+ assert_equal(i.dtypes[1], np.dtype('u4'));
+ i = newiter([array([3],dtype='u4'),array(-12,dtype='i4')],
+ ['common_dtype'],
+ [['readonly','copy']]*2,
+ casting='safe')
+ assert_equal(i.dtypes[0], np.dtype('i8'));
+ assert_equal(i.dtypes[1], np.dtype('i8'));
+ i = newiter([array([3],dtype='u4'),array(-12,dtype='i4'),
+ array([2j],dtype='c8'),array([9],dtype='f8')],
+ ['common_dtype'],
+ [['readonly','copy']]*4,
+ casting='safe')
+ assert_equal(i.dtypes[0], np.dtype('c16'));
+ assert_equal(i.dtypes[1], np.dtype('c16'));
+ assert_equal(i.dtypes[2], np.dtype('c16'));
+ assert_equal(i.dtypes[3], np.dtype('c16'));
+ assert_equal(i.value, (3,-12,2j,9))
+
+ # When allocating outputs, other outputs aren't factored in
+ i = newiter([array([3],dtype='i4'),None,array([2j],dtype='c16')], [],
+ [['readonly','copy'],
+ ['writeonly','allocate'],
+ ['writeonly']],
+ casting='safe')
+ assert_equal(i.dtypes[0], np.dtype('i4'));
+ assert_equal(i.dtypes[1], np.dtype('i4'));
+ assert_equal(i.dtypes[2], np.dtype('c16'));
+ # But, if common data types are requested, they are
+ i = newiter([array([3],dtype='i4'),None,array([2j],dtype='c16')],
+ ['common_dtype'],
+ [['readonly','copy'],
+ ['writeonly','allocate'],
+ ['writeonly']],
+ casting='safe')
+ assert_equal(i.dtypes[0], np.dtype('c16'));
+ assert_equal(i.dtypes[1], np.dtype('c16'));
+ assert_equal(i.dtypes[2], np.dtype('c16'));
+
+def test_iter_op_axes():
+ # Check that custom axes work
+
+ # Reverse the axes
+ a = arange(6).reshape(2,3)
+ i = newiter([a,a.T], [], [['readonly']]*2, op_axes=[[0,1],[1,0]])
+ assert_(all([x==y for (x,y) in i]))
+ a = arange(24).reshape(2,3,4)
+ i = newiter([a.T,a], [], [['readonly']]*2, op_axes=[[2,1,0],None])
+ assert_(all([x==y for (x,y) in i]))
+
+ # Broadcast 1D to any dimension
+ a = arange(1,31).reshape(2,3,5)
+ b = arange(1,3)
+ i = newiter([a,b], [], [['readonly']]*2, op_axes=[None,[0,-1,-1]])
+ assert_equal([x*y for (x,y) in i], (a*b.reshape(2,1,1)).ravel())
+ b = arange(1,4)
+ i = newiter([a,b], [], [['readonly']]*2, op_axes=[None,[-1,0,-1]])
+ assert_equal([x*y for (x,y) in i], (a*b.reshape(1,3,1)).ravel())
+ b = arange(1,6)
+ i = newiter([a,b], [], [['readonly']]*2,
+ op_axes=[None,[np.newaxis,np.newaxis,0]])
+ assert_equal([x*y for (x,y) in i], (a*b.reshape(1,1,5)).ravel())
+
+ # Inner product-style broadcasting
+ a = arange(24).reshape(2,3,4)
+ b = arange(40).reshape(5,2,4)
+ i = newiter([a,b], ['coords'], [['readonly']]*2,
+ op_axes=[[0,1,-1,-1],[-1,-1,0,1]])
+ assert_equal(i.shape, (2,3,5,2))
+
+ # Matrix product-style broadcasting
+ a = arange(12).reshape(3,4)
+ b = arange(20).reshape(4,5)
+ i = newiter([a,b], ['coords'], [['readonly']]*2,
+ op_axes=[[0,-1],[-1,1]])
+ assert_equal(i.shape, (3,5))
+
+def test_iter_op_axes_errors():
+ # Check that custom axes throws errors for bad inputs
+
+ # Wrong number of items in op_axes
+ a = arange(6).reshape(2,3)
+ assert_raises(ValueError, newiter, [a,a], [], [['readonly']]*2,
+ op_axes=[[0],[1],[0]])
+ # Out of bounds items in op_axes
+ assert_raises(ValueError, newiter, [a,a], [], [['readonly']]*2,
+ op_axes=[[2,1],[0,1]])
+ assert_raises(ValueError, newiter, [a,a], [], [['readonly']]*2,
+ op_axes=[[0,1],[2,-1]])
+ # Duplicate items in op_axes
+ assert_raises(ValueError, newiter, [a,a], [], [['readonly']]*2,
+ op_axes=[[0,0],[0,1]])
+ assert_raises(ValueError, newiter, [a,a], [], [['readonly']]*2,
+ op_axes=[[0,1],[1,1]])
+
+ # Different sized arrays in op_axes
+ assert_raises(ValueError, newiter, [a,a], [], [['readonly']]*2,
+ op_axes=[[0,1],[0,1,0]])
+
+ # Non-broadcastable dimensions in the result
+ assert_raises(ValueError, newiter, [a,a], [], [['readonly']]*2,
+ op_axes=[[0,1],[1,0]])
+
+def test_iter_copy():
+ # Check that copying the iterator works correctly
+ a = arange(24).reshape(2,3,4)
+
+ # Simple iterator
+ i = newiter(a)
+ j = i.copy()
+ assert_equal([x[()] for x in i], [x[()] for x in j])
+
+ i.iterindex = 3
+ j = i.copy()
+ assert_equal([x[()] for x in i], [x[()] for x in j])
+
+ # Buffered iterator
+ i = newiter(a, ['buffered','ranged'], order='F', buffersize=3)
+ j = i.copy()
+ assert_equal([x[()] for x in i], [x[()] for x in j])
+
+ i.iterindex = 3
+ j = i.copy()
+ assert_equal([x[()] for x in i], [x[()] for x in j])
+
+ i.iterrange = (3,9)
+ j = i.copy()
+ assert_equal([x[()] for x in i], [x[()] for x in j])
+
+ i.iterrange = (2,18)
+ i.next(); i.next()
+ j = i.copy()
+ assert_equal([x[()] for x in i], [x[()] for x in j])
+
+ # Casting iterator
+ i = newiter(a, ['buffered'], order='F', casting='unsafe',
+ op_dtypes='f8', buffersize=5)
+ j = i.copy()
+ i = None
+ assert_equal([x[()] for x in j], a.ravel(order='F'))
+
+ a = arange(24, dtype='<i4').reshape(2,3,4)
+ i = newiter(a, ['buffered'], order='F', casting='unsafe',
+ op_dtypes='>f8', buffersize=5)
+ j = i.copy()
+ i = None
+ assert_equal([x[()] for x in j], a.ravel(order='F'))
+
+def test_iter_allocate_output_simple():
+ # Check that the iterator will properly allocate outputs
+
+ # Simple case
+ a = arange(6)
+ i = newiter([a,None], [], [['readonly'],['writeonly','allocate']],
+ op_dtypes=[None,np.dtype('f4')])
+ assert_equal(i.operands[1].shape, a.shape)
+ assert_equal(i.operands[1].dtype, np.dtype('f4'))
+
+def test_iter_allocate_output_buffered_readwrite():
+ # Allocated output with buffering + delay_bufalloc
+
+ a = arange(6)
+ i = newiter([a,None], ['buffered','delay_bufalloc'],
+ [['readonly'],['allocate','readwrite']])
+ i.operands[1][:] = 1
+ i.reset()
+ for x in i:
+ x[1][...] += x[0][...]
+ assert_equal(i.operands[1], a+1)
+
+def test_iter_allocate_output_itorder():
+ # The allocated output should match the iteration order
+
+ # C-order input, best iteration order
+ a = arange(6, dtype='i4').reshape(2,3)
+ i = newiter([a,None], [], [['readonly'],['writeonly','allocate']],
+ op_dtypes=[None,np.dtype('f4')])
+ assert_equal(i.operands[1].shape, a.shape)
+ assert_equal(i.operands[1].strides, a.strides)
+ assert_equal(i.operands[1].dtype, np.dtype('f4'))
+ # F-order input, best iteration order
+ a = arange(24, dtype='i4').reshape(2,3,4).T
+ i = newiter([a,None], [], [['readonly'],['writeonly','allocate']],
+ op_dtypes=[None,np.dtype('f4')])
+ assert_equal(i.operands[1].shape, a.shape)
+ assert_equal(i.operands[1].strides, a.strides)
+ assert_equal(i.operands[1].dtype, np.dtype('f4'))
+ # Non-contiguous input, C iteration order
+ a = arange(24, dtype='i4').reshape(2,3,4).swapaxes(0,1)
+ i = newiter([a,None], [],
+ [['readonly'],['writeonly','allocate']],
+ order='C',
+ op_dtypes=[None,np.dtype('f4')])
+ assert_equal(i.operands[1].shape, a.shape)
+ assert_equal(i.operands[1].strides, (32,16,4))
+ assert_equal(i.operands[1].dtype, np.dtype('f4'))
+
+def test_iter_allocate_output_opaxes():
+ # Specifing op_axes should work
+
+ a = arange(24, dtype='i4').reshape(2,3,4)
+ i = newiter([None,a], [], [['writeonly','allocate'],['readonly']],
+ op_dtypes=[np.dtype('u4'),None],
+ op_axes=[[1,2,0],None]);
+ assert_equal(i.operands[0].shape, (4,2,3))
+ assert_equal(i.operands[0].strides, (4,48,16))
+ assert_equal(i.operands[0].dtype, np.dtype('u4'))
+
+def test_iter_allocate_output_types_promotion():
+ # Check type promotion of automatic outputs
+
+ i = newiter([array([3],dtype='f4'),array([0],dtype='f8'),None], [],
+ [['readonly']]*2+[['writeonly','allocate']])
+ assert_equal(i.dtypes[2], np.dtype('f8'));
+ i = newiter([array([3],dtype='i4'),array([0],dtype='f4'),None], [],
+ [['readonly']]*2+[['writeonly','allocate']])
+ assert_equal(i.dtypes[2], np.dtype('f8'));
+ i = newiter([array([3],dtype='f4'),array(0,dtype='f8'),None], [],
+ [['readonly']]*2+[['writeonly','allocate']])
+ assert_equal(i.dtypes[2], np.dtype('f4'));
+ i = newiter([array([3],dtype='u4'),array(0,dtype='i4'),None], [],
+ [['readonly']]*2+[['writeonly','allocate']])
+ assert_equal(i.dtypes[2], np.dtype('u4'));
+ i = newiter([array([3],dtype='u4'),array(-12,dtype='i4'),None], [],
+ [['readonly']]*2+[['writeonly','allocate']])
+ assert_equal(i.dtypes[2], np.dtype('i8'));
+
+def test_iter_allocate_output_types_byte_order():
+ # Verify the rules for byte order changes
+
+ # When there's just one input, the output type exactly matches
+ a = array([3],dtype='u4').newbyteorder()
+ i = newiter([a,None], [],
+ [['readonly'],['writeonly','allocate']])
+ assert_equal(i.dtypes[0], i.dtypes[1]);
+ # With two or more inputs, the output type is in native byte order
+ i = newiter([a,a,None], [],
+ [['readonly'],['readonly'],['writeonly','allocate']])
+ assert_(i.dtypes[0] != i.dtypes[2]);
+ assert_equal(i.dtypes[0].newbyteorder('='), i.dtypes[2])
+
+def test_iter_allocate_output_types_scalar():
+ # If the inputs are all scalars, the output should be a scalar
+
+ i = newiter([None,1,2.3,np.float32(12),np.complex128(3)],[],
+ [['writeonly','allocate']] + [['readonly']]*4)
+ assert_equal(i.operands[0].dtype, np.dtype('complex128'))
+ assert_equal(i.operands[0].ndim, 0)
+
+def test_iter_allocate_output_subtype():
+ # Make sure that the subtype with priority wins
+
+ # matrix vs ndarray
+ a = np.matrix([[1,2], [3,4]])
+ b = np.arange(4).reshape(2,2).T
+ i = newiter([a,b,None], [],
+ [['readonly'],['readonly'],['writeonly','allocate']])
+ assert_equal(type(a), type(i.operands[2]))
+ assert_(type(b) != type(i.operands[2]))
+ assert_equal(i.operands[2].shape, (2,2))
+
+ # matrix always wants things to be 2D
+ b = np.arange(4).reshape(1,2,2)
+ assert_raises(RuntimeError, newiter, [a,b,None], [],
+ [['readonly'],['readonly'],['writeonly','allocate']])
+ # but if subtypes are disabled, the result can still work
+ i = newiter([a,b,None], [],
+ [['readonly'],['readonly'],['writeonly','allocate','no_subtype']])
+ assert_equal(type(b), type(i.operands[2]))
+ assert_(type(a) != type(i.operands[2]))
+ assert_equal(i.operands[2].shape, (1,2,2))
+
+def test_iter_allocate_output_errors():
+ # Check that the iterator will throw errors for bad output allocations
+
+ # Need an input if no output data type is specified
+ a = arange(6)
+ assert_raises(TypeError, newiter, [a,None], [],
+ [['writeonly'],['writeonly','allocate']])
+ # Allocated output should be flagged for writing
+ assert_raises(ValueError, newiter, [a,None], [],
+ [['readonly'],['allocate','readonly']])
+ # Allocated output can't have buffering without delayed bufalloc
+ assert_raises(ValueError, newiter, [a,None], ['buffered'],
+ ['allocate','readwrite'])
+ # Must specify at least one input
+ assert_raises(ValueError, newiter, [None,None], [],
+ [['writeonly','allocate'],
+ ['writeonly','allocate']],
+ op_dtypes=[np.dtype('f4'),np.dtype('f4')])
+ # If using op_axes, must specify all the axes
+ a = arange(24, dtype='i4').reshape(2,3,4)
+ assert_raises(ValueError, newiter, [a,None], [],
+ [['readonly'],['writeonly','allocate']],
+ op_dtypes=[None,np.dtype('f4')],
+ op_axes=[None,[0,np.newaxis,1]])
+ # If using op_axes, the axes must be within bounds
+ assert_raises(ValueError, newiter, [a,None], [],
+ [['readonly'],['writeonly','allocate']],
+ op_dtypes=[None,np.dtype('f4')],
+ op_axes=[None,[0,3,1]])
+ # If using op_axes, there can't be duplicates
+ assert_raises(ValueError, newiter, [a,None], [],
+ [['readonly'],['writeonly','allocate']],
+ op_dtypes=[None,np.dtype('f4')],
+ op_axes=[None,[0,2,1,0]])
+
+def test_iter_remove_axis():
+ a = arange(24).reshape(2,3,4)
+
+ i = newiter(a,['coords'])
+ i.remove_axis(1)
+ assert_equal([x for x in i], a[:,0,:].ravel())
+
+ a = a[::-1,:,:]
+ i = newiter(a,['coords'])
+ i.remove_axis(0)
+ assert_equal([x for x in i], a[0,:,:].ravel())
+
+def test_iter_remove_coords_inner_loop():
+ # Check that removing coords support works
+
+ a = arange(24).reshape(2,3,4)
+
+ i = newiter(a,['coords'])
+ assert_equal(i.ndim, 3)
+ assert_equal(i.shape, (2,3,4))
+ assert_equal(i.itviews[0].shape, (2,3,4))
+
+ # Removing coords causes all dimensions to coalesce
+ before = [x for x in i]
+ i.remove_coords()
+ after = [x for x in i]
+
+ assert_equal(before, after)
+ assert_equal(i.ndim, 1)
+ assert_raises(ValueError, lambda i:i.shape, i)
+ assert_equal(i.itviews[0].shape, (24,))
+
+ # Removing the inner loop means there's just one iteration
+ i.reset()
+ assert_equal(i.itersize, 24)
+ assert_equal(i[0].shape, tuple())
+ i.remove_inner_loop()
+ assert_equal(i.itersize, 24)
+ assert_equal(i[0].shape, (24,))
+ assert_equal(i.value, arange(24))
+
+def test_iter_iterindex():
+ # Make sure iterindex works
+
+ buffersize = 5
+ a = arange(24).reshape(4,3,2)
+ for flags in ([], ['buffered']):
+ i = newiter(a, flags, buffersize=buffersize)
+ assert_equal(iter_iterindices(i), range(24))
+ i.iterindex = 2
+ assert_equal(iter_iterindices(i), range(2,24))
+
+ i = newiter(a, flags, order='F', buffersize=buffersize)
+ assert_equal(iter_iterindices(i), range(24))
+ i.iterindex = 5
+ assert_equal(iter_iterindices(i), range(5,24))
+
+ i = newiter(a[::-1], flags, order='F', buffersize=buffersize)
+ assert_equal(iter_iterindices(i), range(24))
+ i.iterindex = 9
+ assert_equal(iter_iterindices(i), range(9,24))
+
+ i = newiter(a[::-1,::-1], flags, order='C', buffersize=buffersize)
+ assert_equal(iter_iterindices(i), range(24))
+ i.iterindex = 13
+ assert_equal(iter_iterindices(i), range(13,24))
+
+ i = newiter(a[::1,::-1], flags, buffersize=buffersize)
+ assert_equal(iter_iterindices(i), range(24))
+ i.iterindex = 23
+ assert_equal(iter_iterindices(i), range(23,24))
+ i.reset()
+ i.iterindex = 2
+ assert_equal(iter_iterindices(i), range(2,24))
+
+def test_iter_iterrange():
+ # Make sure getting and resetting the iterrange works
+
+ buffersize = 5
+ a = arange(24, dtype='i4').reshape(4,3,2)
+ a_fort = a.ravel(order='F')
+
+ i = newiter(a, ['ranged'], ['readonly'], order='F',
+ buffersize=buffersize)
+ assert_equal(i.iterrange, (0,24))
+ assert_equal([x[()] for x in i], a_fort)
+ for r in [(0,24), (1,2), (3,24), (5,5), (0,20), (23,24)]:
+ i.iterrange = r
+ assert_equal(i.iterrange, r)
+ assert_equal([x[()] for x in i], a_fort[r[0]:r[1]])
+
+ i = newiter(a, ['ranged','buffered'], ['readonly'], order='F',
+ op_dtypes='f8', buffersize=buffersize)
+ assert_equal(i.iterrange, (0,24))
+ assert_equal([x[()] for x in i], a_fort)
+ for r in [(0,24), (1,2), (3,24), (5,5), (0,20), (23,24)]:
+ i.iterrange = r
+ assert_equal(i.iterrange, r)
+ assert_equal([x[()] for x in i], a_fort[r[0]:r[1]])
+
+ def get_array(i):
+ val = np.array([], dtype='f8')
+ for x in i:
+ val = np.concatenate((val, x))
+ return val
+
+ i = newiter(a, ['ranged','buffered','no_inner_iteration'],
+ ['readonly'], order='F',
+ op_dtypes='f8', buffersize=buffersize)
+ assert_equal(i.iterrange, (0,24))
+ assert_equal(get_array(i), a_fort)
+ for r in [(0,24), (1,2), (3,24), (5,5), (0,20), (23,24)]:
+ i.iterrange = r
+ assert_equal(i.iterrange, r)
+ assert_equal(get_array(i), a_fort[r[0]:r[1]])
+
+def test_iter_buffering():
+ # Test buffering with several buffer sizes and types
+ arrays = []
+ # F-order swapped array
+ arrays.append(np.arange(24,
+ dtype='c16').reshape(2,3,4).T.newbyteorder().byteswap())
+ # Contiguous 1-dimensional array
+ arrays.append(np.arange(10, dtype='f4'))
+ # Unaligned array
+ a = np.zeros((4*16+1,), dtype='i1')[1:]
+ a.dtype = 'i4'
+ a[:] = np.arange(16,dtype='i4')
+ arrays.append(a)
+ # 4-D F-order array
+ arrays.append(np.arange(120,dtype='i4').reshape(5,3,2,4).T)
+ for a in arrays:
+ for buffersize in (1,2,3,5,8,11,16,1024):
+ vals = []
+ i = newiter(a, ['buffered','no_inner_iteration'],
+ [['readonly','nbo','aligned']],
+ order='C',
+ casting='equiv',
+ buffersize=buffersize)
+ while not i.finished:
+ assert_(i[0].size <= buffersize)
+ vals.append(i[0].copy())
+ i.iternext()
+ assert_equal(np.concatenate(vals), a.ravel(order='C'))
+
+def test_iter_write_buffering():
+ # Test that buffering of writes is working
+
+ # F-order swapped array
+ a = np.arange(24).reshape(2,3,4).T.newbyteorder().byteswap()
+ i = newiter(a, ['buffered'],
+ [['readwrite','nbo','aligned']],
+ casting='equiv',
+ order='C',
+ buffersize=16)
+ x = 0
+ while not i.finished:
+ i[0] = x
+ x += 1
+ i.iternext()
+ assert_equal(a.ravel(order='C'), np.arange(24))
+
+def test_iter_buffering_delayed_alloc():
+ # Test that delaying buffer allocation works
+
+ a = np.arange(6)
+ b = np.arange(1, dtype='f4')
+ i = newiter([a,b], ['buffered','delay_bufalloc','coords','reduce_ok'],
+ ['readwrite'],
+ casting='unsafe',
+ op_dtypes='f4')
+ assert_(i.hasdelayedbufalloc)
+ assert_raises(ValueError, lambda i:i.coords, i)
+ assert_raises(ValueError, lambda i:i[0], i)
+ assert_raises(ValueError, lambda i:i[0:2], i)
+ def assign_iter(i):
+ i[0] = 0
+ assert_raises(ValueError, assign_iter, i)
+
+ i.reset()
+ assert_(not i.hasdelayedbufalloc)
+ assert_equal(i.coords, (0,))
+ assert_equal(i[0], 0)
+ i[1] = 1
+ assert_equal(i[0:2], [0,1])
+ assert_equal([[x[0][()],x[1][()]] for x in i], zip(range(6), [1]*6))
+
+def test_iter_buffered_cast_simple():
+ # Test that buffering can handle a simple cast
+
+ a = np.arange(10, dtype='f4')
+ i = newiter(a, ['buffered','no_inner_iteration'],
+ [['readwrite','nbo','aligned']],
+ casting='same_kind',
+ op_dtypes=[np.dtype('f8')],
+ buffersize=3)
+ for v in i:
+ v[...] *= 2
+
+ assert_equal(a, 2*np.arange(10, dtype='f4'))
+
+def test_iter_buffered_cast_byteswapped():
+ # Test that buffering can handle a cast which requires swap->cast->swap
+
+ a = np.arange(10, dtype='f4').newbyteorder().byteswap()
+ i = newiter(a, ['buffered','no_inner_iteration'],
+ [['readwrite','nbo','aligned']],
+ casting='same_kind',
+ op_dtypes=[np.dtype('f8').newbyteorder()],
+ buffersize=3)
+ for v in i:
+ v[...] *= 2
+
+ assert_equal(a, 2*np.arange(10, dtype='f4'))
+
+ try:
+ warnings.simplefilter("ignore", np.ComplexWarning)
+
+ a = np.arange(10, dtype='f8').newbyteorder().byteswap()
+ i = newiter(a, ['buffered','no_inner_iteration'],
+ [['readwrite','nbo','aligned']],
+ casting='unsafe',
+ op_dtypes=[np.dtype('c8').newbyteorder()],
+ buffersize=3)
+ for v in i:
+ v[...] *= 2
+
+ assert_equal(a, 2*np.arange(10, dtype='f8'))
+ finally:
+ warnings.simplefilter("default", np.ComplexWarning)
+
+def test_iter_buffered_cast_byteswapped_complex():
+ # Test that buffering can handle a cast which requires swap->cast->copy
+
+ a = np.arange(10, dtype='c8').newbyteorder().byteswap()
+ a += 2j
+ i = newiter(a, ['buffered','no_inner_iteration'],
+ [['readwrite','nbo','aligned']],
+ casting='same_kind',
+ op_dtypes=[np.dtype('c16')],
+ buffersize=3)
+ for v in i:
+ v[...] *= 2
+ assert_equal(a, 2*np.arange(10, dtype='c8') + 4j)
+
+ a = np.arange(10, dtype='c8')
+ a += 2j
+ i = newiter(a, ['buffered','no_inner_iteration'],
+ [['readwrite','nbo','aligned']],
+ casting='same_kind',
+ op_dtypes=[np.dtype('c16').newbyteorder()],
+ buffersize=3)
+ for v in i:
+ v[...] *= 2
+ assert_equal(a, 2*np.arange(10, dtype='c8') + 4j)
+
+ a = np.arange(10, dtype=np.clongdouble).newbyteorder().byteswap()
+ a += 2j
+ i = newiter(a, ['buffered','no_inner_iteration'],
+ [['readwrite','nbo','aligned']],
+ casting='same_kind',
+ op_dtypes=[np.dtype('c16')],
+ buffersize=3)
+ for v in i:
+ v[...] *= 2
+ assert_equal(a, 2*np.arange(10, dtype=np.clongdouble) + 4j)
+
+ a = np.arange(10, dtype=np.longdouble).newbyteorder().byteswap()
+ i = newiter(a, ['buffered','no_inner_iteration'],
+ [['readwrite','nbo','aligned']],
+ casting='same_kind',
+ op_dtypes=[np.dtype('f4')],
+ buffersize=7)
+ for v in i:
+ v[...] *= 2
+ assert_equal(a, 2*np.arange(10, dtype=np.longdouble))
+
+def test_iter_buffered_cast_structured_type():
+ # Tests buffering of structured types
+
+ # simple -> struct type (duplicates the value)
+ sdt = [('a', 'f4'), ('b', 'i8'), ('c', 'c8', (2,3)), ('d', 'O')]
+ a = np.arange(3, dtype='f4') + 0.5
+ i = newiter(a, ['buffered','refs_ok'], ['readonly'],
+ casting='unsafe',
+ op_dtypes=sdt)
+ vals = [np.array(x) for x in i]
+ assert_equal(vals[0]['a'], 0.5)
+ assert_equal(vals[0]['b'], 0)
+ assert_equal(vals[0]['c'], [[(0.5)]*3]*2)
+ assert_equal(vals[0]['d'], 0.5)
+ assert_equal(vals[1]['a'], 1.5)
+ assert_equal(vals[1]['b'], 1)
+ assert_equal(vals[1]['c'], [[(1.5)]*3]*2)
+ assert_equal(vals[1]['d'], 1.5)
+ assert_equal(vals[0].dtype, np.dtype(sdt))
+
+ # object -> struct type
+ sdt = [('a', 'f4'), ('b', 'i8'), ('c', 'c8', (2,3)), ('d', 'O')]
+ a = np.arange(3, dtype='O') + 0.5
+ rc = sys.getrefcount(a[0])
+ i = newiter(a, ['buffered','refs_ok'], ['readonly'],
+ casting='unsafe',
+ op_dtypes=sdt)
+ vals = [np.array(x) for x in i]
+ assert_equal(vals[0]['a'], 0.5)
+ assert_equal(vals[0]['b'], 0)
+ assert_equal(vals[0]['c'], [[(0.5)]*3]*2)
+ assert_equal(vals[0]['d'], 0.5)
+ assert_equal(vals[1]['a'], 1.5)
+ assert_equal(vals[1]['b'], 1)
+ assert_equal(vals[1]['c'], [[(1.5)]*3]*2)
+ assert_equal(vals[1]['d'], 1.5)
+ assert_equal(vals[0].dtype, np.dtype(sdt))
+ vals, i, x = [None]*3
+ assert_equal(sys.getrefcount(a[0]), rc)
+
+ # struct type -> simple (takes the first value)
+ sdt = [('a', 'f4'), ('b', 'i8'), ('d', 'O')]
+ a = np.array([(5.5,7,'test'),(8,10,11)], dtype=sdt)
+ i = newiter(a, ['buffered','refs_ok'], ['readonly'],
+ casting='unsafe',
+ op_dtypes='i4')
+ assert_equal([x[()] for x in i], [5, 8])
+
+ # struct type -> struct type (field-wise copy)
+ sdt1 = [('a', 'f4'), ('b', 'i8'), ('d', 'O')]
+ sdt2 = [('d', 'u2'), ('a', 'O'), ('b', 'f8')]
+ a = np.array([(1,2,3),(4,5,6)], dtype=sdt1)
+ i = newiter(a, ['buffered','refs_ok'], ['readonly'],
+ casting='unsafe',
+ op_dtypes=sdt2)
+ assert_equal(i[0].dtype, np.dtype(sdt2))
+ assert_equal([np.array(x) for x in i],
+ [np.array((3,1,2), dtype=sdt2),
+ np.array((6,4,5), dtype=sdt2)])
+
+ # struct type -> struct type (field gets discarded)
+ sdt1 = [('a', 'f4'), ('b', 'i8'), ('d', 'O')]
+ sdt2 = [('b', 'O'), ('a', 'f8')]
+ a = np.array([(1,2,3),(4,5,6)], dtype=sdt1)
+ i = newiter(a, ['buffered','refs_ok'], ['readwrite'],
+ casting='unsafe',
+ op_dtypes=sdt2)
+ assert_equal(i[0].dtype, np.dtype(sdt2))
+ vals = []
+ for x in i:
+ vals.append(np.array(x))
+ x['a'] = x['b']+3
+ assert_equal(vals, [np.array((2,1), dtype=sdt2),
+ np.array((5,4), dtype=sdt2)])
+ assert_equal(a, np.array([(5,2,None),(8,5,None)], dtype=sdt1))
+
+ # struct type -> struct type (structured field gets discarded)
+ sdt1 = [('a', 'f4'), ('b', 'i8'), ('d', [('a', 'i2'),('b','i4')])]
+ sdt2 = [('b', 'O'), ('a', 'f8')]
+ a = np.array([(1,2,(0,9)),(4,5,(20,21))], dtype=sdt1)
+ i = newiter(a, ['buffered','refs_ok'], ['readwrite'],
+ casting='unsafe',
+ op_dtypes=sdt2)
+ assert_equal(i[0].dtype, np.dtype(sdt2))
+ vals = []
+ for x in i:
+ vals.append(np.array(x))
+ x['a'] = x['b']+3
+ assert_equal(vals, [np.array((2,1), dtype=sdt2),
+ np.array((5,4), dtype=sdt2)])
+ assert_equal(a, np.array([(5,2,(0,0)),(8,5,(0,0))], dtype=sdt1))
+
+ # struct type -> struct type (structured field w/ ref gets discarded)
+ sdt1 = [('a', 'f4'), ('b', 'i8'), ('d', [('a', 'i2'),('b','O')])]
+ sdt2 = [('b', 'O'), ('a', 'f8')]
+ a = np.array([(1,2,(0,9)),(4,5,(20,21))], dtype=sdt1)
+ i = newiter(a, ['buffered','refs_ok'], ['readwrite'],
+ casting='unsafe',
+ op_dtypes=sdt2)
+ assert_equal(i[0].dtype, np.dtype(sdt2))
+ vals = []
+ for x in i:
+ vals.append(np.array(x))
+ x['a'] = x['b']+3
+ assert_equal(vals, [np.array((2,1), dtype=sdt2),
+ np.array((5,4), dtype=sdt2)])
+ assert_equal(a, np.array([(5,2,(0,None)),(8,5,(0,None))], dtype=sdt1))
+
+ # struct type -> struct type back (structured field w/ ref gets discarded)
+ sdt1 = [('b', 'O'), ('a', 'f8')]
+ sdt2 = [('a', 'f4'), ('b', 'i8'), ('d', [('a', 'i2'),('b','O')])]
+ a = np.array([(1,2),(4,5)], dtype=sdt1)
+ i = newiter(a, ['buffered','refs_ok'], ['readwrite'],
+ casting='unsafe',
+ op_dtypes=sdt2)
+ assert_equal(i[0].dtype, np.dtype(sdt2))
+ vals = []
+ for x in i:
+ vals.append(np.array(x))
+ assert_equal(x['d'], np.array((0, None), dtype=[('a','i2'),('b','O')]))
+ x['a'] = x['b']+3
+ assert_equal(vals, [np.array((2,1,(0,None)), dtype=sdt2),
+ np.array((5,4,(0,None)), dtype=sdt2)])
+ assert_equal(a, np.array([(1,4),(4,7)], dtype=sdt1))
+
+def test_iter_buffered_cast_subarray():
+ # Tests buffering of subarrays
+
+ # one element -> many (copies it to all)
+ sdt1 = [('a', 'f4')]
+ sdt2 = [('a', 'f8', (3,2,2))]
+ a = np.zeros((6,), dtype=sdt1)
+ a['a'] = np.arange(6)
+ i = newiter(a, ['buffered','refs_ok'], ['readonly'],
+ casting='unsafe',
+ op_dtypes=sdt2)
+ assert_equal(i[0].dtype, np.dtype(sdt2))
+ for x, count in zip(i, range(6)):
+ assert_(np.all(x['a'] == count))
+
+ # one element -> many -> back (copies it to all)
+ sdt1 = [('a', 'O', (1,1))]
+ sdt2 = [('a', 'O', (3,2,2))]
+ a = np.zeros((6,), dtype=sdt1)
+ a['a'][:,0,0] = np.arange(6)
+ i = newiter(a, ['buffered','refs_ok'], ['readwrite'],
+ casting='unsafe',
+ op_dtypes=sdt2)
+ assert_equal(i[0].dtype, np.dtype(sdt2))
+ count = 0
+ for x in i:
+ assert_(np.all(x['a'] == count))
+ x['a'][0] += 2
+ count += 1
+ assert_equal(a['a'], np.arange(6).reshape(6,1,1)+2)
+
+ # many -> one element -> back (copies just element 0)
+ sdt1 = [('a', 'O', (3,2,2))]
+ sdt2 = [('a', 'O', (1,))]
+ a = np.zeros((6,), dtype=sdt1)
+ a['a'][:,0,0,0] = np.arange(6)
+ i = newiter(a, ['buffered','refs_ok'], ['readwrite'],
+ casting='unsafe',
+ op_dtypes=sdt2)
+ assert_equal(i[0].dtype, np.dtype(sdt2))
+ count = 0
+ for x in i:
+ assert_equal(x['a'], count)
+ x['a'] += 2
+ count += 1
+ assert_equal(a['a'], np.arange(6).reshape(6,1,1,1)*np.ones((1,3,2,2))+2)
+
+ # many -> one element -> back (copies just element 0)
+ sdt1 = [('a', 'f8', (3,2,2))]
+ sdt2 = [('a', 'O', (1,))]
+ a = np.zeros((6,), dtype=sdt1)
+ a['a'][:,0,0,0] = np.arange(6)
+ i = newiter(a, ['buffered','refs_ok'], ['readonly'],
+ casting='unsafe',
+ op_dtypes=sdt2)
+ assert_equal(i[0].dtype, np.dtype(sdt2))
+ count = 0
+ for x in i:
+ assert_equal(x['a'], count)
+ count += 1
+
+ # many -> one element (copies just element 0)
+ sdt1 = [('a', 'O', (3,2,2))]
+ sdt2 = [('a', 'f4', (1,))]
+ a = np.zeros((6,), dtype=sdt1)
+ a['a'][:,0,0,0] = np.arange(6)
+ i = newiter(a, ['buffered','refs_ok'], ['readonly'],
+ casting='unsafe',
+ op_dtypes=sdt2)
+ assert_equal(i[0].dtype, np.dtype(sdt2))
+ count = 0
+ for x in i:
+ assert_equal(x['a'], count)
+ count += 1
+
+ # many -> matching shape (straightforward copy)
+ sdt1 = [('a', 'O', (3,2,2))]
+ sdt2 = [('a', 'f4', (3,2,2))]
+ a = np.zeros((6,), dtype=sdt1)
+ a['a'] = np.arange(6*3*2*2).reshape(6,3,2,2)
+ i = newiter(a, ['buffered','refs_ok'], ['readonly'],
+ casting='unsafe',
+ op_dtypes=sdt2)
+ assert_equal(i[0].dtype, np.dtype(sdt2))
+ count = 0
+ for x in i:
+ assert_equal(x['a'], a[count]['a'])
+ count += 1
+
+ # vector -> smaller vector (truncates)
+ sdt1 = [('a', 'f8', (6,))]
+ sdt2 = [('a', 'f4', (2,))]
+ a = np.zeros((6,), dtype=sdt1)
+ a['a'] = np.arange(6*6).reshape(6,6)
+ i = newiter(a, ['buffered','refs_ok'], ['readonly'],
+ casting='unsafe',
+ op_dtypes=sdt2)
+ assert_equal(i[0].dtype, np.dtype(sdt2))
+ count = 0
+ for x in i:
+ assert_equal(x['a'], a[count]['a'][:2])
+ count += 1
+
+ # vector -> bigger vector (pads with zeros)
+ sdt1 = [('a', 'f8', (2,))]
+ sdt2 = [('a', 'f4', (6,))]
+ a = np.zeros((6,), dtype=sdt1)
+ a['a'] = np.arange(6*2).reshape(6,2)
+ i = newiter(a, ['buffered','refs_ok'], ['readonly'],
+ casting='unsafe',
+ op_dtypes=sdt2)
+ assert_equal(i[0].dtype, np.dtype(sdt2))
+ count = 0
+ for x in i:
+ assert_equal(x['a'][:2], a[count]['a'])
+ assert_equal(x['a'][2:], [0,0,0,0])
+ count += 1
+
+ # vector -> matrix (broadcasts)
+ sdt1 = [('a', 'f8', (2,))]
+ sdt2 = [('a', 'f4', (2,2))]
+ a = np.zeros((6,), dtype=sdt1)
+ a['a'] = np.arange(6*2).reshape(6,2)
+ i = newiter(a, ['buffered','refs_ok'], ['readonly'],
+ casting='unsafe',
+ op_dtypes=sdt2)
+ assert_equal(i[0].dtype, np.dtype(sdt2))
+ count = 0
+ for x in i:
+ assert_equal(x['a'][0], a[count]['a'])
+ assert_equal(x['a'][1], a[count]['a'])
+ count += 1
+
+ # vector -> matrix (broadcasts and zero-pads)
+ sdt1 = [('a', 'f8', (2,1))]
+ sdt2 = [('a', 'f4', (3,2))]
+ a = np.zeros((6,), dtype=sdt1)
+ a['a'] = np.arange(6*2).reshape(6,2,1)
+ i = newiter(a, ['buffered','refs_ok'], ['readonly'],
+ casting='unsafe',
+ op_dtypes=sdt2)
+ assert_equal(i[0].dtype, np.dtype(sdt2))
+ count = 0
+ for x in i:
+ assert_equal(x['a'][:2,0], a[count]['a'][:,0])
+ assert_equal(x['a'][:2,1], a[count]['a'][:,0])
+ assert_equal(x['a'][2,:], [0,0])
+ count += 1
+
+ # matrix -> matrix (truncates and zero-pads)
+ sdt1 = [('a', 'f8', (2,3))]
+ sdt2 = [('a', 'f4', (3,2))]
+ a = np.zeros((6,), dtype=sdt1)
+ a['a'] = np.arange(6*2*3).reshape(6,2,3)
+ i = newiter(a, ['buffered','refs_ok'], ['readonly'],
+ casting='unsafe',
+ op_dtypes=sdt2)
+ assert_equal(i[0].dtype, np.dtype(sdt2))
+ count = 0
+ for x in i:
+ assert_equal(x['a'][:2,0], a[count]['a'][:,0])
+ assert_equal(x['a'][:2,1], a[count]['a'][:,1])
+ assert_equal(x['a'][2,:], [0,0])
+ count += 1
+
+def test_iter_buffering_badwriteback():
+ # Writing back from a buffer cannot combine elements
+
+ # a needs write buffering, but had a broadcast dimension
+ a = np.arange(6).reshape(2,3,1)
+ b = np.arange(12).reshape(2,3,2)
+ assert_raises(ValueError,newiter,[a,b],
+ ['buffered','no_inner_iteration'],
+ [['readwrite'],['writeonly']],
+ order='C')
+
+ # But if a is readonly, it's fine
+ i = newiter([a,b],['buffered','no_inner_iteration'],
+ [['readonly'],['writeonly']],
+ order='C')
+
+ # If a has just one element, it's fine too (constant 0 stride, a reduction)
+ a = np.arange(1).reshape(1,1,1)
+ i = newiter([a,b],['buffered','no_inner_iteration','reduce_ok'],
+ [['readwrite'],['writeonly']],
+ order='C')
+
+ # check that it fails on other dimensions too
+ a = np.arange(6).reshape(1,3,2)
+ assert_raises(ValueError,newiter,[a,b],
+ ['buffered','no_inner_iteration'],
+ [['readwrite'],['writeonly']],
+ order='C')
+ a = np.arange(4).reshape(2,1,2)
+ assert_raises(ValueError,newiter,[a,b],
+ ['buffered','no_inner_iteration'],
+ [['readwrite'],['writeonly']],
+ order='C')
+
+def test_iter_buffering_string():
+ # Safe casting disallows shrinking strings
+ a = np.array(['abc', 'a', 'abcd'], dtype=np.bytes_)
+ assert_equal(a.dtype, np.dtype('S4'));
+ assert_raises(TypeError,newiter,a,['buffered'],['readonly'],
+ op_dtypes='S2')
+ i = newiter(a, ['buffered'], ['readonly'], op_dtypes='S6')
+ assert_equal(i[0], asbytes('abc'))
+ assert_equal(i[0].dtype, np.dtype('S6'))
+
+ a = np.array(['abc', 'a', 'abcd'], dtype=np.unicode)
+ assert_equal(a.dtype, np.dtype('U4'));
+ assert_raises(TypeError,newiter,a,['buffered'],['readonly'],
+ op_dtypes='U2')
+ i = newiter(a, ['buffered'], ['readonly'], op_dtypes='U6')
+ assert_equal(i[0], u'abc')
+ assert_equal(i[0].dtype, np.dtype('U6'))
+
+def test_iter_buffering_growinner():
+ # Test that the inner loop grows when no buffering is needed
+ a = np.arange(30)
+ i = newiter(a, ['buffered','growinner','no_inner_iteration'],
+ buffersize=5)
+ # Should end up with just one inner loop here
+ assert_equal(i[0].size, a.size)
+
+def test_iter_no_broadcast():
+ # Test that the no_broadcast flag works
+ a = np.arange(24).reshape(2,3,4)
+ b = np.arange(6).reshape(2,3,1)
+ c = np.arange(12).reshape(3,4)
+
+ i = newiter([a,b,c], [],
+ [['readonly','no_broadcast'],['readonly'],['readonly']])
+ assert_raises(ValueError, newiter, [a,b,c], [],
+ [['readonly'],['readonly','no_broadcast'],['readonly']])
+ assert_raises(ValueError, newiter, [a,b,c], [],
+ [['readonly'],['readonly'],['readonly','no_broadcast']])
+
+def test_iter_nested_iters_basic():
+ # Test nested iteration basic usage
+ a = arange(12).reshape(2,3,2)
+
+ i, j = np.nested_iters(a, [[0],[1,2]])
+ vals = []
+ for x in i:
+ vals.append([y for y in j])
+ assert_equal(vals, [[0,1,2,3,4,5],[6,7,8,9,10,11]])
+
+ i, j = np.nested_iters(a, [[0,1],[2]])
+ vals = []
+ for x in i:
+ vals.append([y for y in j])
+ assert_equal(vals, [[0,1],[2,3],[4,5],[6,7],[8,9],[10,11]])
+
+ i, j = np.nested_iters(a, [[0,2],[1]])
+ vals = []
+ for x in i:
+ vals.append([y for y in j])
+ assert_equal(vals, [[0,2,4],[1,3,5],[6,8,10],[7,9,11]])
+
+def test_iter_nested_iters_reorder():
+ # Test nested iteration basic usage
+ a = arange(12).reshape(2,3,2)
+
+ # In 'K' order (default), it gets reordered
+ i, j = np.nested_iters(a, [[0],[2,1]])
+ vals = []
+ for x in i:
+ vals.append([y for y in j])
+ assert_equal(vals, [[0,1,2,3,4,5],[6,7,8,9,10,11]])
+
+ i, j = np.nested_iters(a, [[1,0],[2]])
+ vals = []
+ for x in i:
+ vals.append([y for y in j])
+ assert_equal(vals, [[0,1],[2,3],[4,5],[6,7],[8,9],[10,11]])
+
+ i, j = np.nested_iters(a, [[2,0],[1]])
+ vals = []
+ for x in i:
+ vals.append([y for y in j])
+ assert_equal(vals, [[0,2,4],[1,3,5],[6,8,10],[7,9,11]])
+
+ # In 'C' order, it doesn't
+ i, j = np.nested_iters(a, [[0],[2,1]], order='C')
+ vals = []
+ for x in i:
+ vals.append([y for y in j])
+ assert_equal(vals, [[0,2,4,1,3,5],[6,8,10,7,9,11]])
+
+ i, j = np.nested_iters(a, [[1,0],[2]], order='C')
+ vals = []
+ for x in i:
+ vals.append([y for y in j])
+ assert_equal(vals, [[0,1],[6,7],[2,3],[8,9],[4,5],[10,11]])
+
+ i, j = np.nested_iters(a, [[2,0],[1]], order='C')
+ vals = []
+ for x in i:
+ vals.append([y for y in j])
+ assert_equal(vals, [[0,2,4],[6,8,10],[1,3,5],[7,9,11]])
+
+def test_iter_nested_iters_flip_axes():
+ # Test nested iteration with negative axes
+ a = arange(12).reshape(2,3,2)[::-1,::-1,::-1]
+
+ # In 'K' order (default), the axes all get flipped
+ i, j = np.nested_iters(a, [[0],[1,2]])
+ vals = []
+ for x in i:
+ vals.append([y for y in j])
+ assert_equal(vals, [[0,1,2,3,4,5],[6,7,8,9,10,11]])
+
+ i, j = np.nested_iters(a, [[0,1],[2]])
+ vals = []
+ for x in i:
+ vals.append([y for y in j])
+ assert_equal(vals, [[0,1],[2,3],[4,5],[6,7],[8,9],[10,11]])
+
+ i, j = np.nested_iters(a, [[0,2],[1]])
+ vals = []
+ for x in i:
+ vals.append([y for y in j])
+ assert_equal(vals, [[0,2,4],[1,3,5],[6,8,10],[7,9,11]])
+
+ # In 'C' order, flipping axes is disabled
+ i, j = np.nested_iters(a, [[0],[1,2]], order='C')
+ vals = []
+ for x in i:
+ vals.append([y for y in j])
+ assert_equal(vals, [[11,10,9,8,7,6],[5,4,3,2,1,0]])
+
+ i, j = np.nested_iters(a, [[0,1],[2]], order='C')
+ vals = []
+ for x in i:
+ vals.append([y for y in j])
+ assert_equal(vals, [[11,10],[9,8],[7,6],[5,4],[3,2],[1,0]])
+
+ i, j = np.nested_iters(a, [[0,2],[1]], order='C')
+ vals = []
+ for x in i:
+ vals.append([y for y in j])
+ assert_equal(vals, [[11,9,7],[10,8,6],[5,3,1],[4,2,0]])
+
+def test_iter_nested_iters_broadcast():
+ # Test nested iteration with broadcasting
+ a = arange(2).reshape(2,1)
+ b = arange(3).reshape(1,3)
+
+ i, j = np.nested_iters([a,b], [[0],[1]])
+ vals = []
+ for x in i:
+ vals.append([y for y in j])
+ assert_equal(vals, [[[0,0],[0,1],[0,2]],[[1,0],[1,1],[1,2]]])
+
+ i, j = np.nested_iters([a,b], [[1],[0]])
+ vals = []
+ for x in i:
+ vals.append([y for y in j])
+ assert_equal(vals, [[[0,0],[1,0]],[[0,1],[1,1]],[[0,2],[1,2]]])
+
+def test_iter_nested_iters_dtype_copy():
+ # Test nested iteration with a copy to change dtype
+
+ # copy
+ a = arange(6, dtype='i4').reshape(2,3)
+ i, j = np.nested_iters(a, [[0],[1]],
+ op_flags=['readonly','copy'],
+ op_dtypes='f8')
+ assert_equal(j[0].dtype, np.dtype('f8'))
+ vals = []
+ for x in i:
+ vals.append([y for y in j])
+ assert_equal(vals, [[0,1,2],[3,4,5]])
+ vals = None
+
+ # updateifcopy
+ a = arange(6, dtype='f4').reshape(2,3)
+ i, j = np.nested_iters(a, [[0],[1]],
+ op_flags=['readwrite','updateifcopy'],
+ casting='same_kind',
+ op_dtypes='f8')
+ assert_equal(j[0].dtype, np.dtype('f8'))
+ for x in i:
+ for y in j:
+ y[...] += 1
+ assert_equal(a, [[0,1,2],[3,4,5]])
+ i, j, x, y = (None,)*4 # force the updateifcopy
+ assert_equal(a, [[1,2,3],[4,5,6]])
+
+def test_iter_nested_iters_dtype_buffered():
+ # Test nested iteration with buffering to change dtype
+
+ a = arange(6, dtype='f4').reshape(2,3)
+ i, j = np.nested_iters(a, [[0],[1]],
+ flags=['buffered'],
+ op_flags=['readwrite'],
+ casting='same_kind',
+ op_dtypes='f8')
+ assert_equal(j[0].dtype, np.dtype('f8'))
+ for x in i:
+ for y in j:
+ y[...] += 1
+ assert_equal(a, [[1,2,3],[4,5,6]])
+
+def test_iter_reduction_error():
+
+ a = np.arange(6)
+ assert_raises(ValueError, newiter, [a,None], [],
+ [['readonly'], ['readwrite','allocate']],
+ op_axes=[[0],[-1]])
+
+ a = np.arange(6).reshape(2,3)
+ assert_raises(ValueError, newiter, [a,None], ['no_inner_iteration'],
+ [['readonly'], ['readwrite','allocate']],
+ op_axes=[[0,1],[-1,-1]])
+
+def test_iter_reduction():
+ # Test doing reductions with the iterator
+
+ a = np.arange(6)
+ i = newiter([a,None], ['reduce_ok'],
+ [['readonly'], ['readwrite','allocate']],
+ op_axes=[[0],[-1]])
+ # Need to initialize the output operand to the addition unit
+ i.operands[1][...] = 0
+ # Do the reduction
+ for x, y in i:
+ y[...] += x
+ # Since no axes were specified, should have allocated a scalar
+ assert_equal(i.operands[1].ndim, 0)
+ assert_equal(i.operands[1], np.sum(a))
+
+ a = np.arange(6).reshape(2,3)
+ i = newiter([a,None], ['reduce_ok','no_inner_iteration'],
+ [['readonly'], ['readwrite','allocate']],
+ op_axes=[[0,1],[-1,-1]])
+ # Need to initialize the output operand to the addition unit
+ i.operands[1][...] = 0
+ # Reduction shape/strides for the output
+ assert_equal(i[1].shape, (6,))
+ assert_equal(i[1].strides, (0,))
+ # Do the reduction
+ for x, y in i:
+ y[...] += x
+ # Since no axes were specified, should have allocated a scalar
+ assert_equal(i.operands[1].ndim, 0)
+ assert_equal(i.operands[1], np.sum(a))
+
+
+def test_iter_buffering_reduction():
+ # Test doing buffered reductions with the iterator
+
+ a = np.arange(6)
+ b = np.array(0., dtype='f8').byteswap().newbyteorder()
+ i = newiter([a,b], ['reduce_ok', 'buffered'],
+ [['readonly'], ['readwrite','nbo']],
+ op_axes=[[0],[-1]])
+ assert_equal(i[1].dtype, np.dtype('f8'))
+ assert_(i[1].dtype != b.dtype)
+ # Do the reduction
+ for x, y in i:
+ y[...] += x
+ # Since no axes were specified, should have allocated a scalar
+ assert_equal(b, np.sum(a))
+
+ a = np.arange(6).reshape(2,3)
+ b = np.array([0,0], dtype='f8').byteswap().newbyteorder()
+ i = newiter([a,b], ['reduce_ok','no_inner_iteration', 'buffered'],
+ [['readonly'], ['readwrite','nbo']],
+ op_axes=[[0,1],[0,-1]])
+ # Reduction shape/strides for the output
+ assert_equal(i[1].shape, (3,))
+ assert_equal(i[1].strides, (0,))
+ # Do the reduction
+ for x, y in i:
+ y[...] += x
+ assert_equal(b, np.sum(a, axis=1))
+
+if __name__ == "__main__":
+ run_module_suite()
diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py
index d8f179454..3752e0571 100644
--- a/numpy/core/tests/test_numeric.py
+++ b/numpy/core/tests/test_numeric.py
@@ -5,7 +5,9 @@ import numpy as np
from numpy.core import *
from numpy.random import rand, randint, randn
from numpy.testing import *
+from numpy.testing.utils import WarningManager
from numpy.core.multiarray import dot as dot_
+import warnings
class Vec:
def __init__(self,sequence=None):
@@ -151,7 +153,6 @@ class TestResize(TestCase):
Ar = resize(A, (0,))
assert_equal(Ar, array([]))
-
class TestNonarrayArgs(TestCase):
# check that non-array arguments to functions wrap them in arrays
def test_squeeze(self):
@@ -315,9 +316,13 @@ class TestFloatExceptions(TestCase):
lambda a,b:a+b, ft_max, ft_max*ft_eps)
self.assert_raises_fpe(overflow,
lambda a,b:a-b, -ft_max, ft_max*ft_eps)
+ self.assert_raises_fpe(overflow,
+ np.power, ftype(2), ftype(2**fi.nexp))
self.assert_raises_fpe(divbyzero,
lambda a,b:a/b, ftype(1), ftype(0))
self.assert_raises_fpe(invalid,
+ lambda a,b:a/b, ftype(np.inf), ftype(np.inf))
+ self.assert_raises_fpe(invalid,
lambda a,b:a/b, ftype(0), ftype(0))
self.assert_raises_fpe(invalid,
lambda a,b:a-b, ftype(np.inf), ftype(np.inf))
@@ -325,13 +330,11 @@ class TestFloatExceptions(TestCase):
lambda a,b:a+b, ftype(np.inf), ftype(-np.inf))
self.assert_raises_fpe(invalid,
lambda a,b:a*b, ftype(0), ftype(np.inf))
- self.assert_raises_fpe(overflow,
- np.power, ftype(2), ftype(2**fi.nexp))
finally:
np.seterr(**oldsettings)
-class TestCoercion(TestCase):
- def test_coercion(self):
+class TestTypes(TestCase):
+ def check_promotion_cases(self, promote_func):
"""Tests that the scalars get coerced correctly."""
i8, i16, i32, i64 = int8(0), int16(0), int32(0), int64(0)
u8, u16, u32, u64 = uint8(0), uint16(0), uint32(0), uint64(0)
@@ -339,40 +342,106 @@ class TestCoercion(TestCase):
c64, c128, cld = complex64(0), complex128(0), clongdouble(0)
# coercion within the same type
- assert_equal(np.add(i8,i16).dtype, int16)
- assert_equal(np.add(i32,i8).dtype, int32)
- assert_equal(np.add(i16,i64).dtype, int64)
- assert_equal(np.add(u8,u32).dtype, uint32)
- assert_equal(np.add(f32,f64).dtype, float64)
- assert_equal(np.add(fld,f32).dtype, longdouble)
- assert_equal(np.add(f64,fld).dtype, longdouble)
- assert_equal(np.add(c128,c64).dtype, complex128)
- assert_equal(np.add(cld,c128).dtype, clongdouble)
- assert_equal(np.add(c64,fld).dtype, clongdouble)
+ assert_equal(promote_func(i8,i16), np.dtype(int16))
+ assert_equal(promote_func(i32,i8), np.dtype(int32))
+ assert_equal(promote_func(i16,i64), np.dtype(int64))
+ assert_equal(promote_func(u8,u32), np.dtype(uint32))
+ assert_equal(promote_func(f32,f64), np.dtype(float64))
+ assert_equal(promote_func(fld,f32), np.dtype(longdouble))
+ assert_equal(promote_func(f64,fld), np.dtype(longdouble))
+ assert_equal(promote_func(c128,c64), np.dtype(complex128))
+ assert_equal(promote_func(cld,c128), np.dtype(clongdouble))
+ assert_equal(promote_func(c64,fld), np.dtype(clongdouble))
# coercion between types
- assert_equal(np.add(i8,u8).dtype, int16)
- assert_equal(np.add(u8,i32).dtype, int32)
- assert_equal(np.add(i64,u32).dtype, int64)
- assert_equal(np.add(u64,i32).dtype, float64)
- assert_equal(np.add(i32,f32).dtype, float64)
- assert_equal(np.add(i64,f32).dtype, float64)
- assert_equal(np.add(f32,i16).dtype, float32)
- assert_equal(np.add(f32,u32).dtype, float64)
- assert_equal(np.add(f32,c64).dtype, complex64)
- assert_equal(np.add(c128,f32).dtype, complex128)
- assert_equal(np.add(cld,f64).dtype, clongdouble)
+ assert_equal(promote_func(i8,u8), np.dtype(int16))
+ assert_equal(promote_func(u8,i32), np.dtype(int32))
+ assert_equal(promote_func(i64,u32), np.dtype(int64))
+ assert_equal(promote_func(u64,i32), np.dtype(float64))
+ assert_equal(promote_func(i32,f32), np.dtype(float64))
+ assert_equal(promote_func(i64,f32), np.dtype(float64))
+ assert_equal(promote_func(f32,i16), np.dtype(float32))
+ assert_equal(promote_func(f32,u32), np.dtype(float64))
+ assert_equal(promote_func(f32,c64), np.dtype(complex64))
+ assert_equal(promote_func(c128,f32), np.dtype(complex128))
+ assert_equal(promote_func(cld,f64), np.dtype(clongdouble))
# coercion between scalars and 1-D arrays
- assert_equal(np.add(array([i8]),i64).dtype, int8)
- assert_equal(np.add(u64,array([i32])).dtype, int32)
- assert_equal(np.add(i64,array([u32])).dtype, uint32)
- assert_equal(np.add(int32(-1),array([u64])).dtype, float64)
- assert_equal(np.add(f64,array([f32])).dtype, float32)
- assert_equal(np.add(fld,array([f32])).dtype, float32)
- assert_equal(np.add(array([f64]),fld).dtype, float64)
- assert_equal(np.add(fld,array([c64])).dtype, complex64)
- assert_equal(np.add(c64,array([f64])).dtype, complex128)
+ assert_equal(promote_func(array([i8]),i64), np.dtype(int8))
+ assert_equal(promote_func(u64,array([i32])), np.dtype(int32))
+ assert_equal(promote_func(i64,array([u32])), np.dtype(uint32))
+ assert_equal(promote_func(int32(-1),array([u64])), np.dtype(float64))
+ assert_equal(promote_func(f64,array([f32])), np.dtype(float32))
+ assert_equal(promote_func(fld,array([f32])), np.dtype(float32))
+ assert_equal(promote_func(array([f64]),fld), np.dtype(float64))
+ assert_equal(promote_func(fld,array([c64])), np.dtype(complex64))
+
+ def test_coercion(self):
+ def res_type(a, b):
+ return np.add(a, b).dtype
+
+ ctx = WarningManager()
+ ctx.__enter__()
+ warnings.simplefilter('ignore', np.ComplexWarning)
+
+ self.check_promotion_cases(res_type)
+
+ f64 = float64(0)
+ c64 = complex64(0)
+ ## Scalars do not coerce to complex if the value is real
+ #assert_equal(res_type(c64,array([f64])), np.dtype(float64))
+ # But they do if the value is complex
+ assert_equal(res_type(complex64(3j),array([f64])),
+ np.dtype(complex128))
+
+ # Scalars do coerce to complex even if the value is real
+ # This is so "a+0j" can be reliably used to make something complex.
+ assert_equal(res_type(c64,array([f64])), np.dtype(complex128))
+
+ ctx.__exit__()
+
+
+ def test_result_type(self):
+ self.check_promotion_cases(np.result_type)
+
+ f64 = float64(0)
+ c64 = complex64(0)
+ ## Scalars do not coerce to complex if the value is real
+ #assert_equal(np.result_type(c64,array([f64])), np.dtype(float64))
+ # But they do if the value is complex
+ assert_equal(np.result_type(complex64(3j),array([f64])),
+ np.dtype(complex128))
+
+ # Scalars do coerce to complex even if the value is real
+ # This is so "a+0j" can be reliably used to make something complex.
+ assert_equal(np.result_type(c64,array([f64])), np.dtype(complex128))
+
+
+ def can_cast(self):
+ assert_(np.can_cast(np.int32, np.int64))
+ assert_(np.can_cast(np.float64, np.complex))
+ assert_(not np.can_cast(np.complex, np.float))
+
+ assert_(np.can_cast('i8', 'f8'))
+ assert_(not np.can_cast('i8', 'f4'))
+ assert_(np.can_cast('i4', 'S4'))
+
+ assert_(np.can_cast('i8', 'i8', 'no'))
+ assert_(not np.can_cast('<i8', '>i8', 'no'))
+
+ assert_(np.can_cast('<i8', '>i8', 'equiv'))
+ assert_(not np.can_cast('<i4', '>i8', 'equiv'))
+
+ assert_(np.can_cast('<i4', '>i8', 'safe'))
+ assert_(not np.can_cast('<i8', '>i4', 'safe'))
+
+ assert_(np.can_cast('<i8', '>i4', 'same_kind'))
+ assert_(not np.can_cast('<i8', '>u4', 'same_kind'))
+
+ assert_(np.can_cast('<i8', '>u4', 'unsafe'))
+
+ assert_raises(TypeError, np.can_cast, 'i4', None)
+ assert_raises(TypeError, np.can_cast, None, 'i4')
class TestFromiter(TestCase):
def makegen(self):
@@ -407,6 +476,49 @@ class TestFromiter(TestCase):
self.assertTrue(alltrue(a == expected,axis=0))
self.assertTrue(alltrue(a20 == expected[:20],axis=0))
+class TestNonzero(TestCase):
+ def test_nonzero_trivial(self):
+ assert_equal(np.count_nonzero(array([])), 0)
+ assert_equal(np.nonzero(array([])), ([],))
+
+ assert_equal(np.count_nonzero(array(0)), 0)
+ assert_equal(np.nonzero(array(0)), ([],))
+ assert_equal(np.count_nonzero(array(1)), 1)
+ assert_equal(np.nonzero(array(1)), ([0],))
+
+ def test_nonzero_onedim(self):
+ x = array([1,0,2,-1,0,0,8])
+ assert_equal(np.count_nonzero(x), 4)
+ assert_equal(np.nonzero(x), ([0, 2, 3, 6],))
+
+ x = array([(1,2),(0,0),(1,1),(-1,3),(0,7)],
+ dtype=[('a','i4'),('b','i2')])
+ assert_equal(np.count_nonzero(x['a']), 3)
+ assert_equal(np.count_nonzero(x['b']), 4)
+ assert_equal(np.nonzero(x['a']), ([0,2,3],))
+ assert_equal(np.nonzero(x['b']), ([0,2,3,4],))
+
+ def test_nonzero_twodim(self):
+ x = array([[0,1,0],[2,0,3]])
+ assert_equal(np.count_nonzero(x), 3)
+ assert_equal(np.nonzero(x), ([0,1,1],[1,0,2]))
+
+ x = np.eye(3)
+ assert_equal(np.count_nonzero(x), 3)
+ assert_equal(np.nonzero(x), ([0,1,2],[0,1,2]))
+
+ x = array([[(0,1),(0,0),(1,11)],
+ [(1,1),(1,0),(0,0)],
+ [(0,0),(1,5),(0,1)]], dtype=[('a','f4'),('b','u1')])
+ assert_equal(np.count_nonzero(x['a']), 4)
+ assert_equal(np.count_nonzero(x['b']), 5)
+ assert_equal(np.nonzero(x['a']), ([0,1,1,2],[2,0,1,1]))
+ assert_equal(np.nonzero(x['b']), ([0,0,1,2,2],[0,2,0,1,2]))
+
+ assert_equal(np.count_nonzero(x['a'].T), 4)
+ assert_equal(np.count_nonzero(x['b'].T), 5)
+ assert_equal(np.nonzero(x['a'].T), ([0,1,1,2],[1,1,2,0]))
+ assert_equal(np.nonzero(x['b'].T), ([0,0,1,2,2],[0,1,2,0,2]))
class TestIndex(TestCase):
def test_boolean(self):
@@ -655,7 +767,7 @@ class TestClip(TestCase):
assert_array_strict_equal(ac, act)
def test_simple_int64_inout(self):
- """Test native in32 input with double array min/max and int32 out."""
+ """Test native int32 input with double array min/max and int32 out."""
a = self._generate_int32_data(self.nr, self.nc)
m = zeros(a.shape, float64)
M = float64(1)
@@ -915,7 +1027,7 @@ class TestClip(TestCase):
a2 = clip(a, m, M, out=a)
self.clip(a, m, M, ac)
assert_array_strict_equal(a2, ac)
- self.assert_(a2 is a)
+ self.assertTrue(a2 is a)
class test_allclose_inf(TestCase):
@@ -1006,25 +1118,91 @@ class TestStdVarComplex(TestCase):
class TestLikeFuncs(TestCase):
- '''Test zeros_like and empty_like'''
+ '''Test ones_like, zeros_like, and empty_like'''
def setUp(self):
- self.data = [(array([[1,2,3],[4,5,6]],dtype=int32), (2,3), int32),
- (array([[1,2,3],[4,5,6]],dtype=float32), (2,3), float32),
+ self.data = [
+ # Array scalars
+ (array(3.), None),
+ (array(3), 'f8'),
+ # 1D arrays
+ (arange(6, dtype='f4'), None),
+ (arange(6), 'c16'),
+ # 2D C-layout arrays
+ (arange(6).reshape(2,3), None),
+ (arange(6).reshape(3,2), 'i1'),
+ # 2D F-layout arrays
+ (arange(6).reshape((2,3), order='F'), None),
+ (arange(6).reshape((3,2), order='F'), 'i1'),
+ # 3D C-layout arrays
+ (arange(24).reshape(2,3,4), None),
+ (arange(24).reshape(4,3,2), 'f4'),
+ # 3D F-layout arrays
+ (arange(24).reshape((2,3,4), order='F'), None),
+ (arange(24).reshape((4,3,2), order='F'), 'f4'),
+ # 3D non-C/F-layout arrays
+ (arange(24).reshape(2,3,4).swapaxes(0,1), None),
+ (arange(24).reshape(4,3,2).swapaxes(0,1), '?'),
]
+ def check_like_function(self, like_function, value):
+ for d, dtype in self.data:
+ # default (K) order, dtype
+ dz = like_function(d, dtype=dtype)
+ assert_equal(dz.shape, d.shape)
+ assert_equal(array(dz.strides)*d.dtype.itemsize,
+ array(d.strides)*dz.dtype.itemsize)
+ if dtype is None:
+ assert_equal(dz.dtype, d.dtype)
+ else:
+ assert_equal(dz.dtype, np.dtype(dtype))
+ if not value is None:
+ assert_(all(dz == value))
+
+ # C order, default dtype
+ dz = like_function(d, order='C', dtype=dtype)
+ assert_equal(dz.shape, d.shape)
+ assert_(dz.flags.c_contiguous)
+ if dtype is None:
+ assert_equal(dz.dtype, d.dtype)
+ else:
+ assert_equal(dz.dtype, np.dtype(dtype))
+ if not value is None:
+ assert_(all(dz == value))
+
+ # F order, default dtype
+ dz = like_function(d, order='F', dtype=dtype)
+ assert_equal(dz.shape, d.shape)
+ assert_(dz.flags.f_contiguous)
+ if dtype is None:
+ assert_equal(dz.dtype, d.dtype)
+ else:
+ assert_equal(dz.dtype, np.dtype(dtype))
+ if not value is None:
+ assert_(all(dz == value))
+
+ # A order
+ dz = like_function(d, order='A', dtype=dtype)
+ assert_equal(dz.shape, d.shape)
+ if d.flags.f_contiguous:
+ assert_(dz.flags.f_contiguous)
+ else:
+ assert_(dz.flags.c_contiguous)
+ if dtype is None:
+ assert_equal(dz.dtype, d.dtype)
+ else:
+ assert_equal(dz.dtype, np.dtype(dtype))
+ if not value is None:
+ assert_(all(dz == value))
+
+ def test_ones_like(self):
+ self.check_like_function(np.ones_like, 1)
+
def test_zeros_like(self):
- for d, dshape, dtype in self.data:
- dz = zeros_like(d)
- assert dz.shape == dshape
- assert dz.dtype.type == dtype
- assert all(abs(dz) == 0)
+ self.check_like_function(np.zeros_like, 0)
def test_empty_like(self):
- for d, dshape, dtype in self.data:
- dz = zeros_like(d)
- assert dz.shape == dshape
- assert dz.dtype.type == dtype
+ self.check_like_function(np.empty_like, None)
class _TestCorrelate(TestCase):
def _setup(self, dt):
diff --git a/numpy/core/tests/test_numerictypes.py b/numpy/core/tests/test_numerictypes.py
index 44878b117..bb71ce008 100644
--- a/numpy/core/tests/test_numerictypes.py
+++ b/numpy/core/tests/test_numerictypes.py
@@ -104,30 +104,30 @@ class create_zeros(object):
def test_zeros0D(self):
"""Check creation of 0-dimensional objects"""
h = np.zeros((), dtype=self._descr)
- self.assert_(normalize_descr(self._descr) == h.dtype.descr)
- self.assert_(h.dtype.fields['x'][0].name[:4] == 'void')
- self.assert_(h.dtype.fields['x'][0].char == 'V')
- self.assert_(h.dtype.fields['x'][0].type == np.void)
+ self.assertTrue(normalize_descr(self._descr) == h.dtype.descr)
+ self.assertTrue(h.dtype.fields['x'][0].name[:4] == 'void')
+ self.assertTrue(h.dtype.fields['x'][0].char == 'V')
+ self.assertTrue(h.dtype.fields['x'][0].type == np.void)
# A small check that data is ok
assert_equal(h['z'], np.zeros((), dtype='u1'))
def test_zerosSD(self):
"""Check creation of single-dimensional objects"""
h = np.zeros((2,), dtype=self._descr)
- self.assert_(normalize_descr(self._descr) == h.dtype.descr)
- self.assert_(h.dtype['y'].name[:4] == 'void')
- self.assert_(h.dtype['y'].char == 'V')
- self.assert_(h.dtype['y'].type == np.void)
+ self.assertTrue(normalize_descr(self._descr) == h.dtype.descr)
+ self.assertTrue(h.dtype['y'].name[:4] == 'void')
+ self.assertTrue(h.dtype['y'].char == 'V')
+ self.assertTrue(h.dtype['y'].type == np.void)
# A small check that data is ok
assert_equal(h['z'], np.zeros((2,), dtype='u1'))
def test_zerosMD(self):
"""Check creation of multi-dimensional objects"""
h = np.zeros((2,3), dtype=self._descr)
- self.assert_(normalize_descr(self._descr) == h.dtype.descr)
- self.assert_(h.dtype['z'].name == 'uint8')
- self.assert_(h.dtype['z'].char == 'B')
- self.assert_(h.dtype['z'].type == np.uint8)
+ self.assertTrue(normalize_descr(self._descr) == h.dtype.descr)
+ self.assertTrue(h.dtype['z'].name == 'uint8')
+ self.assertTrue(h.dtype['z'].char == 'B')
+ self.assertTrue(h.dtype['z'].type == np.uint8)
# A small check that data is ok
assert_equal(h['z'], np.zeros((2,3), dtype='u1'))
@@ -147,29 +147,29 @@ class create_values(object):
def test_tuple(self):
"""Check creation from tuples"""
h = np.array(self._buffer, dtype=self._descr)
- self.assert_(normalize_descr(self._descr) == h.dtype.descr)
+ self.assertTrue(normalize_descr(self._descr) == h.dtype.descr)
if self.multiple_rows:
- self.assert_(h.shape == (2,))
+ self.assertTrue(h.shape == (2,))
else:
- self.assert_(h.shape == ())
+ self.assertTrue(h.shape == ())
def test_list_of_tuple(self):
"""Check creation from list of tuples"""
h = np.array([self._buffer], dtype=self._descr)
- self.assert_(normalize_descr(self._descr) == h.dtype.descr)
+ self.assertTrue(normalize_descr(self._descr) == h.dtype.descr)
if self.multiple_rows:
- self.assert_(h.shape == (1,2))
+ self.assertTrue(h.shape == (1,2))
else:
- self.assert_(h.shape == (1,))
+ self.assertTrue(h.shape == (1,))
def test_list_of_list_of_tuple(self):
"""Check creation from list of list of tuples"""
h = np.array([[self._buffer]], dtype=self._descr)
- self.assert_(normalize_descr(self._descr) == h.dtype.descr)
+ self.assertTrue(normalize_descr(self._descr) == h.dtype.descr)
if self.multiple_rows:
- self.assert_(h.shape == (1,1,2))
+ self.assertTrue(h.shape == (1,1,2))
else:
- self.assert_(h.shape == (1,1))
+ self.assertTrue(h.shape == (1,1))
class test_create_values_plain_single(create_values, TestCase):
@@ -207,12 +207,12 @@ class read_values_plain(object):
def test_access_fields(self):
h = np.array(self._buffer, dtype=self._descr)
if not self.multiple_rows:
- self.assert_(h.shape == ())
+ self.assertTrue(h.shape == ())
assert_equal(h['x'], np.array(self._buffer[0], dtype='i4'))
assert_equal(h['y'], np.array(self._buffer[1], dtype='f8'))
assert_equal(h['z'], np.array(self._buffer[2], dtype='u1'))
else:
- self.assert_(len(h) == 2)
+ self.assertTrue(len(h) == 2)
assert_equal(h['x'], np.array([self._buffer[0][0],
self._buffer[1][0]], dtype='i4'))
assert_equal(h['y'], np.array([self._buffer[0][1],
@@ -241,12 +241,12 @@ class read_values_nested(object):
"""Check reading the top fields of a nested array"""
h = np.array(self._buffer, dtype=self._descr)
if not self.multiple_rows:
- self.assert_(h.shape == ())
+ self.assertTrue(h.shape == ())
assert_equal(h['x'], np.array(self._buffer[0], dtype='i4'))
assert_equal(h['y'], np.array(self._buffer[4], dtype='f8'))
assert_equal(h['z'], np.array(self._buffer[5], dtype='u1'))
else:
- self.assert_(len(h) == 2)
+ self.assertTrue(len(h) == 2)
assert_equal(h['x'], np.array([self._buffer[0][0],
self._buffer[1][0]], dtype='i4'))
assert_equal(h['y'], np.array([self._buffer[0][4],
@@ -306,19 +306,19 @@ class read_values_nested(object):
def test_nested1_descriptor(self):
"""Check access nested descriptors of a nested array (1st level)"""
h = np.array(self._buffer, dtype=self._descr)
- self.assert_(h.dtype['Info']['value'].name == 'complex128')
- self.assert_(h.dtype['Info']['y2'].name == 'float64')
+ self.assertTrue(h.dtype['Info']['value'].name == 'complex128')
+ self.assertTrue(h.dtype['Info']['y2'].name == 'float64')
if sys.version_info[0] >= 3:
- self.assert_(h.dtype['info']['Name'].name == 'str256')
+ self.assertTrue(h.dtype['info']['Name'].name == 'str256')
else:
- self.assert_(h.dtype['info']['Name'].name == 'unicode256')
- self.assert_(h.dtype['info']['Value'].name == 'complex128')
+ self.assertTrue(h.dtype['info']['Name'].name == 'unicode256')
+ self.assertTrue(h.dtype['info']['Value'].name == 'complex128')
def test_nested2_descriptor(self):
"""Check access nested descriptors of a nested array (2nd level)"""
h = np.array(self._buffer, dtype=self._descr)
- self.assert_(h.dtype['Info']['Info2']['value'].name == 'void256')
- self.assert_(h.dtype['Info']['Info2']['z3'].name == 'void64')
+ self.assertTrue(h.dtype['Info']['Info2']['value'].name == 'void256')
+ self.assertTrue(h.dtype['Info']['Info2']['z3'].name == 'void64')
class test_read_values_nested_single(read_values_nested, TestCase):
@@ -366,7 +366,7 @@ class TestMultipleFields(TestCase):
self.assertRaises(ValueError, self._bad_call)
def test_return(self):
res = self.ary[['f0','f2']].tolist()
- assert(res == [(1,3), (5,7)])
+ assert(res == [(1,3), (5,7)])
if __name__ == "__main__":
run_module_suite()
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index 06055b2cd..5458fac33 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -115,11 +115,11 @@ class TestRegression(TestCase):
"""Ticket #72"""
a = np.array(['test', 'auto'])
assert_array_equal(a == 'auto', np.array([False,True]))
- self.assert_(a[1] == 'auto')
- self.assert_(a[0] != 'auto')
+ self.assertTrue(a[1] == 'auto')
+ self.assertTrue(a[0] != 'auto')
b = np.linspace(0, 10, 11)
- self.assert_(b != 'auto')
- self.assert_(b[0] != 'auto')
+ self.assertTrue(b != 'auto')
+ self.assertTrue(b[0] != 'auto')
def test_unicode_swapping(self,level=rlevel):
"""Ticket #79"""
@@ -160,8 +160,8 @@ class TestRegression(TestCase):
yb = ((b>2) & (b<6))
assert_array_almost_equal(xa,ya.nonzero())
assert_array_almost_equal(xb,yb.nonzero())
- assert(np.all(a[ya] > 0.5))
- assert(np.all(b[yb] > 0.5))
+ assert_(np.all(a[ya] > 0.5))
+ assert_(np.all(b[yb] > 0.5))
def test_mem_dot(self,level=rlevel):
"""Ticket #106"""
@@ -183,7 +183,7 @@ class TestRegression(TestCase):
# """Ticket #112"""
# if np.longfloat(0).itemsize > 8:
# a = np.exp(np.array([1000],dtype=np.longfloat))
-# assert(str(a)[1:9] == str(a[0])[:8])
+# assert_(str(a)[1:9] == str(a[0])[:8])
def test_argmax(self,level=rlevel):
"""Ticket #119"""
@@ -207,8 +207,8 @@ class TestRegression(TestCase):
"""Ticket #133"""
a = np.array([3])
b = np.array(3)
- assert(type(a.squeeze()) is np.ndarray)
- assert(type(b.squeeze()) is np.ndarray)
+ assert_(type(a.squeeze()) is np.ndarray)
+ assert_(type(b.squeeze()) is np.ndarray)
def test_add_identity(self,level=rlevel):
"""Ticket #143"""
@@ -347,7 +347,7 @@ class TestRegression(TestCase):
dt = np.dtype([('one', '<i4'),('two', '<i4')])
x = np.array((1,2), dtype=dt)
x = x.byteswap()
- assert(x['one'] > 1 and x['two'] > 2)
+ assert_(x['one'] > 1 and x['two'] > 2)
def test_method_args(self, level=rlevel):
# Make sure methods and functions have same default axis
@@ -488,7 +488,7 @@ class TestRegression(TestCase):
np.rec.array([(1,2),(3,4)]),
np.rec.fromarrays([(1,2),(3,4)],"i4,i4"),
np.rec.fromarrays([(1,2),(3,4)])]:
- assert(a.dtype in [dt0,dt1])
+ assert_(a.dtype in [dt0,dt1])
def test_random_shuffle(self, level=rlevel):
"""Ticket #374"""
@@ -608,6 +608,9 @@ class TestRegression(TestCase):
assert_equal(np.dot(x,z),np.dot(x,y2))
def test_object_casting(self, level=rlevel):
+ # This used to trigger the object-type version of
+ # the bitwise_or operation, because float64 -> object
+ # casting succeeds
def rs():
x = np.ones([484,286])
y = np.zeros([484,286])
@@ -720,15 +723,15 @@ class TestRegression(TestCase):
arr = np.zeros(5, dtype=np.object_)
arr[:] = a
- assert cnt(a) == cnt0_a + 5
+ assert_equal(cnt(a), cnt0_a + 5)
arr[:] = b
- assert cnt(a) == cnt0_a
- assert cnt(b) == cnt0_b + 5
+ assert_equal(cnt(a), cnt0_a)
+ assert_equal(cnt(b), cnt0_b + 5)
arr[:2] = c
- assert cnt(b) == cnt0_b + 3
- assert cnt(c) == cnt0_c + 2
+ assert_equal(cnt(b), cnt0_b + 3)
+ assert_equal(cnt(c), cnt0_c + 2)
del arr
@@ -912,7 +915,6 @@ class TestRegression(TestCase):
def test_attributes(self, level=rlevel):
"""Ticket #791
"""
- import numpy as np
class TestArray(np.ndarray):
def __new__(cls, data, info):
result = np.array(data)
@@ -922,63 +924,63 @@ class TestRegression(TestCase):
def __array_finalize__(self, obj):
self.info = getattr(obj, 'info', '')
dat = TestArray([[1,2,3,4],[5,6,7,8]],'jubba')
- assert dat.info == 'jubba'
+ assert_(dat.info == 'jubba')
dat.resize((4,2))
- assert dat.info == 'jubba'
+ assert_(dat.info == 'jubba')
dat.sort()
- assert dat.info == 'jubba'
+ assert_(dat.info == 'jubba')
dat.fill(2)
- assert dat.info == 'jubba'
+ assert_(dat.info == 'jubba')
dat.put([2,3,4],[6,3,4])
- assert dat.info == 'jubba'
+ assert_(dat.info == 'jubba')
dat.setfield(4, np.int32,0)
- assert dat.info == 'jubba'
+ assert_(dat.info == 'jubba')
dat.setflags()
- assert dat.info == 'jubba'
- assert dat.all(1).info == 'jubba'
- assert dat.any(1).info == 'jubba'
- assert dat.argmax(1).info == 'jubba'
- assert dat.argmin(1).info == 'jubba'
- assert dat.argsort(1).info == 'jubba'
- assert dat.astype(TestArray).info == 'jubba'
- assert dat.byteswap().info == 'jubba'
- assert dat.clip(2,7).info == 'jubba'
- assert dat.compress([0,1,1]).info == 'jubba'
- assert dat.conj().info == 'jubba'
- assert dat.conjugate().info == 'jubba'
- assert dat.copy().info == 'jubba'
+ assert_(dat.info == 'jubba')
+ assert_(dat.all(1).info == 'jubba')
+ assert_(dat.any(1).info == 'jubba')
+ assert_(dat.argmax(1).info == 'jubba')
+ assert_(dat.argmin(1).info == 'jubba')
+ assert_(dat.argsort(1).info == 'jubba')
+ assert_(dat.astype(TestArray).info == 'jubba')
+ assert_(dat.byteswap().info == 'jubba')
+ assert_(dat.clip(2,7).info == 'jubba')
+ assert_(dat.compress([0,1,1]).info == 'jubba')
+ assert_(dat.conj().info == 'jubba')
+ assert_(dat.conjugate().info == 'jubba')
+ assert_(dat.copy().info == 'jubba')
dat2 = TestArray([2, 3, 1, 0],'jubba')
choices = [[0, 1, 2, 3], [10, 11, 12, 13],
[20, 21, 22, 23], [30, 31, 32, 33]]
- assert dat2.choose(choices).info == 'jubba'
- assert dat.cumprod(1).info == 'jubba'
- assert dat.cumsum(1).info == 'jubba'
- assert dat.diagonal().info == 'jubba'
- assert dat.flatten().info == 'jubba'
- assert dat.getfield(np.int32,0).info == 'jubba'
- assert dat.imag.info == 'jubba'
- assert dat.max(1).info == 'jubba'
- assert dat.mean(1).info == 'jubba'
- assert dat.min(1).info == 'jubba'
- assert dat.newbyteorder().info == 'jubba'
- assert dat.nonzero()[0].info == 'jubba'
- assert dat.nonzero()[1].info == 'jubba'
- assert dat.prod(1).info == 'jubba'
- assert dat.ptp(1).info == 'jubba'
- assert dat.ravel().info == 'jubba'
- assert dat.real.info == 'jubba'
- assert dat.repeat(2).info == 'jubba'
- assert dat.reshape((2,4)).info == 'jubba'
- assert dat.round().info == 'jubba'
- assert dat.squeeze().info == 'jubba'
- assert dat.std(1).info == 'jubba'
- assert dat.sum(1).info == 'jubba'
- assert dat.swapaxes(0,1).info == 'jubba'
- assert dat.take([2,3,5]).info == 'jubba'
- assert dat.transpose().info == 'jubba'
- assert dat.T.info == 'jubba'
- assert dat.var(1).info == 'jubba'
- assert dat.view(TestArray).info == 'jubba'
+ assert_(dat2.choose(choices).info == 'jubba')
+ assert_(dat.cumprod(1).info == 'jubba')
+ assert_(dat.cumsum(1).info == 'jubba')
+ assert_(dat.diagonal().info == 'jubba')
+ assert_(dat.flatten().info == 'jubba')
+ assert_(dat.getfield(np.int32,0).info == 'jubba')
+ assert_(dat.imag.info == 'jubba')
+ assert_(dat.max(1).info == 'jubba')
+ assert_(dat.mean(1).info == 'jubba')
+ assert_(dat.min(1).info == 'jubba')
+ assert_(dat.newbyteorder().info == 'jubba')
+ assert_(dat.nonzero()[0].info == 'jubba')
+ assert_(dat.nonzero()[1].info == 'jubba')
+ assert_(dat.prod(1).info == 'jubba')
+ assert_(dat.ptp(1).info == 'jubba')
+ assert_(dat.ravel().info == 'jubba')
+ assert_(dat.real.info == 'jubba')
+ assert_(dat.repeat(2).info == 'jubba')
+ assert_(dat.reshape((2,4)).info == 'jubba')
+ assert_(dat.round().info == 'jubba')
+ assert_(dat.squeeze().info == 'jubba')
+ assert_(dat.std(1).info == 'jubba')
+ assert_(dat.sum(1).info == 'jubba')
+ assert_(dat.swapaxes(0,1).info == 'jubba')
+ assert_(dat.take([2,3,5]).info == 'jubba')
+ assert_(dat.transpose().info == 'jubba')
+ assert_(dat.T.info == 'jubba')
+ assert_(dat.var(1).info == 'jubba')
+ assert_(dat.view(TestArray).info == 'jubba')
def test_recarray_tolist(self, level=rlevel):
"""Ticket #793, changeset r5215
@@ -988,8 +990,8 @@ class TestRegression(TestCase):
buf = np.zeros(40, dtype=np.int8)
a = np.recarray(2, formats="i4,f8,f8", names="id,x,y", buf=buf)
b = a.tolist()
- assert( a[0].tolist() == b[0])
- assert( a[1].tolist() == b[1])
+ assert_( a[0].tolist() == b[0])
+ assert_( a[1].tolist() == b[1])
def test_char_array_creation(self, level=rlevel):
a = np.array('123', dtype='c')
@@ -1129,18 +1131,23 @@ class TestRegression(TestCase):
def test_array_from_sequence_scalar_array(self):
"""Ticket #1078: segfaults when creating an array with a sequence of 0d
arrays."""
- a = np.ones(2)
- b = np.array(3)
- assert_raises(ValueError, lambda: np.array((a, b)))
-
- t = ((1,), np.array(1))
- assert_raises(ValueError, lambda: np.array(t))
+ a = np.array((np.ones(2), np.array(2)))
+ assert_equal(a.shape, (2,))
+ assert_equal(a.dtype, np.dtype(object))
+ assert_equal(a[0], np.ones(2))
+ assert_equal(a[1], np.array(2))
+
+ a = np.array(((1,), np.array(1)))
+ assert_equal(a.shape, (2,))
+ assert_equal(a.dtype, np.dtype(object))
+ assert_equal(a[0], (1,))
+ assert_equal(a[1], np.array(1))
- @dec.knownfailureif(True, "This is a corner case, see ticket #1081.")
def test_array_from_sequence_scalar_array2(self):
"""Ticket #1081: weird array with strange input..."""
t = np.array([np.array([]), np.array(0, object)])
- assert_raises(ValueError, lambda: np.array(t))
+ assert_equal(t.shape, (2,))
+ assert_equal(t.dtype, np.dtype(object))
def test_array_too_big(self):
"""Ticket #1080."""
@@ -1441,5 +1448,119 @@ class TestRegression(TestCase):
a = a.byteswap().newbyteorder()
assert_equal(a.nonzero()[0], [1]) # [0] if nonzero() ignores swap
+ def test_find_common_type_boolean(self):
+ # Ticket #1695
+ assert_(np.find_common_type([],['?','?']) == '?')
+
+ def test_empty_mul(self):
+ a = np.array([1.])
+ a[1:1] *= 2
+ assert_equal(a, [1.])
+
+ def test_array_side_effect(self):
+ assert_equal(np.dtype('S10').itemsize, 10)
+
+ A = np.array([['abc', 2], ['long ', '0123456789']], dtype=np.string_)
+
+ # This was throwing an exception because in ctors.c,
+ # discover_itemsize was calling PyObject_Length without checking
+ # the return code. This failed to get the length of the number 2,
+ # and the exception hung around until something checked
+ # PyErr_Occurred() and returned an error.
+ assert_equal(np.dtype('S10').itemsize, 10)
+
+ def test_any_float(self):
+ # all and any for floats
+ a = np.array([0.1, 0.9])
+ assert_(np.any(a))
+ assert_(np.all(a))
+
+ def test_large_float_sum(self):
+ a = np.arange(10000, dtype='f')
+ assert_equal(a.sum(dtype='d'), a.astype('d').sum())
+
+ def test_ufunc_casting_out(self):
+ a = np.array(1.0, dtype=np.float32)
+ b = np.array(1.0, dtype=np.float64)
+ c = np.array(1.0, dtype=np.float32)
+ np.add(a, b, out=c)
+ assert_equal(c, 2.0)
+
+ def test_array_scalar_contiguous(self):
+ # Array scalars are both C and Fortran contiguous
+ assert_(np.array(1.0).flags.c_contiguous)
+ assert_(np.array(1.0).flags.f_contiguous)
+ assert_(np.array(np.float32(1.0)).flags.c_contiguous)
+ assert_(np.array(np.float32(1.0)).flags.f_contiguous)
+
+ def test_object_array_self_reference(self):
+ # Object arrays with references to themselves can cause problems
+ a = np.array(0, dtype=object)
+ a[()] = a
+ assert_raises(TypeError, int, a)
+ assert_raises(TypeError, long, a)
+ assert_raises(TypeError, float, a)
+ assert_raises(TypeError, oct, a)
+ assert_raises(TypeError, hex, a)
+
+ # This was causing a to become like the above
+ a = np.array(0, dtype=object)
+ a[...] += 1
+ assert_equal(a, 1)
+
+ def test_zerosize_accumulate(self):
+ "Ticket #1733"
+ x = np.array([[42, 0]], dtype=np.uint32)
+ assert_equal(np.add.accumulate(x[:-1,0]), [])
+
+ def test_objectarray_setfield(self):
+ # Setfield directly manipulates the raw array data,
+ # so is invalid for object arrays.
+ x = np.array([1,2,3], dtype=object)
+ assert_raises(RuntimeError, x.setfield, 4, np.int32, 0)
+
+ def test_setting_rank0_string(self):
+ "Ticket #1736"
+ s1 = asbytes("hello1")
+ s2 = asbytes("hello2")
+ a = np.zeros((), dtype="S10")
+ a[()] = s1
+ assert_equal(a, np.array(s1))
+ a[()] = np.array(s2)
+ assert_equal(a, np.array(s2))
+
+ a = np.zeros((), dtype='f4')
+ a[()] = 3
+ assert_equal(a, np.array(3))
+ a[()] = np.array(4)
+ assert_equal(a, np.array(4))
+
+ def test_string_astype(self):
+ "Ticket #1748"
+ s1 = asbytes('black')
+ s2 = asbytes('white')
+ s3 = asbytes('other')
+ a = np.array([[s1],[s2],[s3]])
+ assert_equal(a.dtype, np.dtype('S5'))
+ b = a.astype('str')
+ assert_equal(b.dtype, np.dtype('S5'))
+
+ def test_string_astype(self):
+ """Ticket #1756 """
+ s = asbytes('0123456789abcdef')
+ a = np.array([s]*5)
+ for i in range(1,17):
+ a1 = np.array(a, "|S%d"%i)
+ a2 = np.array([s[:i]]*5)
+ assert_equal(a1, a2)
+
+ def test_fields_strides(self):
+ "Ticket #1760"
+ r=np.fromstring('abcdefghijklmnop'*4*3, dtype='i4,(2,3)u2')
+ assert_equal(r[0:3:2]['f1'], r['f1'][0:3:2])
+ assert_equal(r[0:3:2]['f1'][0], r[0:3:2][0]['f1'])
+ assert_equal(r[0:3:2]['f1'][0][()], r[0:3:2][0]['f1'][()])
+ assert_equal(r[0:3:2]['f1'][0].strides, r[0:3:2][0]['f1'].strides)
+
if __name__ == "__main__":
run_module_suite()
diff --git a/numpy/core/tests/test_scalarmath.py b/numpy/core/tests/test_scalarmath.py
index 520b6eb17..a2b3a232b 100644
--- a/numpy/core/tests/test_scalarmath.py
+++ b/numpy/core/tests/test_scalarmath.py
@@ -18,16 +18,22 @@ class TestTypes(TestCase):
def test_type_add(self, level=1):
# list of types
for k, atype in enumerate(types):
- vala = atype(3)
- val1 = np.array([3],dtype=atype)
+ a_scalar = atype(3)
+ a_array = np.array([3],dtype=atype)
for l, btype in enumerate(types):
- valb = btype(1)
- val2 = np.array([1],dtype=btype)
- val = vala+valb
- valo = val1 + val2
- assert val.dtype.num == valo.dtype.num and \
- val.dtype.char == valo.dtype.char, \
- "error with (%d,%d)" % (k,l)
+ b_scalar = btype(1)
+ b_array = np.array([1],dtype=btype)
+ c_scalar = a_scalar + b_scalar
+ c_array = a_array + b_array
+ # It was comparing the type numbers, but the new ufunc
+ # function-finding mechanism finds the lowest function
+ # to which both inputs can be cast - which produces 'l'
+ # when you do 'q' + 'b'. The old function finding mechanism
+ # skipped ahead based on the first argument, but that
+ # does not produce properly symmetric results...
+ assert_equal(c_scalar.dtype, c_array.dtype,
+ "error with types (%d/'%c' + %d/'%c')" %
+ (k,np.dtype(atype).char,l,np.dtype(btype).char))
def test_type_create(self, level=1):
for k, atype in enumerate(types):
diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py
index 84e64bf45..a7a41dfe2 100644
--- a/numpy/core/tests/test_ufunc.py
+++ b/numpy/core/tests/test_ufunc.py
@@ -275,6 +275,32 @@ class TestUfunc(TestCase):
def test_get_signature(self):
assert_equal(umt.inner1d.signature, "(i),(i)->()")
+ def test_forced_sig(self):
+ a = 0.5*np.arange(3,dtype='f8')
+ assert_equal(np.add(a,0.5), [0.5, 1, 1.5])
+ assert_equal(np.add(a,0.5,sig='i',casting='unsafe'), [0, 0, 1])
+ assert_equal(np.add(a,0.5,sig='ii->i',casting='unsafe'), [0, 0, 1])
+ assert_equal(np.add(a,0.5,sig=('i4',),casting='unsafe'), [0, 0, 1])
+ assert_equal(np.add(a,0.5,sig=('i4','i4','i4'),
+ casting='unsafe'), [0, 0, 1])
+
+ b = np.zeros((3,),dtype='f8')
+ np.add(a,0.5,out=b)
+ assert_equal(b, [0.5, 1, 1.5])
+ b[:] = 0
+ np.add(a,0.5,sig='i',out=b, casting='unsafe')
+ assert_equal(b, [0, 0, 1])
+ b[:] = 0
+ np.add(a,0.5,sig='ii->i',out=b, casting='unsafe')
+ assert_equal(b, [0, 0, 1])
+ b[:] = 0
+ np.add(a,0.5,sig=('i4',),out=b, casting='unsafe')
+ assert_equal(b, [0, 0, 1])
+ b[:] = 0
+ np.add(a,0.5,sig=('i4','i4','i4'),out=b, casting='unsafe')
+ assert_equal(b, [0, 0, 1])
+
+
def test_inner1d(self):
a = np.arange(6).reshape((2,3))
assert_array_equal(umt.inner1d(a,a), np.sum(a*a,axis=-1))
@@ -344,14 +370,25 @@ class TestUfunc(TestCase):
c = np.zeros((2,3),dtype='int')
umt.inner1d(a,b,c)
assert_array_equal(c, np.sum(a*b,axis=-1), err_msg=msg)
+ c[:] = -1
+ umt.inner1d(a,b,out=c)
+ assert_array_equal(c, np.sum(a*b,axis=-1), err_msg=msg)
+
msg = "output argument with type cast"
c = np.zeros((2,3),dtype='int16')
umt.inner1d(a,b,c)
assert_array_equal(c, np.sum(a*b,axis=-1), err_msg=msg)
+ c[:] = -1
+ umt.inner1d(a,b,out=c)
+ assert_array_equal(c, np.sum(a*b,axis=-1), err_msg=msg)
+
msg = "output argument with incontiguous layout"
c = np.zeros((2,3,4),dtype='int16')
umt.inner1d(a,b,c[...,0])
assert_array_equal(c[...,0], np.sum(a*b,axis=-1), err_msg=msg)
+ c[:] = -1
+ umt.inner1d(a,b,out=c[...,0])
+ assert_array_equal(c[...,0], np.sum(a*b,axis=-1), err_msg=msg)
def test_innerwt(self):
a = np.arange(6).reshape((2,3))
diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py
index 40b78fdb5..b5f9d5745 100644
--- a/numpy/core/tests/test_umath.py
+++ b/numpy/core/tests/test_umath.py
@@ -413,6 +413,27 @@ class TestLdexp(TestCase):
class TestMaximum(TestCase):
+ def test_reduce(self):
+ dflt = np.typecodes['AllFloat']
+ dint = np.typecodes['AllInteger']
+ seq1 = np.arange(11)
+ seq2 = seq1[::-1]
+ func = np.maximum.reduce
+ for dt in dint:
+ tmp1 = seq1.astype(dt)
+ tmp2 = seq2.astype(dt)
+ assert_equal(func(tmp1), 10)
+ assert_equal(func(tmp2), 10)
+ for dt in dflt:
+ tmp1 = seq1.astype(dt)
+ tmp2 = seq2.astype(dt)
+ assert_equal(func(tmp1), 10)
+ assert_equal(func(tmp2), 10)
+ tmp1[::2] = np.nan
+ tmp2[::2] = np.nan
+ assert_equal(func(tmp1), np.nan)
+ assert_equal(func(tmp2), np.nan)
+
def test_reduce_complex(self):
assert_equal(np.maximum.reduce([1,2j]),1)
assert_equal(np.maximum.reduce([1+3j,2j]),1+3j)
@@ -434,6 +455,27 @@ class TestMaximum(TestCase):
class TestMinimum(TestCase):
+ def test_reduce(self):
+ dflt = np.typecodes['AllFloat']
+ dint = np.typecodes['AllInteger']
+ seq1 = np.arange(11)
+ seq2 = seq1[::-1]
+ func = np.minimum.reduce
+ for dt in dint:
+ tmp1 = seq1.astype(dt)
+ tmp2 = seq2.astype(dt)
+ assert_equal(func(tmp1), 0)
+ assert_equal(func(tmp2), 0)
+ for dt in dflt:
+ tmp1 = seq1.astype(dt)
+ tmp2 = seq2.astype(dt)
+ assert_equal(func(tmp1), 0)
+ assert_equal(func(tmp2), 0)
+ tmp1[::2] = np.nan
+ tmp2[::2] = np.nan
+ assert_equal(func(tmp1), np.nan)
+ assert_equal(func(tmp2), np.nan)
+
def test_reduce_complex(self):
assert_equal(np.minimum.reduce([1,2j]),2j)
assert_equal(np.minimum.reduce([1+3j,2j]),2j)
@@ -455,6 +497,27 @@ class TestMinimum(TestCase):
class TestFmax(TestCase):
+ def test_reduce(self):
+ dflt = np.typecodes['AllFloat']
+ dint = np.typecodes['AllInteger']
+ seq1 = np.arange(11)
+ seq2 = seq1[::-1]
+ func = np.fmax.reduce
+ for dt in dint:
+ tmp1 = seq1.astype(dt)
+ tmp2 = seq2.astype(dt)
+ assert_equal(func(tmp1), 10)
+ assert_equal(func(tmp2), 10)
+ for dt in dflt:
+ tmp1 = seq1.astype(dt)
+ tmp2 = seq2.astype(dt)
+ assert_equal(func(tmp1), 10)
+ assert_equal(func(tmp2), 10)
+ tmp1[::2] = np.nan
+ tmp2[::2] = np.nan
+ assert_equal(func(tmp1), 9)
+ assert_equal(func(tmp2), 9)
+
def test_reduce_complex(self):
assert_equal(np.fmax.reduce([1,2j]),1)
assert_equal(np.fmax.reduce([1+3j,2j]),1+3j)
@@ -476,6 +539,27 @@ class TestFmax(TestCase):
class TestFmin(TestCase):
+ def test_reduce(self):
+ dflt = np.typecodes['AllFloat']
+ dint = np.typecodes['AllInteger']
+ seq1 = np.arange(11)
+ seq2 = seq1[::-1]
+ func = np.fmin.reduce
+ for dt in dint:
+ tmp1 = seq1.astype(dt)
+ tmp2 = seq2.astype(dt)
+ assert_equal(func(tmp1), 0)
+ assert_equal(func(tmp2), 0)
+ for dt in dflt:
+ tmp1 = seq1.astype(dt)
+ tmp2 = seq2.astype(dt)
+ assert_equal(func(tmp1), 0)
+ assert_equal(func(tmp2), 0)
+ tmp1[::2] = np.nan
+ tmp2[::2] = np.nan
+ assert_equal(func(tmp1), 1)
+ assert_equal(func(tmp2), 1)
+
def test_reduce_complex(self):
assert_equal(np.fmin.reduce([1,2j]),2j)
assert_equal(np.fmin.reduce([1+3j,2j]),2j)
diff --git a/numpy/core/tests/test_umath_complex.py b/numpy/core/tests/test_umath_complex.py
index 7f964e57e..619e6f0a3 100644
--- a/numpy/core/tests/test_umath_complex.py
+++ b/numpy/core/tests/test_umath_complex.py
@@ -12,8 +12,12 @@ import numpy as np
# At least on Windows the results of many complex functions are not conforming
# to the C99 standard. See ticket 1574.
# Ditto for Solaris (ticket 1642).
-functions_seem_flaky = ((np.exp(complex(np.inf, 0)).imag != 0)
- or (np.log(complex(np.NZERO, 0)).imag != np.pi))
+olderr = np.seterr(divide='ignore')
+try:
+ functions_seem_flaky = ((np.exp(complex(np.inf, 0)).imag != 0)
+ or (np.log(complex(np.NZERO, 0)).imag != np.pi))
+finally:
+ np.seterr(**olderr)
# TODO: replace with a check on whether platform-provided C99 funcs are used
have_platform_functions = (sys.platform.startswith('win')
or sys.platform.startswith('sunos')
diff --git a/numpy/core/tests/test_unicode.py b/numpy/core/tests/test_unicode.py
index 5ae4ad9dd..d47ac548b 100644
--- a/numpy/core/tests/test_unicode.py
+++ b/numpy/core/tests/test_unicode.py
@@ -42,18 +42,18 @@ class create_zeros(object):
def content_check(self, ua, ua_scalar, nbytes):
# Check the length of the unicode base type
- self.assert_(int(ua.dtype.str[2:]) == self.ulen)
+ self.assertTrue(int(ua.dtype.str[2:]) == self.ulen)
# Check the length of the data buffer
- self.assert_(buffer_length(ua) == nbytes)
+ self.assertTrue(buffer_length(ua) == nbytes)
# Small check that data in array element is ok
- self.assert_(ua_scalar == u'')
+ self.assertTrue(ua_scalar == u'')
# Encode to ascii and double check
- self.assert_(ua_scalar.encode('ascii') == asbytes(''))
+ self.assertTrue(ua_scalar.encode('ascii') == asbytes(''))
# Check buffer lengths for scalars
if ucs4:
- self.assert_(buffer_length(ua_scalar) == 0)
+ self.assertTrue(buffer_length(ua_scalar) == 0)
else:
- self.assert_(buffer_length(ua_scalar) == 0)
+ self.assertTrue(buffer_length(ua_scalar) == 0)
def test_zeros0D(self):
"""Check creation of 0-dimensional objects"""
@@ -94,26 +94,26 @@ class create_values(object):
def content_check(self, ua, ua_scalar, nbytes):
# Check the length of the unicode base type
- self.assert_(int(ua.dtype.str[2:]) == self.ulen)
+ self.assertTrue(int(ua.dtype.str[2:]) == self.ulen)
# Check the length of the data buffer
- self.assert_(buffer_length(ua) == nbytes)
+ self.assertTrue(buffer_length(ua) == nbytes)
# Small check that data in array element is ok
- self.assert_(ua_scalar == self.ucs_value*self.ulen)
+ self.assertTrue(ua_scalar == self.ucs_value*self.ulen)
# Encode to UTF-8 and double check
- self.assert_(ua_scalar.encode('utf-8') == \
+ self.assertTrue(ua_scalar.encode('utf-8') == \
(self.ucs_value*self.ulen).encode('utf-8'))
# Check buffer lengths for scalars
if ucs4:
- self.assert_(buffer_length(ua_scalar) == 4*self.ulen)
+ self.assertTrue(buffer_length(ua_scalar) == 4*self.ulen)
else:
if self.ucs_value == ucs4_value:
# In UCS2, the \U0010FFFF will be represented using a
# surrogate *pair*
- self.assert_(buffer_length(ua_scalar) == 2*2*self.ulen)
+ self.assertTrue(buffer_length(ua_scalar) == 2*2*self.ulen)
else:
# In UCS2, the \uFFFF will be represented using a
# regular 2-byte word
- self.assert_(buffer_length(ua_scalar) == 2*self.ulen)
+ self.assertTrue(buffer_length(ua_scalar) == 2*self.ulen)
def test_values0D(self):
"""Check creation of 0-dimensional objects with values"""
@@ -179,26 +179,26 @@ class assign_values(object):
def content_check(self, ua, ua_scalar, nbytes):
# Check the length of the unicode base type
- self.assert_(int(ua.dtype.str[2:]) == self.ulen)
+ self.assertTrue(int(ua.dtype.str[2:]) == self.ulen)
# Check the length of the data buffer
- self.assert_(buffer_length(ua) == nbytes)
+ self.assertTrue(buffer_length(ua) == nbytes)
# Small check that data in array element is ok
- self.assert_(ua_scalar == self.ucs_value*self.ulen)
+ self.assertTrue(ua_scalar == self.ucs_value*self.ulen)
# Encode to UTF-8 and double check
- self.assert_(ua_scalar.encode('utf-8') == \
+ self.assertTrue(ua_scalar.encode('utf-8') == \
(self.ucs_value*self.ulen).encode('utf-8'))
# Check buffer lengths for scalars
if ucs4:
- self.assert_(buffer_length(ua_scalar) == 4*self.ulen)
+ self.assertTrue(buffer_length(ua_scalar) == 4*self.ulen)
else:
if self.ucs_value == ucs4_value:
# In UCS2, the \U0010FFFF will be represented using a
# surrogate *pair*
- self.assert_(buffer_length(ua_scalar) == 2*2*self.ulen)
+ self.assertTrue(buffer_length(ua_scalar) == 2*2*self.ulen)
else:
# In UCS2, the \uFFFF will be represented using a
# regular 2-byte word
- self.assert_(buffer_length(ua_scalar) == 2*self.ulen)
+ self.assertTrue(buffer_length(ua_scalar) == 2*self.ulen)
def test_values0D(self):
"""Check assignment of 0-dimensional objects with values"""
@@ -274,7 +274,7 @@ class byteorder_values:
# This changes the interpretation of the data region (but not the
# actual data), therefore the returned scalars are not
# the same (they are byte-swapped versions of each other).
- self.assert_(ua[()] != ua2[()])
+ self.assertTrue(ua[()] != ua2[()])
ua3 = ua2.newbyteorder()
# Arrays must be equal after the round-trip
assert_equal(ua, ua3)
@@ -283,8 +283,8 @@ class byteorder_values:
"""Check byteorder of single-dimensional objects"""
ua = array([self.ucs_value*self.ulen]*2, dtype='U%s' % self.ulen)
ua2 = ua.newbyteorder()
- self.assert_(ua[0] != ua2[0])
- self.assert_(ua[-1] != ua2[-1])
+ self.assertTrue(ua[0] != ua2[0])
+ self.assertTrue(ua[-1] != ua2[-1])
ua3 = ua2.newbyteorder()
# Arrays must be equal after the round-trip
assert_equal(ua, ua3)
@@ -294,8 +294,8 @@ class byteorder_values:
ua = array([[[self.ucs_value*self.ulen]*2]*3]*4,
dtype='U%s' % self.ulen)
ua2 = ua.newbyteorder()
- self.assert_(ua[0,0,0] != ua2[0,0,0])
- self.assert_(ua[-1,-1,-1] != ua2[-1,-1,-1])
+ self.assertTrue(ua[0,0,0] != ua2[0,0,0])
+ self.assertTrue(ua[-1,-1,-1] != ua2[-1,-1,-1])
ua3 = ua2.newbyteorder()
# Arrays must be equal after the round-trip
assert_equal(ua, ua3)
diff --git a/numpy/distutils/ccompiler.py b/numpy/distutils/ccompiler.py
index 011122b60..14213dc4b 100644
--- a/numpy/distutils/ccompiler.py
+++ b/numpy/distutils/ccompiler.py
@@ -17,13 +17,6 @@ from numpy.distutils.misc_util import cyg2win32, is_sequence, mingw32, \
quote_args, msvc_on_amd64
from numpy.distutils.compat import get_exception
-# hack to set compiler optimizing options. Needs to integrated with something.
-import distutils.sysconfig
-_old_init_posix = distutils.sysconfig._init_posix
-def _new_init_posix():
- _old_init_posix()
- distutils.sysconfig._config_vars['OPT'] = '-Wall -g -O0'
-#distutils.sysconfig._init_posix = _new_init_posix
def replace_method(klass, method_name, func):
if sys.version_info[0] < 3:
@@ -346,12 +339,7 @@ def CCompiler_customize(self, dist, need_cxx=0):
if need_cxx:
# In general, distutils uses -Wstrict-prototypes, but this option is
# not valid for C++ code, only for C. Remove it if it's there to
- # avoid a spurious warning on every compilation. All the default
- # options used by distutils can be extracted with:
-
- # from distutils import sysconfig
- # sysconfig.get_config_vars('CC', 'CXX', 'OPT', 'BASECFLAGS',
- # 'CCSHARED', 'LDSHARED', 'SO')
+ # avoid a spurious warning on every compilation.
try:
self.compiler_so.remove('-Wstrict-prototypes')
except (AttributeError, ValueError):
@@ -506,10 +494,13 @@ compiler_class['intel'] = ('intelccompiler','IntelCCompiler',
"Intel C Compiler for 32-bit applications")
compiler_class['intele'] = ('intelccompiler','IntelItaniumCCompiler',
"Intel C Itanium Compiler for Itanium-based applications")
+compiler_class['intelem'] = ('intelccompiler','IntelEM64TCCompiler',
+ "Intel C Compiler for 64-bit applications")
compiler_class['pathcc'] = ('pathccompiler','PathScaleCCompiler',
"PathScale Compiler for SiCortex-based applications")
ccompiler._default_compilers += (('linux.*','intel'),
('linux.*','intele'),
+ ('linux.*','intelem'),
('linux.*','pathcc'))
if sys.platform == 'win32':
diff --git a/numpy/distutils/fcompiler/__init__.py b/numpy/distutils/fcompiler/__init__.py
index 397b36ce9..d2400459f 100644
--- a/numpy/distutils/fcompiler/__init__.py
+++ b/numpy/distutils/fcompiler/__init__.py
@@ -27,7 +27,7 @@ except NameError:
from numpy.compat import open_latin1
-from distutils.sysconfig import get_config_var, get_python_lib
+from distutils.sysconfig import get_config_var, get_config_vars, get_python_lib
from distutils.fancy_getopt import FancyGetopt
from distutils.errors import DistutilsModuleError, \
DistutilsExecError, CompileError, LinkError, DistutilsPlatformError
@@ -196,6 +196,9 @@ class FCompiler(CCompiler):
src_extensions = ['.for','.ftn','.f77','.f','.f90','.f95','.F','.F90']
obj_extension = ".o"
shared_lib_extension = get_config_var('SO') # or .dll
+ # fix long extension for Python >=3.2, see PEP 3149.
+ if 'SOABI' in get_config_vars():
+ shared_lib_extension = shared_lib_extension.replace('.'+get_config_var('SOABI'), '', 1)
static_lib_extension = ".a" # or .lib
static_lib_format = "lib%s%s" # or %s%s
shared_lib_format = "%s%s"
diff --git a/numpy/distutils/fcompiler/intel.py b/numpy/distutils/fcompiler/intel.py
index d7effb01e..b593a91c7 100644
--- a/numpy/distutils/fcompiler/intel.py
+++ b/numpy/distutils/fcompiler/intel.py
@@ -136,9 +136,9 @@ class IntelItaniumFCompiler(IntelFCompiler):
class IntelEM64TFCompiler(IntelFCompiler):
compiler_type = 'intelem'
compiler_aliases = ()
- description = 'Intel Fortran Compiler for EM64T-based apps'
+ description = 'Intel Fortran Compiler for 64-bit apps'
- version_match = intel_version_match('EM64T-based|Intel\\(R\\) 64')
+ version_match = intel_version_match('EM64T-based|Intel\\(R\\) 64|64|IA-64|64-bit')
possible_executables = ['ifort', 'efort', 'efc']
@@ -165,9 +165,9 @@ class IntelVisualFCompiler(BaseIntelFCompiler):
compiler_type = 'intelv'
description = 'Intel Visual Fortran Compiler for 32-bit apps'
version_match = intel_version_match('32-bit|IA-32')
-
+
def update_executables(self):
- f = dummy_fortran_file()
+ f = dummy_fortran_file()
self.executables['version_cmd'] = ['<F77>', '/FI', '/c',
f + '.f', '/o', f + '.o']
diff --git a/numpy/distutils/intelccompiler.py b/numpy/distutils/intelccompiler.py
index e03c5beba..b82445ab8 100644
--- a/numpy/distutils/intelccompiler.py
+++ b/numpy/distutils/intelccompiler.py
@@ -9,9 +9,11 @@ class IntelCCompiler(UnixCCompiler):
compiler_type = 'intel'
cc_exe = 'icc'
+ cc_args = 'fPIC'
def __init__ (self, verbose=0, dry_run=0, force=0):
UnixCCompiler.__init__ (self, verbose,dry_run, force)
+ self.cc_exe = 'icc -fPIC'
compiler = self.cc_exe
self.set_executables(compiler=compiler,
compiler_so=compiler,
@@ -27,3 +29,21 @@ class IntelItaniumCCompiler(IntelCCompiler):
for cc_exe in map(find_executable,['icc','ecc']):
if cc_exe:
break
+
+class IntelEM64TCCompiler(UnixCCompiler):
+
+""" A modified Intel x86_64 compiler compatible with a 64bit gcc built Python.
+ """
+
+ compiler_type = 'intelem'
+ cc_exe = 'icc -m64 -fPIC'
+ cc_args = "-fPIC"
+ def __init__ (self, verbose=0, dry_run=0, force=0):
+ UnixCCompiler.__init__ (self, verbose,dry_run, force)
+ self.cc_exe = 'icc -m64 -fPIC'
+ compiler = self.cc_exe
+ self.set_executables(compiler=compiler,
+ compiler_so=compiler,
+ compiler_cxx=compiler,
+ linker_exe=compiler,
+ linker_so=compiler + ' -shared')
diff --git a/numpy/distutils/npy_pkg_config.py b/numpy/distutils/npy_pkg_config.py
index fed95b921..4f64623ed 100644
--- a/numpy/distutils/npy_pkg_config.py
+++ b/numpy/distutils/npy_pkg_config.py
@@ -2,7 +2,7 @@ import sys
if sys.version_info[0] < 3:
from ConfigParser import SafeConfigParser, NoOptionError
else:
- from configparser import SafeConfigParser, NoOptionError
+ from configparser import ConfigParser, SafeConfigParser, NoOptionError
import re
import os
import shlex
@@ -270,7 +270,12 @@ def parse_config(filename, dirs=None):
else:
filenames = [filename]
- config = SafeConfigParser()
+ if sys.version[:3] > '3.1':
+ # SafeConfigParser is deprecated in py-3.2 and renamed to ConfigParser
+ config = ConfigParser()
+ else:
+ config = SafeConfigParser()
+
n = config.read(filenames)
if not len(n) >= 1:
raise PkgNotFound("Could not find file(s) %s" % str(filenames))
diff --git a/numpy/distutils/system_info.py b/numpy/distutils/system_info.py
index 7cc33eb43..667ca82bc 100644
--- a/numpy/distutils/system_info.py
+++ b/numpy/distutils/system_info.py
@@ -117,9 +117,9 @@ import copy
import warnings
from glob import glob
if sys.version_info[0] < 3:
- from ConfigParser import SafeConfigParser, NoOptionError, ConfigParser
+ from ConfigParser import NoOptionError, ConfigParser
else:
- from configparser import SafeConfigParser, NoOptionError, ConfigParser
+ from configparser import NoOptionError, ConfigParser
from distutils.errors import DistutilsError
from distutils.dist import Distribution
@@ -211,6 +211,10 @@ default_include_dirs = filter(os.path.isdir, default_include_dirs)
default_src_dirs = filter(os.path.isdir, default_src_dirs)
so_ext = distutils.sysconfig.get_config_vars('SO')[0] or ''
+# fix long extension for Python >=3.2, see PEP 3149.
+if 'SOABI' in distutils.sysconfig.get_config_vars():
+ so_ext = so_ext.replace('.'+distutils.sysconfig.get_config_var('SOABI'), '', 1)
+
def get_standard_file(fname):
"""Returns a list of files named 'fname' from
@@ -1324,7 +1328,7 @@ class lapack_opt_info(system_info):
or ('ATLAS_WITHOUT_LAPACK',None) in l:
need_lapack = 1
info = atlas_info
-
+
else:
warnings.warn(AtlasNotFoundError.__doc__)
need_blas = 1
diff --git a/numpy/distutils/tests/test_fcompiler_intel.py b/numpy/distutils/tests/test_fcompiler_intel.py
new file mode 100644
index 000000000..ad03daeea
--- /dev/null
+++ b/numpy/distutils/tests/test_fcompiler_intel.py
@@ -0,0 +1,34 @@
+from numpy.testing import *
+
+import numpy.distutils.fcompiler
+
+intel_32bit_version_strings = [
+ ("Intel(R) Fortran Intel(R) 32-bit Compiler Professional for applications"\
+ "running on Intel(R) 32, Version 11.1", '11.1'),
+]
+
+intel_64bit_version_strings = [
+ ("Intel(R) Fortran IA-64 Compiler Professional for applications"\
+ "running on IA-64, Version 11.0", '11.0'),
+ ("Intel(R) Fortran Intel(R) 64 Compiler Professional for applications"\
+ "running on Intel(R) 64, Version 11.1", '11.1')
+]
+
+class TestIntelFCompilerVersions(TestCase):
+ def test_32bit_version(self):
+ fc = numpy.distutils.fcompiler.new_fcompiler(compiler='intel')
+ for vs, version in intel_32bit_version_strings:
+ v = fc.version_match(vs)
+ assert_(v == version)
+
+
+class TestIntelEM64TFCompilerVersions(TestCase):
+ def test_64bit_version(self):
+ fc = numpy.distutils.fcompiler.new_fcompiler(compiler='intelem')
+ for vs, version in intel_64bit_version_strings:
+ v = fc.version_match(vs)
+ assert_(v == version)
+
+
+if __name__ == '__main__':
+ run_module_suite()
diff --git a/numpy/doc/structured_arrays.py b/numpy/doc/structured_arrays.py
index 6eafd71cd..af777efa4 100644
--- a/numpy/doc/structured_arrays.py
+++ b/numpy/doc/structured_arrays.py
@@ -1,6 +1,6 @@
"""
=====================================
-Structured Arrays (aka Record Arrays)
+Structured Arrays (and Record Arrays)
=====================================
Introduction
@@ -26,7 +26,7 @@ position we get the second record: ::
Conveniently, one can access any field of the array by indexing using the
string that names that field. In this case the fields have received the
-default names 'f0', 'f1' and 'f2'.
+default names 'f0', 'f1' and 'f2'. ::
>>> y = x['f1']
>>> y
@@ -118,7 +118,7 @@ like Fortran equivalencing).
3) List argument: In this case the record structure is defined with a list of
tuples. Each tuple has 2 or 3 elements specifying: 1) The name of the field
('' is permitted), 2) the type of the field, and 3) the shape (optional).
-For example:
+For example::
>>> x = np.zeros(3, dtype=[('x','f4'),('y',np.float32),('value','f4',(2,2))])
>>> x
@@ -142,7 +142,7 @@ to be strings), where the value of None is permitted. As an example: ::
dtype=[('col1', '>i4'), ('col2', '>f4')])
The other dictionary form permitted is a dictionary of name keys with tuple
-values specifying type, offset, and an optional title.
+values specifying type, offset, and an optional title. ::
>>> x = np.zeros(3, dtype={'col1':('i1',0,'title 1'), 'col2':('f4',1,'title 2')})
>>> x
@@ -168,9 +168,56 @@ Accessing field titles
====================================
The field titles provide a standard place to put associated info for fields.
-They do not have to be strings.
+They do not have to be strings. ::
>>> x.dtype.fields['x'][2]
'title 1'
+Accessing multiple fields at once
+====================================
+
+You can access multiple fields at once using a list of field names: ::
+
+ >>> x = np.array([(1.5,2.5,(1.0,2.0)),(3.,4.,(4.,5.)),(1.,3.,(2.,6.))],
+ dtype=[('x','f4'),('y',np.float32),('value','f4',(2,2))])
+
+Notice that `x` is created with a list of tuples. ::
+
+ >>> x[['x','y']]
+ array([(1.5, 2.5), (3.0, 4.0), (1.0, 3.0)],
+ dtype=[('x', '<f4'), ('y', '<f4')])
+ >>> x[['x','value']]
+ array([(1.5, [[1.0, 2.0], [1.0, 2.0]]), (3.0, [[4.0, 5.0], [4.0, 5.0]]),
+ (1.0, [[2.0, 6.0], [2.0, 6.0]])],
+ dtype=[('x', '<f4'), ('value', '<f4', (2, 2))])
+
+Notice that the fields are always returned in the same order regardless of
+the sequence they are asked for. ::
+
+ >>> x[['y','x']]
+ array([(1.5, 2.5), (3.0, 4.0), (1.0, 3.0)],
+ dtype=[('x', '<f4'), ('y', '<f4')])
+
+Filling structured arrays
+=========================
+
+Structured arrays can be filled by field or row by row. ::
+
+ >>> arr = np.zeros((5,), dtype=[('var1','f8'),('var2','f8')])
+ >>> arr['var1'] = np.arange(5)
+
+If you fill it in row by row, it takes a take a tuple
+(but not a list or array!)::
+
+ >>> arr[0] = (10,20)
+ >>> arr
+ array([(10.0, 20.0), (1.0, 0.0), (2.0, 0.0), (3.0, 0.0), (4.0, 0.0)],
+ dtype=[('var1', '<f8'), ('var2', '<f8')])
+
+More information
+====================================
+You can find some more information on recarrays and structured arrays
+(including the difference between the two) `here
+<http://www.scipy.org/Cookbook/Recarray>`_.
+
"""
diff --git a/numpy/f2py/crackfortran.py b/numpy/f2py/crackfortran.py
index ccc62188b..c3082bbf7 100755
--- a/numpy/f2py/crackfortran.py
+++ b/numpy/f2py/crackfortran.py
@@ -696,7 +696,7 @@ def appenddecl(decl,decl2,force=1):
return decl
selectpattern=re.compile(r'\s*(?P<this>(@\(@.*?@\)@|[*][\d*]+|[*]\s*@\(@.*?@\)@|))(?P<after>.*)\Z',re.I)
-nameargspattern=re.compile(r'\s*(?P<name>\b[\w$]+\b)\s*(@\(@\s*(?P<args>[\w\s,]*)\s*@\)@|)\s*(result(\s*@\(@\s*(?P<result>\b[\w$]+\b)\s*@\)@|))*\s*\Z',re.I)
+nameargspattern=re.compile(r'\s*(?P<name>\b[\w$]+\b)\s*(@\(@\s*(?P<args>[\w\s,]*)\s*@\)@|)\s*((result(\s*@\(@\s*(?P<result>\b[\w$]+\b)\s*@\)@|))|(bind\s*@\(@\s*(?P<bind>.*)\s*@\)@))*\s*\Z',re.I)
callnameargspattern=re.compile(r'\s*(?P<name>\b[\w$]+\b)\s*@\(@\s*(?P<args>.*)\s*@\)@\s*\Z',re.I)
real16pattern = re.compile(r'([-+]?(?:\d+(?:\.\d*)?|\d*\.\d+))[dD]((?:[-+]?\d+)?)')
real8pattern = re.compile(r'([-+]?((?:\d+(?:\.\d*)?|\d*\.\d+))[eE]((?:[-+]?\d+)?)|(\d+\.\d*))')
@@ -711,10 +711,12 @@ def _is_intent_callback(vdecl):
def _resolvenameargspattern(line):
line = markouterparen(line)
m1=nameargspattern.match(line)
- if m1: return m1.group('name'),m1.group('args'),m1.group('result')
+ if m1:
+ return m1.group('name'),m1.group('args'),m1.group('result'), m1.group('bind')
m1=callnameargspattern.match(line)
- if m1: return m1.group('name'),m1.group('args'),None
- return None,[],None
+ if m1:
+ return m1.group('name'),m1.group('args'),None, None
+ return None,[],None, None
def analyzeline(m,case,line):
global groupcounter,groupname,groupcache,grouplist,filepositiontext,\
@@ -743,7 +745,7 @@ def analyzeline(m,case,line):
block = block.lower()
if re.match(r'block\s*data',block,re.I): block='block data'
if re.match(r'python\s*module',block,re.I): block='python module'
- name,args,result = _resolvenameargspattern(m.group('after'))
+ name,args,result,bind = _resolvenameargspattern(m.group('after'))
if name is None:
if block=='block data':
name = '_BLOCK_DATA_'
@@ -779,7 +781,8 @@ def analyzeline(m,case,line):
if f77modulename and neededmodule==-1 and groupcounter<=1:
neededmodule=groupcounter+2
needmodule=1
- needinterface=1
+ if block != 'interface':
+ needinterface=1
# Create new block(s)
groupcounter=groupcounter+1
groupcache[groupcounter]={}
@@ -826,7 +829,9 @@ def analyzeline(m,case,line):
else:
groupcache[groupcounter]['from']='%s:%s'%(groupcache[groupcounter-1]['from'],groupcache[groupcounter-1]['name'])
for k in groupcache[groupcounter].keys():
- if not groupcache[groupcounter][k]: del groupcache[groupcounter][k]
+ if not groupcache[groupcounter][k]:
+ del groupcache[groupcounter][k]
+
groupcache[groupcounter]['args']=args
groupcache[groupcounter]['body']=[]
groupcache[groupcounter]['externals']=[]
@@ -860,6 +865,7 @@ def analyzeline(m,case,line):
if t:
typespec,selector,attr,edecl=cracktypespec0(t.group('this'),t.group('after'))
updatevars(typespec,selector,attr,edecl)
+
if case in ['call','callfun']:
grouplist[groupcounter-1].append(groupcache[groupcounter])
grouplist[groupcounter-1][-1]['body']=grouplist[groupcounter]
@@ -869,8 +875,9 @@ def analyzeline(m,case,line):
grouplist[groupcounter-1][-1]['body']=grouplist[groupcounter]
del grouplist[groupcounter]
groupcounter=groupcounter-1 # end interface
+
elif case=='entry':
- name,args,result=_resolvenameargspattern(m.group('after'))
+ name,args,result,bind=_resolvenameargspattern(m.group('after'))
if name is not None:
if args:
args=rmbadname([x.strip() for x in markoutercomma(args).split('@,@')])
@@ -921,11 +928,12 @@ def analyzeline(m,case,line):
if _intentcallbackpattern.match(ap):
if k not in groupcache[groupcounter]['args']:
if groupcounter>1:
- outmess('analyzeline: appending intent(callback) %s'\
- ' to %s arguments\n' % (k,groupcache[groupcounter]['name']))
if '__user__' not in groupcache[groupcounter-2]['name']:
outmess('analyzeline: missing __user__ module (could be nothing)\n')
- groupcache[groupcounter]['args'].append(k)
+ if k!=groupcache[groupcounter]['name']: # fixes ticket 1693
+ outmess('analyzeline: appending intent(callback) %s'\
+ ' to %s arguments\n' % (k,groupcache[groupcounter]['name']))
+ groupcache[groupcounter]['args'].append(k)
else:
errmess('analyzeline: intent(callback) %s is ignored' % (k))
else:
diff --git a/numpy/fft/fftpack.py b/numpy/fft/fftpack.py
index 52cd1ae0c..7f9ee57fd 100644
--- a/numpy/fft/fftpack.py
+++ b/numpy/fft/fftpack.py
@@ -31,8 +31,7 @@ version of the FFTPACK routines.
"""
__all__ = ['fft','ifft', 'rfft', 'irfft', 'hfft', 'ihfft', 'rfftn',
- 'irfftn', 'rfft2', 'irfft2', 'fft2', 'ifft2', 'fftn', 'ifftn',
- 'refft', 'irefft','refftn','irefftn', 'refft2', 'irefft2']
+ 'irfftn', 'rfft2', 'irfft2', 'fft2', 'ifft2', 'fftn', 'ifftn']
from numpy.core import asarray, zeros, swapaxes, shape, conjugate, \
take
@@ -1114,12 +1113,3 @@ def irfft2(a, s=None, axes=(-2,-1)):
"""
return irfftn(a, s, axes)
-
-# Deprecated names
-from numpy import deprecate
-refft = deprecate(rfft, 'refft', 'rfft')
-irefft = deprecate(irfft, 'irefft', 'irfft')
-refft2 = deprecate(rfft2, 'refft2', 'rfft2')
-irefft2 = deprecate(irfft2, 'irefft2', 'irfft2')
-refftn = deprecate(rfftn, 'refftn', 'rfftn')
-irefftn = deprecate(irfftn, 'irefftn', 'irfftn')
diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py
index 042866f30..721039238 100644
--- a/numpy/lib/arraysetops.py
+++ b/numpy/lib/arraysetops.py
@@ -10,11 +10,6 @@ Set operations for 1D numeric arrays based on sorting.
union1d,
setdiff1d
-:Deprecated:
- unique1d,
- intersect1d_nu,
- setmember1d
-
:Notes:
For floating point arrays, inaccurate results may appear due to usual round-off
@@ -28,8 +23,8 @@ To do: Optionally return indices analogously to unique for all functions.
:Author: Robert Cimrman
"""
-__all__ = ['ediff1d', 'unique1d', 'intersect1d', 'intersect1d_nu', 'setxor1d',
- 'setmember1d', 'union1d', 'setdiff1d', 'unique', 'in1d']
+__all__ = ['ediff1d', 'intersect1d', 'setxor1d', 'union1d', 'setdiff1d',
+ 'unique', 'in1d']
import numpy as np
from numpy.lib.utils import deprecate
@@ -417,72 +412,3 @@ def setdiff1d(ar1, ar2, assume_unique=False):
return aux
else:
return np.asarray(ar1)[aux == 0]
-
-@deprecate
-def unique1d(ar1, return_index=False, return_inverse=False):
- """
- This function is deprecated. Use unique() instead.
- """
- if return_index:
- import warnings
- warnings.warn("The order of the output arguments for "
- "`return_index` has changed. Before, "
- "the output was (indices, unique_arr), but "
- "has now been reversed to be more consistent.")
-
- ar = np.asanyarray(ar1).flatten()
- if ar.size == 0:
- if return_inverse and return_index:
- return ar, np.empty(0, np.bool), np.empty(0, np.bool)
- elif return_inverse or return_index:
- return ar, np.empty(0, np.bool)
- else:
- return ar
-
- if return_inverse or return_index:
- perm = ar.argsort()
- aux = ar[perm]
- flag = np.concatenate(([True], aux[1:] != aux[:-1]))
- if return_inverse:
- iflag = np.cumsum(flag) - 1
- iperm = perm.argsort()
- if return_index:
- return aux[flag], perm[flag], iflag[iperm]
- else:
- return aux[flag], iflag[iperm]
- else:
- return aux[flag], perm[flag]
-
- else:
- ar.sort()
- flag = np.concatenate(([True], ar[1:] != ar[:-1]))
- return ar[flag]
-
-@deprecate
-def intersect1d_nu(ar1, ar2):
- """
- This function is deprecated. Use intersect1d()
- instead.
- """
- # Might be faster than unique1d( intersect1d( ar1, ar2 ) )?
- aux = np.concatenate((unique1d(ar1), unique1d(ar2)))
- aux.sort()
- return aux[aux[1:] == aux[:-1]]
-
-@deprecate
-def setmember1d(ar1, ar2):
- """
- This function is deprecated. Use in1d(assume_unique=True)
- instead.
- """
- # We need this to be a stable sort, so always use 'mergesort' here. The
- # values from the first array should always come before the values from the
- # second array.
- ar = np.concatenate( (ar1, ar2 ) )
- order = ar.argsort(kind='mergesort')
- sar = ar[order]
- equal_adj = (sar[1:] == sar[:-1])
- flag = np.concatenate( (equal_adj, [False] ) )
-
- indx = order.argsort(kind='mergesort')[:len( ar1 )]
- return flag[indx]
diff --git a/numpy/lib/arrayterator.py b/numpy/lib/arrayterator.py
index 3f07cd263..2df05e514 100644
--- a/numpy/lib/arrayterator.py
+++ b/numpy/lib/arrayterator.py
@@ -141,12 +141,41 @@ class Arrayterator(object):
@property
def flat(self):
+ """
+ A 1-D flat iterator for Arrayterator objects.
+
+ This iterator returns elements of the array to be iterated over in
+ `Arrayterator` one by one. It is similar to `flatiter`.
+
+ See Also
+ --------
+ `Arrayterator`
+ flatiter
+
+ Examples
+ --------
+ >>> a = np.arange(3 * 4 * 5 * 6).reshape(3, 4, 5, 6)
+ >>> a_itor = np.lib.arrayterator.Arrayterator(a, 2)
+
+ >>> for subarr in a_itor.flat:
+ ... if not subarr:
+ ... print subarr, type(subarr)
+ ...
+ 0 <type 'numpy.int32'>
+
+ """
for block in self:
for value in block.flat:
yield value
@property
def shape(self):
+ """
+ The shape of the array to be iterated over.
+
+ For an example, see `Arrayterator`.
+
+ """
return tuple(((stop-start-1)//step+1) for start, stop, step in
zip(self.start, self.stop, self.step))
diff --git a/numpy/lib/benchmarks/bench_arraysetops.py b/numpy/lib/benchmarks/bench_arraysetops.py
deleted file mode 100644
index 2c77fb758..000000000
--- a/numpy/lib/benchmarks/bench_arraysetops.py
+++ /dev/null
@@ -1,65 +0,0 @@
-import numpy as np
-import time
-from numpy.lib.arraysetops import *
-
-def bench_unique1d( plot_results = False ):
- exponents = np.linspace( 2, 7, 9 )
- ratios = []
- nItems = []
- dt1s = []
- dt2s = []
- for ii in exponents:
-
- nItem = 10 ** ii
- print 'using %d items:' % nItem
- a = np.fix( nItem / 10 * np.random.random( nItem ) )
-
- print 'unique:'
- tt = time.clock()
- b = np.unique( a )
- dt1 = time.clock() - tt
- print dt1
-
- print 'unique1d:'
- tt = time.clock()
- c = unique1d( a )
- dt2 = time.clock() - tt
- print dt2
-
-
- if dt1 < 1e-8:
- ratio = 'ND'
- else:
- ratio = dt2 / dt1
- print 'ratio:', ratio
- print 'nUnique: %d == %d\n' % (len( b ), len( c ))
-
- nItems.append( nItem )
- ratios.append( ratio )
- dt1s.append( dt1 )
- dt2s.append( dt2 )
-
- assert np.alltrue( b == c )
-
- print nItems
- print dt1s
- print dt2s
- print ratios
-
- if plot_results:
- import pylab
-
- def plotMe( fig, fun, nItems, dt1s, dt2s ):
- pylab.figure( fig )
- fun( nItems, dt1s, 'g-o', linewidth = 2, markersize = 8 )
- fun( nItems, dt2s, 'b-x', linewidth = 2, markersize = 8 )
- pylab.legend( ('unique', 'unique1d' ) )
- pylab.xlabel( 'nItem' )
- pylab.ylabel( 'time [s]' )
-
- plotMe( 1, pylab.loglog, nItems, dt1s, dt2s )
- plotMe( 2, pylab.plot, nItems, dt1s, dt2s )
- pylab.show()
-
-if __name__ == '__main__':
- bench_unique1d( plot_results = True )
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 292dbe41d..dd792c509 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -99,7 +99,7 @@ def histogram(a, bins=10, range=None, normed=False, weights=None):
See Also
--------
- histogramdd, bincount, searchsorted
+ histogramdd, bincount, searchsorted, digitize
Notes
-----
@@ -1447,8 +1447,7 @@ def nanmin(a, axis=None):
Positive infinity is treated as a very large number and negative infinity
is treated as a very small (i.e. negative) number.
- If the input has a integer type, an integer type is returned unless
- the input contains NaNs and infinity.
+ If the input has a integer type the function is equivalent to np.min.
Examples
@@ -1469,7 +1468,11 @@ def nanmin(a, axis=None):
-inf
"""
- return _nanop(np.min, np.inf, a, axis)
+ a = np.asanyarray(a)
+ if axis is not None:
+ return np.fmin.reduce(a, axis)
+ else:
+ return np.fmin.reduce(a.flat)
def nanargmin(a, axis=None):
"""
@@ -1541,8 +1544,7 @@ def nanmax(a, axis=None):
Positive infinity is treated as a very large number and negative infinity
is treated as a very small (i.e. negative) number.
- If the input has a integer type, an integer type is returned unless
- the input contains NaNs and infinity.
+ If the input has a integer type the function is equivalent to np.max.
Examples
--------
@@ -1562,7 +1564,11 @@ def nanmax(a, axis=None):
inf
"""
- return _nanop(np.max, -np.inf, a, axis)
+ a = np.asanyarray(a)
+ if axis is not None:
+ return np.fmax.reduce(a, axis)
+ else:
+ return np.fmax.reduce(a.flat)
def nanargmax(a, axis=None):
"""
@@ -2921,22 +2927,22 @@ def percentile(a, q, axis=None, out=None, overwrite_input=False):
a : array_like
Input array or object that can be converted to an array.
q : float in range of [0,100] (or sequence of floats)
- percentile to compute which must be between 0 and 100 inclusive
- axis : {None, int}, optional
- Axis along which the percentiles are computed. The default (axis=None)
+ Percentile to compute which must be between 0 and 100 inclusive.
+ axis : int, optional
+ Axis along which the percentiles are computed. The default (None)
is to compute the median along a flattened version of the array.
out : ndarray, optional
Alternative output array in which to place the result. It must
have the same shape and buffer length as the expected output,
but the type (of the output) will be cast if necessary.
- overwrite_input : {False, True}, optional
- If True, then allow use of memory of input array (a) for
+ overwrite_input : bool, optional
+ If True, then allow use of memory of input array `a` for
calculations. The input array will be modified by the call to
median. This will save memory when you do not need to preserve
the contents of the input array. Treat the input as undefined,
- but it will probably be fully or partially sorted. Default is
- False. Note that, if `overwrite_input` is True and the input
- is not already an ndarray, an error will be raised.
+ but it will probably be fully or partially sorted.
+ Default is False. Note that, if `overwrite_input` is True and the
+ input is not already an array, an error will be raised.
Returns
-------
@@ -2954,10 +2960,10 @@ def percentile(a, q, axis=None, out=None, overwrite_input=False):
Notes
-----
Given a vector V of length N, the qth percentile of V is the qth ranked
- value in a sorted copy of V. A weighted average of the two nearest neighbors
- is used if the normalized ranking does not match q exactly.
- The same as the median if q is 0.5; the same as the min if q is 0;
- and the same as the max if q is 1
+ value in a sorted copy of V. A weighted average of the two nearest
+ neighbors is used if the normalized ranking does not match q exactly.
+ The same as the median if ``q=0.5``, the same as the minimum if ``q=0``
+ and the same as the maximum if ``q=1``.
Examples
--------
@@ -2971,12 +2977,14 @@ def percentile(a, q, axis=None, out=None, overwrite_input=False):
array([ 6.5, 4.5, 2.5])
>>> np.percentile(a, 0.5, axis=1)
array([ 7., 2.])
+
>>> m = np.percentile(a, 0.5, axis=0)
>>> out = np.zeros_like(m)
>>> np.percentile(a, 0.5, axis=0, out=m)
array([ 6.5, 4.5, 2.5])
>>> m
array([ 6.5, 4.5, 2.5])
+
>>> b = a.copy()
>>> np.percentile(b, 0.5, axis=1, overwrite_input=True)
array([ 7., 2.])
diff --git a/numpy/lib/index_tricks.py b/numpy/lib/index_tricks.py
index 264ebaad0..d1e925ead 100644
--- a/numpy/lib/index_tricks.py
+++ b/numpy/lib/index_tricks.py
@@ -1,4 +1,5 @@
-__all__ = ['unravel_index',
+__all__ = ['ravel_coords',
+ 'unravel_index',
'mgrid',
'ogrid',
'r_', 'c_', 's_',
@@ -16,70 +17,9 @@ import math
import function_base
import numpy.matrixlib as matrix
from function_base import diff
+from numpy.lib._compiled_base import ravel_coords, unravel_index
makemat = matrix.matrix
-# contributed by Stefan van der Walt
-def unravel_index(x,dims):
- """
- Convert a flat index to an index tuple for an array of given shape.
-
- Parameters
- ----------
- x : int
- Flattened index.
- dims : tuple of ints
- Input shape, the shape of an array into which indexing is
- required.
-
- Returns
- -------
- idx : tuple of ints
- Tuple of the same shape as `dims`, containing the unraveled index.
-
- Notes
- -----
- In the Examples section, since ``arr.flat[x] == arr.max()`` it may be
- easier to use flattened indexing than to re-map the index to a tuple.
-
- Examples
- --------
- >>> arr = np.arange(20).reshape(5, 4)
- >>> arr
- array([[ 0, 1, 2, 3],
- [ 4, 5, 6, 7],
- [ 8, 9, 10, 11],
- [12, 13, 14, 15],
- [16, 17, 18, 19]])
- >>> x = arr.argmax()
- >>> x
- 19
- >>> dims = arr.shape
- >>> idx = np.unravel_index(x, dims)
- >>> idx
- (4, 3)
- >>> arr[idx] == arr.max()
- True
-
- """
- if x > _nx.prod(dims)-1 or x < 0:
- raise ValueError("Invalid index, must be 0 <= x <= number of elements.")
-
- idx = _nx.empty_like(dims)
-
- # Take dimensions
- # [a,b,c,d]
- # Reverse and drop first element
- # [d,c,b]
- # Prepend [1]
- # [1,d,c,b]
- # Calculate cumulative product
- # [1,d,dc,dcb]
- # Reverse
- # [dcb,dc,d,1]
- dim_prod = _nx.cumprod([1] + list(dims)[:0:-1])[::-1]
- # Indices become [x/dcb % a, x/dc % b, x/d % c, x/1 % d]
- return tuple(x//dim_prod % dims)
-
def ix_(*args):
"""
Construct an open mesh from multiple sequences.
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index aeccc2a24..9fbacaa22 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -500,7 +500,7 @@ def savez_compressed(file, *args, **kwds):
Parameters
----------
- file : string
+ file : str
File name of .npz file.
args : Arguments
Function arguments.
@@ -683,19 +683,44 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None,
X = []
def flatten_dtype(dt):
- """Unpack a structured data-type."""
+ """Unpack a structured data-type, and produce re-packing info."""
if dt.names is None:
# If the dtype is flattened, return.
# If the dtype has a shape, the dtype occurs
# in the list more than once.
- return [dt.base] * int(np.prod(dt.shape))
+ shape = dt.shape
+ if len(shape) == 0:
+ return ([dt.base], None)
+ else:
+ packing = [(shape[-1], tuple)]
+ if len(shape) > 1:
+ for dim in dt.shape[-2:0:-1]:
+ packing = [(dim*packing[0][0],packing*dim)]
+ packing = packing*shape[0]
+ return ([dt.base] * int(np.prod(dt.shape)), packing)
else:
types = []
+ packing = []
for field in dt.names:
tp, bytes = dt.fields[field]
- flat_dt = flatten_dtype(tp)
+ flat_dt, flat_packing = flatten_dtype(tp)
types.extend(flat_dt)
- return types
+ packing.append((len(flat_dt),flat_packing))
+ return (types, packing)
+
+ def pack_items(items, packing):
+ """Pack items into nested lists based on re-packing info."""
+ if packing == None:
+ return items[0]
+ elif packing is tuple:
+ return tuple(items)
+ else:
+ start = 0
+ ret = []
+ for length, subpacking in packing:
+ ret.append(pack_items(items[start:start+length], subpacking))
+ start += length
+ return tuple(ret)
def split_line(line):
"""Chop off comments, strip, and split at delimiter."""
@@ -724,7 +749,7 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None,
first_vals = split_line(first_line)
N = len(usecols or first_vals)
- dtype_types = flatten_dtype(dtype)
+ dtype_types, packing = flatten_dtype(dtype)
if len(dtype_types) > 1:
# We're dealing with a structured array, each field of
# the dtype matches a column
@@ -732,6 +757,8 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None,
else:
# All fields have the same dtype
converters = [defconv for i in xrange(N)]
+ if N > 1:
+ packing = [(N, tuple)]
# By preference, use the converters specified by the user
for i, conv in (user_converters or {}).iteritems():
@@ -753,27 +780,16 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None,
vals = [vals[i] for i in usecols]
# Convert each value according to its column and store
- X.append(tuple([conv(val) for (conv, val) in zip(converters, vals)]))
+ items = [conv(val) for (conv, val) in zip(converters, vals)]
+ # Then pack it according to the dtype's nesting
+ items = pack_items(items, packing)
+
+ X.append(items)
finally:
if own_fh:
fh.close()
- if len(dtype_types) > 1:
- # We're dealing with a structured array, with a dtype such as
- # [('x', int), ('y', [('s', int), ('t', float)])]
- #
- # First, create the array using a flattened dtype:
- # [('x', int), ('s', int), ('t', float)]
- #
- # Then, view the array using the specified dtype.
- try:
- X = np.array(X, dtype=np.dtype([('', t) for t in dtype_types]))
- X = X.view(dtype)
- except TypeError:
- # In the case we have an object dtype
- X = np.array(X, dtype=dtype)
- else:
- X = np.array(X, dtype)
+ X = np.array(X, dtype)
X = np.squeeze(X)
if unpack:
@@ -1012,7 +1028,7 @@ def fromregex(file, regexp, dtype):
return output
finally:
if own_fh:
- fh.close()
+ file.close()
@@ -1033,7 +1049,7 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
"""
Load data from a text file, with missing values handled as specified.
- Each line past the first `skiprows` lines is split at the `delimiter`
+ Each line past the first `skip_header` lines is split at the `delimiter`
character, and characters following the `comments` character are discarded.
Parameters
@@ -1056,20 +1072,20 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
The numbers of lines to skip at the beginning of the file.
skip_footer : int, optional
The numbers of lines to skip at the end of the file
- converters : variable or None, optional
+ converters : variable, optional
The set of functions that convert the data of a column to a value.
The converters can also be used to provide a default value
for missing data: ``converters = {3: lambda s: float(s or 0)}``.
- missing_values : variable or None, optional
+ missing_values : variable, optional
The set of strings corresponding to missing data.
- filling_values : variable or None, optional
+ filling_values : variable, optional
The set of values to be used as default when the data are missing.
- usecols : sequence or None, optional
+ usecols : sequence, optional
Which columns to read, with 0 being the first. For example,
``usecols = (1, 4, 5)`` will extract the 2nd, 5th and 6th columns.
names : {None, True, str, sequence}, optional
If `names` is True, the field names are read from the first valid line
- after the first `skiprows` lines.
+ after the first `skip_header` lines.
If `names` is a sequence or a single-string of comma-separated names,
the names will be used to define the field names in a structured dtype.
If `names` is None, the names of the dtype fields will be used, if any.
@@ -1202,9 +1218,10 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
# Get the first valid lines after the first skiprows ones ..
if skiprows:
- warnings.warn("The use of `skiprows` is deprecated.\n"\
- "Please use `skip_header` instead.",
- DeprecationWarning)
+ warnings.warn(\
+ "The use of `skiprows` is deprecated, it will be removed in numpy 2.0.\n" \
+ "Please use `skip_header` instead.",
+ DeprecationWarning)
skip_header = skiprows
# Skip the first `skip_header` rows
for i in xrange(skip_header):
@@ -1269,7 +1286,7 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
elif (names is not None) and (len(names) > nbcols):
names = [names[_] for _ in usecols]
elif (names is not None) and (dtype is not None):
- names = dtype.names
+ names = list(dtype.names)
# Process the missing values ...............................
@@ -1327,9 +1344,10 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
# Process the deprecated `missing`
if missing != asbytes(''):
- warnings.warn("The use of `missing` is deprecated.\n"\
- "Please use `missing_values` instead.",
- DeprecationWarning)
+ warnings.warn(\
+ "The use of `missing` is deprecated, it will be removed in Numpy 2.0.\n" \
+ "Please use `missing_values` instead.",
+ DeprecationWarning)
values = [str(_) for _ in missing.split(asbytes(","))]
for entry in missing_values:
entry.extend(values)
@@ -1486,7 +1504,7 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
if _[0] > nbrows + skip_header])
invalid = invalid[:nbinvalid - nbinvalid_skipped]
skip_footer -= nbinvalid_skipped
-#
+#
# nbrows -= skip_footer
# errmsg = [template % (i, nb)
# for (i, nb) in invalid if i < nbrows]
diff --git a/numpy/lib/polynomial.py b/numpy/lib/polynomial.py
index 603655ec2..f3146d691 100644
--- a/numpy/lib/polynomial.py
+++ b/numpy/lib/polynomial.py
@@ -151,13 +151,14 @@ def roots(p):
Return the roots of a polynomial with coefficients given in p.
The values in the rank-1 array `p` are coefficients of a polynomial.
- If the length of `p` is n+1 then the polynomial is described by
- p[0] * x**n + p[1] * x**(n-1) + ... + p[n-1]*x + p[n]
+ If the length of `p` is n+1 then the polynomial is described by::
+
+ p[0] * x**n + p[1] * x**(n-1) + ... + p[n-1]*x + p[n]
Parameters
----------
- p : array_like of shape(M,)
- Rank-1 array of polynomial co-efficients.
+ p : array_like
+ Rank-1 array of polynomial coefficients.
Returns
-------
@@ -166,32 +167,29 @@ def roots(p):
Raises
------
- ValueError:
+ ValueError :
When `p` cannot be converted to a rank-1 array.
See also
--------
-
- poly : Find the coefficients of a polynomial with
- a given sequence of roots.
+ poly : Find the coefficients of a polynomial with a given sequence
+ of roots.
polyval : Evaluate a polynomial at a point.
polyfit : Least squares polynomial fit.
poly1d : A one-dimensional polynomial class.
Notes
-----
-
The algorithm relies on computing the eigenvalues of the
companion matrix [1]_.
References
----------
- .. [1] Wikipedia, "Companion matrix",
- http://en.wikipedia.org/wiki/Companion_matrix
+ .. [1] R. A. Horn & C. R. Johnson, *Matrix Analysis*. Cambridge, UK:
+ Cambridge University Press, 1999, pp. 146-7.
Examples
--------
-
>>> coeff = [3.2, 2, 1]
>>> np.roots(coeff)
array([-0.3125+0.46351241j, -0.3125-0.46351241j])
diff --git a/numpy/lib/recfunctions.py b/numpy/lib/recfunctions.py
index f722a89d1..b3c210fff 100644
--- a/numpy/lib/recfunctions.py
+++ b/numpy/lib/recfunctions.py
@@ -376,7 +376,7 @@ def merge_arrays(seqarrays,
# Only one item in the input sequence ?
if (len(seqarrays) == 1):
seqarrays = np.asanyarray(seqarrays[0])
- # Do we have a single ndarary as input ?
+ # Do we have a single ndarray as input ?
if isinstance(seqarrays, (ndarray, np.void)):
seqdtype = seqarrays.dtype
if (not flatten) or \
diff --git a/numpy/lib/src/_compiled_base.c b/numpy/lib/src/_compiled_base.c
index 466fa0202..b44cfb471 100644
--- a/numpy/lib/src/_compiled_base.c
+++ b/numpy/lib/src/_compiled_base.c
@@ -90,27 +90,29 @@ mnx (intp *i , intp len)
/*
* arr_bincount is registered as bincount.
*
- * bincount accepts one or two arguments. The first is an array of
- * non-negative integers and the second, if present, is an array of weights,
- * which must be promotable to double. Call these arguments list and
+ * bincount accepts one, two or three arguments. The first is an array of
+ * non-negative integers The second, if present, is an array of weights,
+ * which must be promotable to double. Call these arguments list and
* weight. Both must be one-dimensional with len(weight) == len(list). If
* weight is not present then bincount(list)[i] is the number of occurrences
* of i in list. If weight is present then bincount(self,list, weight)[i]
* is the sum of all weight[j] where list [j] == i. Self is not used.
+ * The third argument, if present, is a minimum length desired for the
+ * output array.
*/
static PyObject *
arr_bincount(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
{
PyArray_Descr *type;
- PyObject *list = NULL, *weight=Py_None;
+ PyObject *list = NULL, *weight=Py_None, *mlength=Py_None;
PyObject *lst=NULL, *ans=NULL, *wts=NULL;
- intp *numbers, *ians, len , mxi, mni, ans_size;
+ intp *numbers, *ians, len , mxi, mni, ans_size, minlength;
int i;
double *weights , *dans;
- static char *kwlist[] = {"list", "weights", NULL};
+ static char *kwlist[] = {"list", "weights", "minlength", NULL};
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O",
- kwlist, &list, &weight)) {
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|OO",
+ kwlist, &list, &weight, &mlength)) {
goto fail;
}
if (!(lst = PyArray_ContiguousFromAny(list, PyArray_INTP, 1, 1))) {
@@ -131,6 +133,20 @@ arr_bincount(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
goto fail;
}
ans_size = numbers [mxi] + 1;
+ if (mlength != Py_None) {
+ if (!(minlength = PyArray_PyIntAsIntp(mlength))) {
+ goto fail;
+ }
+ if (minlength <= 0) {
+ /* superfluous, but may catch incorrect usage */
+ PyErr_SetString(PyExc_ValueError,
+ "minlength must be positive");
+ goto fail;
+ }
+ if (ans_size < minlength) {
+ ans_size = minlength;
+ }
+ }
type = PyArray_DescrFromType(PyArray_INTP);
if (weight == Py_None) {
if (!(ans = PyArray_Zeros(1, &ans_size, type, 0))) {
@@ -549,6 +565,502 @@ fail:
return NULL;
}
+/*
+ * Converts a Python sequence into 'count' PyArrayObjects
+ *
+ * seq - Input Python object, usually a tuple but any sequence works.
+ * op - Where the arrays are placed.
+ * count - How many arrays there should be (errors if it doesn't match).
+ * paramname - The name of the parameter that produced 'seq'.
+ */
+static int sequence_to_arrays(PyObject *seq,
+ PyArrayObject **op, int count,
+ char *paramname)
+{
+ int i;
+
+ if (!PySequence_Check(seq) || PySequence_Size(seq) != count) {
+ PyErr_Format(PyExc_ValueError,
+ "parameter %s must be a sequence of length %d",
+ paramname, count);
+ return -1;
+ }
+
+ for (i = 0; i < count; ++i) {
+ PyObject *item = PySequence_GetItem(seq, i);
+ if (item == NULL) {
+ while (--i >= 0) {
+ Py_DECREF(op[i]);
+ op[i] = NULL;
+ }
+ return -1;
+ }
+
+ op[i] = (PyArrayObject *)PyArray_FromAny(item, NULL, 0, 0, 0, NULL);
+ if (op[i] == NULL) {
+ while (--i >= 0) {
+ Py_DECREF(op[i]);
+ op[i] = NULL;
+ }
+ Py_DECREF(item);
+ return -1;
+ }
+
+ Py_DECREF(item);
+ }
+
+ return 0;
+}
+
+/* Inner loop for unravel_index */
+static int
+ravel_coords_loop(int ravel_ndim, npy_intp *ravel_dims,
+ npy_intp *ravel_strides,
+ npy_intp count,
+ NPY_CLIPMODE *modes,
+ char **coords, npy_intp *coords_strides)
+{
+ int i;
+ npy_intp j, m;
+
+ while (count--) {
+ npy_intp raveled = 0;
+ for (i = 0; i < ravel_ndim; ++i) {
+ m = ravel_dims[i];
+ j = *(npy_intp *)coords[i];
+ switch (modes[i]) {
+ case NPY_RAISE:
+ if(j < 0 || j>=m) {
+ PyErr_SetString(PyExc_ValueError,
+ "invalid entry in coordinates array");
+ return NPY_FAIL;
+ }
+ break;
+ case NPY_WRAP:
+ if(j < 0) {
+ j += m;
+ if(j < 0) {
+ j = j%m;
+ if(j != 0) {
+ j += m;
+ }
+ }
+ }
+ else if(j >= m) {
+ j -= m;
+ if(j >= m) {
+ j = j%m;
+ }
+ }
+ break;
+ case NPY_CLIP:
+ if(j < 0) {
+ j = 0;
+ }
+ else if(j >= m) {
+ j = m-1;
+ }
+ break;
+
+ }
+ raveled += j * ravel_strides[i];
+
+ coords[i] += coords_strides[i];
+ }
+ *(npy_intp *)coords[ravel_ndim] = raveled;
+ coords[ravel_ndim] += coords_strides[ravel_ndim];
+ }
+
+ return NPY_SUCCEED;
+}
+
+/* ravel_coords implementation - see add_newdocs.py */
+static PyObject *
+arr_ravel_coords(PyObject *self, PyObject *args, PyObject *kwds)
+{
+ int i, s;
+ PyObject *mode0=NULL, *coords0=NULL, *ret;
+ PyArray_Dims dimensions={0,0};
+ npy_intp ravel_strides[NPY_MAXDIMS];
+ PyArray_ORDER order = NPY_CORDER;
+ NPY_CLIPMODE modes[NPY_MAXDIMS];
+
+ PyArrayObject *op[NPY_MAXARGS];
+ PyArray_Descr *dtype[NPY_MAXARGS];
+ npy_uint32 op_flags[NPY_MAXARGS];
+
+ NpyIter *iter = NULL;
+
+ char *kwlist[] = {"coords", "dims", "mode", "order", NULL};
+
+ memset(op, 0, sizeof(op));
+ dtype[0] = NULL;
+
+ if(!PyArg_ParseTupleAndKeywords(args, kwds, "OO&|OO&:ravel_coords", kwlist,
+ &coords0,
+ PyArray_IntpConverter, &dimensions,
+ &mode0,
+ PyArray_OrderConverter, &order)) {
+ goto fail;
+ }
+
+ if (dimensions.len+1 > NPY_MAXARGS) {
+ PyErr_SetString(PyExc_ValueError,
+ "too many dimensions passed to ravel_coords");
+ goto fail;
+ }
+
+ if(!PyArray_ConvertClipmodeSequence(mode0, modes, dimensions.len)) {
+ goto fail;
+ }
+
+ switch (order) {
+ case NPY_CORDER:
+ s = 1;
+ for (i = dimensions.len-1; i >= 0; --i) {
+ ravel_strides[i] = s;
+ s *= dimensions.ptr[i];
+ }
+ break;
+ case NPY_FORTRANORDER:
+ s = 1;
+ for (i = 0; i < dimensions.len; ++i) {
+ ravel_strides[i] = s;
+ s *= dimensions.ptr[i];
+ }
+ break;
+ default:
+ PyErr_SetString(PyExc_ValueError,
+ "only 'C' or 'F' order is permitted");
+ goto fail;
+ }
+
+ /* Get the coords into op */
+ if (sequence_to_arrays(coords0, op, dimensions.len, "coords") < 0) {
+ goto fail;
+ }
+
+
+ for (i = 0; i < dimensions.len; ++i) {
+ op_flags[i] = NPY_ITER_READONLY|
+ NPY_ITER_ALIGNED;
+ }
+ op_flags[dimensions.len] = NPY_ITER_WRITEONLY|
+ NPY_ITER_ALIGNED|
+ NPY_ITER_ALLOCATE;
+ dtype[0] = PyArray_DescrFromType(NPY_INTP);
+ for (i = 1; i <= dimensions.len; ++i) {
+ dtype[i] = dtype[0];
+ }
+
+ iter = NpyIter_MultiNew(dimensions.len+1, op, NPY_ITER_BUFFERED|
+ NPY_ITER_NO_INNER_ITERATION|
+ NPY_ITER_ZEROSIZE_OK,
+ NPY_KEEPORDER,
+ NPY_SAME_KIND_CASTING,
+ op_flags, dtype,
+ 0, NULL, 0);
+ if (iter == NULL) {
+ goto fail;
+ }
+
+ if (NpyIter_GetIterSize(iter) != 0) {
+ NpyIter_IterNextFunc *iternext;
+ char **dataptr;
+ npy_intp *strides;
+ npy_intp *countptr;
+
+ iternext = NpyIter_GetIterNext(iter, NULL);
+ if (iternext == NULL) {
+ goto fail;
+ }
+ dataptr = NpyIter_GetDataPtrArray(iter);
+ strides = NpyIter_GetInnerStrideArray(iter);
+ countptr = NpyIter_GetInnerLoopSizePtr(iter);
+
+ do {
+ if (ravel_coords_loop(dimensions.len, dimensions.ptr,
+ ravel_strides, *countptr, modes,
+ dataptr, strides) != NPY_SUCCEED) {
+ goto fail;
+ }
+ } while(iternext(iter));
+ }
+
+ ret = (PyObject *)NpyIter_GetOperandArray(iter)[dimensions.len];
+ Py_INCREF(ret);
+
+ Py_DECREF(dtype[0]);
+ for (i = 0; i < dimensions.len; ++i) {
+ Py_XDECREF(op[i]);
+ }
+ PyDimMem_FREE(dimensions.ptr);
+ NpyIter_Deallocate(iter);
+ return PyArray_Return(ret);
+
+fail:
+ Py_XDECREF(dtype[0]);
+ for (i = 0; i < dimensions.len; ++i) {
+ Py_XDECREF(op[i]);
+ }
+ if (dimensions.ptr) {
+ PyDimMem_FREE(dimensions.ptr);
+ }
+ if (iter != NULL) {
+ NpyIter_Deallocate(iter);
+ }
+ return NULL;
+}
+
+/* C-order inner loop for unravel_index */
+static int
+unravel_index_loop_corder(int unravel_ndim, npy_intp *unravel_dims,
+ npy_intp unravel_size, npy_intp count,
+ char *indices, npy_intp indices_stride,
+ npy_intp *coords)
+{
+ int i;
+ npy_intp val;
+
+ while (count--) {
+ val = *(npy_intp *)indices;
+ if (val < 0 || val >= unravel_size) {
+ PyErr_SetString(PyExc_ValueError,
+ "invalid entry in index array");
+ return NPY_FAIL;
+ }
+ for (i = unravel_ndim-1; i >= 0; --i) {
+ coords[i] = val % unravel_dims[i];
+ val /= unravel_dims[i];
+ }
+ coords += unravel_ndim;
+ indices += indices_stride;
+ }
+
+ return NPY_SUCCEED;
+}
+
+/* Fortran-order inner loop for unravel_index */
+static int
+unravel_index_loop_forder(int unravel_ndim, npy_intp *unravel_dims,
+ npy_intp unravel_size, npy_intp count,
+ char *indices, npy_intp indices_stride,
+ npy_intp *coords)
+{
+ int i;
+ npy_intp val;
+
+ while (count--) {
+ val = *(npy_intp *)indices;
+ if (val < 0 || val >= unravel_size) {
+ PyErr_SetString(PyExc_ValueError,
+ "invalid entry in index array");
+ return NPY_FAIL;
+ }
+ for (i = 0; i < unravel_ndim; ++i) {
+ *coords++ = val % unravel_dims[i];
+ val /= unravel_dims[i];
+ }
+ indices += indices_stride;
+ }
+
+ return NPY_SUCCEED;
+}
+
+/* unravel_index implementation - see add_newdocs.py */
+static PyObject *
+arr_unravel_index(PyObject *self, PyObject *args, PyObject *kwds)
+{
+ PyObject *indices0 = NULL, *ret_tuple = NULL;
+ PyArrayObject *ret_arr = NULL;
+ PyArrayObject *indices = NULL;
+ PyArray_Descr *dtype = NULL;
+ PyArray_Dims dimensions={0,0};
+ PyArray_ORDER order = PyArray_CORDER;
+ npy_intp unravel_size;
+
+ NpyIter *iter = NULL;
+ int i, ret_ndim;
+ npy_intp ret_dims[NPY_MAXDIMS], ret_strides[NPY_MAXDIMS];
+
+ char *kwlist[] = {"indices", "dims", "order", NULL};
+
+ if(!PyArg_ParseTupleAndKeywords(args, kwds, "OO&|O&:unravel_index",
+ kwlist,
+ &indices0,
+ PyArray_IntpConverter, &dimensions,
+ PyArray_OrderConverter, &order)) {
+ goto fail;
+ }
+
+ if (dimensions.len == 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "dims must have at least one value");
+ goto fail;
+ }
+
+ unravel_size = PyArray_MultiplyList(dimensions.ptr, dimensions.len);
+
+ if(!PyArray_Check(indices0)) {
+ indices = (PyArrayObject*)PyArray_FromAny(indices0,
+ NULL, 0, 0, 0, NULL);
+ if(indices == NULL) {
+ goto fail;
+ }
+ }
+ else {
+ indices = (PyArrayObject *)indices0;
+ Py_INCREF(indices);
+ }
+
+ dtype = PyArray_DescrFromType(NPY_INTP);
+ if (dtype == NULL) {
+ goto fail;
+ }
+
+ iter = NpyIter_New(indices, NPY_ITER_READONLY|
+ NPY_ITER_ALIGNED|
+ NPY_ITER_BUFFERED|
+ NPY_ITER_ZEROSIZE_OK|
+ NPY_ITER_DONT_NEGATE_STRIDES|
+ NPY_ITER_COORDS,
+ NPY_KEEPORDER, NPY_SAME_KIND_CASTING,
+ dtype, 0, NULL, 0);
+ if (iter == NULL) {
+ goto fail;
+ }
+
+ /*
+ * Create the return array with a layout compatible with the indices
+ * and with a dimension added to the end for the coordinates
+ */
+ ret_ndim = PyArray_NDIM(indices) + 1;
+ if (NpyIter_GetShape(iter, ret_dims) != NPY_SUCCEED) {
+ goto fail;
+ }
+ ret_dims[ret_ndim-1] = dimensions.len;
+ if (NpyIter_CreateCompatibleStrides(iter,
+ dimensions.len*sizeof(npy_intp), ret_strides) != NPY_SUCCEED) {
+ goto fail;
+ }
+ ret_strides[ret_ndim-1] = sizeof(npy_intp);
+
+ /* Remove the coords and inner loop */
+ if (NpyIter_RemoveCoords(iter) != NPY_SUCCEED) {
+ goto fail;
+ }
+ if (NpyIter_RemoveInnerLoop(iter) != NPY_SUCCEED) {
+ goto fail;
+ }
+
+ ret_arr = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, dtype,
+ ret_ndim, ret_dims, ret_strides, NULL, 0, NULL);
+ dtype = NULL;
+ if (ret_arr == NULL) {
+ goto fail;
+ }
+
+ if (order == NPY_CORDER) {
+ if (NpyIter_GetIterSize(iter) != 0) {
+ NpyIter_IterNextFunc *iternext;
+ char **dataptr;
+ npy_intp *strides;
+ npy_intp *countptr, count;
+ npy_intp *coordsptr = (npy_intp *)PyArray_DATA(ret_arr);
+
+ iternext = NpyIter_GetIterNext(iter, NULL);
+ if (iternext == NULL) {
+ goto fail;
+ }
+ dataptr = NpyIter_GetDataPtrArray(iter);
+ strides = NpyIter_GetInnerStrideArray(iter);
+ countptr = NpyIter_GetInnerLoopSizePtr(iter);
+
+ do {
+ count = *countptr;
+ if (unravel_index_loop_corder(dimensions.len, dimensions.ptr,
+ unravel_size, count, *dataptr, *strides,
+ coordsptr) != NPY_SUCCEED) {
+ goto fail;
+ }
+ coordsptr += count*dimensions.len;
+ } while(iternext(iter));
+ }
+ }
+ else if (order == NPY_FORTRANORDER) {
+ if (NpyIter_GetIterSize(iter) != 0) {
+ NpyIter_IterNextFunc *iternext;
+ char **dataptr;
+ npy_intp *strides;
+ npy_intp *countptr, count;
+ npy_intp *coordsptr = (npy_intp *)PyArray_DATA(ret_arr);
+
+ iternext = NpyIter_GetIterNext(iter, NULL);
+ if (iternext == NULL) {
+ goto fail;
+ }
+ dataptr = NpyIter_GetDataPtrArray(iter);
+ strides = NpyIter_GetInnerStrideArray(iter);
+ countptr = NpyIter_GetInnerLoopSizePtr(iter);
+
+ do {
+ count = *countptr;
+ if (unravel_index_loop_forder(dimensions.len, dimensions.ptr,
+ unravel_size, count, *dataptr, *strides,
+ coordsptr) != NPY_SUCCEED) {
+ goto fail;
+ }
+ coordsptr += count*dimensions.len;
+ } while(iternext(iter));
+ }
+ }
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "only 'C' or 'F' order is permitted");
+ goto fail;
+ }
+
+ /* Now make a tuple of views, one per coordinate */
+ ret_tuple = PyTuple_New(dimensions.len);
+ if (ret_tuple == NULL) {
+ goto fail;
+ }
+ for (i = 0; i < dimensions.len; ++i) {
+ PyArrayObject *view;
+
+ view = (PyArrayObject *)PyArray_New(&PyArray_Type, ret_ndim-1,
+ ret_dims, NPY_INTP,
+ ret_strides,
+ PyArray_BYTES(ret_arr) + i*sizeof(npy_intp),
+ 0, 0, NULL);
+ if (view == NULL) {
+ goto fail;
+ }
+ Py_INCREF(ret_arr);
+ view->base = (PyObject *)ret_arr;
+ PyTuple_SET_ITEM(ret_tuple, i, PyArray_Return(view));
+ }
+
+ Py_DECREF(ret_arr);
+ Py_XDECREF(indices);
+ PyDimMem_FREE(dimensions.ptr);
+ NpyIter_Deallocate(iter);
+
+ return ret_tuple;
+
+fail:
+ Py_XDECREF(ret_tuple);
+ Py_XDECREF(ret_arr);
+ Py_XDECREF(dtype);
+ Py_XDECREF(indices);
+ if (dimensions.ptr) {
+ PyDimMem_FREE(dimensions.ptr);
+ }
+ if (iter != NULL) {
+ NpyIter_Deallocate(iter);
+ }
+ return NULL;
+}
static PyTypeObject *PyMemberDescr_TypePtr = NULL;
@@ -889,6 +1401,7 @@ io_unpack(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
return pack_or_unpack_bits(obj, axis, 1);
}
+/* The docstrings for many of these methods are in add_newdocs.py. */
static struct PyMethodDef methods[] = {
{"_insert", (PyCFunction)arr_insert,
METH_VARARGS | METH_KEYWORDS, arr_insert__doc__},
@@ -898,6 +1411,10 @@ static struct PyMethodDef methods[] = {
METH_VARARGS | METH_KEYWORDS, NULL},
{"interp", (PyCFunction)arr_interp,
METH_VARARGS | METH_KEYWORDS, NULL},
+ {"ravel_coords", (PyCFunction)arr_ravel_coords,
+ METH_VARARGS | METH_KEYWORDS, NULL},
+ {"unravel_index", (PyCFunction)arr_unravel_index,
+ METH_VARARGS | METH_KEYWORDS, NULL},
{"add_docstring", (PyCFunction)arr_add_docstring,
METH_VARARGS, NULL},
{"packbits", (PyCFunction)io_pack,
diff --git a/numpy/lib/tests/test__datasource.py b/numpy/lib/tests/test__datasource.py
index 29dbb7ae5..ed5af516f 100644
--- a/numpy/lib/tests/test__datasource.py
+++ b/numpy/lib/tests/test__datasource.py
@@ -83,7 +83,9 @@ class TestDataSourceOpen(TestCase):
del self.ds
def test_ValidHTTP(self):
- assert self.ds.open(valid_httpurl())
+ fh = self.ds.open(valid_httpurl())
+ assert_(fh)
+ fh.close()
def test_InvalidHTTP(self):
url = invalid_httpurl()
@@ -92,14 +94,16 @@ class TestDataSourceOpen(TestCase):
self.ds.open(url)
except IOError, e:
# Regression test for bug fixed in r4342.
- assert e.errno is None
+ assert_(e.errno is None)
def test_InvalidHTTPCacheURLError(self):
self.assertRaises(URLError, self.ds._cache, invalid_httpurl())
def test_ValidFile(self):
local_file = valid_textfile(self.tmpdir)
- assert self.ds.open(local_file)
+ fh = self.ds.open(local_file)
+ assert_(fh)
+ fh.close()
def test_InvalidFile(self):
invalid_file = invalid_textfile(self.tmpdir)
@@ -150,7 +154,7 @@ class TestDataSourceExists(TestCase):
del self.ds
def test_ValidHTTP(self):
- assert self.ds.exists(valid_httpurl())
+ assert_(self.ds.exists(valid_httpurl()))
def test_InvalidHTTP(self):
self.assertEqual(self.ds.exists(invalid_httpurl()), False)
@@ -158,11 +162,11 @@ class TestDataSourceExists(TestCase):
def test_ValidFile(self):
# Test valid file in destpath
tmpfile = valid_textfile(self.tmpdir)
- assert self.ds.exists(tmpfile)
+ assert_(self.ds.exists(tmpfile))
# Test valid local file not in destpath
localdir = mkdtemp()
tmpfile = valid_textfile(localdir)
- assert self.ds.exists(tmpfile)
+ assert_(self.ds.exists(tmpfile))
rmtree(localdir)
def test_InvalidFile(self):
@@ -214,13 +218,13 @@ class TestDataSourceAbspath(TestCase):
tmp_path = lambda x: os.path.abspath(self.ds.abspath(x))
- assert tmp_path(valid_httpurl()).startswith(self.tmpdir)
- assert tmp_path(invalid_httpurl()).startswith(self.tmpdir)
- assert tmp_path(tmpfile).startswith(self.tmpdir)
- assert tmp_path(tmpfilename).startswith(self.tmpdir)
+ assert_(tmp_path(valid_httpurl()).startswith(self.tmpdir))
+ assert_(tmp_path(invalid_httpurl()).startswith(self.tmpdir))
+ assert_(tmp_path(tmpfile).startswith(self.tmpdir))
+ assert_(tmp_path(tmpfilename).startswith(self.tmpdir))
for fn in malicious_files:
- assert tmp_path(http_path+fn).startswith(self.tmpdir)
- assert tmp_path(fn).startswith(self.tmpdir)
+ assert_(tmp_path(http_path+fn).startswith(self.tmpdir))
+ assert_(tmp_path(fn).startswith(self.tmpdir))
def test_windows_os_sep(self):
orig_os_sep = os.sep
@@ -253,10 +257,10 @@ class TestRepositoryAbspath(TestCase):
def test_sandboxing(self):
tmp_path = lambda x: os.path.abspath(self.repos.abspath(x))
- assert tmp_path(valid_httpfile()).startswith(self.tmpdir)
+ assert_(tmp_path(valid_httpfile()).startswith(self.tmpdir))
for fn in malicious_files:
- assert tmp_path(http_path+fn).startswith(self.tmpdir)
- assert tmp_path(fn).startswith(self.tmpdir)
+ assert_(tmp_path(http_path+fn).startswith(self.tmpdir))
+ assert_(tmp_path(fn).startswith(self.tmpdir))
def test_windows_os_sep(self):
orig_os_sep = os.sep
@@ -280,14 +284,14 @@ class TestRepositoryExists(TestCase):
def test_ValidFile(self):
# Create local temp file
tmpfile = valid_textfile(self.tmpdir)
- assert self.repos.exists(tmpfile)
+ assert_(self.repos.exists(tmpfile))
def test_InvalidFile(self):
tmpfile = invalid_textfile(self.tmpdir)
self.assertEqual(self.repos.exists(tmpfile), False)
def test_RemoveHTTPFile(self):
- assert self.repos.exists(valid_httpurl())
+ assert_(self.repos.exists(valid_httpurl()))
def test_CachedHTTPFile(self):
localfile = valid_httpurl()
@@ -298,7 +302,7 @@ class TestRepositoryExists(TestCase):
local_path = os.path.join(self.repos._destpath, netloc)
os.mkdir(local_path, 0700)
tmpfile = valid_textfile(local_path)
- assert self.repos.exists(tmpfile)
+ assert_(self.repos.exists(tmpfile))
class TestOpenFunc(TestCase):
def setUp(self):
@@ -310,9 +314,13 @@ class TestOpenFunc(TestCase):
def test_DataSourceOpen(self):
local_file = valid_textfile(self.tmpdir)
# Test case where destpath is passed in
- assert datasource.open(local_file, destpath=self.tmpdir)
+ fp = datasource.open(local_file, destpath=self.tmpdir)
+ assert_(fp)
+ fp.close()
# Test case where default destpath is used
- assert datasource.open(local_file)
+ fp = datasource.open(local_file)
+ assert_(fp)
+ fp.close()
if __name__ == "__main__":
diff --git a/numpy/lib/tests/test_arraysetops.py b/numpy/lib/tests/test_arraysetops.py
index dac39cd50..907a27a8c 100644
--- a/numpy/lib/tests/test_arraysetops.py
+++ b/numpy/lib/tests/test_arraysetops.py
@@ -17,7 +17,7 @@ class TestAso(TestCase):
assert_array_equal( c, ec )
vals, indices = unique( a, return_index=True )
-
+
ed = np.array( [2, 3, 0, 1] )
assert_array_equal(vals, ec)
@@ -25,7 +25,7 @@ class TestAso(TestCase):
vals, ind0, ind1 = unique( a, return_index=True,
return_inverse=True )
-
+
ee = np.array( [2, 3, 0, 1, 0, 2, 3] )
assert_array_equal(vals, ec)
@@ -53,21 +53,6 @@ class TestAso(TestCase):
assert_array_equal([], intersect1d([],[]))
- def test_intersect1d_nu( self ):
- # This should be removed when intersect1d_nu is removed.
- a = np.array( [5, 5, 7, 1, 2] )
- b = np.array( [2, 1, 4, 3, 3, 1, 5] )
-
- ec = np.array( [1, 2, 5] )
- warnings.filterwarnings('ignore', message='\s*`intersect1d_nu` is deprecated!')
- warnings.filterwarnings('ignore', message='\s*`unique1d` is deprecated!')
- c = intersect1d_nu( a, b )
- assert_array_equal( c, ec )
- assert_array_equal([], intersect1d_nu([],[]))
- warnings.filters.pop(0)
- warnings.filters.pop(0)
-
-
def test_setxor1d( self ):
a = np.array( [5, 7, 1, 2] )
b = np.array( [2, 4, 3, 1, 5] )
@@ -104,30 +89,6 @@ class TestAso(TestCase):
assert_array_equal([],ediff1d(one_elem))
assert_array_equal([1],ediff1d(two_elem))
- def test_setmember1d( self ):
- # This should be removed when setmember1d is removed.
- a = np.array( [5, 7, 1, 2] )
- b = np.array( [2, 4, 3, 1, 5] )
-
- ec = np.array( [True, False, True, True] )
- warnings.filterwarnings('ignore', '\s*`setmember1d` is deprecated!')
- c = setmember1d( a, b )
-
- assert_array_equal( c, ec )
-
- a[0] = 8
- ec = np.array( [False, False, True, True] )
- c = setmember1d( a, b )
- assert_array_equal( c, ec )
-
- a[0], a[3] = 4, 8
- ec = np.array( [True, False, True, False] )
- c = setmember1d( a, b )
- assert_array_equal( c, ec )
-
- assert_array_equal([], setmember1d([],[]))
- warnings.filters.pop(0)
-
def test_in1d(self):
a = np.array( [5, 7, 1, 2] )
b = np.array( [2, 4, 3, 1, 5] )
@@ -145,7 +106,7 @@ class TestAso(TestCase):
ec = np.array( [True, False, True, False] )
c = in1d( a, b, assume_unique=True )
assert_array_equal( c, ec )
-
+
a = np.array([5,4,5,3,4,4,3,4,3,5,2,1,5,5])
b = [2,3,4]
diff --git a/numpy/lib/tests/test_format.py b/numpy/lib/tests/test_format.py
index 2e6935141..ff8e93704 100644
--- a/numpy/lib/tests/test_format.py
+++ b/numpy/lib/tests/test_format.py
@@ -463,7 +463,7 @@ def test_memmap_roundtrip():
# Check that reading the file using memmap works.
ma = format.open_memmap(nfn, mode='r')
#yield assert_array_equal, ma, arr
- #del ma
+ del ma
def test_write_version_1_0():
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index 4df13e5f9..13930c79e 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -13,13 +13,13 @@ class TestAny(TestCase):
y1 = [0, 0, 1, 0]
y2 = [0, 0, 0, 0]
y3 = [1, 0, 1, 0]
- assert(any(y1))
- assert(any(y3))
- assert(not any(y2))
+ assert_(any(y1))
+ assert_(any(y3))
+ assert_(not any(y2))
def test_nd(self):
y1 = [[0, 0, 0], [0, 1, 0], [1, 1, 0]]
- assert(any(y1))
+ assert_(any(y1))
assert_array_equal(sometrue(y1, axis=0), [1, 1, 0])
assert_array_equal(sometrue(y1, axis=1), [0, 1, 1])
@@ -29,14 +29,14 @@ class TestAll(TestCase):
y1 = [0, 1, 1, 0]
y2 = [0, 0, 0, 0]
y3 = [1, 1, 1, 1]
- assert(not all(y1))
- assert(all(y3))
- assert(not all(y2))
- assert(all(~array(y2)))
+ assert_(not all(y1))
+ assert_(all(y3))
+ assert_(not all(y2))
+ assert_(all(~array(y2)))
def test_nd(self):
y1 = [[0, 0, 1], [0, 1, 1], [1, 1, 1]]
- assert(not all(y1))
+ assert_(not all(y1))
assert_array_equal(alltrue(y1, axis=0), [0, 0, 1])
assert_array_equal(alltrue(y1, axis=1), [0, 0, 1])
@@ -44,11 +44,11 @@ class TestAll(TestCase):
class TestAverage(TestCase):
def test_basic(self):
y1 = array([1, 2, 3])
- assert(average(y1, axis=0) == 2.)
+ assert_(average(y1, axis=0) == 2.)
y2 = array([1., 2., 3.])
- assert(average(y2, axis=0) == 2.)
+ assert_(average(y2, axis=0) == 2.)
y3 = [0., 0., 0.]
- assert(average(y3, axis=0) == 0.)
+ assert_(average(y3, axis=0) == 0.)
y4 = ones((4, 4))
y4[0, 1] = 0
@@ -407,7 +407,7 @@ class TestDigitize(TestCase):
def test_random(self):
x = rand(10)
bin = linspace(x.min(), x.max(), 10)
- assert all(digitize(x, bin) != 0)
+ assert_(all(digitize(x, bin) != 0))
class TestUnwrap(TestCase):
@@ -415,7 +415,7 @@ class TestUnwrap(TestCase):
#check that unwrap removes jumps greather that 2*pi
assert_array_equal(unwrap([1, 1 + 2 * pi]), [1, 1])
#check that unwrap maintans continuity
- assert(all(diff(unwrap(rand(10) * 100)) < pi))
+ assert_(all(diff(unwrap(rand(10) * 100)) < pi))
class TestFilterwindows(TestCase):
@@ -520,7 +520,7 @@ class TestTrapz(TestCase):
class TestSinc(TestCase):
def test_simple(self):
- assert(sinc(0) == 1)
+ assert_(sinc(0) == 1)
w = sinc(linspace(-1, 1, 100))
#check symmetry
assert_array_almost_equal(w, flipud(w), 7)
@@ -565,7 +565,7 @@ class TestHistogram(TestCase):
area = sum(a * diff(b))
assert_almost_equal(area, 1)
- warnings.filterwarnings('ignore',
+ warnings.filterwarnings('ignore',
message="\s*This release of NumPy fixes a normalization bug")
# Check with non-constant bin widths
v = np.arange(10)
@@ -573,20 +573,20 @@ class TestHistogram(TestCase):
a, b = histogram(v, bins, normed=True)
assert_array_equal(a, .1)
assert_equal(sum(a*diff(b)), 1)
-
+
# Variale bin widths are especially useful to deal with
# infinities.
v = np.arange(10)
bins = [0,1,3,6,np.inf]
a, b = histogram(v, bins, normed=True)
assert_array_equal(a, [.1,.1,.1,0.])
-
+
# Taken from a bug report from N. Becker on the numpy-discussion
- # mailing list Aug. 6, 2010.
+ # mailing list Aug. 6, 2010.
counts, dmy = np.histogram([1,2,3,4], [0.5,1.5,np.inf], normed=True)
assert_equal(counts, [.25, 0])
warnings.filters.pop(0)
-
+
def test_outliers(self):
# Check that outliers are not tallied
a = arange(10) + .5
@@ -615,16 +615,16 @@ class TestHistogram(TestCase):
# Check the type of the returned histogram
a = arange(10) + .5
h, b = histogram(a)
- assert(issubdtype(h.dtype, int))
+ assert_(issubdtype(h.dtype, int))
h, b = histogram(a, normed=True)
- assert(issubdtype(h.dtype, float))
+ assert_(issubdtype(h.dtype, float))
h, b = histogram(a, weights=ones(10, int))
- assert(issubdtype(h.dtype, int))
+ assert_(issubdtype(h.dtype, int))
h, b = histogram(a, weights=ones(10, float))
- assert(issubdtype(h.dtype, float))
+ assert_(issubdtype(h.dtype, float))
def test_weights(self):
v = rand(100)
@@ -655,7 +655,7 @@ class TestHistogram(TestCase):
weights=[2,1,1,1,1,1,1,1,1], normed=True)
assert_almost_equal(a, [.2, .1, .1, .075])
warnings.filters.pop(0)
-
+
class TestHistogramdd(TestCase):
def test_simple(self):
@@ -668,7 +668,7 @@ class TestHistogramdd(TestCase):
# Check normalization
ed = [[-2, 0, 2], [0, 1, 2, 3], [0, 1, 2, 3]]
H, edges = histogramdd(x, bins=ed, normed=True)
- assert(all(H == answer / 12.))
+ assert_(all(H == answer / 12.))
# Check that H has the correct shape.
H, edges = histogramdd(x, (2, 3, 4), range=[[-1, 1], [0, 3], [0, 4]],
normed=True)
@@ -697,7 +697,7 @@ class TestHistogramdd(TestCase):
r = rand(10, 3)
for b in bins:
H, edges = histogramdd(r, b)
- assert(H.shape == b)
+ assert_(H.shape == b)
def test_shape_4d(self):
# All possible permutations for bins of different lengths in 4D.
@@ -711,7 +711,7 @@ class TestHistogramdd(TestCase):
r = rand(10, 4)
for b in bins:
H, edges = histogramdd(r, b)
- assert(H.shape == b)
+ assert_(H.shape == b)
def test_weights(self):
v = rand(100, 2)
@@ -733,12 +733,12 @@ class TestHistogramdd(TestCase):
class TestUnique(TestCase):
def test_simple(self):
x = array([4, 3, 2, 1, 1, 2, 3, 4, 0])
- assert(all(unique(x) == [0, 1, 2, 3, 4]))
- assert(unique(array([1, 1, 1, 1, 1])) == array([1]))
+ assert_(all(unique(x) == [0, 1, 2, 3, 4]))
+ assert_(unique(array([1, 1, 1, 1, 1])) == array([1]))
x = ['widget', 'ham', 'foo', 'bar', 'foo', 'ham']
- assert(all(unique(x) == ['bar', 'foo', 'ham', 'widget']))
+ assert_(all(unique(x) == ['bar', 'foo', 'ham', 'widget']))
x = array([5 + 6j, 1 + 1j, 1 + 10j, 10, 5 + 6j])
- assert(all(unique(x) == [1 + 1j, 1 + 10j, 5 + 6j, 10]))
+ assert_(all(unique(x) == [1 + 1j, 1 + 10j, 5 + 6j, 10]))
class TestCheckFinite(TestCase):
@@ -792,7 +792,7 @@ class TestNaNFuncts(TestCase):
array([[ 0.01319214, 0.11704017, 0.1630199 ],
[ 0.37910852, 0.87964135, 0.34306596],
[ 0.72687499, 0.23913896, 0.33850425]]))
- assert nanmin([nan, nan]) is nan
+ assert_(np.isnan(nanmin([nan, nan])))
def test_nanargmin(self):
assert_almost_equal(nanargmin(self.A), 1)
@@ -823,6 +823,7 @@ class TestNaNFuncts(TestCase):
array([[ 0.01620964, 0.75157887, 0.28333658],
[ 0.59541557, 0.87964135, 0.70543747],
[ 0.91084584, 0.84386844, 0.37068164]]))
+ assert_(np.isnan(nanmax([nan, nan])))
def test_nanmin_allnan_on_axis(self):
assert_array_equal(isnan(nanmin([[nan] * 2] * 3, axis=1)),
@@ -923,7 +924,7 @@ class Test_i0(TestCase):
class TestKaiser(TestCase):
def test_simple(self):
assert_almost_equal(kaiser(0, 1.0), array([]))
- assert isfinite(kaiser(1, 1.0))
+ assert_(isfinite(kaiser(1, 1.0)))
assert_almost_equal(kaiser(2, 1.0), array([ 0.78984831, 0.78984831]))
assert_almost_equal(kaiser(5, 1.0),
array([ 0.78984831, 0.94503323, 1. ,
@@ -950,14 +951,14 @@ class TestMsort(TestCase):
class TestMeshgrid(TestCase):
def test_simple(self):
[X, Y] = meshgrid([1, 2, 3], [4, 5, 6, 7])
- assert all(X == array([[1, 2, 3],
+ assert_(all(X == array([[1, 2, 3],
[1, 2, 3],
[1, 2, 3],
- [1, 2, 3]]))
- assert all(Y == array([[4, 4, 4],
+ [1, 2, 3]])))
+ assert_(all(Y == array([[4, 4, 4],
[5, 5, 5],
[6, 6, 6],
- [7, 7, 7]]))
+ [7, 7, 7]])))
class TestPiecewise(TestCase):
@@ -1001,8 +1002,8 @@ class TestPiecewise(TestCase):
def test_0d(self):
x = array(3)
y = piecewise(x, x > 3, [4, 0])
- assert y.ndim == 0
- assert y == 0
+ assert_(y.ndim == 0)
+ assert_(y == 0)
class TestBincount(TestCase):
@@ -1026,6 +1027,21 @@ class TestBincount(TestCase):
y = np.bincount(x, w)
assert_array_equal(y, np.array([0, 0.2, 0.5, 0, 0.5, 0.1]))
+ def test_with_minlength(self):
+ x = np.array([0, 1, 0, 1, 1])
+ y = np.bincount(x, minlength=3)
+ assert_array_equal(y, np.array([2, 3, 0]))
+
+ def test_with_minlength_smaller_than_maxvalue(self):
+ x = np.array([0, 1, 1, 2, 2, 3, 3])
+ y = np.bincount(x, minlength=2)
+ assert_array_equal(y, np.array([1, 2, 2, 2]))
+
+ def test_with_minlength_and_weights(self):
+ x = np.array([1, 2, 4, 5, 2])
+ w = np.array([0.2, 0.3, 0.5, 0.1, 0.2])
+ y = np.bincount(x, w, 8)
+ assert_array_equal(y, np.array([0, 0.2, 0.5, 0, 0.5, 0.1, 0, 0]))
class TestInterp(TestCase):
def test_exceptions(self):
diff --git a/numpy/lib/tests/test_index_tricks.py b/numpy/lib/tests/test_index_tricks.py
index c17ee5d6a..40f75936e 100644
--- a/numpy/lib/tests/test_index_tricks.py
+++ b/numpy/lib/tests/test_index_tricks.py
@@ -4,12 +4,69 @@ from numpy import ( array, ones, r_, mgrid, unravel_index, zeros, where,
ndenumerate, fill_diagonal, diag_indices,
diag_indices_from, s_, index_exp )
-class TestUnravelIndex(TestCase):
+class TestRavelUnravelIndex(TestCase):
def test_basic(self):
- assert unravel_index(2,(2,2)) == (1,0)
- assert unravel_index(254,(17,94)) == (2, 66)
- assert_raises(ValueError, unravel_index, 4,(2,2))
-
+ assert_equal(np.unravel_index(2,(2,2)), (1,0))
+ assert_equal(np.ravel_coords((1,0),(2,2)), 2)
+ assert_equal(np.unravel_index(254,(17,94)), (2,66))
+ assert_equal(np.ravel_coords((2,66),(17,94)), 254)
+ assert_raises(ValueError, np.unravel_index, -1, (2,2))
+ assert_raises(TypeError, np.unravel_index, 0.5, (2,2))
+ assert_raises(ValueError, np.unravel_index, 4, (2,2))
+ assert_raises(ValueError, np.ravel_coords, (-3,1), (2,2))
+ assert_raises(ValueError, np.ravel_coords, (2,1), (2,2))
+ assert_raises(ValueError, np.ravel_coords, (0,-3), (2,2))
+ assert_raises(ValueError, np.ravel_coords, (0,2), (2,2))
+ assert_raises(TypeError, np.ravel_coords, (0.1,0.), (2,2))
+
+ assert_equal(np.unravel_index((2*3 + 1)*6 + 4, (4,3,6)), [2,1,4])
+ assert_equal(np.ravel_coords([2,1,4], (4,3,6)), (2*3 + 1)*6 + 4)
+
+ arr = np.array([[3,6,6],[4,5,1]])
+ assert_equal(np.ravel_coords(arr, (7,6)), [22,41,37])
+ assert_equal(np.ravel_coords(arr, (7,6), order='F'), [31,41,13])
+ assert_equal(np.ravel_coords(arr, (4,6), mode='clip'), [22,23,19])
+ assert_equal(np.ravel_coords(arr, (4,4), mode=('clip','wrap')),
+ [12,13,13])
+ assert_equal(np.ravel_coords((3,1,4,1), (6,7,8,9)), 1621)
+
+ assert_equal(np.unravel_index(np.array([22, 41, 37]), (7,6)),
+ [[3, 6, 6],[4, 5, 1]])
+ assert_equal(np.unravel_index(np.array([31, 41, 13]), (7,6), order='F'),
+ [[3, 6, 6], [4, 5, 1]])
+ assert_equal(np.unravel_index(1621, (6,7,8,9)), [3,1,4,1])
+
+ def test_dtypes(self):
+ # Test with different data types
+ for dtype in [np.int16, np.uint16, np.int32,
+ np.uint32, np.int64, np.uint64]:
+ coords = np.array([[1,0,1,2,3,4],[1,6,1,3,2,0]], dtype=dtype)
+ shape = (5,8)
+ uncoords = 8*coords[0]+coords[1]
+ assert_equal(np.ravel_coords(coords, shape), uncoords)
+ assert_equal(coords, np.unravel_index(uncoords, shape))
+ uncoords = coords[0]+5*coords[1]
+ assert_equal(np.ravel_coords(coords, shape, order='F'), uncoords)
+ assert_equal(coords, np.unravel_index(uncoords, shape, order='F'))
+
+ coords = np.array([[1,0,1,2,3,4],[1,6,1,3,2,0],[1,3,1,0,9,5]],
+ dtype=dtype)
+ shape = (5,8,10)
+ uncoords = 10*(8*coords[0]+coords[1])+coords[2]
+ assert_equal(np.ravel_coords(coords, shape), uncoords)
+ assert_equal(coords, np.unravel_index(uncoords, shape))
+ uncoords = coords[0]+5*(coords[1]+8*coords[2])
+ assert_equal(np.ravel_coords(coords, shape, order='F'), uncoords)
+ assert_equal(coords, np.unravel_index(uncoords, shape, order='F'))
+
+ def test_clipmodes(self):
+ # Test clipmodes
+ assert_equal(np.ravel_coords([5,1,-1,2], (4,3,7,12), mode='wrap'),
+ np.ravel_coords([1,1,6,2], (4,3,7,12)))
+ assert_equal(np.ravel_coords([5,1,-1,2], (4,3,7,12),
+ mode=('wrap','raise','clip','raise')),
+ np.ravel_coords([1,1,0,2], (4,3,7,12)))
+ assert_raises(ValueError, np.ravel_coords, [5,1,-1,2], (4,3,7,12))
class TestGrid(TestCase):
def test_basic(self):
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index a85b01909..5001f6bac 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -381,6 +381,15 @@ class TestLoadTxt(TestCase):
dtype=dt)
assert_array_equal(x, a)
+ def test_3d_shaped_dtype(self):
+ c = StringIO("aaaa 1.0 8.0 1 2 3 4 5 6 7 8 9 10 11 12")
+ dt = np.dtype([('name', 'S4'), ('x', float), ('y', float),
+ ('block', int, (2, 2, 3))])
+ x = np.loadtxt(c, dtype=dt)
+ a = np.array([('aaaa', 1.0, 8.0, [[[1, 2, 3], [4, 5, 6]],[[7, 8, 9], [10, 11, 12]]])],
+ dtype=dt)
+ assert_array_equal(x, a)
+
def test_empty_file(self):
c = StringIO()
assert_raises(IOError, np.loadtxt, c)
@@ -884,7 +893,6 @@ M 33 21.99
dtype=dt)
assert_array_equal(x, a)
-
def test_withmissing(self):
data = StringIO('A,B\n0,1\n2,N/A')
kwargs = dict(delimiter=",", missing_values="N/A", names=True)
@@ -1042,7 +1050,7 @@ M 33 21.99
converters = {4: lambda x:"(%s)" % x}
kwargs = dict(delimiter=",", converters=converters,
dtype=[(_, int) for _ in 'abcde'],)
- assert_raises(TypeError, np.genfromtxt, mdata, **kwargs)
+ assert_raises(ValueError, np.genfromtxt, mdata, **kwargs)
def test_default_field_format(self):
diff --git a/numpy/lib/tests/test_polynomial.py b/numpy/lib/tests/test_polynomial.py
index 227413c19..2dbffa0b8 100644
--- a/numpy/lib/tests/test_polynomial.py
+++ b/numpy/lib/tests/test_polynomial.py
@@ -1,23 +1,20 @@
"""
->>> import numpy.core as nx
->>> from numpy.lib.polynomial import poly1d, polydiv
-
->>> p = poly1d([1.,2,3])
+>>> p = np.poly1d([1.,2,3])
>>> p
poly1d([ 1., 2., 3.])
>>> print(p)
2
1 x + 2 x + 3
->>> q = poly1d([3.,2,1])
+>>> q = np.poly1d([3.,2,1])
>>> q
poly1d([ 3., 2., 1.])
>>> print(q)
2
3 x + 2 x + 1
->>> print(poly1d([1.89999+2j, -3j, -5.12345678, 2+1j]))
+>>> print(np.poly1d([1.89999+2j, -3j, -5.12345678, 2+1j]))
3 2
(1.9 + 2j) x - 3j x - 5.123 x + (2 + 1j)
->>> print(poly1d([-3, -2, -1]))
+>>> print(np.poly1d([-3, -2, -1]))
2
-3 x - 2 x - 1
@@ -46,7 +43,7 @@ poly1d([ 9., 12., 16., 8., 6.])
>>> q(p)
poly1d([ 3., 12., 32., 40., 34.])
->>> nx.asarray(p)
+>>> np.asarray(p)
array([ 1., 2., 3.])
>>> len(p)
2
@@ -66,16 +63,16 @@ poly1d([ 2., 2.])
>>> p.deriv(2)
poly1d([ 2.])
->>> q = poly1d([1.,2,3], variable='y')
+>>> q = np.poly1d([1.,2,3], variable='y')
>>> print(q)
2
1 y + 2 y + 3
->>> q = poly1d([1.,2,3], variable='lambda')
+>>> q = np.poly1d([1.,2,3], variable='lambda')
>>> print(q)
2
1 lambda + 2 lambda + 3
->>> polydiv(poly1d([1,0,-1]), poly1d([1,1]))
+>>> np.polydiv(np.poly1d([1,0,-1]), np.poly1d([1,1]))
(poly1d([ 1., -1.]), poly1d([ 0.]))
"""
diff --git a/numpy/lib/tests/test_recfunctions.py b/numpy/lib/tests/test_recfunctions.py
index 0a22e2a34..14af43a59 100644
--- a/numpy/lib/tests/test_recfunctions.py
+++ b/numpy/lib/tests/test_recfunctions.py
@@ -540,13 +540,17 @@ class TestStackArrays(TestCase):
class TestJoinBy(TestCase):
+ def setUp(self):
+ self.a = np.array(zip(np.arange(10), np.arange(50, 60),
+ np.arange(100, 110)),
+ dtype=[('a', int), ('b', int), ('c', int)])
+ self.b = np.array(zip(np.arange(5, 15), np.arange(65, 75),
+ np.arange(100, 110)),
+ dtype=[('a', int), ('b', int), ('d', int)])
#
- def test_base(self):
+ def test_inner_join(self):
"Basic test of join_by"
- a = np.array(zip(np.arange(10), np.arange(50, 60), np.arange(100, 110)),
- dtype=[('a', int), ('b', int), ('c', int)])
- b = np.array(zip(np.arange(5, 15), np.arange(65, 75), np.arange(100, 110)),
- dtype=[('a', int), ('b', int), ('d', int)])
+ a, b = self.a, self.b
#
test = join_by('a', a, b, jointype='inner')
control = np.array([(5, 55, 65, 105, 100), (6, 56, 66, 106, 101),
@@ -555,6 +559,9 @@ class TestJoinBy(TestCase):
dtype=[('a', int), ('b1', int), ('b2', int),
('c', int), ('d', int)])
assert_equal(test, control)
+
+ def test_join(self):
+ a, b = self.a, self.b
#
test = join_by(('a', 'b'), a, b)
control = np.array([(5, 55, 105, 100), (6, 56, 106, 101),
@@ -562,6 +569,9 @@ class TestJoinBy(TestCase):
(9, 59, 109, 104)],
dtype=[('a', int), ('b', int),
('c', int), ('d', int)])
+
+ def test_outer_join(self):
+ a, b = self.a, self.b
#
test = join_by(('a', 'b'), a, b, 'outer')
control = ma.array([(0, 50, 100, -1), (1, 51, 101, -1),
@@ -587,6 +597,9 @@ class TestJoinBy(TestCase):
dtype=[('a', int), ('b', int),
('c', int), ('d', int)])
assert_equal(test, control)
+
+ def test_leftouter_join(self):
+ a, b = self.a, self.b
#
test = join_by(('a', 'b'), a, b, 'leftouter')
control = ma.array([(0, 50, 100, -1), (1, 51, 101, -1),
diff --git a/numpy/lib/tests/test_regression.py b/numpy/lib/tests/test_regression.py
index a67355957..ea4d75f6b 100644
--- a/numpy/lib/tests/test_regression.py
+++ b/numpy/lib/tests/test_regression.py
@@ -70,8 +70,8 @@ class TestRegression(TestCase):
"""Ticket #554"""
x = np.poly1d([1,2,3])
y = np.poly1d([3,4])
- assert x != y
- assert x == x
+ assert_(x != y)
+ assert_(x == x)
def test_mem_insert(self, level=rlevel):
"""Ticket #572"""
@@ -152,34 +152,34 @@ class TestRegression(TestCase):
def test_void_coercion(self, level=rlevel):
dt = np.dtype([('a','f4'),('b','i4')])
x = np.zeros((1,),dt)
- assert(np.r_[x,x].dtype == dt)
+ assert_(np.r_[x,x].dtype == dt)
def test_who_with_0dim_array(self, level=rlevel) :
"""ticket #1243"""
import os, sys
+ oldstdout = sys.stdout
sys.stdout = open(os.devnull, 'w')
- try :
- tmp = np.who({'foo' : np.array(1)})
- sys.stdout = sys.__stdout__
- except :
- sys.stdout = sys.__stdout__
- raise AssertionError("ticket #1243")
+ try:
+ try:
+ tmp = np.who({'foo' : np.array(1)})
+ except:
+ raise AssertionError("ticket #1243")
+ finally:
+ sys.stdout = oldstdout
def test_bincount_empty(self):
"""Ticket #1387: empty array as input for bincount."""
assert_raises(ValueError, lambda : np.bincount(np.array([], dtype=np.intp)))
- @dec.deprecated()
def test_include_dirs(self):
"""As a sanity check, just test that get_include and
get_numarray_include include something reasonable. Somewhat
related to ticket #1405."""
- include_dirs = [np.get_include(), np.get_numarray_include(),
- np.get_numpy_include()]
+ include_dirs = [np.get_include(), np.get_numarray_include()]
for path in include_dirs:
- assert isinstance(path, (str, unicode))
- assert path != ''
+ assert_(isinstance(path, (str, unicode)))
+ assert_(path != '')
def test_polyder_return_type(self):
"""Ticket #1249"""
diff --git a/numpy/lib/tests/test_type_check.py b/numpy/lib/tests/test_type_check.py
index 888c60420..941768aa5 100644
--- a/numpy/lib/tests/test_type_check.py
+++ b/numpy/lib/tests/test_type_check.py
@@ -3,6 +3,13 @@ from numpy.lib import *
from numpy.core import *
from numpy.compat import asbytes
+try:
+ import ctypes
+ _HAS_CTYPE = True
+except ImportError:
+ _HAS_CTYPE = False
+
+
def assert_all(x):
assert(all(x)), x
@@ -375,9 +382,9 @@ class TestArrayConversion(TestCase):
assert_equal(a.__class__,ndarray)
assert issubdtype(a.dtype,float)
-
class TestDateTimeData:
+ @dec.skipif(not _HAS_CTYPE, "ctypes not available on this python installation")
def test_basic(self):
a = array(['1980-03-23'], dtype=datetime64)
assert_equal(datetime_data(a.dtype), (asbytes('us'), 1, 1, 1))
diff --git a/numpy/lib/tests/test_ufunclike.py b/numpy/lib/tests/test_ufunclike.py
index e9c41d09c..29b47f257 100644
--- a/numpy/lib/tests/test_ufunclike.py
+++ b/numpy/lib/tests/test_ufunclike.py
@@ -27,17 +27,6 @@ class TestUfunclike(TestCase):
assert_equal(res, tgt)
assert_equal(out, tgt)
- @deprecated()
- def test_log2(self):
- a = nx.array([4.5, 2.3, 6.5])
- out = nx.zeros(a.shape, float)
- tgt = nx.array([2.169925, 1.20163386, 2.70043972])
- res = ufl.log2(a)
- assert_almost_equal(res, tgt)
- res = ufl.log2(a, out)
- assert_almost_equal(res, tgt)
- assert_almost_equal(out, tgt)
-
def test_fix(self):
a = nx.array([[1.0, 1.1, 1.5, 1.8], [-1.0, -1.1, -1.5, -1.8]])
out = nx.zeros(a.shape, float)
@@ -64,7 +53,7 @@ class TestUfunclike(TestCase):
m = MyArray(a, metadata='foo')
f = ufl.fix(m)
assert_array_equal(f, nx.array([1,-1]))
- assert isinstance(f, MyArray)
+ assert_(isinstance(f, MyArray))
assert_equal(f.metadata, 'foo')
if __name__ == "__main__":
diff --git a/numpy/lib/ufunclike.py b/numpy/lib/ufunclike.py
index 8f81fe4b2..b51365f41 100644
--- a/numpy/lib/ufunclike.py
+++ b/numpy/lib/ufunclike.py
@@ -172,45 +172,3 @@ def isneginf(x, y=None):
y = nx.empty(x.shape, dtype=nx.bool_)
nx.logical_and(nx.isinf(x), nx.signbit(x), y)
return y
-
-
-_log2 = nx.log(2)
-def log2(x, y=None):
- """
- Return the base 2 logarithm of the input array, element-wise.
- This function is now deprecated, use the np.log2 ufunc instead.
-
- Parameters
- ----------
- x : array_like
- Input array.
- y : array_like
- Optional output array with the same shape as `x`.
-
- Returns
- -------
- y : ndarray
- The logarithm to the base 2 of `x` element-wise.
- NaNs are returned where `x` is negative.
-
- See Also
- --------
- log, log1p, log10
-
- Examples
- --------
- >>> np.log2([-1, 2, 4])
- array([ NaN, 1., 2.])
-
- """
- import warnings
- msg = "numpy.lib.log2 is deprecated, use np.log2 instead."
- warnings.warn(msg, DeprecationWarning)
-
- x = nx.asanyarray(x)
- if y is None:
- y = nx.log(x)
- else:
- nx.log(x, y)
- y /= _log2
- return y
diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py
index fb597a7ed..1e7364adc 100644
--- a/numpy/lib/utils.py
+++ b/numpy/lib/utils.py
@@ -6,7 +6,7 @@ import re
from numpy.core.numerictypes import issubclass_, issubsctype, issubdtype
from numpy.core import product, ndarray, ufunc
-__all__ = ['issubclass_', 'get_numpy_include', 'issubsctype', 'issubdtype',
+__all__ = ['issubclass_', 'issubsctype', 'issubdtype',
'deprecate', 'deprecate_with_doc', 'get_numarray_include',
'get_include', 'info', 'source', 'who', 'lookfor', 'byte_bounds',
'may_share_memory', 'safe_eval']
@@ -215,7 +215,6 @@ def deprecate(*args, **kwargs):
return _Deprecate(*args, **kwargs)
deprecate_with_doc = lambda msg: _Deprecate(message=msg)
-get_numpy_include = deprecate(get_include, 'get_numpy_include', 'get_include')
#--------------------------------------------
diff --git a/numpy/linalg/linalg.py b/numpy/linalg/linalg.py
index c044176cf..87be0e8a3 100644
--- a/numpy/linalg/linalg.py
+++ b/numpy/linalg/linalg.py
@@ -205,7 +205,7 @@ def tensorsolve(a, b, axes=None):
See Also
--------
- tensordot, tensorinv
+ tensordot, tensorinv, einsum
Examples
--------
@@ -1567,8 +1567,8 @@ def slogdet(a):
Parameters
----------
- a : array_like, shape (M, M)
- Input array.
+ a : array_like
+ Input array, has to be a square 2-D array.
Returns
-------
@@ -1580,18 +1580,22 @@ def slogdet(a):
The natural log of the absolute value of the determinant.
If the determinant is zero, then `sign` will be 0 and `logdet` will be
- -Inf. In all cases, the determinant is equal to `sign * np.exp(logdet)`.
+ -Inf. In all cases, the determinant is equal to ``sign * np.exp(logdet)``.
+
+ See Also
+ --------
+ det
Notes
-----
The determinant is computed via LU factorization using the LAPACK
routine z/dgetrf.
- .. versionadded:: 2.0.0.
+ .. versionadded:: 1.6.0.
Examples
--------
- The determinant of a 2-D array [[a, b], [c, d]] is ad - bc:
+ The determinant of a 2-D array ``[[a, b], [c, d]]`` is ``ad - bc``:
>>> a = np.array([[1, 2], [3, 4]])
>>> (sign, logdet) = np.linalg.slogdet(a)
@@ -1607,10 +1611,6 @@ def slogdet(a):
>>> np.linalg.slogdet(np.eye(500) * 0.1)
(1, -1151.2925464970228)
- See Also
- --------
- det
-
"""
a = asarray(a)
_assertRank2(a)
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index a945789df..936df17f3 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -940,7 +940,9 @@ class _MaskedBinaryOperation:
# Revert result to da where masked
if m.any():
np.putmask(result, m, 0)
- result += m * da
+ # This only makes sense if the operation preserved the dtype
+ if result.dtype == da.dtype:
+ result += m * da
# Transforms to a (subclass of) MaskedArray
result = result.view(get_masked_subclass(a, b))
result._mask = m
@@ -1417,7 +1419,7 @@ def is_mask(m):
except AttributeError:
return False
-def make_mask(m, copy=False, shrink=True, flag=None, dtype=MaskType):
+def make_mask(m, copy=False, shrink=True, dtype=MaskType):
"""
Create a boolean mask from an array.
@@ -1434,8 +1436,6 @@ def make_mask(m, copy=False, shrink=True, flag=None, dtype=MaskType):
Whether to return a copy of `m` (True) or `m` itself (False).
shrink : bool, optional
Whether to shrink `m` to ``nomask`` if all its values are False.
- flag : bool, optional
- Deprecated equivalent of `shrink`.
dtype : dtype, optional
Data-type of the output mask. By default, the output mask has
a dtype of MaskType (bool). If the dtype is flexible, each field
@@ -1489,10 +1489,6 @@ def make_mask(m, copy=False, shrink=True, flag=None, dtype=MaskType):
dtype=[('man', '|b1'), ('mouse', '|b1')])
"""
- if flag is not None:
- warnings.warn("The flag 'flag' is now called 'shrink'!",
- DeprecationWarning)
- shrink = flag
if m is nomask:
return nomask
elif isinstance(m, ndarray):
@@ -2578,9 +2574,9 @@ class MaskedArray(ndarray):
Construction::
- x = MaskedArray(data, mask=nomask, dtype=None, copy=True,
- fill_value=None, keep_mask=True, hard_mask=False,
- shrink=True)
+ x = MaskedArray(data, mask=nomask, dtype=None,
+ copy=False, subok=True, ndmin=0, fill_value=None,
+ keep_mask=True, hard_mask=None, shrink=True)
Parameters
----------
@@ -2623,7 +2619,7 @@ class MaskedArray(ndarray):
def __new__(cls, data=None, mask=nomask, dtype=None, copy=False,
subok=True, ndmin=0, fill_value=None,
- keep_mask=True, hard_mask=None, flag=None, shrink=True,
+ keep_mask=True, hard_mask=None, shrink=True,
**options):
"""
Create a new masked array from scratch.
@@ -2633,10 +2629,6 @@ class MaskedArray(ndarray):
A masked array can also be created by taking a .view(MaskedArray).
"""
- if flag is not None:
- warnings.warn("The flag 'flag' is now called 'shrink'!",
- DeprecationWarning)
- shrink = flag
# Process data............
_data = np.array(data, dtype=dtype, copy=copy, subok=True, ndmin=ndmin)
_baseclass = getattr(data, '_baseclass', type(_data))
@@ -3256,27 +3248,6 @@ class MaskedArray(ndarray):
_data = property(fget=_get_data)
data = property(fget=_get_data)
- def raw_data(self):
- """
- Return the data part of the masked array.
-
- DEPRECATED: You should really use ``.data`` instead.
-
- Examples
- --------
- >>> x = np.ma.array([1, 2, 3], mask=[False, True, False])
- >>> x
- masked_array(data = [1 -- 3],
- mask = [False True False],
- fill_value = 999999)
- >>> x.data
- array([1, 2, 3])
-
- """
- warnings.warn('Use .data instead.', DeprecationWarning)
- return self._data
-
-
def _get_flat(self):
"Return a flat iterator."
return MaskedIterator(self)
@@ -3371,6 +3342,12 @@ class MaskedArray(ndarray):
The value to use for invalid entries (None by default).
If None, the `fill_value` attribute of the array is used instead.
+ Returns
+ -------
+ filled_array : ndarray
+ A copy of ``self`` with invalid entries replaced by *fill_value*
+ (be it the function argument or the attribute of ``self``.
+
Notes
-----
The result is **not** a MaskedArray!
@@ -4314,6 +4291,8 @@ class MaskedArray(ndarray):
array.
ndarray.nonzero :
Equivalent ndarray method.
+ count_nonzero :
+ Counts the number of non-zero elements in the input array.
Examples
--------
@@ -5015,7 +4994,7 @@ class MaskedArray(ndarray):
>>> a.sort(endwith=False, fill_value=3)
>>> print a
[1 -- -- 3 5]
-
+
"""
if self._mask is nomask:
ndarray.sort(self, axis=axis, kind=kind, order=order)
@@ -5550,8 +5529,8 @@ class mvoid(MaskedArray):
def __getitem__(self, indx):
"Get the index..."
- _mask = self._mask.astype(np.void)
- if _mask is not nomask and _mask[indx]:
+ m = self._mask
+ if m is not nomask and m[indx]:
return masked
return self._data[indx]
@@ -6788,7 +6767,7 @@ def allequal (a, b, fill_value=True):
else:
return False
-def allclose (a, b, masked_equal=True, rtol=1e-5, atol=1e-8, fill_value=None):
+def allclose (a, b, masked_equal=True, rtol=1e-5, atol=1e-8):
"""
Returns True if two arrays are element-wise equal within a tolerance.
@@ -6809,9 +6788,6 @@ def allclose (a, b, masked_equal=True, rtol=1e-5, atol=1e-8, fill_value=None):
atol : float, optional
Absolute tolerance. The absolute difference is equal to `atol`.
Default is 1e-8.
- fill_value : bool, optional
- *Deprecated* - Whether masked values in `a` or `b` are considered equal
- (True) or not (False).
Returns
-------
@@ -6863,11 +6839,6 @@ def allclose (a, b, masked_equal=True, rtol=1e-5, atol=1e-8, fill_value=None):
False
"""
- if fill_value is not None:
- warnings.warn("The use of fill_value is deprecated."\
- " Please use masked_equal instead.")
- masked_equal = fill_value
- #
x = masked_array(a, copy=False)
y = masked_array(b, copy=False)
m = mask_or(getmask(x), getmask(y))
diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py
index 5ca1e3d1b..1c28eadb8 100644
--- a/numpy/ma/extras.py
+++ b/numpy/ma/extras.py
@@ -1087,7 +1087,7 @@ def intersect1d(ar1, ar2, assume_unique=False):
if assume_unique:
aux = ma.concatenate((ar1, ar2))
else:
- # Might be faster than unique1d( intersect1d( ar1, ar2 ) )?
+ # Might be faster than unique( intersect1d( ar1, ar2 ) )?
aux = ma.concatenate((unique(ar1), unique(ar2)))
aux.sort()
return aux[aux[1:] == aux[:-1]]
@@ -1522,7 +1522,7 @@ def flatnotmasked_edges(a):
See Also
--------
- flatnotmasked_contiguous, notmasked_contiguous, notmasked_edges,
+ flatnotmasked_contiguous, notmasked_contiguous, notmasked_edges,
clump_masked, clump_unmasked
Notes
@@ -1637,7 +1637,7 @@ def flatnotmasked_contiguous(a):
>>> a = np.ma.arange(10)
>>> np.ma.extras.flatnotmasked_contiguous(a)
slice(0, 10, None)
-
+
>>> mask = (a < 3) | (a > 8) | (a == 5)
>>> a[mask] = np.ma.masked
>>> np.array(a[~a.mask])
@@ -1761,7 +1761,7 @@ def clump_unmasked(a):
See Also
--------
- flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges,
+ flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges,
notmasked_contiguous, clump_masked
Examples
@@ -1805,7 +1805,7 @@ def clump_masked(a):
See Also
--------
- flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges,
+ flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges,
notmasked_contiguous, clump_unmasked
Examples
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index e3b7b99ef..070701089 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -243,9 +243,9 @@ class TestMaskedArray(TestCase):
junk, garbage = str(x2), repr(x2)
assert_equal(np.sort(x1), sort(x2, endwith=False))
# tests of indexing
- assert type(x2[1]) is type(x1[1])
- assert x1[1] == x2[1]
- assert x2[0] is masked
+ assert_(type(x2[1]) is type(x1[1]))
+ assert_(x1[1] == x2[1])
+ assert_(x2[0] is masked)
assert_equal(x1[2], x2[2])
assert_equal(x1[2:5], x2[2:5])
assert_equal(x1[:], x2[:])
@@ -262,16 +262,16 @@ class TestMaskedArray(TestCase):
assert_equal(x1, x2)
x2[:] = x1
x2[1] = masked
- assert allequal(getmask(x2), array([0, 1, 0, 0]))
+ assert_(allequal(getmask(x2), array([0, 1, 0, 0])))
x3[:] = masked_array([1, 2, 3, 4], [0, 1, 1, 0])
- assert allequal(getmask(x3), array([0, 1, 1, 0]))
+ assert_(allequal(getmask(x3), array([0, 1, 1, 0])))
x4[:] = masked_array([1, 2, 3, 4], [0, 1, 1, 0])
- assert allequal(getmask(x4), array([0, 1, 1, 0]))
- assert allequal(x4, array([1, 2, 3, 4]))
+ assert_(allequal(getmask(x4), array([0, 1, 1, 0])))
+ assert_(allequal(x4, array([1, 2, 3, 4])))
x1 = np.arange(5) * 1.0
x2 = masked_values(x1, 3.0)
assert_equal(x1, x2)
- assert allequal(array([0, 0, 0, 1, 0], MaskType), x2.mask)
+ assert_(allequal(array([0, 0, 0, 1, 0], MaskType), x2.mask))
assert_equal(3.0, x2.fill_value)
x1 = array([1, 'hello', 2, 3], object)
x2 = np.array([1, 'hello', 2, 3], object)
@@ -280,7 +280,7 @@ class TestMaskedArray(TestCase):
assert_equal(type(s2), str)
assert_equal(type(s1), str)
assert_equal(s1, s2)
- assert x1[1:1].shape == (0,)
+ assert_(x1[1:1].shape == (0,))
def test_copy(self):
@@ -292,23 +292,19 @@ class TestMaskedArray(TestCase):
m3 = make_mask(m, copy=1)
self.assertTrue(m is not m3)
- warnings.simplefilter('ignore', DeprecationWarning)
x1 = np.arange(5)
y1 = array(x1, mask=m)
#self.assertTrue( y1._data is x1)
assert_equal(y1._data.__array_interface__, x1.__array_interface__)
- self.assertTrue(allequal(x1, y1.raw_data()))
+ self.assertTrue(allequal(x1, y1.data))
#self.assertTrue( y1.mask is m)
assert_equal(y1._mask.__array_interface__, m.__array_interface__)
- warnings.simplefilter('default', DeprecationWarning)
y1a = array(y1)
- #self.assertTrue( y1a.raw_data() is y1.raw_data())
self.assertTrue(y1a._data.__array_interface__ == y1._data.__array_interface__)
self.assertTrue(y1a.mask is y1.mask)
y2 = array(x1, mask=m)
- #self.assertTrue( y2.raw_data() is x1)
self.assertTrue(y2._data.__array_interface__ == x1.__array_interface__)
#self.assertTrue( y2.mask is m)
self.assertTrue(y2._mask.__array_interface__ == m.__array_interface__)
@@ -431,7 +427,7 @@ class TestMaskedArray(TestCase):
self.assertRaises(TypeError, float, array([1, 1]))
#
warnings.simplefilter('ignore', UserWarning)
- assert np.isnan(float(array([1], mask=[1])))
+ assert_(np.isnan(float(array([1], mask=[1]))))
warnings.simplefilter('default', UserWarning)
#
a = array([1, 2, 3], mask=[1, 0, 0])
@@ -448,7 +444,7 @@ class TestMaskedArray(TestCase):
x = arange(20)
x = x.reshape(4, 5)
x.flat[5] = 12
- assert x[1, 0] == 12
+ assert_(x[1, 0] == 12)
z = x + 10j * x
assert_equal(z.real, x)
assert_equal(z.imag, 10 * x)
@@ -457,18 +453,18 @@ class TestMaskedArray(TestCase):
#
x = arange(10)
x[3] = masked
- assert str(x[3]) == str(masked)
+ assert_(str(x[3]) == str(masked))
c = x >= 8
- assert count(where(c, masked, masked)) == 0
- assert shape(where(c, masked, masked)) == c.shape
+ assert_(count(where(c, masked, masked)) == 0)
+ assert_(shape(where(c, masked, masked)) == c.shape)
#
z = masked_where(c, x)
- assert z.dtype is x.dtype
- assert z[3] is masked
- assert z[4] is not masked
- assert z[7] is not masked
- assert z[8] is masked
- assert z[9] is masked
+ assert_(z.dtype is x.dtype)
+ assert_(z[3] is masked)
+ assert_(z[4] is not masked)
+ assert_(z[7] is not masked)
+ assert_(z[8] is masked)
+ assert_(z[9] is masked)
assert_equal(x, z)
@@ -482,9 +478,9 @@ class TestMaskedArray(TestCase):
c[0] = masked
z = where(c, x, -x)
assert_equal(z, [1., 2., 0., -4., -5])
- assert z[0] is masked
- assert z[1] is not masked
- assert z[2] is masked
+ assert_(z[0] is masked)
+ assert_(z[1] is not masked)
+ assert_(z[2] is masked)
def test_oddfeatures_3(self):
@@ -769,7 +765,7 @@ class TestMaskedArrayArithmetic(TestCase):
assert_equal(y.shape, x.shape)
assert_equal(y._mask, [True, True])
y = x[0] * masked
- assert y is masked
+ assert_(y is masked)
y = x + masked
assert_equal(y.shape, x.shape)
assert_equal(y._mask, [True, True])
@@ -830,13 +826,13 @@ class TestMaskedArrayArithmetic(TestCase):
assert_equal(1, count(1))
assert_equal(0, array(1, mask=[1]))
ott = ott.reshape((2, 2))
- assert isinstance(count(ott, 0), ndarray)
+ assert_(isinstance(count(ott, 0), ndarray))
if sys.version_info[0] >= 3:
- assert isinstance(count(ott), np.integer)
+ assert_(isinstance(count(ott), np.integer))
else:
- assert isinstance(count(ott), types.IntType)
+ assert_(isinstance(count(ott), types.IntType))
assert_equal(3, count(ott))
- assert getmask(count(ott, 0)) is nomask
+ assert_(getmask(count(ott, 0)) is nomask)
assert_equal([1, 2], count(ott, 0))
@@ -856,8 +852,8 @@ class TestMaskedArrayArithmetic(TestCase):
y[0] = masked
assert_equal(minimum(x, y), where(less(x, y), x, y))
assert_equal(maximum(x, y), where(greater(x, y), x, y))
- assert minimum(x) == 0
- assert maximum(x) == 4
+ assert_(minimum(x) == 0)
+ assert_(maximum(x) == 4)
#
x = arange(4).reshape(2, 2)
x[-1, -1] = masked
@@ -1076,9 +1072,9 @@ class TestMaskedArrayArithmetic(TestCase):
y = array(['abc', 1, 'def', 2, 3], object)
y[2] = masked
t = take(y, [0, 3, 4])
- assert t[0] == 'abc'
- assert t[1] == 2
- assert t[2] == 3
+ assert_(t[0] == 'abc')
+ assert_(t[1] == 2)
+ assert_(t[2] == 3)
def test_imag_real(self):
@@ -1366,12 +1362,18 @@ class TestFillingValues(TestCase):
fval = _check_fill_value(fill_val, ndtype)
self.assertTrue(isinstance(fval, ndarray))
assert_equal(fval.item(), [-999, -12345678.9, asbytes("???")])
+
#.....Using a flexible type w/ a different type shouldn't matter
- fill_val = np.array((-999, -12345678.9, "???"),
- dtype=[("A", int), ("B", float), ("C", "|S3")])
+ # BEHAVIOR in 1.5 and earlier: match structured types by position
+ #fill_val = np.array((-999, -12345678.9, "???"),
+ # dtype=[("A", int), ("B", float), ("C", "|S3")])
+ # BEHAVIOR in 1.6 and later: match structured types by name
+ fill_val = np.array(("???", -999, -12345678.9),
+ dtype=[("c", "|S3"), ("a", int), ("b", float), ])
fval = _check_fill_value(fill_val, ndtype)
self.assertTrue(isinstance(fval, ndarray))
assert_equal(fval.item(), [-999, -12345678.9, asbytes("???")])
+
#.....Using an object-array shouldn't matter either
fill_value = np.array((-999, -12345678.9, "???"), dtype=object)
fval = _check_fill_value(fill_val, ndtype)
@@ -1634,13 +1636,11 @@ class TestMaskedArrayInPlaceArithmetics(TestCase):
xm += 1
assert_equal(xm, y + 1)
#
- warnings.simplefilter('ignore', DeprecationWarning)
(x, _, xm) = self.floatdata
- id1 = x.raw_data().ctypes._data
+ id1 = x.data.ctypes._data
x += 1.
- assert (id1 == x.raw_data().ctypes._data)
+ assert_(id1 == x.data.ctypes._data)
assert_equal(x, y + 1.)
- warnings.simplefilter('default', DeprecationWarning)
def test_inplace_addition_array(self):
"""Test of inplace additions"""
@@ -1990,15 +1990,15 @@ class TestMaskedArrayMethods(TestCase):
mxbig = (mx > 0.5)
mxsmall = (mx < 0.5)
#
- assert (mxbig.all() == False)
- assert (mxbig.any() == True)
+ assert_((mxbig.all() == False))
+ assert_((mxbig.any() == True))
assert_equal(mxbig.all(0), [False, False, True])
assert_equal(mxbig.all(1), [False, False, True])
assert_equal(mxbig.any(0), [False, False, True])
assert_equal(mxbig.any(1), [True, True, True])
#
- assert (mxsmall.all() == False)
- assert (mxsmall.any() == True)
+ assert_((mxsmall.all() == False))
+ assert_((mxsmall.any() == True))
assert_equal(mxsmall.all(0), [True, True, False])
assert_equal(mxsmall.all(1), [False, False, False])
assert_equal(mxsmall.any(0), [True, True, False])
@@ -2017,15 +2017,15 @@ class TestMaskedArrayMethods(TestCase):
mXbig = (mX > 0.5)
mXsmall = (mX < 0.5)
#
- assert (mXbig.all() == False)
- assert (mXbig.any() == True)
+ assert_((mXbig.all() == False))
+ assert_((mXbig.any() == True))
assert_equal(mXbig.all(0), np.matrix([False, False, True]))
assert_equal(mXbig.all(1), np.matrix([False, False, True]).T)
assert_equal(mXbig.any(0), np.matrix([False, False, True]))
assert_equal(mXbig.any(1), np.matrix([ True, True, True]).T)
#
- assert (mXsmall.all() == False)
- assert (mXsmall.any() == True)
+ assert_((mXsmall.all() == False))
+ assert_((mXsmall.any() == True))
assert_equal(mXsmall.all(0), np.matrix([True, True, False]))
assert_equal(mXsmall.all(1), np.matrix([False, False, False]).T)
assert_equal(mXsmall.any(0), np.matrix([True, True, False]))
@@ -2936,9 +2936,9 @@ class TestMaskedArrayFunctions(TestCase):
c[0] = masked
z = where(c, x, -x)
assert_equal(z, [1., 2., 0., -4., -5])
- assert z[0] is masked
- assert z[1] is not masked
- assert z[2] is masked
+ assert_(z[0] is masked)
+ assert_(z[1] is not masked)
+ assert_(z[2] is masked)
def test_round_with_output(self):
@@ -3059,21 +3059,21 @@ class TestMaskedArrayFunctions(TestCase):
c = x >= 8
# Set False to masked
z = where(c , x, masked)
- assert z.dtype is x.dtype
- assert z[3] is masked
- assert z[4] is masked
- assert z[7] is masked
- assert z[8] is not masked
- assert z[9] is not masked
+ assert_(z.dtype is x.dtype)
+ assert_(z[3] is masked)
+ assert_(z[4] is masked)
+ assert_(z[7] is masked)
+ assert_(z[8] is not masked)
+ assert_(z[9] is not masked)
assert_equal(x, z)
# Set True to masked
z = where(c , masked, x)
- assert z.dtype is x.dtype
- assert z[3] is masked
- assert z[4] is not masked
- assert z[7] is not masked
- assert z[8] is masked
- assert z[9] is masked
+ assert_(z.dtype is x.dtype)
+ assert_(z[3] is masked)
+ assert_(z[4] is not masked)
+ assert_(z[7] is not masked)
+ assert_(z[8] is masked)
+ assert_(z[9] is masked)
def test_where_with_masked_condition(self):
x = array([1., 2., 3., 4., 5.])
@@ -3084,9 +3084,9 @@ class TestMaskedArrayFunctions(TestCase):
c[0] = masked
z = where(c, x, -x)
assert_equal(z, [1., 2., 0., -4., -5])
- assert z[0] is masked
- assert z[1] is not masked
- assert z[2] is masked
+ assert_(z[0] is masked)
+ assert_(z[1] is not masked)
+ assert_(z[2] is masked)
#
x = arange(1, 6)
x[-1] = masked
@@ -3097,7 +3097,7 @@ class TestMaskedArrayFunctions(TestCase):
z = where(c, x, y)
zm = where(cm, x, y)
assert_equal(z, zm)
- assert getmask(zm) is nomask
+ assert_(getmask(zm) is nomask)
assert_equal(zm, [1, 2, 3, 40, 50])
z = where(c, masked, 1)
assert_equal(z, [99, 99, 99, 1, 1])
diff --git a/numpy/ma/tests/test_subclassing.py b/numpy/ma/tests/test_subclassing.py
index 146ea3051..fb72ca773 100644
--- a/numpy/ma/tests/test_subclassing.py
+++ b/numpy/ma/tests/test_subclassing.py
@@ -93,8 +93,12 @@ class TestSubclassing(TestCase):
def test_masked_unary_operations(self):
"Tests masked_unary_operation"
(x, mx) = self.data
- self.assertTrue(isinstance(log(mx), mmatrix))
- assert_equal(log(x), np.log(x))
+ olderr = np.seterr(divide='ignore')
+ try:
+ self.assertTrue(isinstance(log(mx), mmatrix))
+ assert_equal(log(x), np.log(x))
+ finally:
+ np.seterr(**olderr)
def test_masked_binary_operations(self):
"Tests masked_binary_operation"
diff --git a/numpy/ma/testutils.py b/numpy/ma/testutils.py
index 2b69cc4ad..5cfc9f2ab 100644
--- a/numpy/ma/testutils.py
+++ b/numpy/ma/testutils.py
@@ -77,8 +77,7 @@ def assert_equal_records(a, b):
def assert_equal(actual, desired, err_msg=''):
- """Asserts that two items are equal.
- """
+ "Asserts that two items are equal."
# Case #1: dictionary .....
if isinstance(desired, dict):
if not isinstance(actual, dict):
diff --git a/numpy/matrixlib/tests/test_defmatrix.py b/numpy/matrixlib/tests/test_defmatrix.py
index 65d79df0b..ccb68f0e7 100644
--- a/numpy/matrixlib/tests/test_defmatrix.py
+++ b/numpy/matrixlib/tests/test_defmatrix.py
@@ -263,7 +263,7 @@ class TestMatrixReturn(TestCase):
'searchsorted', 'setflags', 'setfield', 'sort', 'take',
'tofile', 'tolist', 'tostring', 'all', 'any', 'sum',
'argmax', 'argmin', 'min', 'max', 'mean', 'var', 'ptp',
- 'prod', 'std', 'ctypes', 'itemset'
+ 'prod', 'std', 'ctypes', 'itemset', 'setasflat'
]
for attrib in dir(a):
if attrib.startswith('_') or attrib in excluded_methods:
diff --git a/numpy/polynomial/chebyshev.py b/numpy/polynomial/chebyshev.py
index ea064a695..6b1edf497 100644
--- a/numpy/polynomial/chebyshev.py
+++ b/numpy/polynomial/chebyshev.py
@@ -23,6 +23,7 @@ Arithmetic
- `chebsub` -- subtract one Chebyshev series from another.
- `chebmul` -- multiply two Chebyshev series.
- `chebdiv` -- divide one Chebyshev series by another.
+- `chebpow` -- raise a Chebyshev series to an positive integer power
- `chebval` -- evaluate a Chebyshev series at given points.
Calculus
@@ -39,7 +40,7 @@ Misc Functions
- `chebpts1` -- Chebyshev points of the first kind.
- `chebpts2` -- Chebyshev points of the second kind.
- `chebtrim` -- trim leading coefficients from a Chebyshev series.
-- `chebline` -- Chebyshev series of given straight line.
+- `chebline` -- Chebyshev series representing given straight line.
- `cheb2poly` -- convert a Chebyshev series to a polynomial.
- `poly2cheb` -- convert a polynomial to a Chebyshev series.
@@ -78,10 +79,10 @@ References
from __future__ import division
__all__ = ['chebzero', 'chebone', 'chebx', 'chebdomain', 'chebline',
- 'chebadd', 'chebsub', 'chebmulx', 'chebmul', 'chebdiv', 'chebval',
- 'chebder', 'chebint', 'cheb2poly', 'poly2cheb', 'chebfromroots',
- 'chebvander', 'chebfit', 'chebtrim', 'chebroots', 'chebpts1',
- 'chebpts2', 'Chebyshev']
+ 'chebadd', 'chebsub', 'chebmulx', 'chebmul', 'chebdiv', 'chebpow',
+ 'chebval', 'chebder', 'chebint', 'cheb2poly', 'poly2cheb',
+ 'chebfromroots', 'chebvander', 'chebfit', 'chebtrim', 'chebroots',
+ 'chebpts1', 'chebpts2', 'Chebyshev']
import numpy as np
import numpy.linalg as la
@@ -1344,12 +1345,12 @@ def chebpts1(npts):
Parameters
----------
- npts: int
+ npts : int
Number of sample points desired.
Returns
-------
- pts: ndarray
+ pts : ndarray
The Chebyshev points of the second kind.
Notes
@@ -1375,12 +1376,12 @@ def chebpts2(npts):
Parameters
----------
- npts: int
+ npts : int
Number of sample points desired.
Returns
-------
- pts: ndarray
+ pts : ndarray
The Chebyshev points of the second kind.
Notes
diff --git a/numpy/polynomial/legendre.py b/numpy/polynomial/legendre.py
index f09f3dc17..9aec256cd 100644
--- a/numpy/polynomial/legendre.py
+++ b/numpy/polynomial/legendre.py
@@ -21,6 +21,7 @@ Arithmetic
- `legsub` -- subtract one Legendre series from another.
- `legmul` -- multiply two Legendre series.
- `legdiv` -- divide one Legendre series by another.
+- `legpow` -- raise a Legendre series to an positive integer power
- `legval` -- evaluate a Legendre series at given points.
Calculus
@@ -35,7 +36,7 @@ Misc Functions
- `legvander` -- Vandermonde-like matrix for Legendre polynomials.
- `legfit` -- least-squares fit returning a Legendre series.
- `legtrim` -- trim leading coefficients from a Legendre series.
-- `legline` -- Legendre series of given straight line.
+- `legline` -- Legendre series representing given straight line.
- `leg2poly` -- convert a Legendre series to a polynomial.
- `poly2leg` -- convert a polynomial to a Legendre series.
@@ -51,9 +52,10 @@ See also
from __future__ import division
__all__ = ['legzero', 'legone', 'legx', 'legdomain', 'legline',
- 'legadd', 'legsub', 'legmulx', 'legmul', 'legdiv', 'legval',
- 'legder', 'legint', 'leg2poly', 'poly2leg', 'legfromroots',
- 'legvander', 'legfit', 'legtrim', 'legroots', 'Legendre']
+ 'legadd', 'legsub', 'legmulx', 'legmul', 'legdiv', 'legpow',
+ 'legval', 'legder', 'legint', 'leg2poly', 'poly2leg',
+ 'legfromroots', 'legvander', 'legfit', 'legtrim', 'legroots',
+ 'Legendre']
import numpy as np
import numpy.linalg as la
@@ -65,8 +67,6 @@ legtrim = pu.trimcoef
def poly2leg(pol) :
"""
- poly2leg(pol)
-
Convert a polynomial to a Legendre series.
Convert an array representing the coefficients of a polynomial (relative
@@ -463,7 +463,7 @@ def legmulx(cs):
.. math::
- xP_i(x) = ((i + 1)*P_{i + 1}(x) + i*P_{i - 1}(x))/(2i + 1)
+ xP_i(x) = ((i + 1)*P_{i + 1}(x) + i*P_{i - 1}(x))/(2i + 1)
"""
# cs is a trimmed copy
@@ -564,12 +564,12 @@ def legdiv(c1, c2):
Parameters
----------
c1, c2 : array_like
- 1-d arrays of Legendre series coefficients ordered from low to
+ 1-D arrays of Legendre series coefficients ordered from low to
high.
Returns
-------
- [quo, rem] : ndarrays
+ quo, rem : ndarrays
Of Legendre series coefficients representing the quotient and
remainder.
@@ -683,8 +683,8 @@ def legder(cs, m=1, scl=1) :
Parameters
----------
- cs: array_like
- 1-d array of Legendre series coefficients ordered from low to high.
+ cs : array_like
+ 1-D array of Legendre series coefficients ordered from low to high.
m : int, optional
Number of derivatives taken, must be non-negative. (Default: 1)
scl : scalar, optional
@@ -887,9 +887,6 @@ def legval(x, cs):
--------
legfit
- Examples
- --------
-
Notes
-----
The evaluation uses Clenshaw recursion, aka synthetic division.
diff --git a/numpy/polynomial/polynomial.py b/numpy/polynomial/polynomial.py
index 6b5b7be98..3efe25920 100644
--- a/numpy/polynomial/polynomial.py
+++ b/numpy/polynomial/polynomial.py
@@ -20,6 +20,7 @@ Arithmetic
- `polysub` -- subtract one polynomial from another.
- `polymul` -- multiply two polynomials.
- `polydiv` -- divide one polynomial by another.
+- `polypow` -- raise a polynomial to an positive integer power
- `polyval` -- evaluate a polynomial at given points.
Calculus
@@ -34,8 +35,7 @@ Misc Functions
- `polyvander` -- Vandermonde-like matrix for powers.
- `polyfit` -- least-squares fit returning a polynomial.
- `polytrim` -- trim leading coefficients from a polynomial.
-- `polyline` -- Given a straight line, return the equivalent polynomial
- object.
+- `polyline` -- polynomial representing given straight line.
Classes
-------
@@ -49,9 +49,9 @@ See also
from __future__ import division
__all__ = ['polyzero', 'polyone', 'polyx', 'polydomain', 'polyline',
- 'polyadd', 'polysub', 'polymulx', 'polymul', 'polydiv', 'polyval',
- 'polyder', 'polyint', 'polyfromroots', 'polyvander', 'polyfit',
- 'polytrim', 'polyroots', 'Polynomial']
+ 'polyadd', 'polysub', 'polymulx', 'polymul', 'polydiv', 'polypow',
+ 'polyval', 'polyder', 'polyint', 'polyfromroots', 'polyvander',
+ 'polyfit', 'polytrim', 'polyroots', 'Polynomial']
import numpy as np
import numpy.linalg as la
diff --git a/numpy/polynomial/polytemplate.py b/numpy/polynomial/polytemplate.py
index 37f0018d0..2106ad84e 100644
--- a/numpy/polynomial/polytemplate.py
+++ b/numpy/polynomial/polytemplate.py
@@ -345,12 +345,12 @@ class $name(pu.PolyBase) :
Parameters
----------
- domain : {None, array_like}
- The domain of the new series type instance. If the value is is
- ``None``, then the default domain of `kind` is used.
- kind : {None, class}
+ domain : array_like, optional
+ The domain of the new series type instance. If the value is None,
+ then the default domain of `kind` is used.
+ kind : class, optional
The polynomial series type class to which the current instance
- should be converted. If kind is ``None``, then the class of the
+ should be converted. If kind is None, then the class of the
current instance is used.
Returns
@@ -359,14 +359,14 @@ class $name(pu.PolyBase) :
The returned class can be of different type than the current
instance and/or have a different domain.
- Examples
- --------
-
Notes
-----
Conversion between domains and class types can result in
numerically ill defined series.
+ Examples
+ --------
+
"""
if kind is None :
kind = $name
@@ -390,11 +390,11 @@ class $name(pu.PolyBase) :
off, scl : floats or complex
The mapping function is defined by ``off + scl*x``.
- Notes:
- ------
+ Notes
+ -----
If the current domain is the interval ``[l_1, r_1]`` and the default
interval is ``[l_2, r_2]``, then the linear mapping function ``L`` is
- defined by the equations:
+ defined by the equations::
L(l_1) = l_2
L(r_1) = r_2
@@ -491,8 +491,8 @@ class $name(pu.PolyBase) :
See Also
--------
- `${nick}int` : similar function.
- `${nick}der` : similar function for derivative.
+ ${nick}int : similar function.
+ ${nick}der : similar function for derivative.
"""
off, scl = self.mapparms()
@@ -521,8 +521,8 @@ class $name(pu.PolyBase) :
See Also
--------
- `${nick}der` : similar function.
- `${nick}int` : similar function for integration.
+ ${nick}der : similar function.
+ ${nick}int : similar function for integration.
"""
off, scl = self.mapparms()
@@ -538,8 +538,8 @@ class $name(pu.PolyBase) :
See Also
--------
- `${nick}roots` : similar function
- `${nick}fromroots` : function to go generate series from roots.
+ ${nick}roots : similar function
+ ${nick}fromroots : function to go generate series from roots.
"""
roots = ${nick}roots(self.coef)
@@ -552,8 +552,8 @@ class $name(pu.PolyBase) :
Here y is the value of the polynomial at the points x. This is
intended as a plotting aid.
- Paramters
- ---------
+ Parameters
+ ----------
n : int, optional
Number of point pairs to return. The default value is 100.
@@ -577,9 +577,9 @@ class $name(pu.PolyBase) :
"""Least squares fit to data.
Return a `$name` instance that is the least squares fit to the data
- `y` sampled at `x`. Unlike ${nick}fit, the domain of the returned
+ `y` sampled at `x`. Unlike `${nick}fit`, the domain of the returned
instance can be specified and this will often result in a superior
- fit with less chance of ill conditioning. See ${nick}fit for full
+ fit with less chance of ill conditioning. See `${nick}fit` for full
documentation of the implementation.
Parameters
@@ -591,7 +591,7 @@ class $name(pu.PolyBase) :
points sharing the same x-coordinates can be fitted at once by
passing in a 2D-array that contains one dataset per column.
deg : int
- Degree of the fitting polynomial
+ Degree of the fitting polynomial.
domain : {None, [beg, end], []}, optional
Domain to use for the returned $name instance. If ``None``,
then a minimal domain that covers the points `x` is chosen. If
@@ -671,14 +671,14 @@ class $name(pu.PolyBase) :
If ``p`` is the returned $name object, then ``p(x) == x`` for all
values of x.
- Parameters:
- -----------
+ Parameters
+ ----------
domain : array_like
The resulting array must be if the form ``[beg, end]``, where
``beg`` and ``end`` are the endpoints of the domain.
- Returns:
- --------
+ Returns
+ -------
identity : $name object
"""
diff --git a/numpy/random/mtrand/mtrand.c b/numpy/random/mtrand/mtrand.c
index cfb4bf4c9..eda815fdd 100644
--- a/numpy/random/mtrand/mtrand.c
+++ b/numpy/random/mtrand/mtrand.c
@@ -1,18 +1,39 @@
-/* Generated by Cython 0.12.1 on Mon Jul 5 13:47:19 2010 */
+/* Generated by Cython 0.14.1 on Thu Mar 10 10:20:54 2011 */
#define PY_SSIZE_T_CLEAN
#include "Python.h"
-#include "structmember.h"
#ifndef Py_PYTHON_H
#error Python headers needed to compile C extensions, please install development version of Python.
#else
-#ifndef PY_LONG_LONG
- #define PY_LONG_LONG LONG_LONG
+#include <stddef.h> /* For offsetof */
+#ifndef offsetof
+#define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
+#endif
+
+#if !defined(WIN32) && !defined(MS_WINDOWS)
+ #ifndef __stdcall
+ #define __stdcall
+ #endif
+ #ifndef __cdecl
+ #define __cdecl
+ #endif
+ #ifndef __fastcall
+ #define __fastcall
+ #endif
+#endif
+
+#ifndef DL_IMPORT
+ #define DL_IMPORT(t) t
#endif
#ifndef DL_EXPORT
#define DL_EXPORT(t) t
#endif
+
+#ifndef PY_LONG_LONG
+ #define PY_LONG_LONG LONG_LONG
+#endif
+
#if PY_VERSION_HEX < 0x02040000
#define METH_COEXIST 0
#define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)
@@ -82,14 +103,43 @@
#if PY_MAJOR_VERSION >= 3
#define PyBaseString_Type PyUnicode_Type
+ #define PyStringObject PyUnicodeObject
#define PyString_Type PyUnicode_Type
+ #define PyString_Check PyUnicode_Check
#define PyString_CheckExact PyUnicode_CheckExact
-#else
+#endif
+
+#if PY_VERSION_HEX < 0x02060000
+ #define PyBytesObject PyStringObject
#define PyBytes_Type PyString_Type
+ #define PyBytes_Check PyString_Check
#define PyBytes_CheckExact PyString_CheckExact
+ #define PyBytes_FromString PyString_FromString
+ #define PyBytes_FromStringAndSize PyString_FromStringAndSize
+ #define PyBytes_FromFormat PyString_FromFormat
+ #define PyBytes_DecodeEscape PyString_DecodeEscape
+ #define PyBytes_AsString PyString_AsString
+ #define PyBytes_AsStringAndSize PyString_AsStringAndSize
+ #define PyBytes_Size PyString_Size
+ #define PyBytes_AS_STRING PyString_AS_STRING
+ #define PyBytes_GET_SIZE PyString_GET_SIZE
+ #define PyBytes_Repr PyString_Repr
+ #define PyBytes_Concat PyString_Concat
+ #define PyBytes_ConcatAndDel PyString_ConcatAndDel
#endif
+#if PY_VERSION_HEX < 0x02060000
+ #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type)
+ #define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type)
+#endif
+#ifndef PySet_CheckExact
+ #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type)
+#endif
+
+#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
+
#if PY_MAJOR_VERSION >= 3
+ #define PyIntObject PyLongObject
#define PyInt_Type PyLong_Type
#define PyInt_Check(op) PyLong_Check(op)
#define PyInt_CheckExact(op) PyLong_CheckExact(op)
@@ -103,30 +153,42 @@
#define PyInt_AsSsize_t PyLong_AsSsize_t
#define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
#define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
+#endif
+
+#if PY_MAJOR_VERSION >= 3
+ #define PyBoolObject PyLongObject
+#endif
+
+
+#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)
#define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y)
#else
#define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y)
#define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y)
-
#endif
-#if PY_MAJOR_VERSION >= 3
- #define PyMethod_New(func, self, klass) PyInstanceMethod_New(func)
+#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300)
+ #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b)
+ #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value)
+ #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b)
+#else
+ #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \
+ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \
+ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \
+ (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0)))
+ #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \
+ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
+ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \
+ (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1)))
+ #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \
+ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
+ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \
+ (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1)))
#endif
-#if !defined(WIN32) && !defined(MS_WINDOWS)
- #ifndef __stdcall
- #define __stdcall
- #endif
- #ifndef __cdecl
- #define __cdecl
- #endif
- #ifndef __fastcall
- #define __fastcall
- #endif
-#else
- #define _USE_MATH_DEFINES
+#if PY_MAJOR_VERSION >= 3
+ #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
#endif
#if PY_VERSION_HEX < 0x02050000
@@ -146,11 +208,16 @@
#define __Pyx_NAMESTR(n) (n)
#define __Pyx_DOCSTR(n) (n)
#endif
+
#ifdef __cplusplus
#define __PYX_EXTERN_C extern "C"
#else
#define __PYX_EXTERN_C extern
#endif
+
+#if defined(WIN32) || defined(MS_WINDOWS)
+#define _USE_MATH_DEFINES
+#endif
#include <math.h>
#define __PYX_HAVE_API__mtrand
#include "string.h"
@@ -161,100 +228,51 @@
#include "distributions.h"
#include "initarray.h"
+#ifdef PYREX_WITHOUT_ASSERTIONS
+#define CYTHON_WITHOUT_ASSERTIONS
+#endif
+
+
+/* inline attribute */
#ifndef CYTHON_INLINE
#if defined(__GNUC__)
#define CYTHON_INLINE __inline__
#elif defined(_MSC_VER)
#define CYTHON_INLINE __inline
+ #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+ #define CYTHON_INLINE inline
#else
- #define CYTHON_INLINE
+ #define CYTHON_INLINE
#endif
#endif
+/* unused attribute */
+#ifndef CYTHON_UNUSED
+# if defined(__GNUC__)
+# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+# define CYTHON_UNUSED __attribute__ ((__unused__))
+# else
+# define CYTHON_UNUSED
+# endif
+# elif defined(__ICC) || defined(__INTEL_COMPILER)
+# define CYTHON_UNUSED __attribute__ ((__unused__))
+# else
+# define CYTHON_UNUSED
+# endif
+#endif
+
typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/
/* Type Conversion Predeclarations */
-#if PY_MAJOR_VERSION < 3
-#define __Pyx_PyBytes_FromString PyString_FromString
-#define __Pyx_PyBytes_FromStringAndSize PyString_FromStringAndSize
-#define __Pyx_PyBytes_AsString PyString_AsString
-#else
-#define __Pyx_PyBytes_FromString PyBytes_FromString
-#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
-#define __Pyx_PyBytes_AsString PyBytes_AsString
-#endif
-
-#define __Pyx_PyBytes_FromUString(s) __Pyx_PyBytes_FromString((char*)s)
-#define __Pyx_PyBytes_AsUString(s) ((unsigned char*) __Pyx_PyBytes_AsString(s))
+#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s)
+#define __Pyx_PyBytes_AsUString(s) ((unsigned char*) PyBytes_AsString(s))
#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);
-#if !defined(T_PYSSIZET)
-#if PY_VERSION_HEX < 0x02050000
-#define T_PYSSIZET T_INT
-#elif !defined(T_LONGLONG)
-#define T_PYSSIZET \
- ((sizeof(Py_ssize_t) == sizeof(int)) ? T_INT : \
- ((sizeof(Py_ssize_t) == sizeof(long)) ? T_LONG : -1))
-#else
-#define T_PYSSIZET \
- ((sizeof(Py_ssize_t) == sizeof(int)) ? T_INT : \
- ((sizeof(Py_ssize_t) == sizeof(long)) ? T_LONG : \
- ((sizeof(Py_ssize_t) == sizeof(PY_LONG_LONG)) ? T_LONGLONG : -1)))
-#endif
-#endif
-
-
-#if !defined(T_ULONGLONG)
-#define __Pyx_T_UNSIGNED_INT(x) \
- ((sizeof(x) == sizeof(unsigned char)) ? T_UBYTE : \
- ((sizeof(x) == sizeof(unsigned short)) ? T_USHORT : \
- ((sizeof(x) == sizeof(unsigned int)) ? T_UINT : \
- ((sizeof(x) == sizeof(unsigned long)) ? T_ULONG : -1))))
-#else
-#define __Pyx_T_UNSIGNED_INT(x) \
- ((sizeof(x) == sizeof(unsigned char)) ? T_UBYTE : \
- ((sizeof(x) == sizeof(unsigned short)) ? T_USHORT : \
- ((sizeof(x) == sizeof(unsigned int)) ? T_UINT : \
- ((sizeof(x) == sizeof(unsigned long)) ? T_ULONG : \
- ((sizeof(x) == sizeof(unsigned PY_LONG_LONG)) ? T_ULONGLONG : -1)))))
-#endif
-#if !defined(T_LONGLONG)
-#define __Pyx_T_SIGNED_INT(x) \
- ((sizeof(x) == sizeof(char)) ? T_BYTE : \
- ((sizeof(x) == sizeof(short)) ? T_SHORT : \
- ((sizeof(x) == sizeof(int)) ? T_INT : \
- ((sizeof(x) == sizeof(long)) ? T_LONG : -1))))
-#else
-#define __Pyx_T_SIGNED_INT(x) \
- ((sizeof(x) == sizeof(char)) ? T_BYTE : \
- ((sizeof(x) == sizeof(short)) ? T_SHORT : \
- ((sizeof(x) == sizeof(int)) ? T_INT : \
- ((sizeof(x) == sizeof(long)) ? T_LONG : \
- ((sizeof(x) == sizeof(PY_LONG_LONG)) ? T_LONGLONG : -1)))))
-#endif
-
-#define __Pyx_T_FLOATING(x) \
- ((sizeof(x) == sizeof(float)) ? T_FLOAT : \
- ((sizeof(x) == sizeof(double)) ? T_DOUBLE : -1))
-
-#if !defined(T_SIZET)
-#if !defined(T_ULONGLONG)
-#define T_SIZET \
- ((sizeof(size_t) == sizeof(unsigned int)) ? T_UINT : \
- ((sizeof(size_t) == sizeof(unsigned long)) ? T_ULONG : -1))
-#else
-#define T_SIZET \
- ((sizeof(size_t) == sizeof(unsigned int)) ? T_UINT : \
- ((sizeof(size_t) == sizeof(unsigned long)) ? T_ULONG : \
- ((sizeof(size_t) == sizeof(unsigned PY_LONG_LONG)) ? T_ULONGLONG : -1)))
-#endif
-#endif
-
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);
@@ -264,7 +282,7 @@ static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);
#ifdef __GNUC__
/* Test for GCC > 2.95 */
-#if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))
+#if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#else /* __GNUC__ > 2 ... */
@@ -284,9 +302,13 @@ static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;
-static const char **__pyx_f;
+static const char *__pyx_f[] = {
+ "mtrand.pyx",
+ "numpy.pxi",
+};
+
/* Type declarations */
typedef double (*__pyx_t_6mtrand_rk_cont0)(rk_state *);
@@ -366,14 +388,21 @@ struct __pyx_obj_6mtrand_RandomState {
#define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);} } while(0)
#define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r);} } while(0)
+static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/
+
+static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
+static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
+
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
+
static void __Pyx_RaiseDoubleKeywordsError(
const char* func_name, PyObject* kw_name); /*proto*/
+static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, const char* function_name); /*proto*/
+
static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/
-static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, const char* function_name); /*proto*/
-
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
PyObject *r;
@@ -384,11 +413,11 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j
}
-#define __Pyx_GetItemInt_List(o, i, size, to_py_func) ((size <= sizeof(Py_ssize_t)) ? \
- __Pyx_GetItemInt_List_Fast(o, i, size <= sizeof(long)) : \
+#define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
+ __Pyx_GetItemInt_List_Fast(o, i) : \
__Pyx_GetItemInt_Generic(o, to_py_func(i)))
-static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, int fits_long) {
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) {
if (likely(o != Py_None)) {
if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
PyObject *r = PyList_GET_ITEM(o, i);
@@ -401,14 +430,14 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_
return r;
}
}
- return __Pyx_GetItemInt_Generic(o, fits_long ? PyInt_FromLong(i) : PyLong_FromLongLong(i));
+ return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}
-#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) ((size <= sizeof(Py_ssize_t)) ? \
- __Pyx_GetItemInt_Tuple_Fast(o, i, size <= sizeof(long)) : \
+#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
+ __Pyx_GetItemInt_Tuple_Fast(o, i) : \
__Pyx_GetItemInt_Generic(o, to_py_func(i)))
-static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, int fits_long) {
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) {
if (likely(o != Py_None)) {
if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
PyObject *r = PyTuple_GET_ITEM(o, i);
@@ -421,15 +450,15 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize
return r;
}
}
- return __Pyx_GetItemInt_Generic(o, fits_long ? PyInt_FromLong(i) : PyLong_FromLongLong(i));
+ return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}
-#define __Pyx_GetItemInt(o, i, size, to_py_func) ((size <= sizeof(Py_ssize_t)) ? \
- __Pyx_GetItemInt_Fast(o, i, size <= sizeof(long)) : \
+#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
+ __Pyx_GetItemInt_Fast(o, i) : \
__Pyx_GetItemInt_Generic(o, to_py_func(i)))
-static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int fits_long) {
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) {
PyObject *r;
if (PyList_CheckExact(o) && ((0 <= i) & (i < PyList_GET_SIZE(o)))) {
r = PyList_GET_ITEM(o, i);
@@ -443,17 +472,17 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
r = PySequence_GetItem(o, i);
}
else {
- r = __Pyx_GetItemInt_Generic(o, fits_long ? PyInt_FromLong(i) : PyLong_FromLongLong(i));
+ r = __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}
return r;
}
static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);
-static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(void);
+static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);
static PyObject *__Pyx_UnpackItem(PyObject *, Py_ssize_t index); /*proto*/
-static int __Pyx_EndUnpack(PyObject *); /*proto*/
+static int __Pyx_EndUnpack(PyObject *, Py_ssize_t expected); /*proto*/
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
@@ -462,24 +491,8 @@ static CYTHON_INLINE int __Pyx_CheckKeywordStrings(PyObject *kwdict,
static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
-static CYTHON_INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
- if (likely(PyList_CheckExact(L))) {
- if (PyList_Append(L, x) < 0) return NULL;
- Py_INCREF(Py_None);
- return Py_None; /* this is just to have an accurate signature */
- }
- else {
- PyObject *r, *m;
- m = __Pyx_GetAttrString(L, "append");
- if (!m) return NULL;
- r = PyObject_CallFunctionObjArgs(m, x, NULL);
- Py_DECREF(m);
- return r;
- }
-}
-
-#define __Pyx_SetItemInt(o, i, v, size, to_py_func) ((size <= sizeof(Py_ssize_t)) ? \
- __Pyx_SetItemInt_Fast(o, i, v, size <= sizeof(long)) : \
+#define __Pyx_SetItemInt(o, i, v, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
+ __Pyx_SetItemInt_Fast(o, i, v) : \
__Pyx_SetItemInt_Generic(o, to_py_func(i), v))
static CYTHON_INLINE int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) {
@@ -490,7 +503,7 @@ static CYTHON_INLINE int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyOb
return r;
}
-static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v, int fits_long) {
+static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v) {
if (PyList_CheckExact(o) && ((0 <= i) & (i < PyList_GET_SIZE(o)))) {
Py_INCREF(v);
Py_DECREF(PyList_GET_ITEM(o, i));
@@ -500,7 +513,7 @@ static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObje
else if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_ass_item && (likely(i >= 0)))
return PySequence_SetItem(o, i, v);
else {
- PyObject *j = fits_long ? PyInt_FromLong(i) : PyLong_FromLongLong(i);
+ PyObject *j = PyInt_FromSsize_t(i);
return __Pyx_SetItemInt_Generic(o, j, v);
}
}
@@ -510,13 +523,6 @@ static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb);
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/
-static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/
-
-static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
-static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
-
-static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
-
static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);
static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);
@@ -535,6 +541,8 @@ static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);
static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);
+static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *);
+
static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);
static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);
@@ -581,107 +589,147 @@ static PyObject *__pyx_f_6mtrand_discd_array_sc(rk_state *, __pyx_t_6mtrand_rk_d
static PyObject *__pyx_f_6mtrand_discd_array(rk_state *, __pyx_t_6mtrand_rk_discd, PyObject *, PyArrayObject *); /*proto*/
static double __pyx_f_6mtrand_kahan_sum(double *, long); /*proto*/
#define __Pyx_MODULE_NAME "mtrand"
-int __pyx_module_is_main_mtrand = 0;
+static int __pyx_module_is_main_mtrand = 0;
/* Implementation of mtrand */
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_TypeError;
static char __pyx_k_1[] = "size is not compatible with inputs";
-static char __pyx_k_2[] = "algorithm must be 'MT19937'";
-static char __pyx_k_3[] = "state must be 624 longs";
-static char __pyx_k_4[] = "low >= high";
-static char __pyx_k_9[] = "scale <= 0";
-static char __pyx_k_10[] = "a <= 0";
-static char __pyx_k_11[] = "b <= 0";
-static char __pyx_k_13[] = "shape <= 0";
-static char __pyx_k_15[] = "dfnum <= 0";
-static char __pyx_k_16[] = "dfden <= 0";
-static char __pyx_k_17[] = "dfnum <= 1";
-static char __pyx_k_18[] = "nonc < 0";
-static char __pyx_k_19[] = "df <= 0";
-static char __pyx_k_20[] = "nonc <= 0";
-static char __pyx_k_21[] = "df <= 1";
-static char __pyx_k_22[] = "kappa < 0";
-static char __pyx_k_31[] = "sigma <= 0";
-static char __pyx_k_32[] = "sigma <= 0.0";
-static char __pyx_k_34[] = "scale <= 0.0";
-static char __pyx_k_35[] = "mean <= 0";
-static char __pyx_k_36[] = "mean <= 0.0";
-static char __pyx_k_37[] = "left > mode";
-static char __pyx_k_38[] = "mode > right";
-static char __pyx_k_39[] = "left == right";
-static char __pyx_k_40[] = "n <= 0";
-static char __pyx_k_41[] = "p < 0";
-static char __pyx_k_42[] = "p > 1";
-static char __pyx_k_44[] = "lam < 0";
-static char __pyx_k_45[] = "a <= 1.0";
-static char __pyx_k_46[] = "p < 0.0";
-static char __pyx_k_47[] = "p > 1.0";
-static char __pyx_k_48[] = "ngood < 1";
-static char __pyx_k_49[] = "nbad < 1";
-static char __pyx_k_50[] = "nsample < 1";
-static char __pyx_k_51[] = "ngood + nbad < nsample";
-static char __pyx_k_52[] = "p <= 0.0";
-static char __pyx_k_53[] = "p >= 1.0";
-static char __pyx_k_54[] = "mean must be 1 dimensional";
-static char __pyx_k_55[] = "cov must be 2 dimensional and square";
-static char __pyx_k_56[] = "mean and cov must have same length";
-static char __pyx_k_57[] = "numpy.dual";
-static char __pyx_k_58[] = "sum(pvals[:-1]) > 1.0";
-static char __pyx_k_59[] = "standard_exponential";
-static char __pyx_k_60[] = "noncentral_chisquare";
-static char __pyx_k_61[] = "RandomState.seed (line 567)";
-static char __pyx_k_62[] = "RandomState.get_state (line 600)";
-static char __pyx_k_63[] = "RandomState.set_state (line 637)";
-static char __pyx_k_64[] = "RandomState.random_sample (line 718)";
-static char __pyx_k_65[] = "RandomState.tomaxint (line 761)";
-static char __pyx_k_66[] = "RandomState.randint (line 789)";
-static char __pyx_k_67[] = "RandomState.bytes (line 866)";
-static char __pyx_k_68[] = "RandomState.uniform (line 893)";
-static char __pyx_k_69[] = "RandomState.rand (line 981)";
-static char __pyx_k_70[] = "RandomState.randn (line 1024)";
-static char __pyx_k_71[] = "RandomState.random_integers (line 1080)";
-static char __pyx_k_72[] = "RandomState.standard_normal (line 1158)";
-static char __pyx_k_73[] = "RandomState.normal (line 1190)";
-static char __pyx_k_74[] = "RandomState.beta (line 1290)";
-static char __pyx_k_75[] = "RandomState.exponential (line 1349)";
-static char __pyx_k_76[] = "RandomState.standard_exponential (line 1403)";
-static char __pyx_k_77[] = "RandomState.standard_gamma (line 1431)";
-static char __pyx_k_78[] = "RandomState.gamma (line 1513)";
-static char __pyx_k_79[] = "RandomState.f (line 1604)";
-static char __pyx_k_80[] = "RandomState.noncentral_f (line 1707)";
-static char __pyx_k_81[] = "RandomState.chisquare (line 1802)";
-static char __pyx_k_82[] = "RandomState.noncentral_chisquare (line 1882)";
-static char __pyx_k_83[] = "RandomState.standard_cauchy (line 1974)";
-static char __pyx_k_84[] = "RandomState.standard_t (line 2035)";
-static char __pyx_k_85[] = "RandomState.vonmises (line 2136)";
-static char __pyx_k_86[] = "RandomState.pareto (line 2231)";
-static char __pyx_k_87[] = "RandomState.weibull (line 2320)";
-static char __pyx_k_88[] = "RandomState.power (line 2420)";
-static char __pyx_k_89[] = "RandomState.laplace (line 2529)";
-static char __pyx_k_90[] = "RandomState.gumbel (line 2619)";
-static char __pyx_k_91[] = "RandomState.logistic (line 2743)";
-static char __pyx_k_92[] = "RandomState.lognormal (line 2831)";
-static char __pyx_k_93[] = "RandomState.rayleigh (line 2962)";
-static char __pyx_k_94[] = "RandomState.wald (line 3034)";
-static char __pyx_k_95[] = "RandomState.triangular (line 3120)";
-static char __pyx_k_96[] = "RandomState.binomial (line 3208)";
-static char __pyx_k_97[] = "RandomState.negative_binomial (line 3316)";
-static char __pyx_k_98[] = "RandomState.poisson (line 3411)";
-static char __pyx_k_99[] = "RandomState.zipf (line 3474)";
+static char __pyx_k_9[] = "algorithm must be 'MT19937'";
+static char __pyx_k_11[] = "state must be 624 longs";
+static char __pyx_k_13[] = "low >= high";
+static char __pyx_k_19[] = "scale <= 0";
+static char __pyx_k_22[] = "a <= 0";
+static char __pyx_k_24[] = "b <= 0";
+static char __pyx_k_31[] = "shape <= 0";
+static char __pyx_k_41[] = "dfnum <= 0";
+static char __pyx_k_43[] = "dfden <= 0";
+static char __pyx_k_45[] = "dfnum <= 1";
+static char __pyx_k_48[] = "nonc < 0";
+static char __pyx_k_53[] = "df <= 0";
+static char __pyx_k_57[] = "nonc <= 0";
+static char __pyx_k_59[] = "df <= 1";
+static char __pyx_k_64[] = "kappa < 0";
+static char __pyx_k_87[] = "sigma <= 0";
+static char __pyx_k_89[] = "sigma <= 0.0";
+static char __pyx_k_93[] = "scale <= 0.0";
+static char __pyx_k_95[] = "mean <= 0";
+static char __pyx_k_98[] = "mean <= 0.0";
static char __pyx_k__a[] = "a";
static char __pyx_k__b[] = "b";
static char __pyx_k__f[] = "f";
+static char __pyx_k__l[] = "l";
static char __pyx_k__n[] = "n";
static char __pyx_k__p[] = "p";
-static char __pyx_k_100[] = "RandomState.geometric (line 3566)";
-static char __pyx_k_101[] = "RandomState.hypergeometric (line 3632)";
-static char __pyx_k_102[] = "RandomState.logseries (line 3751)";
-static char __pyx_k_103[] = "RandomState.multivariate_normal (line 3846)";
-static char __pyx_k_104[] = "RandomState.multinomial (line 3979)";
-static char __pyx_k_105[] = "RandomState.dirichlet (line 4072)";
-static char __pyx_k_106[] = "RandomState.shuffle (line 4166)";
-static char __pyx_k_107[] = "RandomState.permutation (line 4202)";
+static char __pyx_k_101[] = "left > mode";
+static char __pyx_k_103[] = "mode > right";
+static char __pyx_k_105[] = "left == right";
+static char __pyx_k_110[] = "n <= 0";
+static char __pyx_k_112[] = "p < 0";
+static char __pyx_k_114[] = "p > 1";
+static char __pyx_k_126[] = "lam < 0";
+static char __pyx_k_128[] = "lam value too large";
+static char __pyx_k_131[] = "lam value too large.";
+static char __pyx_k_133[] = "a <= 1.0";
+static char __pyx_k_136[] = "p < 0.0";
+static char __pyx_k_138[] = "p > 1.0";
+static char __pyx_k_142[] = "ngood < 1";
+static char __pyx_k_144[] = "nbad < 1";
+static char __pyx_k_146[] = "nsample < 1";
+static char __pyx_k_148[] = "ngood + nbad < nsample";
+static char __pyx_k_154[] = "p <= 0.0";
+static char __pyx_k_156[] = "p >= 1.0";
+static char __pyx_k_160[] = "mean must be 1 dimensional";
+static char __pyx_k_162[] = "cov must be 2 dimensional and square";
+static char __pyx_k_164[] = "mean and cov must have same length";
+static char __pyx_k_166[] = "numpy.dual";
+static char __pyx_k_167[] = "sum(pvals[:-1]) > 1.0";
+static char __pyx_k_171[] = "standard_exponential";
+static char __pyx_k_172[] = "noncentral_chisquare";
+static char __pyx_k_173[] = "RandomState.random_sample (line 719)";
+static char __pyx_k_174[] = "\n random_sample(size=None)\n\n Return random floats in the half-open interval [0.0, 1.0).\n\n Results are from the \"continuous uniform\" distribution over the\n stated interval. To sample :math:`Unif[a, b), b > a` multiply\n the output of `random_sample` by `(b-a)` and add `a`::\n\n (b - a) * random_sample() + a\n\n Parameters\n ----------\n size : int or tuple of ints, optional\n Defines the shape of the returned array of random floats. If None\n (the default), returns a single float.\n\n Returns\n -------\n out : float or ndarray of floats\n Array of random floats of shape `size` (unless ``size=None``, in which\n case a single float is returned).\n\n Examples\n --------\n >>> np.random.random_sample()\n 0.47108547995356098\n >>> type(np.random.random_sample())\n <type 'float'>\n >>> np.random.random_sample((5,))\n array([ 0.30220482, 0.86820401, 0.1654503 , 0.11659149, 0.54323428])\n\n Three-by-two array of random numbers from [-5, 0):\n\n >>> 5 * np.random.random_sample((3, 2)) - 5\n array([[-3.99149989, -0.52338984],\n [-2.99091858, -0.79479508],\n [-1.23204345, -1.75224494]])\n\n ";
+static char __pyx_k_175[] = "RandomState.tomaxint (line 762)";
+static char __pyx_k_176[] = "\n tomaxint(size=None)\n\n Random integers between 0 and ``sys.maxint``, inclusive.\n\n Return a sample of uniformly distributed random integers in the interval\n [0, ``sys.maxint``].\n\n Parameters\n ----------\n size : tuple of ints, int, optional\n Shape of output. If this is, for example, (m,n,k), m*n*k samples\n are generated. If no shape is specified, a single sample is\n returned.\n\n Returns\n -------\n out : ndarray\n Drawn samples, with shape `size`.\n\n See Also\n --------\n randint : Uniform sampling over a given half-open interval of integers.\n random_integers : Uniform sampling over a given closed interval of\n integers.\n\n Examples\n --------\n >>> RS = np.random.mtrand.RandomState() # need a RandomState object\n >>> RS.tomaxint((2,2,2))\n array([[[1170048599, 1600360186],\n [ 739731006, 1947757578]],\n [[1871712945, 752307660],\n [1601631370, 1479324245]]])\n >>> import sys\n >>> sys.maxint\n 2147483647\n >>> RS.tomaxint((2,2,2)) < sys.maxint\n array([[[ True, True],\n [ True, True]],\n [[ True, True],\n [ True, True]]], dtype=bool)\n\n ";
+static char __pyx_k_177[] = "RandomState.randint (line 809)";
+static char __pyx_k_178[] = "\n randint(low, high=None, size=None)\n\n Return random integers from `low` (inclusive) to `high` (exclusive).\n\n Return random integers from the \"discrete uniform\" distribution in the\n \"half-open\" interval [`low`, `high`). If `high` is None (the default),\n then results are from [0, `low`).\n\n Parameters\n ----------\n low : int\n Lowest (signed) integer to be drawn from the distribution (unless\n ``high=None``, in which case this parameter is the *highest* such\n integer).\n high : int, optional\n If provided, one above the largest (signed) integer to be drawn\n from the distribution (see above for behavior if ``high=None``).\n size : int or tuple of ints, optional\n Output shape. Default is None, in which case a single int is\n returned.\n\n Returns\n -------\n out : int or ndarray of ints\n `size`-shaped array of random integers from the appropriate\n distribution, or a single such random int if `size` not provided.\n\n See Also\n --------\n random.random_integers : similar to `randint`, only for the closed\n interval [`low`, `high`], and 1 is the lowest value if `high` is\n omitted. In particular, this other one is the one to use to generate\n uniformly distributed discrete non-integers.\n\n Examples\n --------\n >>> np.random.randint(2, size=10)\n array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0])\n >>> np.random.randint(1, size=10)\n array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])\n\n Generate a 2 x 4 array of ints between 0 and 4, inclusive:\n\n >>> np.random.randint(5, size=(2, 4))\n array([[4, 0, 2, 1],\n [3, 2, 2, 0]])\n\n ";
+static char __pyx_k_179[] = "RandomState.bytes (line 889)";
+static char __pyx_k_180[] = "\n bytes(length)\n\n Return random bytes.\n\n Parameters\n ----------\n length : int\n Number of random bytes.\n\n Returns\n -------\n out : str\n String of length `length`.\n\n Examples\n --------\n >>> np.random.bytes(10)\n ' eh\\x85\\x022SZ\\xbf\\xa4' #random\n\n ";
+static char __pyx_k_181[] = "RandomState.uniform (line 916)";
+static char __pyx_k_182[] = "\n uniform(low=0.0, high=1.0, size=1)\n\n Draw samples from a uniform distribution.\n\n Samples are uniformly distributed over the half-open interval\n ``[low, high)`` (includes low, but excludes high). In other words,\n any value within the given interval is equally likely to be drawn\n by `uniform`.\n\n Parameters\n ----------\n low : float, optional\n Lower boundary of the output interval. All values generated will be\n greater than or equal to low. The default value is 0.\n high : float\n Upper boundary of the output interval. All values generated will be\n less than high. The default value is 1.0.\n size : int or tuple of ints, optional\n Shape of output. If the given size is, for example, (m,n,k),\n m*n*k samples are generated. If no shape is specified, a single sample\n is returned.\n\n Returns\n -------\n out : ndarray\n Drawn samples, with shape `size`.\n\n See Also\n --------\n randint : Discrete uniform distribution, yielding integers.\n random_integers : Discrete uniform distribution over the closed\n interval ``[low, high]``.\n random_sample : Floats uniformly distributed over ``[0, 1)``.\n random : Alias for `random_sample`.\n rand : Convenience function that accepts dimensions as input, e.g.,\n ``rand(2,2)`` would generate a 2-by-2 array of floats,\n uniformly distributed over ``[0, 1)``.\n\n Notes\n -----\n The probability density function of the uniform distribution is\n\n .. math:: p(x) = \\frac{1}{b - a}\n\n anywhere within the interval ``[a, b)``, and zero elsewhere.\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> s = np.random.uniform(-1,0,1000)\n\n All values are w""ithin the given interval:\n\n >>> np.all(s >= -1)\n True\n >>> np.all(s < 0)\n True\n\n Display the histogram of the samples, along with the\n probability density function:\n\n >>> import matplotlib.pyplot as plt\n >>> count, bins, ignored = plt.hist(s, 15, normed=True)\n >>> plt.plot(bins, np.ones_like(bins), linewidth=2, color='r')\n >>> plt.show()\n\n ";
+static char __pyx_k_183[] = "RandomState.rand (line 1003)";
+static char __pyx_k_184[] = "\n rand(d0, d1, ..., dn)\n\n Random values in a given shape.\n\n Create an array of the given shape and propagate it with\n random samples from a uniform distribution\n over ``[0, 1)``.\n\n Parameters\n ----------\n d0, d1, ..., dn : int\n Shape of the output.\n\n Returns\n -------\n out : ndarray, shape ``(d0, d1, ..., dn)``\n Random values.\n\n See Also\n --------\n random\n\n Notes\n -----\n This is a convenience function. If you want an interface that\n takes a shape-tuple as the first argument, refer to\n `random`.\n\n Examples\n --------\n >>> np.random.rand(3,2)\n array([[ 0.14022471, 0.96360618], #random\n [ 0.37601032, 0.25528411], #random\n [ 0.49313049, 0.94909878]]) #random\n\n ";
+static char __pyx_k_185[] = "RandomState.randn (line 1046)";
+static char __pyx_k_186[] = "\n randn([d1, ..., dn])\n\n Return a sample (or samples) from the \"standard normal\" distribution.\n\n If positive, int_like or int-convertible arguments are provided,\n `randn` generates an array of shape ``(d1, ..., dn)``, filled\n with random floats sampled from a univariate \"normal\" (Gaussian)\n distribution of mean 0 and variance 1 (if any of the :math:`d_i` are\n floats, they are first converted to integers by truncation). A single\n float randomly sampled from the distribution is returned if no\n argument is provided.\n\n This is a convenience function. If you want an interface that takes a\n tuple as the first argument, use `numpy.random.standard_normal` instead.\n\n Parameters\n ----------\n d1, ..., dn : `n` ints, optional\n The dimensions of the returned array, should be all positive.\n\n Returns\n -------\n Z : ndarray or float\n A ``(d1, ..., dn)``-shaped array of floating-point samples from\n the standard normal distribution, or a single such float if\n no parameters were supplied.\n\n See Also\n --------\n random.standard_normal : Similar, but takes a tuple as its argument.\n\n Notes\n -----\n For random samples from :math:`N(\\mu, \\sigma^2)`, use:\n\n ``sigma * np.random.randn(...) + mu``\n\n Examples\n --------\n >>> np.random.randn()\n 2.1923875335537315 #random\n\n Two-by-four array of samples from N(3, 6.25):\n\n >>> 2.5 * np.random.randn(2, 4) + 3\n array([[-4.49401501, 4.00950034, -1.81814867, 7.29718677], #random\n [ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) #random\n\n ";
+static char __pyx_k_187[] = "RandomState.random_integers (line 1102)";
+static char __pyx_k_188[] = "\n random_integers(low, high=None, size=None)\n\n Return random integers between `low` and `high`, inclusive.\n\n Return random integers from the \"discrete uniform\" distribution in the\n closed interval [`low`, `high`]. If `high` is None (the default),\n then results are from [1, `low`].\n\n Parameters\n ----------\n low : int\n Lowest (signed) integer to be drawn from the distribution (unless\n ``high=None``, in which case this parameter is the *highest* such\n integer).\n high : int, optional\n If provided, the largest (signed) integer to be drawn from the\n distribution (see above for behavior if ``high=None``).\n size : int or tuple of ints, optional\n Output shape. Default is None, in which case a single int is returned.\n\n Returns\n -------\n out : int or ndarray of ints\n `size`-shaped array of random integers from the appropriate\n distribution, or a single such random int if `size` not provided.\n\n See Also\n --------\n random.randint : Similar to `random_integers`, only for the half-open\n interval [`low`, `high`), and 0 is the lowest value if `high` is\n omitted.\n\n Notes\n -----\n To sample from N evenly spaced floating-point numbers between a and b,\n use::\n\n a + (b - a) * (np.random.random_integers(N) - 1) / (N - 1.)\n\n Examples\n --------\n >>> np.random.random_integers(5)\n 4\n >>> type(np.random.random_integers(5))\n <type 'int'>\n >>> np.random.random_integers(5, size=(3.,2.))\n array([[5, 4],\n [3, 3],\n [4, 5]])\n\n Choose five random numbers from the set of five evenly-spaced\n numbers between 0 and 2.5, inclusive (*i.e.*, from the set\n :math:`{0, 5/8, 10/8, 15/8, 20/8}`):\n""\n >>> 2.5 * (np.random.random_integers(5, size=(5,)) - 1) / 4.\n array([ 0.625, 1.25 , 0.625, 0.625, 2.5 ])\n\n Roll two six sided dice 1000 times and sum the results:\n\n >>> d1 = np.random.random_integers(1, 6, 1000)\n >>> d2 = np.random.random_integers(1, 6, 1000)\n >>> dsums = d1 + d2\n\n Display results as a histogram:\n\n >>> import matplotlib.pyplot as plt\n >>> count, bins, ignored = plt.hist(dsums, 11, normed=True)\n >>> plt.show()\n\n ";
+static char __pyx_k_189[] = "RandomState.standard_normal (line 1180)";
+static char __pyx_k_190[] = "\n standard_normal(size=None)\n\n Returns samples from a Standard Normal distribution (mean=0, stdev=1).\n\n Parameters\n ----------\n size : int or tuple of ints, optional\n Output shape. Default is None, in which case a single value is\n returned.\n\n Returns\n -------\n out : float or ndarray\n Drawn samples.\n\n Examples\n --------\n >>> s = np.random.standard_normal(8000)\n >>> s\n array([ 0.6888893 , 0.78096262, -0.89086505, ..., 0.49876311, #random\n -0.38672696, -0.4685006 ]) #random\n >>> s.shape\n (8000,)\n >>> s = np.random.standard_normal(size=(3, 4, 2))\n >>> s.shape\n (3, 4, 2)\n\n ";
+static char __pyx_k_191[] = "RandomState.normal (line 1212)";
+static char __pyx_k_192[] = "\n normal(loc=0.0, scale=1.0, size=None)\n\n Draw random samples from a normal (Gaussian) distribution.\n\n The probability density function of the normal distribution, first\n derived by De Moivre and 200 years later by both Gauss and Laplace\n independently [2]_, is often called the bell curve because of\n its characteristic shape (see the example below).\n\n The normal distributions occurs often in nature. For example, it\n describes the commonly occurring distribution of samples influenced\n by a large number of tiny, random disturbances, each with its own\n unique distribution [2]_.\n\n Parameters\n ----------\n loc : float\n Mean (\"centre\") of the distribution.\n scale : float\n Standard deviation (spread or \"width\") of the distribution.\n size : tuple of ints\n Output shape. If the given shape is, e.g., ``(m, n, k)``, then\n ``m * n * k`` samples are drawn.\n\n See Also\n --------\n scipy.stats.distributions.norm : probability density function,\n distribution or cumulative density function, etc.\n\n Notes\n -----\n The probability density for the Gaussian distribution is\n\n .. math:: p(x) = \\frac{1}{\\sqrt{ 2 \\pi \\sigma^2 }}\n e^{ - \\frac{ (x - \\mu)^2 } {2 \\sigma^2} },\n\n where :math:`\\mu` is the mean and :math:`\\sigma` the standard deviation.\n The square of the standard deviation, :math:`\\sigma^2`, is called the\n variance.\n\n The function has its peak at the mean, and its \"spread\" increases with\n the standard deviation (the function reaches 0.607 times its maximum at\n :math:`x + \\sigma` and :math:`x - \\sigma` [2]_). This implies that\n `numpy.random.normal` is more likely to return samples lying close to the\n mean, rather than those far away.\n""\n References\n ----------\n .. [1] Wikipedia, \"Normal distribution\",\n http://en.wikipedia.org/wiki/Normal_distribution\n .. [2] P. R. Peebles Jr., \"Central Limit Theorem\" in \"Probability, Random\n Variables and Random Signal Principles\", 4th ed., 2001,\n pp. 51, 51, 125.\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> mu, sigma = 0, 0.1 # mean and standard deviation\n >>> s = np.random.normal(mu, sigma, 1000)\n\n Verify the mean and the variance:\n\n >>> abs(mu - np.mean(s)) < 0.01\n True\n\n >>> abs(sigma - np.std(s, ddof=1)) < 0.01\n True\n\n Display the histogram of the samples, along with\n the probability density function:\n\n >>> import matplotlib.pyplot as plt\n >>> count, bins, ignored = plt.hist(s, 30, normed=True)\n >>> plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) *\n ... np.exp( - (bins - mu)**2 / (2 * sigma**2) ),\n ... linewidth=2, color='r')\n >>> plt.show()\n\n ";
+static char __pyx_k_193[] = "RandomState.standard_exponential (line 1425)";
+static char __pyx_k_194[] = "\n standard_exponential(size=None)\n\n Draw samples from the standard exponential distribution.\n\n `standard_exponential` is identical to the exponential distribution\n with a scale parameter of 1.\n\n Parameters\n ----------\n size : int or tuple of ints\n Shape of the output.\n\n Returns\n -------\n out : float or ndarray\n Drawn samples.\n\n Examples\n --------\n Output a 3x8000 array:\n\n >>> n = np.random.standard_exponential((3, 8000))\n\n ";
+static char __pyx_k_195[] = "RandomState.standard_gamma (line 1453)";
+static char __pyx_k_196[] = "\n standard_gamma(shape, size=None)\n\n Draw samples from a Standard Gamma distribution.\n\n Samples are drawn from a Gamma distribution with specified parameters,\n shape (sometimes designated \"k\") and scale=1.\n\n Parameters\n ----------\n shape : float\n Parameter, should be > 0.\n size : int or tuple of ints\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 drawn samples.\n\n See Also\n --------\n scipy.stats.distributions.gamma : probability density function,\n distribution or cumulative density function, etc.\n\n Notes\n -----\n The probability density for the Gamma distribution is\n\n .. math:: p(x) = x^{k-1}\\frac{e^{-x/\\theta}}{\\theta^k\\Gamma(k)},\n\n where :math:`k` is the shape and :math:`\\theta` the scale,\n and :math:`\\Gamma` is the Gamma function.\n\n The Gamma distribution is often used to model the times to failure of\n electronic components, and arises naturally in processes for which the\n waiting times between Poisson distributed events are relevant.\n\n References\n ----------\n .. [1] Weisstein, Eric W. \"Gamma Distribution.\" From MathWorld--A\n Wolfram Web Resource.\n http://mathworld.wolfram.com/GammaDistribution.html\n .. [2] Wikipedia, \"Gamma-distribution\",\n http://en.wikipedia.org/wiki/Gamma-distribution\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> shape, scale = 2., 1. # mean and width\n >>> s = np.random.standard_gamma(shape, 1000000)\n\n Display the histogram of the samples, along with\n the probability density function:\n\n >>> import matplotlib.pyplot as plt""\n >>> import scipy.special as sps\n >>> count, bins, ignored = plt.hist(s, 50, normed=True)\n >>> y = bins**(shape-1) * ((np.exp(-bins/scale))/ \\\n ... (sps.gamma(shape) * scale**shape))\n >>> plt.plot(bins, y, linewidth=2, color='r')\n >>> plt.show()\n\n ";
+static char __pyx_k_197[] = "RandomState.gamma (line 1535)";
+static char __pyx_k_198[] = "\n gamma(shape, scale=1.0, size=None)\n\n Draw samples from a Gamma distribution.\n\n Samples are drawn from a Gamma distribution with specified parameters,\n `shape` (sometimes designated \"k\") and `scale` (sometimes designated\n \"theta\"), where both parameters are > 0.\n\n Parameters\n ----------\n shape : scalar > 0\n The shape of the gamma distribution.\n scale : scalar > 0, optional\n The scale of the gamma distribution. Default is equal to 1.\n size : shape_tuple, optional\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 out : ndarray, float\n Returns one sample unless `size` parameter is specified.\n\n See Also\n --------\n scipy.stats.distributions.gamma : probability density function,\n distribution or cumulative density function, etc.\n\n Notes\n -----\n The probability density for the Gamma distribution is\n\n .. math:: p(x) = x^{k-1}\\frac{e^{-x/\\theta}}{\\theta^k\\Gamma(k)},\n\n where :math:`k` is the shape and :math:`\\theta` the scale,\n and :math:`\\Gamma` is the Gamma function.\n\n The Gamma distribution is often used to model the times to failure of\n electronic components, and arises naturally in processes for which the\n waiting times between Poisson distributed events are relevant.\n\n References\n ----------\n .. [1] Weisstein, Eric W. \"Gamma Distribution.\" From MathWorld--A\n Wolfram Web Resource.\n http://mathworld.wolfram.com/GammaDistribution.html\n .. [2] Wikipedia, \"Gamma-distribution\",\n http://en.wikipedia.org/wiki/Gamma-distribution\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> shape, scale = 2.,"" 2. # mean and dispersion\n >>> s = np.random.gamma(shape, scale, 1000)\n\n Display the histogram of the samples, along with\n the probability density function:\n\n >>> import matplotlib.pyplot as plt\n >>> import scipy.special as sps\n >>> count, bins, ignored = plt.hist(s, 50, normed=True)\n >>> y = bins**(shape-1)*(np.exp(-bins/scale) /\n ... (sps.gamma(shape)*scale**shape))\n >>> plt.plot(bins, y, linewidth=2, color='r')\n >>> plt.show()\n\n ";
+static char __pyx_k_199[] = "RandomState.f (line 1626)";
+static char __pyx_k_200[] = "\n f(dfnum, dfden, size=None)\n\n Draw samples from a F distribution.\n\n Samples are drawn from an F distribution with specified parameters,\n `dfnum` (degrees of freedom in numerator) and `dfden` (degrees of freedom\n in denominator), where both parameters should be greater than zero.\n\n The random variate of the F distribution (also known as the\n Fisher distribution) is a continuous probability distribution\n that arises in ANOVA tests, and is the ratio of two chi-square\n variates.\n\n Parameters\n ----------\n dfnum : float\n Degrees of freedom in numerator. Should be greater than zero.\n dfden : float\n Degrees of freedom in denominator. Should be greater than zero.\n size : {tuple, int}, optional\n Output shape. If the given shape is, e.g., ``(m, n, k)``,\n then ``m * n * k`` samples are drawn. By default only one sample\n is returned.\n\n Returns\n -------\n samples : {ndarray, scalar}\n Samples from the Fisher distribution.\n\n See Also\n --------\n scipy.stats.distributions.f : probability density function,\n distribution or cumulative density function, etc.\n\n Notes\n -----\n\n The F statistic is used to compare in-group variances to between-group\n variances. Calculating the distribution depends on the sampling, and\n so it is a function of the respective degrees of freedom in the\n problem. The variable `dfnum` is the number of samples minus one, the\n between-groups degrees of freedom, while `dfden` is the within-groups\n degrees of freedom, the sum of the number of samples in each group\n minus the number of groups.\n\n References\n ----------\n .. [1] Glantz, Stanton A. \"Primer of Biostatistics.\", McGraw-Hill,\n Fifth Edition, 2002.""\n .. [2] Wikipedia, \"F-distribution\",\n http://en.wikipedia.org/wiki/F-distribution\n\n Examples\n --------\n An example from Glantz[1], pp 47-40.\n Two groups, children of diabetics (25 people) and children from people\n without diabetes (25 controls). Fasting blood glucose was measured,\n case group had a mean value of 86.1, controls had a mean value of\n 82.2. Standard deviations were 2.09 and 2.49 respectively. Are these\n data consistent with the null hypothesis that the parents diabetic\n status does not affect their children's blood glucose levels?\n Calculating the F statistic from the data gives a value of 36.01.\n\n Draw samples from the distribution:\n\n >>> dfnum = 1. # between group degrees of freedom\n >>> dfden = 48. # within groups degrees of freedom\n >>> s = np.random.f(dfnum, dfden, 1000)\n\n The lower bound for the top 1% of the samples is :\n\n >>> sort(s)[-10]\n 7.61988120985\n\n So there is about a 1% chance that the F statistic will exceed 7.62,\n the measured value is 36, so the null hypothesis is rejected at the 1%\n level.\n\n ";
+static char __pyx_k_201[] = "RandomState.noncentral_f (line 1729)";
+static char __pyx_k_202[] = "\n noncentral_f(dfnum, dfden, nonc, size=None)\n\n Draw samples from the noncentral F distribution.\n\n Samples are drawn from an F distribution with specified parameters,\n `dfnum` (degrees of freedom in numerator) and `dfden` (degrees of\n freedom in denominator), where both parameters > 1.\n `nonc` is the non-centrality parameter.\n\n Parameters\n ----------\n dfnum : int\n Parameter, should be > 1.\n dfden : int\n Parameter, should be > 1.\n nonc : float\n Parameter, should be >= 0.\n size : int or tuple of ints\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 : scalar or ndarray\n Drawn samples.\n\n Notes\n -----\n When calculating the power of an experiment (power = probability of\n rejecting the null hypothesis when a specific alternative is true) the\n non-central F statistic becomes important. When the null hypothesis is\n true, the F statistic follows a central F distribution. When the null\n hypothesis is not true, then it follows a non-central F statistic.\n\n References\n ----------\n Weisstein, Eric W. \"Noncentral F-Distribution.\" From MathWorld--A Wolfram\n Web Resource. http://mathworld.wolfram.com/NoncentralF-Distribution.html\n\n Wikipedia, \"Noncentral F distribution\",\n http://en.wikipedia.org/wiki/Noncentral_F-distribution\n\n Examples\n --------\n In a study, testing for a specific alternative to the null hypothesis\n requires use of the Noncentral F distribution. We need to calculate the\n area in the tail of the distribution that exceeds the value of the F\n distribution for the null hypothesis. We'll plot the two probability\n distributions for comp""arison.\n\n >>> dfnum = 3 # between group deg of freedom\n >>> dfden = 20 # within groups degrees of freedom\n >>> nonc = 3.0\n >>> nc_vals = np.random.noncentral_f(dfnum, dfden, nonc, 1000000)\n >>> NF = np.histogram(nc_vals, bins=50, normed=True)\n >>> c_vals = np.random.f(dfnum, dfden, 1000000)\n >>> F = np.histogram(c_vals, bins=50, normed=True)\n >>> plt.plot(F[1][1:], F[0])\n >>> plt.plot(NF[1][1:], NF[0])\n >>> plt.show()\n\n ";
+static char __pyx_k_203[] = "RandomState.chisquare (line 1824)";
+static char __pyx_k_204[] = "\n chisquare(df, size=None)\n\n Draw samples from a chi-square distribution.\n\n When `df` independent random variables, each with standard normal\n distributions (mean 0, variance 1), are squared and summed, the\n resulting distribution is chi-square (see Notes). This distribution\n is often used in hypothesis testing.\n\n Parameters\n ----------\n df : int\n Number of degrees of freedom.\n size : tuple of ints, int, optional\n Size of the returned array. By default, a scalar is\n returned.\n\n Returns\n -------\n output : ndarray\n Samples drawn from the distribution, packed in a `size`-shaped\n array.\n\n Raises\n ------\n ValueError\n When `df` <= 0 or when an inappropriate `size` (e.g. ``size=-1``)\n is given.\n\n Notes\n -----\n The variable obtained by summing the squares of `df` independent,\n standard normally distributed random variables:\n\n .. math:: Q = \\sum_{i=0}^{\\mathtt{df}} X^2_i\n\n is chi-square distributed, denoted\n\n .. math:: Q \\sim \\chi^2_k.\n\n The probability density function of the chi-squared distribution is\n\n .. math:: p(x) = \\frac{(1/2)^{k/2}}{\\Gamma(k/2)}\n x^{k/2 - 1} e^{-x/2},\n\n where :math:`\\Gamma` is the gamma function,\n\n .. math:: \\Gamma(x) = \\int_0^{-\\infty} t^{x - 1} e^{-t} dt.\n\n References\n ----------\n `NIST/SEMATECH e-Handbook of Statistical Methods\n <http://www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm>`_\n\n Examples\n --------\n >>> np.random.chisquare(2,4)\n array([ 1.89920014, 9.00867716, 3.13710533, 5.62318272])\n\n ";
+static char __pyx_k_205[] = "RandomState.noncentral_chisquare (line 1902)";
+static char __pyx_k_206[] = "\n noncentral_chisquare(df, nonc, size=None)\n\n Draw samples from a noncentral chi-square distribution.\n\n The noncentral :math:`\\chi^2` distribution is a generalisation of\n the :math:`\\chi^2` distribution.\n\n Parameters\n ----------\n df : int\n Degrees of freedom, should be >= 1.\n nonc : float\n Non-centrality, should be > 0.\n size : int or tuple of ints\n Shape of the output.\n\n Notes\n -----\n The probability density function for the noncentral Chi-square distribution\n is\n\n .. math:: P(x;df,nonc) = \\sum^{\\infty}_{i=0}\n \\frac{e^{-nonc/2}(nonc/2)^{i}}{i!}P_{Y_{df+2i}}(x),\n\n where :math:`Y_{q}` is the Chi-square with q degrees of freedom.\n\n In Delhi (2007), it is noted that the noncentral chi-square is useful in\n bombing and coverage problems, the probability of killing the point target\n given by the noncentral chi-squared distribution.\n\n References\n ----------\n .. [1] Delhi, M.S. Holla, \"On a noncentral chi-square distribution in the\n analysis of weapon systems effectiveness\", Metrika, Volume 15,\n Number 1 / December, 1970.\n .. [2] Wikipedia, \"Noncentral chi-square distribution\"\n http://en.wikipedia.org/wiki/Noncentral_chi-square_distribution\n\n Examples\n --------\n Draw values from the distribution and plot the histogram\n\n >>> import matplotlib.pyplot as plt\n >>> values = plt.hist(np.random.noncentral_chisquare(3, 20, 100000),\n ... bins=200, normed=True)\n >>> plt.show()\n\n Draw values from a noncentral chisquare with very small noncentrality,\n and compare to a chisquare.\n\n >>> plt.figure()\n >>> values = plt.hist(np.random.noncentral_chisquare(3, .0000001, 100000),\n "" ... bins=np.arange(0., 25, .1), normed=True)\n >>> values2 = plt.hist(np.random.chisquare(3, 100000),\n ... bins=np.arange(0., 25, .1), normed=True)\n >>> plt.plot(values[1][0:-1], values[0]-values2[0], 'ob')\n >>> plt.show()\n\n Demonstrate how large values of non-centrality lead to a more symmetric\n distribution.\n\n >>> plt.figure()\n >>> values = plt.hist(np.random.noncentral_chisquare(3, 20, 100000),\n ... bins=200, normed=True)\n >>> plt.show()\n\n ";
+static char __pyx_k_207[] = "RandomState.standard_cauchy (line 1994)";
+static char __pyx_k_208[] = "\n standard_cauchy(size=None)\n\n Standard Cauchy distribution with mode = 0.\n\n Also known as the Lorentz distribution.\n\n Parameters\n ----------\n size : int or tuple of ints\n Shape of the output.\n\n Returns\n -------\n samples : ndarray or scalar\n The drawn samples.\n\n Notes\n -----\n The probability density function for the full Cauchy distribution is\n\n .. math:: P(x; x_0, \\gamma) = \\frac{1}{\\pi \\gamma \\bigl[ 1+\n (\\frac{x-x_0}{\\gamma})^2 \\bigr] }\n\n and the Standard Cauchy distribution just sets :math:`x_0=0` and\n :math:`\\gamma=1`\n\n The Cauchy distribution arises in the solution to the driven harmonic\n oscillator problem, and also describes spectral line broadening. It\n also describes the distribution of values at which a line tilted at\n a random angle will cut the x axis.\n\n When studying hypothesis tests that assume normality, seeing how the\n tests perform on data from a Cauchy distribution is a good indicator of\n their sensitivity to a heavy-tailed distribution, since the Cauchy looks\n very much like a Gaussian distribution, but with heavier tails.\n\n References\n ----------\n ..[1] NIST/SEMATECH e-Handbook of Statistical Methods, \"Cauchy\n Distribution\",\n http://www.itl.nist.gov/div898/handbook/eda/section3/eda3663.htm\n ..[2] Weisstein, Eric W. \"Cauchy Distribution.\" From MathWorld--A\n Wolfram Web Resource.\n http://mathworld.wolfram.com/CauchyDistribution.html\n ..[3] Wikipedia, \"Cauchy distribution\"\n http://en.wikipedia.org/wiki/Cauchy_distribution\n\n Examples\n --------\n Draw samples and plot the distribution:\n\n >>> s = np.random.standard_cauchy(1000000)\n >>> s = s[(s>-25) & (s<25)""] # truncate distribution so it plots well\n >>> plt.hist(s, bins=100)\n >>> plt.show()\n\n ";
+static char __pyx_k_209[] = "RandomState.standard_t (line 2055)";
+static char __pyx_k_210[] = "\n standard_t(df, size=None)\n\n Standard Student's t distribution with df degrees of freedom.\n\n A special case of the hyperbolic distribution.\n As `df` gets large, the result resembles that of the standard normal\n distribution (`standard_normal`).\n\n Parameters\n ----------\n df : int\n Degrees of freedom, should be > 0.\n size : int or tuple of ints, optional\n Output shape. Default is None, in which case a single value is\n returned.\n\n Returns\n -------\n samples : ndarray or scalar\n Drawn samples.\n\n Notes\n -----\n The probability density function for the t distribution is\n\n .. math:: P(x, df) = \\frac{\\Gamma(\\frac{df+1}{2})}{\\sqrt{\\pi df}\n \\Gamma(\\frac{df}{2})}\\Bigl( 1+\\frac{x^2}{df} \\Bigr)^{-(df+1)/2}\n\n The t test is based on an assumption that the data come from a Normal\n distribution. The t test provides a way to test whether the sample mean\n (that is the mean calculated from the data) is a good estimate of the true\n mean.\n\n The derivation of the t-distribution was forst published in 1908 by William\n Gisset while working for the Guinness Brewery in Dublin. Due to proprietary\n issues, he had to publish under a pseudonym, and so he used the name\n Student.\n\n References\n ----------\n .. [1] Dalgaard, Peter, \"Introductory Statistics With R\",\n Springer, 2002.\n .. [2] Wikipedia, \"Student's t-distribution\"\n http://en.wikipedia.org/wiki/Student's_t-distribution\n\n Examples\n --------\n From Dalgaard page 83 [1]_, suppose the daily energy intake for 11\n women in Kj is:\n\n >>> intake = np.array([5260., 5470, 5640, 6180, 6390, 6515, 6805, 7515, \\\n ... 7515, 8230, 8770])\n\n Doe""s their energy intake deviate systematically from the recommended\n value of 7725 kJ?\n\n We have 10 degrees of freedom, so is the sample mean within 95% of the\n recommended value?\n\n >>> s = np.random.standard_t(10, size=100000)\n >>> np.mean(intake)\n 6753.636363636364\n >>> intake.std(ddof=1)\n 1142.1232221373727\n\n Calculate the t statistic, setting the ddof parameter to the unbiased\n value so the divisor in the standard deviation will be degrees of\n freedom, N-1.\n\n >>> t = (np.mean(intake)-7725)/(intake.std(ddof=1)/np.sqrt(len(intake)))\n >>> import matplotlib.pyplot as plt\n >>> h = plt.hist(s, bins=100, normed=True)\n\n For a one-sided t-test, how far out in the distribution does the t\n statistic appear?\n\n >>> >>> np.sum(s<t) / float(len(s))\n 0.0090699999999999999 #random\n\n So the p-value is about 0.009, which says the null hypothesis has a\n probability of about 99% of being true.\n\n ";
+static char __pyx_k_211[] = "RandomState.vonmises (line 2156)";
+static char __pyx_k_212[] = "\n vonmises(mu, kappa, size=None)\n\n Draw samples from a von Mises distribution.\n\n Samples are drawn from a von Mises distribution with specified mode\n (mu) and dispersion (kappa), on the interval [-pi, pi].\n\n The von Mises distribution (also known as the circular normal\n distribution) is a continuous probability distribution on the unit\n circle. It may be thought of as the circular analogue of the normal\n distribution.\n\n Parameters\n ----------\n mu : float\n Mode (\"center\") of the distribution.\n kappa : float\n Dispersion of the distribution, has to be >=0.\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 : scalar or ndarray\n The returned samples, which are in the interval [-pi, pi].\n\n See Also\n --------\n scipy.stats.distributions.vonmises : probability density function,\n distribution, or cumulative density function, etc.\n\n Notes\n -----\n The probability density for the von Mises distribution is\n\n .. math:: p(x) = \\frac{e^{\\kappa cos(x-\\mu)}}{2\\pi I_0(\\kappa)},\n\n where :math:`\\mu` is the mode and :math:`\\kappa` the dispersion,\n and :math:`I_0(\\kappa)` is the modified Bessel function of order 0.\n\n The von Mises is named for Richard Edler von Mises, who was born in\n Austria-Hungary, in what is now the Ukraine. He fled to the United\n States in 1939 and became a professor at Harvard. He worked in\n probability theory, aerodynamics, fluid mechanics, and philosophy of\n science.\n\n References\n ----------\n Abramowitz, M. and Stegun, I. A. (ed.), *Handbook of Mathematical\n Functions*, New York: Dover, 1965.\n\n "" von Mises, R., *Mathematical Theory of Probability and Statistics*,\n New York: Academic Press, 1964.\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> mu, kappa = 0.0, 4.0 # mean and dispersion\n >>> s = np.random.vonmises(mu, kappa, 1000)\n\n Display the histogram of the samples, along with\n the probability density function:\n\n >>> import matplotlib.pyplot as plt\n >>> import scipy.special as sps\n >>> count, bins, ignored = plt.hist(s, 50, normed=True)\n >>> x = np.arange(-np.pi, np.pi, 2*np.pi/50.)\n >>> y = -np.exp(kappa*np.cos(x-mu))/(2*np.pi*sps.jn(0,kappa))\n >>> plt.plot(x, y/max(y), linewidth=2, color='r')\n >>> plt.show()\n\n ";
+static char __pyx_k_213[] = "RandomState.pareto (line 2250)";
+static char __pyx_k_214[] = "\n pareto(a, size=None)\n\n Draw samples from a Pareto II or Lomax distribution with specified shape.\n\n The Lomax or Pareto II distribution is a shifted Pareto distribution. The\n classical Pareto distribution can be obtained from the Lomax distribution\n by adding the location parameter m, see below. The smallest value of the\n Lomax distribution is zero while for the classical Pareto distribution it\n is m, where the standard Pareto distribution has location m=1.\n Lomax can also be considered as a simplified version of the Generalized\n Pareto distribution (available in SciPy), with the scale set to one and\n the location set to zero.\n\n The Pareto distribution must be greater than zero, and is unbounded above.\n It is also known as the \"80-20 rule\". In this distribution, 80 percent of\n the weights are in the lowest 20 percent of the range, while the other 20\n percent fill the remaining 80 percent of the range.\n\n Parameters\n ----------\n shape : float, > 0.\n Shape of the distribution.\n size : tuple of ints\n Output shape. If the given shape is, e.g., ``(m, n, k)``, then\n ``m * n * k`` samples are drawn.\n\n See Also\n --------\n scipy.stats.distributions.lomax.pdf : probability density function,\n distribution or cumulative density function, etc.\n scipy.stats.distributions.genpareto.pdf : probability density function,\n distribution or cumulative density function, etc.\n\n Notes\n -----\n The probability density for the Pareto distribution is\n\n .. math:: p(x) = \\frac{am^a}{x^{a+1}}\n\n where :math:`a` is the shape and :math:`m` the location\n\n The Pareto distribution, named after the Italian economist Vilfredo Pareto,\n is a power law probability distribution useful in many real world probl""ems.\n Outside the field of economics it is generally referred to as the Bradford\n distribution. Pareto developed the distribution to describe the\n distribution of wealth in an economy. It has also found use in insurance,\n web page access statistics, oil field sizes, and many other problems,\n including the download frequency for projects in Sourceforge [1]. It is\n one of the so-called \"fat-tailed\" distributions.\n\n\n References\n ----------\n .. [1] Francis Hunt and Paul Johnson, On the Pareto Distribution of\n Sourceforge projects.\n .. [2] Pareto, V. (1896). Course of Political Economy. Lausanne.\n .. [3] Reiss, R.D., Thomas, M.(2001), Statistical Analysis of Extreme\n Values, Birkhauser Verlag, Basel, pp 23-30.\n .. [4] Wikipedia, \"Pareto distribution\",\n http://en.wikipedia.org/wiki/Pareto_distribution\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> a, m = 3., 1. # shape and mode\n >>> s = np.random.pareto(a, 1000) + m\n\n Display the histogram of the samples, along with\n the probability density function:\n\n >>> import matplotlib.pyplot as plt\n >>> count, bins, ignored = plt.hist(s, 100, normed=True, align='center')\n >>> fit = a*m**a/bins**(a+1)\n >>> plt.plot(bins, max(count)*fit/max(fit),linewidth=2, color='r')\n >>> plt.show()\n\n ";
+static char __pyx_k_215[] = "RandomState.weibull (line 2346)";
+static char __pyx_k_216[] = "\n weibull(a, size=None)\n\n Weibull distribution.\n\n Draw samples from a 1-parameter Weibull distribution with the given\n shape parameter `a`.\n\n .. math:: X = (-ln(U))^{1/a}\n\n Here, U is drawn from the uniform distribution over (0,1].\n\n The more common 2-parameter Weibull, including a scale parameter\n :math:`\\lambda` is just :math:`X = \\lambda(-ln(U))^{1/a}`.\n\n Parameters\n ----------\n a : float\n Shape of the distribution.\n size : tuple of ints\n Output shape. If the given shape is, e.g., ``(m, n, k)``, then\n ``m * n * k`` samples are drawn.\n\n See Also\n --------\n scipy.stats.distributions.weibull : probability density function,\n distribution or cumulative density function, etc.\n\n gumbel, scipy.stats.distributions.genextreme\n\n Notes\n -----\n The Weibull (or Type III asymptotic extreme value distribution for smallest\n values, SEV Type III, or Rosin-Rammler distribution) is one of a class of\n Generalized Extreme Value (GEV) distributions used in modeling extreme\n value problems. This class includes the Gumbel and Frechet distributions.\n\n The probability density for the Weibull distribution is\n\n .. math:: p(x) = \\frac{a}\n {\\lambda}(\\frac{x}{\\lambda})^{a-1}e^{-(x/\\lambda)^a},\n\n where :math:`a` is the shape and :math:`\\lambda` the scale.\n\n The function has its peak (the mode) at\n :math:`\\lambda(\\frac{a-1}{a})^{1/a}`.\n\n When ``a = 1``, the Weibull distribution reduces to the exponential\n distribution.\n\n References\n ----------\n .. [1] Waloddi Weibull, Professor, Royal Technical University, Stockholm,\n 1939 \"A Statistical Theory Of The Strength Of Materials\",\n Ingeniorsvetenskapsakademiens Handlingar"" Nr 151, 1939,\n Generalstabens Litografiska Anstalts Forlag, Stockholm.\n .. [2] Waloddi Weibull, 1951 \"A Statistical Distribution Function of Wide\n Applicability\", Journal Of Applied Mechanics ASME Paper.\n .. [3] Wikipedia, \"Weibull distribution\",\n http://en.wikipedia.org/wiki/Weibull_distribution\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> a = 5. # shape\n >>> s = np.random.weibull(a, 1000)\n\n Display the histogram of the samples, along with\n the probability density function:\n\n >>> import matplotlib.pyplot as plt\n >>> x = np.arange(1,100.)/50.\n >>> def weib(x,n,a):\n ... return (a / n) * (x / n)**(a - 1) * np.exp(-(x / n)**a)\n\n >>> count, bins, ignored = plt.hist(np.random.weibull(5.,1000))\n >>> x = np.arange(1,100.)/50.\n >>> scale = count.max()/weib(x, 1., 5.).max()\n >>> plt.plot(x, weib(x, 1., 5.)*scale)\n >>> plt.show()\n\n ";
+static char __pyx_k_217[] = "RandomState.power (line 2446)";
+static char __pyx_k_218[] = "\n power(a, size=None)\n\n Draws samples in [0, 1] from a power distribution with positive\n exponent a - 1.\n\n Also known as the power function distribution.\n\n Parameters\n ----------\n a : float\n parameter, > 0\n size : tuple of ints\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 The returned samples lie in [0, 1].\n\n Raises\n ------\n ValueError\n If a<1.\n\n Notes\n -----\n The probability density function is\n\n .. math:: P(x; a) = ax^{a-1}, 0 \\le x \\le 1, a>0.\n\n The power function distribution is just the inverse of the Pareto\n distribution. It may also be seen as a special case of the Beta\n distribution.\n\n It is used, for example, in modeling the over-reporting of insurance\n claims.\n\n References\n ----------\n .. [1] Christian Kleiber, Samuel Kotz, \"Statistical size distributions\n in economics and actuarial sciences\", Wiley, 2003.\n .. [2] Heckert, N. A. and Filliben, James J. (2003). NIST Handbook 148:\n Dataplot Reference Manual, Volume 2: Let Subcommands and Library\n Functions\", National Institute of Standards and Technology Handbook\n Series, June 2003.\n http://www.itl.nist.gov/div898/software/dataplot/refman2/auxillar/powpdf.pdf\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> a = 5. # shape\n >>> samples = 1000\n >>> s = np.random.power(a, samples)\n\n Display the histogram of the samples, along with\n the probability density function:\n\n >>> import matplotlib.pyplot as plt\n >>> count, bins, ignored = plt.hist(s, bins=""30)\n >>> x = np.linspace(0, 1, 100)\n >>> y = a*x**(a-1.)\n >>> normed_y = samples*np.diff(bins)[0]*y\n >>> plt.plot(x, normed_y)\n >>> plt.show()\n\n Compare the power function distribution to the inverse of the Pareto.\n\n >>> from scipy import stats\n >>> rvs = np.random.power(5, 1000000)\n >>> rvsp = np.random.pareto(5, 1000000)\n >>> xx = np.linspace(0,1,100)\n >>> powpdf = stats.powerlaw.pdf(xx,5)\n\n >>> plt.figure()\n >>> plt.hist(rvs, bins=50, normed=True)\n >>> plt.plot(xx,powpdf,'r-')\n >>> plt.title('np.random.power(5)')\n\n >>> plt.figure()\n >>> plt.hist(1./(1.+rvsp), bins=50, normed=True)\n >>> plt.plot(xx,powpdf,'r-')\n >>> plt.title('inverse of 1 + np.random.pareto(5)')\n\n >>> plt.figure()\n >>> plt.hist(1./(1.+rvsp), bins=50, normed=True)\n >>> plt.plot(xx,powpdf,'r-')\n >>> plt.title('inverse of stats.pareto(5)')\n\n ";
+static char __pyx_k_219[] = "RandomState.laplace (line 2555)";
+static char __pyx_k_220[] = "\n laplace(loc=0.0, scale=1.0, size=None)\n\n Draw samples from the Laplace or double exponential distribution with\n specified location (or mean) and scale (decay).\n\n The Laplace distribution is similar to the Gaussian/normal distribution,\n but is sharper at the peak and has fatter tails. It represents the\n difference between two independent, identically distributed exponential\n random variables.\n\n Parameters\n ----------\n loc : float\n The position, :math:`\\mu`, of the distribution peak.\n scale : float\n :math:`\\lambda`, the exponential decay.\n\n Notes\n -----\n It has the probability density function\n\n .. math:: f(x; \\mu, \\lambda) = \\frac{1}{2\\lambda}\n \\exp\\left(-\\frac{|x - \\mu|}{\\lambda}\\right).\n\n The first law of Laplace, from 1774, states that the frequency of an error\n can be expressed as an exponential function of the absolute magnitude of\n the error, which leads to the Laplace distribution. For many problems in\n Economics and Health sciences, this distribution seems to model the data\n better than the standard Gaussian distribution\n\n\n References\n ----------\n .. [1] Abramowitz, M. and Stegun, I. A. (Eds.). Handbook of Mathematical\n Functions with Formulas, Graphs, and Mathematical Tables, 9th\n printing. New York: Dover, 1972.\n\n .. [2] The Laplace distribution and generalizations\n By Samuel Kotz, Tomasz J. Kozubowski, Krzysztof Podgorski,\n Birkhauser, 2001.\n\n .. [3] Weisstein, Eric W. \"Laplace Distribution.\"\n From MathWorld--A Wolfram Web Resource.\n http://mathworld.wolfram.com/LaplaceDistribution.html\n\n .. [4] Wikipedia, \"Laplace distribution\",\n http://en.wikipedia.org/wik""i/Laplace_distribution\n\n Examples\n --------\n Draw samples from the distribution\n\n >>> loc, scale = 0., 1.\n >>> s = np.random.laplace(loc, scale, 1000)\n\n Display the histogram of the samples, along with\n the probability density function:\n\n >>> import matplotlib.pyplot as plt\n >>> count, bins, ignored = plt.hist(s, 30, normed=True)\n >>> x = np.arange(-8., 8., .01)\n >>> pdf = np.exp(-abs(x-loc/scale))/(2.*scale)\n >>> plt.plot(x, pdf)\n\n Plot Gaussian for comparison:\n\n >>> g = (1/(scale * np.sqrt(2 * np.pi)) * \n ... np.exp( - (x - loc)**2 / (2 * scale**2) ))\n >>> plt.plot(x,g)\n\n ";
+static char __pyx_k_221[] = "RandomState.gumbel (line 2645)";
+static char __pyx_k_222[] = "\n gumbel(loc=0.0, scale=1.0, size=None)\n\n Gumbel distribution.\n\n Draw samples from a Gumbel distribution with specified location and scale.\n For more information on the Gumbel distribution, see Notes and References\n below.\n\n Parameters\n ----------\n loc : float\n The location of the mode of the distribution.\n scale : float\n The scale parameter of the distribution.\n size : tuple of ints\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 out : ndarray\n The samples\n\n See Also\n --------\n scipy.stats.gumbel_l\n scipy.stats.gumbel_r\n scipy.stats.genextreme\n probability density function, distribution, or cumulative density\n function, etc. for each of the above\n weibull\n\n Notes\n -----\n The Gumbel (or Smallest Extreme Value (SEV) or the Smallest Extreme Value\n Type I) distribution is one of a class of Generalized Extreme Value (GEV)\n distributions used in modeling extreme value problems. The Gumbel is a\n special case of the Extreme Value Type I distribution for maximums from\n distributions with \"exponential-like\" tails.\n\n The probability density for the Gumbel distribution is\n\n .. math:: p(x) = \\frac{e^{-(x - \\mu)/ \\beta}}{\\beta} e^{ -e^{-(x - \\mu)/\n \\beta}},\n\n where :math:`\\mu` is the mode, a location parameter, and :math:`\\beta` is\n the scale parameter.\n\n The Gumbel (named for German mathematician Emil Julius Gumbel) was used\n very early in the hydrology literature, for modeling the occurrence of\n flood events. It is also used for modeling maximum wind speed and rainfall\n rates. It is a \"fat-tailed\" distribution - the ""probability of an event in\n the tail of the distribution is larger than if one used a Gaussian, hence\n the surprisingly frequent occurrence of 100-year floods. Floods were\n initially modeled as a Gaussian process, which underestimated the frequency\n of extreme events.\n\n\n It is one of a class of extreme value distributions, the Generalized\n Extreme Value (GEV) distributions, which also includes the Weibull and\n Frechet.\n\n The function has a mean of :math:`\\mu + 0.57721\\beta` and a variance of\n :math:`\\frac{\\pi^2}{6}\\beta^2`.\n\n References\n ----------\n Gumbel, E. J., *Statistics of Extremes*, New York: Columbia University\n Press, 1958.\n\n Reiss, R.-D. and Thomas, M., *Statistical Analysis of Extreme Values from\n Insurance, Finance, Hydrology and Other Fields*, Basel: Birkhauser Verlag,\n 2001.\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> mu, beta = 0, 0.1 # location and scale\n >>> s = np.random.gumbel(mu, beta, 1000)\n\n Display the histogram of the samples, along with\n the probability density function:\n\n >>> import matplotlib.pyplot as plt\n >>> count, bins, ignored = plt.hist(s, 30, normed=True)\n >>> plt.plot(bins, (1/beta)*np.exp(-(bins - mu)/beta)\n ... * np.exp( -np.exp( -(bins - mu) /beta) ),\n ... linewidth=2, color='r')\n >>> plt.show()\n\n Show how an extreme value distribution can arise from a Gaussian process\n and compare to a Gaussian:\n\n >>> means = []\n >>> maxima = []\n >>> for i in range(0,1000) :\n ... a = np.random.normal(mu, beta, 1000)\n ... means.append(a.mean())\n ... maxima.append(a.max())\n >>> count, bins, ignored = plt.hist(maxima, 30, normed=True)\n >>> beta = np.std(maxima)*np.pi/np.sqrt(6)""\n >>> mu = np.mean(maxima) - 0.57721*beta\n >>> plt.plot(bins, (1/beta)*np.exp(-(bins - mu)/beta)\n ... * np.exp(-np.exp(-(bins - mu)/beta)),\n ... linewidth=2, color='r')\n >>> plt.plot(bins, 1/(beta * np.sqrt(2 * np.pi))\n ... * np.exp(-(bins - mu)**2 / (2 * beta**2)),\n ... linewidth=2, color='g')\n >>> plt.show()\n\n ";
+static char __pyx_k_223[] = "RandomState.logistic (line 2776)";
+static char __pyx_k_224[] = "\n logistic(loc=0.0, scale=1.0, size=None)\n\n Draw samples from a Logistic distribution.\n\n Samples are drawn from a Logistic distribution with specified\n parameters, loc (location or mean, also median), and scale (>0).\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.logistic : probability density function,\n distribution or cumulative density function, etc.\n\n Notes\n -----\n The probability density for the Logistic distribution is\n\n .. math:: P(x) = P(x) = \\frac{e^{-(x-\\mu)/s}}{s(1+e^{-(x-\\mu)/s})^2},\n\n where :math:`\\mu` = location and :math:`s` = scale.\n\n The Logistic distribution is used in Extreme Value problems where it\n can act as a mixture of Gumbel distributions, in Epidemiology, and by\n the World Chess Federation (FIDE) where it is used in the Elo ranking\n system, assuming the performance of each player is a logistically\n distributed random variable.\n\n References\n ----------\n .. [1] Reiss, R.-D. and Thomas M. (2001), Statistical Analysis of Extreme\n Values, from Insurance, Finance, Hydrology and Other Fields,\n Birkhauser Verlag, Basel, pp 132-133.\n .. [2] Weisstein, Eric W. \"Logistic Distribution.\" From\n MathWorld--A Wolfram Web Resource.\n http://mathworld.wolfram.com/LogisticDistribution.html\n .. [3] Wikipedia, \"Logistic-distribution\",\n http://en.wikipedia.org/wiki/Logistic-distribution\n\n Examples\n "" --------\n Draw samples from the distribution:\n\n >>> loc, scale = 10, 1\n >>> s = np.random.logistic(loc, scale, 10000)\n >>> count, bins, ignored = plt.hist(s, bins=50)\n\n # plot against distribution\n\n >>> def logist(x, loc, scale):\n ... return exp((loc-x)/scale)/(scale*(1+exp((loc-x)/scale))**2)\n >>> plt.plot(bins, logist(bins, loc, scale)*count.max()/\\\n ... logist(bins, loc, scale).max())\n >>> plt.show()\n\n ";
+static char __pyx_k_225[] = "RandomState.lognormal (line 2864)";
+static char __pyx_k_226[] = "\n lognormal(mean=0.0, sigma=1.0, size=None)\n\n Return samples drawn from a log-normal distribution.\n\n Draw samples from a log-normal distribution with specified mean, standard\n deviation, and shape. Note that the mean and standard deviation are not the\n values for the distribution itself, but of the underlying normal\n distribution it is derived from.\n\n\n Parameters\n ----------\n mean : float\n Mean value of the underlying normal distribution\n sigma : float, >0.\n Standard deviation of the underlying normal distribution\n size : tuple of ints\n Output shape. If the given shape is, e.g., ``(m, n, k)``, then\n ``m * n * k`` samples are drawn.\n\n See Also\n --------\n scipy.stats.lognorm : probability density function, distribution,\n cumulative density function, etc.\n\n Notes\n -----\n A variable `x` has a log-normal distribution if `log(x)` is normally\n distributed.\n\n The probability density function for the log-normal distribution is\n\n .. math:: p(x) = \\frac{1}{\\sigma x \\sqrt{2\\pi}}\n e^{(-\\frac{(ln(x)-\\mu)^2}{2\\sigma^2})}\n\n where :math:`\\mu` is the mean and :math:`\\sigma` is the standard deviation\n of the normally distributed logarithm of the variable.\n\n A log-normal distribution results if a random variable is the *product* of\n a large number of independent, identically-distributed variables in the\n same way that a normal distribution results if the variable is the *sum*\n of a large number of independent, identically-distributed variables\n (see the last example). It is one of the so-called \"fat-tailed\"\n distributions.\n\n The log-normal distribution is commonly used to model the lifespan of units\n with fatigue-stress failure modes. Since thi""s includes\n most mechanical systems, the log-normal distribution has widespread\n application.\n\n It is also commonly used to model oil field sizes, species abundance, and\n latent periods of infectious diseases.\n\n References\n ----------\n .. [1] Eckhard Limpert, Werner A. Stahel, and Markus Abbt, \"Log-normal\n Distributions across the Sciences: Keys and Clues\", May 2001\n Vol. 51 No. 5 BioScience\n http://stat.ethz.ch/~stahel/lognormal/bioscience.pdf\n .. [2] Reiss, R.D., Thomas, M.(2001), Statistical Analysis of Extreme\n Values, Birkhauser Verlag, Basel, pp 31-32.\n .. [3] Wikipedia, \"Lognormal distribution\",\n http://en.wikipedia.org/wiki/Lognormal_distribution\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> mu, sigma = 3., 1. # mean and standard deviation\n >>> s = np.random.lognormal(mu, sigma, 1000)\n\n Display the histogram of the samples, along with\n the probability density function:\n\n >>> import matplotlib.pyplot as plt\n >>> count, bins, ignored = plt.hist(s, 100, normed=True, align='mid')\n\n >>> x = np.linspace(min(bins), max(bins), 10000)\n >>> pdf = (np.exp(-(np.log(x) - mu)**2 / (2 * sigma**2))\n ... / (x * sigma * np.sqrt(2 * np.pi)))\n\n >>> plt.plot(x, pdf, linewidth=2, color='r')\n >>> plt.axis('tight')\n >>> plt.show()\n\n Demonstrate that taking the products of random samples from a uniform\n distribution can be fit well by a log-normal probability density function.\n\n >>> # Generate a thousand samples: each is the product of 100 random\n >>> # values, drawn from a normal distribution.\n >>> b = []\n >>> for i in range(1000):\n ... a = 10. + np.random.random(100)\n ... b.append(np.product(a))\n\n >>> b"" = np.array(b) / np.min(b) # scale values to be positive\n\n >>> count, bins, ignored = plt.hist(b, 100, normed=True, align='center')\n\n >>> sigma = np.std(np.log(b))\n >>> mu = np.mean(np.log(b))\n\n >>> x = np.linspace(min(bins), max(bins), 10000)\n >>> pdf = (np.exp(-(np.log(x) - mu)**2 / (2 * sigma**2))\n ... / (x * sigma * np.sqrt(2 * np.pi)))\n\n >>> plt.plot(x, pdf, color='r', linewidth=2)\n >>> plt.show()\n\n ";
+static char __pyx_k_227[] = "RandomState.rayleigh (line 2995)";
+static char __pyx_k_228[] = "\n rayleigh(scale=1.0, size=None)\n\n Draw samples from a Rayleigh distribution.\n\n The :math:`\\chi` and Weibull distributions are generalizations of the\n Rayleigh.\n\n Parameters\n ----------\n scale : scalar\n Scale, also equals the mode. Should be >= 0.\n size : int or tuple of ints, optional\n Shape of the output. Default is None, in which case a single\n value is returned.\n\n Notes\n -----\n The probability density function for the Rayleigh distribution is\n\n .. math:: P(x;scale) = \\frac{x}{scale^2}e^{\\frac{-x^2}{2 \\cdotp scale^2}}\n\n The Rayleigh distribution arises if the wind speed and wind direction are\n both gaussian variables, then the vector wind velocity forms a Rayleigh\n distribution. The Rayleigh distribution is used to model the expected\n output from wind turbines.\n\n References\n ----------\n ..[1] Brighton Webs Ltd., Rayleigh Distribution,\n http://www.brighton-webs.co.uk/distributions/rayleigh.asp\n ..[2] Wikipedia, \"Rayleigh distribution\"\n http://en.wikipedia.org/wiki/Rayleigh_distribution\n\n Examples\n --------\n Draw values from the distribution and plot the histogram\n\n >>> values = hist(np.random.rayleigh(3, 100000), bins=200, normed=True)\n\n Wave heights tend to follow a Rayleigh distribution. If the mean wave\n height is 1 meter, what fraction of waves are likely to be larger than 3\n meters?\n\n >>> meanvalue = 1\n >>> modevalue = np.sqrt(2 / np.pi) * meanvalue\n >>> s = np.random.rayleigh(modevalue, 1000000)\n\n The percentage of waves larger than 3 meters is:\n\n >>> 100.*sum(s>3)/1000000.\n 0.087300000000000003\n\n ";
+static char __pyx_k_229[] = "RandomState.wald (line 3067)";
+static char __pyx_k_230[] = "\n wald(mean, scale, size=None)\n\n Draw samples from a Wald, or Inverse Gaussian, distribution.\n\n As the scale approaches infinity, the distribution becomes more like a\n Gaussian.\n\n Some references claim that the Wald is an Inverse Gaussian with mean=1, but\n this is by no means universal.\n\n The Inverse Gaussian distribution was first studied in relationship to\n Brownian motion. In 1956 M.C.K. Tweedie used the name Inverse Gaussian\n because there is an inverse relationship between the time to cover a unit\n distance and distance covered in unit time.\n\n Parameters\n ----------\n mean : scalar\n Distribution mean, should be > 0.\n scale : scalar\n Scale parameter, should be >= 0.\n size : int or tuple of ints, optional\n Output shape. Default is None, in which case a single value is\n returned.\n\n Returns\n -------\n samples : ndarray or scalar\n Drawn sample, all greater than zero.\n\n Notes\n -----\n The probability density function for the Wald distribution is\n\n .. math:: P(x;mean,scale) = \\sqrt{\\frac{scale}{2\\pi x^3}}e^\n \\frac{-scale(x-mean)^2}{2\\cdotp mean^2x}\n\n As noted above the Inverse Gaussian distribution first arise from attempts\n to model Brownian Motion. It is also a competitor to the Weibull for use in\n reliability modeling and modeling stock returns and interest rate\n processes.\n\n References\n ----------\n ..[1] Brighton Webs Ltd., Wald Distribution,\n http://www.brighton-webs.co.uk/distributions/wald.asp\n ..[2] Chhikara, Raj S., and Folks, J. Leroy, \"The Inverse Gaussian\n Distribution: Theory : Methodology, and Applications\", CRC Press,\n 1988.\n ..[3] Wikipedia, \"Wald distributio""n\"\n http://en.wikipedia.org/wiki/Wald_distribution\n\n Examples\n --------\n Draw values from the distribution and plot the histogram:\n\n >>> import matplotlib.pyplot as plt\n >>> h = plt.hist(np.random.wald(3, 2, 100000), bins=200, normed=True)\n >>> plt.show()\n\n ";
+static char __pyx_k_231[] = "RandomState.triangular (line 3153)";
+static char __pyx_k_232[] = "\n triangular(left, mode, right, size=None)\n\n Draw samples from the triangular distribution.\n\n The triangular distribution is a continuous probability distribution with\n lower limit left, peak at mode, and upper limit right. Unlike the other\n distributions, these parameters directly define the shape of the pdf.\n\n Parameters\n ----------\n left : scalar\n Lower limit.\n mode : scalar\n The value where the peak of the distribution occurs.\n The value should fulfill the condition ``left <= mode <= right``.\n right : scalar\n Upper limit, should be larger than `left`.\n size : int or tuple of ints, optional\n Output shape. Default is None, in which case a single value is\n returned.\n\n Returns\n -------\n samples : ndarray or scalar\n The returned samples all lie in the interval [left, right].\n\n Notes\n -----\n The probability density function for the Triangular distribution is\n\n .. math:: P(x;l, m, r) = \\begin{cases}\n \\frac{2(x-l)}{(r-l)(m-l)}& \\text{for $l \\leq x \\leq m$},\\\\\n \\frac{2(m-x)}{(r-l)(r-m)}& \\text{for $m \\leq x \\leq r$},\\\\\n 0& \\text{otherwise}.\n \\end{cases}\n\n The triangular distribution is often used in ill-defined problems where the\n underlying distribution is not known, but some knowledge of the limits and\n mode exists. Often it is used in simulations.\n\n References\n ----------\n ..[1] Wikipedia, \"Triangular distribution\"\n http://en.wikipedia.org/wiki/Triangular_distribution\n\n Examples\n --------\n Draw values from the distribution and plot the histogram:\n\n >>> import matplotlib.pyplot as plt\n >>> h = plt.hist(np.random.triangular(-3, 0, 8, 100000), bins=2""00,\n ... normed=True)\n >>> plt.show()\n\n ";
+static char __pyx_k_233[] = "RandomState.binomial (line 3241)";
+static char __pyx_k_234[] = "\n binomial(n, p, size=None)\n\n Draw samples from a binomial distribution.\n\n Samples are drawn from a Binomial distribution with specified\n parameters, n trials and p probability of success where\n n an integer > 0 and p is in the interval [0,1]. (n may be\n input as a float, but it is truncated to an integer in use)\n\n Parameters\n ----------\n n : float (but truncated to an integer)\n parameter, > 0.\n p : float\n parameter, >= 0 and <=1.\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.binom : probability density function,\n distribution or cumulative density function, etc.\n\n Notes\n -----\n The probability density for the Binomial distribution is\n\n .. math:: P(N) = \\binom{n}{N}p^N(1-p)^{n-N},\n\n where :math:`n` is the number of trials, :math:`p` is the probability\n of success, and :math:`N` is the number of successes.\n\n When estimating the standard error of a proportion in a population by\n using a random sample, the normal distribution works well unless the\n product p*n <=5, where p = population proportion estimate, and n =\n number of samples, in which case the binomial distribution is used\n instead. For example, a sample of 15 people shows 4 who are left\n handed, and 11 who are right handed. Then p = 4/15 = 27%. 0.27*15 = 4,\n so the binomial distribution should be used in this case.\n\n References\n ----------\n .. [1] Dalgaard, Peter, \"Introductory Statistics with R\",\n Springer-Verlag, 2002.\n "" .. [2] Glantz, Stanton A. \"Primer of Biostatistics.\", McGraw-Hill,\n Fifth Edition, 2002.\n .. [3] Lentner, Marvin, \"Elementary Applied Statistics\", Bogden\n and Quigley, 1972.\n .. [4] Weisstein, Eric W. \"Binomial Distribution.\" From MathWorld--A\n Wolfram Web Resource.\n http://mathworld.wolfram.com/BinomialDistribution.html\n .. [5] Wikipedia, \"Binomial-distribution\",\n http://en.wikipedia.org/wiki/Binomial_distribution\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> n, p = 10, .5 # number of trials, probability of each trial\n >>> s = np.random.binomial(n, p, 1000)\n # result of flipping a coin 10 times, tested 1000 times.\n\n A real world example. A company drills 9 wild-cat oil exploration\n wells, each with an estimated probability of success of 0.1. All nine\n wells fail. What is the probability of that happening?\n\n Let's do 20,000 trials of the model, and count the number that\n generate zero positive results.\n\n >>> sum(np.random.binomial(9,0.1,20000)==0)/20000.\n answer = 0.38885, or 38%.\n\n ";
+static char __pyx_k_235[] = "RandomState.negative_binomial (line 3349)";
+static char __pyx_k_236[] = "\n negative_binomial(n, p, size=None)\n\n Draw samples from a negative_binomial distribution.\n\n Samples are drawn from a negative_Binomial distribution with specified\n parameters, `n` trials and `p` probability of success where `n` is an\n integer > 0 and `p` is in the interval [0, 1].\n\n Parameters\n ----------\n n : int\n Parameter, > 0.\n p : float\n Parameter, >= 0 and <=1.\n size : int or tuple of ints\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 : int or ndarray of ints\n Drawn samples.\n\n Notes\n -----\n The probability density for the Negative Binomial distribution is\n\n .. math:: P(N;n,p) = \\binom{N+n-1}{n-1}p^{n}(1-p)^{N},\n\n where :math:`n-1` is the number of successes, :math:`p` is the probability\n of success, and :math:`N+n-1` is the number of trials.\n\n The negative binomial distribution gives the probability of n-1 successes\n and N failures in N+n-1 trials, and success on the (N+n)th trial.\n\n If one throws a die repeatedly until the third time a \"1\" appears, then the\n probability distribution of the number of non-\"1\"s that appear before the\n third \"1\" is a negative binomial distribution.\n\n References\n ----------\n .. [1] Weisstein, Eric W. \"Negative Binomial Distribution.\" From\n MathWorld--A Wolfram Web Resource.\n http://mathworld.wolfram.com/NegativeBinomialDistribution.html\n .. [2] Wikipedia, \"Negative binomial distribution\",\n http://en.wikipedia.org/wiki/Negative_binomial_distribution\n\n Examples\n --------\n Draw samples from the distribution:\n\n A real world example. A company drills wild-cat oil exploration well""s, each\n with an estimated probability of success of 0.1. What is the probability\n of having one success for each successive well, that is what is the\n probability of a single success after drilling 5 wells, after 6 wells,\n etc.?\n\n >>> s = np.random.negative_binomial(1, 0.1, 100000)\n >>> for i in range(1, 11):\n ... probability = sum(s<i) / 100000.\n ... print i, \"wells drilled, probability of one success =\", probability\n\n ";
+static char __pyx_k_237[] = "RandomState.poisson (line 3444)";
+static char __pyx_k_238[] = "\n poisson(lam=1.0, size=None)\n\n Draw samples from a Poisson distribution.\n\n The Poisson distribution is the limit of the Binomial\n distribution for large N.\n\n Parameters\n ----------\n lam : float\n Expectation of interval, should be >= 0.\n size : int or tuple of ints, optional\n Output shape. If the given shape is, e.g., ``(m, n, k)``, then\n ``m * n * k`` samples are drawn.\n\n Notes\n -----\n The Poisson distribution\n\n .. math:: f(k; \\lambda)=\\frac{\\lambda^k e^{-\\lambda}}{k!}\n\n For events with an expected separation :math:`\\lambda` the Poisson\n distribution :math:`f(k; \\lambda)` describes the probability of\n :math:`k` events occurring within the observed interval :math:`\\lambda`.\n\n Because the output is limited to the range of the C long type, a\n ValueError is raised when `lam` is within 10 sigma of the maximum\n representable value.\n\n References\n ----------\n .. [1] Weisstein, Eric W. \"Poisson Distribution.\" From MathWorld--A Wolfram\n Web Resource. http://mathworld.wolfram.com/PoissonDistribution.html\n .. [2] Wikipedia, \"Poisson distribution\",\n http://en.wikipedia.org/wiki/Poisson_distribution\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> import numpy as np\n >>> s = np.random.poisson(5, 10000)\n\n Display histogram of the sample:\n\n >>> import matplotlib.pyplot as plt\n >>> count, bins, ignored = plt.hist(s, 14, normed=True)\n >>> plt.show()\n\n ";
+static char __pyx_k_239[] = "RandomState.zipf (line 3515)";
+static char __pyx_k_240[] = "\n zipf(a, size=None)\n\n Draw samples from a Zipf distribution.\n\n Samples are drawn from a Zipf distribution with specified parameter\n `a` > 1.\n\n The Zipf distribution (also known as the zeta distribution) is a\n continuous probability distribution that satisfies Zipf's law: the\n frequency of an item is inversely proportional to its rank in a\n frequency table.\n\n Parameters\n ----------\n a : float > 1\n Distribution parameter.\n size : int or tuple of int, optional\n Output shape. If the given shape is, e.g., ``(m, n, k)``, then\n ``m * n * k`` samples are drawn; a single integer is equivalent in\n its result to providing a mono-tuple, i.e., a 1-D array of length\n *size* is returned. The default is None, in which case a single\n scalar is returned.\n\n Returns\n -------\n samples : scalar or ndarray\n The returned samples are greater than or equal to one.\n\n See Also\n --------\n scipy.stats.distributions.zipf : probability density function,\n distribution, or cumulative density function, etc.\n\n Notes\n -----\n The probability density for the Zipf distribution is\n\n .. math:: p(x) = \\frac{x^{-a}}{\\zeta(a)},\n\n where :math:`\\zeta` is the Riemann Zeta function.\n\n It is named for the American linguist George Kingsley Zipf, who noted\n that the frequency of any word in a sample of a language is inversely\n proportional to its rank in the frequency table.\n\n References\n ----------\n Zipf, G. K., *Selected Studies of the Principle of Relative Frequency\n in Language*, Cambridge, MA: Harvard Univ. Press, 1932.\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> a = 2. # parameter\n >>> s = np.random.zipf""(a, 1000)\n\n Display the histogram of the samples, along with\n the probability density function:\n\n >>> import matplotlib.pyplot as plt\n >>> import scipy.special as sps\n Truncate s values at 50 so plot is interesting\n >>> count, bins, ignored = plt.hist(s[s<50], 50, normed=True)\n >>> x = np.arange(1., 50.)\n >>> y = x**(-a)/sps.zetac(a)\n >>> plt.plot(x, y/max(y), linewidth=2, color='r')\n >>> plt.show()\n\n ";
+static char __pyx_k_241[] = "RandomState.geometric (line 3603)";
+static char __pyx_k_242[] = "\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_243[] = "RandomState.hypergeometric (line 3669)";
+static char __pyx_k_244[] = "\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_245[] = "RandomState.logseries (line 3788)";
+static char __pyx_k_246[] = "\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_247[] = "RandomState.multivariate_normal (line 3883)";
+static char __pyx_k_248[] = "\n multivariate_normal(mean, cov[, size])\n\n Draw random samples from a multivariate normal distribution.\n\n The multivariate normal, multinormal or Gaussian distribution is a\n generalization of the one-dimensional normal distribution to higher\n dimensions. Such a distribution is specified by its mean and\n covariance matrix. These parameters are analogous to the mean\n (average or \"center\") and variance (standard deviation, or \"width,\"\n squared) of the one-dimensional normal distribution.\n\n Parameters\n ----------\n mean : 1-D array_like, of length N\n Mean of the N-dimensional distribution.\n cov : 2-D array_like, of shape (N, N)\n Covariance matrix of the distribution. Must be symmetric and\n positive semi-definite for \"physically meaningful\" results.\n size : tuple of ints, optional\n Given a shape of, for example, ``(m,n,k)``, ``m*n*k`` samples are\n generated, and packed in an `m`-by-`n`-by-`k` arrangement. Because\n each sample is `N`-dimensional, the output shape is ``(m,n,k,N)``.\n If no shape is specified, a single (`N`-D) sample is returned.\n\n Returns\n -------\n out : ndarray\n The drawn samples, of shape *size*, if that was provided. If not,\n the shape is ``(N,)``.\n\n In other words, each entry ``out[i,j,...,:]`` is an N-dimensional\n value drawn from the distribution.\n\n Notes\n -----\n The mean is a coordinate in N-dimensional space, which represents the\n location where samples are most likely to be generated. This is\n analogous to the peak of the bell curve for the one-dimensional or\n univariate normal distribution.\n\n Covariance indicates the level to which two variables vary together.\n From the multivariate normal distribution, we draw ""N-dimensional\n samples, :math:`X = [x_1, x_2, ... x_N]`. The covariance matrix\n element :math:`C_{ij}` is the covariance of :math:`x_i` and :math:`x_j`.\n The element :math:`C_{ii}` is the variance of :math:`x_i` (i.e. its\n \"spread\").\n\n Instead of specifying the full covariance matrix, popular\n approximations include:\n\n - Spherical covariance (*cov* is a multiple of the identity matrix)\n - Diagonal covariance (*cov* has non-negative elements, and only on\n the diagonal)\n\n This geometrical property can be seen in two dimensions by plotting\n generated data-points:\n\n >>> mean = [0,0]\n >>> cov = [[1,0],[0,100]] # diagonal covariance, points lie on x or y-axis\n\n >>> import matplotlib.pyplot as plt\n >>> x,y = np.random.multivariate_normal(mean,cov,5000).T\n >>> plt.plot(x,y,'x'); plt.axis('equal'); plt.show()\n\n Note that the covariance matrix must be non-negative definite.\n\n References\n ----------\n Papoulis, A., *Probability, Random Variables, and Stochastic Processes*,\n 3rd ed., New York: McGraw-Hill, 1991.\n\n Duda, R. O., Hart, P. E., and Stork, D. G., *Pattern Classification*,\n 2nd ed., New York: Wiley, 2001.\n\n Examples\n --------\n >>> mean = (1,2)\n >>> cov = [[1,0],[1,0]]\n >>> x = np.random.multivariate_normal(mean,cov,(3,3))\n >>> x.shape\n (3, 3, 2)\n\n The following is probably true, given that 0.6 is roughly twice the\n standard deviation:\n\n >>> print list( (x[0,0,:] - mean) < 0.6 )\n [True, True]\n\n ";
+static char __pyx_k_249[] = "RandomState.multinomial (line 4015)";
+static char __pyx_k_250[] = "\n multinomial(n, pvals, size=None)\n\n Draw samples from a multinomial distribution.\n\n The multinomial distribution is a multivariate generalisation of the\n binomial distribution. Take an experiment with one of ``p``\n possible outcomes. An example of such an experiment is throwing a dice,\n where the outcome can be 1 through 6. Each sample drawn from the\n distribution represents `n` such experiments. Its values,\n ``X_i = [X_0, X_1, ..., X_p]``, represent the number of times the outcome\n was ``i``.\n\n Parameters\n ----------\n n : int\n Number of experiments.\n pvals : sequence of floats, length p\n Probabilities of each of the ``p`` different outcomes. These\n should sum to 1 (however, the last element is always assumed to\n account for the remaining probability, as long as\n ``sum(pvals[:-1]) <= 1)``.\n size : tuple of ints\n Given a `size` of ``(M, N, K)``, then ``M*N*K`` samples are drawn,\n and the output shape becomes ``(M, N, K, p)``, since each sample\n has shape ``(p,)``.\n\n Examples\n --------\n Throw a dice 20 times:\n\n >>> np.random.multinomial(20, [1/6.]*6, size=1)\n array([[4, 1, 7, 5, 2, 1]])\n\n It landed 4 times on 1, once on 2, etc.\n\n Now, throw the dice 20 times, and 20 times again:\n\n >>> np.random.multinomial(20, [1/6.]*6, size=2)\n array([[3, 4, 3, 3, 4, 3],\n [2, 4, 3, 4, 0, 7]])\n\n For the first run, we threw 3 times 1, 4 times 2, etc. For the second,\n we threw 2 times 1, 4 times 2, etc.\n\n A loaded dice is more likely to land on number 6:\n\n >>> np.random.multinomial(100, [1/7.]*5)\n array([13, 16, 13, 16, 42])\n\n ";
+static char __pyx_k_251[] = "RandomState.dirichlet (line 4108)";
+static char __pyx_k_252[] = "\n dirichlet(alpha, size=None)\n\n Draw samples from the Dirichlet distribution.\n\n Draw `size` samples of dimension k from a Dirichlet distribution. A\n Dirichlet-distributed random variable can be seen as a multivariate\n generalization of a Beta distribution. Dirichlet pdf is the conjugate\n prior of a multinomial in Bayesian inference.\n\n Parameters\n ----------\n alpha : array\n Parameter of the distribution (k dimension for sample of\n dimension k).\n size : array\n Number of samples to draw.\n\n Returns\n -------\n samples : ndarray,\n The drawn samples, of shape (alpha.ndim, size).\n\n Notes\n -----\n .. math:: X \\approx \\prod_{i=1}^{k}{x^{\\alpha_i-1}_i}\n\n Uses the following property for computation: for each dimension,\n draw a random sample y_i from a standard gamma generator of shape\n `alpha_i`, then\n :math:`X = \\frac{1}{\\sum_{i=1}^k{y_i}} (y_1, \\ldots, y_n)` is\n Dirichlet distributed.\n\n References\n ----------\n .. [1] David McKay, \"Information Theory, Inference and Learning\n Algorithms,\" chapter 23,\n http://www.inference.phy.cam.ac.uk/mackay/\n .. [2] Wikipedia, \"Dirichlet distribution\",\n http://en.wikipedia.org/wiki/Dirichlet_distribution\n\n Examples\n --------\n Taking an example cited in Wikipedia, this distribution can be used if\n one wanted to cut strings (each of initial length 1.0) into K pieces\n with different lengths, where each piece had, on average, a designated\n average length, but allowing some variation in the relative sizes of the\n pieces.\n\n >>> s = np.random.dirichlet((10, 5, 3), 20).transpose()\n\n >>> plt.barh(range(20), s[0])\n >>> plt.barh(range(20), s[1], left=s[0], color='g')""\n >>> plt.barh(range(20), s[2], left=s[0]+s[1], color='r')\n >>> plt.title(\"Lengths of Strings\")\n\n ";
+static char __pyx_k_253[] = "RandomState.shuffle (line 4224)";
+static char __pyx_k_254[] = "\n shuffle(x)\n\n Modify a sequence in-place by shuffling its contents.\n\n Parameters\n ----------\n x : array_like\n The array or list to be shuffled.\n\n Returns\n -------\n None\n\n Examples\n --------\n >>> arr = np.arange(10)\n >>> np.random.shuffle(arr)\n >>> arr\n [1 7 5 2 9 4 3 6 0 8]\n\n This function only shuffles the array along the first index of a\n multi-dimensional array:\n\n >>> arr = np.arange(9).reshape((3, 3))\n >>> np.random.shuffle(arr)\n >>> arr\n array([[3, 4, 5],\n [6, 7, 8],\n [0, 1, 2]])\n\n ";
+static char __pyx_k_255[] = "RandomState.permutation (line 4286)";
+static char __pyx_k_256[] = "\n permutation(x)\n\n Randomly permute a sequence, or return a permuted range.\n\n If `x` is a multi-dimensional array, it is only shuffled along its\n first index.\n\n Parameters\n ----------\n x : int or array_like\n If `x` is an integer, randomly permute ``np.arange(x)``.\n If `x` is an array, make a copy and shuffle the elements\n randomly.\n\n Returns\n -------\n out : ndarray\n Permuted sequence or array range.\n\n Examples\n --------\n >>> np.random.permutation(10)\n array([1, 7, 4, 3, 0, 9, 2, 5, 8, 6])\n\n >>> np.random.permutation([1, 4, 9, 12, 15])\n array([15, 1, 9, 4, 12])\n\n >>> arr = np.arange(9).reshape((3, 3))\n >>> np.random.permutation(arr)\n array([[6, 7, 8],\n [0, 1, 2],\n [3, 4, 5]])\n\n ";
static char __pyx_k__df[] = "df";
static char __pyx_k__mu[] = "mu";
static char __pyx_k__nd[] = "nd";
@@ -694,6 +742,7 @@ static char __pyx_k__key[] = "key";
static char __pyx_k__lam[] = "lam";
static char __pyx_k__loc[] = "loc";
static char __pyx_k__low[] = "low";
+static char __pyx_k__max[] = "max";
static char __pyx_k__pos[] = "pos";
static char __pyx_k__svd[] = "svd";
static char __pyx_k__beta[] = "beta";
@@ -723,6 +772,7 @@ static char __pyx_k__empty[] = "empty";
static char __pyx_k__equal[] = "equal";
static char __pyx_k__gamma[] = "gamma";
static char __pyx_k__gauss[] = "gauss";
+static char __pyx_k__iinfo[] = "iinfo";
static char __pyx_k__kappa[] = "kappa";
static char __pyx_k__ngood[] = "ngood";
static char __pyx_k__numpy[] = "numpy";
@@ -734,6 +784,7 @@ static char __pyx_k__scale[] = "scale";
static char __pyx_k__shape[] = "shape";
static char __pyx_k__sigma[] = "sigma";
static char __pyx_k__zeros[] = "zeros";
+static char __pyx_k__append[] = "append";
static char __pyx_k__arange[] = "arange";
static char __pyx_k__gumbel[] = "gumbel";
static char __pyx_k__normal[] = "normal";
@@ -761,7 +812,6 @@ static char __pyx_k__logistic[] = "logistic";
static char __pyx_k__multiply[] = "multiply";
static char __pyx_k__rayleigh[] = "rayleigh";
static char __pyx_k__subtract[] = "subtract";
-static char __pyx_k__tomaxint[] = "tomaxint";
static char __pyx_k__vonmises[] = "vonmises";
static char __pyx_k__TypeError[] = "TypeError";
static char __pyx_k__chisquare[] = "chisquare";
@@ -777,7 +827,6 @@ static char __pyx_k__dimensions[] = "dimensions";
static char __pyx_k__less_equal[] = "less_equal";
static char __pyx_k__standard_t[] = "standard_t";
static char __pyx_k__triangular[] = "triangular";
-static char __pyx_k__RandomState[] = "RandomState";
static char __pyx_k__exponential[] = "exponential";
static char __pyx_k__multinomial[] = "multinomial";
static char __pyx_k__permutation[] = "permutation";
@@ -787,6 +836,7 @@ static char __pyx_k__random_sample[] = "random_sample";
static char __pyx_k__hypergeometric[] = "hypergeometric";
static char __pyx_k__internal_state[] = "internal_state";
static char __pyx_k__standard_gamma[] = "standard_gamma";
+static char __pyx_k__poisson_lam_max[] = "poisson_lam_max";
static char __pyx_k__random_integers[] = "random_integers";
static char __pyx_k__standard_cauchy[] = "standard_cauchy";
static char __pyx_k__standard_normal[] = "standard_normal";
@@ -794,98 +844,136 @@ static char __pyx_k__negative_binomial[] = "negative_binomial";
static char __pyx_k____RandomState_ctor[] = "__RandomState_ctor";
static char __pyx_k__multivariate_normal[] = "multivariate_normal";
static PyObject *__pyx_kp_s_1;
-static PyObject *__pyx_kp_s_10;
-static PyObject *__pyx_kp_u_100;
-static PyObject *__pyx_kp_u_101;
-static PyObject *__pyx_kp_u_102;
-static PyObject *__pyx_kp_u_103;
-static PyObject *__pyx_kp_u_104;
-static PyObject *__pyx_kp_u_105;
-static PyObject *__pyx_kp_u_106;
-static PyObject *__pyx_kp_u_107;
+static PyObject *__pyx_kp_s_101;
+static PyObject *__pyx_kp_s_103;
+static PyObject *__pyx_kp_s_105;
static PyObject *__pyx_kp_s_11;
+static PyObject *__pyx_kp_s_110;
+static PyObject *__pyx_kp_s_112;
+static PyObject *__pyx_kp_s_114;
+static PyObject *__pyx_kp_s_126;
+static PyObject *__pyx_kp_s_128;
static PyObject *__pyx_kp_s_13;
-static PyObject *__pyx_kp_s_15;
-static PyObject *__pyx_kp_s_16;
-static PyObject *__pyx_kp_s_17;
-static PyObject *__pyx_kp_s_18;
+static PyObject *__pyx_kp_s_131;
+static PyObject *__pyx_kp_s_133;
+static PyObject *__pyx_kp_s_136;
+static PyObject *__pyx_kp_s_138;
+static PyObject *__pyx_kp_s_142;
+static PyObject *__pyx_kp_s_144;
+static PyObject *__pyx_kp_s_146;
+static PyObject *__pyx_kp_s_148;
+static PyObject *__pyx_kp_s_154;
+static PyObject *__pyx_kp_s_156;
+static PyObject *__pyx_kp_s_160;
+static PyObject *__pyx_kp_s_162;
+static PyObject *__pyx_kp_s_164;
+static PyObject *__pyx_n_s_166;
+static PyObject *__pyx_kp_s_167;
+static PyObject *__pyx_n_s_171;
+static PyObject *__pyx_n_s_172;
+static PyObject *__pyx_kp_u_173;
+static PyObject *__pyx_kp_u_174;
+static PyObject *__pyx_kp_u_175;
+static PyObject *__pyx_kp_u_176;
+static PyObject *__pyx_kp_u_177;
+static PyObject *__pyx_kp_u_178;
+static PyObject *__pyx_kp_u_179;
+static PyObject *__pyx_kp_u_180;
+static PyObject *__pyx_kp_u_181;
+static PyObject *__pyx_kp_u_182;
+static PyObject *__pyx_kp_u_183;
+static PyObject *__pyx_kp_u_184;
+static PyObject *__pyx_kp_u_185;
+static PyObject *__pyx_kp_u_186;
+static PyObject *__pyx_kp_u_187;
+static PyObject *__pyx_kp_u_188;
+static PyObject *__pyx_kp_u_189;
static PyObject *__pyx_kp_s_19;
-static PyObject *__pyx_kp_s_2;
-static PyObject *__pyx_kp_s_20;
-static PyObject *__pyx_kp_s_21;
+static PyObject *__pyx_kp_u_190;
+static PyObject *__pyx_kp_u_191;
+static PyObject *__pyx_kp_u_192;
+static PyObject *__pyx_kp_u_193;
+static PyObject *__pyx_kp_u_194;
+static PyObject *__pyx_kp_u_195;
+static PyObject *__pyx_kp_u_196;
+static PyObject *__pyx_kp_u_197;
+static PyObject *__pyx_kp_u_198;
+static PyObject *__pyx_kp_u_199;
+static PyObject *__pyx_kp_u_200;
+static PyObject *__pyx_kp_u_201;
+static PyObject *__pyx_kp_u_202;
+static PyObject *__pyx_kp_u_203;
+static PyObject *__pyx_kp_u_204;
+static PyObject *__pyx_kp_u_205;
+static PyObject *__pyx_kp_u_206;
+static PyObject *__pyx_kp_u_207;
+static PyObject *__pyx_kp_u_208;
+static PyObject *__pyx_kp_u_209;
+static PyObject *__pyx_kp_u_210;
+static PyObject *__pyx_kp_u_211;
+static PyObject *__pyx_kp_u_212;
+static PyObject *__pyx_kp_u_213;
+static PyObject *__pyx_kp_u_214;
+static PyObject *__pyx_kp_u_215;
+static PyObject *__pyx_kp_u_216;
+static PyObject *__pyx_kp_u_217;
+static PyObject *__pyx_kp_u_218;
+static PyObject *__pyx_kp_u_219;
static PyObject *__pyx_kp_s_22;
-static PyObject *__pyx_kp_s_3;
+static PyObject *__pyx_kp_u_220;
+static PyObject *__pyx_kp_u_221;
+static PyObject *__pyx_kp_u_222;
+static PyObject *__pyx_kp_u_223;
+static PyObject *__pyx_kp_u_224;
+static PyObject *__pyx_kp_u_225;
+static PyObject *__pyx_kp_u_226;
+static PyObject *__pyx_kp_u_227;
+static PyObject *__pyx_kp_u_228;
+static PyObject *__pyx_kp_u_229;
+static PyObject *__pyx_kp_u_230;
+static PyObject *__pyx_kp_u_231;
+static PyObject *__pyx_kp_u_232;
+static PyObject *__pyx_kp_u_233;
+static PyObject *__pyx_kp_u_234;
+static PyObject *__pyx_kp_u_235;
+static PyObject *__pyx_kp_u_236;
+static PyObject *__pyx_kp_u_237;
+static PyObject *__pyx_kp_u_238;
+static PyObject *__pyx_kp_u_239;
+static PyObject *__pyx_kp_s_24;
+static PyObject *__pyx_kp_u_240;
+static PyObject *__pyx_kp_u_241;
+static PyObject *__pyx_kp_u_242;
+static PyObject *__pyx_kp_u_243;
+static PyObject *__pyx_kp_u_244;
+static PyObject *__pyx_kp_u_245;
+static PyObject *__pyx_kp_u_246;
+static PyObject *__pyx_kp_u_247;
+static PyObject *__pyx_kp_u_248;
+static PyObject *__pyx_kp_u_249;
+static PyObject *__pyx_kp_u_250;
+static PyObject *__pyx_kp_u_251;
+static PyObject *__pyx_kp_u_252;
+static PyObject *__pyx_kp_u_253;
+static PyObject *__pyx_kp_u_254;
+static PyObject *__pyx_kp_u_255;
+static PyObject *__pyx_kp_u_256;
static PyObject *__pyx_kp_s_31;
-static PyObject *__pyx_kp_s_32;
-static PyObject *__pyx_kp_s_34;
-static PyObject *__pyx_kp_s_35;
-static PyObject *__pyx_kp_s_36;
-static PyObject *__pyx_kp_s_37;
-static PyObject *__pyx_kp_s_38;
-static PyObject *__pyx_kp_s_39;
-static PyObject *__pyx_kp_s_4;
-static PyObject *__pyx_kp_s_40;
static PyObject *__pyx_kp_s_41;
-static PyObject *__pyx_kp_s_42;
-static PyObject *__pyx_kp_s_44;
+static PyObject *__pyx_kp_s_43;
static PyObject *__pyx_kp_s_45;
-static PyObject *__pyx_kp_s_46;
-static PyObject *__pyx_kp_s_47;
static PyObject *__pyx_kp_s_48;
-static PyObject *__pyx_kp_s_49;
-static PyObject *__pyx_kp_s_50;
-static PyObject *__pyx_kp_s_51;
-static PyObject *__pyx_kp_s_52;
static PyObject *__pyx_kp_s_53;
-static PyObject *__pyx_kp_s_54;
-static PyObject *__pyx_kp_s_55;
-static PyObject *__pyx_kp_s_56;
-static PyObject *__pyx_n_s_57;
-static PyObject *__pyx_kp_s_58;
-static PyObject *__pyx_n_s_59;
-static PyObject *__pyx_n_s_60;
-static PyObject *__pyx_kp_u_61;
-static PyObject *__pyx_kp_u_62;
-static PyObject *__pyx_kp_u_63;
-static PyObject *__pyx_kp_u_64;
-static PyObject *__pyx_kp_u_65;
-static PyObject *__pyx_kp_u_66;
-static PyObject *__pyx_kp_u_67;
-static PyObject *__pyx_kp_u_68;
-static PyObject *__pyx_kp_u_69;
-static PyObject *__pyx_kp_u_70;
-static PyObject *__pyx_kp_u_71;
-static PyObject *__pyx_kp_u_72;
-static PyObject *__pyx_kp_u_73;
-static PyObject *__pyx_kp_u_74;
-static PyObject *__pyx_kp_u_75;
-static PyObject *__pyx_kp_u_76;
-static PyObject *__pyx_kp_u_77;
-static PyObject *__pyx_kp_u_78;
-static PyObject *__pyx_kp_u_79;
-static PyObject *__pyx_kp_u_80;
-static PyObject *__pyx_kp_u_81;
-static PyObject *__pyx_kp_u_82;
-static PyObject *__pyx_kp_u_83;
-static PyObject *__pyx_kp_u_84;
-static PyObject *__pyx_kp_u_85;
-static PyObject *__pyx_kp_u_86;
-static PyObject *__pyx_kp_u_87;
-static PyObject *__pyx_kp_u_88;
-static PyObject *__pyx_kp_u_89;
+static PyObject *__pyx_kp_s_57;
+static PyObject *__pyx_kp_s_59;
+static PyObject *__pyx_kp_s_64;
+static PyObject *__pyx_kp_s_87;
+static PyObject *__pyx_kp_s_89;
static PyObject *__pyx_kp_s_9;
-static PyObject *__pyx_kp_u_90;
-static PyObject *__pyx_kp_u_91;
-static PyObject *__pyx_kp_u_92;
-static PyObject *__pyx_kp_u_93;
-static PyObject *__pyx_kp_u_94;
-static PyObject *__pyx_kp_u_95;
-static PyObject *__pyx_kp_u_96;
-static PyObject *__pyx_kp_u_97;
-static PyObject *__pyx_kp_u_98;
-static PyObject *__pyx_kp_u_99;
+static PyObject *__pyx_kp_s_93;
+static PyObject *__pyx_kp_s_95;
+static PyObject *__pyx_kp_s_98;
static PyObject *__pyx_n_s__MT19937;
-static PyObject *__pyx_n_s__RandomState;
static PyObject *__pyx_n_s__TypeError;
static PyObject *__pyx_n_s__ValueError;
static PyObject *__pyx_n_s____RandomState_ctor;
@@ -896,6 +984,7 @@ static PyObject *__pyx_n_s__a;
static PyObject *__pyx_n_s__add;
static PyObject *__pyx_n_s__alpha;
static PyObject *__pyx_n_s__any;
+static PyObject *__pyx_n_s__append;
static PyObject *__pyx_n_s__arange;
static PyObject *__pyx_n_s__array;
static PyObject *__pyx_n_s__asarray;
@@ -929,10 +1018,12 @@ static PyObject *__pyx_n_s__gumbel;
static PyObject *__pyx_n_s__has_gauss;
static PyObject *__pyx_n_s__high;
static PyObject *__pyx_n_s__hypergeometric;
+static PyObject *__pyx_n_s__iinfo;
static PyObject *__pyx_n_s__integer;
static PyObject *__pyx_n_s__internal_state;
static PyObject *__pyx_n_s__kappa;
static PyObject *__pyx_n_s__key;
+static PyObject *__pyx_n_s__l;
static PyObject *__pyx_n_s__lam;
static PyObject *__pyx_n_s__laplace;
static PyObject *__pyx_n_s__left;
@@ -943,6 +1034,7 @@ static PyObject *__pyx_n_s__logistic;
static PyObject *__pyx_n_s__lognormal;
static PyObject *__pyx_n_s__logseries;
static PyObject *__pyx_n_s__low;
+static PyObject *__pyx_n_s__max;
static PyObject *__pyx_n_s__mean;
static PyObject *__pyx_n_s__mode;
static PyObject *__pyx_n_s__mu;
@@ -964,6 +1056,7 @@ static PyObject *__pyx_n_s__p;
static PyObject *__pyx_n_s__pareto;
static PyObject *__pyx_n_s__permutation;
static PyObject *__pyx_n_s__poisson;
+static PyObject *__pyx_n_s__poisson_lam_max;
static PyObject *__pyx_n_s__pos;
static PyObject *__pyx_n_s__power;
static PyObject *__pyx_n_s__pvals;
@@ -990,7 +1083,6 @@ static PyObject *__pyx_n_s__standard_normal;
static PyObject *__pyx_n_s__standard_t;
static PyObject *__pyx_n_s__subtract;
static PyObject *__pyx_n_s__svd;
-static PyObject *__pyx_n_s__tomaxint;
static PyObject *__pyx_n_s__triangular;
static PyObject *__pyx_n_s__uint;
static PyObject *__pyx_n_s__uint32;
@@ -1002,23 +1094,134 @@ static PyObject *__pyx_n_s__zeros;
static PyObject *__pyx_n_s__zipf;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
+static PyObject *__pyx_int_10;
static PyObject *__pyx_int_624;
-static PyObject *__pyx_k_5;
-static PyObject *__pyx_k_6;
-static PyObject *__pyx_k_7;
-static PyObject *__pyx_k_8;
-static PyObject *__pyx_k_12;
-static PyObject *__pyx_k_14;
-static PyObject *__pyx_k_23;
-static PyObject *__pyx_k_24;
-static PyObject *__pyx_k_25;
-static PyObject *__pyx_k_26;
-static PyObject *__pyx_k_27;
+static PyObject *__pyx_k_15;
+static PyObject *__pyx_k_16;
+static PyObject *__pyx_k_17;
+static PyObject *__pyx_k_18;
static PyObject *__pyx_k_28;
-static PyObject *__pyx_k_29;
-static PyObject *__pyx_k_30;
-static PyObject *__pyx_k_33;
-static PyObject *__pyx_k_43;
+static PyObject *__pyx_k_34;
+static PyObject *__pyx_k_73;
+static PyObject *__pyx_k_74;
+static PyObject *__pyx_k_77;
+static PyObject *__pyx_k_78;
+static PyObject *__pyx_k_81;
+static PyObject *__pyx_k_82;
+static PyObject *__pyx_k_85;
+static PyObject *__pyx_k_86;
+static PyObject *__pyx_k_91;
+static PyObject *__pyx_k_125;
+static PyObject *__pyx_k_tuple_2;
+static PyObject *__pyx_k_tuple_3;
+static PyObject *__pyx_k_tuple_4;
+static PyObject *__pyx_k_tuple_5;
+static PyObject *__pyx_k_tuple_6;
+static PyObject *__pyx_k_tuple_7;
+static PyObject *__pyx_k_tuple_8;
+static PyObject *__pyx_k_tuple_10;
+static PyObject *__pyx_k_tuple_12;
+static PyObject *__pyx_k_tuple_14;
+static PyObject *__pyx_k_tuple_20;
+static PyObject *__pyx_k_tuple_21;
+static PyObject *__pyx_k_tuple_23;
+static PyObject *__pyx_k_tuple_25;
+static PyObject *__pyx_k_tuple_26;
+static PyObject *__pyx_k_tuple_27;
+static PyObject *__pyx_k_tuple_29;
+static PyObject *__pyx_k_tuple_30;
+static PyObject *__pyx_k_tuple_32;
+static PyObject *__pyx_k_tuple_33;
+static PyObject *__pyx_k_tuple_35;
+static PyObject *__pyx_k_tuple_36;
+static PyObject *__pyx_k_tuple_37;
+static PyObject *__pyx_k_tuple_38;
+static PyObject *__pyx_k_tuple_39;
+static PyObject *__pyx_k_tuple_40;
+static PyObject *__pyx_k_tuple_42;
+static PyObject *__pyx_k_tuple_44;
+static PyObject *__pyx_k_tuple_46;
+static PyObject *__pyx_k_tuple_47;
+static PyObject *__pyx_k_tuple_49;
+static PyObject *__pyx_k_tuple_50;
+static PyObject *__pyx_k_tuple_51;
+static PyObject *__pyx_k_tuple_52;
+static PyObject *__pyx_k_tuple_54;
+static PyObject *__pyx_k_tuple_55;
+static PyObject *__pyx_k_tuple_56;
+static PyObject *__pyx_k_tuple_58;
+static PyObject *__pyx_k_tuple_60;
+static PyObject *__pyx_k_tuple_61;
+static PyObject *__pyx_k_tuple_62;
+static PyObject *__pyx_k_tuple_63;
+static PyObject *__pyx_k_tuple_65;
+static PyObject *__pyx_k_tuple_66;
+static PyObject *__pyx_k_tuple_67;
+static PyObject *__pyx_k_tuple_68;
+static PyObject *__pyx_k_tuple_69;
+static PyObject *__pyx_k_tuple_70;
+static PyObject *__pyx_k_tuple_71;
+static PyObject *__pyx_k_tuple_72;
+static PyObject *__pyx_k_tuple_75;
+static PyObject *__pyx_k_tuple_76;
+static PyObject *__pyx_k_tuple_79;
+static PyObject *__pyx_k_tuple_80;
+static PyObject *__pyx_k_tuple_83;
+static PyObject *__pyx_k_tuple_84;
+static PyObject *__pyx_k_tuple_88;
+static PyObject *__pyx_k_tuple_90;
+static PyObject *__pyx_k_tuple_92;
+static PyObject *__pyx_k_tuple_94;
+static PyObject *__pyx_k_tuple_96;
+static PyObject *__pyx_k_tuple_97;
+static PyObject *__pyx_k_tuple_99;
+static PyObject *__pyx_k_tuple_100;
+static PyObject *__pyx_k_tuple_102;
+static PyObject *__pyx_k_tuple_104;
+static PyObject *__pyx_k_tuple_106;
+static PyObject *__pyx_k_tuple_107;
+static PyObject *__pyx_k_tuple_108;
+static PyObject *__pyx_k_tuple_109;
+static PyObject *__pyx_k_tuple_111;
+static PyObject *__pyx_k_tuple_113;
+static PyObject *__pyx_k_tuple_115;
+static PyObject *__pyx_k_tuple_116;
+static PyObject *__pyx_k_tuple_117;
+static PyObject *__pyx_k_tuple_118;
+static PyObject *__pyx_k_tuple_119;
+static PyObject *__pyx_k_tuple_120;
+static PyObject *__pyx_k_tuple_121;
+static PyObject *__pyx_k_tuple_122;
+static PyObject *__pyx_k_tuple_123;
+static PyObject *__pyx_k_tuple_124;
+static PyObject *__pyx_k_tuple_127;
+static PyObject *__pyx_k_tuple_129;
+static PyObject *__pyx_k_tuple_130;
+static PyObject *__pyx_k_tuple_132;
+static PyObject *__pyx_k_tuple_134;
+static PyObject *__pyx_k_tuple_135;
+static PyObject *__pyx_k_tuple_137;
+static PyObject *__pyx_k_tuple_139;
+static PyObject *__pyx_k_tuple_140;
+static PyObject *__pyx_k_tuple_141;
+static PyObject *__pyx_k_tuple_143;
+static PyObject *__pyx_k_tuple_145;
+static PyObject *__pyx_k_tuple_147;
+static PyObject *__pyx_k_tuple_149;
+static PyObject *__pyx_k_tuple_150;
+static PyObject *__pyx_k_tuple_151;
+static PyObject *__pyx_k_tuple_152;
+static PyObject *__pyx_k_tuple_153;
+static PyObject *__pyx_k_tuple_155;
+static PyObject *__pyx_k_tuple_157;
+static PyObject *__pyx_k_tuple_158;
+static PyObject *__pyx_k_tuple_159;
+static PyObject *__pyx_k_tuple_161;
+static PyObject *__pyx_k_tuple_163;
+static PyObject *__pyx_k_tuple_165;
+static PyObject *__pyx_k_tuple_168;
+static PyObject *__pyx_k_tuple_169;
+static PyObject *__pyx_k_tuple_170;
/* "mtrand.pyx":128
* import numpy as np
@@ -1040,7 +1243,6 @@ static PyObject *__pyx_f_6mtrand_cont0_array(rk_state *__pyx_v_state, __pyx_t_6
PyObject *__pyx_t_4 = NULL;
long __pyx_t_5;
__Pyx_RefNannySetupContext("cont0_array");
- __Pyx_INCREF(__pyx_v_size);
arrayObject = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
/* "mtrand.pyx":134
@@ -1088,17 +1290,17 @@ static PyObject *__pyx_f_6mtrand_cont0_array(rk_state *__pyx_v_state, __pyx_t_6
__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 = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_size);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_size);
__Pyx_GIVEREF(__pyx_v_size);
PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4);
__Pyx_GIVEREF(__pyx_t_4);
__pyx_t_4 = 0;
- __pyx_t_4 = PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __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_2)); __pyx_t_2 = 0;
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_4)));
__Pyx_DECREF(((PyObject *)arrayObject));
arrayObject = ((PyArrayObject *)__pyx_t_4);
@@ -1166,7 +1368,6 @@ static PyObject *__pyx_f_6mtrand_cont0_array(rk_state *__pyx_v_state, __pyx_t_6
__pyx_r = 0;
__pyx_L0:;
__Pyx_DECREF((PyObject *)arrayObject);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
@@ -1192,7 +1393,6 @@ static PyObject *__pyx_f_6mtrand_cont1_array_sc(rk_state *__pyx_v_state, __pyx_
PyObject *__pyx_t_4 = NULL;
long __pyx_t_5;
__Pyx_RefNannySetupContext("cont1_array_sc");
- __Pyx_INCREF(__pyx_v_size);
arrayObject = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
/* "mtrand.pyx":151
@@ -1240,17 +1440,17 @@ static PyObject *__pyx_f_6mtrand_cont1_array_sc(rk_state *__pyx_v_state, __pyx_
__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 = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_size);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_size);
__Pyx_GIVEREF(__pyx_v_size);
PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4);
__Pyx_GIVEREF(__pyx_t_4);
__pyx_t_4 = 0;
- __pyx_t_4 = PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __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_2)); __pyx_t_2 = 0;
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_4)));
__Pyx_DECREF(((PyObject *)arrayObject));
arrayObject = ((PyArrayObject *)__pyx_t_4);
@@ -1318,7 +1518,6 @@ static PyObject *__pyx_f_6mtrand_cont1_array_sc(rk_state *__pyx_v_state, __pyx_
__pyx_r = 0;
__pyx_L0:;
__Pyx_DECREF((PyObject *)arrayObject);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
@@ -1347,8 +1546,6 @@ static PyObject *__pyx_f_6mtrand_cont1_array(rk_state *__pyx_v_state, __pyx_t_6
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
__Pyx_RefNannySetupContext("cont1_array");
- __Pyx_INCREF(__pyx_v_size);
- __Pyx_INCREF((PyObject *)__pyx_v_oa);
arrayObject = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_itera = ((PyArrayIterObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_multi = ((PyArrayMultiIterObject *)Py_None); __Pyx_INCREF(Py_None);
@@ -1459,17 +1656,17 @@ static PyObject *__pyx_f_6mtrand_cont1_array(rk_state *__pyx_v_state, __pyx_t_6
__Pyx_GOTREF(__pyx_t_5);
__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 = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_size);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_size);
__Pyx_GIVEREF(__pyx_v_size);
PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5);
__Pyx_GIVEREF(__pyx_t_5);
__pyx_t_5 = 0;
- __pyx_t_5 = PyObject_Call(__pyx_t_4, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_5)));
__Pyx_DECREF(((PyObject *)arrayObject));
arrayObject = ((PyArrayObject *)__pyx_t_5);
@@ -1515,16 +1712,10 @@ static PyObject *__pyx_f_6mtrand_cont1_array(rk_state *__pyx_v_state, __pyx_t_6
* for i from 0 <= i < multi.size:
* oa_data = <double *>PyArray_MultiIter_DATA(multi, 1)
*/
- __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_2), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
- PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_1));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
- __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_5, 0, 0);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_Raise(__pyx_t_2, 0, 0);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L6;
}
@@ -1594,8 +1785,6 @@ static PyObject *__pyx_f_6mtrand_cont1_array(rk_state *__pyx_v_state, __pyx_t_6
__Pyx_DECREF((PyObject *)arrayObject);
__Pyx_DECREF((PyObject *)__pyx_v_itera);
__Pyx_DECREF((PyObject *)__pyx_v_multi);
- __Pyx_DECREF(__pyx_v_size);
- __Pyx_DECREF((PyObject *)__pyx_v_oa);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
@@ -1621,7 +1810,6 @@ static PyObject *__pyx_f_6mtrand_cont2_array_sc(rk_state *__pyx_v_state, __pyx_
PyObject *__pyx_t_4 = NULL;
long __pyx_t_5;
__Pyx_RefNannySetupContext("cont2_array_sc");
- __Pyx_INCREF(__pyx_v_size);
arrayObject = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
/* "mtrand.pyx":198
@@ -1669,17 +1857,17 @@ static PyObject *__pyx_f_6mtrand_cont2_array_sc(rk_state *__pyx_v_state, __pyx_
__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 = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_size);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_size);
__Pyx_GIVEREF(__pyx_v_size);
PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4);
__Pyx_GIVEREF(__pyx_t_4);
__pyx_t_4 = 0;
- __pyx_t_4 = PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 201; __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_2)); __pyx_t_2 = 0;
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_4)));
__Pyx_DECREF(((PyObject *)arrayObject));
arrayObject = ((PyArrayObject *)__pyx_t_4);
@@ -1747,7 +1935,6 @@ static PyObject *__pyx_f_6mtrand_cont2_array_sc(rk_state *__pyx_v_state, __pyx_
__pyx_r = 0;
__pyx_L0:;
__Pyx_DECREF((PyObject *)arrayObject);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
@@ -1775,9 +1962,6 @@ static PyObject *__pyx_f_6mtrand_cont2_array(rk_state *__pyx_v_state, __pyx_t_6
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
__Pyx_RefNannySetupContext("cont2_array");
- __Pyx_INCREF(__pyx_v_size);
- __Pyx_INCREF((PyObject *)__pyx_v_oa);
- __Pyx_INCREF((PyObject *)__pyx_v_ob);
arrayObject = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_multi = ((PyArrayMultiIterObject *)Py_None); __Pyx_INCREF(Py_None);
@@ -1896,17 +2080,17 @@ static PyObject *__pyx_f_6mtrand_cont2_array(rk_state *__pyx_v_state, __pyx_t_6
__Pyx_GOTREF(__pyx_t_5);
__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 = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_size);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_size);
__Pyx_GIVEREF(__pyx_v_size);
PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5);
__Pyx_GIVEREF(__pyx_t_5);
__pyx_t_5 = 0;
- __pyx_t_5 = PyObject_Call(__pyx_t_4, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_5)));
__Pyx_DECREF(((PyObject *)arrayObject));
arrayObject = ((PyArrayObject *)__pyx_t_5);
@@ -1952,16 +2136,10 @@ static PyObject *__pyx_f_6mtrand_cont2_array(rk_state *__pyx_v_state, __pyx_t_6
* for i from 0 <= i < multi.size:
* oa_data = <double *>PyArray_MultiIter_DATA(multi, 1)
*/
- __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_3), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
- PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_1));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
- __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_5, 0, 0);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_Raise(__pyx_t_2, 0, 0);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L6;
}
@@ -2048,9 +2226,6 @@ static PyObject *__pyx_f_6mtrand_cont2_array(rk_state *__pyx_v_state, __pyx_t_6
__pyx_L0:;
__Pyx_DECREF((PyObject *)arrayObject);
__Pyx_DECREF((PyObject *)__pyx_v_multi);
- __Pyx_DECREF(__pyx_v_size);
- __Pyx_DECREF((PyObject *)__pyx_v_oa);
- __Pyx_DECREF((PyObject *)__pyx_v_ob);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
@@ -2076,7 +2251,6 @@ static PyObject *__pyx_f_6mtrand_cont3_array_sc(rk_state *__pyx_v_state, __pyx_
PyObject *__pyx_t_4 = NULL;
long __pyx_t_5;
__Pyx_RefNannySetupContext("cont3_array_sc");
- __Pyx_INCREF(__pyx_v_size);
arrayObject = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
/* "mtrand.pyx":250
@@ -2124,17 +2298,17 @@ static PyObject *__pyx_f_6mtrand_cont3_array_sc(rk_state *__pyx_v_state, __pyx_
__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 = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_size);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_size);
__Pyx_GIVEREF(__pyx_v_size);
PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4);
__Pyx_GIVEREF(__pyx_t_4);
__pyx_t_4 = 0;
- __pyx_t_4 = PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 253; __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_2)); __pyx_t_2 = 0;
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_4)));
__Pyx_DECREF(((PyObject *)arrayObject));
arrayObject = ((PyArrayObject *)__pyx_t_4);
@@ -2202,7 +2376,6 @@ static PyObject *__pyx_f_6mtrand_cont3_array_sc(rk_state *__pyx_v_state, __pyx_
__pyx_r = 0;
__pyx_L0:;
__Pyx_DECREF((PyObject *)arrayObject);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
@@ -2231,10 +2404,6 @@ static PyObject *__pyx_f_6mtrand_cont3_array(rk_state *__pyx_v_state, __pyx_t_6
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
__Pyx_RefNannySetupContext("cont3_array");
- __Pyx_INCREF(__pyx_v_size);
- __Pyx_INCREF((PyObject *)__pyx_v_oa);
- __Pyx_INCREF((PyObject *)__pyx_v_ob);
- __Pyx_INCREF((PyObject *)__pyx_v_oc);
arrayObject = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_multi = ((PyArrayMultiIterObject *)Py_None); __Pyx_INCREF(Py_None);
@@ -2362,17 +2531,17 @@ static PyObject *__pyx_f_6mtrand_cont3_array(rk_state *__pyx_v_state, __pyx_t_6
__Pyx_GOTREF(__pyx_t_5);
__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 = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_size);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_size);
__Pyx_GIVEREF(__pyx_v_size);
PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5);
__Pyx_GIVEREF(__pyx_t_5);
__pyx_t_5 = 0;
- __pyx_t_5 = PyObject_Call(__pyx_t_4, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_5)));
__Pyx_DECREF(((PyObject *)arrayObject));
arrayObject = ((PyArrayObject *)__pyx_t_5);
@@ -2418,16 +2587,10 @@ static PyObject *__pyx_f_6mtrand_cont3_array(rk_state *__pyx_v_state, __pyx_t_6
* for i from 0 <= i < multi.size:
* oa_data = <double *>PyArray_MultiIter_DATA(multi, 1)
*/
- __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
- PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_1));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
- __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_5, 0, 0);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_Raise(__pyx_t_2, 0, 0);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L6;
}
@@ -2514,10 +2677,6 @@ static PyObject *__pyx_f_6mtrand_cont3_array(rk_state *__pyx_v_state, __pyx_t_6
__pyx_L0:;
__Pyx_DECREF((PyObject *)arrayObject);
__Pyx_DECREF((PyObject *)__pyx_v_multi);
- __Pyx_DECREF(__pyx_v_size);
- __Pyx_DECREF((PyObject *)__pyx_v_oa);
- __Pyx_DECREF((PyObject *)__pyx_v_ob);
- __Pyx_DECREF((PyObject *)__pyx_v_oc);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
@@ -2543,7 +2702,6 @@ static PyObject *__pyx_f_6mtrand_disc0_array(rk_state *__pyx_v_state, __pyx_t_6
PyObject *__pyx_t_4 = NULL;
long __pyx_t_5;
__Pyx_RefNannySetupContext("disc0_array");
- __Pyx_INCREF(__pyx_v_size);
arrayObject = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
/* "mtrand.pyx":303
@@ -2586,17 +2744,17 @@ static PyObject *__pyx_f_6mtrand_disc0_array(rk_state *__pyx_v_state, __pyx_t_6
__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 = 306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_size);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_size);
__Pyx_GIVEREF(__pyx_v_size);
- __Pyx_INCREF(((PyObject *)((PyObject*)&PyInt_Type)));
- PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)((PyObject*)&PyInt_Type)));
- __Pyx_GIVEREF(((PyObject *)((PyObject*)&PyInt_Type)));
- __pyx_t_4 = PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_INCREF(((PyObject *)((PyObject*)(&PyInt_Type))));
+ PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)((PyObject*)(&PyInt_Type))));
+ __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyInt_Type))));
+ __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 306; __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_2)); __pyx_t_2 = 0;
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_4)));
__Pyx_DECREF(((PyObject *)arrayObject));
arrayObject = ((PyArrayObject *)__pyx_t_4);
@@ -2664,7 +2822,6 @@ static PyObject *__pyx_f_6mtrand_disc0_array(rk_state *__pyx_v_state, __pyx_t_6
__pyx_r = 0;
__pyx_L0:;
__Pyx_DECREF((PyObject *)arrayObject);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
@@ -2690,7 +2847,6 @@ static PyObject *__pyx_f_6mtrand_discnp_array_sc(rk_state *__pyx_v_state, __pyx
PyObject *__pyx_t_4 = NULL;
long __pyx_t_5;
__Pyx_RefNannySetupContext("discnp_array_sc");
- __Pyx_INCREF(__pyx_v_size);
arrayObject = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
/* "mtrand.pyx":319
@@ -2733,17 +2889,17 @@ static PyObject *__pyx_f_6mtrand_discnp_array_sc(rk_state *__pyx_v_state, __pyx
__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 = 322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_size);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_size);
__Pyx_GIVEREF(__pyx_v_size);
- __Pyx_INCREF(((PyObject *)((PyObject*)&PyInt_Type)));
- PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)((PyObject*)&PyInt_Type)));
- __Pyx_GIVEREF(((PyObject *)((PyObject*)&PyInt_Type)));
- __pyx_t_4 = PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_INCREF(((PyObject *)((PyObject*)(&PyInt_Type))));
+ PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)((PyObject*)(&PyInt_Type))));
+ __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyInt_Type))));
+ __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 322; __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_2)); __pyx_t_2 = 0;
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_4)));
__Pyx_DECREF(((PyObject *)arrayObject));
arrayObject = ((PyArrayObject *)__pyx_t_4);
@@ -2811,7 +2967,6 @@ static PyObject *__pyx_f_6mtrand_discnp_array_sc(rk_state *__pyx_v_state, __pyx
__pyx_r = 0;
__pyx_L0:;
__Pyx_DECREF((PyObject *)arrayObject);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
@@ -2839,9 +2994,6 @@ static PyObject *__pyx_f_6mtrand_discnp_array(rk_state *__pyx_v_state, __pyx_t_
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
__Pyx_RefNannySetupContext("discnp_array");
- __Pyx_INCREF(__pyx_v_size);
- __Pyx_INCREF((PyObject *)__pyx_v_on);
- __Pyx_INCREF((PyObject *)__pyx_v_op);
arrayObject = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_multi = ((PyArrayMultiIterObject *)Py_None); __Pyx_INCREF(Py_None);
@@ -2955,17 +3107,17 @@ static PyObject *__pyx_f_6mtrand_discnp_array(rk_state *__pyx_v_state, __pyx_t_
__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 = 348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_size);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_size);
__Pyx_GIVEREF(__pyx_v_size);
- __Pyx_INCREF(((PyObject *)((PyObject*)&PyInt_Type)));
- PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)((PyObject*)&PyInt_Type)));
- __Pyx_GIVEREF(((PyObject *)((PyObject*)&PyInt_Type)));
- __pyx_t_5 = PyObject_Call(__pyx_t_4, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_INCREF(((PyObject *)((PyObject*)(&PyInt_Type))));
+ PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)((PyObject*)(&PyInt_Type))));
+ __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyInt_Type))));
+ __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 = 348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_5)));
__Pyx_DECREF(((PyObject *)arrayObject));
arrayObject = ((PyArrayObject *)__pyx_t_5);
@@ -3011,16 +3163,10 @@ static PyObject *__pyx_f_6mtrand_discnp_array(rk_state *__pyx_v_state, __pyx_t_
* for i from 0 <= i < multi.size:
* on_data = <long *>PyArray_MultiIter_DATA(multi, 1)
*/
- __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_5), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
- PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_1));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
- __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_5, 0, 0);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_Raise(__pyx_t_2, 0, 0);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L6;
}
@@ -3107,9 +3253,6 @@ static PyObject *__pyx_f_6mtrand_discnp_array(rk_state *__pyx_v_state, __pyx_t_
__pyx_L0:;
__Pyx_DECREF((PyObject *)arrayObject);
__Pyx_DECREF((PyObject *)__pyx_v_multi);
- __Pyx_DECREF(__pyx_v_size);
- __Pyx_DECREF((PyObject *)__pyx_v_on);
- __Pyx_DECREF((PyObject *)__pyx_v_op);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
@@ -3135,7 +3278,6 @@ static PyObject *__pyx_f_6mtrand_discdd_array_sc(rk_state *__pyx_v_state, __pyx
PyObject *__pyx_t_4 = NULL;
long __pyx_t_5;
__Pyx_RefNannySetupContext("discdd_array_sc");
- __Pyx_INCREF(__pyx_v_size);
arrayObject = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
/* "mtrand.pyx":368
@@ -3178,17 +3320,17 @@ static PyObject *__pyx_f_6mtrand_discdd_array_sc(rk_state *__pyx_v_state, __pyx
__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 = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_size);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_size);
__Pyx_GIVEREF(__pyx_v_size);
- __Pyx_INCREF(((PyObject *)((PyObject*)&PyInt_Type)));
- PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)((PyObject*)&PyInt_Type)));
- __Pyx_GIVEREF(((PyObject *)((PyObject*)&PyInt_Type)));
- __pyx_t_4 = PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_INCREF(((PyObject *)((PyObject*)(&PyInt_Type))));
+ PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)((PyObject*)(&PyInt_Type))));
+ __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyInt_Type))));
+ __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __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_2)); __pyx_t_2 = 0;
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_4)));
__Pyx_DECREF(((PyObject *)arrayObject));
arrayObject = ((PyArrayObject *)__pyx_t_4);
@@ -3256,7 +3398,6 @@ static PyObject *__pyx_f_6mtrand_discdd_array_sc(rk_state *__pyx_v_state, __pyx
__pyx_r = 0;
__pyx_L0:;
__Pyx_DECREF((PyObject *)arrayObject);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
@@ -3284,9 +3425,6 @@ static PyObject *__pyx_f_6mtrand_discdd_array(rk_state *__pyx_v_state, __pyx_t_
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
__Pyx_RefNannySetupContext("discdd_array");
- __Pyx_INCREF(__pyx_v_size);
- __Pyx_INCREF((PyObject *)__pyx_v_on);
- __Pyx_INCREF((PyObject *)__pyx_v_op);
arrayObject = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_multi = ((PyArrayMultiIterObject *)Py_None); __Pyx_INCREF(Py_None);
@@ -3400,17 +3538,17 @@ static PyObject *__pyx_f_6mtrand_discdd_array(rk_state *__pyx_v_state, __pyx_t_
__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 = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_size);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_size);
__Pyx_GIVEREF(__pyx_v_size);
- __Pyx_INCREF(((PyObject *)((PyObject*)&PyInt_Type)));
- PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)((PyObject*)&PyInt_Type)));
- __Pyx_GIVEREF(((PyObject *)((PyObject*)&PyInt_Type)));
- __pyx_t_5 = PyObject_Call(__pyx_t_4, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_INCREF(((PyObject *)((PyObject*)(&PyInt_Type))));
+ PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)((PyObject*)(&PyInt_Type))));
+ __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyInt_Type))));
+ __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 = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_5)));
__Pyx_DECREF(((PyObject *)arrayObject));
arrayObject = ((PyArrayObject *)__pyx_t_5);
@@ -3456,16 +3594,10 @@ static PyObject *__pyx_f_6mtrand_discdd_array(rk_state *__pyx_v_state, __pyx_t_
* for i from 0 <= i < multi.size:
* on_data = <double *>PyArray_MultiIter_DATA(multi, 1)
*/
- __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
- PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_1));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
- __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_5, 0, 0);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_Raise(__pyx_t_2, 0, 0);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L6;
}
@@ -3552,9 +3684,6 @@ static PyObject *__pyx_f_6mtrand_discdd_array(rk_state *__pyx_v_state, __pyx_t_
__pyx_L0:;
__Pyx_DECREF((PyObject *)arrayObject);
__Pyx_DECREF((PyObject *)__pyx_v_multi);
- __Pyx_DECREF(__pyx_v_size);
- __Pyx_DECREF((PyObject *)__pyx_v_on);
- __Pyx_DECREF((PyObject *)__pyx_v_op);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
@@ -3580,7 +3709,6 @@ static PyObject *__pyx_f_6mtrand_discnmN_array_sc(rk_state *__pyx_v_state, __py
PyObject *__pyx_t_4 = NULL;
long __pyx_t_5;
__Pyx_RefNannySetupContext("discnmN_array_sc");
- __Pyx_INCREF(__pyx_v_size);
arrayObject = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
/* "mtrand.pyx":418
@@ -3623,17 +3751,17 @@ static PyObject *__pyx_f_6mtrand_discnmN_array_sc(rk_state *__pyx_v_state, __py
__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 = 421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_size);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_size);
__Pyx_GIVEREF(__pyx_v_size);
- __Pyx_INCREF(((PyObject *)((PyObject*)&PyInt_Type)));
- PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)((PyObject*)&PyInt_Type)));
- __Pyx_GIVEREF(((PyObject *)((PyObject*)&PyInt_Type)));
- __pyx_t_4 = PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_INCREF(((PyObject *)((PyObject*)(&PyInt_Type))));
+ PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)((PyObject*)(&PyInt_Type))));
+ __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyInt_Type))));
+ __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 421; __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_2)); __pyx_t_2 = 0;
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_4)));
__Pyx_DECREF(((PyObject *)arrayObject));
arrayObject = ((PyArrayObject *)__pyx_t_4);
@@ -3701,7 +3829,6 @@ static PyObject *__pyx_f_6mtrand_discnmN_array_sc(rk_state *__pyx_v_state, __py
__pyx_r = 0;
__pyx_L0:;
__Pyx_DECREF((PyObject *)arrayObject);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
@@ -3730,10 +3857,6 @@ static PyObject *__pyx_f_6mtrand_discnmN_array(rk_state *__pyx_v_state, __pyx_t
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
__Pyx_RefNannySetupContext("discnmN_array");
- __Pyx_INCREF(__pyx_v_size);
- __Pyx_INCREF((PyObject *)__pyx_v_on);
- __Pyx_INCREF((PyObject *)__pyx_v_om);
- __Pyx_INCREF((PyObject *)__pyx_v_oN);
arrayObject = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_multi = ((PyArrayMultiIterObject *)Py_None); __Pyx_INCREF(Py_None);
@@ -3856,17 +3979,17 @@ static PyObject *__pyx_f_6mtrand_discnmN_array(rk_state *__pyx_v_state, __pyx_t
__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 = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_size);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_size);
__Pyx_GIVEREF(__pyx_v_size);
- __Pyx_INCREF(((PyObject *)((PyObject*)&PyInt_Type)));
- PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)((PyObject*)&PyInt_Type)));
- __Pyx_GIVEREF(((PyObject *)((PyObject*)&PyInt_Type)));
- __pyx_t_5 = PyObject_Call(__pyx_t_4, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_INCREF(((PyObject *)((PyObject*)(&PyInt_Type))));
+ PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)((PyObject*)(&PyInt_Type))));
+ __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyInt_Type))));
+ __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 = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_5)));
__Pyx_DECREF(((PyObject *)arrayObject));
arrayObject = ((PyArrayObject *)__pyx_t_5);
@@ -3912,16 +4035,10 @@ static PyObject *__pyx_f_6mtrand_discnmN_array(rk_state *__pyx_v_state, __pyx_t
* for i from 0 <= i < multi.size:
* on_data = <long *>PyArray_MultiIter_DATA(multi, 1)
*/
- __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
- PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_1));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
- __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_5, 0, 0);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_Raise(__pyx_t_2, 0, 0);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L6;
}
@@ -4008,10 +4125,6 @@ static PyObject *__pyx_f_6mtrand_discnmN_array(rk_state *__pyx_v_state, __pyx_t
__pyx_L0:;
__Pyx_DECREF((PyObject *)arrayObject);
__Pyx_DECREF((PyObject *)__pyx_v_multi);
- __Pyx_DECREF(__pyx_v_size);
- __Pyx_DECREF((PyObject *)__pyx_v_on);
- __Pyx_DECREF((PyObject *)__pyx_v_om);
- __Pyx_DECREF((PyObject *)__pyx_v_oN);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
@@ -4037,7 +4150,6 @@ static PyObject *__pyx_f_6mtrand_discd_array_sc(rk_state *__pyx_v_state, __pyx_
PyObject *__pyx_t_4 = NULL;
long __pyx_t_5;
__Pyx_RefNannySetupContext("discd_array_sc");
- __Pyx_INCREF(__pyx_v_size);
arrayObject = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
/* "mtrand.pyx":471
@@ -4080,17 +4192,17 @@ static PyObject *__pyx_f_6mtrand_discd_array_sc(rk_state *__pyx_v_state, __pyx_
__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 = 474; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_size);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_size);
__Pyx_GIVEREF(__pyx_v_size);
- __Pyx_INCREF(((PyObject *)((PyObject*)&PyInt_Type)));
- PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)((PyObject*)&PyInt_Type)));
- __Pyx_GIVEREF(((PyObject *)((PyObject*)&PyInt_Type)));
- __pyx_t_4 = PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 474; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_INCREF(((PyObject *)((PyObject*)(&PyInt_Type))));
+ PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)((PyObject*)(&PyInt_Type))));
+ __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyInt_Type))));
+ __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 474; __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_2)); __pyx_t_2 = 0;
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_4)));
__Pyx_DECREF(((PyObject *)arrayObject));
arrayObject = ((PyArrayObject *)__pyx_t_4);
@@ -4158,7 +4270,6 @@ static PyObject *__pyx_f_6mtrand_discd_array_sc(rk_state *__pyx_v_state, __pyx_
__pyx_r = 0;
__pyx_L0:;
__Pyx_DECREF((PyObject *)arrayObject);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
@@ -4187,8 +4298,6 @@ static PyObject *__pyx_f_6mtrand_discd_array(rk_state *__pyx_v_state, __pyx_t_6
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
__Pyx_RefNannySetupContext("discd_array");
- __Pyx_INCREF(__pyx_v_size);
- __Pyx_INCREF((PyObject *)__pyx_v_oa);
arrayObject = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_multi = ((PyArrayMultiIterObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_itera = ((PyArrayIterObject *)Py_None); __Pyx_INCREF(Py_None);
@@ -4294,17 +4403,17 @@ static PyObject *__pyx_f_6mtrand_discd_array(rk_state *__pyx_v_state, __pyx_t_6
__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 = 499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_size);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_size);
__Pyx_GIVEREF(__pyx_v_size);
- __Pyx_INCREF(((PyObject *)((PyObject*)&PyInt_Type)));
- PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)((PyObject*)&PyInt_Type)));
- __Pyx_GIVEREF(((PyObject *)((PyObject*)&PyInt_Type)));
- __pyx_t_5 = PyObject_Call(__pyx_t_4, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_INCREF(((PyObject *)((PyObject*)(&PyInt_Type))));
+ PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)((PyObject*)(&PyInt_Type))));
+ __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyInt_Type))));
+ __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 = 499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_5)));
__Pyx_DECREF(((PyObject *)arrayObject));
arrayObject = ((PyArrayObject *)__pyx_t_5);
@@ -4350,16 +4459,10 @@ static PyObject *__pyx_f_6mtrand_discd_array(rk_state *__pyx_v_state, __pyx_t_6
* for i from 0 <= i < multi.size:
* oa_data = <double *>PyArray_MultiIter_DATA(multi, 1)
*/
- __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_8), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
- PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_1));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
- __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_5, 0, 0);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_Raise(__pyx_t_2, 0, 0);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L6;
}
@@ -4429,8 +4532,6 @@ static PyObject *__pyx_f_6mtrand_discd_array(rk_state *__pyx_v_state, __pyx_t_6
__Pyx_DECREF((PyObject *)arrayObject);
__Pyx_DECREF((PyObject *)__pyx_v_multi);
__Pyx_DECREF((PyObject *)__pyx_v_itera);
- __Pyx_DECREF(__pyx_v_size);
- __Pyx_DECREF((PyObject *)__pyx_v_oa);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
@@ -4535,8 +4636,8 @@ static double __pyx_f_6mtrand_kahan_sum(double *__pyx_v_darr, long __pyx_v_n) {
return __pyx_r;
}
-/* "mtrand.pyx":557
- * cdef rk_state *internal_state
+/* "mtrand.pyx":558
+ * poisson_lam_max = np.iinfo('l').max - np.sqrt(np.iinfo('l').max)*10
*
* def __init__(self, seed=None): # <<<<<<<<<<<<<<
* self.internal_state = <rk_state*>PyMem_Malloc(sizeof(rk_state))
@@ -4563,13 +4664,13 @@ static int __pyx_pf_6mtrand_11RandomState___init__(PyObject *__pyx_v_self, PyObj
}
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 0:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__seed);
- if (unlikely(value)) { values[0] = value; kw_args--; }
+ if (value) { values[0] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 557; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 558; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_seed = values[0];
} else {
@@ -4582,13 +4683,14 @@ static int __pyx_pf_6mtrand_11RandomState___init__(PyObject *__pyx_v_self, PyObj
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 557; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 558; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.__init__");
+ __Pyx_RefNannyFinishContext();
return -1;
__pyx_L4_argument_unpacking_done:;
- /* "mtrand.pyx":558
+ /* "mtrand.pyx":559
*
* def __init__(self, seed=None):
* self.internal_state = <rk_state*>PyMem_Malloc(sizeof(rk_state)) # <<<<<<<<<<<<<<
@@ -4597,24 +4699,24 @@ static int __pyx_pf_6mtrand_11RandomState___init__(PyObject *__pyx_v_self, PyObj
*/
((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state = ((rk_state *)PyMem_Malloc((sizeof(rk_state))));
- /* "mtrand.pyx":560
+ /* "mtrand.pyx":561
* self.internal_state = <rk_state*>PyMem_Malloc(sizeof(rk_state))
*
* self.seed(seed) # <<<<<<<<<<<<<<
*
* def __dealloc__(self):
*/
- __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__seed); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__seed); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_seed);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_seed);
__Pyx_GIVEREF(__pyx_v_seed);
- __pyx_t_3 = PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_r = 0;
@@ -4630,7 +4732,7 @@ static int __pyx_pf_6mtrand_11RandomState___init__(PyObject *__pyx_v_self, PyObj
return __pyx_r;
}
-/* "mtrand.pyx":562
+/* "mtrand.pyx":563
* self.seed(seed)
*
* def __dealloc__(self): # <<<<<<<<<<<<<<
@@ -4638,13 +4740,12 @@ static int __pyx_pf_6mtrand_11RandomState___init__(PyObject *__pyx_v_self, PyObj
* PyMem_Free(self.internal_state)
*/
-static void __pyx_pf_6mtrand_11RandomState___dealloc__(PyObject *__pyx_v_self); /*proto*/
-static void __pyx_pf_6mtrand_11RandomState___dealloc__(PyObject *__pyx_v_self) {
+static void __pyx_pf_6mtrand_11RandomState_1__dealloc__(PyObject *__pyx_v_self); /*proto*/
+static void __pyx_pf_6mtrand_11RandomState_1__dealloc__(PyObject *__pyx_v_self) {
int __pyx_t_1;
__Pyx_RefNannySetupContext("__dealloc__");
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- /* "mtrand.pyx":563
+ /* "mtrand.pyx":564
*
* def __dealloc__(self):
* if self.internal_state != NULL: # <<<<<<<<<<<<<<
@@ -4654,7 +4755,7 @@ static void __pyx_pf_6mtrand_11RandomState___dealloc__(PyObject *__pyx_v_self) {
__pyx_t_1 = (((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state != NULL);
if (__pyx_t_1) {
- /* "mtrand.pyx":564
+ /* "mtrand.pyx":565
* def __dealloc__(self):
* if self.internal_state != NULL:
* PyMem_Free(self.internal_state) # <<<<<<<<<<<<<<
@@ -4663,7 +4764,7 @@ static void __pyx_pf_6mtrand_11RandomState___dealloc__(PyObject *__pyx_v_self) {
*/
PyMem_Free(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state);
- /* "mtrand.pyx":565
+ /* "mtrand.pyx":566
* if self.internal_state != NULL:
* PyMem_Free(self.internal_state)
* self.internal_state = NULL # <<<<<<<<<<<<<<
@@ -4675,11 +4776,10 @@ static void __pyx_pf_6mtrand_11RandomState___dealloc__(PyObject *__pyx_v_self) {
}
__pyx_L5:;
- __Pyx_DECREF((PyObject *)__pyx_v_self);
__Pyx_RefNannyFinishContext();
}
-/* "mtrand.pyx":567
+/* "mtrand.pyx":568
* self.internal_state = NULL
*
* def seed(self, seed=None): # <<<<<<<<<<<<<<
@@ -4687,9 +4787,9 @@ static void __pyx_pf_6mtrand_11RandomState___dealloc__(PyObject *__pyx_v_self) {
* seed(seed=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_seed(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_seed[] = "\n seed(seed=None)\n\n Seed the generator.\n\n This method is called when `RandomState` is initialized. It can be\n called again to re-seed the generator. For details, see `RandomState`.\n\n Parameters\n ----------\n seed : int or array_like, optional\n Seed for `RandomState`.\n\n See Also\n --------\n RandomState\n\n ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_seed(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_2seed(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_2seed[] = "\n seed(seed=None)\n\n Seed the generator.\n\n This method is called when `RandomState` is initialized. It can be\n called again to re-seed the generator. For details, see `RandomState`.\n\n Parameters\n ----------\n seed : int or array_like, optional\n Seed for `RandomState`.\n\n See Also\n --------\n RandomState\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_2seed(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_seed = 0;
rk_error __pyx_v_errcode;
PyArrayObject *arrayObject_obj;
@@ -4712,13 +4812,13 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_seed(PyObject *__pyx_v_self, PyO
}
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 0:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__seed);
- if (unlikely(value)) { values[0] = value; kw_args--; }
+ if (value) { values[0] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "seed") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 567; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "seed") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 568; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_seed = values[0];
} else {
@@ -4731,17 +4831,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_seed(PyObject *__pyx_v_self, PyO
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("seed", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 567; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("seed", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 568; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.seed");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_seed);
arrayObject_obj = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_iseed = Py_None; __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":588
+ /* "mtrand.pyx":589
* cdef rk_error errcode
* cdef ndarray obj "arrayObject_obj"
* if seed is None: # <<<<<<<<<<<<<<
@@ -4751,7 +4850,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_seed(PyObject *__pyx_v_self, PyO
__pyx_t_1 = (__pyx_v_seed == Py_None);
if (__pyx_t_1) {
- /* "mtrand.pyx":589
+ /* "mtrand.pyx":590
* cdef ndarray obj "arrayObject_obj"
* if seed is None:
* errcode = rk_randomseed(self.internal_state) # <<<<<<<<<<<<<<
@@ -4762,91 +4861,91 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_seed(PyObject *__pyx_v_self, PyO
goto __pyx_L6;
}
- /* "mtrand.pyx":590
+ /* "mtrand.pyx":591
* if seed is None:
* errcode = rk_randomseed(self.internal_state)
* elif type(seed) is int: # <<<<<<<<<<<<<<
* rk_seed(seed, self.internal_state)
* elif isinstance(seed, np.integer):
*/
- __pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_seed)) == ((PyObject *)((PyObject*)&PyInt_Type)));
+ __pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_seed)) == ((PyObject *)((PyObject*)(&PyInt_Type))));
if (__pyx_t_1) {
- /* "mtrand.pyx":591
+ /* "mtrand.pyx":592
* errcode = rk_randomseed(self.internal_state)
* elif type(seed) is int:
* rk_seed(seed, self.internal_state) # <<<<<<<<<<<<<<
* elif isinstance(seed, np.integer):
* iseed = int(seed)
*/
- __pyx_t_2 = __Pyx_PyInt_AsUnsignedLong(__pyx_v_seed); if (unlikely((__pyx_t_2 == (unsigned long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 591; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_PyInt_AsUnsignedLong(__pyx_v_seed); if (unlikely((__pyx_t_2 == (unsigned long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
rk_seed(__pyx_t_2, ((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state);
goto __pyx_L6;
}
- /* "mtrand.pyx":592
+ /* "mtrand.pyx":593
* elif type(seed) is int:
* rk_seed(seed, self.internal_state)
* elif isinstance(seed, np.integer): # <<<<<<<<<<<<<<
* iseed = int(seed)
* rk_seed(iseed, self.internal_state)
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__integer); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__integer); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_1 = PyObject_IsInstance(__pyx_v_seed, __pyx_t_4); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyObject_IsInstance(__pyx_v_seed, __pyx_t_4); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":593
+ /* "mtrand.pyx":594
* rk_seed(seed, self.internal_state)
* elif isinstance(seed, np.integer):
* iseed = int(seed) # <<<<<<<<<<<<<<
* rk_seed(iseed, self.internal_state)
* else:
*/
- __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 594; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
__Pyx_INCREF(__pyx_v_seed);
PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_seed);
__Pyx_GIVEREF(__pyx_v_seed);
- __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)&PyInt_Type)), __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 594; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
__Pyx_DECREF(__pyx_v_iseed);
__pyx_v_iseed = __pyx_t_3;
__pyx_t_3 = 0;
- /* "mtrand.pyx":594
+ /* "mtrand.pyx":595
* elif isinstance(seed, np.integer):
* iseed = int(seed)
* rk_seed(iseed, self.internal_state) # <<<<<<<<<<<<<<
* else:
* obj = <ndarray>PyArray_ContiguousFromObject(seed, NPY_LONG, 1, 1)
*/
- __pyx_t_2 = __Pyx_PyInt_AsUnsignedLong(__pyx_v_iseed); if (unlikely((__pyx_t_2 == (unsigned long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 594; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_PyInt_AsUnsignedLong(__pyx_v_iseed); if (unlikely((__pyx_t_2 == (unsigned long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 595; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
rk_seed(__pyx_t_2, ((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state);
goto __pyx_L6;
}
/*else*/ {
- /* "mtrand.pyx":596
+ /* "mtrand.pyx":597
* rk_seed(iseed, self.internal_state)
* else:
* obj = <ndarray>PyArray_ContiguousFromObject(seed, NPY_LONG, 1, 1) # <<<<<<<<<<<<<<
* init_by_array(self.internal_state, <unsigned long *>(obj.data),
* obj.dimensions[0])
*/
- __pyx_t_3 = PyArray_ContiguousFromObject(__pyx_v_seed, NPY_LONG, 1, 1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 596; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyArray_ContiguousFromObject(__pyx_v_seed, NPY_LONG, 1, 1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
__Pyx_DECREF(((PyObject *)arrayObject_obj));
arrayObject_obj = ((PyArrayObject *)__pyx_t_3);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- /* "mtrand.pyx":598
+ /* "mtrand.pyx":599
* obj = <ndarray>PyArray_ContiguousFromObject(seed, NPY_LONG, 1, 1)
* init_by_array(self.internal_state, <unsigned long *>(obj.data),
* obj.dimensions[0]) # <<<<<<<<<<<<<<
@@ -4867,14 +4966,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_seed(PyObject *__pyx_v_self, PyO
__pyx_L0:;
__Pyx_DECREF((PyObject *)arrayObject_obj);
__Pyx_DECREF(__pyx_v_iseed);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_seed);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":600
+/* "mtrand.pyx":601
* obj.dimensions[0])
*
* def get_state(self): # <<<<<<<<<<<<<<
@@ -4882,9 +4979,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_seed(PyObject *__pyx_v_self, PyO
* get_state()
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_get_state(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_get_state[] = "\n get_state()\n\n Return a tuple representing the internal state of the generator.\n\n For more details, see `set_state`.\n\n Returns\n -------\n out : tuple(str, ndarray of 624 uints, int, int, float)\n The returned tuple has the following items:\n\n 1. the string 'MT19937'.\n 2. a 1-D array of 624 unsigned integer keys.\n 3. an integer ``pos``.\n 4. an integer ``has_gauss``.\n 5. a float ``cached_gaussian``.\n\n See Also\n --------\n set_state\n\n Notes\n -----\n `set_state` and `get_state` are not needed to work with any of the\n random distributions in NumPy. If the internal state is manually altered,\n the user should know exactly what he/she is doing.\n\n ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_get_state(PyObject *__pyx_v_self, PyObject *unused) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_3get_state(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_3get_state[] = "\n get_state()\n\n Return a tuple representing the internal state of the generator.\n\n For more details, see `set_state`.\n\n Returns\n -------\n out : tuple(str, ndarray of 624 uints, int, int, float)\n The returned tuple has the following items:\n\n 1. the string 'MT19937'.\n 2. a 1-D array of 624 unsigned integer keys.\n 3. an integer ``pos``.\n 4. an integer ``has_gauss``.\n 5. a float ``cached_gaussian``.\n\n See Also\n --------\n set_state\n\n Notes\n -----\n `set_state` and `get_state` are not needed to work with any of the\n random distributions in NumPy. If the internal state is manually altered,\n the user should know exactly what he/she is doing.\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_3get_state(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
PyArrayObject *arrayObject_state;
PyObject *__pyx_r = NULL;
PyObject *__pyx_t_1 = NULL;
@@ -4894,41 +4991,41 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_get_state(PyObject *__pyx_v_self
__Pyx_RefNannySetupContext("get_state");
arrayObject_state = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":631
+ /* "mtrand.pyx":632
* """
* cdef ndarray state "arrayObject_state"
* state = <ndarray>np.empty(624, np.uint) # <<<<<<<<<<<<<<
* memcpy(<void*>(state.data), <void*>(self.internal_state.key), 624*sizeof(long))
* state = <ndarray>np.asarray(state, np.uint32)
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__uint); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__uint); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_1));
__Pyx_INCREF(__pyx_int_624);
PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_int_624);
__Pyx_GIVEREF(__pyx_int_624);
PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3);
__Pyx_GIVEREF(__pyx_t_3);
__pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
__Pyx_DECREF(((PyObject *)arrayObject_state));
arrayObject_state = ((PyArrayObject *)__pyx_t_3);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- /* "mtrand.pyx":632
+ /* "mtrand.pyx":633
* cdef ndarray state "arrayObject_state"
* state = <ndarray>np.empty(624, np.uint)
* memcpy(<void*>(state.data), <void*>(self.internal_state.key), 624*sizeof(long)) # <<<<<<<<<<<<<<
@@ -4937,41 +5034,41 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_get_state(PyObject *__pyx_v_self
*/
memcpy(((void *)arrayObject_state->data), ((void *)((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state->key), (624 * (sizeof(long))));
- /* "mtrand.pyx":633
+ /* "mtrand.pyx":634
* state = <ndarray>np.empty(624, np.uint)
* memcpy(<void*>(state.data), <void*>(self.internal_state.key), 624*sizeof(long))
* state = <ndarray>np.asarray(state, np.uint32) # <<<<<<<<<<<<<<
* return ('MT19937', state, self.internal_state.pos,
* self.internal_state.has_gauss, self.internal_state.gauss)
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__asarray); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__asarray); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__uint32); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__uint32); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __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 = 633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_3));
__Pyx_INCREF(((PyObject *)arrayObject_state));
PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)arrayObject_state));
__Pyx_GIVEREF(((PyObject *)arrayObject_state));
PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
__Pyx_GIVEREF(__pyx_t_2);
__pyx_t_2 = 0;
- __pyx_t_2 = PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)arrayObject_state));
arrayObject_state = ((PyArrayObject *)__pyx_t_2);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":634
+ /* "mtrand.pyx":635
* memcpy(<void*>(state.data), <void*>(self.internal_state.key), 624*sizeof(long))
* state = <ndarray>np.asarray(state, np.uint32)
* return ('MT19937', state, self.internal_state.pos, # <<<<<<<<<<<<<<
@@ -4979,22 +5076,22 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_get_state(PyObject *__pyx_v_self
*
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_2 = PyInt_FromLong(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state->pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyInt_FromLong(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state->pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 635; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- /* "mtrand.pyx":635
+ /* "mtrand.pyx":636
* state = <ndarray>np.asarray(state, np.uint32)
* return ('MT19937', state, self.internal_state.pos,
* self.internal_state.has_gauss, self.internal_state.gauss) # <<<<<<<<<<<<<<
*
* def set_state(self, state):
*/
- __pyx_t_3 = PyInt_FromLong(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state->has_gauss); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 635; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyInt_FromLong(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state->has_gauss); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 636; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state->gauss); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 635; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state->gauss); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 636; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_4 = PyTuple_New(5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_4 = PyTuple_New(5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 635; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
__Pyx_INCREF(((PyObject *)__pyx_n_s__MT19937));
PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_n_s__MT19937));
__Pyx_GIVEREF(((PyObject *)__pyx_n_s__MT19937));
@@ -5010,7 +5107,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_get_state(PyObject *__pyx_v_self
__pyx_t_2 = 0;
__pyx_t_3 = 0;
__pyx_t_1 = 0;
- __pyx_r = __pyx_t_4;
+ __pyx_r = ((PyObject *)__pyx_t_4);
__pyx_t_4 = 0;
goto __pyx_L0;
@@ -5030,7 +5127,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_get_state(PyObject *__pyx_v_self
return __pyx_r;
}
-/* "mtrand.pyx":637
+/* "mtrand.pyx":638
* self.internal_state.has_gauss, self.internal_state.gauss)
*
* def set_state(self, state): # <<<<<<<<<<<<<<
@@ -5038,9 +5135,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_get_state(PyObject *__pyx_v_self
* set_state(state)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_set_state(PyObject *__pyx_v_self, PyObject *__pyx_v_state); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_set_state[] = "\n set_state(state)\n\n Set the internal state of the generator from a tuple.\n\n For use if one has reason to manually (re-)set the internal state of the\n \"Mersenne Twister\"[1]_ pseudo-random number generating algorithm.\n\n Parameters\n ----------\n state : tuple(str, ndarray of 624 uints, int, int, float)\n The `state` tuple has the following items:\n\n 1. the string 'MT19937', specifying the Mersenne Twister algorithm.\n 2. a 1-D array of 624 unsigned integers ``keys``.\n 3. an integer ``pos``.\n 4. an integer ``has_gauss``.\n 5. a float ``cached_gaussian``.\n\n Returns\n -------\n out : None\n Returns 'None' on success.\n\n See Also\n --------\n get_state\n\n Notes\n -----\n `set_state` and `get_state` are not needed to work with any of the\n random distributions in NumPy. If the internal state is manually altered,\n the user should know exactly what he/she is doing.\n\n For backwards compatibility, the form (str, array of 624 uints, int) is\n also accepted although it is missing some information about the cached\n Gaussian value: ``state = ('MT19937', keys, pos)``.\n\n References\n ----------\n .. [1] M. Matsumoto and T. Nishimura, \"Mersenne Twister: A\n 623-dimensionally equidistributed uniform pseudorandom number\n generator,\" *ACM Trans. on Modeling and Computer Simulation*,\n Vol. 8, No. 1, pp. 3-30, Jan. 1998.\n\n ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_set_state(PyObject *__pyx_v_self, PyObject *__pyx_v_state) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_4set_state(PyObject *__pyx_v_self, PyObject *__pyx_v_state); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_4set_state[] = "\n set_state(state)\n\n Set the internal state of the generator from a tuple.\n\n For use if one has reason to manually (re-)set the internal state of the\n \"Mersenne Twister\"[1]_ pseudo-random number generating algorithm.\n\n Parameters\n ----------\n state : tuple(str, ndarray of 624 uints, int, int, float)\n The `state` tuple has the following items:\n\n 1. the string 'MT19937', specifying the Mersenne Twister algorithm.\n 2. a 1-D array of 624 unsigned integers ``keys``.\n 3. an integer ``pos``.\n 4. an integer ``has_gauss``.\n 5. a float ``cached_gaussian``.\n\n Returns\n -------\n out : None\n Returns 'None' on success.\n\n See Also\n --------\n get_state\n\n Notes\n -----\n `set_state` and `get_state` are not needed to work with any of the\n random distributions in NumPy. If the internal state is manually altered,\n the user should know exactly what he/she is doing.\n\n For backwards compatibility, the form (str, array of 624 uints, int) is\n also accepted although it is missing some information about the cached\n Gaussian value: ``state = ('MT19937', keys, pos)``.\n\n References\n ----------\n .. [1] M. Matsumoto and T. Nishimura, \"Mersenne Twister: A\n 623-dimensionally equidistributed uniform pseudorandom number\n generator,\" *ACM Trans. on Modeling and Computer Simulation*,\n Vol. 8, No. 1, pp. 3-30, Jan. 1998.\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_4set_state(PyObject *__pyx_v_self, PyObject *__pyx_v_state) {
PyArrayObject *arrayObject_obj;
int __pyx_v_pos;
PyObject *__pyx_v_algorithm_name;
@@ -5057,112 +5154,104 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_set_state(PyObject *__pyx_v_self
Py_ssize_t __pyx_t_7;
double __pyx_t_8;
__Pyx_RefNannySetupContext("set_state");
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_state);
arrayObject_obj = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_algorithm_name = Py_None; __Pyx_INCREF(Py_None);
__pyx_v_key = Py_None; __Pyx_INCREF(Py_None);
__pyx_v_has_gauss = Py_None; __Pyx_INCREF(Py_None);
__pyx_v_cached_gaussian = Py_None; __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":686
+ /* "mtrand.pyx":687
* cdef ndarray obj "arrayObject_obj"
* cdef int pos
* algorithm_name = state[0] # <<<<<<<<<<<<<<
* if algorithm_name != 'MT19937':
* raise ValueError("algorithm must be 'MT19937'")
*/
- __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_state, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 686; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_state, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_v_algorithm_name);
__pyx_v_algorithm_name = __pyx_t_1;
__pyx_t_1 = 0;
- /* "mtrand.pyx":687
+ /* "mtrand.pyx":688
* cdef int pos
* algorithm_name = state[0]
* if algorithm_name != 'MT19937': # <<<<<<<<<<<<<<
* raise ValueError("algorithm must be 'MT19937'")
* key, pos = state[1:3]
*/
- __pyx_t_1 = PyObject_RichCompare(__pyx_v_algorithm_name, ((PyObject *)__pyx_n_s__MT19937), Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyObject_RichCompare(__pyx_v_algorithm_name, ((PyObject *)__pyx_n_s__MT19937), Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 688; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 688; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if (__pyx_t_2) {
- /* "mtrand.pyx":688
+ /* "mtrand.pyx":689
* algorithm_name = state[0]
* if algorithm_name != 'MT19937':
* raise ValueError("algorithm must be 'MT19937'") # <<<<<<<<<<<<<<
* key, pos = state[1:3]
* if len(state) == 3:
*/
- __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 688; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_10), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_2));
- PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_kp_s_2));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_2));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 688; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_1, 0, 0);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 688; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L5;
}
__pyx_L5:;
- /* "mtrand.pyx":689
+ /* "mtrand.pyx":690
* if algorithm_name != 'MT19937':
* raise ValueError("algorithm must be 'MT19937'")
* key, pos = state[1:3] # <<<<<<<<<<<<<<
* if len(state) == 3:
* has_gauss = 0
*/
- __pyx_t_3 = PySequence_GetSlice(__pyx_v_state, 1, 3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- if (PyTuple_CheckExact(__pyx_t_3) && likely(PyTuple_GET_SIZE(__pyx_t_3) == 2)) {
- PyObject* tuple = __pyx_t_3;
- __pyx_t_1 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_1);
+ __pyx_t_1 = __Pyx_PySequence_GetSlice(__pyx_v_state, 1, 3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ if (PyTuple_CheckExact(__pyx_t_1) && likely(PyTuple_GET_SIZE(__pyx_t_1) == 2)) {
+ PyObject* tuple = __pyx_t_1;
+ __pyx_t_3 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_3);
__pyx_t_4 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_4);
- __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_v_key);
- __pyx_v_key = __pyx_t_1;
- __pyx_t_1 = 0;
+ __pyx_v_key = __pyx_t_3;
+ __pyx_t_3 = 0;
__pyx_v_pos = __pyx_t_5;
} else {
- __pyx_t_6 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_6 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_6);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_1 = __Pyx_UnpackItem(__pyx_t_6, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_t_4 = __Pyx_UnpackItem(__pyx_t_6, 1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_t_3 = __Pyx_UnpackItem(__pyx_t_6, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_t_4 = __Pyx_UnpackItem(__pyx_t_6, 1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- if (__Pyx_EndUnpack(__pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__Pyx_EndUnpack(__pyx_t_6, 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__Pyx_DECREF(__pyx_v_key);
- __pyx_v_key = __pyx_t_1;
- __pyx_t_1 = 0;
+ __pyx_v_key = __pyx_t_3;
+ __pyx_t_3 = 0;
__pyx_v_pos = __pyx_t_5;
}
- /* "mtrand.pyx":690
+ /* "mtrand.pyx":691
* raise ValueError("algorithm must be 'MT19937'")
* key, pos = state[1:3]
* if len(state) == 3: # <<<<<<<<<<<<<<
* has_gauss = 0
* cached_gaussian = 0.0
*/
- __pyx_t_7 = PyObject_Length(__pyx_v_state); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_7 = PyObject_Length(__pyx_v_state); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_t_2 = (__pyx_t_7 == 3);
if (__pyx_t_2) {
- /* "mtrand.pyx":691
+ /* "mtrand.pyx":692
* key, pos = state[1:3]
* if len(state) == 3:
* has_gauss = 0 # <<<<<<<<<<<<<<
@@ -5173,63 +5262,63 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_set_state(PyObject *__pyx_v_self
__Pyx_DECREF(__pyx_v_has_gauss);
__pyx_v_has_gauss = __pyx_int_0;
- /* "mtrand.pyx":692
+ /* "mtrand.pyx":693
* if len(state) == 3:
* has_gauss = 0
* cached_gaussian = 0.0 # <<<<<<<<<<<<<<
* else:
* has_gauss, cached_gaussian = state[3:5]
*/
- __pyx_t_3 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __pyx_t_1 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_v_cached_gaussian);
- __pyx_v_cached_gaussian = __pyx_t_3;
- __pyx_t_3 = 0;
+ __pyx_v_cached_gaussian = __pyx_t_1;
+ __pyx_t_1 = 0;
goto __pyx_L6;
}
/*else*/ {
- /* "mtrand.pyx":694
+ /* "mtrand.pyx":695
* cached_gaussian = 0.0
* else:
* has_gauss, cached_gaussian = state[3:5] # <<<<<<<<<<<<<<
* try:
* obj = <ndarray>PyArray_ContiguousFromObject(key, NPY_ULONG, 1, 1)
*/
- __pyx_t_3 = PySequence_GetSlice(__pyx_v_state, 3, 5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- if (PyTuple_CheckExact(__pyx_t_3) && likely(PyTuple_GET_SIZE(__pyx_t_3) == 2)) {
- PyObject* tuple = __pyx_t_3;
+ __pyx_t_1 = __Pyx_PySequence_GetSlice(__pyx_v_state, 3, 5); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 695; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ if (PyTuple_CheckExact(__pyx_t_1) && likely(PyTuple_GET_SIZE(__pyx_t_1) == 2)) {
+ PyObject* tuple = __pyx_t_1;
__pyx_t_4 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_4);
- __pyx_t_1 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_t_3 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_v_has_gauss);
__pyx_v_has_gauss = __pyx_t_4;
__pyx_t_4 = 0;
__Pyx_DECREF(__pyx_v_cached_gaussian);
- __pyx_v_cached_gaussian = __pyx_t_1;
- __pyx_t_1 = 0;
+ __pyx_v_cached_gaussian = __pyx_t_3;
+ __pyx_t_3 = 0;
} else {
- __pyx_t_6 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_6 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 695; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_6);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_4 = __Pyx_UnpackItem(__pyx_t_6, 0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_t_4 = __Pyx_UnpackItem(__pyx_t_6, 0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 695; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __pyx_t_1 = __Pyx_UnpackItem(__pyx_t_6, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- if (__Pyx_EndUnpack(__pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_UnpackItem(__pyx_t_6, 1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 695; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ if (__Pyx_EndUnpack(__pyx_t_6, 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 695; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__Pyx_DECREF(__pyx_v_has_gauss);
__pyx_v_has_gauss = __pyx_t_4;
__pyx_t_4 = 0;
__Pyx_DECREF(__pyx_v_cached_gaussian);
- __pyx_v_cached_gaussian = __pyx_t_1;
- __pyx_t_1 = 0;
+ __pyx_v_cached_gaussian = __pyx_t_3;
+ __pyx_t_3 = 0;
}
}
__pyx_L6:;
- /* "mtrand.pyx":695
+ /* "mtrand.pyx":696
* else:
* has_gauss, cached_gaussian = state[3:5]
* try: # <<<<<<<<<<<<<<
@@ -5244,19 +5333,19 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_set_state(PyObject *__pyx_v_self
__Pyx_XGOTREF(__pyx_save_exc_tb);
/*try:*/ {
- /* "mtrand.pyx":696
+ /* "mtrand.pyx":697
* has_gauss, cached_gaussian = state[3:5]
* try:
* obj = <ndarray>PyArray_ContiguousFromObject(key, NPY_ULONG, 1, 1) # <<<<<<<<<<<<<<
* except TypeError:
* # compatibility -- could be an older pickle
*/
- __pyx_t_3 = PyArray_ContiguousFromObject(__pyx_v_key, NPY_ULONG, 1, 1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __pyx_L7_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
+ __pyx_t_1 = PyArray_ContiguousFromObject(__pyx_v_key, NPY_ULONG, 1, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L7_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_1)));
__Pyx_DECREF(((PyObject *)arrayObject_obj));
- arrayObject_obj = ((PyArrayObject *)__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ arrayObject_obj = ((PyArrayObject *)__pyx_t_1);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
}
__Pyx_XDECREF(__pyx_save_exc_type); __pyx_save_exc_type = 0;
__Pyx_XDECREF(__pyx_save_exc_value); __pyx_save_exc_value = 0;
@@ -5265,10 +5354,10 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_set_state(PyObject *__pyx_v_self
__pyx_L7_error:;
__Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
- /* "mtrand.pyx":697
+ /* "mtrand.pyx":698
* try:
* obj = <ndarray>PyArray_ContiguousFromObject(key, NPY_ULONG, 1, 1)
* except TypeError: # <<<<<<<<<<<<<<
@@ -5278,26 +5367,26 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_set_state(PyObject *__pyx_v_self
__pyx_t_5 = PyErr_ExceptionMatches(__pyx_builtin_TypeError);
if (__pyx_t_5) {
__Pyx_AddTraceback("mtrand.RandomState.set_state");
- if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_1, &__pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_3, &__pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 698; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
__Pyx_GOTREF(__pyx_t_1);
+ __Pyx_GOTREF(__pyx_t_3);
__Pyx_GOTREF(__pyx_t_4);
- /* "mtrand.pyx":699
+ /* "mtrand.pyx":700
* except TypeError:
* # compatibility -- could be an older pickle
* obj = <ndarray>PyArray_ContiguousFromObject(key, NPY_LONG, 1, 1) # <<<<<<<<<<<<<<
* if obj.dimensions[0] != 624:
* raise ValueError("state must be 624 longs")
*/
- __pyx_t_6 = PyArray_ContiguousFromObject(__pyx_v_key, NPY_LONG, 1, 1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 699; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
+ __pyx_t_6 = PyArray_ContiguousFromObject(__pyx_v_key, NPY_LONG, 1, 1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
__Pyx_GOTREF(__pyx_t_6);
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_6)));
__Pyx_DECREF(((PyObject *)arrayObject_obj));
arrayObject_obj = ((PyArrayObject *)__pyx_t_6);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
goto __pyx_L8_exception_handled;
}
@@ -5315,7 +5404,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_set_state(PyObject *__pyx_v_self
__pyx_L14_try_end:;
}
- /* "mtrand.pyx":700
+ /* "mtrand.pyx":701
* # compatibility -- could be an older pickle
* obj = <ndarray>PyArray_ContiguousFromObject(key, NPY_LONG, 1, 1)
* if obj.dimensions[0] != 624: # <<<<<<<<<<<<<<
@@ -5325,29 +5414,23 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_set_state(PyObject *__pyx_v_self
__pyx_t_2 = ((arrayObject_obj->dimensions[0]) != 624);
if (__pyx_t_2) {
- /* "mtrand.pyx":701
+ /* "mtrand.pyx":702
* obj = <ndarray>PyArray_ContiguousFromObject(key, NPY_LONG, 1, 1)
* if obj.dimensions[0] != 624:
* raise ValueError("state must be 624 longs") # <<<<<<<<<<<<<<
* memcpy(<void*>(self.internal_state.key), <void*>(obj.data), 624*sizeof(long))
* self.internal_state.pos = pos
*/
- __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_12), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_3));
- PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_kp_s_3));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3));
- __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_Raise(__pyx_t_4, 0, 0);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_Raise(__pyx_t_1, 0, 0);
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L17;
}
__pyx_L17:;
- /* "mtrand.pyx":702
+ /* "mtrand.pyx":703
* if obj.dimensions[0] != 624:
* raise ValueError("state must be 624 longs")
* memcpy(<void*>(self.internal_state.key), <void*>(obj.data), 624*sizeof(long)) # <<<<<<<<<<<<<<
@@ -5356,7 +5439,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_set_state(PyObject *__pyx_v_self
*/
memcpy(((void *)((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state->key), ((void *)arrayObject_obj->data), (624 * (sizeof(long))));
- /* "mtrand.pyx":703
+ /* "mtrand.pyx":704
* raise ValueError("state must be 624 longs")
* memcpy(<void*>(self.internal_state.key), <void*>(obj.data), 624*sizeof(long))
* self.internal_state.pos = pos # <<<<<<<<<<<<<<
@@ -5365,24 +5448,24 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_set_state(PyObject *__pyx_v_self
*/
((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state->pos = __pyx_v_pos;
- /* "mtrand.pyx":704
+ /* "mtrand.pyx":705
* memcpy(<void*>(self.internal_state.key), <void*>(obj.data), 624*sizeof(long))
* self.internal_state.pos = pos
* self.internal_state.has_gauss = has_gauss # <<<<<<<<<<<<<<
* self.internal_state.gauss = cached_gaussian
*
*/
- __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_v_has_gauss); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_v_has_gauss); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state->has_gauss = __pyx_t_5;
- /* "mtrand.pyx":705
+ /* "mtrand.pyx":706
* self.internal_state.pos = pos
* self.internal_state.has_gauss = has_gauss
* self.internal_state.gauss = cached_gaussian # <<<<<<<<<<<<<<
*
* # Pickling support:
*/
- __pyx_t_8 = __pyx_PyFloat_AsDouble(__pyx_v_cached_gaussian); if (unlikely((__pyx_t_8 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_8 = __pyx_PyFloat_AsDouble(__pyx_v_cached_gaussian); if (unlikely((__pyx_t_8 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 706; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state->gauss = __pyx_t_8;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -5400,14 +5483,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_set_state(PyObject *__pyx_v_self
__Pyx_DECREF(__pyx_v_key);
__Pyx_DECREF(__pyx_v_has_gauss);
__Pyx_DECREF(__pyx_v_cached_gaussian);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_state);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":708
+/* "mtrand.pyx":709
*
* # Pickling support:
* def __getstate__(self): # <<<<<<<<<<<<<<
@@ -5415,14 +5496,14 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_set_state(PyObject *__pyx_v_self
*
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState___getstate__(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
-static PyObject *__pyx_pf_6mtrand_11RandomState___getstate__(PyObject *__pyx_v_self, PyObject *unused) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_5__getstate__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pf_6mtrand_11RandomState_5__getstate__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
PyObject *__pyx_r = NULL;
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
__Pyx_RefNannySetupContext("__getstate__");
- /* "mtrand.pyx":709
+ /* "mtrand.pyx":710
* # Pickling support:
* def __getstate__(self):
* return self.get_state() # <<<<<<<<<<<<<<
@@ -5430,9 +5511,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState___getstate__(PyObject *__pyx_v_s
* def __setstate__(self, state):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__get_state); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__get_state); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_r = __pyx_t_2;
@@ -5452,7 +5533,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState___getstate__(PyObject *__pyx_v_s
return __pyx_r;
}
-/* "mtrand.pyx":711
+/* "mtrand.pyx":712
* return self.get_state()
*
* def __setstate__(self, state): # <<<<<<<<<<<<<<
@@ -5460,32 +5541,32 @@ static PyObject *__pyx_pf_6mtrand_11RandomState___getstate__(PyObject *__pyx_v_s
*
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState___setstate__(PyObject *__pyx_v_self, PyObject *__pyx_v_state); /*proto*/
-static PyObject *__pyx_pf_6mtrand_11RandomState___setstate__(PyObject *__pyx_v_self, PyObject *__pyx_v_state) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_6__setstate__(PyObject *__pyx_v_self, PyObject *__pyx_v_state); /*proto*/
+static PyObject *__pyx_pf_6mtrand_11RandomState_6__setstate__(PyObject *__pyx_v_self, PyObject *__pyx_v_state) {
PyObject *__pyx_r = NULL;
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
PyObject *__pyx_t_3 = NULL;
__Pyx_RefNannySetupContext("__setstate__");
- /* "mtrand.pyx":712
+ /* "mtrand.pyx":713
*
* def __setstate__(self, state):
* self.set_state(state) # <<<<<<<<<<<<<<
*
* def __reduce__(self):
*/
- __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__set_state); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__set_state); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_state);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_state);
__Pyx_GIVEREF(__pyx_v_state);
- __pyx_t_3 = PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -5502,7 +5583,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState___setstate__(PyObject *__pyx_v_s
return __pyx_r;
}
-/* "mtrand.pyx":714
+/* "mtrand.pyx":715
* self.set_state(state)
*
* def __reduce__(self): # <<<<<<<<<<<<<<
@@ -5510,15 +5591,15 @@ static PyObject *__pyx_pf_6mtrand_11RandomState___setstate__(PyObject *__pyx_v_s
*
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState___reduce__(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
-static PyObject *__pyx_pf_6mtrand_11RandomState___reduce__(PyObject *__pyx_v_self, PyObject *unused) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_7__reduce__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pf_6mtrand_11RandomState_7__reduce__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
PyObject *__pyx_r = NULL;
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
PyObject *__pyx_t_3 = NULL;
__Pyx_RefNannySetupContext("__reduce__");
- /* "mtrand.pyx":715
+ /* "mtrand.pyx":716
*
* def __reduce__(self):
* return (np.random.__RandomState_ctor, (), self.get_state()) # <<<<<<<<<<<<<<
@@ -5526,21 +5607,21 @@ static PyObject *__pyx_pf_6mtrand_11RandomState___reduce__(PyObject *__pyx_v_sel
* # Basic distributions:
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__random); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__random); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____RandomState_ctor); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____RandomState_ctor); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__get_state); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__get_state); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __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(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
__Pyx_GIVEREF(__pyx_t_1);
__Pyx_INCREF(((PyObject *)__pyx_empty_tuple));
@@ -5550,7 +5631,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState___reduce__(PyObject *__pyx_v_sel
__Pyx_GIVEREF(__pyx_t_3);
__pyx_t_1 = 0;
__pyx_t_3 = 0;
- __pyx_r = __pyx_t_2;
+ __pyx_r = ((PyObject *)__pyx_t_2);
__pyx_t_2 = 0;
goto __pyx_L0;
@@ -5568,7 +5649,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState___reduce__(PyObject *__pyx_v_sel
return __pyx_r;
}
-/* "mtrand.pyx":718
+/* "mtrand.pyx":719
*
* # Basic distributions:
* def random_sample(self, size=None): # <<<<<<<<<<<<<<
@@ -5576,9 +5657,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState___reduce__(PyObject *__pyx_v_sel
* random_sample(size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_random_sample(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_random_sample[] = "\n random_sample(size=None)\n\n Return random floats in the half-open interval [0.0, 1.0).\n\n Results are from the \"continuous uniform\" distribution over the\n stated interval. To sample :math:`Unif[a, b), b > a` multiply\n the output of `random_sample` by `(b-a)` and add `a`::\n\n (b - a) * random_sample() + a\n\n Parameters\n ----------\n size : int or tuple of ints, optional\n Defines the shape of the returned array of random floats. If None\n (the default), returns a single float.\n\n Returns\n -------\n out : float or ndarray of floats\n Array of random floats of shape `size` (unless ``size=None``, in which\n case a single float is returned).\n\n Examples\n --------\n >>> np.random.random_sample()\n 0.47108547995356098\n >>> type(np.random.random_sample())\n <type 'float'>\n >>> np.random.random_sample((5,))\n array([ 0.30220482, 0.86820401, 0.1654503 , 0.11659149, 0.54323428])\n\n Three-by-two array of random numbers from [-5, 0):\n\n >>> 5 * np.random.random_sample((3, 2)) - 5\n array([[-3.99149989, -0.52338984],\n [-2.99091858, -0.79479508],\n [-1.23204345, -1.75224494]])\n\n ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_random_sample(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_8random_sample(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_8random_sample[] = "\n random_sample(size=None)\n\n Return random floats in the half-open interval [0.0, 1.0).\n\n Results are from the \"continuous uniform\" distribution over the\n stated interval. To sample :math:`Unif[a, b), b > a` multiply\n the output of `random_sample` by `(b-a)` and add `a`::\n\n (b - a) * random_sample() + a\n\n Parameters\n ----------\n size : int or tuple of ints, optional\n Defines the shape of the returned array of random floats. If None\n (the default), returns a single float.\n\n Returns\n -------\n out : float or ndarray of floats\n Array of random floats of shape `size` (unless ``size=None``, in which\n case a single float is returned).\n\n Examples\n --------\n >>> np.random.random_sample()\n 0.47108547995356098\n >>> type(np.random.random_sample())\n <type 'float'>\n >>> np.random.random_sample((5,))\n array([ 0.30220482, 0.86820401, 0.1654503 , 0.11659149, 0.54323428])\n\n Three-by-two array of random numbers from [-5, 0):\n\n >>> 5 * np.random.random_sample((3, 2)) - 5\n array([[-3.99149989, -0.52338984],\n [-2.99091858, -0.79479508],\n [-1.23204345, -1.75224494]])\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_8random_sample(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_size = 0;
PyObject *__pyx_r = NULL;
PyObject *__pyx_t_1 = NULL;
@@ -5595,13 +5676,13 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_random_sample(PyObject *__pyx_v_
}
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 0:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[0] = value; kw_args--; }
+ if (value) { values[0] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "random_sample") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 718; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "random_sample") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 719; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_size = values[0];
} else {
@@ -5614,13 +5695,14 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_random_sample(PyObject *__pyx_v_
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("random_sample", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 718; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("random_sample", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 719; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.random_sample");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- /* "mtrand.pyx":759
+ /* "mtrand.pyx":760
*
* """
* return cont0_array(self.internal_state, rk_double, size) # <<<<<<<<<<<<<<
@@ -5628,7 +5710,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_random_sample(PyObject *__pyx_v_
* def tomaxint(self, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = __pyx_f_6mtrand_cont0_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_double, __pyx_v_size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 759; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __pyx_f_6mtrand_cont0_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_double, __pyx_v_size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
@@ -5646,7 +5728,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_random_sample(PyObject *__pyx_v_
return __pyx_r;
}
-/* "mtrand.pyx":761
+/* "mtrand.pyx":762
* return cont0_array(self.internal_state, rk_double, size)
*
* def tomaxint(self, size=None): # <<<<<<<<<<<<<<
@@ -5654,9 +5736,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_random_sample(PyObject *__pyx_v_
* tomaxint(size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_tomaxint(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_tomaxint[] = "\n tomaxint(size=None)\n\n Uniformly sample discrete random integers `x` such that\n ``0 <= x <= sys.maxint``.\n\n Parameters\n ----------\n size : tuple of ints, int, optional\n Shape of output. If the given size is, for example, (m,n,k),\n m*n*k samples are generated. If no shape is specified, a single sample\n is returned.\n\n Returns\n -------\n out : ndarray\n Drawn samples, with shape `size`.\n\n See Also\n --------\n randint : Uniform sampling over a given half-open interval of integers.\n random_integers : Uniform sampling over a given closed interval of\n integers.\n\n ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_tomaxint(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_9tomaxint(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_9tomaxint[] = "\n tomaxint(size=None)\n\n Random integers between 0 and ``sys.maxint``, inclusive.\n\n Return a sample of uniformly distributed random integers in the interval\n [0, ``sys.maxint``].\n\n Parameters\n ----------\n size : tuple of ints, int, optional\n Shape of output. If this is, for example, (m,n,k), m*n*k samples\n are generated. If no shape is specified, a single sample is\n returned.\n\n Returns\n -------\n out : ndarray\n Drawn samples, with shape `size`.\n\n See Also\n --------\n randint : Uniform sampling over a given half-open interval of integers.\n random_integers : Uniform sampling over a given closed interval of\n integers.\n\n Examples\n --------\n >>> RS = np.random.mtrand.RandomState() # need a RandomState object\n >>> RS.tomaxint((2,2,2))\n array([[[1170048599, 1600360186],\n [ 739731006, 1947757578]],\n [[1871712945, 752307660],\n [1601631370, 1479324245]]])\n >>> import sys\n >>> sys.maxint\n 2147483647\n >>> RS.tomaxint((2,2,2)) < sys.maxint\n array([[[ True, True],\n [ True, True]],\n [[ True, True],\n [ True, True]]], dtype=bool)\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_9tomaxint(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_size = 0;
PyObject *__pyx_r = NULL;
PyObject *__pyx_t_1 = NULL;
@@ -5673,13 +5755,13 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_tomaxint(PyObject *__pyx_v_self,
}
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 0:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[0] = value; kw_args--; }
+ if (value) { values[0] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "tomaxint") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 761; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "tomaxint") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 762; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_size = values[0];
} else {
@@ -5692,13 +5774,14 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_tomaxint(PyObject *__pyx_v_self,
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("tomaxint", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 761; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("tomaxint", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 762; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.tomaxint");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- /* "mtrand.pyx":787
+ /* "mtrand.pyx":807
*
* """
* return disc0_array(self.internal_state, rk_long, size) # <<<<<<<<<<<<<<
@@ -5706,7 +5789,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_tomaxint(PyObject *__pyx_v_self,
* def randint(self, low, high=None, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = __pyx_f_6mtrand_disc0_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_long, __pyx_v_size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __pyx_f_6mtrand_disc0_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_long, __pyx_v_size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
@@ -5724,7 +5807,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_tomaxint(PyObject *__pyx_v_self,
return __pyx_r;
}
-/* "mtrand.pyx":789
+/* "mtrand.pyx":809
* return disc0_array(self.internal_state, rk_long, size)
*
* def randint(self, low, high=None, size=None): # <<<<<<<<<<<<<<
@@ -5732,15 +5815,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_tomaxint(PyObject *__pyx_v_self,
* randint(low, high=None, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_randint(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_randint[] = "\n randint(low, high=None, size=None)\n\n Return random integers from `low` (inclusive) to `high` (exclusive).\n\n Return random integers from the \"discrete uniform\" distribution in the\n \"half-open\" interval [`low`, `high`). If `high` is None (the default),\n then results are from [0, `low`).\n\n Parameters\n ----------\n low : int\n Lowest (signed) integer to be drawn from the distribution (unless\n ``high=None``, in which case this parameter is the *highest* such\n integer).\n high : int, optional\n If provided, one above the largest (signed) integer to be drawn\n from the distribution (see above for behavior if ``high=None``).\n size : int or tuple of ints, optional\n Output shape. Default is None, in which case a single int is\n returned.\n\n Returns\n -------\n out : int or ndarray of ints\n `size`-shaped array of random integers from the appropriate\n distribution, or a single such random int if `size` not provided.\n\n See Also\n --------\n random.random_integers : similar to `randint`, only for the closed\n interval [`low`, `high`], and 1 is the lowest value if `high` is\n omitted. In particular, this other one is the one to use to generate\n uniformly distributed discrete non-integers.\n\n Examples\n --------\n >>> np.random.randint(2, size=10)\n array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0])\n >>> np.random.randint(1, size=10)\n array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])\n\n Generate a 2 x 4 array of ints between 0 and 4, inclusive:\n\n >>> np.random.randint(5, size=(2, 4))\n array([[4, 0, 2, 1],\n [3, 2, 2, 0]])\n\n ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_randint(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_10randint(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_10randint[] = "\n randint(low, high=None, size=None)\n\n Return random integers from `low` (inclusive) to `high` (exclusive).\n\n Return random integers from the \"discrete uniform\" distribution in the\n \"half-open\" interval [`low`, `high`). If `high` is None (the default),\n then results are from [0, `low`).\n\n Parameters\n ----------\n low : int\n Lowest (signed) integer to be drawn from the distribution (unless\n ``high=None``, in which case this parameter is the *highest* such\n integer).\n high : int, optional\n If provided, one above the largest (signed) integer to be drawn\n from the distribution (see above for behavior if ``high=None``).\n size : int or tuple of ints, optional\n Output shape. Default is None, in which case a single int is\n returned.\n\n Returns\n -------\n out : int or ndarray of ints\n `size`-shaped array of random integers from the appropriate\n distribution, or a single such random int if `size` not provided.\n\n See Also\n --------\n random.random_integers : similar to `randint`, only for the closed\n interval [`low`, `high`], and 1 is the lowest value if `high` is\n omitted. In particular, this other one is the one to use to generate\n uniformly distributed discrete non-integers.\n\n Examples\n --------\n >>> np.random.randint(2, size=10)\n array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0])\n >>> np.random.randint(1, size=10)\n array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])\n\n Generate a 2 x 4 array of ints between 0 and 4, inclusive:\n\n >>> np.random.randint(5, size=(2, 4))\n array([[4, 0, 2, 1],\n [3, 2, 2, 0]])\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_10randint(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_low = 0;
PyObject *__pyx_v_high = 0;
PyObject *__pyx_v_size = 0;
long __pyx_v_lo;
long __pyx_v_hi;
- long __pyx_v_diff;
+ long __pyx_v_rv;
+ unsigned long __pyx_v_diff;
long *__pyx_v_array_data;
PyArrayObject *arrayObject;
long __pyx_v_length;
@@ -5771,18 +5855,18 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_randint(PyObject *__pyx_v_self,
if (likely(values[0])) kw_args--;
else goto __pyx_L5_argtuple_error;
case 1:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__high);
- if (unlikely(value)) { values[1] = value; kw_args--; }
+ if (value) { values[1] = value; kw_args--; }
}
case 2:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[2] = value; kw_args--; }
+ if (value) { values[2] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "randint") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "randint") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 809; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_low = values[0];
__pyx_v_high = values[1];
@@ -5800,18 +5884,15 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_randint(PyObject *__pyx_v_self,
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("randint", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("randint", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 809; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.randint");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_low);
- __Pyx_INCREF(__pyx_v_high);
- __Pyx_INCREF(__pyx_v_size);
arrayObject = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":845
+ /* "mtrand.pyx":866
* cdef long i
*
* if high is None: # <<<<<<<<<<<<<<
@@ -5821,7 +5902,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_randint(PyObject *__pyx_v_self,
__pyx_t_1 = (__pyx_v_high == Py_None);
if (__pyx_t_1) {
- /* "mtrand.pyx":846
+ /* "mtrand.pyx":867
*
* if high is None:
* lo = 0 # <<<<<<<<<<<<<<
@@ -5830,139 +5911,142 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_randint(PyObject *__pyx_v_self,
*/
__pyx_v_lo = 0;
- /* "mtrand.pyx":847
+ /* "mtrand.pyx":868
* if high is None:
* lo = 0
* hi = low # <<<<<<<<<<<<<<
* else:
* lo = low
*/
- __pyx_t_2 = __Pyx_PyInt_AsLong(__pyx_v_low); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 847; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_PyInt_AsLong(__pyx_v_low); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_v_hi = __pyx_t_2;
goto __pyx_L6;
}
/*else*/ {
- /* "mtrand.pyx":849
+ /* "mtrand.pyx":870
* hi = low
* else:
* lo = low # <<<<<<<<<<<<<<
* hi = high
*
*/
- __pyx_t_2 = __Pyx_PyInt_AsLong(__pyx_v_low); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_PyInt_AsLong(__pyx_v_low); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_v_lo = __pyx_t_2;
- /* "mtrand.pyx":850
+ /* "mtrand.pyx":871
* else:
* lo = low
* hi = high # <<<<<<<<<<<<<<
*
- * diff = hi - lo - 1
+ * if lo >= hi :
*/
- __pyx_t_2 = __Pyx_PyInt_AsLong(__pyx_v_high); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 850; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_PyInt_AsLong(__pyx_v_high); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_v_hi = __pyx_t_2;
}
__pyx_L6:;
- /* "mtrand.pyx":852
+ /* "mtrand.pyx":873
* hi = high
*
- * diff = hi - lo - 1 # <<<<<<<<<<<<<<
- * if diff < 0:
- * raise ValueError("low >= high")
- */
- __pyx_v_diff = ((__pyx_v_hi - __pyx_v_lo) - 1);
-
- /* "mtrand.pyx":853
- *
- * diff = hi - lo - 1
- * if diff < 0: # <<<<<<<<<<<<<<
+ * if lo >= hi : # <<<<<<<<<<<<<<
* raise ValueError("low >= high")
*
*/
- __pyx_t_1 = (__pyx_v_diff < 0);
+ __pyx_t_1 = (__pyx_v_lo >= __pyx_v_hi);
if (__pyx_t_1) {
- /* "mtrand.pyx":854
- * diff = hi - lo - 1
- * if diff < 0:
+ /* "mtrand.pyx":874
+ *
+ * if lo >= hi :
* raise ValueError("low >= high") # <<<<<<<<<<<<<<
*
- * if size is None:
+ * diff = <unsigned long>hi - <unsigned long>lo - 1UL
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_14), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 874; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_4));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_4));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_4));
- __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_Raise(__pyx_t_3, 0, 0);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_Raise(__pyx_t_4, 0, 0);
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 874; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":856
+ /* "mtrand.pyx":876
* raise ValueError("low >= high")
*
+ * diff = <unsigned long>hi - <unsigned long>lo - 1UL # <<<<<<<<<<<<<<
+ * if size is None:
+ * rv = lo + <long>rk_interval(diff, self. internal_state)
+ */
+ __pyx_v_diff = ((((unsigned long)__pyx_v_hi) - ((unsigned long)__pyx_v_lo)) - 1UL);
+
+ /* "mtrand.pyx":877
+ *
+ * diff = <unsigned long>hi - <unsigned long>lo - 1UL
* if size is None: # <<<<<<<<<<<<<<
- * return <long>rk_interval(diff, self.internal_state) + lo
- * else:
+ * rv = lo + <long>rk_interval(diff, self. internal_state)
+ * return rv
*/
__pyx_t_1 = (__pyx_v_size == Py_None);
if (__pyx_t_1) {
- /* "mtrand.pyx":857
- *
+ /* "mtrand.pyx":878
+ * diff = <unsigned long>hi - <unsigned long>lo - 1UL
* if size is None:
- * return <long>rk_interval(diff, self.internal_state) + lo # <<<<<<<<<<<<<<
+ * rv = lo + <long>rk_interval(diff, self. internal_state) # <<<<<<<<<<<<<<
+ * return rv
+ * else:
+ */
+ __pyx_v_rv = (__pyx_v_lo + ((long)rk_interval(__pyx_v_diff, ((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state)));
+
+ /* "mtrand.pyx":879
+ * if size is None:
+ * rv = lo + <long>rk_interval(diff, self. internal_state)
+ * return rv # <<<<<<<<<<<<<<
* else:
* array = <ndarray>np.empty(size, int)
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_4 = PyInt_FromLong((((long)rk_interval(__pyx_v_diff, ((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state)) + __pyx_v_lo)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- __pyx_r = __pyx_t_4;
- __pyx_t_4 = 0;
+ __pyx_t_3 = PyInt_FromLong(__pyx_v_rv); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 879; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_r = __pyx_t_3;
+ __pyx_t_3 = 0;
goto __pyx_L0;
goto __pyx_L8;
}
/*else*/ {
- /* "mtrand.pyx":859
- * return <long>rk_interval(diff, self.internal_state) + lo
+ /* "mtrand.pyx":881
+ * return rv
* else:
* array = <ndarray>np.empty(size, int) # <<<<<<<<<<<<<<
* length = PyArray_SIZE(array)
* array_data = <long *>array.data
*/
- __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 881; __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 = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
+ __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 = 881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_3));
__Pyx_INCREF(__pyx_v_size);
- PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_size);
+ PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_size);
__Pyx_GIVEREF(__pyx_v_size);
- __Pyx_INCREF(((PyObject *)((PyObject*)&PyInt_Type)));
- PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)((PyObject*)&PyInt_Type)));
- __Pyx_GIVEREF(((PyObject *)((PyObject*)&PyInt_Type)));
- __pyx_t_5 = PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_INCREF(((PyObject *)((PyObject*)(&PyInt_Type))));
+ PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)((PyObject*)(&PyInt_Type))));
+ __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyInt_Type))));
+ __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 = 881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_5)));
__Pyx_DECREF(((PyObject *)arrayObject));
arrayObject = ((PyArrayObject *)__pyx_t_5);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- /* "mtrand.pyx":860
+ /* "mtrand.pyx":882
* else:
* array = <ndarray>np.empty(size, int)
* length = PyArray_SIZE(array) # <<<<<<<<<<<<<<
@@ -5971,38 +6055,47 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_randint(PyObject *__pyx_v_self,
*/
__pyx_v_length = PyArray_SIZE(arrayObject);
- /* "mtrand.pyx":861
+ /* "mtrand.pyx":883
* array = <ndarray>np.empty(size, int)
* length = PyArray_SIZE(array)
* array_data = <long *>array.data # <<<<<<<<<<<<<<
* for i from 0 <= i < length:
- * array_data[i] = lo + <long>rk_interval(diff, self.internal_state)
+ * rv = lo + <long>rk_interval(diff, self. internal_state)
*/
__pyx_v_array_data = ((long *)arrayObject->data);
- /* "mtrand.pyx":862
+ /* "mtrand.pyx":884
* length = PyArray_SIZE(array)
* array_data = <long *>array.data
* for i from 0 <= i < length: # <<<<<<<<<<<<<<
- * array_data[i] = lo + <long>rk_interval(diff, self.internal_state)
- * return array
+ * rv = lo + <long>rk_interval(diff, self. internal_state)
+ * array_data[i] = rv
*/
__pyx_t_2 = __pyx_v_length;
for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) {
- /* "mtrand.pyx":863
+ /* "mtrand.pyx":885
* array_data = <long *>array.data
* for i from 0 <= i < length:
- * array_data[i] = lo + <long>rk_interval(diff, self.internal_state) # <<<<<<<<<<<<<<
+ * rv = lo + <long>rk_interval(diff, self. internal_state) # <<<<<<<<<<<<<<
+ * array_data[i] = rv
+ * return array
+ */
+ __pyx_v_rv = (__pyx_v_lo + ((long)rk_interval(__pyx_v_diff, ((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state)));
+
+ /* "mtrand.pyx":886
+ * for i from 0 <= i < length:
+ * rv = lo + <long>rk_interval(diff, self. internal_state)
+ * array_data[i] = rv # <<<<<<<<<<<<<<
* return array
*
*/
- (__pyx_v_array_data[__pyx_v_i]) = (__pyx_v_lo + ((long)rk_interval(__pyx_v_diff, ((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state)));
+ (__pyx_v_array_data[__pyx_v_i]) = __pyx_v_rv;
}
- /* "mtrand.pyx":864
- * for i from 0 <= i < length:
- * array_data[i] = lo + <long>rk_interval(diff, self.internal_state)
+ /* "mtrand.pyx":887
+ * rv = lo + <long>rk_interval(diff, self. internal_state)
+ * array_data[i] = rv
* return array # <<<<<<<<<<<<<<
*
* def bytes(self, unsigned int length):
@@ -6024,16 +6117,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_randint(PyObject *__pyx_v_self,
__pyx_r = NULL;
__pyx_L0:;
__Pyx_DECREF((PyObject *)arrayObject);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_low);
- __Pyx_DECREF(__pyx_v_high);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":866
+/* "mtrand.pyx":889
* return array
*
* def bytes(self, unsigned int length): # <<<<<<<<<<<<<<
@@ -6041,9 +6130,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_randint(PyObject *__pyx_v_self,
* bytes(length)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_bytes(PyObject *__pyx_v_self, PyObject *__pyx_arg_length); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_bytes[] = "\n bytes(length)\n\n Return random bytes.\n\n Parameters\n ----------\n length : int\n Number of random bytes.\n\n Returns\n -------\n out : str\n String of length `N`.\n\n Examples\n --------\n >>> np.random.bytes(10)\n ' eh\\x85\\x022SZ\\xbf\\xa4' #random\n\n ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_bytes(PyObject *__pyx_v_self, PyObject *__pyx_arg_length) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_11bytes(PyObject *__pyx_v_self, PyObject *__pyx_arg_length); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_11bytes[] = "\n bytes(length)\n\n Return random bytes.\n\n Parameters\n ----------\n length : int\n Number of random bytes.\n\n Returns\n -------\n out : str\n String of length `length`.\n\n Examples\n --------\n >>> np.random.bytes(10)\n ' eh\\x85\\x022SZ\\xbf\\xa4' #random\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_11bytes(PyObject *__pyx_v_self, PyObject *__pyx_arg_length) {
unsigned int __pyx_v_length;
void *__pyx_v_bytes;
PyObject *__pyx_v_bytestring;
@@ -6051,29 +6140,30 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_bytes(PyObject *__pyx_v_self, Py
PyObject *__pyx_t_1 = NULL;
__Pyx_RefNannySetupContext("bytes");
assert(__pyx_arg_length); {
- __pyx_v_length = __Pyx_PyInt_AsUnsignedInt(__pyx_arg_length); if (unlikely((__pyx_v_length == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 866; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __pyx_v_length = __Pyx_PyInt_AsUnsignedInt(__pyx_arg_length); if (unlikely((__pyx_v_length == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.bytes");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_v_bytestring = Py_None; __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":889
+ /* "mtrand.pyx":912
* """
* cdef void *bytes
* bytestring = empty_py_bytes(length, &bytes) # <<<<<<<<<<<<<<
* rk_fill(bytes, length, self.internal_state)
* return bytestring
*/
- __pyx_t_1 = empty_py_bytes(__pyx_v_length, (&__pyx_v_bytes)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = empty_py_bytes(__pyx_v_length, (&__pyx_v_bytes)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 912; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_v_bytestring);
__pyx_v_bytestring = __pyx_t_1;
__pyx_t_1 = 0;
- /* "mtrand.pyx":890
+ /* "mtrand.pyx":913
* cdef void *bytes
* bytestring = empty_py_bytes(length, &bytes)
* rk_fill(bytes, length, self.internal_state) # <<<<<<<<<<<<<<
@@ -6082,7 +6172,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_bytes(PyObject *__pyx_v_self, Py
*/
rk_fill(__pyx_v_bytes, __pyx_v_length, ((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state);
- /* "mtrand.pyx":891
+ /* "mtrand.pyx":914
* bytestring = empty_py_bytes(length, &bytes)
* rk_fill(bytes, length, self.internal_state)
* return bytestring # <<<<<<<<<<<<<<
@@ -6107,7 +6197,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_bytes(PyObject *__pyx_v_self, Py
return __pyx_r;
}
-/* "mtrand.pyx":893
+/* "mtrand.pyx":916
* return bytestring
*
* def uniform(self, low=0.0, high=1.0, size=None): # <<<<<<<<<<<<<<
@@ -6115,9 +6205,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_bytes(PyObject *__pyx_v_self, Py
* uniform(low=0.0, high=1.0, size=1)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_uniform(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_uniform[] = "\n"" uniform(low=0.0, high=1.0, size=1)\n""\n"" Draw samples from a uniform distribution.\n""\n"" Samples are uniformly distributed over the half-open interval\n"" ``[low, high)`` (includes low, but excludes high). In other words,\n"" any value within the given interval is equally likely to be drawn\n"" by `uniform`.\n""\n"" Parameters\n"" ----------\n"" low : float, optional\n"" Lower boundary of the output interval. All values generated will be\n"" greater than or equal to low. The default value is 0.\n"" high : float\n"" Upper boundary of the output interval. All values generated will be\n"" less than high. The default value is 1.0.\n"" size : tuple of ints, int, optional\n"" Shape of output. If the given size is, for example, (m,n,k),\n"" m*n*k samples are generated. If no shape is specified, a single sample\n"" is returned.\n""\n"" Returns\n"" -------\n"" out : ndarray\n"" Drawn samples, with shape `size`.\n""\n"" See Also\n"" --------\n"" randint : Discrete uniform distribution, yielding integers.\n"" random_integers : Discrete uniform distribution over the closed interval\n"" ``[low, high]``.\n"" random_sample : Floats uniformly distributed over ``[0, 1)``.\n"" random : Alias for `random_sample`.\n"" rand : Convenience function that accepts dimensions as input, e.g.,\n"" ``rand(2,2)`` would generate a 2-by-2 array of floats, uniformly\n"" distributed over ``[0, 1)``.\n""\n"" Notes\n"" -----\n"" The probability density function of the uniform distribution is\n""\n"" .. math:: p(x) = \\frac{1}{b - a}\n""\n"" anywhere within the interval ``[a, b)``, and zero elsewhere.\n""\n"" Examples\n"" --------\n"" Draw samples from the distribution:\n""\n"" >>> s = np.random.uniform(-1,0,1000)\n""\n"" All values are within the given interval:\n""\n"" >>> np.all(s >= -1)\n"" True\n""\n"" >>> np.all(s < 0)\n"" True\n""\n"" Display the histogram of the samples, along with the\n"" probability density function:\n""\n"" >>> import matplotlib.pyplot as plt\n"" >>> count, bins, ignored = plt.hist(s, 15, normed=True)\n"" >>> plt.plot(bins, np.ones_like(bins), linewidth=2, color='r')\n"" >>> plt.show()\n""\n"" ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_uniform(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_12uniform(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_12uniform[] = "\n uniform(low=0.0, high=1.0, size=1)\n\n Draw samples from a uniform distribution.\n\n Samples are uniformly distributed over the half-open interval\n ``[low, high)`` (includes low, but excludes high). In other words,\n any value within the given interval is equally likely to be drawn\n by `uniform`.\n\n Parameters\n ----------\n low : float, optional\n Lower boundary of the output interval. All values generated will be\n greater than or equal to low. The default value is 0.\n high : float\n Upper boundary of the output interval. All values generated will be\n less than high. The default value is 1.0.\n size : int or tuple of ints, optional\n Shape of output. If the given size is, for example, (m,n,k),\n m*n*k samples are generated. If no shape is specified, a single sample\n is returned.\n\n Returns\n -------\n out : ndarray\n Drawn samples, with shape `size`.\n\n See Also\n --------\n randint : Discrete uniform distribution, yielding integers.\n random_integers : Discrete uniform distribution over the closed\n interval ``[low, high]``.\n random_sample : Floats uniformly distributed over ``[0, 1)``.\n random : Alias for `random_sample`.\n rand : Convenience function that accepts dimensions as input, e.g.,\n ``rand(2,2)`` would generate a 2-by-2 array of floats,\n uniformly distributed over ``[0, 1)``.\n\n Notes\n -----\n The probability density function of the uniform distribution is\n\n .. math:: p(x) = \\frac{1}{b - a}\n\n anywhere within the interval ``[a, b)``, and zero elsewhere.\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> s = np.random.uniform(-1,0,1000)\n\n All values are w""ithin the given interval:\n\n >>> np.all(s >= -1)\n True\n >>> np.all(s < 0)\n True\n\n Display the histogram of the samples, along with the\n probability density function:\n\n >>> import matplotlib.pyplot as plt\n >>> count, bins, ignored = plt.hist(s, 15, normed=True)\n >>> plt.plot(bins, np.ones_like(bins), linewidth=2, color='r')\n >>> plt.show()\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_12uniform(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_low = 0;
PyObject *__pyx_v_high = 0;
PyObject *__pyx_v_size = 0;
@@ -6137,8 +6227,8 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_uniform(PyObject *__pyx_v_self,
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
PyObject* values[3] = {0,0,0};
- values[0] = __pyx_k_5;
- values[1] = __pyx_k_6;
+ values[0] = __pyx_k_15;
+ values[1] = __pyx_k_16;
values[2] = ((PyObject *)Py_None);
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
@@ -6149,30 +6239,30 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_uniform(PyObject *__pyx_v_self,
}
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 0:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__low);
- if (unlikely(value)) { values[0] = value; kw_args--; }
+ if (value) { values[0] = value; kw_args--; }
}
case 1:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__high);
- if (unlikely(value)) { values[1] = value; kw_args--; }
+ if (value) { values[1] = value; kw_args--; }
}
case 2:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[2] = value; kw_args--; }
+ if (value) { values[2] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "uniform") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 893; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "uniform") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 916; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_low = values[0];
__pyx_v_high = values[1];
__pyx_v_size = values[2];
} else {
- __pyx_v_low = __pyx_k_5;
- __pyx_v_high = __pyx_k_6;
+ __pyx_v_low = __pyx_k_15;
+ __pyx_v_high = __pyx_k_16;
__pyx_v_size = ((PyObject *)Py_None);
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 3: __pyx_v_size = PyTuple_GET_ITEM(__pyx_args, 2);
@@ -6184,21 +6274,18 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_uniform(PyObject *__pyx_v_self,
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("uniform", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 893; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("uniform", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 916; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.uniform");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_low);
- __Pyx_INCREF(__pyx_v_high);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_olow = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_ohigh = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_odiff = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_temp = Py_None; __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":968
+ /* "mtrand.pyx":990
* cdef object temp
*
* flow = PyFloat_AsDouble(low) # <<<<<<<<<<<<<<
@@ -6207,7 +6294,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_uniform(PyObject *__pyx_v_self,
*/
__pyx_v_flow = PyFloat_AsDouble(__pyx_v_low);
- /* "mtrand.pyx":969
+ /* "mtrand.pyx":991
*
* flow = PyFloat_AsDouble(low)
* fhigh = PyFloat_AsDouble(high) # <<<<<<<<<<<<<<
@@ -6216,7 +6303,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_uniform(PyObject *__pyx_v_self,
*/
__pyx_v_fhigh = PyFloat_AsDouble(__pyx_v_high);
- /* "mtrand.pyx":970
+ /* "mtrand.pyx":992
* flow = PyFloat_AsDouble(low)
* fhigh = PyFloat_AsDouble(high)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -6226,7 +6313,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_uniform(PyObject *__pyx_v_self,
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":971
+ /* "mtrand.pyx":993
* fhigh = PyFloat_AsDouble(high)
* if not PyErr_Occurred():
* return cont2_array_sc(self.internal_state, rk_uniform, size, flow, fhigh-flow) # <<<<<<<<<<<<<<
@@ -6234,7 +6321,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_uniform(PyObject *__pyx_v_self,
* olow = <ndarray>PyArray_FROM_OTF(low, NPY_DOUBLE, NPY_ALIGNED)
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_2 = __pyx_f_6mtrand_cont2_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_uniform, __pyx_v_size, __pyx_v_flow, (__pyx_v_fhigh - __pyx_v_flow)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 971; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __pyx_f_6mtrand_cont2_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_uniform, __pyx_v_size, __pyx_v_flow, (__pyx_v_fhigh - __pyx_v_flow)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__pyx_r = __pyx_t_2;
__pyx_t_2 = 0;
@@ -6243,7 +6330,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_uniform(PyObject *__pyx_v_self,
}
__pyx_L6:;
- /* "mtrand.pyx":972
+ /* "mtrand.pyx":994
* if not PyErr_Occurred():
* return cont2_array_sc(self.internal_state, rk_uniform, size, flow, fhigh-flow)
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -6252,63 +6339,63 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_uniform(PyObject *__pyx_v_self,
*/
PyErr_Clear();
- /* "mtrand.pyx":973
+ /* "mtrand.pyx":995
* return cont2_array_sc(self.internal_state, rk_uniform, size, flow, fhigh-flow)
* PyErr_Clear()
* olow = <ndarray>PyArray_FROM_OTF(low, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* ohigh = <ndarray>PyArray_FROM_OTF(high, NPY_DOUBLE, NPY_ALIGNED)
* temp = np.subtract(ohigh, olow)
*/
- __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_low, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 973; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_low, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_olow));
__pyx_v_olow = ((PyArrayObject *)__pyx_t_2);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":974
+ /* "mtrand.pyx":996
* PyErr_Clear()
* olow = <ndarray>PyArray_FROM_OTF(low, NPY_DOUBLE, NPY_ALIGNED)
* ohigh = <ndarray>PyArray_FROM_OTF(high, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* temp = np.subtract(ohigh, olow)
* Py_INCREF(temp) # needed to get around Pyrex's automatic reference-counting
*/
- __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_high, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 974; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_high, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 996; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_ohigh));
__pyx_v_ohigh = ((PyArrayObject *)__pyx_t_2);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":975
+ /* "mtrand.pyx":997
* olow = <ndarray>PyArray_FROM_OTF(low, NPY_DOUBLE, NPY_ALIGNED)
* ohigh = <ndarray>PyArray_FROM_OTF(high, NPY_DOUBLE, NPY_ALIGNED)
* temp = np.subtract(ohigh, olow) # <<<<<<<<<<<<<<
* Py_INCREF(temp) # needed to get around Pyrex's automatic reference-counting
* # rules because EnsureArray steals a reference
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 975; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 997; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__subtract); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 975; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__subtract); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 997; __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 = 975; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 997; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(((PyObject *)__pyx_v_ohigh));
PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_ohigh));
__Pyx_GIVEREF(((PyObject *)__pyx_v_ohigh));
__Pyx_INCREF(((PyObject *)__pyx_v_olow));
PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_olow));
__Pyx_GIVEREF(((PyObject *)__pyx_v_olow));
- __pyx_t_4 = PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 975; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 997; __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_2)); __pyx_t_2 = 0;
__Pyx_DECREF(__pyx_v_temp);
__pyx_v_temp = __pyx_t_4;
__pyx_t_4 = 0;
- /* "mtrand.pyx":976
+ /* "mtrand.pyx":998
* ohigh = <ndarray>PyArray_FROM_OTF(high, NPY_DOUBLE, NPY_ALIGNED)
* temp = np.subtract(ohigh, olow)
* Py_INCREF(temp) # needed to get around Pyrex's automatic reference-counting # <<<<<<<<<<<<<<
@@ -6317,21 +6404,21 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_uniform(PyObject *__pyx_v_self,
*/
Py_INCREF(__pyx_v_temp);
- /* "mtrand.pyx":978
+ /* "mtrand.pyx":1000
* Py_INCREF(temp) # needed to get around Pyrex's automatic reference-counting
* # rules because EnsureArray steals a reference
* odiff = <ndarray>PyArray_EnsureArray(temp) # <<<<<<<<<<<<<<
* return cont2_array(self.internal_state, rk_uniform, size, olow, odiff)
*
*/
- __pyx_t_4 = PyArray_EnsureArray(__pyx_v_temp); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 978; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyArray_EnsureArray(__pyx_v_temp); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1000; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_4)));
__Pyx_DECREF(((PyObject *)__pyx_v_odiff));
__pyx_v_odiff = ((PyArrayObject *)__pyx_t_4);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "mtrand.pyx":979
+ /* "mtrand.pyx":1001
* # rules because EnsureArray steals a reference
* odiff = <ndarray>PyArray_EnsureArray(temp)
* return cont2_array(self.internal_state, rk_uniform, size, olow, odiff) # <<<<<<<<<<<<<<
@@ -6339,7 +6426,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_uniform(PyObject *__pyx_v_self,
* def rand(self, *args):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_4 = __pyx_f_6mtrand_cont2_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_uniform, __pyx_v_size, __pyx_v_olow, __pyx_v_odiff); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 979; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __pyx_f_6mtrand_cont2_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_uniform, __pyx_v_size, __pyx_v_olow, __pyx_v_odiff); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1001; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__pyx_r = __pyx_t_4;
__pyx_t_4 = 0;
@@ -6358,16 +6445,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_uniform(PyObject *__pyx_v_self,
__Pyx_DECREF((PyObject *)__pyx_v_ohigh);
__Pyx_DECREF((PyObject *)__pyx_v_odiff);
__Pyx_DECREF(__pyx_v_temp);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_low);
- __Pyx_DECREF(__pyx_v_high);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":981
+/* "mtrand.pyx":1003
* return cont2_array(self.internal_state, rk_uniform, size, olow, odiff)
*
* def rand(self, *args): # <<<<<<<<<<<<<<
@@ -6375,9 +6458,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_uniform(PyObject *__pyx_v_self,
* rand(d0, d1, ..., dn)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_rand(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_rand[] = "\n rand(d0, d1, ..., dn)\n\n Random values in a given shape.\n\n Create an array of the given shape and propagate it with\n random samples from a uniform distribution\n over ``[0, 1)``.\n\n Parameters\n ----------\n d0, d1, ..., dn : int\n Shape of the output.\n\n Returns\n -------\n out : ndarray, shape ``(d0, d1, ..., dn)``\n Random values.\n\n See Also\n --------\n random\n\n Notes\n -----\n This is a convenience function. If you want an interface that\n takes a shape-tuple as the first argument, refer to\n `random`.\n\n Examples\n --------\n >>> np.random.rand(3,2)\n array([[ 0.14022471, 0.96360618], #random\n [ 0.37601032, 0.25528411], #random\n [ 0.49313049, 0.94909878]]) #random\n\n ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_rand(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_13rand(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_13rand[] = "\n rand(d0, d1, ..., dn)\n\n Random values in a given shape.\n\n Create an array of the given shape and propagate it with\n random samples from a uniform distribution\n over ``[0, 1)``.\n\n Parameters\n ----------\n d0, d1, ..., dn : int\n Shape of the output.\n\n Returns\n -------\n out : ndarray, shape ``(d0, d1, ..., dn)``\n Random values.\n\n See Also\n --------\n random\n\n Notes\n -----\n This is a convenience function. If you want an interface that\n takes a shape-tuple as the first argument, refer to\n `random`.\n\n Examples\n --------\n >>> np.random.rand(3,2)\n array([[ 0.14022471, 0.96360618], #random\n [ 0.37601032, 0.25528411], #random\n [ 0.49313049, 0.94909878]]) #random\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_13rand(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_args = 0;
PyObject *__pyx_r = NULL;
Py_ssize_t __pyx_t_1;
@@ -6389,20 +6472,22 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_rand(PyObject *__pyx_v_self, PyO
if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "rand", 0))) return NULL;
__Pyx_INCREF(__pyx_args);
__pyx_v_args = __pyx_args;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- /* "mtrand.pyx":1019
+ /* "mtrand.pyx":1041
*
* """
* if len(args) == 0: # <<<<<<<<<<<<<<
* return self.random_sample()
* else:
*/
- __pyx_t_1 = PyObject_Length(__pyx_v_args); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1019; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(__pyx_v_args == Py_None)) {
+ PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ __pyx_t_1 = PyTuple_GET_SIZE(((PyObject *)__pyx_v_args));
__pyx_t_2 = (__pyx_t_1 == 0);
if (__pyx_t_2) {
- /* "mtrand.pyx":1020
+ /* "mtrand.pyx":1042
* """
* if len(args) == 0:
* return self.random_sample() # <<<<<<<<<<<<<<
@@ -6410,9 +6495,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_rand(PyObject *__pyx_v_self, PyO
* return self.random_sample(size=args)
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__random_sample); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__random_sample); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_r = __pyx_t_4;
@@ -6422,7 +6507,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_rand(PyObject *__pyx_v_self, PyO
}
/*else*/ {
- /* "mtrand.pyx":1022
+ /* "mtrand.pyx":1044
* return self.random_sample()
* else:
* return self.random_sample(size=args) # <<<<<<<<<<<<<<
@@ -6430,12 +6515,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_rand(PyObject *__pyx_v_self, PyO
* def randn(self, *args):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__random_sample); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__random_sample); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_3));
- if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__size), __pyx_v_args) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __pyx_t_5 = PyEval_CallObjectWithKeywords(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__size), ((PyObject *)__pyx_v_args)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyEval_CallObjectWithKeywords(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1044; __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_3)); __pyx_t_3 = 0;
@@ -6455,13 +6540,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_rand(PyObject *__pyx_v_self, PyO
__pyx_r = NULL;
__pyx_L0:;
__Pyx_DECREF(__pyx_v_args);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":1024
+/* "mtrand.pyx":1046
* return self.random_sample(size=args)
*
* def randn(self, *args): # <<<<<<<<<<<<<<
@@ -6469,9 +6553,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_rand(PyObject *__pyx_v_self, PyO
* randn([d1, ..., dn])
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_randn(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_randn[] = "\n randn([d1, ..., dn])\n\n Return a sample (or samples) from the \"standard normal\" distribution.\n\n If positive, int_like or int-convertible arguments are provided,\n `randn` generates an array of shape ``(d1, ..., dn)``, filled\n with random floats sampled from a univariate \"normal\" (Gaussian)\n distribution of mean 0 and variance 1 (if any of the :math:`d_i` are\n floats, they are first converted to integers by truncation). A single\n float randomly sampled from the distribution is returned if no\n argument is provided.\n\n This is a convenience function. If you want an interface that takes a\n tuple as the first argument, use `numpy.random.standard_normal` instead.\n\n Parameters\n ----------\n d1, ..., dn : `n` ints, optional\n The dimensions of the returned array, should be all positive.\n\n Returns\n -------\n Z : ndarray or float\n A ``(d1, ..., dn)``-shaped array of floating-point samples from\n the standard normal distribution, or a single such float if\n no parameters were supplied.\n\n See Also\n --------\n random.standard_normal : Similar, but takes a tuple as its argument.\n\n Notes\n -----\n For random samples from :math:`N(\\mu, \\sigma^2)`, use:\n\n ``sigma * np.random.randn(...) + mu``\n\n Examples\n --------\n >>> np.random.randn()\n 2.1923875335537315 #random\n\n Two-by-four array of samples from N(3, 6.25):\n\n >>> 2.5 * np.random.randn(2, 4) + 3\n array([[-4.49401501, 4.00950034, -1.81814867, 7.29718677], #random\n [ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) #random\n\n ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_randn(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_14randn(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_14randn[] = "\n randn([d1, ..., dn])\n\n Return a sample (or samples) from the \"standard normal\" distribution.\n\n If positive, int_like or int-convertible arguments are provided,\n `randn` generates an array of shape ``(d1, ..., dn)``, filled\n with random floats sampled from a univariate \"normal\" (Gaussian)\n distribution of mean 0 and variance 1 (if any of the :math:`d_i` are\n floats, they are first converted to integers by truncation). A single\n float randomly sampled from the distribution is returned if no\n argument is provided.\n\n This is a convenience function. If you want an interface that takes a\n tuple as the first argument, use `numpy.random.standard_normal` instead.\n\n Parameters\n ----------\n d1, ..., dn : `n` ints, optional\n The dimensions of the returned array, should be all positive.\n\n Returns\n -------\n Z : ndarray or float\n A ``(d1, ..., dn)``-shaped array of floating-point samples from\n the standard normal distribution, or a single such float if\n no parameters were supplied.\n\n See Also\n --------\n random.standard_normal : Similar, but takes a tuple as its argument.\n\n Notes\n -----\n For random samples from :math:`N(\\mu, \\sigma^2)`, use:\n\n ``sigma * np.random.randn(...) + mu``\n\n Examples\n --------\n >>> np.random.randn()\n 2.1923875335537315 #random\n\n Two-by-four array of samples from N(3, 6.25):\n\n >>> 2.5 * np.random.randn(2, 4) + 3\n array([[-4.49401501, 4.00950034, -1.81814867, 7.29718677], #random\n [ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) #random\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_14randn(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_args = 0;
PyObject *__pyx_r = NULL;
Py_ssize_t __pyx_t_1;
@@ -6483,20 +6567,22 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_randn(PyObject *__pyx_v_self, Py
if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "randn", 0))) return NULL;
__Pyx_INCREF(__pyx_args);
__pyx_v_args = __pyx_args;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- /* "mtrand.pyx":1075
+ /* "mtrand.pyx":1097
*
* """
* if len(args) == 0: # <<<<<<<<<<<<<<
* return self.standard_normal()
* else:
*/
- __pyx_t_1 = PyObject_Length(__pyx_v_args); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(__pyx_v_args == Py_None)) {
+ PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ __pyx_t_1 = PyTuple_GET_SIZE(((PyObject *)__pyx_v_args));
__pyx_t_2 = (__pyx_t_1 == 0);
if (__pyx_t_2) {
- /* "mtrand.pyx":1076
+ /* "mtrand.pyx":1098
* """
* if len(args) == 0:
* return self.standard_normal() # <<<<<<<<<<<<<<
@@ -6504,9 +6590,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_randn(PyObject *__pyx_v_self, Py
* return self.standard_normal(args)
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__standard_normal); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__standard_normal); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_r = __pyx_t_4;
@@ -6516,7 +6602,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_randn(PyObject *__pyx_v_self, Py
}
/*else*/ {
- /* "mtrand.pyx":1078
+ /* "mtrand.pyx":1100
* return self.standard_normal()
* else:
* return self.standard_normal(args) # <<<<<<<<<<<<<<
@@ -6524,17 +6610,17 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_randn(PyObject *__pyx_v_self, Py
* def random_integers(self, low, high=None, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__standard_normal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1078; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__standard_normal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1078; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(__pyx_v_args);
- PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_args);
- __Pyx_GIVEREF(__pyx_v_args);
- __pyx_t_5 = PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1078; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_3));
+ __Pyx_INCREF(((PyObject *)__pyx_v_args));
+ PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_args));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_args));
+ __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 = 1100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
__pyx_r = __pyx_t_5;
__pyx_t_5 = 0;
goto __pyx_L0;
@@ -6551,13 +6637,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_randn(PyObject *__pyx_v_self, Py
__pyx_r = NULL;
__pyx_L0:;
__Pyx_DECREF(__pyx_v_args);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":1080
+/* "mtrand.pyx":1102
* return self.standard_normal(args)
*
* def random_integers(self, low, high=None, size=None): # <<<<<<<<<<<<<<
@@ -6565,9 +6650,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_randn(PyObject *__pyx_v_self, Py
* random_integers(low, high=None, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_random_integers(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_random_integers[] = "\n"" random_integers(low, high=None, size=None)\n""\n"" Return random integers between `low` and `high`, inclusive.\n""\n"" Return random integers from the \"discrete uniform\" distribution in the\n"" closed interval [`low`, `high`]. If `high` is None (the default),\n"" then results are from [1, `low`].\n""\n"" Parameters\n"" ----------\n"" low : int\n"" Lowest (signed) integer to be drawn from the distribution (unless\n"" ``high=None``, in which case this parameter is the *highest* such\n"" integer).\n"" high : int, optional\n"" If provided, the largest (signed) integer to be drawn from the\n"" distribution (see above for behavior if ``high=None``).\n"" size : int or tuple of ints, optional\n"" Output shape. Default is None, in which case a single int is returned.\n""\n"" Returns\n"" -------\n"" out : int or ndarray of ints\n"" `size`-shaped array of random integers from the appropriate\n"" distribution, or a single such random int if `size` not provided.\n""\n"" See Also\n"" --------\n"" random.randint : Similar to `random_integers`, only for the half-open\n"" interval [`low`, `high`), and 0 is the lowest value if `high` is\n"" omitted.\n""\n"" Notes\n"" -----\n"" To sample from N evenly spaced floating-point numbers between a and b,\n"" use::\n""\n"" a + (b - a) * (np.random.random_integers(N) - 1) / (N - 1.)\n""\n"" Examples\n"" --------\n"" >>> np.random.random_integers(5)\n"" 4\n"" >>> type(np.random.random_integers(5))\n"" <type 'int'>\n"" >>> np.random.random_integers(5, size=(3.,2.))\n"" array([[5, 4],\n"" [3, 3],\n"" [4, 5]])\n""\n"" Choose five random numbers from the set of five evenly-spaced\n"" numbers between 0 and 2.5, inclusive (*i.e.*, from the set\n"" :math:`{0, 5/8, 10/8, 15/8, 20/8}`):\n""\n"" >>> 2.5 * (np.random.random_integers(5, size=(5,)) - 1) / 4.\n"" array([ 0.625, 1.25 , 0.625, 0.625, 2.5 ])\n""\n"" Roll two six sided dice 1000 times and sum the results:\n""\n"" >>> d1 = np.random.random_integers(1, 6, 1000)\n"" >>> d2 = np.random.random_integers(1, 6, 1000)\n"" >>> dsums = d1 + d2\n""\n"" Display results as a histogram:\n""\n"" >>> import matplotlib.pyplot as plt\n"" >>> count, bins, ignored = plt.hist(dsums, 11, normed=True)\n"" >>> plt.show()\n""\n"" ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_random_integers(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_15random_integers(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_15random_integers[] = "\n random_integers(low, high=None, size=None)\n\n Return random integers between `low` and `high`, inclusive.\n\n Return random integers from the \"discrete uniform\" distribution in the\n closed interval [`low`, `high`]. If `high` is None (the default),\n then results are from [1, `low`].\n\n Parameters\n ----------\n low : int\n Lowest (signed) integer to be drawn from the distribution (unless\n ``high=None``, in which case this parameter is the *highest* such\n integer).\n high : int, optional\n If provided, the largest (signed) integer to be drawn from the\n distribution (see above for behavior if ``high=None``).\n size : int or tuple of ints, optional\n Output shape. Default is None, in which case a single int is returned.\n\n Returns\n -------\n out : int or ndarray of ints\n `size`-shaped array of random integers from the appropriate\n distribution, or a single such random int if `size` not provided.\n\n See Also\n --------\n random.randint : Similar to `random_integers`, only for the half-open\n interval [`low`, `high`), and 0 is the lowest value if `high` is\n omitted.\n\n Notes\n -----\n To sample from N evenly spaced floating-point numbers between a and b,\n use::\n\n a + (b - a) * (np.random.random_integers(N) - 1) / (N - 1.)\n\n Examples\n --------\n >>> np.random.random_integers(5)\n 4\n >>> type(np.random.random_integers(5))\n <type 'int'>\n >>> np.random.random_integers(5, size=(3.,2.))\n array([[5, 4],\n [3, 3],\n [4, 5]])\n\n Choose five random numbers from the set of five evenly-spaced\n numbers between 0 and 2.5, inclusive (*i.e.*, from the set\n :math:`{0, 5/8, 10/8, 15/8, 20/8}`):\n""\n >>> 2.5 * (np.random.random_integers(5, size=(5,)) - 1) / 4.\n array([ 0.625, 1.25 , 0.625, 0.625, 2.5 ])\n\n Roll two six sided dice 1000 times and sum the results:\n\n >>> d1 = np.random.random_integers(1, 6, 1000)\n >>> d2 = np.random.random_integers(1, 6, 1000)\n >>> dsums = d1 + d2\n\n Display results as a histogram:\n\n >>> import matplotlib.pyplot as plt\n >>> count, bins, ignored = plt.hist(dsums, 11, normed=True)\n >>> plt.show()\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_15random_integers(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_low = 0;
PyObject *__pyx_v_high = 0;
PyObject *__pyx_v_size = 0;
@@ -6596,18 +6681,18 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_random_integers(PyObject *__pyx_
if (likely(values[0])) kw_args--;
else goto __pyx_L5_argtuple_error;
case 1:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__high);
- if (unlikely(value)) { values[1] = value; kw_args--; }
+ if (value) { values[1] = value; kw_args--; }
}
case 2:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[2] = value; kw_args--; }
+ if (value) { values[2] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "random_integers") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "random_integers") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1102; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_low = values[0];
__pyx_v_high = values[1];
@@ -6625,17 +6710,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_random_integers(PyObject *__pyx_
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("random_integers", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("random_integers", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1102; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.random_integers");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
__Pyx_INCREF(__pyx_v_low);
__Pyx_INCREF(__pyx_v_high);
- __Pyx_INCREF(__pyx_v_size);
- /* "mtrand.pyx":1152
+ /* "mtrand.pyx":1174
*
* """
* if high is None: # <<<<<<<<<<<<<<
@@ -6645,7 +6729,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_random_integers(PyObject *__pyx_
__pyx_t_1 = (__pyx_v_high == Py_None);
if (__pyx_t_1) {
- /* "mtrand.pyx":1153
+ /* "mtrand.pyx":1175
* """
* if high is None:
* high = low # <<<<<<<<<<<<<<
@@ -6656,7 +6740,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_random_integers(PyObject *__pyx_
__Pyx_DECREF(__pyx_v_high);
__pyx_v_high = __pyx_v_low;
- /* "mtrand.pyx":1154
+ /* "mtrand.pyx":1176
* if high is None:
* high = low
* low = 1 # <<<<<<<<<<<<<<
@@ -6670,7 +6754,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_random_integers(PyObject *__pyx_
}
__pyx_L6:;
- /* "mtrand.pyx":1155
+ /* "mtrand.pyx":1177
* high = low
* low = 1
* return self.randint(low, high+1, size) # <<<<<<<<<<<<<<
@@ -6678,12 +6762,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_random_integers(PyObject *__pyx_
* # Complicated, continuous distributions:
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__randint); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__randint); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyNumber_Add(__pyx_v_high, __pyx_int_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyNumber_Add(__pyx_v_high, __pyx_int_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
__Pyx_INCREF(__pyx_v_low);
PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_low);
__Pyx_GIVEREF(__pyx_v_low);
@@ -6693,10 +6777,10 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_random_integers(PyObject *__pyx_
PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_size);
__Pyx_GIVEREF(__pyx_v_size);
__pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 1177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
__pyx_r = __pyx_t_3;
__pyx_t_3 = 0;
goto __pyx_L0;
@@ -6710,16 +6794,14 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_random_integers(PyObject *__pyx_
__Pyx_AddTraceback("mtrand.RandomState.random_integers");
__pyx_r = NULL;
__pyx_L0:;
- __Pyx_DECREF((PyObject *)__pyx_v_self);
__Pyx_DECREF(__pyx_v_low);
__Pyx_DECREF(__pyx_v_high);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":1158
+/* "mtrand.pyx":1180
*
* # Complicated, continuous distributions:
* def standard_normal(self, size=None): # <<<<<<<<<<<<<<
@@ -6727,9 +6809,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_random_integers(PyObject *__pyx_
* standard_normal(size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_standard_normal(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_standard_normal[] = "\n standard_normal(size=None)\n\n Returns samples from a Standard Normal distribution (mean=0, stdev=1).\n\n Parameters\n ----------\n size : int or tuple of ints, optional\n Output shape. Default is None, in which case a single value is\n returned.\n\n Returns\n -------\n out : float or ndarray\n Drawn samples.\n\n Examples\n --------\n >>> s = np.random.standard_normal(8000)\n >>> s\n array([ 0.6888893 , 0.78096262, -0.89086505, ..., 0.49876311, #random\n -0.38672696, -0.4685006 ]) #random\n >>> s.shape\n (8000,)\n >>> s = np.random.standard_normal(size=(3, 4, 2))\n >>> s.shape\n (3, 4, 2)\n\n ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_standard_normal(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_16standard_normal(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_16standard_normal[] = "\n standard_normal(size=None)\n\n Returns samples from a Standard Normal distribution (mean=0, stdev=1).\n\n Parameters\n ----------\n size : int or tuple of ints, optional\n Output shape. Default is None, in which case a single value is\n returned.\n\n Returns\n -------\n out : float or ndarray\n Drawn samples.\n\n Examples\n --------\n >>> s = np.random.standard_normal(8000)\n >>> s\n array([ 0.6888893 , 0.78096262, -0.89086505, ..., 0.49876311, #random\n -0.38672696, -0.4685006 ]) #random\n >>> s.shape\n (8000,)\n >>> s = np.random.standard_normal(size=(3, 4, 2))\n >>> s.shape\n (3, 4, 2)\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_16standard_normal(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_size = 0;
PyObject *__pyx_r = NULL;
PyObject *__pyx_t_1 = NULL;
@@ -6746,13 +6828,13 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_normal(PyObject *__pyx_
}
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 0:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[0] = value; kw_args--; }
+ if (value) { values[0] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "standard_normal") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1158; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "standard_normal") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1180; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_size = values[0];
} else {
@@ -6765,13 +6847,14 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_normal(PyObject *__pyx_
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("standard_normal", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1158; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("standard_normal", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1180; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.standard_normal");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- /* "mtrand.pyx":1188
+ /* "mtrand.pyx":1210
*
* """
* return cont0_array(self.internal_state, rk_gauss, size) # <<<<<<<<<<<<<<
@@ -6779,7 +6862,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_normal(PyObject *__pyx_
* def normal(self, loc=0.0, scale=1.0, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = __pyx_f_6mtrand_cont0_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_gauss, __pyx_v_size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __pyx_f_6mtrand_cont0_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_gauss, __pyx_v_size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
@@ -6797,7 +6880,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_normal(PyObject *__pyx_
return __pyx_r;
}
-/* "mtrand.pyx":1190
+/* "mtrand.pyx":1212
* return cont0_array(self.internal_state, rk_gauss, size)
*
* def normal(self, loc=0.0, scale=1.0, size=None): # <<<<<<<<<<<<<<
@@ -6805,9 +6888,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_normal(PyObject *__pyx_
* normal(loc=0.0, scale=1.0, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_normal(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_normal[] = "\n"" normal(loc=0.0, scale=1.0, size=None)\n""\n"" Draw random samples from a normal (Gaussian) distribution.\n""\n"" The probability density function of the normal distribution, first\n"" derived by De Moivre and 200 years later by both Gauss and Laplace\n"" independently [2]_, is often called the bell curve because of\n"" its characteristic shape (see the example below).\n""\n"" The normal distributions occurs often in nature. For example, it\n"" describes the commonly occurring distribution of samples influenced\n"" by a large number of tiny, random disturbances, each with its own\n"" unique distribution [2]_.\n""\n"" Parameters\n"" ----------\n"" loc : float\n"" Mean (\"centre\") of the distribution.\n"" scale : float\n"" Standard deviation (spread or \"width\") of the distribution.\n"" size : tuple of ints\n"" Output shape. If the given shape is, e.g., ``(m, n, k)``, then\n"" ``m * n * k`` samples are drawn.\n""\n"" See Also\n"" --------\n"" scipy.stats.distributions.norm : probability density function,\n"" distribution or cumulative density function, etc.\n""\n"" Notes\n"" -----\n"" The probability density for the Gaussian distribution is\n""\n"" .. math:: p(x) = \\frac{1}{\\sqrt{ 2 \\pi \\sigma^2 }}\n"" e^{ - \\frac{ (x - \\mu)^2 } {2 \\sigma^2} },\n""\n"" where :math:`\\mu` is the mean and :math:`\\sigma` the standard deviation.\n"" The square of the standard deviation, :math:`\\sigma^2`, is called the\n"" variance.\n""\n"" The function has its peak at the mean, and its \"spread\" increases with\n"" the standard deviation (the function reaches 0.607 times its maximum at\n"" :math:`x + \\sigma` and :math:`x - \\sigma` [2]_). This implies that\n"" `numpy.random.normal` is more likely to return samples lying close to the\n"" mean, rather than those far away.\n""\n"" References\n"" ----------\n"" .. [1] Wikipedia, \"Normal distribution\",\n"" http://en.wikipedia.org/wiki/Normal_distribution\n"" .. [2] P. R. Peebles Jr., \"Central Limit Theorem\" in \"Probability, Random\n"" Variables and Random Signal Principles\", 4th ed., 2001,\n"" pp. 51, 51, 125.\n""\n"" Examples\n"" --------\n"" Draw samples from the distribution:\n""\n"" >>> mu, sigma = 0, 0.1 # mean and standard deviation\n"" >>> s = np.random.normal(mu, sigma, 1000)\n""\n"" Verify the mean and the variance:\n""\n"" >>> abs(mu - np.mean(s)) < 0.01\n"" True\n""\n"" >>> abs(sigma - np.std(s, ddof=1)) < 0.01\n"" True\n""\n"" Display the histogram of the samples, along with\n"" the probability density function:\n""\n"" >>> import matplotlib.pyplot as plt\n"" >>> count, bins, ignored = plt.hist(s, 30, normed=True)\n"" >>> plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) *\n"" ... np.exp( - (bins - mu)**2 / (2 * sigma**2) ),\n"" ... linewidth=2, color='r')\n"" >>> plt.show()\n""\n"" ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_normal(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_17normal(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_17normal[] = "\n normal(loc=0.0, scale=1.0, size=None)\n\n Draw random samples from a normal (Gaussian) distribution.\n\n The probability density function of the normal distribution, first\n derived by De Moivre and 200 years later by both Gauss and Laplace\n independently [2]_, is often called the bell curve because of\n its characteristic shape (see the example below).\n\n The normal distributions occurs often in nature. For example, it\n describes the commonly occurring distribution of samples influenced\n by a large number of tiny, random disturbances, each with its own\n unique distribution [2]_.\n\n Parameters\n ----------\n loc : float\n Mean (\"centre\") of the distribution.\n scale : float\n Standard deviation (spread or \"width\") of the distribution.\n size : tuple of ints\n Output shape. If the given shape is, e.g., ``(m, n, k)``, then\n ``m * n * k`` samples are drawn.\n\n See Also\n --------\n scipy.stats.distributions.norm : probability density function,\n distribution or cumulative density function, etc.\n\n Notes\n -----\n The probability density for the Gaussian distribution is\n\n .. math:: p(x) = \\frac{1}{\\sqrt{ 2 \\pi \\sigma^2 }}\n e^{ - \\frac{ (x - \\mu)^2 } {2 \\sigma^2} },\n\n where :math:`\\mu` is the mean and :math:`\\sigma` the standard deviation.\n The square of the standard deviation, :math:`\\sigma^2`, is called the\n variance.\n\n The function has its peak at the mean, and its \"spread\" increases with\n the standard deviation (the function reaches 0.607 times its maximum at\n :math:`x + \\sigma` and :math:`x - \\sigma` [2]_). This implies that\n `numpy.random.normal` is more likely to return samples lying close to the\n mean, rather than those far away.\n""\n References\n ----------\n .. [1] Wikipedia, \"Normal distribution\",\n http://en.wikipedia.org/wiki/Normal_distribution\n .. [2] P. R. Peebles Jr., \"Central Limit Theorem\" in \"Probability, Random\n Variables and Random Signal Principles\", 4th ed., 2001,\n pp. 51, 51, 125.\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> mu, sigma = 0, 0.1 # mean and standard deviation\n >>> s = np.random.normal(mu, sigma, 1000)\n\n Verify the mean and the variance:\n\n >>> abs(mu - np.mean(s)) < 0.01\n True\n\n >>> abs(sigma - np.std(s, ddof=1)) < 0.01\n True\n\n Display the histogram of the samples, along with\n the probability density function:\n\n >>> import matplotlib.pyplot as plt\n >>> count, bins, ignored = plt.hist(s, 30, normed=True)\n >>> plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) *\n ... np.exp( - (bins - mu)**2 / (2 * sigma**2) ),\n ... linewidth=2, color='r')\n >>> plt.show()\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_17normal(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_loc = 0;
PyObject *__pyx_v_scale = 0;
PyObject *__pyx_v_size = 0;
@@ -6826,8 +6909,8 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_normal(PyObject *__pyx_v_self, P
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
PyObject* values[3] = {0,0,0};
- values[0] = __pyx_k_7;
- values[1] = __pyx_k_8;
+ values[0] = __pyx_k_17;
+ values[1] = __pyx_k_18;
values[2] = ((PyObject *)Py_None);
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
@@ -6838,30 +6921,30 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_normal(PyObject *__pyx_v_self, P
}
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 0:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__loc);
- if (unlikely(value)) { values[0] = value; kw_args--; }
+ if (value) { values[0] = value; kw_args--; }
}
case 1:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__scale);
- if (unlikely(value)) { values[1] = value; kw_args--; }
+ if (value) { values[1] = value; kw_args--; }
}
case 2:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[2] = value; kw_args--; }
+ if (value) { values[2] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "normal") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1190; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "normal") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1212; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_loc = values[0];
__pyx_v_scale = values[1];
__pyx_v_size = values[2];
} else {
- __pyx_v_loc = __pyx_k_7;
- __pyx_v_scale = __pyx_k_8;
+ __pyx_v_loc = __pyx_k_17;
+ __pyx_v_scale = __pyx_k_18;
__pyx_v_size = ((PyObject *)Py_None);
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 3: __pyx_v_size = PyTuple_GET_ITEM(__pyx_args, 2);
@@ -6873,19 +6956,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_normal(PyObject *__pyx_v_self, P
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("normal", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1190; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("normal", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1212; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.normal");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_loc);
- __Pyx_INCREF(__pyx_v_scale);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_oloc = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_oscale = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":1275
+ /* "mtrand.pyx":1297
* cdef double floc, fscale
*
* floc = PyFloat_AsDouble(loc) # <<<<<<<<<<<<<<
@@ -6894,7 +6974,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_normal(PyObject *__pyx_v_self, P
*/
__pyx_v_floc = PyFloat_AsDouble(__pyx_v_loc);
- /* "mtrand.pyx":1276
+ /* "mtrand.pyx":1298
*
* floc = PyFloat_AsDouble(loc)
* fscale = PyFloat_AsDouble(scale) # <<<<<<<<<<<<<<
@@ -6903,7 +6983,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_normal(PyObject *__pyx_v_self, P
*/
__pyx_v_fscale = PyFloat_AsDouble(__pyx_v_scale);
- /* "mtrand.pyx":1277
+ /* "mtrand.pyx":1299
* floc = PyFloat_AsDouble(loc)
* fscale = PyFloat_AsDouble(scale)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -6913,39 +6993,33 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_normal(PyObject *__pyx_v_self, P
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":1278
+ /* "mtrand.pyx":1300
* fscale = PyFloat_AsDouble(scale)
* if not PyErr_Occurred():
* if fscale <= 0: # <<<<<<<<<<<<<<
* raise ValueError("scale <= 0")
* return cont2_array_sc(self.internal_state, rk_normal, size, floc, fscale)
*/
- __pyx_t_1 = (__pyx_v_fscale <= 0);
+ __pyx_t_1 = (__pyx_v_fscale <= 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":1279
+ /* "mtrand.pyx":1301
* if not PyErr_Occurred():
* if fscale <= 0:
* raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
* return cont2_array_sc(self.internal_state, rk_normal, size, floc, fscale)
*
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_20), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_9));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_9));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_9));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":1280
+ /* "mtrand.pyx":1302
* if fscale <= 0:
* raise ValueError("scale <= 0")
* return cont2_array_sc(self.internal_state, rk_normal, size, floc, fscale) # <<<<<<<<<<<<<<
@@ -6953,16 +7027,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_normal(PyObject *__pyx_v_self, P
* PyErr_Clear()
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = __pyx_f_6mtrand_cont2_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_normal, __pyx_v_size, __pyx_v_floc, __pyx_v_fscale); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1280; __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_cont2_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_normal, __pyx_v_size, __pyx_v_floc, __pyx_v_fscale); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1302; __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_L6;
}
__pyx_L6:;
- /* "mtrand.pyx":1282
+ /* "mtrand.pyx":1304
* return cont2_array_sc(self.internal_state, rk_normal, size, floc, fscale)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -6971,99 +7045,93 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_normal(PyObject *__pyx_v_self, P
*/
PyErr_Clear();
- /* "mtrand.pyx":1284
+ /* "mtrand.pyx":1306
* PyErr_Clear()
*
* oloc = <ndarray>PyArray_FROM_OTF(loc, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* oscale = <ndarray>PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oscale, 0)):
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_loc, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1284; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_loc, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_oloc));
- __pyx_v_oloc = ((PyArrayObject *)__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_oloc = ((PyArrayObject *)__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":1285
+ /* "mtrand.pyx":1307
*
* oloc = <ndarray>PyArray_FROM_OTF(loc, NPY_DOUBLE, NPY_ALIGNED)
* oscale = <ndarray>PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less_equal(oscale, 0)):
* raise ValueError("scale <= 0")
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_scale, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_scale, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_oscale));
- __pyx_v_oscale = ((PyArrayObject *)__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_oscale = ((PyArrayObject *)__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":1286
+ /* "mtrand.pyx":1308
* oloc = <ndarray>PyArray_FROM_OTF(loc, NPY_DOUBLE, NPY_ALIGNED)
* oscale = <ndarray>PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oscale, 0)): # <<<<<<<<<<<<<<
* raise ValueError("scale <= 0")
* return cont2_array(self.internal_state, rk_normal, size, oloc, oscale)
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __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 = 1286; __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 = 1308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(((PyObject *)__pyx_v_oscale));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_oscale));
+ PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_oscale));
__Pyx_GIVEREF(((PyObject *)__pyx_v_oscale));
__Pyx_INCREF(__pyx_int_0);
- PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0);
+ PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_0);
__Pyx_GIVEREF(__pyx_int_0);
- __pyx_t_5 = PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 1308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 1286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
+ __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 = 1308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
__Pyx_GIVEREF(__pyx_t_5);
__pyx_t_5 = 0;
- __pyx_t_5 = PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 1308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_DECREF(__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 = 1286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":1287
+ /* "mtrand.pyx":1309
* oscale = <ndarray>PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oscale, 0)):
* raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
* return cont2_array(self.internal_state, rk_normal, size, oloc, oscale)
*
*/
- __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_21), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1309; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_9));
- PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_9));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_9));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_5, 0, 0);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1309; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":1288
+ /* "mtrand.pyx":1310
* if np.any(np.less_equal(oscale, 0)):
* raise ValueError("scale <= 0")
* return cont2_array(self.internal_state, rk_normal, size, oloc, oscale) # <<<<<<<<<<<<<<
@@ -7071,10 +7139,10 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_normal(PyObject *__pyx_v_self, P
* def beta(self, a, b, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = __pyx_f_6mtrand_cont2_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_normal, __pyx_v_size, __pyx_v_oloc, __pyx_v_oscale); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_r = __pyx_t_3;
- __pyx_t_3 = 0;
+ __pyx_t_5 = __pyx_f_6mtrand_cont2_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_normal, __pyx_v_size, __pyx_v_oloc, __pyx_v_oscale); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_5);
+ __pyx_r = __pyx_t_5;
+ __pyx_t_5 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -7089,16 +7157,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_normal(PyObject *__pyx_v_self, P
__pyx_L0:;
__Pyx_DECREF((PyObject *)__pyx_v_oloc);
__Pyx_DECREF((PyObject *)__pyx_v_oscale);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_loc);
- __Pyx_DECREF(__pyx_v_scale);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":1290
+/* "mtrand.pyx":1312
* return cont2_array(self.internal_state, rk_normal, size, oloc, oscale)
*
* def beta(self, a, b, size=None): # <<<<<<<<<<<<<<
@@ -7106,9 +7170,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_normal(PyObject *__pyx_v_self, P
* beta(a, b, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_beta(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_beta[] = "\n beta(a, b, size=None)\n\n The Beta distribution over ``[0, 1]``.\n\n The Beta distribution is a special case of the Dirichlet distribution,\n and is related to the Gamma distribution. It has the probability\n distribution function\n\n .. math:: f(x; a,b) = \\frac{1}{B(\\alpha, \\beta)} x^{\\alpha - 1}\n (1 - x)^{\\beta - 1},\n\n where the normalisation, B, is the beta function,\n\n .. math:: B(\\alpha, \\beta) = \\int_0^1 t^{\\alpha - 1}\n (1 - t)^{\\beta - 1} dt.\n\n It is often seen in Bayesian inference and order statistics.\n\n Parameters\n ----------\n a : float\n Alpha, non-negative.\n b : float\n Beta, non-negative.\n size : tuple of ints, optional\n The number of samples to draw. The ouput is packed according to\n the size given.\n\n Returns\n -------\n out : ndarray\n Array of the given shape, containing values drawn from a\n Beta distribution.\n\n ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_beta(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_18beta(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_18beta[] = "\n beta(a, b, size=None)\n\n The Beta distribution over ``[0, 1]``.\n\n The Beta distribution is a special case of the Dirichlet distribution,\n and is related to the Gamma distribution. It has the probability\n distribution function\n\n .. math:: f(x; a,b) = \\frac{1}{B(\\alpha, \\beta)} x^{\\alpha - 1}\n (1 - x)^{\\beta - 1},\n\n where the normalisation, B, is the beta function,\n\n .. math:: B(\\alpha, \\beta) = \\int_0^1 t^{\\alpha - 1}\n (1 - t)^{\\beta - 1} dt.\n\n It is often seen in Bayesian inference and order statistics.\n\n Parameters\n ----------\n a : float\n Alpha, non-negative.\n b : float\n Beta, non-negative.\n size : tuple of ints, optional\n The number of samples to draw. The ouput is packed according to\n the size given.\n\n Returns\n -------\n out : ndarray\n Array of the given shape, containing values drawn from a\n Beta distribution.\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_18beta(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_a = 0;
PyObject *__pyx_v_b = 0;
PyObject *__pyx_v_size = 0;
@@ -7144,16 +7208,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_beta(PyObject *__pyx_v_self, PyO
values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__b);
if (likely(values[1])) kw_args--;
else {
- __Pyx_RaiseArgtupleInvalid("beta", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1290; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("beta", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1312; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
case 2:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[2] = value; kw_args--; }
+ if (value) { values[2] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "beta") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1290; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "beta") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1312; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_a = values[0];
__pyx_v_b = values[1];
@@ -7172,19 +7236,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_beta(PyObject *__pyx_v_self, PyO
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("beta", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1290; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("beta", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1312; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.beta");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_a);
- __Pyx_INCREF(__pyx_v_b);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_oa = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_ob = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":1330
+ /* "mtrand.pyx":1352
* cdef double fa, fb
*
* fa = PyFloat_AsDouble(a) # <<<<<<<<<<<<<<
@@ -7193,7 +7254,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_beta(PyObject *__pyx_v_self, PyO
*/
__pyx_v_fa = PyFloat_AsDouble(__pyx_v_a);
- /* "mtrand.pyx":1331
+ /* "mtrand.pyx":1353
*
* fa = PyFloat_AsDouble(a)
* fb = PyFloat_AsDouble(b) # <<<<<<<<<<<<<<
@@ -7202,7 +7263,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_beta(PyObject *__pyx_v_self, PyO
*/
__pyx_v_fb = PyFloat_AsDouble(__pyx_v_b);
- /* "mtrand.pyx":1332
+ /* "mtrand.pyx":1354
* fa = PyFloat_AsDouble(a)
* fb = PyFloat_AsDouble(b)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -7212,71 +7273,59 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_beta(PyObject *__pyx_v_self, PyO
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":1333
+ /* "mtrand.pyx":1355
* fb = PyFloat_AsDouble(b)
* if not PyErr_Occurred():
* if fa <= 0: # <<<<<<<<<<<<<<
* raise ValueError("a <= 0")
* if fb <= 0:
*/
- __pyx_t_1 = (__pyx_v_fa <= 0);
+ __pyx_t_1 = (__pyx_v_fa <= 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":1334
+ /* "mtrand.pyx":1356
* if not PyErr_Occurred():
* if fa <= 0:
* raise ValueError("a <= 0") # <<<<<<<<<<<<<<
* if fb <= 0:
* raise ValueError("b <= 0")
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_23), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_10));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":1335
+ /* "mtrand.pyx":1357
* if fa <= 0:
* raise ValueError("a <= 0")
* if fb <= 0: # <<<<<<<<<<<<<<
* raise ValueError("b <= 0")
* return cont2_array_sc(self.internal_state, rk_beta, size, fa, fb)
*/
- __pyx_t_1 = (__pyx_v_fb <= 0);
+ __pyx_t_1 = (__pyx_v_fb <= 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":1336
+ /* "mtrand.pyx":1358
* raise ValueError("a <= 0")
* if fb <= 0:
* raise ValueError("b <= 0") # <<<<<<<<<<<<<<
* return cont2_array_sc(self.internal_state, rk_beta, size, fa, fb)
*
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_11));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_11));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_11));
- __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_25), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":1337
+ /* "mtrand.pyx":1359
* if fb <= 0:
* raise ValueError("b <= 0")
* return cont2_array_sc(self.internal_state, rk_beta, size, fa, fb) # <<<<<<<<<<<<<<
@@ -7284,7 +7333,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_beta(PyObject *__pyx_v_self, PyO
* PyErr_Clear()
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_2 = __pyx_f_6mtrand_cont2_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_beta, __pyx_v_size, __pyx_v_fa, __pyx_v_fb); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __pyx_f_6mtrand_cont2_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_beta, __pyx_v_size, __pyx_v_fa, __pyx_v_fb); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__pyx_r = __pyx_t_2;
__pyx_t_2 = 0;
@@ -7293,7 +7342,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_beta(PyObject *__pyx_v_self, PyO
}
__pyx_L6:;
- /* "mtrand.pyx":1339
+ /* "mtrand.pyx":1361
* return cont2_array_sc(self.internal_state, rk_beta, size, fa, fb)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -7302,163 +7351,151 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_beta(PyObject *__pyx_v_self, PyO
*/
PyErr_Clear();
- /* "mtrand.pyx":1341
+ /* "mtrand.pyx":1363
* PyErr_Clear()
*
* oa = <ndarray>PyArray_FROM_OTF(a, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* ob = <ndarray>PyArray_FROM_OTF(b, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oa, 0)):
*/
- __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_a, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_a, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_oa));
__pyx_v_oa = ((PyArrayObject *)__pyx_t_2);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":1342
+ /* "mtrand.pyx":1364
*
* oa = <ndarray>PyArray_FROM_OTF(a, NPY_DOUBLE, NPY_ALIGNED)
* ob = <ndarray>PyArray_FROM_OTF(b, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less_equal(oa, 0)):
* raise ValueError("a <= 0")
*/
- __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_b, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_b, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_ob));
__pyx_v_ob = ((PyArrayObject *)__pyx_t_2);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":1343
+ /* "mtrand.pyx":1365
* oa = <ndarray>PyArray_FROM_OTF(a, NPY_DOUBLE, NPY_ALIGNED)
* ob = <ndarray>PyArray_FROM_OTF(b, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oa, 0)): # <<<<<<<<<<<<<<
* raise ValueError("a <= 0")
* if np.any(np.less_equal(ob, 0)):
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __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_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __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 = 1343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(((PyObject *)__pyx_v_oa));
PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_oa));
__Pyx_GIVEREF(((PyObject *)__pyx_v_oa));
__Pyx_INCREF(__pyx_int_0);
PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_0);
__Pyx_GIVEREF(__pyx_int_0);
- __pyx_t_5 = PyObject_Call(__pyx_t_4, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 1343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __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 = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
__Pyx_GIVEREF(__pyx_t_5);
__pyx_t_5 = 0;
- __pyx_t_5 = PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":1344
+ /* "mtrand.pyx":1366
* ob = <ndarray>PyArray_FROM_OTF(b, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oa, 0)):
* raise ValueError("a <= 0") # <<<<<<<<<<<<<<
* if np.any(np.less_equal(ob, 0)):
* raise ValueError("b <= 0")
*/
- __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_26), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
- PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_10));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
- __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_5, 0, 0);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_Raise(__pyx_t_2, 0, 0);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L9;
}
__pyx_L9:;
- /* "mtrand.pyx":1345
+ /* "mtrand.pyx":1367
* if np.any(np.less_equal(oa, 0)):
* raise ValueError("a <= 0")
* if np.any(np.less_equal(ob, 0)): # <<<<<<<<<<<<<<
* raise ValueError("b <= 0")
* return cont2_array(self.internal_state, rk_beta, size, oa, ob)
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_5 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+ __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_5);
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1367; __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 = 1345; __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 = 1367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(((PyObject *)__pyx_v_ob));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_ob));
+ PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_ob));
__Pyx_GIVEREF(((PyObject *)__pyx_v_ob));
__Pyx_INCREF(__pyx_int_0);
- PyTuple_SET_ITEM(__pyx_t_2, 1, __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_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1345; __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 = 1367; __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_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
+ __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 = 1367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__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_5, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 1367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 1367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":1346
+ /* "mtrand.pyx":1368
* raise ValueError("a <= 0")
* if np.any(np.less_equal(ob, 0)):
* raise ValueError("b <= 0") # <<<<<<<<<<<<<<
* return cont2_array(self.internal_state, rk_beta, size, oa, ob)
*
*/
- __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_27), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_11));
- PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_kp_s_11));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_11));
- __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_4, 0, 0);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_Raise(__pyx_t_2, 0, 0);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L10;
}
__pyx_L10:;
- /* "mtrand.pyx":1347
+ /* "mtrand.pyx":1369
* if np.any(np.less_equal(ob, 0)):
* raise ValueError("b <= 0")
* return cont2_array(self.internal_state, rk_beta, size, oa, ob) # <<<<<<<<<<<<<<
@@ -7466,10 +7503,10 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_beta(PyObject *__pyx_v_self, PyO
* def exponential(self, scale=1.0, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_2 = __pyx_f_6mtrand_cont2_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_beta, __pyx_v_size, __pyx_v_oa, __pyx_v_ob); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_r = __pyx_t_2;
- __pyx_t_2 = 0;
+ __pyx_t_4 = __pyx_f_6mtrand_cont2_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_beta, __pyx_v_size, __pyx_v_oa, __pyx_v_ob); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_r = __pyx_t_4;
+ __pyx_t_4 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -7484,16 +7521,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_beta(PyObject *__pyx_v_self, PyO
__pyx_L0:;
__Pyx_DECREF((PyObject *)__pyx_v_oa);
__Pyx_DECREF((PyObject *)__pyx_v_ob);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_a);
- __Pyx_DECREF(__pyx_v_b);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":1349
+/* "mtrand.pyx":1371
* return cont2_array(self.internal_state, rk_beta, size, oa, ob)
*
* def exponential(self, scale=1.0, size=None): # <<<<<<<<<<<<<<
@@ -7501,9 +7534,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_beta(PyObject *__pyx_v_self, PyO
* exponential(scale=1.0, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_exponential(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_exponential[] = "\n exponential(scale=1.0, size=None)\n\n Exponential distribution.\n\n Its probability density function is\n\n .. math:: f(x; \\frac{1}{\\beta}) = \\frac{1}{\\beta} \\exp(-\\frac{x}{\\beta}),\n\n for ``x > 0`` and 0 elsewhere. :math:`\\beta` is the scale parameter,\n which is the inverse of the rate parameter :math:`\\lambda = 1/\\beta`.\n The rate parameter is an alternative, widely used parameterization\n of the exponential distribution [3]_.\n\n The exponential distribution is a continuous analogue of the\n geometric distribution. It describes many common situations, such as\n the size of raindrops measured over many rainstorms [1]_, or the time\n between page requests to Wikipedia [2]_.\n\n Parameters\n ----------\n scale : float\n The scale parameter, :math:`\\beta = 1/\\lambda`.\n size : tuple of ints\n Number of samples to draw. The output is shaped\n according to `size`.\n\n References\n ----------\n .. [1] Peyton Z. Peebles Jr., \"Probability, Random Variables and\n Random Signal Principles\", 4th ed, 2001, p. 57.\n .. [2] \"Poisson Process\", Wikipedia,\n http://en.wikipedia.org/wiki/Poisson_process\n .. [3] \"Exponential Distribution, Wikipedia,\n http://en.wikipedia.org/wiki/Exponential_distribution\n\n ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_exponential(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_19exponential(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_19exponential[] = "\n exponential(scale=1.0, size=None)\n\n Exponential distribution.\n\n Its probability density function is\n\n .. math:: f(x; \\frac{1}{\\beta}) = \\frac{1}{\\beta} \\exp(-\\frac{x}{\\beta}),\n\n for ``x > 0`` and 0 elsewhere. :math:`\\beta` is the scale parameter,\n which is the inverse of the rate parameter :math:`\\lambda = 1/\\beta`.\n The rate parameter is an alternative, widely used parameterization\n of the exponential distribution [3]_.\n\n The exponential distribution is a continuous analogue of the\n geometric distribution. It describes many common situations, such as\n the size of raindrops measured over many rainstorms [1]_, or the time\n between page requests to Wikipedia [2]_.\n\n Parameters\n ----------\n scale : float\n The scale parameter, :math:`\\beta = 1/\\lambda`.\n size : tuple of ints\n Number of samples to draw. The output is shaped\n according to `size`.\n\n References\n ----------\n .. [1] Peyton Z. Peebles Jr., \"Probability, Random Variables and\n Random Signal Principles\", 4th ed, 2001, p. 57.\n .. [2] \"Poisson Process\", Wikipedia,\n http://en.wikipedia.org/wiki/Poisson_process\n .. [3] \"Exponential Distribution, Wikipedia,\n http://en.wikipedia.org/wiki/Exponential_distribution\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_19exponential(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_scale = 0;
PyObject *__pyx_v_size = 0;
PyArrayObject *__pyx_v_oscale;
@@ -7519,7 +7552,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_exponential(PyObject *__pyx_v_se
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
PyObject* values[2] = {0,0};
- values[0] = __pyx_k_12;
+ values[0] = __pyx_k_28;
values[1] = ((PyObject *)Py_None);
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
@@ -7529,23 +7562,23 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_exponential(PyObject *__pyx_v_se
}
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 0:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__scale);
- if (unlikely(value)) { values[0] = value; kw_args--; }
+ if (value) { values[0] = value; kw_args--; }
}
case 1:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[1] = value; kw_args--; }
+ if (value) { values[1] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "exponential") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1349; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "exponential") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1371; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_scale = values[0];
__pyx_v_size = values[1];
} else {
- __pyx_v_scale = __pyx_k_12;
+ __pyx_v_scale = __pyx_k_28;
__pyx_v_size = ((PyObject *)Py_None);
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 2: __pyx_v_size = PyTuple_GET_ITEM(__pyx_args, 1);
@@ -7556,17 +7589,15 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_exponential(PyObject *__pyx_v_se
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("exponential", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1349; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("exponential", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1371; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.exponential");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_scale);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_oscale = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":1390
+ /* "mtrand.pyx":1412
* cdef double fscale
*
* fscale = PyFloat_AsDouble(scale) # <<<<<<<<<<<<<<
@@ -7575,7 +7606,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_exponential(PyObject *__pyx_v_se
*/
__pyx_v_fscale = PyFloat_AsDouble(__pyx_v_scale);
- /* "mtrand.pyx":1391
+ /* "mtrand.pyx":1413
*
* fscale = PyFloat_AsDouble(scale)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -7585,39 +7616,33 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_exponential(PyObject *__pyx_v_se
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":1392
+ /* "mtrand.pyx":1414
* fscale = PyFloat_AsDouble(scale)
* if not PyErr_Occurred():
* if fscale <= 0: # <<<<<<<<<<<<<<
* raise ValueError("scale <= 0")
* return cont1_array_sc(self.internal_state, rk_exponential, size, fscale)
*/
- __pyx_t_1 = (__pyx_v_fscale <= 0);
+ __pyx_t_1 = (__pyx_v_fscale <= 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":1393
+ /* "mtrand.pyx":1415
* if not PyErr_Occurred():
* if fscale <= 0:
* raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
* return cont1_array_sc(self.internal_state, rk_exponential, size, fscale)
*
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_29), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_9));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_9));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_9));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":1394
+ /* "mtrand.pyx":1416
* if fscale <= 0:
* raise ValueError("scale <= 0")
* return cont1_array_sc(self.internal_state, rk_exponential, size, fscale) # <<<<<<<<<<<<<<
@@ -7625,16 +7650,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_exponential(PyObject *__pyx_v_se
* PyErr_Clear()
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = __pyx_f_6mtrand_cont1_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_exponential, __pyx_v_size, __pyx_v_fscale); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1394; __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_cont1_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_exponential, __pyx_v_size, __pyx_v_fscale); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1416; __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_L6;
}
__pyx_L6:;
- /* "mtrand.pyx":1396
+ /* "mtrand.pyx":1418
* return cont1_array_sc(self.internal_state, rk_exponential, size, fscale)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -7643,87 +7668,81 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_exponential(PyObject *__pyx_v_se
*/
PyErr_Clear();
- /* "mtrand.pyx":1398
+ /* "mtrand.pyx":1420
* PyErr_Clear()
*
* oscale = <ndarray> PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less_equal(oscale, 0.0)):
* raise ValueError("scale <= 0")
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_scale, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_scale, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1420; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_oscale));
- __pyx_v_oscale = ((PyArrayObject *)__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_oscale = ((PyArrayObject *)__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":1399
+ /* "mtrand.pyx":1421
*
* oscale = <ndarray> PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oscale, 0.0)): # <<<<<<<<<<<<<<
* raise ValueError("scale <= 0")
* return cont1_array(self.internal_state, rk_exponential, size, oscale)
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(((PyObject *)__pyx_v_oscale));
PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_oscale));
__Pyx_GIVEREF(((PyObject *)__pyx_v_oscale));
- PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 1399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 1421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
+ PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1421; __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_5)); __pyx_t_5 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":1400
+ /* "mtrand.pyx":1422
* oscale = <ndarray> PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oscale, 0.0)):
* raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
* return cont1_array(self.internal_state, rk_exponential, size, oscale)
*
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_9));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_9));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_9));
- __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_Raise(__pyx_t_5, 0, 0);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_30), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1422; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1422; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":1401
+ /* "mtrand.pyx":1423
* if np.any(np.less_equal(oscale, 0.0)):
* raise ValueError("scale <= 0")
* return cont1_array(self.internal_state, rk_exponential, size, oscale) # <<<<<<<<<<<<<<
@@ -7731,10 +7750,10 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_exponential(PyObject *__pyx_v_se
* def standard_exponential(self, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_5 = __pyx_f_6mtrand_cont1_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_exponential, __pyx_v_size, __pyx_v_oscale); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_r = __pyx_t_5;
- __pyx_t_5 = 0;
+ __pyx_t_2 = __pyx_f_6mtrand_cont1_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_exponential, __pyx_v_size, __pyx_v_oscale); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -7748,15 +7767,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_exponential(PyObject *__pyx_v_se
__pyx_r = NULL;
__pyx_L0:;
__Pyx_DECREF((PyObject *)__pyx_v_oscale);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_scale);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":1403
+/* "mtrand.pyx":1425
* return cont1_array(self.internal_state, rk_exponential, size, oscale)
*
* def standard_exponential(self, size=None): # <<<<<<<<<<<<<<
@@ -7764,9 +7780,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_exponential(PyObject *__pyx_v_se
* standard_exponential(size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_standard_exponential(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_standard_exponential[] = "\n standard_exponential(size=None)\n\n Draw samples from the standard exponential distribution.\n\n `standard_exponential` is identical to the exponential distribution\n with a scale parameter of 1.\n\n Parameters\n ----------\n size : int or tuple of ints\n Shape of the output.\n\n Returns\n -------\n out : float or ndarray\n Drawn samples.\n\n Examples\n --------\n Output a 3x8000 array:\n\n >>> n = np.random.standard_exponential((3, 8000))\n\n ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_standard_exponential(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_20standard_exponential(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_20standard_exponential[] = "\n standard_exponential(size=None)\n\n Draw samples from the standard exponential distribution.\n\n `standard_exponential` is identical to the exponential distribution\n with a scale parameter of 1.\n\n Parameters\n ----------\n size : int or tuple of ints\n Shape of the output.\n\n Returns\n -------\n out : float or ndarray\n Drawn samples.\n\n Examples\n --------\n Output a 3x8000 array:\n\n >>> n = np.random.standard_exponential((3, 8000))\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_20standard_exponential(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_size = 0;
PyObject *__pyx_r = NULL;
PyObject *__pyx_t_1 = NULL;
@@ -7783,13 +7799,13 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_exponential(PyObject *_
}
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 0:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[0] = value; kw_args--; }
+ if (value) { values[0] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "standard_exponential") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1403; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "standard_exponential") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1425; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_size = values[0];
} else {
@@ -7802,13 +7818,14 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_exponential(PyObject *_
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("standard_exponential", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1403; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("standard_exponential", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1425; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.standard_exponential");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- /* "mtrand.pyx":1429
+ /* "mtrand.pyx":1451
*
* """
* return cont0_array(self.internal_state, rk_standard_exponential, size) # <<<<<<<<<<<<<<
@@ -7816,7 +7833,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_exponential(PyObject *_
* def standard_gamma(self, shape, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = __pyx_f_6mtrand_cont0_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_standard_exponential, __pyx_v_size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __pyx_f_6mtrand_cont0_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_standard_exponential, __pyx_v_size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
@@ -7834,7 +7851,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_exponential(PyObject *_
return __pyx_r;
}
-/* "mtrand.pyx":1431
+/* "mtrand.pyx":1453
* return cont0_array(self.internal_state, rk_standard_exponential, size)
*
* def standard_gamma(self, shape, size=None): # <<<<<<<<<<<<<<
@@ -7842,9 +7859,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_exponential(PyObject *_
* standard_gamma(shape, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_standard_gamma(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_standard_gamma[] = "\n"" standard_gamma(shape, size=None)\n""\n"" Draw samples from a Standard Gamma distribution.\n""\n"" Samples are drawn from a Gamma distribution with specified parameters,\n"" shape (sometimes designated \"k\") and scale=1.\n""\n"" Parameters\n"" ----------\n"" shape : float\n"" Parameter, should be > 0.\n"" size : int or tuple of ints\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 drawn samples.\n""\n"" See Also\n"" --------\n"" scipy.stats.distributions.gamma : probability density function,\n"" distribution or cumulative density function, etc.\n""\n"" Notes\n"" -----\n"" The probability density for the Gamma distribution is\n""\n"" .. math:: p(x) = x^{k-1}\\frac{e^{-x/\\theta}}{\\theta^k\\Gamma(k)},\n""\n"" where :math:`k` is the shape and :math:`\\theta` the scale,\n"" and :math:`\\Gamma` is the Gamma function.\n""\n"" The Gamma distribution is often used to model the times to failure of\n"" electronic components, and arises naturally in processes for which the\n"" waiting times between Poisson distributed events are relevant.\n""\n"" References\n"" ----------\n"" .. [1] Weisstein, Eric W. \"Gamma Distribution.\" From MathWorld--A\n"" Wolfram Web Resource.\n"" http://mathworld.wolfram.com/GammaDistribution.html\n"" .. [2] Wikipedia, \"Gamma-distribution\",\n"" http://en.wikipedia.org/wiki/Gamma-distribution\n""\n"" Examples\n"" --------\n"" Draw samples from the distribution:\n""\n"" >>> shape, scale = 2., 1. # mean and width\n"" >>> s = np.random.standard_gamma(shape, 1000000)\n""\n"" Display the histogram of the samples, along with\n"" the probability density function:\n""\n"" >>> import matplotlib.pyplot as plt\n"" >>> import scipy.special as sps\n"" >>> count, bins, ignored = plt.hist(s, 50, normed=True)\n"" >>> y = bins**(shape-1) * ((np.exp(-bins/scale))/ \\\n"" ... (sps.gamma(shape) * scale**shape))\n"" >>> plt.plot(bins, y, linewidth=2, color='r')\n"" >>> plt.show()\n""\n"" ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_standard_gamma(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_21standard_gamma(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_21standard_gamma[] = "\n standard_gamma(shape, size=None)\n\n Draw samples from a Standard Gamma distribution.\n\n Samples are drawn from a Gamma distribution with specified parameters,\n shape (sometimes designated \"k\") and scale=1.\n\n Parameters\n ----------\n shape : float\n Parameter, should be > 0.\n size : int or tuple of ints\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 drawn samples.\n\n See Also\n --------\n scipy.stats.distributions.gamma : probability density function,\n distribution or cumulative density function, etc.\n\n Notes\n -----\n The probability density for the Gamma distribution is\n\n .. math:: p(x) = x^{k-1}\\frac{e^{-x/\\theta}}{\\theta^k\\Gamma(k)},\n\n where :math:`k` is the shape and :math:`\\theta` the scale,\n and :math:`\\Gamma` is the Gamma function.\n\n The Gamma distribution is often used to model the times to failure of\n electronic components, and arises naturally in processes for which the\n waiting times between Poisson distributed events are relevant.\n\n References\n ----------\n .. [1] Weisstein, Eric W. \"Gamma Distribution.\" From MathWorld--A\n Wolfram Web Resource.\n http://mathworld.wolfram.com/GammaDistribution.html\n .. [2] Wikipedia, \"Gamma-distribution\",\n http://en.wikipedia.org/wiki/Gamma-distribution\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> shape, scale = 2., 1. # mean and width\n >>> s = np.random.standard_gamma(shape, 1000000)\n\n Display the histogram of the samples, along with\n the probability density function:\n\n >>> import matplotlib.pyplot as plt""\n >>> import scipy.special as sps\n >>> count, bins, ignored = plt.hist(s, 50, normed=True)\n >>> y = bins**(shape-1) * ((np.exp(-bins/scale))/ \\\n ... (sps.gamma(shape) * scale**shape))\n >>> plt.plot(bins, y, linewidth=2, color='r')\n >>> plt.show()\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_21standard_gamma(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_shape = 0;
PyObject *__pyx_v_size = 0;
PyArrayObject *__pyx_v_oshape;
@@ -7873,13 +7890,13 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_gamma(PyObject *__pyx_v
if (likely(values[0])) kw_args--;
else goto __pyx_L5_argtuple_error;
case 1:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[1] = value; kw_args--; }
+ if (value) { values[1] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "standard_gamma") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1431; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "standard_gamma") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1453; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_shape = values[0];
__pyx_v_size = values[1];
@@ -7894,17 +7911,15 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_gamma(PyObject *__pyx_v
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("standard_gamma", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1431; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("standard_gamma", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1453; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.standard_gamma");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_shape);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_oshape = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":1501
+ /* "mtrand.pyx":1523
* cdef double fshape
*
* fshape = PyFloat_AsDouble(shape) # <<<<<<<<<<<<<<
@@ -7913,7 +7928,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_gamma(PyObject *__pyx_v
*/
__pyx_v_fshape = PyFloat_AsDouble(__pyx_v_shape);
- /* "mtrand.pyx":1502
+ /* "mtrand.pyx":1524
*
* fshape = PyFloat_AsDouble(shape)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -7923,39 +7938,33 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_gamma(PyObject *__pyx_v
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":1503
+ /* "mtrand.pyx":1525
* fshape = PyFloat_AsDouble(shape)
* if not PyErr_Occurred():
* if fshape <= 0: # <<<<<<<<<<<<<<
* raise ValueError("shape <= 0")
* return cont1_array_sc(self.internal_state, rk_standard_gamma, size, fshape)
*/
- __pyx_t_1 = (__pyx_v_fshape <= 0);
+ __pyx_t_1 = (__pyx_v_fshape <= 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":1504
+ /* "mtrand.pyx":1526
* if not PyErr_Occurred():
* if fshape <= 0:
* raise ValueError("shape <= 0") # <<<<<<<<<<<<<<
* return cont1_array_sc(self.internal_state, rk_standard_gamma, size, fshape)
*
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_32), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_13));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_13));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_13));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":1505
+ /* "mtrand.pyx":1527
* if fshape <= 0:
* raise ValueError("shape <= 0")
* return cont1_array_sc(self.internal_state, rk_standard_gamma, size, fshape) # <<<<<<<<<<<<<<
@@ -7963,16 +7972,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_gamma(PyObject *__pyx_v
* PyErr_Clear()
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = __pyx_f_6mtrand_cont1_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_standard_gamma, __pyx_v_size, __pyx_v_fshape); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1505; __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_cont1_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_standard_gamma, __pyx_v_size, __pyx_v_fshape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1527; __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_L6;
}
__pyx_L6:;
- /* "mtrand.pyx":1507
+ /* "mtrand.pyx":1529
* return cont1_array_sc(self.internal_state, rk_standard_gamma, size, fshape)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -7981,87 +7990,81 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_gamma(PyObject *__pyx_v
*/
PyErr_Clear();
- /* "mtrand.pyx":1508
+ /* "mtrand.pyx":1530
*
* PyErr_Clear()
* oshape = <ndarray> PyArray_FROM_OTF(shape, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less_equal(oshape, 0.0)):
* raise ValueError("shape <= 0")
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_shape, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1508; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_shape, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_oshape));
- __pyx_v_oshape = ((PyArrayObject *)__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_oshape = ((PyArrayObject *)__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":1509
+ /* "mtrand.pyx":1531
* PyErr_Clear()
* oshape = <ndarray> PyArray_FROM_OTF(shape, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oshape, 0.0)): # <<<<<<<<<<<<<<
* raise ValueError("shape <= 0")
* return cont1_array(self.internal_state, rk_standard_gamma, size, oshape)
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(((PyObject *)__pyx_v_oshape));
PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_oshape));
__Pyx_GIVEREF(((PyObject *)__pyx_v_oshape));
- PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 1509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
+ PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __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_5)); __pyx_t_5 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":1510
+ /* "mtrand.pyx":1532
* oshape = <ndarray> PyArray_FROM_OTF(shape, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oshape, 0.0)):
* raise ValueError("shape <= 0") # <<<<<<<<<<<<<<
* return cont1_array(self.internal_state, rk_standard_gamma, size, oshape)
*
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_13));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_13));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_13));
- __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_Raise(__pyx_t_5, 0, 0);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_33), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":1511
+ /* "mtrand.pyx":1533
* if np.any(np.less_equal(oshape, 0.0)):
* raise ValueError("shape <= 0")
* return cont1_array(self.internal_state, rk_standard_gamma, size, oshape) # <<<<<<<<<<<<<<
@@ -8069,10 +8072,10 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_gamma(PyObject *__pyx_v
* def gamma(self, shape, scale=1.0, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_5 = __pyx_f_6mtrand_cont1_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_standard_gamma, __pyx_v_size, __pyx_v_oshape); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_r = __pyx_t_5;
- __pyx_t_5 = 0;
+ __pyx_t_2 = __pyx_f_6mtrand_cont1_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_standard_gamma, __pyx_v_size, __pyx_v_oshape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1533; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -8086,15 +8089,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_gamma(PyObject *__pyx_v
__pyx_r = NULL;
__pyx_L0:;
__Pyx_DECREF((PyObject *)__pyx_v_oshape);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_shape);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":1513
+/* "mtrand.pyx":1535
* return cont1_array(self.internal_state, rk_standard_gamma, size, oshape)
*
* def gamma(self, shape, scale=1.0, size=None): # <<<<<<<<<<<<<<
@@ -8102,9 +8102,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_gamma(PyObject *__pyx_v
* gamma(shape, scale=1.0, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_gamma(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_gamma[] = "\n"" gamma(shape, scale=1.0, size=None)\n""\n"" Draw samples from a Gamma distribution.\n""\n"" Samples are drawn from a Gamma distribution with specified parameters,\n"" `shape` (sometimes designated \"k\") and `scale` (sometimes designated\n"" \"theta\"), where both parameters are > 0.\n""\n"" Parameters\n"" ----------\n"" shape : scalar > 0\n"" The shape of the gamma distribution.\n"" scale : scalar > 0, optional\n"" The scale of the gamma distribution. Default is equal to 1.\n"" size : shape_tuple, optional\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"" out : ndarray, float\n"" Returns one sample unless `size` parameter is specified.\n""\n"" See Also\n"" --------\n"" scipy.stats.distributions.gamma : probability density function,\n"" distribution or cumulative density function, etc.\n""\n"" Notes\n"" -----\n"" The probability density for the Gamma distribution is\n""\n"" .. math:: p(x) = x^{k-1}\\frac{e^{-x/\\theta}}{\\theta^k\\Gamma(k)},\n""\n"" where :math:`k` is the shape and :math:`\\theta` the scale,\n"" and :math:`\\Gamma` is the Gamma function.\n""\n"" The Gamma distribution is often used to model the times to failure of\n"" electronic components, and arises naturally in processes for which the\n"" waiting times between Poisson distributed events are relevant.\n""\n"" References\n"" ----------\n"" .. [1] Weisstein, Eric W. \"Gamma Distribution.\" From MathWorld--A\n"" Wolfram Web Resource.\n"" http://mathworld.wolfram.com/GammaDistribution.html\n"" .. [2] Wikipedia, \"Gamma-distribution\",\n"" http://en.wikipedia.org/wiki/Gamma-distribution\n""\n"" Examples\n"" --------\n"" Draw samples from the distribution:\n""\n"" >>> shape, scale = 2., 2. # mean and dispersion\n"" >>> s = np.random.gamma(shape, scale, 1000)\n""\n"" Display the histogram of the samples, along with\n"" the probability density function:\n""\n"" >>> import matplotlib.pyplot as plt\n"" >>> import scipy.special as sps\n"" >>> count, bins, ignored = plt.hist(s, 50, normed=True)\n"" >>> y = bins**(shape-1)*(np.exp(-bins/scale) /\n"" ... (sps.gamma(shape)*scale**shape))\n"" >>> plt.plot(bins, y, linewidth=2, color='r')\n"" >>> plt.show()\n""\n"" ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_gamma(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_22gamma(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_22gamma[] = "\n gamma(shape, scale=1.0, size=None)\n\n Draw samples from a Gamma distribution.\n\n Samples are drawn from a Gamma distribution with specified parameters,\n `shape` (sometimes designated \"k\") and `scale` (sometimes designated\n \"theta\"), where both parameters are > 0.\n\n Parameters\n ----------\n shape : scalar > 0\n The shape of the gamma distribution.\n scale : scalar > 0, optional\n The scale of the gamma distribution. Default is equal to 1.\n size : shape_tuple, optional\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 out : ndarray, float\n Returns one sample unless `size` parameter is specified.\n\n See Also\n --------\n scipy.stats.distributions.gamma : probability density function,\n distribution or cumulative density function, etc.\n\n Notes\n -----\n The probability density for the Gamma distribution is\n\n .. math:: p(x) = x^{k-1}\\frac{e^{-x/\\theta}}{\\theta^k\\Gamma(k)},\n\n where :math:`k` is the shape and :math:`\\theta` the scale,\n and :math:`\\Gamma` is the Gamma function.\n\n The Gamma distribution is often used to model the times to failure of\n electronic components, and arises naturally in processes for which the\n waiting times between Poisson distributed events are relevant.\n\n References\n ----------\n .. [1] Weisstein, Eric W. \"Gamma Distribution.\" From MathWorld--A\n Wolfram Web Resource.\n http://mathworld.wolfram.com/GammaDistribution.html\n .. [2] Wikipedia, \"Gamma-distribution\",\n http://en.wikipedia.org/wiki/Gamma-distribution\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> shape, scale = 2.,"" 2. # mean and dispersion\n >>> s = np.random.gamma(shape, scale, 1000)\n\n Display the histogram of the samples, along with\n the probability density function:\n\n >>> import matplotlib.pyplot as plt\n >>> import scipy.special as sps\n >>> count, bins, ignored = plt.hist(s, 50, normed=True)\n >>> y = bins**(shape-1)*(np.exp(-bins/scale) /\n ... (sps.gamma(shape)*scale**shape))\n >>> plt.plot(bins, y, linewidth=2, color='r')\n >>> plt.show()\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_22gamma(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_shape = 0;
PyObject *__pyx_v_scale = 0;
PyObject *__pyx_v_size = 0;
@@ -8123,7 +8123,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_gamma(PyObject *__pyx_v_self, Py
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
PyObject* values[3] = {0,0,0};
- values[1] = __pyx_k_14;
+ values[1] = __pyx_k_34;
values[2] = ((PyObject *)Py_None);
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
@@ -8138,24 +8138,24 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_gamma(PyObject *__pyx_v_self, Py
if (likely(values[0])) kw_args--;
else goto __pyx_L5_argtuple_error;
case 1:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__scale);
- if (unlikely(value)) { values[1] = value; kw_args--; }
+ if (value) { values[1] = value; kw_args--; }
}
case 2:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[2] = value; kw_args--; }
+ if (value) { values[2] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "gamma") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1513; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "gamma") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1535; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_shape = values[0];
__pyx_v_scale = values[1];
__pyx_v_size = values[2];
} else {
- __pyx_v_scale = __pyx_k_14;
+ __pyx_v_scale = __pyx_k_34;
__pyx_v_size = ((PyObject *)Py_None);
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 3: __pyx_v_size = PyTuple_GET_ITEM(__pyx_args, 2);
@@ -8167,19 +8167,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_gamma(PyObject *__pyx_v_self, Py
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("gamma", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1513; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("gamma", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1535; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.gamma");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_shape);
- __Pyx_INCREF(__pyx_v_scale);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_oshape = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_oscale = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":1586
+ /* "mtrand.pyx":1608
* cdef double fshape, fscale
*
* fshape = PyFloat_AsDouble(shape) # <<<<<<<<<<<<<<
@@ -8188,7 +8185,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_gamma(PyObject *__pyx_v_self, Py
*/
__pyx_v_fshape = PyFloat_AsDouble(__pyx_v_shape);
- /* "mtrand.pyx":1587
+ /* "mtrand.pyx":1609
*
* fshape = PyFloat_AsDouble(shape)
* fscale = PyFloat_AsDouble(scale) # <<<<<<<<<<<<<<
@@ -8197,7 +8194,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_gamma(PyObject *__pyx_v_self, Py
*/
__pyx_v_fscale = PyFloat_AsDouble(__pyx_v_scale);
- /* "mtrand.pyx":1588
+ /* "mtrand.pyx":1610
* fshape = PyFloat_AsDouble(shape)
* fscale = PyFloat_AsDouble(scale)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -8207,71 +8204,59 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_gamma(PyObject *__pyx_v_self, Py
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":1589
+ /* "mtrand.pyx":1611
* fscale = PyFloat_AsDouble(scale)
* if not PyErr_Occurred():
* if fshape <= 0: # <<<<<<<<<<<<<<
* raise ValueError("shape <= 0")
* if fscale <= 0:
*/
- __pyx_t_1 = (__pyx_v_fshape <= 0);
+ __pyx_t_1 = (__pyx_v_fshape <= 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":1590
+ /* "mtrand.pyx":1612
* if not PyErr_Occurred():
* if fshape <= 0:
* raise ValueError("shape <= 0") # <<<<<<<<<<<<<<
* if fscale <= 0:
* raise ValueError("scale <= 0")
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1590; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_35), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1612; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_13));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_13));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_13));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1590; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1590; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1612; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":1591
+ /* "mtrand.pyx":1613
* if fshape <= 0:
* raise ValueError("shape <= 0")
* if fscale <= 0: # <<<<<<<<<<<<<<
* raise ValueError("scale <= 0")
* return cont2_array_sc(self.internal_state, rk_gamma, size, fshape, fscale)
*/
- __pyx_t_1 = (__pyx_v_fscale <= 0);
+ __pyx_t_1 = (__pyx_v_fscale <= 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":1592
+ /* "mtrand.pyx":1614
* raise ValueError("shape <= 0")
* if fscale <= 0:
* raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
* return cont2_array_sc(self.internal_state, rk_gamma, size, fshape, fscale)
*
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_9));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_9));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_9));
- __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_36), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1614; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1614; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":1593
+ /* "mtrand.pyx":1615
* if fscale <= 0:
* raise ValueError("scale <= 0")
* return cont2_array_sc(self.internal_state, rk_gamma, size, fshape, fscale) # <<<<<<<<<<<<<<
@@ -8279,7 +8264,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_gamma(PyObject *__pyx_v_self, Py
* PyErr_Clear()
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_2 = __pyx_f_6mtrand_cont2_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_gamma, __pyx_v_size, __pyx_v_fshape, __pyx_v_fscale); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __pyx_f_6mtrand_cont2_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_gamma, __pyx_v_size, __pyx_v_fshape, __pyx_v_fscale); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__pyx_r = __pyx_t_2;
__pyx_t_2 = 0;
@@ -8288,7 +8273,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_gamma(PyObject *__pyx_v_self, Py
}
__pyx_L6:;
- /* "mtrand.pyx":1595
+ /* "mtrand.pyx":1617
* return cont2_array_sc(self.internal_state, rk_gamma, size, fshape, fscale)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -8297,167 +8282,155 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_gamma(PyObject *__pyx_v_self, Py
*/
PyErr_Clear();
- /* "mtrand.pyx":1596
+ /* "mtrand.pyx":1618
*
* PyErr_Clear()
* oshape = <ndarray>PyArray_FROM_OTF(shape, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* oscale = <ndarray>PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oshape, 0.0)):
*/
- __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_shape, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_shape, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1618; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_oshape));
__pyx_v_oshape = ((PyArrayObject *)__pyx_t_2);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":1597
+ /* "mtrand.pyx":1619
* PyErr_Clear()
* oshape = <ndarray>PyArray_FROM_OTF(shape, NPY_DOUBLE, NPY_ALIGNED)
* oscale = <ndarray>PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less_equal(oshape, 0.0)):
* raise ValueError("shape <= 0")
*/
- __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_scale, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_scale, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1619; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_oscale));
__pyx_v_oscale = ((PyArrayObject *)__pyx_t_2);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":1598
+ /* "mtrand.pyx":1620
* oshape = <ndarray>PyArray_FROM_OTF(shape, NPY_DOUBLE, NPY_ALIGNED)
* oscale = <ndarray>PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oshape, 0.0)): # <<<<<<<<<<<<<<
* raise ValueError("shape <= 0")
* if np.any(np.less_equal(oscale, 0.0)):
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1620; __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_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(((PyObject *)__pyx_v_oshape));
PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_oshape));
__Pyx_GIVEREF(((PyObject *)__pyx_v_oshape));
PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
__Pyx_GIVEREF(__pyx_t_2);
__pyx_t_2 = 0;
- __pyx_t_2 = PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __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 = 1620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
__Pyx_GIVEREF(__pyx_t_2);
__pyx_t_2 = 0;
- __pyx_t_2 = PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":1599
+ /* "mtrand.pyx":1621
* oscale = <ndarray>PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oshape, 0.0)):
* raise ValueError("shape <= 0") # <<<<<<<<<<<<<<
* if np.any(np.less_equal(oscale, 0.0)):
* raise ValueError("scale <= 0")
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_37), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_13));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_13));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_13));
- __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_5, 0, 0);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L9;
}
__pyx_L9:;
- /* "mtrand.pyx":1600
+ /* "mtrand.pyx":1622
* if np.any(np.less_equal(oshape, 0.0)):
* raise ValueError("shape <= 0")
* if np.any(np.less_equal(oscale, 0.0)): # <<<<<<<<<<<<<<
* raise ValueError("scale <= 0")
* return cont2_array(self.internal_state, rk_gamma, size, oshape, oscale)
*/
- __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1622; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1622; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1622; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1622; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_5 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1622; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1622; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
__Pyx_INCREF(((PyObject *)__pyx_v_oscale));
PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_oscale));
__Pyx_GIVEREF(((PyObject *)__pyx_v_oscale));
- PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5);
- __Pyx_GIVEREF(__pyx_t_5);
- __pyx_t_5 = 0;
- __pyx_t_5 = PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
+ __Pyx_GIVEREF(__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 = 1622; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_DECREF(__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 = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
- __Pyx_GIVEREF(__pyx_t_5);
- __pyx_t_5 = 0;
- __pyx_t_5 = PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 1622; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
+ 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 = 1622; __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_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1622; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":1601
+ /* "mtrand.pyx":1623
* raise ValueError("shape <= 0")
* if np.any(np.less_equal(oscale, 0.0)):
* raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
* return cont2_array(self.internal_state, rk_gamma, size, oshape, oscale)
*
*/
- __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_9));
- PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_9));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_9));
- __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_Raise(__pyx_t_4, 0, 0);
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_38), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1623; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1623; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L10;
}
__pyx_L10:;
- /* "mtrand.pyx":1602
+ /* "mtrand.pyx":1624
* if np.any(np.less_equal(oscale, 0.0)):
* raise ValueError("scale <= 0")
* return cont2_array(self.internal_state, rk_gamma, size, oshape, oscale) # <<<<<<<<<<<<<<
@@ -8465,10 +8438,10 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_gamma(PyObject *__pyx_v_self, Py
* def f(self, dfnum, dfden, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_4 = __pyx_f_6mtrand_cont2_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_gamma, __pyx_v_size, __pyx_v_oshape, __pyx_v_oscale); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- __pyx_r = __pyx_t_4;
- __pyx_t_4 = 0;
+ __pyx_t_2 = __pyx_f_6mtrand_cont2_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_gamma, __pyx_v_size, __pyx_v_oshape, __pyx_v_oscale); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1624; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -8483,16 +8456,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_gamma(PyObject *__pyx_v_self, Py
__pyx_L0:;
__Pyx_DECREF((PyObject *)__pyx_v_oshape);
__Pyx_DECREF((PyObject *)__pyx_v_oscale);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_shape);
- __Pyx_DECREF(__pyx_v_scale);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":1604
+/* "mtrand.pyx":1626
* return cont2_array(self.internal_state, rk_gamma, size, oshape, oscale)
*
* def f(self, dfnum, dfden, size=None): # <<<<<<<<<<<<<<
@@ -8500,9 +8469,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_gamma(PyObject *__pyx_v_self, Py
* f(dfnum, dfden, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_f(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_f[] = "\n"" f(dfnum, dfden, size=None)\n""\n"" Draw samples from a F distribution.\n""\n"" Samples are drawn from an F distribution with specified parameters,\n"" `dfnum` (degrees of freedom in numerator) and `dfden` (degrees of freedom\n"" in denominator), where both parameters should be greater than zero.\n""\n"" The random variate of the F distribution (also known as the\n"" Fisher distribution) is a continuous probability distribution\n"" that arises in ANOVA tests, and is the ratio of two chi-square\n"" variates.\n""\n"" Parameters\n"" ----------\n"" dfnum : float\n"" Degrees of freedom in numerator. Should be greater than zero.\n"" dfden : float\n"" Degrees of freedom in denominator. Should be greater than zero.\n"" size : {tuple, int}, optional\n"" Output shape. If the given shape is, e.g., ``(m, n, k)``,\n"" then ``m * n * k`` samples are drawn. By default only one sample\n"" is returned.\n""\n"" Returns\n"" -------\n"" samples : {ndarray, scalar}\n"" Samples from the Fisher distribution.\n""\n"" See Also\n"" --------\n"" scipy.stats.distributions.f : probability density function,\n"" distribution or cumulative density function, etc.\n""\n"" Notes\n"" -----\n""\n"" The F statistic is used to compare in-group variances to between-group\n"" variances. Calculating the distribution depends on the sampling, and\n"" so it is a function of the respective degrees of freedom in the\n"" problem. The variable `dfnum` is the number of samples minus one, the\n"" between-groups degrees of freedom, while `dfden` is the within-groups\n"" degrees of freedom, the sum of the number of samples in each group\n"" minus the number of groups.\n""\n"" References\n"" ----------\n"" .. [1] Glantz, Stanton A. \"Primer of Biostatistics.\", McGraw-Hill,\n"" Fifth Edition, 2002.\n"" .. [2] Wikipedia, \"F-distribution\",\n"" http://en.wikipedia.org/wiki/F-distribution\n""\n"" Examples\n"" --------\n"" An example from Glantz[1], pp 47-40.\n"" Two groups, children of diabetics (25 people) and children from people\n"" without diabetes (25 controls). Fasting blood glucose was measured,\n"" case group had a mean value of 86.1, controls had a mean value of\n"" 82.2. Standard deviations were 2.09 and 2.49 respectively. Are these\n"" data consistent with the null hypothesis that the parents diabetic\n"" status does not affect their children's blood glucose levels?\n"" Calculating the F statistic from the data gives a value of 36.01.\n""\n"" Draw samples from the distribution:\n""\n"" >>> dfnum = 1. # between group degrees of freedom\n"" >>> dfden = 48. # within groups degrees of freedom\n"" >>> s = np.random.f(dfnum, dfden, 1000)\n""\n"" The lower bound for the top 1% of the samples is :\n""\n"" >>> sort(s)[-10]\n"" 7.61988120985\n""\n"" So there is about a 1% chance that the F statistic will exceed 7.62,\n"" the measured value is 36, so the null hypothesis is rejected at the 1%\n"" level.\n""\n"" ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_f(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_23f(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_23f[] = "\n f(dfnum, dfden, size=None)\n\n Draw samples from a F distribution.\n\n Samples are drawn from an F distribution with specified parameters,\n `dfnum` (degrees of freedom in numerator) and `dfden` (degrees of freedom\n in denominator), where both parameters should be greater than zero.\n\n The random variate of the F distribution (also known as the\n Fisher distribution) is a continuous probability distribution\n that arises in ANOVA tests, and is the ratio of two chi-square\n variates.\n\n Parameters\n ----------\n dfnum : float\n Degrees of freedom in numerator. Should be greater than zero.\n dfden : float\n Degrees of freedom in denominator. Should be greater than zero.\n size : {tuple, int}, optional\n Output shape. If the given shape is, e.g., ``(m, n, k)``,\n then ``m * n * k`` samples are drawn. By default only one sample\n is returned.\n\n Returns\n -------\n samples : {ndarray, scalar}\n Samples from the Fisher distribution.\n\n See Also\n --------\n scipy.stats.distributions.f : probability density function,\n distribution or cumulative density function, etc.\n\n Notes\n -----\n\n The F statistic is used to compare in-group variances to between-group\n variances. Calculating the distribution depends on the sampling, and\n so it is a function of the respective degrees of freedom in the\n problem. The variable `dfnum` is the number of samples minus one, the\n between-groups degrees of freedom, while `dfden` is the within-groups\n degrees of freedom, the sum of the number of samples in each group\n minus the number of groups.\n\n References\n ----------\n .. [1] Glantz, Stanton A. \"Primer of Biostatistics.\", McGraw-Hill,\n Fifth Edition, 2002.""\n .. [2] Wikipedia, \"F-distribution\",\n http://en.wikipedia.org/wiki/F-distribution\n\n Examples\n --------\n An example from Glantz[1], pp 47-40.\n Two groups, children of diabetics (25 people) and children from people\n without diabetes (25 controls). Fasting blood glucose was measured,\n case group had a mean value of 86.1, controls had a mean value of\n 82.2. Standard deviations were 2.09 and 2.49 respectively. Are these\n data consistent with the null hypothesis that the parents diabetic\n status does not affect their children's blood glucose levels?\n Calculating the F statistic from the data gives a value of 36.01.\n\n Draw samples from the distribution:\n\n >>> dfnum = 1. # between group degrees of freedom\n >>> dfden = 48. # within groups degrees of freedom\n >>> s = np.random.f(dfnum, dfden, 1000)\n\n The lower bound for the top 1% of the samples is :\n\n >>> sort(s)[-10]\n 7.61988120985\n\n So there is about a 1% chance that the F statistic will exceed 7.62,\n the measured value is 36, so the null hypothesis is rejected at the 1%\n level.\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_23f(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_dfnum = 0;
PyObject *__pyx_v_dfden = 0;
PyObject *__pyx_v_size = 0;
@@ -8538,16 +8507,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_f(PyObject *__pyx_v_self, PyObje
values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dfden);
if (likely(values[1])) kw_args--;
else {
- __Pyx_RaiseArgtupleInvalid("f", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("f", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1626; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
case 2:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[2] = value; kw_args--; }
+ if (value) { values[2] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "f") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "f") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1626; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_dfnum = values[0];
__pyx_v_dfden = values[1];
@@ -8566,19 +8535,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_f(PyObject *__pyx_v_self, PyObje
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("f", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("f", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1626; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.f");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_dfnum);
- __Pyx_INCREF(__pyx_v_dfden);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_odfnum = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_odfden = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":1688
+ /* "mtrand.pyx":1710
* cdef double fdfnum, fdfden
*
* fdfnum = PyFloat_AsDouble(dfnum) # <<<<<<<<<<<<<<
@@ -8587,7 +8553,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_f(PyObject *__pyx_v_self, PyObje
*/
__pyx_v_fdfnum = PyFloat_AsDouble(__pyx_v_dfnum);
- /* "mtrand.pyx":1689
+ /* "mtrand.pyx":1711
*
* fdfnum = PyFloat_AsDouble(dfnum)
* fdfden = PyFloat_AsDouble(dfden) # <<<<<<<<<<<<<<
@@ -8596,7 +8562,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_f(PyObject *__pyx_v_self, PyObje
*/
__pyx_v_fdfden = PyFloat_AsDouble(__pyx_v_dfden);
- /* "mtrand.pyx":1690
+ /* "mtrand.pyx":1712
* fdfnum = PyFloat_AsDouble(dfnum)
* fdfden = PyFloat_AsDouble(dfden)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -8606,71 +8572,59 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_f(PyObject *__pyx_v_self, PyObje
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":1691
+ /* "mtrand.pyx":1713
* fdfden = PyFloat_AsDouble(dfden)
* if not PyErr_Occurred():
* if fdfnum <= 0: # <<<<<<<<<<<<<<
* raise ValueError("shape <= 0")
* if fdfden <= 0:
*/
- __pyx_t_1 = (__pyx_v_fdfnum <= 0);
+ __pyx_t_1 = (__pyx_v_fdfnum <= 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":1692
+ /* "mtrand.pyx":1714
* if not PyErr_Occurred():
* if fdfnum <= 0:
* raise ValueError("shape <= 0") # <<<<<<<<<<<<<<
* if fdfden <= 0:
* raise ValueError("scale <= 0")
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_39), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_13));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_13));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_13));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":1693
+ /* "mtrand.pyx":1715
* if fdfnum <= 0:
* raise ValueError("shape <= 0")
* if fdfden <= 0: # <<<<<<<<<<<<<<
* raise ValueError("scale <= 0")
* return cont2_array_sc(self.internal_state, rk_f, size, fdfnum, fdfden)
*/
- __pyx_t_1 = (__pyx_v_fdfden <= 0);
+ __pyx_t_1 = (__pyx_v_fdfden <= 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":1694
+ /* "mtrand.pyx":1716
* raise ValueError("shape <= 0")
* if fdfden <= 0:
* raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
* return cont2_array_sc(self.internal_state, rk_f, size, fdfnum, fdfden)
*
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_9));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_9));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_9));
- __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_40), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":1695
+ /* "mtrand.pyx":1717
* if fdfden <= 0:
* raise ValueError("scale <= 0")
* return cont2_array_sc(self.internal_state, rk_f, size, fdfnum, fdfden) # <<<<<<<<<<<<<<
@@ -8678,7 +8632,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_f(PyObject *__pyx_v_self, PyObje
* PyErr_Clear()
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_2 = __pyx_f_6mtrand_cont2_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_f, __pyx_v_size, __pyx_v_fdfnum, __pyx_v_fdfden); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1695; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __pyx_f_6mtrand_cont2_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_f, __pyx_v_size, __pyx_v_fdfnum, __pyx_v_fdfden); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__pyx_r = __pyx_t_2;
__pyx_t_2 = 0;
@@ -8687,7 +8641,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_f(PyObject *__pyx_v_self, PyObje
}
__pyx_L6:;
- /* "mtrand.pyx":1697
+ /* "mtrand.pyx":1719
* return cont2_array_sc(self.internal_state, rk_f, size, fdfnum, fdfden)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -8696,167 +8650,155 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_f(PyObject *__pyx_v_self, PyObje
*/
PyErr_Clear();
- /* "mtrand.pyx":1699
+ /* "mtrand.pyx":1721
* PyErr_Clear()
*
* odfnum = <ndarray>PyArray_FROM_OTF(dfnum, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* odfden = <ndarray>PyArray_FROM_OTF(dfden, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(odfnum, 0.0)):
*/
- __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_dfnum, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_dfnum, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_odfnum));
__pyx_v_odfnum = ((PyArrayObject *)__pyx_t_2);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":1700
+ /* "mtrand.pyx":1722
*
* odfnum = <ndarray>PyArray_FROM_OTF(dfnum, NPY_DOUBLE, NPY_ALIGNED)
* odfden = <ndarray>PyArray_FROM_OTF(dfden, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less_equal(odfnum, 0.0)):
* raise ValueError("dfnum <= 0")
*/
- __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_dfden, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_dfden, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1722; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_odfden));
__pyx_v_odfden = ((PyArrayObject *)__pyx_t_2);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":1701
+ /* "mtrand.pyx":1723
* odfnum = <ndarray>PyArray_FROM_OTF(dfnum, NPY_DOUBLE, NPY_ALIGNED)
* odfden = <ndarray>PyArray_FROM_OTF(dfden, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(odfnum, 0.0)): # <<<<<<<<<<<<<<
* raise ValueError("dfnum <= 0")
* if np.any(np.less_equal(odfden, 0.0)):
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1723; __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_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(((PyObject *)__pyx_v_odfnum));
PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_odfnum));
__Pyx_GIVEREF(((PyObject *)__pyx_v_odfnum));
PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
__Pyx_GIVEREF(__pyx_t_2);
__pyx_t_2 = 0;
- __pyx_t_2 = PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 1701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __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 = 1723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
__Pyx_GIVEREF(__pyx_t_2);
__pyx_t_2 = 0;
- __pyx_t_2 = PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":1702
+ /* "mtrand.pyx":1724
* odfden = <ndarray>PyArray_FROM_OTF(dfden, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(odfnum, 0.0)):
* raise ValueError("dfnum <= 0") # <<<<<<<<<<<<<<
* if np.any(np.less_equal(odfden, 0.0)):
* raise ValueError("dfden <= 0")
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_42), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_15));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_15));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_15));
- __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_5, 0, 0);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L9;
}
__pyx_L9:;
- /* "mtrand.pyx":1703
+ /* "mtrand.pyx":1725
* if np.any(np.less_equal(odfnum, 0.0)):
* raise ValueError("dfnum <= 0")
* if np.any(np.less_equal(odfden, 0.0)): # <<<<<<<<<<<<<<
* raise ValueError("dfden <= 0")
* return cont2_array(self.internal_state, rk_f, size, odfnum, odfden)
*/
- __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_5 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
__Pyx_INCREF(((PyObject *)__pyx_v_odfden));
PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_odfden));
__Pyx_GIVEREF(((PyObject *)__pyx_v_odfden));
- PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5);
- __Pyx_GIVEREF(__pyx_t_5);
- __pyx_t_5 = 0;
- __pyx_t_5 = PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
+ __Pyx_GIVEREF(__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 = 1725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_DECREF(__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 = 1703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
- __Pyx_GIVEREF(__pyx_t_5);
- __pyx_t_5 = 0;
- __pyx_t_5 = PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 1725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
+ 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 = 1725; __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_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":1704
+ /* "mtrand.pyx":1726
* raise ValueError("dfnum <= 0")
* if np.any(np.less_equal(odfden, 0.0)):
* raise ValueError("dfden <= 0") # <<<<<<<<<<<<<<
* return cont2_array(self.internal_state, rk_f, size, odfnum, odfden)
*
*/
- __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_16));
- PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_16));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_16));
- __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_Raise(__pyx_t_4, 0, 0);
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_44), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1726; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1726; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L10;
}
__pyx_L10:;
- /* "mtrand.pyx":1705
+ /* "mtrand.pyx":1727
* if np.any(np.less_equal(odfden, 0.0)):
* raise ValueError("dfden <= 0")
* return cont2_array(self.internal_state, rk_f, size, odfnum, odfden) # <<<<<<<<<<<<<<
@@ -8864,10 +8806,10 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_f(PyObject *__pyx_v_self, PyObje
* def noncentral_f(self, dfnum, dfden, nonc, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_4 = __pyx_f_6mtrand_cont2_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_f, __pyx_v_size, __pyx_v_odfnum, __pyx_v_odfden); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- __pyx_r = __pyx_t_4;
- __pyx_t_4 = 0;
+ __pyx_t_2 = __pyx_f_6mtrand_cont2_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_f, __pyx_v_size, __pyx_v_odfnum, __pyx_v_odfden); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -8882,16 +8824,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_f(PyObject *__pyx_v_self, PyObje
__pyx_L0:;
__Pyx_DECREF((PyObject *)__pyx_v_odfnum);
__Pyx_DECREF((PyObject *)__pyx_v_odfden);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_dfnum);
- __Pyx_DECREF(__pyx_v_dfden);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":1707
+/* "mtrand.pyx":1729
* return cont2_array(self.internal_state, rk_f, size, odfnum, odfden)
*
* def noncentral_f(self, dfnum, dfden, nonc, size=None): # <<<<<<<<<<<<<<
@@ -8899,9 +8837,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_f(PyObject *__pyx_v_self, PyObje
* noncentral_f(dfnum, dfden, nonc, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_f(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_noncentral_f[] = "\n"" noncentral_f(dfnum, dfden, nonc, size=None)\n""\n"" Draw samples from the noncentral F distribution.\n""\n"" Samples are drawn from an F distribution with specified parameters,\n"" `dfnum` (degrees of freedom in numerator) and `dfden` (degrees of\n"" freedom in denominator), where both parameters > 1.\n"" `nonc` is the non-centrality parameter.\n""\n"" Parameters\n"" ----------\n"" dfnum : int\n"" Parameter, should be > 1.\n"" dfden : int\n"" Parameter, should be > 1.\n"" nonc : float\n"" Parameter, should be >= 0.\n"" size : int or tuple of ints\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 : scalar or ndarray\n"" Drawn samples.\n""\n"" Notes\n"" -----\n"" When calculating the power of an experiment (power = probability of\n"" rejecting the null hypothesis when a specific alternative is true) the\n"" non-central F statistic becomes important. When the null hypothesis is\n"" true, the F statistic follows a central F distribution. When the null\n"" hypothesis is not true, then it follows a non-central F statistic.\n""\n"" References\n"" ----------\n"" Weisstein, Eric W. \"Noncentral F-Distribution.\" From MathWorld--A Wolfram\n"" Web Resource. http://mathworld.wolfram.com/NoncentralF-Distribution.html\n""\n"" Wikipedia, \"Noncentral F distribution\",\n"" http://en.wikipedia.org/wiki/Noncentral_F-distribution\n""\n"" Examples\n"" --------\n"" In a study, testing for a specific alternative to the null hypothesis\n"" requires use of the Noncentral F distribution. We need to calculate the\n"" area in the tail of the distribution that exceeds the value of the F\n"" distribution for the null hypothesis. We'll plot the two probability\n"" distributions for comparison.\n""\n"" >>> dfnum = 3 # between group deg of freedom\n"" >>> dfden = 20 # within groups degrees of freedom\n"" >>> nonc = 3.0\n"" >>> nc_vals = np.random.noncentral_f(dfnum, dfden, nonc, 1000000)\n"" >>> NF = np.histogram(nc_vals, bins=50, normed=True)\n"" >>> c_vals = np.random.f(dfnum, dfden, 1000000)\n"" >>> F = np.histogram(c_vals, bins=50, normed=True)\n"" >>> plt.plot(F[1][1:], F[0])\n"" >>> plt.plot(NF[1][1:], NF[0])\n"" >>> plt.show()\n""\n"" ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_f(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_24noncentral_f(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_24noncentral_f[] = "\n noncentral_f(dfnum, dfden, nonc, size=None)\n\n Draw samples from the noncentral F distribution.\n\n Samples are drawn from an F distribution with specified parameters,\n `dfnum` (degrees of freedom in numerator) and `dfden` (degrees of\n freedom in denominator), where both parameters > 1.\n `nonc` is the non-centrality parameter.\n\n Parameters\n ----------\n dfnum : int\n Parameter, should be > 1.\n dfden : int\n Parameter, should be > 1.\n nonc : float\n Parameter, should be >= 0.\n size : int or tuple of ints\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 : scalar or ndarray\n Drawn samples.\n\n Notes\n -----\n When calculating the power of an experiment (power = probability of\n rejecting the null hypothesis when a specific alternative is true) the\n non-central F statistic becomes important. When the null hypothesis is\n true, the F statistic follows a central F distribution. When the null\n hypothesis is not true, then it follows a non-central F statistic.\n\n References\n ----------\n Weisstein, Eric W. \"Noncentral F-Distribution.\" From MathWorld--A Wolfram\n Web Resource. http://mathworld.wolfram.com/NoncentralF-Distribution.html\n\n Wikipedia, \"Noncentral F distribution\",\n http://en.wikipedia.org/wiki/Noncentral_F-distribution\n\n Examples\n --------\n In a study, testing for a specific alternative to the null hypothesis\n requires use of the Noncentral F distribution. We need to calculate the\n area in the tail of the distribution that exceeds the value of the F\n distribution for the null hypothesis. We'll plot the two probability\n distributions for comp""arison.\n\n >>> dfnum = 3 # between group deg of freedom\n >>> dfden = 20 # within groups degrees of freedom\n >>> nonc = 3.0\n >>> nc_vals = np.random.noncentral_f(dfnum, dfden, nonc, 1000000)\n >>> NF = np.histogram(nc_vals, bins=50, normed=True)\n >>> c_vals = np.random.f(dfnum, dfden, 1000000)\n >>> F = np.histogram(c_vals, bins=50, normed=True)\n >>> plt.plot(F[1][1:], F[0])\n >>> plt.plot(NF[1][1:], NF[0])\n >>> plt.show()\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_24noncentral_f(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_dfnum = 0;
PyObject *__pyx_v_dfden = 0;
PyObject *__pyx_v_nonc = 0;
@@ -8941,22 +8879,22 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_f(PyObject *__pyx_v_s
values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dfden);
if (likely(values[1])) kw_args--;
else {
- __Pyx_RaiseArgtupleInvalid("noncentral_f", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1707; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("noncentral_f", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1729; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
case 2:
values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__nonc);
if (likely(values[2])) kw_args--;
else {
- __Pyx_RaiseArgtupleInvalid("noncentral_f", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1707; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("noncentral_f", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1729; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
case 3:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[3] = value; kw_args--; }
+ if (value) { values[3] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "noncentral_f") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1707; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "noncentral_f") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1729; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_dfnum = values[0];
__pyx_v_dfden = values[1];
@@ -8977,21 +8915,17 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_f(PyObject *__pyx_v_s
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("noncentral_f", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1707; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("noncentral_f", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1729; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.noncentral_f");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_dfnum);
- __Pyx_INCREF(__pyx_v_dfden);
- __Pyx_INCREF(__pyx_v_nonc);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_odfnum = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_odfden = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_ononc = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":1774
+ /* "mtrand.pyx":1796
* cdef double fdfnum, fdfden, fnonc
*
* fdfnum = PyFloat_AsDouble(dfnum) # <<<<<<<<<<<<<<
@@ -9000,7 +8934,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_f(PyObject *__pyx_v_s
*/
__pyx_v_fdfnum = PyFloat_AsDouble(__pyx_v_dfnum);
- /* "mtrand.pyx":1775
+ /* "mtrand.pyx":1797
*
* fdfnum = PyFloat_AsDouble(dfnum)
* fdfden = PyFloat_AsDouble(dfden) # <<<<<<<<<<<<<<
@@ -9009,7 +8943,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_f(PyObject *__pyx_v_s
*/
__pyx_v_fdfden = PyFloat_AsDouble(__pyx_v_dfden);
- /* "mtrand.pyx":1776
+ /* "mtrand.pyx":1798
* fdfnum = PyFloat_AsDouble(dfnum)
* fdfden = PyFloat_AsDouble(dfden)
* fnonc = PyFloat_AsDouble(nonc) # <<<<<<<<<<<<<<
@@ -9018,7 +8952,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_f(PyObject *__pyx_v_s
*/
__pyx_v_fnonc = PyFloat_AsDouble(__pyx_v_nonc);
- /* "mtrand.pyx":1777
+ /* "mtrand.pyx":1799
* fdfden = PyFloat_AsDouble(dfden)
* fnonc = PyFloat_AsDouble(nonc)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -9028,103 +8962,85 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_f(PyObject *__pyx_v_s
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":1778
+ /* "mtrand.pyx":1800
* fnonc = PyFloat_AsDouble(nonc)
* if not PyErr_Occurred():
* if fdfnum <= 1: # <<<<<<<<<<<<<<
* raise ValueError("dfnum <= 1")
* if fdfden <= 0:
*/
- __pyx_t_1 = (__pyx_v_fdfnum <= 1);
+ __pyx_t_1 = (__pyx_v_fdfnum <= 1.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":1779
+ /* "mtrand.pyx":1801
* if not PyErr_Occurred():
* if fdfnum <= 1:
* raise ValueError("dfnum <= 1") # <<<<<<<<<<<<<<
* if fdfden <= 0:
* raise ValueError("dfden <= 0")
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_46), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_17));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_17));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_17));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":1780
+ /* "mtrand.pyx":1802
* if fdfnum <= 1:
* raise ValueError("dfnum <= 1")
* if fdfden <= 0: # <<<<<<<<<<<<<<
* raise ValueError("dfden <= 0")
* if fnonc < 0:
*/
- __pyx_t_1 = (__pyx_v_fdfden <= 0);
+ __pyx_t_1 = (__pyx_v_fdfden <= 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":1781
+ /* "mtrand.pyx":1803
* raise ValueError("dfnum <= 1")
* if fdfden <= 0:
* raise ValueError("dfden <= 0") # <<<<<<<<<<<<<<
* if fnonc < 0:
* raise ValueError("nonc < 0")
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_16));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_16));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_16));
- __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_47), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":1782
+ /* "mtrand.pyx":1804
* if fdfden <= 0:
* raise ValueError("dfden <= 0")
* if fnonc < 0: # <<<<<<<<<<<<<<
* raise ValueError("nonc < 0")
* return cont3_array_sc(self.internal_state, rk_noncentral_f, size,
*/
- __pyx_t_1 = (__pyx_v_fnonc < 0);
+ __pyx_t_1 = (__pyx_v_fnonc < 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":1783
+ /* "mtrand.pyx":1805
* raise ValueError("dfden <= 0")
* if fnonc < 0:
* raise ValueError("nonc < 0") # <<<<<<<<<<<<<<
* return cont3_array_sc(self.internal_state, rk_noncentral_f, size,
* fdfnum, fdfden, fnonc)
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_49), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1805; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_18));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_18));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_18));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1805; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L9;
}
__pyx_L9:;
- /* "mtrand.pyx":1784
+ /* "mtrand.pyx":1806
* if fnonc < 0:
* raise ValueError("nonc < 0")
* return cont3_array_sc(self.internal_state, rk_noncentral_f, size, # <<<<<<<<<<<<<<
@@ -9133,23 +9049,23 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_f(PyObject *__pyx_v_s
*/
__Pyx_XDECREF(__pyx_r);
- /* "mtrand.pyx":1785
+ /* "mtrand.pyx":1807
* raise ValueError("nonc < 0")
* return cont3_array_sc(self.internal_state, rk_noncentral_f, size,
* fdfnum, fdfden, fnonc) # <<<<<<<<<<<<<<
*
* PyErr_Clear()
*/
- __pyx_t_3 = __pyx_f_6mtrand_cont3_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_noncentral_f, __pyx_v_size, __pyx_v_fdfnum, __pyx_v_fdfden, __pyx_v_fnonc); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1784; __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_cont3_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_noncentral_f, __pyx_v_size, __pyx_v_fdfnum, __pyx_v_fdfden, __pyx_v_fnonc); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1806; __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_L6;
}
__pyx_L6:;
- /* "mtrand.pyx":1787
+ /* "mtrand.pyx":1809
* fdfnum, fdfden, fnonc)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -9158,247 +9074,229 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_f(PyObject *__pyx_v_s
*/
PyErr_Clear();
- /* "mtrand.pyx":1789
+ /* "mtrand.pyx":1811
* PyErr_Clear()
*
* odfnum = <ndarray>PyArray_FROM_OTF(dfnum, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* odfden = <ndarray>PyArray_FROM_OTF(dfden, NPY_DOUBLE, NPY_ALIGNED)
* ononc = <ndarray>PyArray_FROM_OTF(nonc, NPY_DOUBLE, NPY_ALIGNED)
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_dfnum, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_dfnum, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_odfnum));
- __pyx_v_odfnum = ((PyArrayObject *)__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_odfnum = ((PyArrayObject *)__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":1790
+ /* "mtrand.pyx":1812
*
* odfnum = <ndarray>PyArray_FROM_OTF(dfnum, NPY_DOUBLE, NPY_ALIGNED)
* odfden = <ndarray>PyArray_FROM_OTF(dfden, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* ononc = <ndarray>PyArray_FROM_OTF(nonc, NPY_DOUBLE, NPY_ALIGNED)
*
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_dfden, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1790; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_dfden, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_odfden));
- __pyx_v_odfden = ((PyArrayObject *)__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_odfden = ((PyArrayObject *)__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":1791
+ /* "mtrand.pyx":1813
* odfnum = <ndarray>PyArray_FROM_OTF(dfnum, NPY_DOUBLE, NPY_ALIGNED)
* odfden = <ndarray>PyArray_FROM_OTF(dfden, NPY_DOUBLE, NPY_ALIGNED)
* ononc = <ndarray>PyArray_FROM_OTF(nonc, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
*
* if np.any(np.less_equal(odfnum, 1.0)):
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_nonc, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1791; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_nonc, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_ononc));
- __pyx_v_ononc = ((PyArrayObject *)__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_ononc = ((PyArrayObject *)__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":1793
+ /* "mtrand.pyx":1815
* ononc = <ndarray>PyArray_FROM_OTF(nonc, NPY_DOUBLE, NPY_ALIGNED)
*
* if np.any(np.less_equal(odfnum, 1.0)): # <<<<<<<<<<<<<<
* raise ValueError("dfnum <= 1")
* if np.any(np.less_equal(odfden, 0.0)):
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(((PyObject *)__pyx_v_odfnum));
PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_odfnum));
__Pyx_GIVEREF(((PyObject *)__pyx_v_odfnum));
- PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 1793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
+ PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1815; __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_5)); __pyx_t_5 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":1794
+ /* "mtrand.pyx":1816
*
* if np.any(np.less_equal(odfnum, 1.0)):
* raise ValueError("dfnum <= 1") # <<<<<<<<<<<<<<
* if np.any(np.less_equal(odfden, 0.0)):
* raise ValueError("dfden <= 0")
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_17));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_17));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_17));
- __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_Raise(__pyx_t_5, 0, 0);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_50), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L10;
}
__pyx_L10:;
- /* "mtrand.pyx":1795
+ /* "mtrand.pyx":1817
* if np.any(np.less_equal(odfnum, 1.0)):
* raise ValueError("dfnum <= 1")
* if np.any(np.less_equal(odfden, 0.0)): # <<<<<<<<<<<<<<
* raise ValueError("dfden <= 0")
* if np.any(np.less(ononc, 0.0)):
*/
- __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_5 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1817; __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_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_5 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
__Pyx_INCREF(((PyObject *)__pyx_v_odfden));
PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_odfden));
__Pyx_GIVEREF(((PyObject *)__pyx_v_odfden));
- PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5);
- __Pyx_GIVEREF(__pyx_t_5);
- __pyx_t_5 = 0;
- __pyx_t_5 = PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__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 = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
- __Pyx_GIVEREF(__pyx_t_5);
- __pyx_t_5 = 0;
- __pyx_t_5 = PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
+ __Pyx_GIVEREF(__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 = 1817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 1817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
+ 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 = 1817; __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_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":1796
+ /* "mtrand.pyx":1818
* raise ValueError("dfnum <= 1")
* if np.any(np.less_equal(odfden, 0.0)):
* raise ValueError("dfden <= 0") # <<<<<<<<<<<<<<
* if np.any(np.less(ononc, 0.0)):
* raise ValueError("nonc < 0")
*/
- __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_16));
- PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_16));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_16));
- __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_Raise(__pyx_t_4, 0, 0);
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_51), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L11;
}
__pyx_L11:;
- /* "mtrand.pyx":1797
+ /* "mtrand.pyx":1819
* if np.any(np.less_equal(odfden, 0.0)):
* raise ValueError("dfden <= 0")
* if np.any(np.less(ononc, 0.0)): # <<<<<<<<<<<<<<
* raise ValueError("nonc < 0")
* return cont3_array(self.internal_state, rk_noncentral_f, size, odfnum,
*/
- __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __pyx_t_5 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__any); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_5 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__less); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __pyx_t_4 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_3));
__Pyx_INCREF(((PyObject *)__pyx_v_ononc));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_ononc));
+ PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_ononc));
__Pyx_GIVEREF(((PyObject *)__pyx_v_ononc));
- PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4);
- __Pyx_GIVEREF(__pyx_t_4);
- __pyx_t_4 = 0;
- __pyx_t_4 = PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1797; __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_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
- __Pyx_GIVEREF(__pyx_t_4);
- __pyx_t_4 = 0;
- __pyx_t_4 = PyObject_Call(__pyx_t_5, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 1819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_3));
+ PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __Pyx_DECREF(((PyObject *)__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 = 1819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":1798
+ /* "mtrand.pyx":1820
* raise ValueError("dfden <= 0")
* if np.any(np.less(ononc, 0.0)):
* raise ValueError("nonc < 0") # <<<<<<<<<<<<<<
* return cont3_array(self.internal_state, rk_noncentral_f, size, odfnum,
* odfden, ononc)
*/
- __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_18));
- PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_kp_s_18));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_18));
- __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_52), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L12;
}
__pyx_L12:;
- /* "mtrand.pyx":1799
+ /* "mtrand.pyx":1821
* if np.any(np.less(ononc, 0.0)):
* raise ValueError("nonc < 0")
* return cont3_array(self.internal_state, rk_noncentral_f, size, odfnum, # <<<<<<<<<<<<<<
@@ -9407,14 +9305,14 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_f(PyObject *__pyx_v_s
*/
__Pyx_XDECREF(__pyx_r);
- /* "mtrand.pyx":1800
+ /* "mtrand.pyx":1822
* raise ValueError("nonc < 0")
* return cont3_array(self.internal_state, rk_noncentral_f, size, odfnum,
* odfden, ononc) # <<<<<<<<<<<<<<
*
* def chisquare(self, df, size=None):
*/
- __pyx_t_2 = __pyx_f_6mtrand_cont3_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_noncentral_f, __pyx_v_size, __pyx_v_odfnum, __pyx_v_odfden, __pyx_v_ononc); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __pyx_f_6mtrand_cont3_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_noncentral_f, __pyx_v_size, __pyx_v_odfnum, __pyx_v_odfden, __pyx_v_ononc); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1821; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__pyx_r = __pyx_t_2;
__pyx_t_2 = 0;
@@ -9433,17 +9331,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_f(PyObject *__pyx_v_s
__Pyx_DECREF((PyObject *)__pyx_v_odfnum);
__Pyx_DECREF((PyObject *)__pyx_v_odfden);
__Pyx_DECREF((PyObject *)__pyx_v_ononc);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_dfnum);
- __Pyx_DECREF(__pyx_v_dfden);
- __Pyx_DECREF(__pyx_v_nonc);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":1802
+/* "mtrand.pyx":1824
* odfden, ononc)
*
* def chisquare(self, df, size=None): # <<<<<<<<<<<<<<
@@ -9451,9 +9344,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_f(PyObject *__pyx_v_s
* chisquare(df, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_chisquare(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_chisquare[] = "\n chisquare(df, size=None)\n\n Draw samples from a chi-square distribution.\n\n When `df` independent random variables, each with standard\n normal distributions (mean 0, variance 1), are squared and summed,\n the resulting distribution is chi-square (see Notes). This\n distribution is often used in hypothesis testing.\n\n Parameters\n ----------\n df : int\n Number of degrees of freedom.\n size : tuple of ints, int, optional\n Size of the returned array. By default, a scalar is\n returned.\n\n Returns\n -------\n output : ndarray\n Samples drawn from the distribution, packed in a `size`-shaped\n array.\n\n Raises\n ------\n ValueError\n When `df` <= 0 or when an inappropriate `size` (e.g. ``size=-1``)\n is given.\n\n Notes\n -----\n The variable obtained by summing the squares of `df` independent,\n standard normally distributed random variables:\n\n .. math:: Q = \\sum_{i=0}^{\\mathtt{df}} X^2_i\n\n is chi-square distributed, denoted\n\n .. math:: Q \\sim \\chi^2_k.\n\n The probability density function of the chi-squared distribution is\n\n .. math:: p(x) = \\frac{(1/2)^{k/2}}{\\Gamma(k/2)}\n x^{k/2 - 1} e^{-x/2},\n\n where :math:`\\Gamma` is the gamma function,\n\n .. math:: \\Gamma(x) = \\int_0^{-\\infty} t^{x - 1} e^{-t} dt.\n\n References\n ----------\n .. [1] NIST/SEMATECH e-Handbook of Statistical Methods,\n http://www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm\n .. [2] Wikipedia, \"Chi-square distribution\",\n http://en.wikipedia.org/wiki/Chi-square_distribution\n\n Examples\n --------\n >>> np.random.chisquare(2,4)\n array([ 1.89920014, 9.00867716, 3.13710533, 5.62318272])\n\n ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_chisquare(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_25chisquare(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_25chisquare[] = "\n chisquare(df, size=None)\n\n Draw samples from a chi-square distribution.\n\n When `df` independent random variables, each with standard normal\n distributions (mean 0, variance 1), are squared and summed, the\n resulting distribution is chi-square (see Notes). This distribution\n is often used in hypothesis testing.\n\n Parameters\n ----------\n df : int\n Number of degrees of freedom.\n size : tuple of ints, int, optional\n Size of the returned array. By default, a scalar is\n returned.\n\n Returns\n -------\n output : ndarray\n Samples drawn from the distribution, packed in a `size`-shaped\n array.\n\n Raises\n ------\n ValueError\n When `df` <= 0 or when an inappropriate `size` (e.g. ``size=-1``)\n is given.\n\n Notes\n -----\n The variable obtained by summing the squares of `df` independent,\n standard normally distributed random variables:\n\n .. math:: Q = \\sum_{i=0}^{\\mathtt{df}} X^2_i\n\n is chi-square distributed, denoted\n\n .. math:: Q \\sim \\chi^2_k.\n\n The probability density function of the chi-squared distribution is\n\n .. math:: p(x) = \\frac{(1/2)^{k/2}}{\\Gamma(k/2)}\n x^{k/2 - 1} e^{-x/2},\n\n where :math:`\\Gamma` is the gamma function,\n\n .. math:: \\Gamma(x) = \\int_0^{-\\infty} t^{x - 1} e^{-t} dt.\n\n References\n ----------\n `NIST/SEMATECH e-Handbook of Statistical Methods\n <http://www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm>`_\n\n Examples\n --------\n >>> np.random.chisquare(2,4)\n array([ 1.89920014, 9.00867716, 3.13710533, 5.62318272])\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_25chisquare(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_df = 0;
PyObject *__pyx_v_size = 0;
PyArrayObject *__pyx_v_odf;
@@ -9482,13 +9375,13 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_chisquare(PyObject *__pyx_v_self
if (likely(values[0])) kw_args--;
else goto __pyx_L5_argtuple_error;
case 1:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[1] = value; kw_args--; }
+ if (value) { values[1] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "chisquare") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1802; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "chisquare") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1824; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_df = values[0];
__pyx_v_size = values[1];
@@ -9503,17 +9396,15 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_chisquare(PyObject *__pyx_v_self
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("chisquare", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1802; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("chisquare", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1824; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.chisquare");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_df);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_odf = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":1869
+ /* "mtrand.pyx":1889
* cdef double fdf
*
* fdf = PyFloat_AsDouble(df) # <<<<<<<<<<<<<<
@@ -9522,7 +9413,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_chisquare(PyObject *__pyx_v_self
*/
__pyx_v_fdf = PyFloat_AsDouble(__pyx_v_df);
- /* "mtrand.pyx":1870
+ /* "mtrand.pyx":1890
*
* fdf = PyFloat_AsDouble(df)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -9532,39 +9423,33 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_chisquare(PyObject *__pyx_v_self
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":1871
+ /* "mtrand.pyx":1891
* fdf = PyFloat_AsDouble(df)
* if not PyErr_Occurred():
* if fdf <= 0: # <<<<<<<<<<<<<<
* raise ValueError("df <= 0")
* return cont1_array_sc(self.internal_state, rk_chisquare, size, fdf)
*/
- __pyx_t_1 = (__pyx_v_fdf <= 0);
+ __pyx_t_1 = (__pyx_v_fdf <= 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":1872
+ /* "mtrand.pyx":1892
* if not PyErr_Occurred():
* if fdf <= 0:
* raise ValueError("df <= 0") # <<<<<<<<<<<<<<
* return cont1_array_sc(self.internal_state, rk_chisquare, size, fdf)
*
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_54), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1892; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_19));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_19));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1892; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":1873
+ /* "mtrand.pyx":1893
* if fdf <= 0:
* raise ValueError("df <= 0")
* return cont1_array_sc(self.internal_state, rk_chisquare, size, fdf) # <<<<<<<<<<<<<<
@@ -9572,16 +9457,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_chisquare(PyObject *__pyx_v_self
* PyErr_Clear()
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = __pyx_f_6mtrand_cont1_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_chisquare, __pyx_v_size, __pyx_v_fdf); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1873; __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_cont1_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_chisquare, __pyx_v_size, __pyx_v_fdf); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1893; __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_L6;
}
__pyx_L6:;
- /* "mtrand.pyx":1875
+ /* "mtrand.pyx":1895
* return cont1_array_sc(self.internal_state, rk_chisquare, size, fdf)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -9590,87 +9475,81 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_chisquare(PyObject *__pyx_v_self
*/
PyErr_Clear();
- /* "mtrand.pyx":1877
+ /* "mtrand.pyx":1897
* PyErr_Clear()
*
* odf = <ndarray>PyArray_FROM_OTF(df, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less_equal(odf, 0.0)):
* raise ValueError("df <= 0")
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_df, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_df, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_odf));
- __pyx_v_odf = ((PyArrayObject *)__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_odf = ((PyArrayObject *)__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":1878
+ /* "mtrand.pyx":1898
*
* odf = <ndarray>PyArray_FROM_OTF(df, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(odf, 0.0)): # <<<<<<<<<<<<<<
* raise ValueError("df <= 0")
* return cont1_array(self.internal_state, rk_chisquare, size, odf)
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(((PyObject *)__pyx_v_odf));
PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_odf));
__Pyx_GIVEREF(((PyObject *)__pyx_v_odf));
- PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 1898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
+ PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1898; __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_5)); __pyx_t_5 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":1879
+ /* "mtrand.pyx":1899
* odf = <ndarray>PyArray_FROM_OTF(df, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(odf, 0.0)):
* raise ValueError("df <= 0") # <<<<<<<<<<<<<<
* return cont1_array(self.internal_state, rk_chisquare, size, odf)
*
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1879; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_19));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_19));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19));
- __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1879; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_Raise(__pyx_t_5, 0, 0);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1879; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_55), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1899; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1899; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":1880
+ /* "mtrand.pyx":1900
* if np.any(np.less_equal(odf, 0.0)):
* raise ValueError("df <= 0")
* return cont1_array(self.internal_state, rk_chisquare, size, odf) # <<<<<<<<<<<<<<
@@ -9678,10 +9557,10 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_chisquare(PyObject *__pyx_v_self
* def noncentral_chisquare(self, df, nonc, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_5 = __pyx_f_6mtrand_cont1_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_chisquare, __pyx_v_size, __pyx_v_odf); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_r = __pyx_t_5;
- __pyx_t_5 = 0;
+ __pyx_t_2 = __pyx_f_6mtrand_cont1_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_chisquare, __pyx_v_size, __pyx_v_odf); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1900; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -9695,15 +9574,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_chisquare(PyObject *__pyx_v_self
__pyx_r = NULL;
__pyx_L0:;
__Pyx_DECREF((PyObject *)__pyx_v_odf);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_df);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":1882
+/* "mtrand.pyx":1902
* return cont1_array(self.internal_state, rk_chisquare, size, odf)
*
* def noncentral_chisquare(self, df, nonc, size=None): # <<<<<<<<<<<<<<
@@ -9711,9 +9587,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_chisquare(PyObject *__pyx_v_self
* noncentral_chisquare(df, nonc, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_chisquare(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_noncentral_chisquare[] = "\n"" noncentral_chisquare(df, nonc, size=None)\n""\n"" Draw samples from a noncentral chi-square distribution.\n""\n"" The noncentral :math:`\\chi^2` distribution is a generalisation of\n"" the :math:`\\chi^2` distribution.\n""\n"" Parameters\n"" ----------\n"" df : int\n"" Degrees of freedom, should be >= 1.\n"" nonc : float\n"" Non-centrality, should be > 0.\n"" size : int or tuple of ints\n"" Shape of the output.\n""\n"" Notes\n"" -----\n"" The probability density function for the noncentral Chi-square distribution\n"" is\n""\n"" .. math:: P(x;df,nonc) = \\sum^{\\infty}_{i=0}\n"" \\frac{e^{-nonc/2}(nonc/2)^{i}}{i!}P_{Y_{df+2i}}(x),\n""\n"" where :math:`Y_{q}` is the Chi-square with q degrees of freedom.\n""\n"" In Delhi (2007), it is noted that the noncentral chi-square is useful in\n"" bombing and coverage problems, the probability of killing the point target\n"" given by the noncentral chi-squared distribution.\n""\n"" References\n"" ----------\n"" .. [1] Delhi, M.S. Holla, \"On a noncentral chi-square distribution in the\n"" analysis of weapon systems effectiveness\", Metrika, Volume 15,\n"" Number 1 / December, 1970.\n"" .. [2] Wikipedia, \"Noncentral chi-square distribution\"\n"" http://en.wikipedia.org/wiki/Noncentral_chi-square_distribution\n""\n"" Examples\n"" --------\n"" Draw values from the distribution and plot the histogram\n""\n"" >>> import matplotlib.pyplot as plt\n"" >>> values = plt.hist(np.random.noncentral_chisquare(3, 20, 100000),\n"" ... bins=200, normed=True)\n"" >>> plt.show()\n""\n"" Draw values from a noncentral chisquare with very small noncentrality,\n"" and compare to a chisquare.\n""\n"" >>> plt.figure()\n"" >>> values = plt.hist(np.random.noncentral_chisquare(3, .0000001, 100000),\n"" ... bins=np.arange(0., 25, .1), normed=True)\n"" >>> values2 = plt.hist(np.random.chisquare(3, 100000),\n"" ... bins=np.arange(0., 25, .1), normed=True)\n"" >>> plt.plot(values[1][0:-1], values[0]-values2[0], 'ob')\n"" >>> plt.show()\n""\n"" Demonstrate how large values of non-centrality lead to a more symmetric\n"" distribution.\n""\n"" >>> plt.figure()\n"" >>> values = plt.hist(np.random.noncentral_chisquare(3, 20, 100000),\n"" ... bins=200, normed=True)\n"" >>> plt.show()\n""\n"" ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_chisquare(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_26noncentral_chisquare(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_26noncentral_chisquare[] = "\n noncentral_chisquare(df, nonc, size=None)\n\n Draw samples from a noncentral chi-square distribution.\n\n The noncentral :math:`\\chi^2` distribution is a generalisation of\n the :math:`\\chi^2` distribution.\n\n Parameters\n ----------\n df : int\n Degrees of freedom, should be >= 1.\n nonc : float\n Non-centrality, should be > 0.\n size : int or tuple of ints\n Shape of the output.\n\n Notes\n -----\n The probability density function for the noncentral Chi-square distribution\n is\n\n .. math:: P(x;df,nonc) = \\sum^{\\infty}_{i=0}\n \\frac{e^{-nonc/2}(nonc/2)^{i}}{i!}P_{Y_{df+2i}}(x),\n\n where :math:`Y_{q}` is the Chi-square with q degrees of freedom.\n\n In Delhi (2007), it is noted that the noncentral chi-square is useful in\n bombing and coverage problems, the probability of killing the point target\n given by the noncentral chi-squared distribution.\n\n References\n ----------\n .. [1] Delhi, M.S. Holla, \"On a noncentral chi-square distribution in the\n analysis of weapon systems effectiveness\", Metrika, Volume 15,\n Number 1 / December, 1970.\n .. [2] Wikipedia, \"Noncentral chi-square distribution\"\n http://en.wikipedia.org/wiki/Noncentral_chi-square_distribution\n\n Examples\n --------\n Draw values from the distribution and plot the histogram\n\n >>> import matplotlib.pyplot as plt\n >>> values = plt.hist(np.random.noncentral_chisquare(3, 20, 100000),\n ... bins=200, normed=True)\n >>> plt.show()\n\n Draw values from a noncentral chisquare with very small noncentrality,\n and compare to a chisquare.\n\n >>> plt.figure()\n >>> values = plt.hist(np.random.noncentral_chisquare(3, .0000001, 100000),\n "" ... bins=np.arange(0., 25, .1), normed=True)\n >>> values2 = plt.hist(np.random.chisquare(3, 100000),\n ... bins=np.arange(0., 25, .1), normed=True)\n >>> plt.plot(values[1][0:-1], values[0]-values2[0], 'ob')\n >>> plt.show()\n\n Demonstrate how large values of non-centrality lead to a more symmetric\n distribution.\n\n >>> plt.figure()\n >>> values = plt.hist(np.random.noncentral_chisquare(3, 20, 100000),\n ... bins=200, normed=True)\n >>> plt.show()\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_26noncentral_chisquare(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_df = 0;
PyObject *__pyx_v_nonc = 0;
PyObject *__pyx_v_size = 0;
@@ -9749,16 +9625,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_chisquare(PyObject *_
values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__nonc);
if (likely(values[1])) kw_args--;
else {
- __Pyx_RaiseArgtupleInvalid("noncentral_chisquare", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1882; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("noncentral_chisquare", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1902; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
case 2:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[2] = value; kw_args--; }
+ if (value) { values[2] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "noncentral_chisquare") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1882; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "noncentral_chisquare") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1902; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_df = values[0];
__pyx_v_nonc = values[1];
@@ -9777,19 +9653,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_chisquare(PyObject *_
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("noncentral_chisquare", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1882; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("noncentral_chisquare", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1902; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.noncentral_chisquare");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_df);
- __Pyx_INCREF(__pyx_v_nonc);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_odf = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_ononc = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":1953
+ /* "mtrand.pyx":1973
* cdef ndarray odf, ononc
* cdef double fdf, fnonc
* fdf = PyFloat_AsDouble(df) # <<<<<<<<<<<<<<
@@ -9798,7 +9671,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_chisquare(PyObject *_
*/
__pyx_v_fdf = PyFloat_AsDouble(__pyx_v_df);
- /* "mtrand.pyx":1954
+ /* "mtrand.pyx":1974
* cdef double fdf, fnonc
* fdf = PyFloat_AsDouble(df)
* fnonc = PyFloat_AsDouble(nonc) # <<<<<<<<<<<<<<
@@ -9807,7 +9680,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_chisquare(PyObject *_
*/
__pyx_v_fnonc = PyFloat_AsDouble(__pyx_v_nonc);
- /* "mtrand.pyx":1955
+ /* "mtrand.pyx":1975
* fdf = PyFloat_AsDouble(df)
* fnonc = PyFloat_AsDouble(nonc)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -9817,71 +9690,59 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_chisquare(PyObject *_
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":1956
+ /* "mtrand.pyx":1976
* fnonc = PyFloat_AsDouble(nonc)
* if not PyErr_Occurred():
* if fdf <= 1: # <<<<<<<<<<<<<<
* raise ValueError("df <= 0")
* if fnonc <= 0:
*/
- __pyx_t_1 = (__pyx_v_fdf <= 1);
+ __pyx_t_1 = (__pyx_v_fdf <= 1.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":1957
+ /* "mtrand.pyx":1977
* if not PyErr_Occurred():
* if fdf <= 1:
* raise ValueError("df <= 0") # <<<<<<<<<<<<<<
* if fnonc <= 0:
* raise ValueError("nonc <= 0")
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_56), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1977; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_19));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_19));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1977; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":1958
+ /* "mtrand.pyx":1978
* if fdf <= 1:
* raise ValueError("df <= 0")
* if fnonc <= 0: # <<<<<<<<<<<<<<
* raise ValueError("nonc <= 0")
* return cont2_array_sc(self.internal_state, rk_noncentral_chisquare,
*/
- __pyx_t_1 = (__pyx_v_fnonc <= 0);
+ __pyx_t_1 = (__pyx_v_fnonc <= 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":1959
+ /* "mtrand.pyx":1979
* raise ValueError("df <= 0")
* if fnonc <= 0:
* raise ValueError("nonc <= 0") # <<<<<<<<<<<<<<
* return cont2_array_sc(self.internal_state, rk_noncentral_chisquare,
* size, fdf, fnonc)
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_20));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_20));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_20));
- __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_58), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1979; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1979; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":1960
+ /* "mtrand.pyx":1980
* if fnonc <= 0:
* raise ValueError("nonc <= 0")
* return cont2_array_sc(self.internal_state, rk_noncentral_chisquare, # <<<<<<<<<<<<<<
@@ -9890,14 +9751,14 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_chisquare(PyObject *_
*/
__Pyx_XDECREF(__pyx_r);
- /* "mtrand.pyx":1961
+ /* "mtrand.pyx":1981
* raise ValueError("nonc <= 0")
* return cont2_array_sc(self.internal_state, rk_noncentral_chisquare,
* size, fdf, fnonc) # <<<<<<<<<<<<<<
*
* PyErr_Clear()
*/
- __pyx_t_2 = __pyx_f_6mtrand_cont2_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_noncentral_chisquare, __pyx_v_size, __pyx_v_fdf, __pyx_v_fnonc); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __pyx_f_6mtrand_cont2_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_noncentral_chisquare, __pyx_v_size, __pyx_v_fdf, __pyx_v_fnonc); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__pyx_r = __pyx_t_2;
__pyx_t_2 = 0;
@@ -9906,7 +9767,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_chisquare(PyObject *_
}
__pyx_L6:;
- /* "mtrand.pyx":1963
+ /* "mtrand.pyx":1983
* size, fdf, fnonc)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -9915,167 +9776,155 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_chisquare(PyObject *_
*/
PyErr_Clear();
- /* "mtrand.pyx":1965
+ /* "mtrand.pyx":1985
* PyErr_Clear()
*
* odf = <ndarray>PyArray_FROM_OTF(df, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* ononc = <ndarray>PyArray_FROM_OTF(nonc, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(odf, 0.0)):
*/
- __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_df, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1965; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_df, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_odf));
__pyx_v_odf = ((PyArrayObject *)__pyx_t_2);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":1966
+ /* "mtrand.pyx":1986
*
* odf = <ndarray>PyArray_FROM_OTF(df, NPY_DOUBLE, NPY_ALIGNED)
* ononc = <ndarray>PyArray_FROM_OTF(nonc, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less_equal(odf, 0.0)):
* raise ValueError("df <= 1")
*/
- __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_nonc, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1966; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_nonc, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_ononc));
__pyx_v_ononc = ((PyArrayObject *)__pyx_t_2);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":1967
+ /* "mtrand.pyx":1987
* odf = <ndarray>PyArray_FROM_OTF(df, NPY_DOUBLE, NPY_ALIGNED)
* ononc = <ndarray>PyArray_FROM_OTF(nonc, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(odf, 0.0)): # <<<<<<<<<<<<<<
* raise ValueError("df <= 1")
* if np.any(np.less_equal(ononc, 0.0)):
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1987; __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_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(((PyObject *)__pyx_v_odf));
PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_odf));
__Pyx_GIVEREF(((PyObject *)__pyx_v_odf));
PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
__Pyx_GIVEREF(__pyx_t_2);
__pyx_t_2 = 0;
- __pyx_t_2 = PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 1967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __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 = 1987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
__Pyx_GIVEREF(__pyx_t_2);
__pyx_t_2 = 0;
- __pyx_t_2 = PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":1968
+ /* "mtrand.pyx":1988
* ononc = <ndarray>PyArray_FROM_OTF(nonc, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(odf, 0.0)):
* raise ValueError("df <= 1") # <<<<<<<<<<<<<<
* if np.any(np.less_equal(ononc, 0.0)):
* raise ValueError("nonc < 0")
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_60), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_21));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_21));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_21));
- __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_5, 0, 0);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L9;
}
__pyx_L9:;
- /* "mtrand.pyx":1969
+ /* "mtrand.pyx":1989
* if np.any(np.less_equal(odf, 0.0)):
* raise ValueError("df <= 1")
* if np.any(np.less_equal(ononc, 0.0)): # <<<<<<<<<<<<<<
* raise ValueError("nonc < 0")
* return cont2_array(self.internal_state, rk_noncentral_chisquare, size,
*/
- __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1969; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1969; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1969; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1969; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_5 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1969; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1969; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
__Pyx_INCREF(((PyObject *)__pyx_v_ononc));
PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_ononc));
__Pyx_GIVEREF(((PyObject *)__pyx_v_ononc));
- PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5);
- __Pyx_GIVEREF(__pyx_t_5);
- __pyx_t_5 = 0;
- __pyx_t_5 = PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1969; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
+ __Pyx_GIVEREF(__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 = 1989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_DECREF(__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 = 1969; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
- __Pyx_GIVEREF(__pyx_t_5);
- __pyx_t_5 = 0;
- __pyx_t_5 = PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1969; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1969; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 1989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
+ 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 = 1989; __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_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":1970
+ /* "mtrand.pyx":1990
* raise ValueError("df <= 1")
* if np.any(np.less_equal(ononc, 0.0)):
* raise ValueError("nonc < 0") # <<<<<<<<<<<<<<
* return cont2_array(self.internal_state, rk_noncentral_chisquare, size,
* odf, ononc)
*/
- __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1970; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_18));
- PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_18));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_18));
- __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1970; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_Raise(__pyx_t_4, 0, 0);
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1970; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_61), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L10;
}
__pyx_L10:;
- /* "mtrand.pyx":1971
+ /* "mtrand.pyx":1991
* if np.any(np.less_equal(ononc, 0.0)):
* raise ValueError("nonc < 0")
* return cont2_array(self.internal_state, rk_noncentral_chisquare, size, # <<<<<<<<<<<<<<
@@ -10084,17 +9933,17 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_chisquare(PyObject *_
*/
__Pyx_XDECREF(__pyx_r);
- /* "mtrand.pyx":1972
+ /* "mtrand.pyx":1992
* raise ValueError("nonc < 0")
* return cont2_array(self.internal_state, rk_noncentral_chisquare, size,
* odf, ononc) # <<<<<<<<<<<<<<
*
* def standard_cauchy(self, size=None):
*/
- __pyx_t_4 = __pyx_f_6mtrand_cont2_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_noncentral_chisquare, __pyx_v_size, __pyx_v_odf, __pyx_v_ononc); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1971; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- __pyx_r = __pyx_t_4;
- __pyx_t_4 = 0;
+ __pyx_t_2 = __pyx_f_6mtrand_cont2_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_noncentral_chisquare, __pyx_v_size, __pyx_v_odf, __pyx_v_ononc); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1991; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -10109,16 +9958,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_chisquare(PyObject *_
__pyx_L0:;
__Pyx_DECREF((PyObject *)__pyx_v_odf);
__Pyx_DECREF((PyObject *)__pyx_v_ononc);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_df);
- __Pyx_DECREF(__pyx_v_nonc);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":1974
+/* "mtrand.pyx":1994
* odf, ononc)
*
* def standard_cauchy(self, size=None): # <<<<<<<<<<<<<<
@@ -10126,9 +9971,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_noncentral_chisquare(PyObject *_
* standard_cauchy(size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_standard_cauchy(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_standard_cauchy[] = "\n"" standard_cauchy(size=None)\n""\n"" Standard Cauchy distribution with mode = 0.\n""\n"" Also known as the Lorentz distribution.\n""\n"" Parameters\n"" ----------\n"" size : int or tuple of ints\n"" Shape of the output.\n""\n"" Returns\n"" -------\n"" samples : ndarray or scalar\n"" The drawn samples.\n""\n"" Notes\n"" -----\n"" The probability density function for the full Cauchy distribution is\n""\n"" .. math:: P(x; x_0, \\gamma) = \\frac{1}{\\pi \\gamma \\bigl[ 1+\n"" (\\frac{x-x_0}{\\gamma})^2 \\bigr] }\n""\n"" and the Standard Cauchy distribution just sets :math:`x_0=0` and\n"" :math:`\\gamma=1`\n""\n"" The Cauchy distribution arises in the solution to the driven harmonic\n"" oscillator problem, and also describes spectral line broadening. It\n"" also describes the distribution of values at which a line tilted at\n"" a random angle will cut the x axis.\n""\n"" When studying hypothesis tests that assume normality, seeing how the\n"" tests perform on data from a Cauchy distribution is a good indicator of\n"" their sensitivity to a heavy-tailed distribution, since the Cauchy looks\n"" very much like a Gaussian distribution, but with heavier tails.\n""\n"" References\n"" ----------\n"" ..[1] NIST/SEMATECH e-Handbook of Statistical Methods, \"Cauchy\n"" Distribution\",\n"" http://www.itl.nist.gov/div898/handbook/eda/section3/eda3663.htm\n"" ..[2] Weisstein, Eric W. \"Cauchy Distribution.\" From MathWorld--A\n"" Wolfram Web Resource.\n"" http://mathworld.wolfram.com/CauchyDistribution.html\n"" ..[3] Wikipedia, \"Cauchy distribution\"\n"" http://en.wikipedia.org/wiki/Cauchy_distribution\n""\n"" Examples\n"" --------\n"" Draw samples and plot the distribution:\n""\n"" >>> s = np.random.standard_cauchy(1000000)\n"" >>> s = s[(s>-25) & (s<25)] # truncate distribution so it plots well\n"" >>> plt.hist(s, bins=100)\n"" >>> plt.show()\n""\n"" ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_standard_cauchy(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_27standard_cauchy(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_27standard_cauchy[] = "\n standard_cauchy(size=None)\n\n Standard Cauchy distribution with mode = 0.\n\n Also known as the Lorentz distribution.\n\n Parameters\n ----------\n size : int or tuple of ints\n Shape of the output.\n\n Returns\n -------\n samples : ndarray or scalar\n The drawn samples.\n\n Notes\n -----\n The probability density function for the full Cauchy distribution is\n\n .. math:: P(x; x_0, \\gamma) = \\frac{1}{\\pi \\gamma \\bigl[ 1+\n (\\frac{x-x_0}{\\gamma})^2 \\bigr] }\n\n and the Standard Cauchy distribution just sets :math:`x_0=0` and\n :math:`\\gamma=1`\n\n The Cauchy distribution arises in the solution to the driven harmonic\n oscillator problem, and also describes spectral line broadening. It\n also describes the distribution of values at which a line tilted at\n a random angle will cut the x axis.\n\n When studying hypothesis tests that assume normality, seeing how the\n tests perform on data from a Cauchy distribution is a good indicator of\n their sensitivity to a heavy-tailed distribution, since the Cauchy looks\n very much like a Gaussian distribution, but with heavier tails.\n\n References\n ----------\n ..[1] NIST/SEMATECH e-Handbook of Statistical Methods, \"Cauchy\n Distribution\",\n http://www.itl.nist.gov/div898/handbook/eda/section3/eda3663.htm\n ..[2] Weisstein, Eric W. \"Cauchy Distribution.\" From MathWorld--A\n Wolfram Web Resource.\n http://mathworld.wolfram.com/CauchyDistribution.html\n ..[3] Wikipedia, \"Cauchy distribution\"\n http://en.wikipedia.org/wiki/Cauchy_distribution\n\n Examples\n --------\n Draw samples and plot the distribution:\n\n >>> s = np.random.standard_cauchy(1000000)\n >>> s = s[(s>-25) & (s<25)""] # truncate distribution so it plots well\n >>> plt.hist(s, bins=100)\n >>> plt.show()\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_27standard_cauchy(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_size = 0;
PyObject *__pyx_r = NULL;
PyObject *__pyx_t_1 = NULL;
@@ -10145,13 +9990,13 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_cauchy(PyObject *__pyx_
}
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 0:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[0] = value; kw_args--; }
+ if (value) { values[0] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "standard_cauchy") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1974; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "standard_cauchy") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1994; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_size = values[0];
} else {
@@ -10164,13 +10009,14 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_cauchy(PyObject *__pyx_
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("standard_cauchy", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1974; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("standard_cauchy", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1994; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.standard_cauchy");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- /* "mtrand.pyx":2033
+ /* "mtrand.pyx":2053
*
* """
* return cont0_array(self.internal_state, rk_standard_cauchy, size) # <<<<<<<<<<<<<<
@@ -10178,7 +10024,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_cauchy(PyObject *__pyx_
* def standard_t(self, df, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = __pyx_f_6mtrand_cont0_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_standard_cauchy, __pyx_v_size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2033; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __pyx_f_6mtrand_cont0_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_standard_cauchy, __pyx_v_size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2053; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
@@ -10196,7 +10042,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_cauchy(PyObject *__pyx_
return __pyx_r;
}
-/* "mtrand.pyx":2035
+/* "mtrand.pyx":2055
* return cont0_array(self.internal_state, rk_standard_cauchy, size)
*
* def standard_t(self, df, size=None): # <<<<<<<<<<<<<<
@@ -10204,9 +10050,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_cauchy(PyObject *__pyx_
* standard_t(df, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_standard_t(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_standard_t[] = "\n"" standard_t(df, size=None)\n""\n"" Standard Student's t distribution with df degrees of freedom.\n""\n"" A special case of the hyperbolic distribution.\n"" As `df` gets large, the result resembles that of the standard normal\n"" distribution (`standard_normal`).\n""\n"" Parameters\n"" ----------\n"" df : int\n"" Degrees of freedom, should be > 0.\n"" size : int or tuple of ints, optional\n"" Output shape. Default is None, in which case a single value is\n"" returned.\n""\n"" Returns\n"" -------\n"" samples : ndarray or scalar\n"" Drawn samples.\n""\n"" Notes\n"" -----\n"" The probability density function for the t distribution is\n""\n"" .. math:: P(x, df) = \\frac{\\Gamma(\\frac{df+1}{2})}{\\sqrt{\\pi df}\n"" \\Gamma(\\frac{df}{2})}\\Bigl( 1+\\frac{x^2}{df} \\Bigr)^{-(df+1)/2}\n""\n"" The t test is based on an assumption that the data come from a Normal\n"" distribution. The t test provides a way to test whether the sample mean\n"" (that is the mean calculated from the data) is a good estimate of the true\n"" mean.\n""\n"" The derivation of the t-distribution was forst published in 1908 by William\n"" Gisset while working for the Guinness Brewery in Dublin. Due to proprietary\n"" issues, he had to publish under a pseudonym, and so he used the name\n"" Student.\n""\n"" References\n"" ----------\n"" .. [1] Dalgaard, Peter, \"Introductory Statistics With R\",\n"" Springer, 2002.\n"" .. [2] Wikipedia, \"Student's t-distribution\"\n"" http://en.wikipedia.org/wiki/Student's_t-distribution\n""\n"" Examples\n"" --------\n"" From Dalgaard page 83 [1]_, suppose the daily energy intake for 11\n"" women in Kj is:\n""\n"" >>> intake = np.array([5260., 5470, 5640, 6180, 6390, 6515, 6805, 7515, \\\n"" ... 7515, 8230, 8770])\n""\n"" Does their energy intake deviate systematically from the recommended\n"" value of 7725 kJ?\n""\n"" We have 10 degrees of freedom, so is the sample mean within 95% of the\n"" recommended value?\n""\n"" >>> s = np.random.standard_t(10, size=100000)\n"" >>> np.mean(intake)\n"" 6753.636363636364\n"" >>> intake.std(ddof=1)\n"" 1142.1232221373727\n""\n"" Calculate the t statistic, setting the ddof parameter to the unbiased\n"" value so the divisor in the standard deviation will be degrees of\n"" freedom, N-1.\n""\n"" >>> t = (np.mean(intake)-7725)/(intake.std(ddof=1)/np.sqrt(len(intake)))\n"" >>> import matplotlib.pyplot as plt\n"" >>> h = plt.hist(s, bins=100, normed=True)\n""\n"" For a one-sided t-test, how far out in the distribution does the t\n"" statistic appear?\n""\n"" >>> >>> np.sum(s<t) / float(len(s))\n"" 0.0090699999999999999 #random\n""\n"" So the p-value is about 0.009, which says the null hypothesis has a\n"" probability of about 99% of being true.\n""\n"" ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_standard_t(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_28standard_t(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_28standard_t[] = "\n standard_t(df, size=None)\n\n Standard Student's t distribution with df degrees of freedom.\n\n A special case of the hyperbolic distribution.\n As `df` gets large, the result resembles that of the standard normal\n distribution (`standard_normal`).\n\n Parameters\n ----------\n df : int\n Degrees of freedom, should be > 0.\n size : int or tuple of ints, optional\n Output shape. Default is None, in which case a single value is\n returned.\n\n Returns\n -------\n samples : ndarray or scalar\n Drawn samples.\n\n Notes\n -----\n The probability density function for the t distribution is\n\n .. math:: P(x, df) = \\frac{\\Gamma(\\frac{df+1}{2})}{\\sqrt{\\pi df}\n \\Gamma(\\frac{df}{2})}\\Bigl( 1+\\frac{x^2}{df} \\Bigr)^{-(df+1)/2}\n\n The t test is based on an assumption that the data come from a Normal\n distribution. The t test provides a way to test whether the sample mean\n (that is the mean calculated from the data) is a good estimate of the true\n mean.\n\n The derivation of the t-distribution was forst published in 1908 by William\n Gisset while working for the Guinness Brewery in Dublin. Due to proprietary\n issues, he had to publish under a pseudonym, and so he used the name\n Student.\n\n References\n ----------\n .. [1] Dalgaard, Peter, \"Introductory Statistics With R\",\n Springer, 2002.\n .. [2] Wikipedia, \"Student's t-distribution\"\n http://en.wikipedia.org/wiki/Student's_t-distribution\n\n Examples\n --------\n From Dalgaard page 83 [1]_, suppose the daily energy intake for 11\n women in Kj is:\n\n >>> intake = np.array([5260., 5470, 5640, 6180, 6390, 6515, 6805, 7515, \\\n ... 7515, 8230, 8770])\n\n Doe""s their energy intake deviate systematically from the recommended\n value of 7725 kJ?\n\n We have 10 degrees of freedom, so is the sample mean within 95% of the\n recommended value?\n\n >>> s = np.random.standard_t(10, size=100000)\n >>> np.mean(intake)\n 6753.636363636364\n >>> intake.std(ddof=1)\n 1142.1232221373727\n\n Calculate the t statistic, setting the ddof parameter to the unbiased\n value so the divisor in the standard deviation will be degrees of\n freedom, N-1.\n\n >>> t = (np.mean(intake)-7725)/(intake.std(ddof=1)/np.sqrt(len(intake)))\n >>> import matplotlib.pyplot as plt\n >>> h = plt.hist(s, bins=100, normed=True)\n\n For a one-sided t-test, how far out in the distribution does the t\n statistic appear?\n\n >>> >>> np.sum(s<t) / float(len(s))\n 0.0090699999999999999 #random\n\n So the p-value is about 0.009, which says the null hypothesis has a\n probability of about 99% of being true.\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_28standard_t(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_df = 0;
PyObject *__pyx_v_size = 0;
PyArrayObject *__pyx_v_odf;
@@ -10235,13 +10081,13 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_t(PyObject *__pyx_v_sel
if (likely(values[0])) kw_args--;
else goto __pyx_L5_argtuple_error;
case 1:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[1] = value; kw_args--; }
+ if (value) { values[1] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "standard_t") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2035; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "standard_t") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2055; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_df = values[0];
__pyx_v_size = values[1];
@@ -10256,17 +10102,15 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_t(PyObject *__pyx_v_sel
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("standard_t", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2035; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("standard_t", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2055; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.standard_t");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_df);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_odf = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":2123
+ /* "mtrand.pyx":2143
* cdef double fdf
*
* fdf = PyFloat_AsDouble(df) # <<<<<<<<<<<<<<
@@ -10275,7 +10119,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_t(PyObject *__pyx_v_sel
*/
__pyx_v_fdf = PyFloat_AsDouble(__pyx_v_df);
- /* "mtrand.pyx":2124
+ /* "mtrand.pyx":2144
*
* fdf = PyFloat_AsDouble(df)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -10285,39 +10129,33 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_t(PyObject *__pyx_v_sel
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":2125
+ /* "mtrand.pyx":2145
* fdf = PyFloat_AsDouble(df)
* if not PyErr_Occurred():
* if fdf <= 0: # <<<<<<<<<<<<<<
* raise ValueError("df <= 0")
* return cont1_array_sc(self.internal_state, rk_standard_t, size, fdf)
*/
- __pyx_t_1 = (__pyx_v_fdf <= 0);
+ __pyx_t_1 = (__pyx_v_fdf <= 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":2126
+ /* "mtrand.pyx":2146
* if not PyErr_Occurred():
* if fdf <= 0:
* raise ValueError("df <= 0") # <<<<<<<<<<<<<<
* return cont1_array_sc(self.internal_state, rk_standard_t, size, fdf)
*
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_62), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_19));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_19));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":2127
+ /* "mtrand.pyx":2147
* if fdf <= 0:
* raise ValueError("df <= 0")
* return cont1_array_sc(self.internal_state, rk_standard_t, size, fdf) # <<<<<<<<<<<<<<
@@ -10325,16 +10163,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_t(PyObject *__pyx_v_sel
* PyErr_Clear()
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = __pyx_f_6mtrand_cont1_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_standard_t, __pyx_v_size, __pyx_v_fdf); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2127; __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_cont1_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_standard_t, __pyx_v_size, __pyx_v_fdf); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2147; __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_L6;
}
__pyx_L6:;
- /* "mtrand.pyx":2129
+ /* "mtrand.pyx":2149
* return cont1_array_sc(self.internal_state, rk_standard_t, size, fdf)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -10343,87 +10181,81 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_t(PyObject *__pyx_v_sel
*/
PyErr_Clear();
- /* "mtrand.pyx":2131
+ /* "mtrand.pyx":2151
* PyErr_Clear()
*
* odf = <ndarray> PyArray_FROM_OTF(df, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less_equal(odf, 0.0)):
* raise ValueError("df <= 0")
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_df, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_df, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_odf));
- __pyx_v_odf = ((PyArrayObject *)__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_odf = ((PyArrayObject *)__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":2132
+ /* "mtrand.pyx":2152
*
* odf = <ndarray> PyArray_FROM_OTF(df, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(odf, 0.0)): # <<<<<<<<<<<<<<
* raise ValueError("df <= 0")
* return cont1_array(self.internal_state, rk_standard_t, size, odf)
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(((PyObject *)__pyx_v_odf));
PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_odf));
__Pyx_GIVEREF(((PyObject *)__pyx_v_odf));
- PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 2132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 2152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
+ PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2152; __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_5)); __pyx_t_5 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":2133
+ /* "mtrand.pyx":2153
* odf = <ndarray> PyArray_FROM_OTF(df, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(odf, 0.0)):
* raise ValueError("df <= 0") # <<<<<<<<<<<<<<
* return cont1_array(self.internal_state, rk_standard_t, size, odf)
*
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_19));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_19));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19));
- __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_Raise(__pyx_t_5, 0, 0);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_63), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":2134
+ /* "mtrand.pyx":2154
* if np.any(np.less_equal(odf, 0.0)):
* raise ValueError("df <= 0")
* return cont1_array(self.internal_state, rk_standard_t, size, odf) # <<<<<<<<<<<<<<
@@ -10431,10 +10263,10 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_t(PyObject *__pyx_v_sel
* def vonmises(self, mu, kappa, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_5 = __pyx_f_6mtrand_cont1_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_standard_t, __pyx_v_size, __pyx_v_odf); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_r = __pyx_t_5;
- __pyx_t_5 = 0;
+ __pyx_t_2 = __pyx_f_6mtrand_cont1_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_standard_t, __pyx_v_size, __pyx_v_odf); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -10448,25 +10280,22 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_standard_t(PyObject *__pyx_v_sel
__pyx_r = NULL;
__pyx_L0:;
__Pyx_DECREF((PyObject *)__pyx_v_odf);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_df);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":2136
+/* "mtrand.pyx":2156
* return cont1_array(self.internal_state, rk_standard_t, size, odf)
*
* def vonmises(self, mu, kappa, size=None): # <<<<<<<<<<<<<<
* """
- * vonmises(mu=0.0, kappa=1.0, size=None)
+ * vonmises(mu, kappa, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_vonmises(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_vonmises[] = "\n"" vonmises(mu=0.0, kappa=1.0, size=None)\n""\n"" Draw samples from a von Mises distribution.\n""\n"" Samples are drawn from a von Mises distribution with specified mode (mu)\n"" and dispersion (kappa), on the interval [-pi, pi].\n""\n"" The von Mises distribution (also known as the circular normal\n"" distribution) is a continuous probability distribution on the circle. It\n"" may be thought of as the circular analogue of the normal distribution.\n""\n"" Parameters\n"" ----------\n"" mu : float\n"" Mode (\"center\") of the distribution.\n"" kappa : float, >= 0.\n"" Dispersion of the distribution.\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"" The returned samples live on the unit circle [-\\pi, \\pi].\n""\n"" See Also\n"" --------\n"" scipy.stats.distributions.vonmises : probability density function,\n"" distribution or cumulative density function, etc.\n""\n"" Notes\n"" -----\n"" The probability density for the von Mises distribution is\n""\n"" .. math:: p(x) = \\frac{e^{\\kappa cos(x-\\mu)}}{2\\pi I_0(\\kappa)},\n""\n"" where :math:`\\mu` is the mode and :math:`\\kappa` the dispersion,\n"" and :math:`I_0(\\kappa)` is the modified Bessel function of order 0.\n""\n"" The von Mises, named for Richard Edler von Mises, born in\n"" Austria-Hungary, in what is now the Ukraine. He fled to the United\n"" States in 1939 and became a professor at Harvard. He worked in\n"" probability theory, aerodynamics, fluid mechanics, and philosophy of\n"" science.\n""\n"" References\n"" ----------\n"" .. [1] Abramowitz, M. and Stegun, I. A. (ed.), Handbook of Mathematical\n"" Functions, National Bureau of Standards, 1964; reprinted Dover\n"" Publications, 1965.\n"" .. [2] von Mises, Richard, 1964, Mathematical Theory of Probability\n"" and Statistics (New York: Academic Press).\n"" .. [3] Wikipedia, \"Von Mises distribution\",\n"" http://en.wikipedia.org/wiki/Von_Mises_distribution\n""\n"" Examples\n"" --------\n"" Draw samples from the distribution:\n""\n"" >>> mu, kappa = 0.0, 4.0 # mean and dispersion\n"" >>> s = np.random.vonmises(mu, kappa, 1000)\n""\n"" Display the histogram of the samples, along with\n"" the probability density function:\n""\n"" >>> import matplotlib.pyplot as plt\n"" >>> import scipy.special as sps\n"" >>> count, bins, ignored = plt.hist(s, 50, normed=True)\n"" >>> x = np.arange(-np.pi, np.pi, 2*np.pi/50.)\n"" >>> y = -np.exp(kappa*np.cos(x-mu))/(2*np.pi*sps.jn(0,kappa))\n"" >>> plt.plot(x, y/max(y), linewidth=2, color='r')\n"" >>> plt.show()\n""\n"" ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_vonmises(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_29vonmises(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_29vonmises[] = "\n vonmises(mu, kappa, size=None)\n\n Draw samples from a von Mises distribution.\n\n Samples are drawn from a von Mises distribution with specified mode\n (mu) and dispersion (kappa), on the interval [-pi, pi].\n\n The von Mises distribution (also known as the circular normal\n distribution) is a continuous probability distribution on the unit\n circle. It may be thought of as the circular analogue of the normal\n distribution.\n\n Parameters\n ----------\n mu : float\n Mode (\"center\") of the distribution.\n kappa : float\n Dispersion of the distribution, has to be >=0.\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 : scalar or ndarray\n The returned samples, which are in the interval [-pi, pi].\n\n See Also\n --------\n scipy.stats.distributions.vonmises : probability density function,\n distribution, or cumulative density function, etc.\n\n Notes\n -----\n The probability density for the von Mises distribution is\n\n .. math:: p(x) = \\frac{e^{\\kappa cos(x-\\mu)}}{2\\pi I_0(\\kappa)},\n\n where :math:`\\mu` is the mode and :math:`\\kappa` the dispersion,\n and :math:`I_0(\\kappa)` is the modified Bessel function of order 0.\n\n The von Mises is named for Richard Edler von Mises, who was born in\n Austria-Hungary, in what is now the Ukraine. He fled to the United\n States in 1939 and became a professor at Harvard. He worked in\n probability theory, aerodynamics, fluid mechanics, and philosophy of\n science.\n\n References\n ----------\n Abramowitz, M. and Stegun, I. A. (ed.), *Handbook of Mathematical\n Functions*, New York: Dover, 1965.\n\n "" von Mises, R., *Mathematical Theory of Probability and Statistics*,\n New York: Academic Press, 1964.\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> mu, kappa = 0.0, 4.0 # mean and dispersion\n >>> s = np.random.vonmises(mu, kappa, 1000)\n\n Display the histogram of the samples, along with\n the probability density function:\n\n >>> import matplotlib.pyplot as plt\n >>> import scipy.special as sps\n >>> count, bins, ignored = plt.hist(s, 50, normed=True)\n >>> x = np.arange(-np.pi, np.pi, 2*np.pi/50.)\n >>> y = -np.exp(kappa*np.cos(x-mu))/(2*np.pi*sps.jn(0,kappa))\n >>> plt.plot(x, y/max(y), linewidth=2, color='r')\n >>> plt.show()\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_29vonmises(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_mu = 0;
PyObject *__pyx_v_kappa = 0;
PyObject *__pyx_v_size = 0;
@@ -10502,16 +10331,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_vonmises(PyObject *__pyx_v_self,
values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__kappa);
if (likely(values[1])) kw_args--;
else {
- __Pyx_RaiseArgtupleInvalid("vonmises", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2136; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("vonmises", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2156; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
case 2:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[2] = value; kw_args--; }
+ if (value) { values[2] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "vonmises") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2136; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "vonmises") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2156; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_mu = values[0];
__pyx_v_kappa = values[1];
@@ -10530,19 +10359,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_vonmises(PyObject *__pyx_v_self,
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("vonmises", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2136; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("vonmises", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2156; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.vonmises");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_mu);
- __Pyx_INCREF(__pyx_v_kappa);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_omu = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_okappa = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":2216
+ /* "mtrand.pyx":2235
* cdef double fmu, fkappa
*
* fmu = PyFloat_AsDouble(mu) # <<<<<<<<<<<<<<
@@ -10551,7 +10377,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_vonmises(PyObject *__pyx_v_self,
*/
__pyx_v_fmu = PyFloat_AsDouble(__pyx_v_mu);
- /* "mtrand.pyx":2217
+ /* "mtrand.pyx":2236
*
* fmu = PyFloat_AsDouble(mu)
* fkappa = PyFloat_AsDouble(kappa) # <<<<<<<<<<<<<<
@@ -10560,7 +10386,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_vonmises(PyObject *__pyx_v_self,
*/
__pyx_v_fkappa = PyFloat_AsDouble(__pyx_v_kappa);
- /* "mtrand.pyx":2218
+ /* "mtrand.pyx":2237
* fmu = PyFloat_AsDouble(mu)
* fkappa = PyFloat_AsDouble(kappa)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -10570,39 +10396,33 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_vonmises(PyObject *__pyx_v_self,
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":2219
+ /* "mtrand.pyx":2238
* fkappa = PyFloat_AsDouble(kappa)
* if not PyErr_Occurred():
* if fkappa < 0: # <<<<<<<<<<<<<<
* raise ValueError("kappa < 0")
* return cont2_array_sc(self.internal_state, rk_vonmises, size, fmu, fkappa)
*/
- __pyx_t_1 = (__pyx_v_fkappa < 0);
+ __pyx_t_1 = (__pyx_v_fkappa < 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":2220
+ /* "mtrand.pyx":2239
* if not PyErr_Occurred():
* if fkappa < 0:
* raise ValueError("kappa < 0") # <<<<<<<<<<<<<<
* return cont2_array_sc(self.internal_state, rk_vonmises, size, fmu, fkappa)
*
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_65), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_22));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_22));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_22));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":2221
+ /* "mtrand.pyx":2240
* if fkappa < 0:
* raise ValueError("kappa < 0")
* return cont2_array_sc(self.internal_state, rk_vonmises, size, fmu, fkappa) # <<<<<<<<<<<<<<
@@ -10610,16 +10430,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_vonmises(PyObject *__pyx_v_self,
* PyErr_Clear()
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = __pyx_f_6mtrand_cont2_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_vonmises, __pyx_v_size, __pyx_v_fmu, __pyx_v_fkappa); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2221; __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_cont2_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_vonmises, __pyx_v_size, __pyx_v_fmu, __pyx_v_fkappa); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2240; __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_L6;
}
__pyx_L6:;
- /* "mtrand.pyx":2223
+ /* "mtrand.pyx":2242
* return cont2_array_sc(self.internal_state, rk_vonmises, size, fmu, fkappa)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -10628,101 +10448,95 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_vonmises(PyObject *__pyx_v_self,
*/
PyErr_Clear();
- /* "mtrand.pyx":2225
+ /* "mtrand.pyx":2244
* PyErr_Clear()
*
* omu = <ndarray> PyArray_FROM_OTF(mu, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* okappa = <ndarray> PyArray_FROM_OTF(kappa, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less(okappa, 0.0)):
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_mu, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_mu, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_omu));
- __pyx_v_omu = ((PyArrayObject *)__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_omu = ((PyArrayObject *)__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":2226
+ /* "mtrand.pyx":2245
*
* omu = <ndarray> PyArray_FROM_OTF(mu, NPY_DOUBLE, NPY_ALIGNED)
* okappa = <ndarray> PyArray_FROM_OTF(kappa, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less(okappa, 0.0)):
* raise ValueError("kappa < 0")
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_kappa, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2226; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_kappa, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_okappa));
- __pyx_v_okappa = ((PyArrayObject *)__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_okappa = ((PyArrayObject *)__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":2227
+ /* "mtrand.pyx":2246
* omu = <ndarray> PyArray_FROM_OTF(mu, NPY_DOUBLE, NPY_ALIGNED)
* okappa = <ndarray> PyArray_FROM_OTF(kappa, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less(okappa, 0.0)): # <<<<<<<<<<<<<<
* raise ValueError("kappa < 0")
* return cont2_array(self.internal_state, rk_vonmises, size, omu, okappa)
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(((PyObject *)__pyx_v_okappa));
PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_okappa));
__Pyx_GIVEREF(((PyObject *)__pyx_v_okappa));
- PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 2227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 2246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
+ PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2246; __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_5)); __pyx_t_5 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":2228
+ /* "mtrand.pyx":2247
* okappa = <ndarray> PyArray_FROM_OTF(kappa, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less(okappa, 0.0)):
* raise ValueError("kappa < 0") # <<<<<<<<<<<<<<
* return cont2_array(self.internal_state, rk_vonmises, size, omu, okappa)
*
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_22));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_22));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_22));
- __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_Raise(__pyx_t_5, 0, 0);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_66), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":2229
+ /* "mtrand.pyx":2248
* if np.any(np.less(okappa, 0.0)):
* raise ValueError("kappa < 0")
* return cont2_array(self.internal_state, rk_vonmises, size, omu, okappa) # <<<<<<<<<<<<<<
@@ -10730,10 +10544,10 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_vonmises(PyObject *__pyx_v_self,
* def pareto(self, a, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_5 = __pyx_f_6mtrand_cont2_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_vonmises, __pyx_v_size, __pyx_v_omu, __pyx_v_okappa); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_r = __pyx_t_5;
- __pyx_t_5 = 0;
+ __pyx_t_2 = __pyx_f_6mtrand_cont2_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_vonmises, __pyx_v_size, __pyx_v_omu, __pyx_v_okappa); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -10748,16 +10562,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_vonmises(PyObject *__pyx_v_self,
__pyx_L0:;
__Pyx_DECREF((PyObject *)__pyx_v_omu);
__Pyx_DECREF((PyObject *)__pyx_v_okappa);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_mu);
- __Pyx_DECREF(__pyx_v_kappa);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":2231
+/* "mtrand.pyx":2250
* return cont2_array(self.internal_state, rk_vonmises, size, omu, okappa)
*
* def pareto(self, a, size=None): # <<<<<<<<<<<<<<
@@ -10765,9 +10575,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_vonmises(PyObject *__pyx_v_self,
* pareto(a, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_pareto(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_pareto[] = "\n"" pareto(a, size=None)\n""\n"" Draw samples from a Pareto distribution with specified shape.\n""\n"" This is a simplified version of the Generalized Pareto distribution\n"" (available in SciPy), with the scale set to one and the location set to\n"" zero. Most authors default the location to one.\n""\n"" The Pareto distribution must be greater than zero, and is unbounded above.\n"" It is also known as the \"80-20 rule\". In this distribution, 80 percent of\n"" the weights are in the lowest 20 percent of the range, while the other 20\n"" percent fill the remaining 80 percent of the range.\n""\n"" Parameters\n"" ----------\n"" shape : float, > 0.\n"" Shape of the distribution.\n"" size : tuple of ints\n"" Output shape. If the given shape is, e.g., ``(m, n, k)``, then\n"" ``m * n * k`` samples are drawn.\n""\n"" See Also\n"" --------\n"" scipy.stats.distributions.genpareto.pdf : probability density function,\n"" distribution or cumulative density function, etc.\n""\n"" Notes\n"" -----\n"" The probability density for the Pareto distribution is\n""\n"" .. math:: p(x) = \\frac{am^a}{x^{a+1}}\n""\n"" where :math:`a` is the shape and :math:`m` the location\n""\n"" The Pareto distribution, named after the Italian economist Vilfredo Pareto,\n"" is a power law probability distribution useful in many real world problems.\n"" Outside the field of economics it is generally referred to as the Bradford\n"" distribution. Pareto developed the distribution to describe the\n"" distribution of wealth in an economy. It has also found use in insurance,\n"" web page access statistics, oil field sizes, and many other problems,\n"" including the download frequency for projects in Sourceforge [1]. It is\n"" one of the so-called \"fat-tailed\" distributions.\n""\n""\n"" References\n"" ----------\n"" .. [1] Francis Hunt and Paul Johnson, On the Pareto Distribution of\n"" Sourceforge projects.\n"" .. [2] Pareto, V. (1896). Course of Political Economy. Lausanne.\n"" .. [3] Reiss, R.D., Thomas, M.(2001), Statistical Analysis of Extreme\n"" Values, Birkhauser Verlag, Basel, pp 23-30.\n"" .. [4] Wikipedia, \"Pareto distribution\",\n"" http://en.wikipedia.org/wiki/Pareto_distribution\n""\n"" Examples\n"" --------\n"" Draw samples from the distribution:\n""\n"" >>> a, m = 3., 1. # shape and mode\n"" >>> s = np.random.pareto(a, 1000) + m\n""\n"" Display the histogram of the samples, along with\n"" the probability density function:\n""\n"" >>> import matplotlib.pyplot as plt\n"" >>> count, bins, ignored = plt.hist(s, 100, normed=True, align='center')\n"" >>> fit = a*m**a/bins**(a+1)\n"" >>> plt.plot(bins, max(count)*fit/max(fit),linewidth=2, color='r')\n"" >>> plt.show()\n""\n"" ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_pareto(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_30pareto(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_30pareto[] = "\n pareto(a, size=None)\n\n Draw samples from a Pareto II or Lomax distribution with specified shape.\n\n The Lomax or Pareto II distribution is a shifted Pareto distribution. The\n classical Pareto distribution can be obtained from the Lomax distribution\n by adding the location parameter m, see below. The smallest value of the\n Lomax distribution is zero while for the classical Pareto distribution it\n is m, where the standard Pareto distribution has location m=1.\n Lomax can also be considered as a simplified version of the Generalized\n Pareto distribution (available in SciPy), with the scale set to one and\n the location set to zero.\n\n The Pareto distribution must be greater than zero, and is unbounded above.\n It is also known as the \"80-20 rule\". In this distribution, 80 percent of\n the weights are in the lowest 20 percent of the range, while the other 20\n percent fill the remaining 80 percent of the range.\n\n Parameters\n ----------\n shape : float, > 0.\n Shape of the distribution.\n size : tuple of ints\n Output shape. If the given shape is, e.g., ``(m, n, k)``, then\n ``m * n * k`` samples are drawn.\n\n See Also\n --------\n scipy.stats.distributions.lomax.pdf : probability density function,\n distribution or cumulative density function, etc.\n scipy.stats.distributions.genpareto.pdf : probability density function,\n distribution or cumulative density function, etc.\n\n Notes\n -----\n The probability density for the Pareto distribution is\n\n .. math:: p(x) = \\frac{am^a}{x^{a+1}}\n\n where :math:`a` is the shape and :math:`m` the location\n\n The Pareto distribution, named after the Italian economist Vilfredo Pareto,\n is a power law probability distribution useful in many real world probl""ems.\n Outside the field of economics it is generally referred to as the Bradford\n distribution. Pareto developed the distribution to describe the\n distribution of wealth in an economy. It has also found use in insurance,\n web page access statistics, oil field sizes, and many other problems,\n including the download frequency for projects in Sourceforge [1]. It is\n one of the so-called \"fat-tailed\" distributions.\n\n\n References\n ----------\n .. [1] Francis Hunt and Paul Johnson, On the Pareto Distribution of\n Sourceforge projects.\n .. [2] Pareto, V. (1896). Course of Political Economy. Lausanne.\n .. [3] Reiss, R.D., Thomas, M.(2001), Statistical Analysis of Extreme\n Values, Birkhauser Verlag, Basel, pp 23-30.\n .. [4] Wikipedia, \"Pareto distribution\",\n http://en.wikipedia.org/wiki/Pareto_distribution\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> a, m = 3., 1. # shape and mode\n >>> s = np.random.pareto(a, 1000) + m\n\n Display the histogram of the samples, along with\n the probability density function:\n\n >>> import matplotlib.pyplot as plt\n >>> count, bins, ignored = plt.hist(s, 100, normed=True, align='center')\n >>> fit = a*m**a/bins**(a+1)\n >>> plt.plot(bins, max(count)*fit/max(fit),linewidth=2, color='r')\n >>> plt.show()\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_30pareto(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_a = 0;
PyObject *__pyx_v_size = 0;
PyArrayObject *__pyx_v_oa;
@@ -10796,13 +10606,13 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_pareto(PyObject *__pyx_v_self, P
if (likely(values[0])) kw_args--;
else goto __pyx_L5_argtuple_error;
case 1:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[1] = value; kw_args--; }
+ if (value) { values[1] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "pareto") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2231; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "pareto") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2250; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_a = values[0];
__pyx_v_size = values[1];
@@ -10817,17 +10627,15 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_pareto(PyObject *__pyx_v_self, P
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("pareto", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2231; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("pareto", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2250; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.pareto");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_a);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_oa = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":2307
+ /* "mtrand.pyx":2333
* cdef double fa
*
* fa = PyFloat_AsDouble(a) # <<<<<<<<<<<<<<
@@ -10836,7 +10644,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_pareto(PyObject *__pyx_v_self, P
*/
__pyx_v_fa = PyFloat_AsDouble(__pyx_v_a);
- /* "mtrand.pyx":2308
+ /* "mtrand.pyx":2334
*
* fa = PyFloat_AsDouble(a)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -10846,39 +10654,33 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_pareto(PyObject *__pyx_v_self, P
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":2309
+ /* "mtrand.pyx":2335
* fa = PyFloat_AsDouble(a)
* if not PyErr_Occurred():
* if fa <= 0: # <<<<<<<<<<<<<<
* raise ValueError("a <= 0")
* return cont1_array_sc(self.internal_state, rk_pareto, size, fa)
*/
- __pyx_t_1 = (__pyx_v_fa <= 0);
+ __pyx_t_1 = (__pyx_v_fa <= 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":2310
+ /* "mtrand.pyx":2336
* if not PyErr_Occurred():
* if fa <= 0:
* raise ValueError("a <= 0") # <<<<<<<<<<<<<<
* return cont1_array_sc(self.internal_state, rk_pareto, size, fa)
*
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_67), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_10));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":2311
+ /* "mtrand.pyx":2337
* if fa <= 0:
* raise ValueError("a <= 0")
* return cont1_array_sc(self.internal_state, rk_pareto, size, fa) # <<<<<<<<<<<<<<
@@ -10886,16 +10688,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_pareto(PyObject *__pyx_v_self, P
* PyErr_Clear()
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = __pyx_f_6mtrand_cont1_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_pareto, __pyx_v_size, __pyx_v_fa); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2311; __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_cont1_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_pareto, __pyx_v_size, __pyx_v_fa); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2337; __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_L6;
}
__pyx_L6:;
- /* "mtrand.pyx":2313
+ /* "mtrand.pyx":2339
* return cont1_array_sc(self.internal_state, rk_pareto, size, fa)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -10904,87 +10706,81 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_pareto(PyObject *__pyx_v_self, P
*/
PyErr_Clear();
- /* "mtrand.pyx":2315
+ /* "mtrand.pyx":2341
* PyErr_Clear()
*
* oa = <ndarray>PyArray_FROM_OTF(a, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less_equal(oa, 0.0)):
* raise ValueError("a <= 0")
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_a, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_a, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_oa));
- __pyx_v_oa = ((PyArrayObject *)__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_oa = ((PyArrayObject *)__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":2316
+ /* "mtrand.pyx":2342
*
* oa = <ndarray>PyArray_FROM_OTF(a, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oa, 0.0)): # <<<<<<<<<<<<<<
* raise ValueError("a <= 0")
* return cont1_array(self.internal_state, rk_pareto, size, oa)
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(((PyObject *)__pyx_v_oa));
PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_oa));
__Pyx_GIVEREF(((PyObject *)__pyx_v_oa));
- PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 2316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 2342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
+ PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2342; __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_5)); __pyx_t_5 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":2317
+ /* "mtrand.pyx":2343
* oa = <ndarray>PyArray_FROM_OTF(a, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oa, 0.0)):
* raise ValueError("a <= 0") # <<<<<<<<<<<<<<
* return cont1_array(self.internal_state, rk_pareto, size, oa)
*
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_10));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
- __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_Raise(__pyx_t_5, 0, 0);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_68), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":2318
+ /* "mtrand.pyx":2344
* if np.any(np.less_equal(oa, 0.0)):
* raise ValueError("a <= 0")
* return cont1_array(self.internal_state, rk_pareto, size, oa) # <<<<<<<<<<<<<<
@@ -10992,10 +10788,10 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_pareto(PyObject *__pyx_v_self, P
* def weibull(self, a, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_5 = __pyx_f_6mtrand_cont1_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_pareto, __pyx_v_size, __pyx_v_oa); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_r = __pyx_t_5;
- __pyx_t_5 = 0;
+ __pyx_t_2 = __pyx_f_6mtrand_cont1_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_pareto, __pyx_v_size, __pyx_v_oa); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -11009,15 +10805,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_pareto(PyObject *__pyx_v_self, P
__pyx_r = NULL;
__pyx_L0:;
__Pyx_DECREF((PyObject *)__pyx_v_oa);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_a);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":2320
+/* "mtrand.pyx":2346
* return cont1_array(self.internal_state, rk_pareto, size, oa)
*
* def weibull(self, a, size=None): # <<<<<<<<<<<<<<
@@ -11025,9 +10818,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_pareto(PyObject *__pyx_v_self, P
* weibull(a, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_weibull(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_weibull[] = "\n"" weibull(a, size=None)\n""\n"" Weibull distribution.\n""\n"" Draw samples from a 1-parameter Weibull distribution with the given\n"" shape parameter.\n""\n"" .. math:: X = (-ln(U))^{1/a}\n""\n"" Here, U is drawn from the uniform distribution over (0,1].\n""\n"" The more common 2-parameter Weibull, including a scale parameter\n"" :math:`\\lambda` is just :math:`X = \\lambda(-ln(U))^{1/a}`.\n""\n"" The Weibull (or Type III asymptotic extreme value distribution for smallest\n"" values, SEV Type III, or Rosin-Rammler distribution) is one of a class of\n"" Generalized Extreme Value (GEV) distributions used in modeling extreme\n"" value problems. This class includes the Gumbel and Frechet distributions.\n""\n"" Parameters\n"" ----------\n"" a : float\n"" Shape of the distribution.\n"" size : tuple of ints\n"" Output shape. If the given shape is, e.g., ``(m, n, k)``, then\n"" ``m * n * k`` samples are drawn.\n""\n"" See Also\n"" --------\n"" scipy.stats.distributions.weibull : probability density function,\n"" distribution or cumulative density function, etc.\n""\n"" gumbel, scipy.stats.distributions.genextreme\n""\n"" Notes\n"" -----\n"" The probability density for the Weibull distribution is\n""\n"" .. math:: p(x) = \\frac{a}\n"" {\\lambda}(\\frac{x}{\\lambda})^{a-1}e^{-(x/\\lambda)^a},\n""\n"" where :math:`a` is the shape and :math:`\\lambda` the scale.\n""\n"" The function has its peak (the mode) at\n"" :math:`\\lambda(\\frac{a-1}{a})^{1/a}`.\n""\n"" When ``a = 1``, the Weibull distribution reduces to the exponential\n"" distribution.\n""\n"" References\n"" ----------\n"" .. [1] Waloddi Weibull, Professor, Royal Technical University, Stockholm,\n"" 1939 \"A Statistical Theory Of The Strength Of Materials\",\n"" Ingeniorsvetenskapsakademiens Handlingar Nr 151, 1939,\n"" Generalstabens Litografiska Anstalts Forlag, Stockholm.\n"" .. [2] Waloddi Weibull, 1951 \"A Statistical Distribution Function of Wide\n"" Applicability\", Journal Of Applied Mechanics ASME Paper.\n"" .. [3] Wikipedia, \"Weibull distribution\",\n"" http://en.wikipedia.org/wiki/Weibull_distribution\n""\n"" Examples\n"" --------\n"" Draw samples from the distribution:\n""\n"" >>> a = 5. # shape\n"" >>> s = np.random.weibull(a, 1000)\n""\n"" Display the histogram of the samples, along with\n"" the probability density function:\n""\n"" >>> import matplotlib.pyplot as plt\n"" >>> x = np.arange(1,100.)/50.\n"" >>> def weib(x,n,a):\n"" ... return (a / n) * (x / n)**(a - 1) * np.exp(-(x / n)**a)\n""\n"" >>> count, bins, ignored = plt.hist(np.random.weibull(5.,1000))\n"" >>> x = np.arange(1,100.)/50.\n"" >>> scale = count.max()/weib(x, 1., 5.).max()\n"" >>> plt.plot(x, weib(x, 1., 5.)*scale)\n"" >>> plt.show()\n""\n"" ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_weibull(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_31weibull(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_31weibull[] = "\n weibull(a, size=None)\n\n Weibull distribution.\n\n Draw samples from a 1-parameter Weibull distribution with the given\n shape parameter `a`.\n\n .. math:: X = (-ln(U))^{1/a}\n\n Here, U is drawn from the uniform distribution over (0,1].\n\n The more common 2-parameter Weibull, including a scale parameter\n :math:`\\lambda` is just :math:`X = \\lambda(-ln(U))^{1/a}`.\n\n Parameters\n ----------\n a : float\n Shape of the distribution.\n size : tuple of ints\n Output shape. If the given shape is, e.g., ``(m, n, k)``, then\n ``m * n * k`` samples are drawn.\n\n See Also\n --------\n scipy.stats.distributions.weibull : probability density function,\n distribution or cumulative density function, etc.\n\n gumbel, scipy.stats.distributions.genextreme\n\n Notes\n -----\n The Weibull (or Type III asymptotic extreme value distribution for smallest\n values, SEV Type III, or Rosin-Rammler distribution) is one of a class of\n Generalized Extreme Value (GEV) distributions used in modeling extreme\n value problems. This class includes the Gumbel and Frechet distributions.\n\n The probability density for the Weibull distribution is\n\n .. math:: p(x) = \\frac{a}\n {\\lambda}(\\frac{x}{\\lambda})^{a-1}e^{-(x/\\lambda)^a},\n\n where :math:`a` is the shape and :math:`\\lambda` the scale.\n\n The function has its peak (the mode) at\n :math:`\\lambda(\\frac{a-1}{a})^{1/a}`.\n\n When ``a = 1``, the Weibull distribution reduces to the exponential\n distribution.\n\n References\n ----------\n .. [1] Waloddi Weibull, Professor, Royal Technical University, Stockholm,\n 1939 \"A Statistical Theory Of The Strength Of Materials\",\n Ingeniorsvetenskapsakademiens Handlingar"" Nr 151, 1939,\n Generalstabens Litografiska Anstalts Forlag, Stockholm.\n .. [2] Waloddi Weibull, 1951 \"A Statistical Distribution Function of Wide\n Applicability\", Journal Of Applied Mechanics ASME Paper.\n .. [3] Wikipedia, \"Weibull distribution\",\n http://en.wikipedia.org/wiki/Weibull_distribution\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> a = 5. # shape\n >>> s = np.random.weibull(a, 1000)\n\n Display the histogram of the samples, along with\n the probability density function:\n\n >>> import matplotlib.pyplot as plt\n >>> x = np.arange(1,100.)/50.\n >>> def weib(x,n,a):\n ... return (a / n) * (x / n)**(a - 1) * np.exp(-(x / n)**a)\n\n >>> count, bins, ignored = plt.hist(np.random.weibull(5.,1000))\n >>> x = np.arange(1,100.)/50.\n >>> scale = count.max()/weib(x, 1., 5.).max()\n >>> plt.plot(x, weib(x, 1., 5.)*scale)\n >>> plt.show()\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_31weibull(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_a = 0;
PyObject *__pyx_v_size = 0;
PyArrayObject *__pyx_v_oa;
@@ -11056,13 +10849,13 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_weibull(PyObject *__pyx_v_self,
if (likely(values[0])) kw_args--;
else goto __pyx_L5_argtuple_error;
case 1:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[1] = value; kw_args--; }
+ if (value) { values[1] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "weibull") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2320; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "weibull") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2346; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_a = values[0];
__pyx_v_size = values[1];
@@ -11077,17 +10870,15 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_weibull(PyObject *__pyx_v_self,
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("weibull", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2320; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("weibull", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2346; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.weibull");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_a);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_oa = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":2407
+ /* "mtrand.pyx":2433
* cdef double fa
*
* fa = PyFloat_AsDouble(a) # <<<<<<<<<<<<<<
@@ -11096,7 +10887,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_weibull(PyObject *__pyx_v_self,
*/
__pyx_v_fa = PyFloat_AsDouble(__pyx_v_a);
- /* "mtrand.pyx":2408
+ /* "mtrand.pyx":2434
*
* fa = PyFloat_AsDouble(a)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -11106,39 +10897,33 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_weibull(PyObject *__pyx_v_self,
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":2409
+ /* "mtrand.pyx":2435
* fa = PyFloat_AsDouble(a)
* if not PyErr_Occurred():
* if fa <= 0: # <<<<<<<<<<<<<<
* raise ValueError("a <= 0")
* return cont1_array_sc(self.internal_state, rk_weibull, size, fa)
*/
- __pyx_t_1 = (__pyx_v_fa <= 0);
+ __pyx_t_1 = (__pyx_v_fa <= 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":2410
+ /* "mtrand.pyx":2436
* if not PyErr_Occurred():
* if fa <= 0:
* raise ValueError("a <= 0") # <<<<<<<<<<<<<<
* return cont1_array_sc(self.internal_state, rk_weibull, size, fa)
*
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_69), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_10));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":2411
+ /* "mtrand.pyx":2437
* if fa <= 0:
* raise ValueError("a <= 0")
* return cont1_array_sc(self.internal_state, rk_weibull, size, fa) # <<<<<<<<<<<<<<
@@ -11146,16 +10931,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_weibull(PyObject *__pyx_v_self,
* PyErr_Clear()
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = __pyx_f_6mtrand_cont1_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_weibull, __pyx_v_size, __pyx_v_fa); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2411; __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_cont1_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_weibull, __pyx_v_size, __pyx_v_fa); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2437; __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_L6;
}
__pyx_L6:;
- /* "mtrand.pyx":2413
+ /* "mtrand.pyx":2439
* return cont1_array_sc(self.internal_state, rk_weibull, size, fa)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -11164,87 +10949,81 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_weibull(PyObject *__pyx_v_self,
*/
PyErr_Clear();
- /* "mtrand.pyx":2415
+ /* "mtrand.pyx":2441
* PyErr_Clear()
*
* oa = <ndarray>PyArray_FROM_OTF(a, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less_equal(oa, 0.0)):
* raise ValueError("a <= 0")
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_a, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_a, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_oa));
- __pyx_v_oa = ((PyArrayObject *)__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_oa = ((PyArrayObject *)__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":2416
+ /* "mtrand.pyx":2442
*
* oa = <ndarray>PyArray_FROM_OTF(a, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oa, 0.0)): # <<<<<<<<<<<<<<
* raise ValueError("a <= 0")
* return cont1_array(self.internal_state, rk_weibull, size, oa)
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(((PyObject *)__pyx_v_oa));
PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_oa));
__Pyx_GIVEREF(((PyObject *)__pyx_v_oa));
- PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 2416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 2442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
+ PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2442; __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_5)); __pyx_t_5 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":2417
+ /* "mtrand.pyx":2443
* oa = <ndarray>PyArray_FROM_OTF(a, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oa, 0.0)):
* raise ValueError("a <= 0") # <<<<<<<<<<<<<<
* return cont1_array(self.internal_state, rk_weibull, size, oa)
*
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_10));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
- __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_Raise(__pyx_t_5, 0, 0);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_70), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2443; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2443; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":2418
+ /* "mtrand.pyx":2444
* if np.any(np.less_equal(oa, 0.0)):
* raise ValueError("a <= 0")
* return cont1_array(self.internal_state, rk_weibull, size, oa) # <<<<<<<<<<<<<<
@@ -11252,10 +11031,10 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_weibull(PyObject *__pyx_v_self,
* def power(self, a, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_5 = __pyx_f_6mtrand_cont1_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_weibull, __pyx_v_size, __pyx_v_oa); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_r = __pyx_t_5;
- __pyx_t_5 = 0;
+ __pyx_t_2 = __pyx_f_6mtrand_cont1_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_weibull, __pyx_v_size, __pyx_v_oa); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -11269,15 +11048,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_weibull(PyObject *__pyx_v_self,
__pyx_r = NULL;
__pyx_L0:;
__Pyx_DECREF((PyObject *)__pyx_v_oa);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_a);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":2420
+/* "mtrand.pyx":2446
* return cont1_array(self.internal_state, rk_weibull, size, oa)
*
* def power(self, a, size=None): # <<<<<<<<<<<<<<
@@ -11285,9 +11061,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_weibull(PyObject *__pyx_v_self,
* power(a, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_power(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_power[] = "\n"" power(a, size=None)\n""\n"" Draws samples in [0, 1] from a power distribution with positive\n"" exponent a - 1.\n""\n"" Also known as the power function distribution.\n""\n"" Parameters\n"" ----------\n"" a : float\n"" parameter, > 0\n"" size : tuple of ints\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"" The returned samples lie in [0, 1].\n""\n"" Raises\n"" ------\n"" ValueError\n"" If a<1.\n""\n"" Notes\n"" -----\n"" The probability density function is\n""\n"" .. math:: P(x; a) = ax^{a-1}, 0 \\le x \\le 1, a>0.\n""\n"" The power function distribution is just the inverse of the Pareto\n"" distribution. It may also be seen as a special case of the Beta\n"" distribution.\n""\n"" It is used, for example, in modeling the over-reporting of insurance\n"" claims.\n""\n"" References\n"" ----------\n"" .. [1] Christian Kleiber, Samuel Kotz, \"Statistical size distributions\n"" in economics and actuarial sciences\", Wiley, 2003.\n"" .. [2] Heckert, N. A. and Filliben, James J. (2003). NIST Handbook 148:\n"" Dataplot Reference Manual, Volume 2: Let Subcommands and Library\n"" Functions\", National Institute of Standards and Technology Handbook\n"" Series, June 2003.\n"" http://www.itl.nist.gov/div898/software/dataplot/refman2/auxillar/powpdf.pdf\n""\n"" Examples\n"" --------\n"" Draw samples from the distribution:\n""\n"" >>> a = 5. # shape\n"" >>> samples = 1000\n"" >>> s = np.random.power(a, samples)\n""\n"" Display the histogram of the samples, along with\n"" the probability density function:\n""\n"" >>> import matplotlib.pyplot as plt\n"" >>> count, bins, ignored = plt.hist(s, bins=30)\n"" >>> x = np.linspace(0, 1, 100)\n"" >>> y = a*x**(a-1.)\n"" >>> normed_y = samples*np.diff(bins)[0]*y\n"" >>> plt.plot(x, normed_y)\n"" >>> plt.show()\n""\n"" Compare the power function distribution to the inverse of the Pareto.\n""\n"" >>> from scipy import stats\n"" >>> rvs = np.random.power(5, 1000000)\n"" >>> rvsp = np.random.pareto(5, 1000000)\n"" >>> xx = np.linspace(0,1,100)\n"" >>> powpdf = stats.powerlaw.pdf(xx,5)\n""\n"" >>> plt.figure()\n"" >>> plt.hist(rvs, bins=50, normed=True)\n"" >>> plt.plot(xx,powpdf,'r-')\n"" >>> plt.title('np.random.power(5)')\n""\n"" >>> plt.figure()\n"" >>> plt.hist(1./(1.+rvsp), bins=50, normed=True)\n"" >>> plt.plot(xx,powpdf,'r-')\n"" >>> plt.title('inverse of 1 + np.random.pareto(5)')\n""\n"" >>> plt.figure()\n"" >>> plt.hist(1./(1.+rvsp), bins=50, normed=True)\n"" >>> plt.plot(xx,powpdf,'r-')\n"" >>> plt.title('inverse of stats.pareto(5)')\n""\n"" ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_power(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_32power(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_32power[] = "\n power(a, size=None)\n\n Draws samples in [0, 1] from a power distribution with positive\n exponent a - 1.\n\n Also known as the power function distribution.\n\n Parameters\n ----------\n a : float\n parameter, > 0\n size : tuple of ints\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 The returned samples lie in [0, 1].\n\n Raises\n ------\n ValueError\n If a<1.\n\n Notes\n -----\n The probability density function is\n\n .. math:: P(x; a) = ax^{a-1}, 0 \\le x \\le 1, a>0.\n\n The power function distribution is just the inverse of the Pareto\n distribution. It may also be seen as a special case of the Beta\n distribution.\n\n It is used, for example, in modeling the over-reporting of insurance\n claims.\n\n References\n ----------\n .. [1] Christian Kleiber, Samuel Kotz, \"Statistical size distributions\n in economics and actuarial sciences\", Wiley, 2003.\n .. [2] Heckert, N. A. and Filliben, James J. (2003). NIST Handbook 148:\n Dataplot Reference Manual, Volume 2: Let Subcommands and Library\n Functions\", National Institute of Standards and Technology Handbook\n Series, June 2003.\n http://www.itl.nist.gov/div898/software/dataplot/refman2/auxillar/powpdf.pdf\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> a = 5. # shape\n >>> samples = 1000\n >>> s = np.random.power(a, samples)\n\n Display the histogram of the samples, along with\n the probability density function:\n\n >>> import matplotlib.pyplot as plt\n >>> count, bins, ignored = plt.hist(s, bins=""30)\n >>> x = np.linspace(0, 1, 100)\n >>> y = a*x**(a-1.)\n >>> normed_y = samples*np.diff(bins)[0]*y\n >>> plt.plot(x, normed_y)\n >>> plt.show()\n\n Compare the power function distribution to the inverse of the Pareto.\n\n >>> from scipy import stats\n >>> rvs = np.random.power(5, 1000000)\n >>> rvsp = np.random.pareto(5, 1000000)\n >>> xx = np.linspace(0,1,100)\n >>> powpdf = stats.powerlaw.pdf(xx,5)\n\n >>> plt.figure()\n >>> plt.hist(rvs, bins=50, normed=True)\n >>> plt.plot(xx,powpdf,'r-')\n >>> plt.title('np.random.power(5)')\n\n >>> plt.figure()\n >>> plt.hist(1./(1.+rvsp), bins=50, normed=True)\n >>> plt.plot(xx,powpdf,'r-')\n >>> plt.title('inverse of 1 + np.random.pareto(5)')\n\n >>> plt.figure()\n >>> plt.hist(1./(1.+rvsp), bins=50, normed=True)\n >>> plt.plot(xx,powpdf,'r-')\n >>> plt.title('inverse of stats.pareto(5)')\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_32power(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_a = 0;
PyObject *__pyx_v_size = 0;
PyArrayObject *__pyx_v_oa;
@@ -11316,13 +11092,13 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_power(PyObject *__pyx_v_self, Py
if (likely(values[0])) kw_args--;
else goto __pyx_L5_argtuple_error;
case 1:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[1] = value; kw_args--; }
+ if (value) { values[1] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "power") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2420; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "power") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2446; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_a = values[0];
__pyx_v_size = values[1];
@@ -11337,17 +11113,15 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_power(PyObject *__pyx_v_self, Py
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("power", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2420; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("power", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2446; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.power");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_a);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_oa = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":2516
+ /* "mtrand.pyx":2542
* cdef double fa
*
* fa = PyFloat_AsDouble(a) # <<<<<<<<<<<<<<
@@ -11356,7 +11130,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_power(PyObject *__pyx_v_self, Py
*/
__pyx_v_fa = PyFloat_AsDouble(__pyx_v_a);
- /* "mtrand.pyx":2517
+ /* "mtrand.pyx":2543
*
* fa = PyFloat_AsDouble(a)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -11366,39 +11140,33 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_power(PyObject *__pyx_v_self, Py
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":2518
+ /* "mtrand.pyx":2544
* fa = PyFloat_AsDouble(a)
* if not PyErr_Occurred():
* if fa <= 0: # <<<<<<<<<<<<<<
* raise ValueError("a <= 0")
* return cont1_array_sc(self.internal_state, rk_power, size, fa)
*/
- __pyx_t_1 = (__pyx_v_fa <= 0);
+ __pyx_t_1 = (__pyx_v_fa <= 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":2519
+ /* "mtrand.pyx":2545
* if not PyErr_Occurred():
* if fa <= 0:
* raise ValueError("a <= 0") # <<<<<<<<<<<<<<
* return cont1_array_sc(self.internal_state, rk_power, size, fa)
*
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2519; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_71), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2545; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_10));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2519; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2519; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2545; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":2520
+ /* "mtrand.pyx":2546
* if fa <= 0:
* raise ValueError("a <= 0")
* return cont1_array_sc(self.internal_state, rk_power, size, fa) # <<<<<<<<<<<<<<
@@ -11406,16 +11174,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_power(PyObject *__pyx_v_self, Py
* PyErr_Clear()
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = __pyx_f_6mtrand_cont1_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_power, __pyx_v_size, __pyx_v_fa); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2520; __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_cont1_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_power, __pyx_v_size, __pyx_v_fa); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2546; __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_L6;
}
__pyx_L6:;
- /* "mtrand.pyx":2522
+ /* "mtrand.pyx":2548
* return cont1_array_sc(self.internal_state, rk_power, size, fa)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -11424,87 +11192,81 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_power(PyObject *__pyx_v_self, Py
*/
PyErr_Clear();
- /* "mtrand.pyx":2524
+ /* "mtrand.pyx":2550
* PyErr_Clear()
*
* oa = <ndarray>PyArray_FROM_OTF(a, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less_equal(oa, 0.0)):
* raise ValueError("a <= 0")
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_a, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_a, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_oa));
- __pyx_v_oa = ((PyArrayObject *)__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_oa = ((PyArrayObject *)__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":2525
+ /* "mtrand.pyx":2551
*
* oa = <ndarray>PyArray_FROM_OTF(a, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oa, 0.0)): # <<<<<<<<<<<<<<
* raise ValueError("a <= 0")
* return cont1_array(self.internal_state, rk_power, size, oa)
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2551; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2551; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2551; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2551; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2551; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2551; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(((PyObject *)__pyx_v_oa));
PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_oa));
__Pyx_GIVEREF(((PyObject *)__pyx_v_oa));
- PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2551; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 2525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 2551; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
+ PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2551; __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_5)); __pyx_t_5 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2551; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":2526
+ /* "mtrand.pyx":2552
* oa = <ndarray>PyArray_FROM_OTF(a, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oa, 0.0)):
* raise ValueError("a <= 0") # <<<<<<<<<<<<<<
* return cont1_array(self.internal_state, rk_power, size, oa)
*
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_10));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
- __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_Raise(__pyx_t_5, 0, 0);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_72), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2552; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2552; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":2527
+ /* "mtrand.pyx":2553
* if np.any(np.less_equal(oa, 0.0)):
* raise ValueError("a <= 0")
* return cont1_array(self.internal_state, rk_power, size, oa) # <<<<<<<<<<<<<<
@@ -11512,10 +11274,10 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_power(PyObject *__pyx_v_self, Py
* def laplace(self, loc=0.0, scale=1.0, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_5 = __pyx_f_6mtrand_cont1_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_power, __pyx_v_size, __pyx_v_oa); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_r = __pyx_t_5;
- __pyx_t_5 = 0;
+ __pyx_t_2 = __pyx_f_6mtrand_cont1_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_power, __pyx_v_size, __pyx_v_oa); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2553; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -11529,15 +11291,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_power(PyObject *__pyx_v_self, Py
__pyx_r = NULL;
__pyx_L0:;
__Pyx_DECREF((PyObject *)__pyx_v_oa);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_a);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":2529
+/* "mtrand.pyx":2555
* return cont1_array(self.internal_state, rk_power, size, oa)
*
* def laplace(self, loc=0.0, scale=1.0, size=None): # <<<<<<<<<<<<<<
@@ -11545,9 +11304,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_power(PyObject *__pyx_v_self, Py
* laplace(loc=0.0, scale=1.0, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_laplace(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_laplace[] = "\n"" laplace(loc=0.0, scale=1.0, size=None)\n""\n"" Draw samples from the Laplace or double exponential distribution with\n"" specified location (or mean) and scale (decay).\n""\n"" The Laplace distribution is similar to the Gaussian/normal distribution,\n"" but is sharper at the peak and has fatter tails. It represents the\n"" difference between two independent, identically distributed exponential\n"" random variables.\n""\n"" Parameters\n"" ----------\n"" loc : float\n"" The position, :math:`\\mu`, of the distribution peak.\n"" scale : float\n"" :math:`\\lambda`, the exponential decay.\n""\n"" Notes\n"" -----\n"" It has the probability density function\n""\n"" .. math:: f(x; \\mu, \\lambda) = \\frac{1}{2\\lambda}\n"" \\exp\\left(-\\frac{|x - \\mu|}{\\lambda}\\right).\n""\n"" The first law of Laplace, from 1774, states that the frequency of an error\n"" can be expressed as an exponential function of the absolute magnitude of\n"" the error, which leads to the Laplace distribution. For many problems in\n"" Economics and Health sciences, this distribution seems to model the data\n"" better than the standard Gaussian distribution\n""\n""\n"" References\n"" ----------\n"" .. [1] Abramowitz, M. and Stegun, I. A. (Eds.). Handbook of Mathematical\n"" Functions with Formulas, Graphs, and Mathematical Tables, 9th\n"" printing. New York: Dover, 1972.\n""\n"" .. [2] The Laplace distribution and generalizations\n"" By Samuel Kotz, Tomasz J. Kozubowski, Krzysztof Podgorski,\n"" Birkhauser, 2001.\n""\n"" .. [3] Weisstein, Eric W. \"Laplace Distribution.\"\n"" From MathWorld--A Wolfram Web Resource.\n"" http://mathworld.wolfram.com/LaplaceDistribution.html\n""\n"" .. [4] Wikipedia, \"Laplace distribution\",\n"" http://en.wikipedia.org/wiki/Laplace_distribution\n""\n"" Examples\n"" --------\n"" Draw samples from the distribution\n""\n"" >>> loc, scale = 0., 1.\n"" >>> s = np.random.laplace(loc, scale, 1000)\n""\n"" Display the histogram of the samples, along with\n"" the probability density function:\n""\n"" >>> import matplotlib.pyplot as plt\n"" >>> count, bins, ignored = plt.hist(s, 30, normed=True)\n"" >>> x = np.arange(-8., 8., .01)\n"" >>> pdf = np.exp(-abs(x-loc/scale))/(2.*scale)\n"" >>> plt.plot(x, pdf)\n""\n"" Plot Gaussian for comparison:\n""\n"" >>> g = (1/(scale * np.sqrt(2 * np.pi)) * \n"" ... np.exp( - (x - loc)**2 / (2 * scale**2) ))\n"" >>> plt.plot(x,g)\n""\n"" ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_laplace(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_33laplace(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_33laplace[] = "\n laplace(loc=0.0, scale=1.0, size=None)\n\n Draw samples from the Laplace or double exponential distribution with\n specified location (or mean) and scale (decay).\n\n The Laplace distribution is similar to the Gaussian/normal distribution,\n but is sharper at the peak and has fatter tails. It represents the\n difference between two independent, identically distributed exponential\n random variables.\n\n Parameters\n ----------\n loc : float\n The position, :math:`\\mu`, of the distribution peak.\n scale : float\n :math:`\\lambda`, the exponential decay.\n\n Notes\n -----\n It has the probability density function\n\n .. math:: f(x; \\mu, \\lambda) = \\frac{1}{2\\lambda}\n \\exp\\left(-\\frac{|x - \\mu|}{\\lambda}\\right).\n\n The first law of Laplace, from 1774, states that the frequency of an error\n can be expressed as an exponential function of the absolute magnitude of\n the error, which leads to the Laplace distribution. For many problems in\n Economics and Health sciences, this distribution seems to model the data\n better than the standard Gaussian distribution\n\n\n References\n ----------\n .. [1] Abramowitz, M. and Stegun, I. A. (Eds.). Handbook of Mathematical\n Functions with Formulas, Graphs, and Mathematical Tables, 9th\n printing. New York: Dover, 1972.\n\n .. [2] The Laplace distribution and generalizations\n By Samuel Kotz, Tomasz J. Kozubowski, Krzysztof Podgorski,\n Birkhauser, 2001.\n\n .. [3] Weisstein, Eric W. \"Laplace Distribution.\"\n From MathWorld--A Wolfram Web Resource.\n http://mathworld.wolfram.com/LaplaceDistribution.html\n\n .. [4] Wikipedia, \"Laplace distribution\",\n http://en.wikipedia.org/wik""i/Laplace_distribution\n\n Examples\n --------\n Draw samples from the distribution\n\n >>> loc, scale = 0., 1.\n >>> s = np.random.laplace(loc, scale, 1000)\n\n Display the histogram of the samples, along with\n the probability density function:\n\n >>> import matplotlib.pyplot as plt\n >>> count, bins, ignored = plt.hist(s, 30, normed=True)\n >>> x = np.arange(-8., 8., .01)\n >>> pdf = np.exp(-abs(x-loc/scale))/(2.*scale)\n >>> plt.plot(x, pdf)\n\n Plot Gaussian for comparison:\n\n >>> g = (1/(scale * np.sqrt(2 * np.pi)) * \n ... np.exp( - (x - loc)**2 / (2 * scale**2) ))\n >>> plt.plot(x,g)\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_33laplace(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_loc = 0;
PyObject *__pyx_v_scale = 0;
PyObject *__pyx_v_size = 0;
@@ -11566,8 +11325,8 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_laplace(PyObject *__pyx_v_self,
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
PyObject* values[3] = {0,0,0};
- values[0] = __pyx_k_23;
- values[1] = __pyx_k_24;
+ values[0] = __pyx_k_73;
+ values[1] = __pyx_k_74;
values[2] = ((PyObject *)Py_None);
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
@@ -11578,30 +11337,30 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_laplace(PyObject *__pyx_v_self,
}
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 0:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__loc);
- if (unlikely(value)) { values[0] = value; kw_args--; }
+ if (value) { values[0] = value; kw_args--; }
}
case 1:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__scale);
- if (unlikely(value)) { values[1] = value; kw_args--; }
+ if (value) { values[1] = value; kw_args--; }
}
case 2:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[2] = value; kw_args--; }
+ if (value) { values[2] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "laplace") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2529; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "laplace") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2555; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_loc = values[0];
__pyx_v_scale = values[1];
__pyx_v_size = values[2];
} else {
- __pyx_v_loc = __pyx_k_23;
- __pyx_v_scale = __pyx_k_24;
+ __pyx_v_loc = __pyx_k_73;
+ __pyx_v_scale = __pyx_k_74;
__pyx_v_size = ((PyObject *)Py_None);
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 3: __pyx_v_size = PyTuple_GET_ITEM(__pyx_args, 2);
@@ -11613,19 +11372,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_laplace(PyObject *__pyx_v_self,
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("laplace", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2529; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("laplace", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2555; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.laplace");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_loc);
- __Pyx_INCREF(__pyx_v_scale);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_oloc = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_oscale = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":2605
+ /* "mtrand.pyx":2631
* cdef double floc, fscale
*
* floc = PyFloat_AsDouble(loc) # <<<<<<<<<<<<<<
@@ -11634,7 +11390,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_laplace(PyObject *__pyx_v_self,
*/
__pyx_v_floc = PyFloat_AsDouble(__pyx_v_loc);
- /* "mtrand.pyx":2606
+ /* "mtrand.pyx":2632
*
* floc = PyFloat_AsDouble(loc)
* fscale = PyFloat_AsDouble(scale) # <<<<<<<<<<<<<<
@@ -11643,7 +11399,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_laplace(PyObject *__pyx_v_self,
*/
__pyx_v_fscale = PyFloat_AsDouble(__pyx_v_scale);
- /* "mtrand.pyx":2607
+ /* "mtrand.pyx":2633
* floc = PyFloat_AsDouble(loc)
* fscale = PyFloat_AsDouble(scale)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -11653,39 +11409,33 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_laplace(PyObject *__pyx_v_self,
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":2608
+ /* "mtrand.pyx":2634
* fscale = PyFloat_AsDouble(scale)
* if not PyErr_Occurred():
* if fscale <= 0: # <<<<<<<<<<<<<<
* raise ValueError("scale <= 0")
* return cont2_array_sc(self.internal_state, rk_laplace, size, floc, fscale)
*/
- __pyx_t_1 = (__pyx_v_fscale <= 0);
+ __pyx_t_1 = (__pyx_v_fscale <= 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":2609
+ /* "mtrand.pyx":2635
* if not PyErr_Occurred():
* if fscale <= 0:
* raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
* return cont2_array_sc(self.internal_state, rk_laplace, size, floc, fscale)
*
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2609; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_75), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2635; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_9));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_9));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_9));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2609; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2609; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2635; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":2610
+ /* "mtrand.pyx":2636
* if fscale <= 0:
* raise ValueError("scale <= 0")
* return cont2_array_sc(self.internal_state, rk_laplace, size, floc, fscale) # <<<<<<<<<<<<<<
@@ -11693,16 +11443,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_laplace(PyObject *__pyx_v_self,
* PyErr_Clear()
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = __pyx_f_6mtrand_cont2_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_laplace, __pyx_v_size, __pyx_v_floc, __pyx_v_fscale); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __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_cont2_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_laplace, __pyx_v_size, __pyx_v_floc, __pyx_v_fscale); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2636; __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_L6;
}
__pyx_L6:;
- /* "mtrand.pyx":2612
+ /* "mtrand.pyx":2638
* return cont2_array_sc(self.internal_state, rk_laplace, size, floc, fscale)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -11711,101 +11461,95 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_laplace(PyObject *__pyx_v_self,
*/
PyErr_Clear();
- /* "mtrand.pyx":2613
+ /* "mtrand.pyx":2639
*
* PyErr_Clear()
* oloc = PyArray_FROM_OTF(loc, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* oscale = PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oscale, 0.0)):
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_loc, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_6mtrand_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_loc, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_6mtrand_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(((PyObject *)__pyx_v_oloc));
- __pyx_v_oloc = ((PyArrayObject *)__pyx_t_3);
- __pyx_t_3 = 0;
+ __pyx_v_oloc = ((PyArrayObject *)__pyx_t_2);
+ __pyx_t_2 = 0;
- /* "mtrand.pyx":2614
+ /* "mtrand.pyx":2640
* PyErr_Clear()
* oloc = PyArray_FROM_OTF(loc, NPY_DOUBLE, NPY_ALIGNED)
* oscale = PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less_equal(oscale, 0.0)):
* raise ValueError("scale <= 0")
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_scale, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2614; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_6mtrand_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2614; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_scale, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_6mtrand_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(((PyObject *)__pyx_v_oscale));
- __pyx_v_oscale = ((PyArrayObject *)__pyx_t_3);
- __pyx_t_3 = 0;
+ __pyx_v_oscale = ((PyArrayObject *)__pyx_t_2);
+ __pyx_t_2 = 0;
- /* "mtrand.pyx":2615
+ /* "mtrand.pyx":2641
* oloc = PyArray_FROM_OTF(loc, NPY_DOUBLE, NPY_ALIGNED)
* oscale = PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oscale, 0.0)): # <<<<<<<<<<<<<<
* raise ValueError("scale <= 0")
* return cont2_array(self.internal_state, rk_laplace, size, oloc, oscale)
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(((PyObject *)__pyx_v_oscale));
PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_oscale));
__Pyx_GIVEREF(((PyObject *)__pyx_v_oscale));
- PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 2615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 2641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
+ PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2641; __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_5)); __pyx_t_5 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":2616
+ /* "mtrand.pyx":2642
* oscale = PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oscale, 0.0)):
* raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
* return cont2_array(self.internal_state, rk_laplace, size, oloc, oscale)
*
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2616; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_9));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_9));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_9));
- __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2616; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_Raise(__pyx_t_5, 0, 0);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2616; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_76), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":2617
+ /* "mtrand.pyx":2643
* if np.any(np.less_equal(oscale, 0.0)):
* raise ValueError("scale <= 0")
* return cont2_array(self.internal_state, rk_laplace, size, oloc, oscale) # <<<<<<<<<<<<<<
@@ -11813,10 +11557,10 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_laplace(PyObject *__pyx_v_self,
* def gumbel(self, loc=0.0, scale=1.0, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_5 = __pyx_f_6mtrand_cont2_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_laplace, __pyx_v_size, __pyx_v_oloc, __pyx_v_oscale); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2617; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_r = __pyx_t_5;
- __pyx_t_5 = 0;
+ __pyx_t_2 = __pyx_f_6mtrand_cont2_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_laplace, __pyx_v_size, __pyx_v_oloc, __pyx_v_oscale); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2643; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -11831,16 +11575,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_laplace(PyObject *__pyx_v_self,
__pyx_L0:;
__Pyx_DECREF((PyObject *)__pyx_v_oloc);
__Pyx_DECREF((PyObject *)__pyx_v_oscale);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_loc);
- __Pyx_DECREF(__pyx_v_scale);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":2619
+/* "mtrand.pyx":2645
* return cont2_array(self.internal_state, rk_laplace, size, oloc, oscale)
*
* def gumbel(self, loc=0.0, scale=1.0, size=None): # <<<<<<<<<<<<<<
@@ -11848,9 +11588,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_laplace(PyObject *__pyx_v_self,
* gumbel(loc=0.0, scale=1.0, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_gumbel(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_gumbel[] = "\n"" gumbel(loc=0.0, scale=1.0, size=None)\n""\n"" Gumbel distribution.\n""\n"" Draw samples from a Gumbel distribution with specified location (or mean)\n"" and scale (or standard deviation).\n""\n"" The Gumbel (or Smallest Extreme Value (SEV) or the Smallest Extreme Value\n"" Type I) distribution is one of a class of Generalized Extreme Value (GEV)\n"" distributions used in modeling extreme value problems. The Gumbel is a\n"" special case of the Extreme Value Type I distribution for maximums from\n"" distributions with \"exponential-like\" tails, it may be derived by\n"" considering a Gaussian process of measurements, and generating the pdf for\n"" the maximum values from that set of measurements (see examples).\n""\n"" Parameters\n"" ----------\n"" loc : float\n"" The location of the mode of the distribution.\n"" scale : float\n"" The scale parameter of the distribution.\n"" size : tuple of ints\n"" Output shape. If the given shape is, e.g., ``(m, n, k)``, then\n"" ``m * n * k`` samples are drawn.\n""\n"" See Also\n"" --------\n"" scipy.stats.gumbel : probability density function,\n"" distribution or cumulative density function, etc.\n"" weibull, scipy.stats.genextreme\n""\n"" Notes\n"" -----\n"" The probability density for the Gumbel distribution is\n""\n"" .. math:: p(x) = \\frac{e^{-(x - \\mu)/ \\beta}}{\\beta} e^{ -e^{-(x - \\mu)/\n"" \\beta}},\n""\n"" where :math:`\\mu` is the mode, a location parameter, and :math:`\\beta`\n"" is the scale parameter.\n""\n"" The Gumbel (named for German mathematician Emil Julius Gumbel) was used\n"" very early in the hydrology literature, for modeling the occurrence of\n"" flood events. It is also used for modeling maximum wind speed and rainfall\n"" rates. It is a \"fat-tailed\" distribution - the probability of an event in\n"" the tail of the distribution is larger than if one used a Gaussian, hence\n"" the surprisingly frequent occurrence of 100-year floods. Floods were\n"" initially modeled as a Gaussian process, which underestimated the frequency\n"" of extreme events.\n""\n"" It is one of a class of extreme value distributions, the Generalized\n"" Extreme Value (GEV) distributions, which also includes the Weibull and\n"" Frechet.\n""\n"" The function has a mean of :math:`\\mu + 0.57721\\beta` and a variance of\n"" :math:`\\frac{\\pi^2}{6}\\beta^2`.\n""\n"" References\n"" ----------\n"" .. [1] Gumbel, E.J. (1958). Statistics of Extremes. Columbia University\n"" Press.\n"" .. [2] Reiss, R.-D. and Thomas M. (2001), Statistical Analysis of Extreme\n"" Values, from Insurance, Finance, Hydrology and Other Fields,\n"" Birkhauser Verlag, Basel: Boston : Berlin.\n"" .. [3] Wikipedia, \"Gumbel distribution\",\n"" http://en.wikipedia.org/wiki/Gumbel_distribution\n""\n"" Examples\n"" --------\n"" Draw samples from the distribution:\n""\n"" >>> mu, beta = 0, 0.1 # location and scale\n"" >>> s = np.random.gumbel(mu, beta, 1000)\n""\n"" Display the histogram of the samples, along with\n"" the probability density function:\n""\n"" >>> import matplotlib.pyplot as plt\n"" >>> count, bins, ignored = plt.hist(s, 30, normed=True)\n"" >>> plt.plot(bins, (1/beta)*np.exp(-(bins - mu)/beta)\n"" ... * np.exp( -np.exp( -(bins - mu) /beta) ),\n"" ... linewidth=2, color='r')\n"" >>> plt.show()\n""\n"" Show how an extreme value distribution can arise from a Gaussian process\n"" and compare to a Gaussian:\n""\n"" >>> means = []\n"" >>> maxima = []\n"" >>> for i in range(0,1000) :\n"" ... a = np.random.normal(mu, beta, 1000)\n"" ... means.append(a.mean())\n"" ... maxima.append(a.max())\n"" >>> count, bins, ignored = plt.hist(maxima, 30, normed=True)\n"" >>> beta = np.std(maxima)*np.pi/np.sqrt(6)\n"" >>> mu = np.mean(maxima) - 0.57721*beta\n"" >>> plt.plot(bins, (1/beta)*np.exp(-(bins - mu)/beta)\n"" ... * np.exp(-np.exp(-(bins - mu)/beta)),\n"" ... linewidth=2, color='r')\n"" >>> plt.plot(bins, 1/(beta * np.sqrt(2 * np.pi))\n"" ... * np.exp(-(bins - mu)**2 / (2 * beta**2)),\n"" ... linewidth=2, color='g')\n"" >>> plt.show()\n""\n"" ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_gumbel(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_34gumbel(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_34gumbel[] = "\n gumbel(loc=0.0, scale=1.0, size=None)\n\n Gumbel distribution.\n\n Draw samples from a Gumbel distribution with specified location and scale.\n For more information on the Gumbel distribution, see Notes and References\n below.\n\n Parameters\n ----------\n loc : float\n The location of the mode of the distribution.\n scale : float\n The scale parameter of the distribution.\n size : tuple of ints\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 out : ndarray\n The samples\n\n See Also\n --------\n scipy.stats.gumbel_l\n scipy.stats.gumbel_r\n scipy.stats.genextreme\n probability density function, distribution, or cumulative density\n function, etc. for each of the above\n weibull\n\n Notes\n -----\n The Gumbel (or Smallest Extreme Value (SEV) or the Smallest Extreme Value\n Type I) distribution is one of a class of Generalized Extreme Value (GEV)\n distributions used in modeling extreme value problems. The Gumbel is a\n special case of the Extreme Value Type I distribution for maximums from\n distributions with \"exponential-like\" tails.\n\n The probability density for the Gumbel distribution is\n\n .. math:: p(x) = \\frac{e^{-(x - \\mu)/ \\beta}}{\\beta} e^{ -e^{-(x - \\mu)/\n \\beta}},\n\n where :math:`\\mu` is the mode, a location parameter, and :math:`\\beta` is\n the scale parameter.\n\n The Gumbel (named for German mathematician Emil Julius Gumbel) was used\n very early in the hydrology literature, for modeling the occurrence of\n flood events. It is also used for modeling maximum wind speed and rainfall\n rates. It is a \"fat-tailed\" distribution - the ""probability of an event in\n the tail of the distribution is larger than if one used a Gaussian, hence\n the surprisingly frequent occurrence of 100-year floods. Floods were\n initially modeled as a Gaussian process, which underestimated the frequency\n of extreme events.\n\n\n It is one of a class of extreme value distributions, the Generalized\n Extreme Value (GEV) distributions, which also includes the Weibull and\n Frechet.\n\n The function has a mean of :math:`\\mu + 0.57721\\beta` and a variance of\n :math:`\\frac{\\pi^2}{6}\\beta^2`.\n\n References\n ----------\n Gumbel, E. J., *Statistics of Extremes*, New York: Columbia University\n Press, 1958.\n\n Reiss, R.-D. and Thomas, M., *Statistical Analysis of Extreme Values from\n Insurance, Finance, Hydrology and Other Fields*, Basel: Birkhauser Verlag,\n 2001.\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> mu, beta = 0, 0.1 # location and scale\n >>> s = np.random.gumbel(mu, beta, 1000)\n\n Display the histogram of the samples, along with\n the probability density function:\n\n >>> import matplotlib.pyplot as plt\n >>> count, bins, ignored = plt.hist(s, 30, normed=True)\n >>> plt.plot(bins, (1/beta)*np.exp(-(bins - mu)/beta)\n ... * np.exp( -np.exp( -(bins - mu) /beta) ),\n ... linewidth=2, color='r')\n >>> plt.show()\n\n Show how an extreme value distribution can arise from a Gaussian process\n and compare to a Gaussian:\n\n >>> means = []\n >>> maxima = []\n >>> for i in range(0,1000) :\n ... a = np.random.normal(mu, beta, 1000)\n ... means.append(a.mean())\n ... maxima.append(a.max())\n >>> count, bins, ignored = plt.hist(maxima, 30, normed=True)\n >>> beta = np.std(maxima)*np.pi/np.sqrt(6)""\n >>> mu = np.mean(maxima) - 0.57721*beta\n >>> plt.plot(bins, (1/beta)*np.exp(-(bins - mu)/beta)\n ... * np.exp(-np.exp(-(bins - mu)/beta)),\n ... linewidth=2, color='r')\n >>> plt.plot(bins, 1/(beta * np.sqrt(2 * np.pi))\n ... * np.exp(-(bins - mu)**2 / (2 * beta**2)),\n ... linewidth=2, color='g')\n >>> plt.show()\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_34gumbel(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_loc = 0;
PyObject *__pyx_v_scale = 0;
PyObject *__pyx_v_size = 0;
@@ -11869,8 +11609,8 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_gumbel(PyObject *__pyx_v_self, P
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
PyObject* values[3] = {0,0,0};
- values[0] = __pyx_k_25;
- values[1] = __pyx_k_26;
+ values[0] = __pyx_k_77;
+ values[1] = __pyx_k_78;
values[2] = ((PyObject *)Py_None);
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
@@ -11881,30 +11621,30 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_gumbel(PyObject *__pyx_v_self, P
}
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 0:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__loc);
- if (unlikely(value)) { values[0] = value; kw_args--; }
+ if (value) { values[0] = value; kw_args--; }
}
case 1:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__scale);
- if (unlikely(value)) { values[1] = value; kw_args--; }
+ if (value) { values[1] = value; kw_args--; }
}
case 2:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[2] = value; kw_args--; }
+ if (value) { values[2] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "gumbel") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2619; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "gumbel") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2645; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_loc = values[0];
__pyx_v_scale = values[1];
__pyx_v_size = values[2];
} else {
- __pyx_v_loc = __pyx_k_25;
- __pyx_v_scale = __pyx_k_26;
+ __pyx_v_loc = __pyx_k_77;
+ __pyx_v_scale = __pyx_k_78;
__pyx_v_size = ((PyObject *)Py_None);
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 3: __pyx_v_size = PyTuple_GET_ITEM(__pyx_args, 2);
@@ -11916,19 +11656,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_gumbel(PyObject *__pyx_v_self, P
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("gumbel", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2619; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("gumbel", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2645; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.gumbel");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_loc);
- __Pyx_INCREF(__pyx_v_scale);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_oloc = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_oscale = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":2729
+ /* "mtrand.pyx":2762
* cdef double floc, fscale
*
* floc = PyFloat_AsDouble(loc) # <<<<<<<<<<<<<<
@@ -11937,7 +11674,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_gumbel(PyObject *__pyx_v_self, P
*/
__pyx_v_floc = PyFloat_AsDouble(__pyx_v_loc);
- /* "mtrand.pyx":2730
+ /* "mtrand.pyx":2763
*
* floc = PyFloat_AsDouble(loc)
* fscale = PyFloat_AsDouble(scale) # <<<<<<<<<<<<<<
@@ -11946,7 +11683,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_gumbel(PyObject *__pyx_v_self, P
*/
__pyx_v_fscale = PyFloat_AsDouble(__pyx_v_scale);
- /* "mtrand.pyx":2731
+ /* "mtrand.pyx":2764
* floc = PyFloat_AsDouble(loc)
* fscale = PyFloat_AsDouble(scale)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -11956,39 +11693,33 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_gumbel(PyObject *__pyx_v_self, P
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":2732
+ /* "mtrand.pyx":2765
* fscale = PyFloat_AsDouble(scale)
* if not PyErr_Occurred():
* if fscale <= 0: # <<<<<<<<<<<<<<
* raise ValueError("scale <= 0")
* return cont2_array_sc(self.internal_state, rk_gumbel, size, floc, fscale)
*/
- __pyx_t_1 = (__pyx_v_fscale <= 0);
+ __pyx_t_1 = (__pyx_v_fscale <= 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":2733
+ /* "mtrand.pyx":2766
* if not PyErr_Occurred():
* if fscale <= 0:
* raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
* return cont2_array_sc(self.internal_state, rk_gumbel, size, floc, fscale)
*
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_79), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_9));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_9));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_9));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":2734
+ /* "mtrand.pyx":2767
* if fscale <= 0:
* raise ValueError("scale <= 0")
* return cont2_array_sc(self.internal_state, rk_gumbel, size, floc, fscale) # <<<<<<<<<<<<<<
@@ -11996,16 +11727,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_gumbel(PyObject *__pyx_v_self, P
* PyErr_Clear()
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = __pyx_f_6mtrand_cont2_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_gumbel, __pyx_v_size, __pyx_v_floc, __pyx_v_fscale); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2734; __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_cont2_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_gumbel, __pyx_v_size, __pyx_v_floc, __pyx_v_fscale); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2767; __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_L6;
}
__pyx_L6:;
- /* "mtrand.pyx":2736
+ /* "mtrand.pyx":2769
* return cont2_array_sc(self.internal_state, rk_gumbel, size, floc, fscale)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -12014,101 +11745,95 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_gumbel(PyObject *__pyx_v_self, P
*/
PyErr_Clear();
- /* "mtrand.pyx":2737
+ /* "mtrand.pyx":2770
*
* PyErr_Clear()
* oloc = PyArray_FROM_OTF(loc, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* oscale = PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oscale, 0.0)):
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_loc, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_6mtrand_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_loc, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2770; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_6mtrand_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2770; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(((PyObject *)__pyx_v_oloc));
- __pyx_v_oloc = ((PyArrayObject *)__pyx_t_3);
- __pyx_t_3 = 0;
+ __pyx_v_oloc = ((PyArrayObject *)__pyx_t_2);
+ __pyx_t_2 = 0;
- /* "mtrand.pyx":2738
+ /* "mtrand.pyx":2771
* PyErr_Clear()
* oloc = PyArray_FROM_OTF(loc, NPY_DOUBLE, NPY_ALIGNED)
* oscale = PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less_equal(oscale, 0.0)):
* raise ValueError("scale <= 0")
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_scale, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_6mtrand_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_scale, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_6mtrand_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(((PyObject *)__pyx_v_oscale));
- __pyx_v_oscale = ((PyArrayObject *)__pyx_t_3);
- __pyx_t_3 = 0;
+ __pyx_v_oscale = ((PyArrayObject *)__pyx_t_2);
+ __pyx_t_2 = 0;
- /* "mtrand.pyx":2739
+ /* "mtrand.pyx":2772
* oloc = PyArray_FROM_OTF(loc, NPY_DOUBLE, NPY_ALIGNED)
* oscale = PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oscale, 0.0)): # <<<<<<<<<<<<<<
* raise ValueError("scale <= 0")
* return cont2_array(self.internal_state, rk_gumbel, size, oloc, oscale)
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(((PyObject *)__pyx_v_oscale));
PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_oscale));
__Pyx_GIVEREF(((PyObject *)__pyx_v_oscale));
- PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 2739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 2772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
+ PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2772; __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_5)); __pyx_t_5 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":2740
+ /* "mtrand.pyx":2773
* oscale = PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oscale, 0.0)):
* raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
* return cont2_array(self.internal_state, rk_gumbel, size, oloc, oscale)
*
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_9));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_9));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_9));
- __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_Raise(__pyx_t_5, 0, 0);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_80), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":2741
+ /* "mtrand.pyx":2774
* if np.any(np.less_equal(oscale, 0.0)):
* raise ValueError("scale <= 0")
* return cont2_array(self.internal_state, rk_gumbel, size, oloc, oscale) # <<<<<<<<<<<<<<
@@ -12116,10 +11841,10 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_gumbel(PyObject *__pyx_v_self, P
* def logistic(self, loc=0.0, scale=1.0, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_5 = __pyx_f_6mtrand_cont2_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_gumbel, __pyx_v_size, __pyx_v_oloc, __pyx_v_oscale); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_r = __pyx_t_5;
- __pyx_t_5 = 0;
+ __pyx_t_2 = __pyx_f_6mtrand_cont2_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_gumbel, __pyx_v_size, __pyx_v_oloc, __pyx_v_oscale); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2774; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -12134,16 +11859,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_gumbel(PyObject *__pyx_v_self, P
__pyx_L0:;
__Pyx_DECREF((PyObject *)__pyx_v_oloc);
__Pyx_DECREF((PyObject *)__pyx_v_oscale);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_loc);
- __Pyx_DECREF(__pyx_v_scale);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":2743
+/* "mtrand.pyx":2776
* return cont2_array(self.internal_state, rk_gumbel, size, oloc, oscale)
*
* def logistic(self, loc=0.0, scale=1.0, size=None): # <<<<<<<<<<<<<<
@@ -12151,9 +11872,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_gumbel(PyObject *__pyx_v_self, P
* logistic(loc=0.0, scale=1.0, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_logistic(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_logistic[] = "\n"" logistic(loc=0.0, scale=1.0, size=None)\n""\n"" Draw samples from a Logistic distribution.\n""\n"" Samples are drawn from a Logistic distribution with specified\n"" parameters, loc (location or mean, also median), and scale (>0).\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.logistic : probability density function,\n"" distribution or cumulative density function, etc.\n""\n"" Notes\n"" -----\n"" The probability density for the Logistic distribution is\n""\n"" .. math:: P(x) = P(x) = \\frac{e^{-(x-\\mu)/s}}{s(1+e^{-(x-\\mu)/s})^2},\n""\n"" where :math:`\\mu` = location and :math:`s` = scale.\n""\n"" The Logistic distribution is used in Extreme Value problems where it\n"" can act as a mixture of Gumbel distributions, in Epidemiology, and by\n"" the World Chess Federation (FIDE) where it is used in the Elo ranking\n"" system, assuming the performance of each player is a logistically\n"" distributed random variable.\n""\n"" References\n"" ----------\n"" .. [1] Reiss, R.-D. and Thomas M. (2001), Statistical Analysis of Extreme\n"" Values, from Insurance, Finance, Hydrology and Other Fields,\n"" Birkhauser Verlag, Basel, pp 132-133.\n"" .. [2] Weisstein, Eric W. \"Logistic Distribution.\" From\n"" MathWorld--A Wolfram Web Resource.\n"" http://mathworld.wolfram.com/LogisticDistribution.html\n"" .. [3] Wikipedia, \"Logistic-distribution\",\n"" http://en.wikipedia.org/wiki/Logistic-distribution\n""\n"" Examples\n"" --------\n"" Draw samples from the distribution:\n""\n"" >>> loc, scale = 10, 1\n"" >>> s = np.random.logistic(loc, scale, 10000)\n"" >>> count, bins, ignored = plt.hist(s, bins=50)\n""\n"" # plot against distribution\n""\n"" >>> def logist(x, loc, scale):\n"" ... return exp((loc-x)/scale)/(scale*(1+exp((loc-x)/scale))**2)\n"" >>> plt.plot(bins, logist(bins, loc, scale)*count.max()/\\\n"" ... logist(bins, loc, scale).max())\n"" >>> plt.show()\n""\n"" ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_logistic(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_35logistic(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_35logistic[] = "\n logistic(loc=0.0, scale=1.0, size=None)\n\n Draw samples from a Logistic distribution.\n\n Samples are drawn from a Logistic distribution with specified\n parameters, loc (location or mean, also median), and scale (>0).\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.logistic : probability density function,\n distribution or cumulative density function, etc.\n\n Notes\n -----\n The probability density for the Logistic distribution is\n\n .. math:: P(x) = P(x) = \\frac{e^{-(x-\\mu)/s}}{s(1+e^{-(x-\\mu)/s})^2},\n\n where :math:`\\mu` = location and :math:`s` = scale.\n\n The Logistic distribution is used in Extreme Value problems where it\n can act as a mixture of Gumbel distributions, in Epidemiology, and by\n the World Chess Federation (FIDE) where it is used in the Elo ranking\n system, assuming the performance of each player is a logistically\n distributed random variable.\n\n References\n ----------\n .. [1] Reiss, R.-D. and Thomas M. (2001), Statistical Analysis of Extreme\n Values, from Insurance, Finance, Hydrology and Other Fields,\n Birkhauser Verlag, Basel, pp 132-133.\n .. [2] Weisstein, Eric W. \"Logistic Distribution.\" From\n MathWorld--A Wolfram Web Resource.\n http://mathworld.wolfram.com/LogisticDistribution.html\n .. [3] Wikipedia, \"Logistic-distribution\",\n http://en.wikipedia.org/wiki/Logistic-distribution\n\n Examples\n "" --------\n Draw samples from the distribution:\n\n >>> loc, scale = 10, 1\n >>> s = np.random.logistic(loc, scale, 10000)\n >>> count, bins, ignored = plt.hist(s, bins=50)\n\n # plot against distribution\n\n >>> def logist(x, loc, scale):\n ... return exp((loc-x)/scale)/(scale*(1+exp((loc-x)/scale))**2)\n >>> plt.plot(bins, logist(bins, loc, scale)*count.max()/\\\n ... logist(bins, loc, scale).max())\n >>> plt.show()\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_35logistic(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_loc = 0;
PyObject *__pyx_v_scale = 0;
PyObject *__pyx_v_size = 0;
@@ -12172,8 +11893,8 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_logistic(PyObject *__pyx_v_self,
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
PyObject* values[3] = {0,0,0};
- values[0] = __pyx_k_27;
- values[1] = __pyx_k_28;
+ values[0] = __pyx_k_81;
+ values[1] = __pyx_k_82;
values[2] = ((PyObject *)Py_None);
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
@@ -12184,30 +11905,30 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_logistic(PyObject *__pyx_v_self,
}
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 0:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__loc);
- if (unlikely(value)) { values[0] = value; kw_args--; }
+ if (value) { values[0] = value; kw_args--; }
}
case 1:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__scale);
- if (unlikely(value)) { values[1] = value; kw_args--; }
+ if (value) { values[1] = value; kw_args--; }
}
case 2:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[2] = value; kw_args--; }
+ if (value) { values[2] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "logistic") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2743; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "logistic") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2776; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_loc = values[0];
__pyx_v_scale = values[1];
__pyx_v_size = values[2];
} else {
- __pyx_v_loc = __pyx_k_27;
- __pyx_v_scale = __pyx_k_28;
+ __pyx_v_loc = __pyx_k_81;
+ __pyx_v_scale = __pyx_k_82;
__pyx_v_size = ((PyObject *)Py_None);
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 3: __pyx_v_size = PyTuple_GET_ITEM(__pyx_args, 2);
@@ -12219,19 +11940,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_logistic(PyObject *__pyx_v_self,
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("logistic", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2743; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("logistic", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2776; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.logistic");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_loc);
- __Pyx_INCREF(__pyx_v_scale);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_oloc = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_oscale = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":2817
+ /* "mtrand.pyx":2850
* cdef double floc, fscale
*
* floc = PyFloat_AsDouble(loc) # <<<<<<<<<<<<<<
@@ -12240,7 +11958,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_logistic(PyObject *__pyx_v_self,
*/
__pyx_v_floc = PyFloat_AsDouble(__pyx_v_loc);
- /* "mtrand.pyx":2818
+ /* "mtrand.pyx":2851
*
* floc = PyFloat_AsDouble(loc)
* fscale = PyFloat_AsDouble(scale) # <<<<<<<<<<<<<<
@@ -12249,7 +11967,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_logistic(PyObject *__pyx_v_self,
*/
__pyx_v_fscale = PyFloat_AsDouble(__pyx_v_scale);
- /* "mtrand.pyx":2819
+ /* "mtrand.pyx":2852
* floc = PyFloat_AsDouble(loc)
* fscale = PyFloat_AsDouble(scale)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -12259,39 +11977,33 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_logistic(PyObject *__pyx_v_self,
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":2820
+ /* "mtrand.pyx":2853
* fscale = PyFloat_AsDouble(scale)
* if not PyErr_Occurred():
* if fscale <= 0: # <<<<<<<<<<<<<<
* raise ValueError("scale <= 0")
* return cont2_array_sc(self.internal_state, rk_logistic, size, floc, fscale)
*/
- __pyx_t_1 = (__pyx_v_fscale <= 0);
+ __pyx_t_1 = (__pyx_v_fscale <= 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":2821
+ /* "mtrand.pyx":2854
* if not PyErr_Occurred():
* if fscale <= 0:
* raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
* return cont2_array_sc(self.internal_state, rk_logistic, size, floc, fscale)
*
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2821; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_83), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_9));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_9));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_9));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2821; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2821; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":2822
+ /* "mtrand.pyx":2855
* if fscale <= 0:
* raise ValueError("scale <= 0")
* return cont2_array_sc(self.internal_state, rk_logistic, size, floc, fscale) # <<<<<<<<<<<<<<
@@ -12299,16 +12011,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_logistic(PyObject *__pyx_v_self,
* PyErr_Clear()
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = __pyx_f_6mtrand_cont2_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_logistic, __pyx_v_size, __pyx_v_floc, __pyx_v_fscale); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2822; __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_cont2_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_logistic, __pyx_v_size, __pyx_v_floc, __pyx_v_fscale); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2855; __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_L6;
}
__pyx_L6:;
- /* "mtrand.pyx":2824
+ /* "mtrand.pyx":2857
* return cont2_array_sc(self.internal_state, rk_logistic, size, floc, fscale)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -12317,101 +12029,95 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_logistic(PyObject *__pyx_v_self,
*/
PyErr_Clear();
- /* "mtrand.pyx":2825
+ /* "mtrand.pyx":2858
*
* PyErr_Clear()
* oloc = PyArray_FROM_OTF(loc, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* oscale = PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oscale, 0.0)):
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_loc, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_6mtrand_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_loc, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2858; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_6mtrand_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2858; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(((PyObject *)__pyx_v_oloc));
- __pyx_v_oloc = ((PyArrayObject *)__pyx_t_3);
- __pyx_t_3 = 0;
+ __pyx_v_oloc = ((PyArrayObject *)__pyx_t_2);
+ __pyx_t_2 = 0;
- /* "mtrand.pyx":2826
+ /* "mtrand.pyx":2859
* PyErr_Clear()
* oloc = PyArray_FROM_OTF(loc, NPY_DOUBLE, NPY_ALIGNED)
* oscale = PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less_equal(oscale, 0.0)):
* raise ValueError("scale <= 0")
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_scale, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_6mtrand_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_scale, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_6mtrand_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(((PyObject *)__pyx_v_oscale));
- __pyx_v_oscale = ((PyArrayObject *)__pyx_t_3);
- __pyx_t_3 = 0;
+ __pyx_v_oscale = ((PyArrayObject *)__pyx_t_2);
+ __pyx_t_2 = 0;
- /* "mtrand.pyx":2827
+ /* "mtrand.pyx":2860
* oloc = PyArray_FROM_OTF(loc, NPY_DOUBLE, NPY_ALIGNED)
* oscale = PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oscale, 0.0)): # <<<<<<<<<<<<<<
* raise ValueError("scale <= 0")
* return cont2_array(self.internal_state, rk_logistic, size, oloc, oscale)
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(((PyObject *)__pyx_v_oscale));
PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_oscale));
__Pyx_GIVEREF(((PyObject *)__pyx_v_oscale));
- PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 2827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 2860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
+ PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2860; __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_5)); __pyx_t_5 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":2828
+ /* "mtrand.pyx":2861
* oscale = PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oscale, 0.0)):
* raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
* return cont2_array(self.internal_state, rk_logistic, size, oloc, oscale)
*
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_9));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_9));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_9));
- __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_Raise(__pyx_t_5, 0, 0);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_84), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2861; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2861; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":2829
+ /* "mtrand.pyx":2862
* if np.any(np.less_equal(oscale, 0.0)):
* raise ValueError("scale <= 0")
* return cont2_array(self.internal_state, rk_logistic, size, oloc, oscale) # <<<<<<<<<<<<<<
@@ -12419,10 +12125,10 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_logistic(PyObject *__pyx_v_self,
* def lognormal(self, mean=0.0, sigma=1.0, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_5 = __pyx_f_6mtrand_cont2_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_logistic, __pyx_v_size, __pyx_v_oloc, __pyx_v_oscale); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_r = __pyx_t_5;
- __pyx_t_5 = 0;
+ __pyx_t_2 = __pyx_f_6mtrand_cont2_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_logistic, __pyx_v_size, __pyx_v_oloc, __pyx_v_oscale); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -12437,16 +12143,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_logistic(PyObject *__pyx_v_self,
__pyx_L0:;
__Pyx_DECREF((PyObject *)__pyx_v_oloc);
__Pyx_DECREF((PyObject *)__pyx_v_oscale);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_loc);
- __Pyx_DECREF(__pyx_v_scale);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":2831
+/* "mtrand.pyx":2864
* return cont2_array(self.internal_state, rk_logistic, size, oloc, oscale)
*
* def lognormal(self, mean=0.0, sigma=1.0, size=None): # <<<<<<<<<<<<<<
@@ -12454,9 +12156,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_logistic(PyObject *__pyx_v_self,
* lognormal(mean=0.0, sigma=1.0, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_lognormal(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_lognormal[] = "\n"" lognormal(mean=0.0, sigma=1.0, size=None)\n""\n"" Return samples drawn from a log-normal distribution.\n""\n"" Draw samples from a log-normal distribution with specified mean, standard\n"" deviation, and shape. Note that the mean and standard deviation are not the\n"" values for the distribution itself, but of the underlying normal\n"" distribution it is derived from.\n""\n""\n"" Parameters\n"" ----------\n"" mean : float\n"" Mean value of the underlying normal distribution\n"" sigma : float, >0.\n"" Standard deviation of the underlying normal distribution\n"" size : tuple of ints\n"" Output shape. If the given shape is, e.g., ``(m, n, k)``, then\n"" ``m * n * k`` samples are drawn.\n""\n"" See Also\n"" --------\n"" scipy.stats.lognorm : probability density function, distribution,\n"" cumulative density function, etc.\n""\n"" Notes\n"" -----\n"" A variable `x` has a log-normal distribution if `log(x)` is normally\n"" distributed.\n""\n"" The probability density function for the log-normal distribution is\n""\n"" .. math:: p(x) = \\frac{1}{\\sigma x \\sqrt{2\\pi}}\n"" e^{(-\\frac{(ln(x)-\\mu)^2}{2\\sigma^2})}\n""\n"" where :math:`\\mu` is the mean and :math:`\\sigma` is the standard deviation\n"" of the normally distributed logarithm of the variable.\n""\n"" A log-normal distribution results if a random variable is the *product* of\n"" a large number of independent, identically-distributed variables in the\n"" same way that a normal distribution results if the variable is the *sum*\n"" of a large number of independent, identically-distributed variables\n"" (see the last example). It is one of the so-called \"fat-tailed\"\n"" distributions.\n""\n"" The log-normal distribution is commonly used to model the lifespan of units\n"" with fatigue-stress failure modes. Since this includes\n"" most mechanical systems, the log-normal distribution has widespread\n"" application.\n""\n"" It is also commonly used to model oil field sizes, species abundance, and\n"" latent periods of infectious diseases.\n""\n"" References\n"" ----------\n"" .. [1] Eckhard Limpert, Werner A. Stahel, and Markus Abbt, \"Log-normal\n"" Distributions across the Sciences: Keys and Clues\", May 2001\n"" Vol. 51 No. 5 BioScience\n"" http://stat.ethz.ch/~stahel/lognormal/bioscience.pdf\n"" .. [2] Reiss, R.D., Thomas, M.(2001), Statistical Analysis of Extreme\n"" Values, Birkhauser Verlag, Basel, pp 31-32.\n"" .. [3] Wikipedia, \"Lognormal distribution\",\n"" http://en.wikipedia.org/wiki/Lognormal_distribution\n""\n"" Examples\n"" --------\n"" Draw samples from the distribution:\n""\n"" >>> mu, sigma = 3., 1. # mean and standard deviation\n"" >>> s = np.random.lognormal(mu, sigma, 1000)\n""\n"" Display the histogram of the samples, along with\n"" the probability density function:\n""\n"" >>> import matplotlib.pyplot as plt\n"" >>> count, bins, ignored = plt.hist(s, 100, normed=True, align='mid')\n""\n"" >>> x = np.linspace(min(bins), max(bins), 10000)\n"" >>> pdf = (np.exp(-(np.log(x) - mu)**2 / (2 * sigma**2))\n"" ... / (x * sigma * np.sqrt(2 * np.pi)))\n""\n"" >>> plt.plot(x, pdf, linewidth=2, color='r')\n"" >>> plt.axis('tight')\n"" >>> plt.show()\n""\n"" Demonstrate that taking the products of random samples from a uniform\n"" distribution can be fit well by a log-normal probability density function.\n""\n"" >>> # Generate a thousand samples: each is the product of 100 random\n"" >>> # values, drawn from a normal distribution.\n"" >>> b = []\n"" >>> for i in range(1000):\n"" ... a = 10. + np.random.random(100)\n"" ... b.append(np.product(a))\n""\n"" >>> b = np.array(b) / np.min(b) # scale values to be positive\n""\n"" >>> count, bins, ignored = plt.hist(b, 100, normed=True, align='center')\n""\n"" >>> sigma = np.std(np.log(b))\n"" >>> mu = np.mean(np.log(b))\n""\n"" >>> x = np.linspace(min(bins), max(bins), 10000)\n"" >>> pdf = (np.exp(-(np.log(x) - mu)**2 / (2 * sigma**2))\n"" ... / (x * sigma * np.sqrt(2 * np.pi)))\n""\n"" >>> plt.plot(x, pdf, color='r', linewidth=2)\n"" >>> plt.show()\n""\n"" ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_lognormal(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_36lognormal(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_36lognormal[] = "\n lognormal(mean=0.0, sigma=1.0, size=None)\n\n Return samples drawn from a log-normal distribution.\n\n Draw samples from a log-normal distribution with specified mean, standard\n deviation, and shape. Note that the mean and standard deviation are not the\n values for the distribution itself, but of the underlying normal\n distribution it is derived from.\n\n\n Parameters\n ----------\n mean : float\n Mean value of the underlying normal distribution\n sigma : float, >0.\n Standard deviation of the underlying normal distribution\n size : tuple of ints\n Output shape. If the given shape is, e.g., ``(m, n, k)``, then\n ``m * n * k`` samples are drawn.\n\n See Also\n --------\n scipy.stats.lognorm : probability density function, distribution,\n cumulative density function, etc.\n\n Notes\n -----\n A variable `x` has a log-normal distribution if `log(x)` is normally\n distributed.\n\n The probability density function for the log-normal distribution is\n\n .. math:: p(x) = \\frac{1}{\\sigma x \\sqrt{2\\pi}}\n e^{(-\\frac{(ln(x)-\\mu)^2}{2\\sigma^2})}\n\n where :math:`\\mu` is the mean and :math:`\\sigma` is the standard deviation\n of the normally distributed logarithm of the variable.\n\n A log-normal distribution results if a random variable is the *product* of\n a large number of independent, identically-distributed variables in the\n same way that a normal distribution results if the variable is the *sum*\n of a large number of independent, identically-distributed variables\n (see the last example). It is one of the so-called \"fat-tailed\"\n distributions.\n\n The log-normal distribution is commonly used to model the lifespan of units\n with fatigue-stress failure modes. Since thi""s includes\n most mechanical systems, the log-normal distribution has widespread\n application.\n\n It is also commonly used to model oil field sizes, species abundance, and\n latent periods of infectious diseases.\n\n References\n ----------\n .. [1] Eckhard Limpert, Werner A. Stahel, and Markus Abbt, \"Log-normal\n Distributions across the Sciences: Keys and Clues\", May 2001\n Vol. 51 No. 5 BioScience\n http://stat.ethz.ch/~stahel/lognormal/bioscience.pdf\n .. [2] Reiss, R.D., Thomas, M.(2001), Statistical Analysis of Extreme\n Values, Birkhauser Verlag, Basel, pp 31-32.\n .. [3] Wikipedia, \"Lognormal distribution\",\n http://en.wikipedia.org/wiki/Lognormal_distribution\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> mu, sigma = 3., 1. # mean and standard deviation\n >>> s = np.random.lognormal(mu, sigma, 1000)\n\n Display the histogram of the samples, along with\n the probability density function:\n\n >>> import matplotlib.pyplot as plt\n >>> count, bins, ignored = plt.hist(s, 100, normed=True, align='mid')\n\n >>> x = np.linspace(min(bins), max(bins), 10000)\n >>> pdf = (np.exp(-(np.log(x) - mu)**2 / (2 * sigma**2))\n ... / (x * sigma * np.sqrt(2 * np.pi)))\n\n >>> plt.plot(x, pdf, linewidth=2, color='r')\n >>> plt.axis('tight')\n >>> plt.show()\n\n Demonstrate that taking the products of random samples from a uniform\n distribution can be fit well by a log-normal probability density function.\n\n >>> # Generate a thousand samples: each is the product of 100 random\n >>> # values, drawn from a normal distribution.\n >>> b = []\n >>> for i in range(1000):\n ... a = 10. + np.random.random(100)\n ... b.append(np.product(a))\n\n >>> b"" = np.array(b) / np.min(b) # scale values to be positive\n\n >>> count, bins, ignored = plt.hist(b, 100, normed=True, align='center')\n\n >>> sigma = np.std(np.log(b))\n >>> mu = np.mean(np.log(b))\n\n >>> x = np.linspace(min(bins), max(bins), 10000)\n >>> pdf = (np.exp(-(np.log(x) - mu)**2 / (2 * sigma**2))\n ... / (x * sigma * np.sqrt(2 * np.pi)))\n\n >>> plt.plot(x, pdf, color='r', linewidth=2)\n >>> plt.show()\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_36lognormal(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_mean = 0;
PyObject *__pyx_v_sigma = 0;
PyObject *__pyx_v_size = 0;
@@ -12475,8 +12177,8 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_lognormal(PyObject *__pyx_v_self
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
PyObject* values[3] = {0,0,0};
- values[0] = __pyx_k_29;
- values[1] = __pyx_k_30;
+ values[0] = __pyx_k_85;
+ values[1] = __pyx_k_86;
values[2] = ((PyObject *)Py_None);
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
@@ -12487,30 +12189,30 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_lognormal(PyObject *__pyx_v_self
}
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 0:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__mean);
- if (unlikely(value)) { values[0] = value; kw_args--; }
+ if (value) { values[0] = value; kw_args--; }
}
case 1:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sigma);
- if (unlikely(value)) { values[1] = value; kw_args--; }
+ if (value) { values[1] = value; kw_args--; }
}
case 2:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[2] = value; kw_args--; }
+ if (value) { values[2] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "lognormal") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2831; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "lognormal") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2864; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_mean = values[0];
__pyx_v_sigma = values[1];
__pyx_v_size = values[2];
} else {
- __pyx_v_mean = __pyx_k_29;
- __pyx_v_sigma = __pyx_k_30;
+ __pyx_v_mean = __pyx_k_85;
+ __pyx_v_sigma = __pyx_k_86;
__pyx_v_size = ((PyObject *)Py_None);
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 3: __pyx_v_size = PyTuple_GET_ITEM(__pyx_args, 2);
@@ -12522,19 +12224,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_lognormal(PyObject *__pyx_v_self
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("lognormal", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2831; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("lognormal", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2864; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.lognormal");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_mean);
- __Pyx_INCREF(__pyx_v_sigma);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_omean = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_osigma = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":2946
+ /* "mtrand.pyx":2979
* cdef double fmean, fsigma
*
* fmean = PyFloat_AsDouble(mean) # <<<<<<<<<<<<<<
@@ -12543,7 +12242,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_lognormal(PyObject *__pyx_v_self
*/
__pyx_v_fmean = PyFloat_AsDouble(__pyx_v_mean);
- /* "mtrand.pyx":2947
+ /* "mtrand.pyx":2980
*
* fmean = PyFloat_AsDouble(mean)
* fsigma = PyFloat_AsDouble(sigma) # <<<<<<<<<<<<<<
@@ -12552,7 +12251,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_lognormal(PyObject *__pyx_v_self
*/
__pyx_v_fsigma = PyFloat_AsDouble(__pyx_v_sigma);
- /* "mtrand.pyx":2949
+ /* "mtrand.pyx":2982
* fsigma = PyFloat_AsDouble(sigma)
*
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -12562,39 +12261,33 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_lognormal(PyObject *__pyx_v_self
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":2950
+ /* "mtrand.pyx":2983
*
* if not PyErr_Occurred():
* if fsigma <= 0: # <<<<<<<<<<<<<<
* raise ValueError("sigma <= 0")
* return cont2_array_sc(self.internal_state, rk_lognormal, size, fmean, fsigma)
*/
- __pyx_t_1 = (__pyx_v_fsigma <= 0);
+ __pyx_t_1 = (__pyx_v_fsigma <= 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":2951
+ /* "mtrand.pyx":2984
* if not PyErr_Occurred():
* if fsigma <= 0:
* raise ValueError("sigma <= 0") # <<<<<<<<<<<<<<
* return cont2_array_sc(self.internal_state, rk_lognormal, size, fmean, fsigma)
*
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_88), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_31));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_31));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_31));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":2952
+ /* "mtrand.pyx":2985
* if fsigma <= 0:
* raise ValueError("sigma <= 0")
* return cont2_array_sc(self.internal_state, rk_lognormal, size, fmean, fsigma) # <<<<<<<<<<<<<<
@@ -12602,16 +12295,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_lognormal(PyObject *__pyx_v_self
* PyErr_Clear()
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = __pyx_f_6mtrand_cont2_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_lognormal, __pyx_v_size, __pyx_v_fmean, __pyx_v_fsigma); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2952; __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_cont2_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_lognormal, __pyx_v_size, __pyx_v_fmean, __pyx_v_fsigma); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2985; __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_L6;
}
__pyx_L6:;
- /* "mtrand.pyx":2954
+ /* "mtrand.pyx":2987
* return cont2_array_sc(self.internal_state, rk_lognormal, size, fmean, fsigma)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -12620,101 +12313,95 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_lognormal(PyObject *__pyx_v_self
*/
PyErr_Clear();
- /* "mtrand.pyx":2956
+ /* "mtrand.pyx":2989
* PyErr_Clear()
*
* omean = PyArray_FROM_OTF(mean, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* osigma = PyArray_FROM_OTF(sigma, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(osigma, 0.0)):
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_mean, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2956; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_6mtrand_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2956; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_mean, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_6mtrand_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(((PyObject *)__pyx_v_omean));
- __pyx_v_omean = ((PyArrayObject *)__pyx_t_3);
- __pyx_t_3 = 0;
+ __pyx_v_omean = ((PyArrayObject *)__pyx_t_2);
+ __pyx_t_2 = 0;
- /* "mtrand.pyx":2957
+ /* "mtrand.pyx":2990
*
* omean = PyArray_FROM_OTF(mean, NPY_DOUBLE, NPY_ALIGNED)
* osigma = PyArray_FROM_OTF(sigma, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less_equal(osigma, 0.0)):
* raise ValueError("sigma <= 0.0")
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_sigma, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_6mtrand_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_sigma, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_6mtrand_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(((PyObject *)__pyx_v_osigma));
- __pyx_v_osigma = ((PyArrayObject *)__pyx_t_3);
- __pyx_t_3 = 0;
+ __pyx_v_osigma = ((PyArrayObject *)__pyx_t_2);
+ __pyx_t_2 = 0;
- /* "mtrand.pyx":2958
+ /* "mtrand.pyx":2991
* omean = PyArray_FROM_OTF(mean, NPY_DOUBLE, NPY_ALIGNED)
* osigma = PyArray_FROM_OTF(sigma, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(osigma, 0.0)): # <<<<<<<<<<<<<<
* raise ValueError("sigma <= 0.0")
* return cont2_array(self.internal_state, rk_lognormal, size, omean, osigma)
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2991; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2991; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2991; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2991; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2991; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2991; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(((PyObject *)__pyx_v_osigma));
PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_osigma));
__Pyx_GIVEREF(((PyObject *)__pyx_v_osigma));
- PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2991; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 2958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 2991; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
+ PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2991; __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_5)); __pyx_t_5 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2991; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":2959
+ /* "mtrand.pyx":2992
* osigma = PyArray_FROM_OTF(sigma, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(osigma, 0.0)):
* raise ValueError("sigma <= 0.0") # <<<<<<<<<<<<<<
* return cont2_array(self.internal_state, rk_lognormal, size, omean, osigma)
*
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_32));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_32));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_32));
- __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_Raise(__pyx_t_5, 0, 0);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_90), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2992; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2992; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":2960
+ /* "mtrand.pyx":2993
* if np.any(np.less_equal(osigma, 0.0)):
* raise ValueError("sigma <= 0.0")
* return cont2_array(self.internal_state, rk_lognormal, size, omean, osigma) # <<<<<<<<<<<<<<
@@ -12722,10 +12409,10 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_lognormal(PyObject *__pyx_v_self
* def rayleigh(self, scale=1.0, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_5 = __pyx_f_6mtrand_cont2_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_lognormal, __pyx_v_size, __pyx_v_omean, __pyx_v_osigma); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_r = __pyx_t_5;
- __pyx_t_5 = 0;
+ __pyx_t_2 = __pyx_f_6mtrand_cont2_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_lognormal, __pyx_v_size, __pyx_v_omean, __pyx_v_osigma); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -12740,16 +12427,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_lognormal(PyObject *__pyx_v_self
__pyx_L0:;
__Pyx_DECREF((PyObject *)__pyx_v_omean);
__Pyx_DECREF((PyObject *)__pyx_v_osigma);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_mean);
- __Pyx_DECREF(__pyx_v_sigma);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":2962
+/* "mtrand.pyx":2995
* return cont2_array(self.internal_state, rk_lognormal, size, omean, osigma)
*
* def rayleigh(self, scale=1.0, size=None): # <<<<<<<<<<<<<<
@@ -12757,9 +12440,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_lognormal(PyObject *__pyx_v_self
* rayleigh(scale=1.0, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_rayleigh(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_rayleigh[] = "\n rayleigh(scale=1.0, size=None)\n\n Draw samples from a Rayleigh distribution.\n\n The :math:`\\chi` and Weibull distributions are generalizations of the\n Rayleigh.\n\n Parameters\n ----------\n scale : scalar\n Scale, also equals the mode. Should be >= 0.\n size : int or tuple of ints, optional\n Shape of the output. Default is None, in which case a single\n value is returned.\n\n Notes\n -----\n The probability density function for the Rayleigh distribution is\n\n .. math:: P(x;scale) = \\frac{x}{scale^2}e^{\\frac{-x^2}{2 \\cdotp scale^2}}\n\n The Rayleigh distribution arises if the wind speed and wind direction are\n both gaussian variables, then the vector wind velocity forms a Rayleigh\n distribution. The Rayleigh distribution is used to model the expected\n output from wind turbines.\n\n References\n ----------\n ..[1] Brighton Webs Ltd., Rayleigh Distribution,\n http://www.brighton-webs.co.uk/distributions/rayleigh.asp\n ..[2] Wikipedia, \"Rayleigh distribution\"\n http://en.wikipedia.org/wiki/Rayleigh_distribution\n\n Examples\n --------\n Draw values from the distribution and plot the histogram\n\n >>> values = hist(np.random.rayleigh(3, 100000), bins=200, normed=True)\n\n Wave heights tend to follow a Rayleigh distribution. If the mean wave\n height is 1 meter, what fraction of waves are likely to be larger than 3\n meters?\n\n >>> meanvalue = 1\n >>> modevalue = np.sqrt(2 / np.pi) * meanvalue\n >>> s = np.random.rayleigh(modevalue, 1000000)\n\n The percentage of waves larger than 3 meters is:\n\n >>> 100.*sum(s>3)/1000000.\n 0.087300000000000003\n\n ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_rayleigh(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_37rayleigh(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_37rayleigh[] = "\n rayleigh(scale=1.0, size=None)\n\n Draw samples from a Rayleigh distribution.\n\n The :math:`\\chi` and Weibull distributions are generalizations of the\n Rayleigh.\n\n Parameters\n ----------\n scale : scalar\n Scale, also equals the mode. Should be >= 0.\n size : int or tuple of ints, optional\n Shape of the output. Default is None, in which case a single\n value is returned.\n\n Notes\n -----\n The probability density function for the Rayleigh distribution is\n\n .. math:: P(x;scale) = \\frac{x}{scale^2}e^{\\frac{-x^2}{2 \\cdotp scale^2}}\n\n The Rayleigh distribution arises if the wind speed and wind direction are\n both gaussian variables, then the vector wind velocity forms a Rayleigh\n distribution. The Rayleigh distribution is used to model the expected\n output from wind turbines.\n\n References\n ----------\n ..[1] Brighton Webs Ltd., Rayleigh Distribution,\n http://www.brighton-webs.co.uk/distributions/rayleigh.asp\n ..[2] Wikipedia, \"Rayleigh distribution\"\n http://en.wikipedia.org/wiki/Rayleigh_distribution\n\n Examples\n --------\n Draw values from the distribution and plot the histogram\n\n >>> values = hist(np.random.rayleigh(3, 100000), bins=200, normed=True)\n\n Wave heights tend to follow a Rayleigh distribution. If the mean wave\n height is 1 meter, what fraction of waves are likely to be larger than 3\n meters?\n\n >>> meanvalue = 1\n >>> modevalue = np.sqrt(2 / np.pi) * meanvalue\n >>> s = np.random.rayleigh(modevalue, 1000000)\n\n The percentage of waves larger than 3 meters is:\n\n >>> 100.*sum(s>3)/1000000.\n 0.087300000000000003\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_37rayleigh(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_scale = 0;
PyObject *__pyx_v_size = 0;
PyArrayObject *__pyx_v_oscale;
@@ -12775,7 +12458,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_rayleigh(PyObject *__pyx_v_self,
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
PyObject* values[2] = {0,0};
- values[0] = __pyx_k_33;
+ values[0] = __pyx_k_91;
values[1] = ((PyObject *)Py_None);
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
@@ -12785,23 +12468,23 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_rayleigh(PyObject *__pyx_v_self,
}
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 0:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__scale);
- if (unlikely(value)) { values[0] = value; kw_args--; }
+ if (value) { values[0] = value; kw_args--; }
}
case 1:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[1] = value; kw_args--; }
+ if (value) { values[1] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "rayleigh") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2962; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "rayleigh") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2995; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_scale = values[0];
__pyx_v_size = values[1];
} else {
- __pyx_v_scale = __pyx_k_33;
+ __pyx_v_scale = __pyx_k_91;
__pyx_v_size = ((PyObject *)Py_None);
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 2: __pyx_v_size = PyTuple_GET_ITEM(__pyx_args, 1);
@@ -12812,17 +12495,15 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_rayleigh(PyObject *__pyx_v_self,
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("rayleigh", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2962; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("rayleigh", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2995; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.rayleigh");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_scale);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_oscale = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":3020
+ /* "mtrand.pyx":3053
* cdef double fscale
*
* fscale = PyFloat_AsDouble(scale) # <<<<<<<<<<<<<<
@@ -12831,7 +12512,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_rayleigh(PyObject *__pyx_v_self,
*/
__pyx_v_fscale = PyFloat_AsDouble(__pyx_v_scale);
- /* "mtrand.pyx":3022
+ /* "mtrand.pyx":3055
* fscale = PyFloat_AsDouble(scale)
*
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -12841,39 +12522,33 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_rayleigh(PyObject *__pyx_v_self,
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":3023
+ /* "mtrand.pyx":3056
*
* if not PyErr_Occurred():
* if fscale <= 0: # <<<<<<<<<<<<<<
* raise ValueError("scale <= 0")
* return cont1_array_sc(self.internal_state, rk_rayleigh, size, fscale)
*/
- __pyx_t_1 = (__pyx_v_fscale <= 0);
+ __pyx_t_1 = (__pyx_v_fscale <= 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":3024
+ /* "mtrand.pyx":3057
* if not PyErr_Occurred():
* if fscale <= 0:
* raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
* return cont1_array_sc(self.internal_state, rk_rayleigh, size, fscale)
*
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_92), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3057; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_9));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_9));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_9));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3057; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":3025
+ /* "mtrand.pyx":3058
* if fscale <= 0:
* raise ValueError("scale <= 0")
* return cont1_array_sc(self.internal_state, rk_rayleigh, size, fscale) # <<<<<<<<<<<<<<
@@ -12881,16 +12556,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_rayleigh(PyObject *__pyx_v_self,
* PyErr_Clear()
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = __pyx_f_6mtrand_cont1_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_rayleigh, __pyx_v_size, __pyx_v_fscale); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3025; __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_cont1_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_rayleigh, __pyx_v_size, __pyx_v_fscale); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3058; __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_L6;
}
__pyx_L6:;
- /* "mtrand.pyx":3027
+ /* "mtrand.pyx":3060
* return cont1_array_sc(self.internal_state, rk_rayleigh, size, fscale)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -12899,87 +12574,81 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_rayleigh(PyObject *__pyx_v_self,
*/
PyErr_Clear();
- /* "mtrand.pyx":3029
+ /* "mtrand.pyx":3062
* PyErr_Clear()
*
* oscale = <ndarray>PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less_equal(oscale, 0.0)):
* raise ValueError("scale <= 0.0")
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_scale, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_scale, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_oscale));
- __pyx_v_oscale = ((PyArrayObject *)__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_oscale = ((PyArrayObject *)__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":3030
+ /* "mtrand.pyx":3063
*
* oscale = <ndarray>PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oscale, 0.0)): # <<<<<<<<<<<<<<
* raise ValueError("scale <= 0.0")
* return cont1_array(self.internal_state, rk_rayleigh, size, oscale)
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(((PyObject *)__pyx_v_oscale));
PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_oscale));
__Pyx_GIVEREF(((PyObject *)__pyx_v_oscale));
- PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 3030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 3063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
+ PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3063; __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_5)); __pyx_t_5 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3031
+ /* "mtrand.pyx":3064
* oscale = <ndarray>PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oscale, 0.0)):
* raise ValueError("scale <= 0.0") # <<<<<<<<<<<<<<
* return cont1_array(self.internal_state, rk_rayleigh, size, oscale)
*
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_34));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_34));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_34));
- __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_Raise(__pyx_t_5, 0, 0);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_94), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":3032
+ /* "mtrand.pyx":3065
* if np.any(np.less_equal(oscale, 0.0)):
* raise ValueError("scale <= 0.0")
* return cont1_array(self.internal_state, rk_rayleigh, size, oscale) # <<<<<<<<<<<<<<
@@ -12987,10 +12656,10 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_rayleigh(PyObject *__pyx_v_self,
* def wald(self, mean, scale, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_5 = __pyx_f_6mtrand_cont1_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_rayleigh, __pyx_v_size, __pyx_v_oscale); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3032; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_r = __pyx_t_5;
- __pyx_t_5 = 0;
+ __pyx_t_2 = __pyx_f_6mtrand_cont1_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_rayleigh, __pyx_v_size, __pyx_v_oscale); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -13004,15 +12673,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_rayleigh(PyObject *__pyx_v_self,
__pyx_r = NULL;
__pyx_L0:;
__Pyx_DECREF((PyObject *)__pyx_v_oscale);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_scale);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":3034
+/* "mtrand.pyx":3067
* return cont1_array(self.internal_state, rk_rayleigh, size, oscale)
*
* def wald(self, mean, scale, size=None): # <<<<<<<<<<<<<<
@@ -13020,9 +12686,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_rayleigh(PyObject *__pyx_v_self,
* wald(mean, scale, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_wald(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_wald[] = "\n"" wald(mean, scale, size=None)\n""\n"" Draw samples from a Wald, or Inverse Gaussian, distribution.\n""\n"" As the scale approaches infinity, the distribution becomes more like a\n"" Gaussian.\n""\n"" Some references claim that the Wald is an Inverse Gaussian with mean=1, but\n"" this is by no means universal.\n""\n"" The Inverse Gaussian distribution was first studied in relationship to\n"" Brownian motion. In 1956 M.C.K. Tweedie used the name Inverse Gaussian\n"" because there is an inverse relationship between the time to cover a unit\n"" distance and distance covered in unit time.\n""\n"" Parameters\n"" ----------\n"" mean : scalar\n"" Distribution mean, should be > 0.\n"" scale : scalar\n"" Scale parameter, should be >= 0.\n"" size : int or tuple of ints, optional\n"" Output shape. Default is None, in which case a single value is\n"" returned.\n""\n"" Returns\n"" -------\n"" samples : ndarray or scalar\n"" Drawn sample, all greater than zero.\n""\n"" Notes\n"" -----\n"" The probability density function for the Wald distribution is\n""\n"" .. math:: P(x;mean,scale) = \\sqrt{\\frac{scale}{2\\pi x^3}}e^\n"" \\frac{-scale(x-mean)^2}{2\\cdotp mean^2x}\n""\n"" As noted above the Inverse Gaussian distribution first arise from attempts\n"" to model Brownian Motion. It is also a competitor to the Weibull for use in\n"" reliability modeling and modeling stock returns and interest rate\n"" processes.\n""\n"" References\n"" ----------\n"" ..[1] Brighton Webs Ltd., Wald Distribution,\n"" http://www.brighton-webs.co.uk/distributions/wald.asp\n"" ..[2] Chhikara, Raj S., and Folks, J. Leroy, \"The Inverse Gaussian\n"" Distribution: Theory : Methodology, and Applications\", CRC Press,\n"" 1988.\n"" ..[3] Wikipedia, \"Wald distribution\"\n"" http://en.wikipedia.org/wiki/Wald_distribution\n""\n"" Examples\n"" --------\n"" Draw values from the distribution and plot the histogram:\n""\n"" >>> import matplotlib.pyplot as plt\n"" >>> h = plt.hist(np.random.wald(3, 2, 100000), bins=200, normed=True)\n"" >>> plt.show()\n""\n"" ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_wald(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_38wald(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_38wald[] = "\n wald(mean, scale, size=None)\n\n Draw samples from a Wald, or Inverse Gaussian, distribution.\n\n As the scale approaches infinity, the distribution becomes more like a\n Gaussian.\n\n Some references claim that the Wald is an Inverse Gaussian with mean=1, but\n this is by no means universal.\n\n The Inverse Gaussian distribution was first studied in relationship to\n Brownian motion. In 1956 M.C.K. Tweedie used the name Inverse Gaussian\n because there is an inverse relationship between the time to cover a unit\n distance and distance covered in unit time.\n\n Parameters\n ----------\n mean : scalar\n Distribution mean, should be > 0.\n scale : scalar\n Scale parameter, should be >= 0.\n size : int or tuple of ints, optional\n Output shape. Default is None, in which case a single value is\n returned.\n\n Returns\n -------\n samples : ndarray or scalar\n Drawn sample, all greater than zero.\n\n Notes\n -----\n The probability density function for the Wald distribution is\n\n .. math:: P(x;mean,scale) = \\sqrt{\\frac{scale}{2\\pi x^3}}e^\n \\frac{-scale(x-mean)^2}{2\\cdotp mean^2x}\n\n As noted above the Inverse Gaussian distribution first arise from attempts\n to model Brownian Motion. It is also a competitor to the Weibull for use in\n reliability modeling and modeling stock returns and interest rate\n processes.\n\n References\n ----------\n ..[1] Brighton Webs Ltd., Wald Distribution,\n http://www.brighton-webs.co.uk/distributions/wald.asp\n ..[2] Chhikara, Raj S., and Folks, J. Leroy, \"The Inverse Gaussian\n Distribution: Theory : Methodology, and Applications\", CRC Press,\n 1988.\n ..[3] Wikipedia, \"Wald distributio""n\"\n http://en.wikipedia.org/wiki/Wald_distribution\n\n Examples\n --------\n Draw values from the distribution and plot the histogram:\n\n >>> import matplotlib.pyplot as plt\n >>> h = plt.hist(np.random.wald(3, 2, 100000), bins=200, normed=True)\n >>> plt.show()\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_38wald(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_mean = 0;
PyObject *__pyx_v_scale = 0;
PyObject *__pyx_v_size = 0;
@@ -13058,16 +12724,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_wald(PyObject *__pyx_v_self, PyO
values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__scale);
if (likely(values[1])) kw_args--;
else {
- __Pyx_RaiseArgtupleInvalid("wald", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3034; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("wald", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3067; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
case 2:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[2] = value; kw_args--; }
+ if (value) { values[2] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "wald") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3034; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "wald") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3067; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_mean = values[0];
__pyx_v_scale = values[1];
@@ -13086,19 +12752,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_wald(PyObject *__pyx_v_self, PyO
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("wald", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3034; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("wald", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3067; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.wald");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_mean);
- __Pyx_INCREF(__pyx_v_scale);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_omean = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_oscale = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":3100
+ /* "mtrand.pyx":3133
* cdef double fmean, fscale
*
* fmean = PyFloat_AsDouble(mean) # <<<<<<<<<<<<<<
@@ -13107,7 +12770,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_wald(PyObject *__pyx_v_self, PyO
*/
__pyx_v_fmean = PyFloat_AsDouble(__pyx_v_mean);
- /* "mtrand.pyx":3101
+ /* "mtrand.pyx":3134
*
* fmean = PyFloat_AsDouble(mean)
* fscale = PyFloat_AsDouble(scale) # <<<<<<<<<<<<<<
@@ -13116,7 +12779,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_wald(PyObject *__pyx_v_self, PyO
*/
__pyx_v_fscale = PyFloat_AsDouble(__pyx_v_scale);
- /* "mtrand.pyx":3102
+ /* "mtrand.pyx":3135
* fmean = PyFloat_AsDouble(mean)
* fscale = PyFloat_AsDouble(scale)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -13126,71 +12789,59 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_wald(PyObject *__pyx_v_self, PyO
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":3103
+ /* "mtrand.pyx":3136
* fscale = PyFloat_AsDouble(scale)
* if not PyErr_Occurred():
* if fmean <= 0: # <<<<<<<<<<<<<<
* raise ValueError("mean <= 0")
* if fscale <= 0:
*/
- __pyx_t_1 = (__pyx_v_fmean <= 0);
+ __pyx_t_1 = (__pyx_v_fmean <= 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":3104
+ /* "mtrand.pyx":3137
* if not PyErr_Occurred():
* if fmean <= 0:
* raise ValueError("mean <= 0") # <<<<<<<<<<<<<<
* if fscale <= 0:
* raise ValueError("scale <= 0")
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_96), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_35));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_35));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_35));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":3105
+ /* "mtrand.pyx":3138
* if fmean <= 0:
* raise ValueError("mean <= 0")
* if fscale <= 0: # <<<<<<<<<<<<<<
* raise ValueError("scale <= 0")
* return cont2_array_sc(self.internal_state, rk_wald, size, fmean, fscale)
*/
- __pyx_t_1 = (__pyx_v_fscale <= 0);
+ __pyx_t_1 = (__pyx_v_fscale <= 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":3106
+ /* "mtrand.pyx":3139
* raise ValueError("mean <= 0")
* if fscale <= 0:
* raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
* return cont2_array_sc(self.internal_state, rk_wald, size, fmean, fscale)
*
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_9));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_9));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_9));
- __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_97), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":3107
+ /* "mtrand.pyx":3140
* if fscale <= 0:
* raise ValueError("scale <= 0")
* return cont2_array_sc(self.internal_state, rk_wald, size, fmean, fscale) # <<<<<<<<<<<<<<
@@ -13198,7 +12849,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_wald(PyObject *__pyx_v_self, PyO
* PyErr_Clear()
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_2 = __pyx_f_6mtrand_cont2_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_wald, __pyx_v_size, __pyx_v_fmean, __pyx_v_fscale); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __pyx_f_6mtrand_cont2_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_wald, __pyx_v_size, __pyx_v_fmean, __pyx_v_fscale); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__pyx_r = __pyx_t_2;
__pyx_t_2 = 0;
@@ -13207,7 +12858,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_wald(PyObject *__pyx_v_self, PyO
}
__pyx_L6:;
- /* "mtrand.pyx":3109
+ /* "mtrand.pyx":3142
* return cont2_array_sc(self.internal_state, rk_wald, size, fmean, fscale)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -13216,166 +12867,154 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_wald(PyObject *__pyx_v_self, PyO
*/
PyErr_Clear();
- /* "mtrand.pyx":3110
+ /* "mtrand.pyx":3143
*
* PyErr_Clear()
* omean = PyArray_FROM_OTF(mean, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* oscale = PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(omean,0.0)):
*/
- __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_mean, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_mean, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_6mtrand_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_6mtrand_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(((PyObject *)__pyx_v_omean));
__pyx_v_omean = ((PyArrayObject *)__pyx_t_2);
__pyx_t_2 = 0;
- /* "mtrand.pyx":3111
+ /* "mtrand.pyx":3144
* PyErr_Clear()
* omean = PyArray_FROM_OTF(mean, NPY_DOUBLE, NPY_ALIGNED)
* oscale = PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less_equal(omean,0.0)):
* raise ValueError("mean <= 0.0")
*/
- __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_scale, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_scale, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_6mtrand_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_6mtrand_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(((PyObject *)__pyx_v_oscale));
__pyx_v_oscale = ((PyArrayObject *)__pyx_t_2);
__pyx_t_2 = 0;
- /* "mtrand.pyx":3112
+ /* "mtrand.pyx":3145
* omean = PyArray_FROM_OTF(mean, NPY_DOUBLE, NPY_ALIGNED)
* oscale = PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(omean,0.0)): # <<<<<<<<<<<<<<
* raise ValueError("mean <= 0.0")
* elif np.any(np.less_equal(oscale,0.0)):
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3145; __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_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(((PyObject *)__pyx_v_omean));
PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_omean));
__Pyx_GIVEREF(((PyObject *)__pyx_v_omean));
PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
__Pyx_GIVEREF(__pyx_t_2);
__pyx_t_2 = 0;
- __pyx_t_2 = PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 3112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __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 = 3145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
__Pyx_GIVEREF(__pyx_t_2);
__pyx_t_2 = 0;
- __pyx_t_2 = PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3113
+ /* "mtrand.pyx":3146
* oscale = PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(omean,0.0)):
* raise ValueError("mean <= 0.0") # <<<<<<<<<<<<<<
* elif np.any(np.less_equal(oscale,0.0)):
* raise ValueError("scale <= 0.0")
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_99), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_36));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_36));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_36));
- __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_5, 0, 0);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L9;
}
- /* "mtrand.pyx":3114
+ /* "mtrand.pyx":3147
* if np.any(np.less_equal(omean,0.0)):
* raise ValueError("mean <= 0.0")
* elif np.any(np.less_equal(oscale,0.0)): # <<<<<<<<<<<<<<
* raise ValueError("scale <= 0.0")
* return cont2_array(self.internal_state, rk_wald, size, omean, oscale)
*/
- __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_5 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
__Pyx_INCREF(((PyObject *)__pyx_v_oscale));
PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_oscale));
__Pyx_GIVEREF(((PyObject *)__pyx_v_oscale));
- PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5);
- __Pyx_GIVEREF(__pyx_t_5);
- __pyx_t_5 = 0;
- __pyx_t_5 = PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
+ __Pyx_GIVEREF(__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 = 3147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_DECREF(__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 = 3114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
- __Pyx_GIVEREF(__pyx_t_5);
- __pyx_t_5 = 0;
- __pyx_t_5 = PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 3147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
+ 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 = 3147; __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_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3115
+ /* "mtrand.pyx":3148
* raise ValueError("mean <= 0.0")
* elif np.any(np.less_equal(oscale,0.0)):
* raise ValueError("scale <= 0.0") # <<<<<<<<<<<<<<
* return cont2_array(self.internal_state, rk_wald, size, omean, oscale)
*
*/
- __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_34));
- PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_34));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_34));
- __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_Raise(__pyx_t_4, 0, 0);
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_100), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3148; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3148; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L9;
}
__pyx_L9:;
- /* "mtrand.pyx":3116
+ /* "mtrand.pyx":3149
* elif np.any(np.less_equal(oscale,0.0)):
* raise ValueError("scale <= 0.0")
* return cont2_array(self.internal_state, rk_wald, size, omean, oscale) # <<<<<<<<<<<<<<
@@ -13383,10 +13022,10 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_wald(PyObject *__pyx_v_self, PyO
*
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_4 = __pyx_f_6mtrand_cont2_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_wald, __pyx_v_size, __pyx_v_omean, __pyx_v_oscale); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- __pyx_r = __pyx_t_4;
- __pyx_t_4 = 0;
+ __pyx_t_2 = __pyx_f_6mtrand_cont2_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_wald, __pyx_v_size, __pyx_v_omean, __pyx_v_oscale); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -13401,16 +13040,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_wald(PyObject *__pyx_v_self, PyO
__pyx_L0:;
__Pyx_DECREF((PyObject *)__pyx_v_omean);
__Pyx_DECREF((PyObject *)__pyx_v_oscale);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_mean);
- __Pyx_DECREF(__pyx_v_scale);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":3120
+/* "mtrand.pyx":3153
*
*
* def triangular(self, left, mode, right, size=None): # <<<<<<<<<<<<<<
@@ -13418,9 +13053,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_wald(PyObject *__pyx_v_self, PyO
* triangular(left, mode, right, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_triangular(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_triangular[] = "\n"" triangular(left, mode, right, size=None)\n""\n"" Draw samples from the triangular distribution.\n""\n"" The triangular distribution is a continuous probability distribution with\n"" lower limit left, peak at mode, and upper limit right. Unlike the other\n"" distributions, these parameters directly define the shape of the pdf.\n""\n"" Parameters\n"" ----------\n"" left : scalar\n"" Lower limit.\n"" mode : scalar\n"" The value where the peak of the distribution occurs.\n"" The value should fulfill the condition ``left <= mode <= right``.\n"" right : scalar\n"" Upper limit, should be larger than `left`.\n"" size : int or tuple of ints, optional\n"" Output shape. Default is None, in which case a single value is\n"" returned.\n""\n"" Returns\n"" -------\n"" samples : ndarray or scalar\n"" The returned samples all lie in the interval [left, right].\n""\n"" Notes\n"" -----\n"" The probability density function for the Triangular distribution is\n""\n"" .. math:: P(x;l, m, r) = \\begin{cases}\n"" \\frac{2(x-l)}{(r-l)(m-l)}& \\text{for $l \\leq x \\leq m$},\\\\\n"" \\frac{2(m-x)}{(r-l)(r-m)}& \\text{for $m \\leq x \\leq r$},\\\\\n"" 0& \\text{otherwise}.\n"" \\end{cases}\n""\n"" The triangular distribution is often used in ill-defined problems where the\n"" underlying distribution is not known, but some knowledge of the limits and\n"" mode exists. Often it is used in simulations.\n""\n"" References\n"" ----------\n"" ..[1] Wikipedia, \"Triangular distribution\"\n"" http://en.wikipedia.org/wiki/Triangular_distribution\n""\n"" Examples\n"" --------\n"" Draw values from the distribution and plot the histogram:\n""\n"" >>> import matplotlib.pyplot as plt\n"" >>> h = plt.hist(np.random.triangular(-3, 0, 8, 100000), bins=200,\n"" ... normed=True)\n"" >>> plt.show()\n""\n"" ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_triangular(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_39triangular(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_39triangular[] = "\n triangular(left, mode, right, size=None)\n\n Draw samples from the triangular distribution.\n\n The triangular distribution is a continuous probability distribution with\n lower limit left, peak at mode, and upper limit right. Unlike the other\n distributions, these parameters directly define the shape of the pdf.\n\n Parameters\n ----------\n left : scalar\n Lower limit.\n mode : scalar\n The value where the peak of the distribution occurs.\n The value should fulfill the condition ``left <= mode <= right``.\n right : scalar\n Upper limit, should be larger than `left`.\n size : int or tuple of ints, optional\n Output shape. Default is None, in which case a single value is\n returned.\n\n Returns\n -------\n samples : ndarray or scalar\n The returned samples all lie in the interval [left, right].\n\n Notes\n -----\n The probability density function for the Triangular distribution is\n\n .. math:: P(x;l, m, r) = \\begin{cases}\n \\frac{2(x-l)}{(r-l)(m-l)}& \\text{for $l \\leq x \\leq m$},\\\\\n \\frac{2(m-x)}{(r-l)(r-m)}& \\text{for $m \\leq x \\leq r$},\\\\\n 0& \\text{otherwise}.\n \\end{cases}\n\n The triangular distribution is often used in ill-defined problems where the\n underlying distribution is not known, but some knowledge of the limits and\n mode exists. Often it is used in simulations.\n\n References\n ----------\n ..[1] Wikipedia, \"Triangular distribution\"\n http://en.wikipedia.org/wiki/Triangular_distribution\n\n Examples\n --------\n Draw values from the distribution and plot the histogram:\n\n >>> import matplotlib.pyplot as plt\n >>> h = plt.hist(np.random.triangular(-3, 0, 8, 100000), bins=2""00,\n ... normed=True)\n >>> plt.show()\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_39triangular(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_left = 0;
PyObject *__pyx_v_mode = 0;
PyObject *__pyx_v_right = 0;
@@ -13460,22 +13095,22 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_triangular(PyObject *__pyx_v_sel
values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__mode);
if (likely(values[1])) kw_args--;
else {
- __Pyx_RaiseArgtupleInvalid("triangular", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3120; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("triangular", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3153; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
case 2:
values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__right);
if (likely(values[2])) kw_args--;
else {
- __Pyx_RaiseArgtupleInvalid("triangular", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3120; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("triangular", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3153; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
case 3:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[3] = value; kw_args--; }
+ if (value) { values[3] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "triangular") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3120; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "triangular") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3153; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_left = values[0];
__pyx_v_mode = values[1];
@@ -13496,21 +13131,17 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_triangular(PyObject *__pyx_v_sel
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("triangular", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3120; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("triangular", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3153; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.triangular");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_left);
- __Pyx_INCREF(__pyx_v_mode);
- __Pyx_INCREF(__pyx_v_right);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_oleft = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_omode = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_oright = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":3180
+ /* "mtrand.pyx":3213
* cdef double fleft, fmode, fright
*
* fleft = PyFloat_AsDouble(left) # <<<<<<<<<<<<<<
@@ -13519,7 +13150,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_triangular(PyObject *__pyx_v_sel
*/
__pyx_v_fleft = PyFloat_AsDouble(__pyx_v_left);
- /* "mtrand.pyx":3181
+ /* "mtrand.pyx":3214
*
* fleft = PyFloat_AsDouble(left)
* fright = PyFloat_AsDouble(right) # <<<<<<<<<<<<<<
@@ -13528,7 +13159,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_triangular(PyObject *__pyx_v_sel
*/
__pyx_v_fright = PyFloat_AsDouble(__pyx_v_right);
- /* "mtrand.pyx":3182
+ /* "mtrand.pyx":3215
* fleft = PyFloat_AsDouble(left)
* fright = PyFloat_AsDouble(right)
* fmode = PyFloat_AsDouble(mode) # <<<<<<<<<<<<<<
@@ -13537,7 +13168,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_triangular(PyObject *__pyx_v_sel
*/
__pyx_v_fmode = PyFloat_AsDouble(__pyx_v_mode);
- /* "mtrand.pyx":3183
+ /* "mtrand.pyx":3216
* fright = PyFloat_AsDouble(right)
* fmode = PyFloat_AsDouble(mode)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -13547,7 +13178,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_triangular(PyObject *__pyx_v_sel
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":3184
+ /* "mtrand.pyx":3217
* fmode = PyFloat_AsDouble(mode)
* if not PyErr_Occurred():
* if fleft > fmode: # <<<<<<<<<<<<<<
@@ -13557,29 +13188,23 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_triangular(PyObject *__pyx_v_sel
__pyx_t_1 = (__pyx_v_fleft > __pyx_v_fmode);
if (__pyx_t_1) {
- /* "mtrand.pyx":3185
+ /* "mtrand.pyx":3218
* if not PyErr_Occurred():
* if fleft > fmode:
* raise ValueError("left > mode") # <<<<<<<<<<<<<<
* if fmode > fright:
* raise ValueError("mode > right")
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_102), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_37));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_37));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_37));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":3186
+ /* "mtrand.pyx":3219
* if fleft > fmode:
* raise ValueError("left > mode")
* if fmode > fright: # <<<<<<<<<<<<<<
@@ -13589,29 +13214,23 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_triangular(PyObject *__pyx_v_sel
__pyx_t_1 = (__pyx_v_fmode > __pyx_v_fright);
if (__pyx_t_1) {
- /* "mtrand.pyx":3187
+ /* "mtrand.pyx":3220
* raise ValueError("left > mode")
* if fmode > fright:
* raise ValueError("mode > right") # <<<<<<<<<<<<<<
* if fleft == fright:
* raise ValueError("left == right")
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_38));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_38));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_38));
- __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_104), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":3188
+ /* "mtrand.pyx":3221
* if fmode > fright:
* raise ValueError("mode > right")
* if fleft == fright: # <<<<<<<<<<<<<<
@@ -13621,29 +13240,23 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_triangular(PyObject *__pyx_v_sel
__pyx_t_1 = (__pyx_v_fleft == __pyx_v_fright);
if (__pyx_t_1) {
- /* "mtrand.pyx":3189
+ /* "mtrand.pyx":3222
* raise ValueError("mode > right")
* if fleft == fright:
* raise ValueError("left == right") # <<<<<<<<<<<<<<
* return cont3_array_sc(self.internal_state, rk_triangular, size, fleft,
* fmode, fright)
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_106), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_39));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_39));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_39));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L9;
}
__pyx_L9:;
- /* "mtrand.pyx":3190
+ /* "mtrand.pyx":3223
* if fleft == fright:
* raise ValueError("left == right")
* return cont3_array_sc(self.internal_state, rk_triangular, size, fleft, # <<<<<<<<<<<<<<
@@ -13652,23 +13265,23 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_triangular(PyObject *__pyx_v_sel
*/
__Pyx_XDECREF(__pyx_r);
- /* "mtrand.pyx":3191
+ /* "mtrand.pyx":3224
* raise ValueError("left == right")
* return cont3_array_sc(self.internal_state, rk_triangular, size, fleft,
* fmode, fright) # <<<<<<<<<<<<<<
*
* PyErr_Clear()
*/
- __pyx_t_3 = __pyx_f_6mtrand_cont3_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_triangular, __pyx_v_size, __pyx_v_fleft, __pyx_v_fmode, __pyx_v_fright); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3190; __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_cont3_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_triangular, __pyx_v_size, __pyx_v_fleft, __pyx_v_fmode, __pyx_v_fright); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3223; __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_L6;
}
__pyx_L6:;
- /* "mtrand.pyx":3193
+ /* "mtrand.pyx":3226
* fmode, fright)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -13677,241 +13290,223 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_triangular(PyObject *__pyx_v_sel
*/
PyErr_Clear();
- /* "mtrand.pyx":3194
+ /* "mtrand.pyx":3227
*
* PyErr_Clear()
* oleft = <ndarray>PyArray_FROM_OTF(left, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* omode = <ndarray>PyArray_FROM_OTF(mode, NPY_DOUBLE, NPY_ALIGNED)
* oright = <ndarray>PyArray_FROM_OTF(right, NPY_DOUBLE, NPY_ALIGNED)
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_left, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_left, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_oleft));
- __pyx_v_oleft = ((PyArrayObject *)__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_oleft = ((PyArrayObject *)__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":3195
+ /* "mtrand.pyx":3228
* PyErr_Clear()
* oleft = <ndarray>PyArray_FROM_OTF(left, NPY_DOUBLE, NPY_ALIGNED)
* omode = <ndarray>PyArray_FROM_OTF(mode, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* oright = <ndarray>PyArray_FROM_OTF(right, NPY_DOUBLE, NPY_ALIGNED)
*
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_mode, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_mode, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_omode));
- __pyx_v_omode = ((PyArrayObject *)__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_omode = ((PyArrayObject *)__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":3196
+ /* "mtrand.pyx":3229
* oleft = <ndarray>PyArray_FROM_OTF(left, NPY_DOUBLE, NPY_ALIGNED)
* omode = <ndarray>PyArray_FROM_OTF(mode, NPY_DOUBLE, NPY_ALIGNED)
* oright = <ndarray>PyArray_FROM_OTF(right, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
*
* if np.any(np.greater(oleft, omode)):
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_right, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_right, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_oright));
- __pyx_v_oright = ((PyArrayObject *)__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_oright = ((PyArrayObject *)__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":3198
+ /* "mtrand.pyx":3231
* oright = <ndarray>PyArray_FROM_OTF(right, NPY_DOUBLE, NPY_ALIGNED)
*
* if np.any(np.greater(oleft, omode)): # <<<<<<<<<<<<<<
* raise ValueError("left > mode")
* if np.any(np.greater(omode, oright)):
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__greater); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__greater); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __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 = 3198; __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 = 3231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(((PyObject *)__pyx_v_oleft));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_oleft));
+ PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_oleft));
__Pyx_GIVEREF(((PyObject *)__pyx_v_oleft));
__Pyx_INCREF(((PyObject *)__pyx_v_omode));
- PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_omode));
+ PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_omode));
__Pyx_GIVEREF(((PyObject *)__pyx_v_omode));
- __pyx_t_5 = PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 3231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 3198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
+ __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 = 3231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
__Pyx_GIVEREF(__pyx_t_5);
__pyx_t_5 = 0;
- __pyx_t_5 = PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 3231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_DECREF(__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 = 3198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3199
+ /* "mtrand.pyx":3232
*
* if np.any(np.greater(oleft, omode)):
* raise ValueError("left > mode") # <<<<<<<<<<<<<<
* if np.any(np.greater(omode, oright)):
* raise ValueError("mode > right")
*/
- __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_107), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_37));
- PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_37));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_37));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_5, 0, 0);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L10;
}
__pyx_L10:;
- /* "mtrand.pyx":3200
+ /* "mtrand.pyx":3233
* if np.any(np.greater(oleft, omode)):
* raise ValueError("left > mode")
* if np.any(np.greater(omode, oright)): # <<<<<<<<<<<<<<
* raise ValueError("mode > right")
* if np.any(np.equal(oleft, oright)):
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3233; __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_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__greater); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3233; __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 = 3200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+ __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_5);
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__greater); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
+ __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 = 3233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(((PyObject *)__pyx_v_omode));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_omode));
+ PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_omode));
__Pyx_GIVEREF(((PyObject *)__pyx_v_omode));
__Pyx_INCREF(((PyObject *)__pyx_v_oright));
- PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_oright));
+ PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_v_oright));
__Pyx_GIVEREF(((PyObject *)__pyx_v_oright));
- __pyx_t_4 = PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3200; __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 = 3233; __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_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
+ __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 = 3233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__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_5, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 3233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 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 = 3233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3201
+ /* "mtrand.pyx":3234
* raise ValueError("left > mode")
* if np.any(np.greater(omode, oright)):
* raise ValueError("mode > right") # <<<<<<<<<<<<<<
* if np.any(np.equal(oleft, oright)):
* raise ValueError("left == right")
*/
- __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_108), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3234; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_38));
- PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_kp_s_38));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_38));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_4, 0, 0);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3234; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L11;
}
__pyx_L11:;
- /* "mtrand.pyx":3202
+ /* "mtrand.pyx":3235
* if np.any(np.greater(omode, oright)):
* raise ValueError("mode > right")
* if np.any(np.equal(oleft, oright)): # <<<<<<<<<<<<<<
* raise ValueError("left == right")
* return cont3_array(self.internal_state, rk_triangular, size, oleft,
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3235; __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_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__equal); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__any); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __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 = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_2 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__equal); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __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 = 3235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
__Pyx_INCREF(((PyObject *)__pyx_v_oleft));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_oleft));
+ PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_oleft));
__Pyx_GIVEREF(((PyObject *)__pyx_v_oleft));
__Pyx_INCREF(((PyObject *)__pyx_v_oright));
- PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_oright));
+ PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_v_oright));
__Pyx_GIVEREF(((PyObject *)__pyx_v_oright));
- __pyx_t_2 = PyObject_Call(__pyx_t_5, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_DECREF(__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 = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 3235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
- __Pyx_GIVEREF(__pyx_t_2);
- __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __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 = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 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 = 3235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__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 = 3235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __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 = 3235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3203
+ /* "mtrand.pyx":3236
* raise ValueError("mode > right")
* if np.any(np.equal(oleft, oright)):
* raise ValueError("left == right") # <<<<<<<<<<<<<<
* return cont3_array(self.internal_state, rk_triangular, size, oleft,
* omode, oright)
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_39));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_39));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_39));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_109), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_Raise(__pyx_t_3, 0, 0);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L12;
}
__pyx_L12:;
- /* "mtrand.pyx":3204
+ /* "mtrand.pyx":3237
* if np.any(np.equal(oleft, oright)):
* raise ValueError("left == right")
* return cont3_array(self.internal_state, rk_triangular, size, oleft, # <<<<<<<<<<<<<<
@@ -13920,14 +13515,14 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_triangular(PyObject *__pyx_v_sel
*/
__Pyx_XDECREF(__pyx_r);
- /* "mtrand.pyx":3205
+ /* "mtrand.pyx":3238
* raise ValueError("left == right")
* return cont3_array(self.internal_state, rk_triangular, size, oleft,
* omode, oright) # <<<<<<<<<<<<<<
*
* # Complicated, discrete distributions:
*/
- __pyx_t_3 = __pyx_f_6mtrand_cont3_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_triangular, __pyx_v_size, __pyx_v_oleft, __pyx_v_omode, __pyx_v_oright); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __pyx_f_6mtrand_cont3_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_triangular, __pyx_v_size, __pyx_v_oleft, __pyx_v_omode, __pyx_v_oright); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__pyx_r = __pyx_t_3;
__pyx_t_3 = 0;
@@ -13946,17 +13541,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_triangular(PyObject *__pyx_v_sel
__Pyx_DECREF((PyObject *)__pyx_v_oleft);
__Pyx_DECREF((PyObject *)__pyx_v_omode);
__Pyx_DECREF((PyObject *)__pyx_v_oright);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_left);
- __Pyx_DECREF(__pyx_v_mode);
- __Pyx_DECREF(__pyx_v_right);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":3208
+/* "mtrand.pyx":3241
*
* # Complicated, discrete distributions:
* def binomial(self, n, p, size=None): # <<<<<<<<<<<<<<
@@ -13964,9 +13554,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_triangular(PyObject *__pyx_v_sel
* binomial(n, p, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_binomial(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_binomial[] = "\n"" binomial(n, p, size=None)\n""\n"" Draw samples from a binomial distribution.\n""\n"" Samples are drawn from a Binomial distribution with specified\n"" parameters, n trials and p probability of success where\n"" n an integer > 0 and p is in the interval [0,1]. (n may be\n"" input as a float, but it is truncated to an integer in use)\n""\n"" Parameters\n"" ----------\n"" n : float (but truncated to an integer)\n"" parameter, > 0.\n"" p : float\n"" parameter, >= 0 and <=1.\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.binom : probability density function,\n"" distribution or cumulative density function, etc.\n""\n"" Notes\n"" -----\n"" The probability density for the Binomial distribution is\n""\n"" .. math:: P(N) = \\binom{n}{N}p^N(1-p)^{n-N},\n""\n"" where :math:`n` is the number of trials, :math:`p` is the probability\n"" of success, and :math:`N` is the number of successes.\n""\n"" When estimating the standard error of a proportion in a population by\n"" using a random sample, the normal distribution works well unless the\n"" product p*n <=5, where p = population proportion estimate, and n =\n"" number of samples, in which case the binomial distribution is used\n"" instead. For example, a sample of 15 people shows 4 who are left\n"" handed, and 11 who are right handed. Then p = 4/15 = 27%. 0.27*15 = 4,\n"" so the binomial distribution should be used in this case.\n""\n"" References\n"" ----------\n"" .. [1] Dalgaard, Peter, \"Introductory Statistics with R\",\n"" Springer-Verlag, 2002.\n"" .. [2] Glantz, Stanton A. \"Primer of Biostatistics.\", McGraw-Hill,\n"" Fifth Edition, 2002.\n"" .. [3] Lentner, Marvin, \"Elementary Applied Statistics\", Bogden\n"" and Quigley, 1972.\n"" .. [4] Weisstein, Eric W. \"Binomial Distribution.\" From MathWorld--A\n"" Wolfram Web Resource.\n"" http://mathworld.wolfram.com/BinomialDistribution.html\n"" .. [5] Wikipedia, \"Binomial-distribution\",\n"" http://en.wikipedia.org/wiki/Binomial_distribution\n""\n"" Examples\n"" --------\n"" Draw samples from the distribution:\n""\n"" >>> n, p = 10, .5 # number of trials, probability of each trial\n"" >>> s = np.random.binomial(n, p, 1000)\n"" # result of flipping a coin 10 times, tested 1000 times.\n""\n"" A real world example. A company drills 9 wild-cat oil exploration\n"" wells, each with an estimated probability of success of 0.1. All nine\n"" wells fail. What is the probability of that happening?\n""\n"" Let's do 20,000 trials of the model, and count the number that\n"" generate zero positive results.\n""\n"" >>> sum(np.random.binomial(9,0.1,20000)==0)/20000.\n"" answer = 0.38885, or 38%.\n""\n"" ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_binomial(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_40binomial(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_40binomial[] = "\n binomial(n, p, size=None)\n\n Draw samples from a binomial distribution.\n\n Samples are drawn from a Binomial distribution with specified\n parameters, n trials and p probability of success where\n n an integer > 0 and p is in the interval [0,1]. (n may be\n input as a float, but it is truncated to an integer in use)\n\n Parameters\n ----------\n n : float (but truncated to an integer)\n parameter, > 0.\n p : float\n parameter, >= 0 and <=1.\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.binom : probability density function,\n distribution or cumulative density function, etc.\n\n Notes\n -----\n The probability density for the Binomial distribution is\n\n .. math:: P(N) = \\binom{n}{N}p^N(1-p)^{n-N},\n\n where :math:`n` is the number of trials, :math:`p` is the probability\n of success, and :math:`N` is the number of successes.\n\n When estimating the standard error of a proportion in a population by\n using a random sample, the normal distribution works well unless the\n product p*n <=5, where p = population proportion estimate, and n =\n number of samples, in which case the binomial distribution is used\n instead. For example, a sample of 15 people shows 4 who are left\n handed, and 11 who are right handed. Then p = 4/15 = 27%. 0.27*15 = 4,\n so the binomial distribution should be used in this case.\n\n References\n ----------\n .. [1] Dalgaard, Peter, \"Introductory Statistics with R\",\n Springer-Verlag, 2002.\n "" .. [2] Glantz, Stanton A. \"Primer of Biostatistics.\", McGraw-Hill,\n Fifth Edition, 2002.\n .. [3] Lentner, Marvin, \"Elementary Applied Statistics\", Bogden\n and Quigley, 1972.\n .. [4] Weisstein, Eric W. \"Binomial Distribution.\" From MathWorld--A\n Wolfram Web Resource.\n http://mathworld.wolfram.com/BinomialDistribution.html\n .. [5] Wikipedia, \"Binomial-distribution\",\n http://en.wikipedia.org/wiki/Binomial_distribution\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> n, p = 10, .5 # number of trials, probability of each trial\n >>> s = np.random.binomial(n, p, 1000)\n # result of flipping a coin 10 times, tested 1000 times.\n\n A real world example. A company drills 9 wild-cat oil exploration\n wells, each with an estimated probability of success of 0.1. All nine\n wells fail. What is the probability of that happening?\n\n Let's do 20,000 trials of the model, and count the number that\n generate zero positive results.\n\n >>> sum(np.random.binomial(9,0.1,20000)==0)/20000.\n answer = 0.38885, or 38%.\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_40binomial(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_n = 0;
PyObject *__pyx_v_p = 0;
PyObject *__pyx_v_size = 0;
@@ -14002,16 +13592,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_binomial(PyObject *__pyx_v_self,
values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__p);
if (likely(values[1])) kw_args--;
else {
- __Pyx_RaiseArgtupleInvalid("binomial", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3208; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("binomial", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3241; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
case 2:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[2] = value; kw_args--; }
+ if (value) { values[2] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "binomial") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3208; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "binomial") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3241; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_n = values[0];
__pyx_v_p = values[1];
@@ -14030,19 +13620,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_binomial(PyObject *__pyx_v_self,
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("binomial", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3208; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("binomial", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3241; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.binomial");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_n);
- __Pyx_INCREF(__pyx_v_p);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_on = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_op = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":3293
+ /* "mtrand.pyx":3326
* cdef double fp
*
* fp = PyFloat_AsDouble(p) # <<<<<<<<<<<<<<
@@ -14051,7 +13638,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_binomial(PyObject *__pyx_v_self,
*/
__pyx_v_fp = PyFloat_AsDouble(__pyx_v_p);
- /* "mtrand.pyx":3294
+ /* "mtrand.pyx":3327
*
* fp = PyFloat_AsDouble(p)
* ln = PyInt_AsLong(n) # <<<<<<<<<<<<<<
@@ -14060,7 +13647,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_binomial(PyObject *__pyx_v_self,
*/
__pyx_v_ln = PyInt_AsLong(__pyx_v_n);
- /* "mtrand.pyx":3295
+ /* "mtrand.pyx":3328
* fp = PyFloat_AsDouble(p)
* ln = PyInt_AsLong(n)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -14070,7 +13657,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_binomial(PyObject *__pyx_v_self,
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":3296
+ /* "mtrand.pyx":3329
* ln = PyInt_AsLong(n)
* if not PyErr_Occurred():
* if ln <= 0: # <<<<<<<<<<<<<<
@@ -14080,92 +13667,74 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_binomial(PyObject *__pyx_v_self,
__pyx_t_1 = (__pyx_v_ln <= 0);
if (__pyx_t_1) {
- /* "mtrand.pyx":3297
+ /* "mtrand.pyx":3330
* if not PyErr_Occurred():
* if ln <= 0:
* raise ValueError("n <= 0") # <<<<<<<<<<<<<<
* if fp < 0:
* raise ValueError("p < 0")
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_111), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_40));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_40));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_40));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":3298
+ /* "mtrand.pyx":3331
* if ln <= 0:
* raise ValueError("n <= 0")
* if fp < 0: # <<<<<<<<<<<<<<
* raise ValueError("p < 0")
* elif fp > 1:
*/
- __pyx_t_1 = (__pyx_v_fp < 0);
+ __pyx_t_1 = (__pyx_v_fp < 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":3299
+ /* "mtrand.pyx":3332
* raise ValueError("n <= 0")
* if fp < 0:
* raise ValueError("p < 0") # <<<<<<<<<<<<<<
* elif fp > 1:
* raise ValueError("p > 1")
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_41));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_41));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_41));
- __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_113), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
- /* "mtrand.pyx":3300
+ /* "mtrand.pyx":3333
* if fp < 0:
* raise ValueError("p < 0")
* elif fp > 1: # <<<<<<<<<<<<<<
* raise ValueError("p > 1")
* return discnp_array_sc(self.internal_state, rk_binomial, size, ln, fp)
*/
- __pyx_t_1 = (__pyx_v_fp > 1);
+ __pyx_t_1 = (__pyx_v_fp > 1.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":3301
+ /* "mtrand.pyx":3334
* raise ValueError("p < 0")
* elif fp > 1:
* raise ValueError("p > 1") # <<<<<<<<<<<<<<
* return discnp_array_sc(self.internal_state, rk_binomial, size, ln, fp)
*
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_115), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_42));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_42));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_42));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":3302
+ /* "mtrand.pyx":3335
* elif fp > 1:
* raise ValueError("p > 1")
* return discnp_array_sc(self.internal_state, rk_binomial, size, ln, fp) # <<<<<<<<<<<<<<
@@ -14173,16 +13742,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_binomial(PyObject *__pyx_v_self,
* PyErr_Clear()
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = __pyx_f_6mtrand_discnp_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_binomial, __pyx_v_size, __pyx_v_ln, __pyx_v_fp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3302; __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_discnp_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_binomial, __pyx_v_size, __pyx_v_ln, __pyx_v_fp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3335; __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_L6;
}
__pyx_L6:;
- /* "mtrand.pyx":3304
+ /* "mtrand.pyx":3337
* return discnp_array_sc(self.internal_state, rk_binomial, size, ln, fp)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -14191,227 +13760,209 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_binomial(PyObject *__pyx_v_self,
*/
PyErr_Clear();
- /* "mtrand.pyx":3306
+ /* "mtrand.pyx":3339
* PyErr_Clear()
*
* on = <ndarray>PyArray_FROM_OTF(n, NPY_LONG, NPY_ALIGNED) # <<<<<<<<<<<<<<
* op = <ndarray>PyArray_FROM_OTF(p, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(n, 0)):
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_n, NPY_LONG, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_n, NPY_LONG, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_on));
- __pyx_v_on = ((PyArrayObject *)__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_on = ((PyArrayObject *)__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":3307
+ /* "mtrand.pyx":3340
*
* on = <ndarray>PyArray_FROM_OTF(n, NPY_LONG, NPY_ALIGNED)
* op = <ndarray>PyArray_FROM_OTF(p, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less_equal(n, 0)):
* raise ValueError("n <= 0")
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_p, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_p, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_op));
- __pyx_v_op = ((PyArrayObject *)__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_op = ((PyArrayObject *)__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":3308
+ /* "mtrand.pyx":3341
* on = <ndarray>PyArray_FROM_OTF(n, NPY_LONG, NPY_ALIGNED)
* op = <ndarray>PyArray_FROM_OTF(p, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(n, 0)): # <<<<<<<<<<<<<<
* raise ValueError("n <= 0")
* if np.any(np.less(p, 0)):
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __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 = 3308; __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 = 3341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_n);
- PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_n);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_n);
__Pyx_GIVEREF(__pyx_v_n);
__Pyx_INCREF(__pyx_int_0);
- PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0);
+ PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_0);
__Pyx_GIVEREF(__pyx_int_0);
- __pyx_t_5 = PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 3341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 3308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
+ __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 = 3341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
__Pyx_GIVEREF(__pyx_t_5);
__pyx_t_5 = 0;
- __pyx_t_5 = PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 3341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_DECREF(__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 = 3308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3309
+ /* "mtrand.pyx":3342
* op = <ndarray>PyArray_FROM_OTF(p, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(n, 0)):
* raise ValueError("n <= 0") # <<<<<<<<<<<<<<
* if np.any(np.less(p, 0)):
* raise ValueError("p < 0")
*/
- __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3309; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_116), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_40));
- PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_40));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_40));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3309; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_5, 0, 0);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3309; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L9;
}
__pyx_L9:;
- /* "mtrand.pyx":3310
+ /* "mtrand.pyx":3343
* if np.any(np.less_equal(n, 0)):
* raise ValueError("n <= 0")
* if np.any(np.less(p, 0)): # <<<<<<<<<<<<<<
* raise ValueError("p < 0")
* if np.any(np.greater(p, 1)):
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3343; __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_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3343; __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 = 3310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+ __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_5);
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__less); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
+ __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 = 3343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(__pyx_v_p);
- PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_p);
+ PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_p);
__Pyx_GIVEREF(__pyx_v_p);
__Pyx_INCREF(__pyx_int_0);
- PyTuple_SET_ITEM(__pyx_t_3, 1, __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, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3310; __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 = 3343; __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_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
+ __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 = 3343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__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_5, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 3343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 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 = 3343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3311
+ /* "mtrand.pyx":3344
* raise ValueError("n <= 0")
* if np.any(np.less(p, 0)):
* raise ValueError("p < 0") # <<<<<<<<<<<<<<
* if np.any(np.greater(p, 1)):
* raise ValueError("p > 1")
*/
- __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_117), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_41));
- PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_kp_s_41));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_41));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_4, 0, 0);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L10;
}
__pyx_L10:;
- /* "mtrand.pyx":3312
+ /* "mtrand.pyx":3345
* if np.any(np.less(p, 0)):
* raise ValueError("p < 0")
* if np.any(np.greater(p, 1)): # <<<<<<<<<<<<<<
* raise ValueError("p > 1")
* return discnp_array(self.internal_state, rk_binomial, size, on, op)
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3345; __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_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__greater); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__any); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __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 = 3312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_2 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__greater); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __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 = 3345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
__Pyx_INCREF(__pyx_v_p);
- PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_p);
+ PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_p);
__Pyx_GIVEREF(__pyx_v_p);
__Pyx_INCREF(__pyx_int_1);
- PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_1);
+ PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_1);
__Pyx_GIVEREF(__pyx_int_1);
- __pyx_t_2 = PyObject_Call(__pyx_t_5, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_DECREF(__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 = 3312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 3345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
- __Pyx_GIVEREF(__pyx_t_2);
- __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __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 = 3312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 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 = 3345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__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 = 3345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __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 = 3345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3313
+ /* "mtrand.pyx":3346
* raise ValueError("p < 0")
* if np.any(np.greater(p, 1)):
* raise ValueError("p > 1") # <<<<<<<<<<<<<<
* return discnp_array(self.internal_state, rk_binomial, size, on, op)
*
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_42));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_42));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_42));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_118), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_Raise(__pyx_t_3, 0, 0);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L11;
}
__pyx_L11:;
- /* "mtrand.pyx":3314
+ /* "mtrand.pyx":3347
* if np.any(np.greater(p, 1)):
* raise ValueError("p > 1")
* return discnp_array(self.internal_state, rk_binomial, size, on, op) # <<<<<<<<<<<<<<
@@ -14419,7 +13970,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_binomial(PyObject *__pyx_v_self,
* def negative_binomial(self, n, p, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = __pyx_f_6mtrand_discnp_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_binomial, __pyx_v_size, __pyx_v_on, __pyx_v_op); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __pyx_f_6mtrand_discnp_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_binomial, __pyx_v_size, __pyx_v_on, __pyx_v_op); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__pyx_r = __pyx_t_3;
__pyx_t_3 = 0;
@@ -14437,16 +13988,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_binomial(PyObject *__pyx_v_self,
__pyx_L0:;
__Pyx_DECREF((PyObject *)__pyx_v_on);
__Pyx_DECREF((PyObject *)__pyx_v_op);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_n);
- __Pyx_DECREF(__pyx_v_p);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":3316
+/* "mtrand.pyx":3349
* return discnp_array(self.internal_state, rk_binomial, size, on, op)
*
* def negative_binomial(self, n, p, size=None): # <<<<<<<<<<<<<<
@@ -14454,9 +14001,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_binomial(PyObject *__pyx_v_self,
* negative_binomial(n, p, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_negative_binomial(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_negative_binomial[] = "\n"" negative_binomial(n, p, size=None)\n""\n"" Draw samples from a negative_binomial distribution.\n""\n"" Samples are drawn from a negative_Binomial distribution with specified\n"" parameters, `n` trials and `p` probability of success where `n` is an\n"" integer > 0 and `p` is in the interval [0, 1].\n""\n"" Parameters\n"" ----------\n"" n : int\n"" Parameter, > 0.\n"" p : float\n"" Parameter, >= 0 and <=1.\n"" size : int or tuple of ints\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 : int or ndarray of ints\n"" Drawn samples.\n""\n"" Notes\n"" -----\n"" The probability density for the Negative Binomial distribution is\n""\n"" .. math:: P(N;n,p) = \\binom{N+n-1}{n-1}p^{n}(1-p)^{N},\n""\n"" where :math:`n-1` is the number of successes, :math:`p` is the probability\n"" of success, and :math:`N+n-1` is the number of trials.\n""\n"" The negative binomial distribution gives the probability of n-1 successes\n"" and N failures in N+n-1 trials, and success on the (N+n)th trial.\n""\n"" If one throws a die repeatedly until the third time a \"1\" appears, then the\n"" probability distribution of the number of non-\"1\"s that appear before the\n"" third \"1\" is a negative binomial distribution.\n""\n"" References\n"" ----------\n"" .. [1] Weisstein, Eric W. \"Negative Binomial Distribution.\" From\n"" MathWorld--A Wolfram Web Resource.\n"" http://mathworld.wolfram.com/NegativeBinomialDistribution.html\n"" .. [2] Wikipedia, \"Negative binomial distribution\",\n"" http://en.wikipedia.org/wiki/Negative_binomial_distribution\n""\n"" Examples\n"" --------\n"" Draw samples from the distribution:\n""\n"" A real world example. A company drills wild-cat oil exploration wells, each\n"" with an estimated probability of success of 0.1. What is the probability\n"" of having one success for each successive well, that is what is the\n"" probability of a single success after drilling 5 wells, after 6 wells,\n"" etc.?\n""\n"" >>> s = np.random.negative_binomial(1, 0.1, 100000)\n"" >>> for i in range(1, 11):\n"" ... probability = sum(s<i) / 100000.\n"" ... print i, \"wells drilled, probability of one success =\", probability\n""\n"" ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_negative_binomial(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_41negative_binomial(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_41negative_binomial[] = "\n negative_binomial(n, p, size=None)\n\n Draw samples from a negative_binomial distribution.\n\n Samples are drawn from a negative_Binomial distribution with specified\n parameters, `n` trials and `p` probability of success where `n` is an\n integer > 0 and `p` is in the interval [0, 1].\n\n Parameters\n ----------\n n : int\n Parameter, > 0.\n p : float\n Parameter, >= 0 and <=1.\n size : int or tuple of ints\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 : int or ndarray of ints\n Drawn samples.\n\n Notes\n -----\n The probability density for the Negative Binomial distribution is\n\n .. math:: P(N;n,p) = \\binom{N+n-1}{n-1}p^{n}(1-p)^{N},\n\n where :math:`n-1` is the number of successes, :math:`p` is the probability\n of success, and :math:`N+n-1` is the number of trials.\n\n The negative binomial distribution gives the probability of n-1 successes\n and N failures in N+n-1 trials, and success on the (N+n)th trial.\n\n If one throws a die repeatedly until the third time a \"1\" appears, then the\n probability distribution of the number of non-\"1\"s that appear before the\n third \"1\" is a negative binomial distribution.\n\n References\n ----------\n .. [1] Weisstein, Eric W. \"Negative Binomial Distribution.\" From\n MathWorld--A Wolfram Web Resource.\n http://mathworld.wolfram.com/NegativeBinomialDistribution.html\n .. [2] Wikipedia, \"Negative binomial distribution\",\n http://en.wikipedia.org/wiki/Negative_binomial_distribution\n\n Examples\n --------\n Draw samples from the distribution:\n\n A real world example. A company drills wild-cat oil exploration well""s, each\n with an estimated probability of success of 0.1. What is the probability\n of having one success for each successive well, that is what is the\n probability of a single success after drilling 5 wells, after 6 wells,\n etc.?\n\n >>> s = np.random.negative_binomial(1, 0.1, 100000)\n >>> for i in range(1, 11):\n ... probability = sum(s<i) / 100000.\n ... print i, \"wells drilled, probability of one success =\", probability\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_41negative_binomial(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_n = 0;
PyObject *__pyx_v_p = 0;
PyObject *__pyx_v_size = 0;
@@ -14492,16 +14039,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_negative_binomial(PyObject *__py
values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__p);
if (likely(values[1])) kw_args--;
else {
- __Pyx_RaiseArgtupleInvalid("negative_binomial", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3316; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("negative_binomial", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3349; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
case 2:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[2] = value; kw_args--; }
+ if (value) { values[2] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "negative_binomial") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3316; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "negative_binomial") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3349; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_n = values[0];
__pyx_v_p = values[1];
@@ -14520,19 +14067,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_negative_binomial(PyObject *__py
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("negative_binomial", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3316; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("negative_binomial", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3349; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.negative_binomial");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_n);
- __Pyx_INCREF(__pyx_v_p);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_on = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_op = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":3386
+ /* "mtrand.pyx":3419
* cdef double fp
*
* fp = PyFloat_AsDouble(p) # <<<<<<<<<<<<<<
@@ -14541,7 +14085,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_negative_binomial(PyObject *__py
*/
__pyx_v_fp = PyFloat_AsDouble(__pyx_v_p);
- /* "mtrand.pyx":3387
+ /* "mtrand.pyx":3420
*
* fp = PyFloat_AsDouble(p)
* fn = PyFloat_AsDouble(n) # <<<<<<<<<<<<<<
@@ -14550,7 +14094,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_negative_binomial(PyObject *__py
*/
__pyx_v_fn = PyFloat_AsDouble(__pyx_v_n);
- /* "mtrand.pyx":3388
+ /* "mtrand.pyx":3421
* fp = PyFloat_AsDouble(p)
* fn = PyFloat_AsDouble(n)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -14560,102 +14104,84 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_negative_binomial(PyObject *__py
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":3389
+ /* "mtrand.pyx":3422
* fn = PyFloat_AsDouble(n)
* if not PyErr_Occurred():
* if fn <= 0: # <<<<<<<<<<<<<<
* raise ValueError("n <= 0")
* if fp < 0:
*/
- __pyx_t_1 = (__pyx_v_fn <= 0);
+ __pyx_t_1 = (__pyx_v_fn <= 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":3390
+ /* "mtrand.pyx":3423
* if not PyErr_Occurred():
* if fn <= 0:
* raise ValueError("n <= 0") # <<<<<<<<<<<<<<
* if fp < 0:
* raise ValueError("p < 0")
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_119), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_40));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_40));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_40));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":3391
+ /* "mtrand.pyx":3424
* if fn <= 0:
* raise ValueError("n <= 0")
* if fp < 0: # <<<<<<<<<<<<<<
* raise ValueError("p < 0")
* elif fp > 1:
*/
- __pyx_t_1 = (__pyx_v_fp < 0);
+ __pyx_t_1 = (__pyx_v_fp < 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":3392
+ /* "mtrand.pyx":3425
* raise ValueError("n <= 0")
* if fp < 0:
* raise ValueError("p < 0") # <<<<<<<<<<<<<<
* elif fp > 1:
* raise ValueError("p > 1")
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_41));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_41));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_41));
- __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_120), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
- /* "mtrand.pyx":3393
+ /* "mtrand.pyx":3426
* if fp < 0:
* raise ValueError("p < 0")
* elif fp > 1: # <<<<<<<<<<<<<<
* raise ValueError("p > 1")
* return discdd_array_sc(self.internal_state, rk_negative_binomial,
*/
- __pyx_t_1 = (__pyx_v_fp > 1);
+ __pyx_t_1 = (__pyx_v_fp > 1.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":3394
+ /* "mtrand.pyx":3427
* raise ValueError("p < 0")
* elif fp > 1:
* raise ValueError("p > 1") # <<<<<<<<<<<<<<
* return discdd_array_sc(self.internal_state, rk_negative_binomial,
* size, fn, fp)
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3394; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_121), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3427; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_42));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_42));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_42));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3394; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3394; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3427; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":3395
+ /* "mtrand.pyx":3428
* elif fp > 1:
* raise ValueError("p > 1")
* return discdd_array_sc(self.internal_state, rk_negative_binomial, # <<<<<<<<<<<<<<
@@ -14664,23 +14190,23 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_negative_binomial(PyObject *__py
*/
__Pyx_XDECREF(__pyx_r);
- /* "mtrand.pyx":3396
+ /* "mtrand.pyx":3429
* raise ValueError("p > 1")
* return discdd_array_sc(self.internal_state, rk_negative_binomial,
* size, fn, fp) # <<<<<<<<<<<<<<
*
* PyErr_Clear()
*/
- __pyx_t_3 = __pyx_f_6mtrand_discdd_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_negative_binomial, __pyx_v_size, __pyx_v_fn, __pyx_v_fp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3395; __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_discdd_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_negative_binomial, __pyx_v_size, __pyx_v_fn, __pyx_v_fp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3428; __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_L6;
}
__pyx_L6:;
- /* "mtrand.pyx":3398
+ /* "mtrand.pyx":3431
* size, fn, fp)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -14689,227 +14215,209 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_negative_binomial(PyObject *__py
*/
PyErr_Clear();
- /* "mtrand.pyx":3400
+ /* "mtrand.pyx":3433
* PyErr_Clear()
*
* on = <ndarray>PyArray_FROM_OTF(n, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* op = <ndarray>PyArray_FROM_OTF(p, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(n, 0)):
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_n, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_n, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3433; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_on));
- __pyx_v_on = ((PyArrayObject *)__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_on = ((PyArrayObject *)__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":3401
+ /* "mtrand.pyx":3434
*
* on = <ndarray>PyArray_FROM_OTF(n, NPY_DOUBLE, NPY_ALIGNED)
* op = <ndarray>PyArray_FROM_OTF(p, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less_equal(n, 0)):
* raise ValueError("n <= 0")
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_p, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_p, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3434; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_op));
- __pyx_v_op = ((PyArrayObject *)__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_op = ((PyArrayObject *)__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":3402
+ /* "mtrand.pyx":3435
* on = <ndarray>PyArray_FROM_OTF(n, NPY_DOUBLE, NPY_ALIGNED)
* op = <ndarray>PyArray_FROM_OTF(p, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(n, 0)): # <<<<<<<<<<<<<<
* raise ValueError("n <= 0")
* if np.any(np.less(p, 0)):
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __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 = 3402; __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 = 3435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_n);
- PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_n);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_n);
__Pyx_GIVEREF(__pyx_v_n);
__Pyx_INCREF(__pyx_int_0);
- PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0);
+ PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_0);
__Pyx_GIVEREF(__pyx_int_0);
- __pyx_t_5 = PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 3435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 3402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
+ __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 = 3435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
__Pyx_GIVEREF(__pyx_t_5);
__pyx_t_5 = 0;
- __pyx_t_5 = PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 3435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_DECREF(__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 = 3402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3403
+ /* "mtrand.pyx":3436
* op = <ndarray>PyArray_FROM_OTF(p, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(n, 0)):
* raise ValueError("n <= 0") # <<<<<<<<<<<<<<
* if np.any(np.less(p, 0)):
* raise ValueError("p < 0")
*/
- __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_122), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_40));
- PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_40));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_40));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_5, 0, 0);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L9;
}
__pyx_L9:;
- /* "mtrand.pyx":3404
+ /* "mtrand.pyx":3437
* if np.any(np.less_equal(n, 0)):
* raise ValueError("n <= 0")
* if np.any(np.less(p, 0)): # <<<<<<<<<<<<<<
* raise ValueError("p < 0")
* if np.any(np.greater(p, 1)):
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3437; __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_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3437; __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 = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+ __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_5);
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__less); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
+ __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 = 3437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(__pyx_v_p);
- PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_p);
+ PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_p);
__Pyx_GIVEREF(__pyx_v_p);
__Pyx_INCREF(__pyx_int_0);
- PyTuple_SET_ITEM(__pyx_t_3, 1, __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, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __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 = 3437; __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_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
+ __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 = 3437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__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_5, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 3437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 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 = 3437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3405
+ /* "mtrand.pyx":3438
* raise ValueError("n <= 0")
* if np.any(np.less(p, 0)):
* raise ValueError("p < 0") # <<<<<<<<<<<<<<
* if np.any(np.greater(p, 1)):
* raise ValueError("p > 1")
*/
- __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_123), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3438; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_41));
- PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_kp_s_41));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_41));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_4, 0, 0);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3438; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L10;
}
__pyx_L10:;
- /* "mtrand.pyx":3406
+ /* "mtrand.pyx":3439
* if np.any(np.less(p, 0)):
* raise ValueError("p < 0")
* if np.any(np.greater(p, 1)): # <<<<<<<<<<<<<<
* raise ValueError("p > 1")
* return discdd_array(self.internal_state, rk_negative_binomial, size,
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3439; __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_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__greater); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__any); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __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 = 3406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_2 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__greater); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __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 = 3439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
__Pyx_INCREF(__pyx_v_p);
- PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_p);
+ PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_p);
__Pyx_GIVEREF(__pyx_v_p);
__Pyx_INCREF(__pyx_int_1);
- PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_1);
+ PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_1);
__Pyx_GIVEREF(__pyx_int_1);
- __pyx_t_2 = PyObject_Call(__pyx_t_5, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_DECREF(__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 = 3406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 3439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
- __Pyx_GIVEREF(__pyx_t_2);
- __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __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 = 3406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 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 = 3439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__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 = 3439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __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 = 3439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3407
+ /* "mtrand.pyx":3440
* raise ValueError("p < 0")
* if np.any(np.greater(p, 1)):
* raise ValueError("p > 1") # <<<<<<<<<<<<<<
* return discdd_array(self.internal_state, rk_negative_binomial, size,
* on, op)
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_42));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_42));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_42));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_124), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_Raise(__pyx_t_3, 0, 0);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L11;
}
__pyx_L11:;
- /* "mtrand.pyx":3408
+ /* "mtrand.pyx":3441
* if np.any(np.greater(p, 1)):
* raise ValueError("p > 1")
* return discdd_array(self.internal_state, rk_negative_binomial, size, # <<<<<<<<<<<<<<
@@ -14918,14 +14426,14 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_negative_binomial(PyObject *__py
*/
__Pyx_XDECREF(__pyx_r);
- /* "mtrand.pyx":3409
+ /* "mtrand.pyx":3442
* raise ValueError("p > 1")
* return discdd_array(self.internal_state, rk_negative_binomial, size,
* on, op) # <<<<<<<<<<<<<<
*
* def poisson(self, lam=1.0, size=None):
*/
- __pyx_t_3 = __pyx_f_6mtrand_discdd_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_negative_binomial, __pyx_v_size, __pyx_v_on, __pyx_v_op); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3408; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __pyx_f_6mtrand_discdd_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_negative_binomial, __pyx_v_size, __pyx_v_on, __pyx_v_op); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__pyx_r = __pyx_t_3;
__pyx_t_3 = 0;
@@ -14943,16 +14451,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_negative_binomial(PyObject *__py
__pyx_L0:;
__Pyx_DECREF((PyObject *)__pyx_v_on);
__Pyx_DECREF((PyObject *)__pyx_v_op);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_n);
- __Pyx_DECREF(__pyx_v_p);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":3411
+/* "mtrand.pyx":3444
* on, op)
*
* def poisson(self, lam=1.0, size=None): # <<<<<<<<<<<<<<
@@ -14960,9 +14464,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_negative_binomial(PyObject *__py
* poisson(lam=1.0, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_poisson(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_poisson[] = "\n poisson(lam=1.0, size=None)\n\n Draw samples from a Poisson distribution.\n\n The Poisson distribution is the limit of the Binomial\n distribution for large N.\n\n Parameters\n ----------\n lam : float\n Expectation of interval, should be >= 0.\n size : int or tuple of ints, optional\n Output shape. If the given shape is, e.g., ``(m, n, k)``, then\n ``m * n * k`` samples are drawn.\n\n Notes\n -----\n The Poisson distribution\n\n .. math:: f(k; \\lambda)=\\frac{\\lambda^k e^{-\\lambda}}{k!}\n\n For events with an expected separation :math:`\\lambda` the Poisson\n distribution :math:`f(k; \\lambda)` describes the probability of\n :math:`k` events occurring within the observed interval :math:`\\lambda`.\n\n References\n ----------\n .. [1] Weisstein, Eric W. \"Poisson Distribution.\" From MathWorld--A Wolfram\n Web Resource. http://mathworld.wolfram.com/PoissonDistribution.html\n .. [2] Wikipedia, \"Poisson distribution\",\n http://en.wikipedia.org/wiki/Poisson_distribution\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> import numpy as np\n >>> s = np.random.poisson(5, 10000)\n\n Display histogram of the sample:\n\n >>> import matplotlib.pyplot as plt\n >>> count, bins, ignored = plt.hist(s, 14, normed=True)\n >>> plt.show()\n\n ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_poisson(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_42poisson(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_42poisson[] = "\n poisson(lam=1.0, size=None)\n\n Draw samples from a Poisson distribution.\n\n The Poisson distribution is the limit of the Binomial\n distribution for large N.\n\n Parameters\n ----------\n lam : float\n Expectation of interval, should be >= 0.\n size : int or tuple of ints, optional\n Output shape. If the given shape is, e.g., ``(m, n, k)``, then\n ``m * n * k`` samples are drawn.\n\n Notes\n -----\n The Poisson distribution\n\n .. math:: f(k; \\lambda)=\\frac{\\lambda^k e^{-\\lambda}}{k!}\n\n For events with an expected separation :math:`\\lambda` the Poisson\n distribution :math:`f(k; \\lambda)` describes the probability of\n :math:`k` events occurring within the observed interval :math:`\\lambda`.\n\n Because the output is limited to the range of the C long type, a\n ValueError is raised when `lam` is within 10 sigma of the maximum\n representable value.\n\n References\n ----------\n .. [1] Weisstein, Eric W. \"Poisson Distribution.\" From MathWorld--A Wolfram\n Web Resource. http://mathworld.wolfram.com/PoissonDistribution.html\n .. [2] Wikipedia, \"Poisson distribution\",\n http://en.wikipedia.org/wiki/Poisson_distribution\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> import numpy as np\n >>> s = np.random.poisson(5, 10000)\n\n Display histogram of the sample:\n\n >>> import matplotlib.pyplot as plt\n >>> count, bins, ignored = plt.hist(s, 14, normed=True)\n >>> plt.show()\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_42poisson(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_lam = 0;
PyObject *__pyx_v_size = 0;
PyArrayObject *__pyx_v_olam;
@@ -14978,7 +14482,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_poisson(PyObject *__pyx_v_self,
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
PyObject* values[2] = {0,0};
- values[0] = __pyx_k_43;
+ values[0] = __pyx_k_125;
values[1] = ((PyObject *)Py_None);
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
@@ -14988,23 +14492,23 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_poisson(PyObject *__pyx_v_self,
}
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 0:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__lam);
- if (unlikely(value)) { values[0] = value; kw_args--; }
+ if (value) { values[0] = value; kw_args--; }
}
case 1:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[1] = value; kw_args--; }
+ if (value) { values[1] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "poisson") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3411; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "poisson") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3444; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_lam = values[0];
__pyx_v_size = values[1];
} else {
- __pyx_v_lam = __pyx_k_43;
+ __pyx_v_lam = __pyx_k_125;
__pyx_v_size = ((PyObject *)Py_None);
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 2: __pyx_v_size = PyTuple_GET_ITEM(__pyx_args, 1);
@@ -15015,17 +14519,15 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_poisson(PyObject *__pyx_v_self,
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("poisson", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3411; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("poisson", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3444; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.poisson");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_lam);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_olam = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":3461
+ /* "mtrand.pyx":3498
* cdef ndarray olam
* cdef double flam
* flam = PyFloat_AsDouble(lam) # <<<<<<<<<<<<<<
@@ -15034,7 +14536,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_poisson(PyObject *__pyx_v_self,
*/
__pyx_v_flam = PyFloat_AsDouble(__pyx_v_lam);
- /* "mtrand.pyx":3462
+ /* "mtrand.pyx":3499
* cdef double flam
* flam = PyFloat_AsDouble(lam)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -15044,50 +14546,76 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_poisson(PyObject *__pyx_v_self,
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":3463
+ /* "mtrand.pyx":3500
* flam = PyFloat_AsDouble(lam)
* if not PyErr_Occurred():
* if lam < 0: # <<<<<<<<<<<<<<
* raise ValueError("lam < 0")
- * return discd_array_sc(self.internal_state, rk_poisson, size, flam)
+ * if lam > self.poisson_lam_max:
*/
- __pyx_t_2 = PyObject_RichCompare(__pyx_v_lam, __pyx_int_0, Py_LT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_RichCompare(__pyx_v_lam, __pyx_int_0, Py_LT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3463; __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 = 3500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3464
+ /* "mtrand.pyx":3501
* if not PyErr_Occurred():
* if lam < 0:
* raise ValueError("lam < 0") # <<<<<<<<<<<<<<
- * return discd_array_sc(self.internal_state, rk_poisson, size, flam)
- *
+ * if lam > self.poisson_lam_max:
+ * raise ValueError("lam value too large")
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3464; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_127), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_44));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_44));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_44));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3464; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3464; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":3465
+ /* "mtrand.pyx":3502
* if lam < 0:
* raise ValueError("lam < 0")
+ * if lam > self.poisson_lam_max: # <<<<<<<<<<<<<<
+ * raise ValueError("lam value too large")
+ * return discd_array_sc(self.internal_state, rk_poisson, size, flam)
+ */
+ __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__poisson_lam_max); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_3 = PyObject_RichCompare(__pyx_v_lam, __pyx_t_2, Py_GT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __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 = 3502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ if (__pyx_t_1) {
+
+ /* "mtrand.pyx":3503
+ * raise ValueError("lam < 0")
+ * if lam > self.poisson_lam_max:
+ * raise ValueError("lam value too large") # <<<<<<<<<<<<<<
+ * return discd_array_sc(self.internal_state, rk_poisson, size, flam)
+ *
+ */
+ __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_129), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_3, 0, 0);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L8;
+ }
+ __pyx_L8:;
+
+ /* "mtrand.pyx":3504
+ * if lam > self.poisson_lam_max:
+ * raise ValueError("lam value too large")
* return discd_array_sc(self.internal_state, rk_poisson, size, flam) # <<<<<<<<<<<<<<
*
* PyErr_Clear()
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = __pyx_f_6mtrand_discd_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_poisson, __pyx_v_size, __pyx_v_flam); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3465; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __pyx_f_6mtrand_discd_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_poisson, __pyx_v_size, __pyx_v_flam); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__pyx_r = __pyx_t_3;
__pyx_t_3 = 0;
@@ -15096,7 +14624,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_poisson(PyObject *__pyx_v_self,
}
__pyx_L6:;
- /* "mtrand.pyx":3467
+ /* "mtrand.pyx":3506
* return discd_array_sc(self.internal_state, rk_poisson, size, flam)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -15105,96 +14633,150 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_poisson(PyObject *__pyx_v_self,
*/
PyErr_Clear();
- /* "mtrand.pyx":3469
+ /* "mtrand.pyx":3508
* PyErr_Clear()
*
* olam = <ndarray>PyArray_FROM_OTF(lam, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less(olam, 0)):
* raise ValueError("lam < 0")
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_lam, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_lam, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3508; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
__Pyx_DECREF(((PyObject *)__pyx_v_olam));
__pyx_v_olam = ((PyArrayObject *)__pyx_t_3);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- /* "mtrand.pyx":3470
+ /* "mtrand.pyx":3509
*
* olam = <ndarray>PyArray_FROM_OTF(lam, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less(olam, 0)): # <<<<<<<<<<<<<<
* raise ValueError("lam < 0")
- * return discd_array(self.internal_state, rk_poisson, size, olam)
+ * if np.any(np.greater(olam, self.poisson_lam_max)):
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3470; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3470; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3470; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3470; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__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 = 3470; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_3));
__Pyx_INCREF(((PyObject *)__pyx_v_olam));
PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_olam));
__Pyx_GIVEREF(((PyObject *)__pyx_v_olam));
__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, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3470; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 3509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 3470; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __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 = 3509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__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_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3470; __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 = 3509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__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 = 3470; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 3509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3471
+ /* "mtrand.pyx":3510
* olam = <ndarray>PyArray_FROM_OTF(lam, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less(olam, 0)):
* raise ValueError("lam < 0") # <<<<<<<<<<<<<<
- * return discd_array(self.internal_state, rk_poisson, size, olam)
- *
+ * if np.any(np.greater(olam, self.poisson_lam_max)):
+ * raise ValueError("lam value too large.")
*/
- __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_130), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_44));
- PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_44));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_44));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_5, 0, 0);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- goto __pyx_L8;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L9;
}
- __pyx_L8:;
+ __pyx_L9:;
- /* "mtrand.pyx":3472
+ /* "mtrand.pyx":3511
* if np.any(np.less(olam, 0)):
* raise ValueError("lam < 0")
+ * if np.any(np.greater(olam, self.poisson_lam_max)): # <<<<<<<<<<<<<<
+ * raise ValueError("lam value too large.")
+ * return discd_array(self.internal_state, rk_poisson, size, olam)
+ */
+ __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_5);
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3511; __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_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_5);
+ __pyx_t_2 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__greater); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+ __pyx_t_5 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__poisson_lam_max); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_5);
+ __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
+ __Pyx_INCREF(((PyObject *)__pyx_v_olam));
+ PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_olam));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_olam));
+ PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5);
+ __Pyx_GIVEREF(__pyx_t_5);
+ __pyx_t_5 = 0;
+ __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 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 = 3511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
+ PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
+ __Pyx_GIVEREF(__pyx_t_5);
+ __pyx_t_5 = 0;
+ __pyx_t_5 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3511; __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_4)); __pyx_t_4 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+ if (__pyx_t_1) {
+
+ /* "mtrand.pyx":3512
+ * raise ValueError("lam < 0")
+ * if np.any(np.greater(olam, self.poisson_lam_max)):
+ * raise ValueError("lam value too large.") # <<<<<<<<<<<<<<
+ * return discd_array(self.internal_state, rk_poisson, size, olam)
+ *
+ */
+ __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_132), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_Raise(__pyx_t_5, 0, 0);
+ __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L10;
+ }
+ __pyx_L10:;
+
+ /* "mtrand.pyx":3513
+ * if np.any(np.greater(olam, self.poisson_lam_max)):
+ * raise ValueError("lam value too large.")
* return discd_array(self.internal_state, rk_poisson, size, olam) # <<<<<<<<<<<<<<
*
* def zipf(self, a, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = __pyx_f_6mtrand_discd_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_poisson, __pyx_v_size, __pyx_v_olam); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3472; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_r = __pyx_t_3;
- __pyx_t_3 = 0;
+ __pyx_t_5 = __pyx_f_6mtrand_discd_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_poisson, __pyx_v_size, __pyx_v_olam); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_5);
+ __pyx_r = __pyx_t_5;
+ __pyx_t_5 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -15208,15 +14790,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_poisson(PyObject *__pyx_v_self,
__pyx_r = NULL;
__pyx_L0:;
__Pyx_DECREF((PyObject *)__pyx_v_olam);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_lam);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":3474
+/* "mtrand.pyx":3515
* return discd_array(self.internal_state, rk_poisson, size, olam)
*
* def zipf(self, a, size=None): # <<<<<<<<<<<<<<
@@ -15224,9 +14803,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_poisson(PyObject *__pyx_v_self,
* zipf(a, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_zipf(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_zipf[] = "\n"" zipf(a, size=None)\n""\n"" Draw samples from a Zipf distribution.\n""\n"" Samples are drawn from a Zipf distribution with specified parameter (a),\n"" where a > 1.\n""\n"" The zipf distribution (also known as the zeta\n"" distribution) is a continuous probability distribution that satisfies\n"" Zipf's law, where the frequency of an item is inversely proportional to\n"" its rank in a frequency table.\n""\n"" Parameters\n"" ----------\n"" a : float\n"" parameter, > 1.\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"" The returned samples are greater than or equal to one.\n""\n"" See Also\n"" --------\n"" scipy.stats.distributions.zipf : probability density function,\n"" distribution or cumulative density function, etc.\n""\n"" Notes\n"" -----\n"" The probability density for the Zipf distribution is\n""\n"" .. math:: p(x) = \\frac{x^{-a}}{\\zeta(a)},\n""\n"" where :math:`\\zeta` is the Riemann Zeta function.\n""\n"" Named after the American linguist George Kingsley Zipf, who noted that\n"" the frequency of any word in a sample of a language is inversely\n"" proportional to its rank in the frequency table.\n""\n""\n"" References\n"" ----------\n"" .. [1] Weisstein, Eric W. \"Zipf Distribution.\" From MathWorld--A Wolfram\n"" Web Resource. http://mathworld.wolfram.com/ZipfDistribution.html\n"" .. [2] Wikipedia, \"Zeta distribution\",\n"" http://en.wikipedia.org/wiki/Zeta_distribution\n"" .. [3] Wikipedia, \"Zipf's Law\",\n"" http://en.wikipedia.org/wiki/Zipf%27s_law\n"" .. [4] Zipf, George Kingsley (1932): Selected Studies of the Principle\n"" of Relative Frequency in Language. Cambridge (Mass.).\n""\n"" Examples\n"" --------\n"" Draw samples from the distribution:\n""\n"" >>> a = 2. # parameter\n"" >>> s = np.random.zipf(a, 1000)\n""\n"" Display the histogram of the samples, along with\n"" the probability density function:\n""\n"" >>> import matplotlib.pyplot as plt\n"" >>> import scipy.special as sps\n"" Truncate s values at 50 so plot is interesting\n"" >>> count, bins, ignored = plt.hist(s[s<50], 50, normed=True)\n"" >>> x = np.arange(1., 50.)\n"" >>> y = x**(-a)/sps.zetac(a)\n"" >>> plt.plot(x, y/max(y), linewidth=2, color='r')\n"" >>> plt.show()\n""\n"" ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_zipf(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_43zipf(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_43zipf[] = "\n zipf(a, size=None)\n\n Draw samples from a Zipf distribution.\n\n Samples are drawn from a Zipf distribution with specified parameter\n `a` > 1.\n\n The Zipf distribution (also known as the zeta distribution) is a\n continuous probability distribution that satisfies Zipf's law: the\n frequency of an item is inversely proportional to its rank in a\n frequency table.\n\n Parameters\n ----------\n a : float > 1\n Distribution parameter.\n size : int or tuple of int, optional\n Output shape. If the given shape is, e.g., ``(m, n, k)``, then\n ``m * n * k`` samples are drawn; a single integer is equivalent in\n its result to providing a mono-tuple, i.e., a 1-D array of length\n *size* is returned. The default is None, in which case a single\n scalar is returned.\n\n Returns\n -------\n samples : scalar or ndarray\n The returned samples are greater than or equal to one.\n\n See Also\n --------\n scipy.stats.distributions.zipf : probability density function,\n distribution, or cumulative density function, etc.\n\n Notes\n -----\n The probability density for the Zipf distribution is\n\n .. math:: p(x) = \\frac{x^{-a}}{\\zeta(a)},\n\n where :math:`\\zeta` is the Riemann Zeta function.\n\n It is named for the American linguist George Kingsley Zipf, who noted\n that the frequency of any word in a sample of a language is inversely\n proportional to its rank in the frequency table.\n\n References\n ----------\n Zipf, G. K., *Selected Studies of the Principle of Relative Frequency\n in Language*, Cambridge, MA: Harvard Univ. Press, 1932.\n\n Examples\n --------\n Draw samples from the distribution:\n\n >>> a = 2. # parameter\n >>> s = np.random.zipf""(a, 1000)\n\n Display the histogram of the samples, along with\n the probability density function:\n\n >>> import matplotlib.pyplot as plt\n >>> import scipy.special as sps\n Truncate s values at 50 so plot is interesting\n >>> count, bins, ignored = plt.hist(s[s<50], 50, normed=True)\n >>> x = np.arange(1., 50.)\n >>> y = x**(-a)/sps.zetac(a)\n >>> plt.plot(x, y/max(y), linewidth=2, color='r')\n >>> plt.show()\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_43zipf(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_a = 0;
PyObject *__pyx_v_size = 0;
PyArrayObject *__pyx_v_oa;
@@ -15255,13 +14834,13 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_zipf(PyObject *__pyx_v_self, PyO
if (likely(values[0])) kw_args--;
else goto __pyx_L5_argtuple_error;
case 1:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[1] = value; kw_args--; }
+ if (value) { values[1] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "zipf") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3474; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "zipf") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3515; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_a = values[0];
__pyx_v_size = values[1];
@@ -15276,17 +14855,15 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_zipf(PyObject *__pyx_v_self, PyO
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("zipf", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3474; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("zipf", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3515; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.zipf");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_a);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_oa = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":3553
+ /* "mtrand.pyx":3590
* cdef double fa
*
* fa = PyFloat_AsDouble(a) # <<<<<<<<<<<<<<
@@ -15295,7 +14872,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_zipf(PyObject *__pyx_v_self, PyO
*/
__pyx_v_fa = PyFloat_AsDouble(__pyx_v_a);
- /* "mtrand.pyx":3554
+ /* "mtrand.pyx":3591
*
* fa = PyFloat_AsDouble(a)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -15305,7 +14882,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_zipf(PyObject *__pyx_v_self, PyO
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":3555
+ /* "mtrand.pyx":3592
* fa = PyFloat_AsDouble(a)
* if not PyErr_Occurred():
* if fa <= 1.0: # <<<<<<<<<<<<<<
@@ -15315,29 +14892,23 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_zipf(PyObject *__pyx_v_self, PyO
__pyx_t_1 = (__pyx_v_fa <= 1.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":3556
+ /* "mtrand.pyx":3593
* if not PyErr_Occurred():
* if fa <= 1.0:
* raise ValueError("a <= 1.0") # <<<<<<<<<<<<<<
* return discd_array_sc(self.internal_state, rk_zipf, size, fa)
*
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_134), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_45));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_45));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_45));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":3557
+ /* "mtrand.pyx":3594
* if fa <= 1.0:
* raise ValueError("a <= 1.0")
* return discd_array_sc(self.internal_state, rk_zipf, size, fa) # <<<<<<<<<<<<<<
@@ -15345,16 +14916,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_zipf(PyObject *__pyx_v_self, PyO
* PyErr_Clear()
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = __pyx_f_6mtrand_discd_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_zipf, __pyx_v_size, __pyx_v_fa); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3557; __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_discd_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_zipf, __pyx_v_size, __pyx_v_fa); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3594; __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_L6;
}
__pyx_L6:;
- /* "mtrand.pyx":3559
+ /* "mtrand.pyx":3596
* return discd_array_sc(self.internal_state, rk_zipf, size, fa)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -15363,87 +14934,81 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_zipf(PyObject *__pyx_v_self, PyO
*/
PyErr_Clear();
- /* "mtrand.pyx":3561
+ /* "mtrand.pyx":3598
* PyErr_Clear()
*
* oa = <ndarray>PyArray_FROM_OTF(a, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less_equal(oa, 1.0)):
* raise ValueError("a <= 1.0")
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_a, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_a, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_oa));
- __pyx_v_oa = ((PyArrayObject *)__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_oa = ((PyArrayObject *)__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":3562
+ /* "mtrand.pyx":3599
*
* oa = <ndarray>PyArray_FROM_OTF(a, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oa, 1.0)): # <<<<<<<<<<<<<<
* raise ValueError("a <= 1.0")
* return discd_array(self.internal_state, rk_zipf, size, oa)
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(((PyObject *)__pyx_v_oa));
PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_oa));
__Pyx_GIVEREF(((PyObject *)__pyx_v_oa));
- PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 3562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 3599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
+ PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3599; __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_5)); __pyx_t_5 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3563
+ /* "mtrand.pyx":3600
* oa = <ndarray>PyArray_FROM_OTF(a, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(oa, 1.0)):
* raise ValueError("a <= 1.0") # <<<<<<<<<<<<<<
* return discd_array(self.internal_state, rk_zipf, size, oa)
*
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_45));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_45));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_45));
- __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_Raise(__pyx_t_5, 0, 0);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_135), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":3564
+ /* "mtrand.pyx":3601
* if np.any(np.less_equal(oa, 1.0)):
* raise ValueError("a <= 1.0")
* return discd_array(self.internal_state, rk_zipf, size, oa) # <<<<<<<<<<<<<<
@@ -15451,10 +15016,10 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_zipf(PyObject *__pyx_v_self, PyO
* def geometric(self, p, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_5 = __pyx_f_6mtrand_discd_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_zipf, __pyx_v_size, __pyx_v_oa); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_r = __pyx_t_5;
- __pyx_t_5 = 0;
+ __pyx_t_2 = __pyx_f_6mtrand_discd_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_zipf, __pyx_v_size, __pyx_v_oa); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -15468,15 +15033,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_zipf(PyObject *__pyx_v_self, PyO
__pyx_r = NULL;
__pyx_L0:;
__Pyx_DECREF((PyObject *)__pyx_v_oa);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_a);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":3566
+/* "mtrand.pyx":3603
* return discd_array(self.internal_state, rk_zipf, size, oa)
*
* def geometric(self, p, size=None): # <<<<<<<<<<<<<<
@@ -15484,9 +15046,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_zipf(PyObject *__pyx_v_self, PyO
* geometric(p, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_geometric(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_geometric[] = "\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 PyObject *__pyx_pf_6mtrand_11RandomState_geometric(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_44geometric(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_44geometric[] = "\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 PyObject *__pyx_pf_6mtrand_11RandomState_44geometric(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_p = 0;
PyObject *__pyx_v_size = 0;
PyArrayObject *__pyx_v_op;
@@ -15515,13 +15077,13 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_geometric(PyObject *__pyx_v_self
if (likely(values[0])) kw_args--;
else goto __pyx_L5_argtuple_error;
case 1:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[1] = value; kw_args--; }
+ if (value) { values[1] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "geometric") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3566; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "geometric") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3603; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_p = values[0];
__pyx_v_size = values[1];
@@ -15536,17 +15098,15 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_geometric(PyObject *__pyx_v_self
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("geometric", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3566; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("geometric", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3603; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.geometric");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_p);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_op = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":3614
+ /* "mtrand.pyx":3651
* cdef double fp
*
* fp = PyFloat_AsDouble(p) # <<<<<<<<<<<<<<
@@ -15555,7 +15115,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_geometric(PyObject *__pyx_v_self
*/
__pyx_v_fp = PyFloat_AsDouble(__pyx_v_p);
- /* "mtrand.pyx":3615
+ /* "mtrand.pyx":3652
*
* fp = PyFloat_AsDouble(p)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -15565,7 +15125,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_geometric(PyObject *__pyx_v_self
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":3616
+ /* "mtrand.pyx":3653
* fp = PyFloat_AsDouble(p)
* if not PyErr_Occurred():
* if fp < 0.0: # <<<<<<<<<<<<<<
@@ -15575,29 +15135,23 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_geometric(PyObject *__pyx_v_self
__pyx_t_1 = (__pyx_v_fp < 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":3617
+ /* "mtrand.pyx":3654
* if not PyErr_Occurred():
* if fp < 0.0:
* raise ValueError("p < 0.0") # <<<<<<<<<<<<<<
* if fp > 1.0:
* raise ValueError("p > 1.0")
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3617; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_137), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3654; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_46));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_46));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_46));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3617; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3617; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3654; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":3618
+ /* "mtrand.pyx":3655
* if fp < 0.0:
* raise ValueError("p < 0.0")
* if fp > 1.0: # <<<<<<<<<<<<<<
@@ -15607,29 +15161,23 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_geometric(PyObject *__pyx_v_self
__pyx_t_1 = (__pyx_v_fp > 1.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":3619
+ /* "mtrand.pyx":3656
* raise ValueError("p < 0.0")
* if fp > 1.0:
* raise ValueError("p > 1.0") # <<<<<<<<<<<<<<
* return discd_array_sc(self.internal_state, rk_geometric, size, fp)
*
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3619; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_47));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_47));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_47));
- __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3619; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_139), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3619; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":3620
+ /* "mtrand.pyx":3657
* if fp > 1.0:
* raise ValueError("p > 1.0")
* return discd_array_sc(self.internal_state, rk_geometric, size, fp) # <<<<<<<<<<<<<<
@@ -15637,7 +15185,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_geometric(PyObject *__pyx_v_self
* PyErr_Clear()
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_2 = __pyx_f_6mtrand_discd_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_geometric, __pyx_v_size, __pyx_v_fp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __pyx_f_6mtrand_discd_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_geometric, __pyx_v_size, __pyx_v_fp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__pyx_r = __pyx_t_2;
__pyx_t_2 = 0;
@@ -15646,7 +15194,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_geometric(PyObject *__pyx_v_self
}
__pyx_L6:;
- /* "mtrand.pyx":3622
+ /* "mtrand.pyx":3659
* return discd_array_sc(self.internal_state, rk_geometric, size, fp)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -15655,153 +15203,141 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_geometric(PyObject *__pyx_v_self
*/
PyErr_Clear();
- /* "mtrand.pyx":3625
+ /* "mtrand.pyx":3662
*
*
* op = <ndarray>PyArray_FROM_OTF(p, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less(op, 0.0)):
* raise ValueError("p < 0.0")
*/
- __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_p, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_p, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3662; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_op));
__pyx_v_op = ((PyArrayObject *)__pyx_t_2);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":3626
+ /* "mtrand.pyx":3663
*
* op = <ndarray>PyArray_FROM_OTF(p, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less(op, 0.0)): # <<<<<<<<<<<<<<
* raise ValueError("p < 0.0")
* if np.any(np.greater(op, 1.0)):
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3663; __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_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(((PyObject *)__pyx_v_op));
PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_op));
__Pyx_GIVEREF(((PyObject *)__pyx_v_op));
PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
__Pyx_GIVEREF(__pyx_t_2);
__pyx_t_2 = 0;
- __pyx_t_2 = PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 3626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __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 = 3663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
__Pyx_GIVEREF(__pyx_t_2);
__pyx_t_2 = 0;
- __pyx_t_2 = PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3627
+ /* "mtrand.pyx":3664
* op = <ndarray>PyArray_FROM_OTF(p, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less(op, 0.0)):
* raise ValueError("p < 0.0") # <<<<<<<<<<<<<<
* if np.any(np.greater(op, 1.0)):
* raise ValueError("p > 1.0")
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_140), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3664; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_46));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_46));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_46));
- __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_5, 0, 0);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3664; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L9;
}
__pyx_L9:;
- /* "mtrand.pyx":3628
+ /* "mtrand.pyx":3665
* if np.any(np.less(op, 0.0)):
* raise ValueError("p < 0.0")
* if np.any(np.greater(op, 1.0)): # <<<<<<<<<<<<<<
* raise ValueError("p > 1.0")
* return discd_array(self.internal_state, rk_geometric, size, op)
*/
- __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__greater); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__greater); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_5 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
__Pyx_INCREF(((PyObject *)__pyx_v_op));
PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_op));
__Pyx_GIVEREF(((PyObject *)__pyx_v_op));
- PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5);
- __Pyx_GIVEREF(__pyx_t_5);
- __pyx_t_5 = 0;
- __pyx_t_5 = PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
+ __Pyx_GIVEREF(__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 = 3665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_DECREF(__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 = 3628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
- __Pyx_GIVEREF(__pyx_t_5);
- __pyx_t_5 = 0;
- __pyx_t_5 = PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 3665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
+ 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 = 3665; __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_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3629
+ /* "mtrand.pyx":3666
* raise ValueError("p < 0.0")
* if np.any(np.greater(op, 1.0)):
* raise ValueError("p > 1.0") # <<<<<<<<<<<<<<
* return discd_array(self.internal_state, rk_geometric, size, op)
*
*/
- __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3629; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_47));
- PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_47));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_47));
- __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3629; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_Raise(__pyx_t_4, 0, 0);
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3629; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_141), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L10;
}
__pyx_L10:;
- /* "mtrand.pyx":3630
+ /* "mtrand.pyx":3667
* if np.any(np.greater(op, 1.0)):
* raise ValueError("p > 1.0")
* return discd_array(self.internal_state, rk_geometric, size, op) # <<<<<<<<<<<<<<
@@ -15809,10 +15345,10 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_geometric(PyObject *__pyx_v_self
* def hypergeometric(self, ngood, nbad, nsample, size=None):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_4 = __pyx_f_6mtrand_discd_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_geometric, __pyx_v_size, __pyx_v_op); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3630; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- __pyx_r = __pyx_t_4;
- __pyx_t_4 = 0;
+ __pyx_t_2 = __pyx_f_6mtrand_discd_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_geometric, __pyx_v_size, __pyx_v_op); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3667; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -15826,15 +15362,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_geometric(PyObject *__pyx_v_self
__pyx_r = NULL;
__pyx_L0:;
__Pyx_DECREF((PyObject *)__pyx_v_op);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_p);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":3632
+/* "mtrand.pyx":3669
* return discd_array(self.internal_state, rk_geometric, size, op)
*
* def hypergeometric(self, ngood, nbad, nsample, size=None): # <<<<<<<<<<<<<<
@@ -15842,9 +15375,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_geometric(PyObject *__pyx_v_self
* hypergeometric(ngood, nbad, nsample, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_hypergeometric(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_hypergeometric[] = "\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 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_pf_6mtrand_11RandomState_hypergeometric(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_45hypergeometric(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_45hypergeometric[] = "\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 PyObject *__pyx_pf_6mtrand_11RandomState_45hypergeometric(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_ngood = 0;
PyObject *__pyx_v_nbad = 0;
PyObject *__pyx_v_nsample = 0;
@@ -15885,22 +15418,22 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_hypergeometric(PyObject *__pyx_v
values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__nbad);
if (likely(values[1])) kw_args--;
else {
- __Pyx_RaiseArgtupleInvalid("hypergeometric", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3632; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("hypergeometric", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3669; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
case 2:
values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__nsample);
if (likely(values[2])) kw_args--;
else {
- __Pyx_RaiseArgtupleInvalid("hypergeometric", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3632; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("hypergeometric", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3669; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
case 3:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[3] = value; kw_args--; }
+ if (value) { values[3] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "hypergeometric") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3632; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "hypergeometric") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3669; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_ngood = values[0];
__pyx_v_nbad = values[1];
@@ -15921,21 +15454,17 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_hypergeometric(PyObject *__pyx_v
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("hypergeometric", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3632; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("hypergeometric", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3669; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.hypergeometric");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_ngood);
- __Pyx_INCREF(__pyx_v_nbad);
- __Pyx_INCREF(__pyx_v_nsample);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_ongood = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_onbad = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_onsample = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":3719
+ /* "mtrand.pyx":3756
* cdef long lngood, lnbad, lnsample
*
* lngood = PyInt_AsLong(ngood) # <<<<<<<<<<<<<<
@@ -15944,7 +15473,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_hypergeometric(PyObject *__pyx_v
*/
__pyx_v_lngood = PyInt_AsLong(__pyx_v_ngood);
- /* "mtrand.pyx":3720
+ /* "mtrand.pyx":3757
*
* lngood = PyInt_AsLong(ngood)
* lnbad = PyInt_AsLong(nbad) # <<<<<<<<<<<<<<
@@ -15953,7 +15482,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_hypergeometric(PyObject *__pyx_v
*/
__pyx_v_lnbad = PyInt_AsLong(__pyx_v_nbad);
- /* "mtrand.pyx":3721
+ /* "mtrand.pyx":3758
* lngood = PyInt_AsLong(ngood)
* lnbad = PyInt_AsLong(nbad)
* lnsample = PyInt_AsLong(nsample) # <<<<<<<<<<<<<<
@@ -15962,7 +15491,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_hypergeometric(PyObject *__pyx_v
*/
__pyx_v_lnsample = PyInt_AsLong(__pyx_v_nsample);
- /* "mtrand.pyx":3722
+ /* "mtrand.pyx":3759
* lnbad = PyInt_AsLong(nbad)
* lnsample = PyInt_AsLong(nsample)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -15972,150 +15501,126 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_hypergeometric(PyObject *__pyx_v
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":3723
+ /* "mtrand.pyx":3760
* lnsample = PyInt_AsLong(nsample)
* if not PyErr_Occurred():
* if ngood < 1: # <<<<<<<<<<<<<<
* raise ValueError("ngood < 1")
* if nbad < 1:
*/
- __pyx_t_2 = PyObject_RichCompare(__pyx_v_ngood, __pyx_int_1, Py_LT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_RichCompare(__pyx_v_ngood, __pyx_int_1, Py_LT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3723; __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 = 3760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3724
+ /* "mtrand.pyx":3761
* if not PyErr_Occurred():
* if ngood < 1:
* raise ValueError("ngood < 1") # <<<<<<<<<<<<<<
* if nbad < 1:
* raise ValueError("nbad < 1")
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_143), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3761; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_48));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_48));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_48));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3761; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":3725
+ /* "mtrand.pyx":3762
* if ngood < 1:
* raise ValueError("ngood < 1")
* if nbad < 1: # <<<<<<<<<<<<<<
* raise ValueError("nbad < 1")
* if nsample < 1:
*/
- __pyx_t_3 = PyObject_RichCompare(__pyx_v_nbad, __pyx_int_1, Py_LT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_t_2 = PyObject_RichCompare(__pyx_v_nbad, __pyx_int_1, Py_LT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3762; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3762; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3726
+ /* "mtrand.pyx":3763
* raise ValueError("ngood < 1")
* if nbad < 1:
* raise ValueError("nbad < 1") # <<<<<<<<<<<<<<
* if nsample < 1:
* raise ValueError("nsample < 1")
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3726; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_49));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_49));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_49));
- __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3726; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_145), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3726; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":3727
+ /* "mtrand.pyx":3764
* if nbad < 1:
* raise ValueError("nbad < 1")
* if nsample < 1: # <<<<<<<<<<<<<<
* raise ValueError("nsample < 1")
* if ngood + nbad < nsample:
*/
- __pyx_t_2 = PyObject_RichCompare(__pyx_v_nsample, __pyx_int_1, Py_LT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_RichCompare(__pyx_v_nsample, __pyx_int_1, Py_LT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3764; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3727; __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 = 3764; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3728
+ /* "mtrand.pyx":3765
* raise ValueError("nbad < 1")
* if nsample < 1:
* raise ValueError("nsample < 1") # <<<<<<<<<<<<<<
* if ngood + nbad < nsample:
* raise ValueError("ngood + nbad < nsample")
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3728; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_147), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_50));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_50));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_50));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3728; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3728; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L9;
}
__pyx_L9:;
- /* "mtrand.pyx":3729
+ /* "mtrand.pyx":3766
* if nsample < 1:
* raise ValueError("nsample < 1")
* if ngood + nbad < nsample: # <<<<<<<<<<<<<<
* raise ValueError("ngood + nbad < nsample")
* return discnmN_array_sc(self.internal_state, rk_hypergeometric, size,
*/
- __pyx_t_3 = PyNumber_Add(__pyx_v_ngood, __pyx_v_nbad); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_v_nsample, Py_LT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyNumber_Add(__pyx_v_ngood, __pyx_v_nbad); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __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 = 3729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_RichCompare(__pyx_t_2, __pyx_v_nsample, Py_LT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
__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 = 3766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3730
+ /* "mtrand.pyx":3767
* raise ValueError("nsample < 1")
* if ngood + nbad < nsample:
* raise ValueError("ngood + nbad < nsample") # <<<<<<<<<<<<<<
* return discnmN_array_sc(self.internal_state, rk_hypergeometric, size,
* lngood, lnbad, lnsample)
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3730; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_51));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_51));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_51));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3730; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_149), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3767; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_Raise(__pyx_t_3, 0, 0);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3730; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3767; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L10;
}
__pyx_L10:;
- /* "mtrand.pyx":3731
+ /* "mtrand.pyx":3768
* if ngood + nbad < nsample:
* raise ValueError("ngood + nbad < nsample")
* return discnmN_array_sc(self.internal_state, rk_hypergeometric, size, # <<<<<<<<<<<<<<
@@ -16124,14 +15629,14 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_hypergeometric(PyObject *__pyx_v
*/
__Pyx_XDECREF(__pyx_r);
- /* "mtrand.pyx":3732
+ /* "mtrand.pyx":3769
* raise ValueError("ngood + nbad < nsample")
* return discnmN_array_sc(self.internal_state, rk_hypergeometric, size,
* lngood, lnbad, lnsample) # <<<<<<<<<<<<<<
*
*
*/
- __pyx_t_3 = __pyx_f_6mtrand_discnmN_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__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 = 3731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __pyx_f_6mtrand_discnmN_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__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 = 3768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__pyx_r = __pyx_t_3;
__pyx_t_3 = 0;
@@ -16140,7 +15645,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_hypergeometric(PyObject *__pyx_v
}
__pyx_L6:;
- /* "mtrand.pyx":3735
+ /* "mtrand.pyx":3772
*
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -16149,322 +15654,298 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_hypergeometric(PyObject *__pyx_v
*/
PyErr_Clear();
- /* "mtrand.pyx":3737
+ /* "mtrand.pyx":3774
* PyErr_Clear()
*
* ongood = <ndarray>PyArray_FROM_OTF(ngood, NPY_LONG, NPY_ALIGNED) # <<<<<<<<<<<<<<
* onbad = <ndarray>PyArray_FROM_OTF(nbad, NPY_LONG, NPY_ALIGNED)
* onsample = <ndarray>PyArray_FROM_OTF(nsample, NPY_LONG, NPY_ALIGNED)
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_ngood, NPY_LONG, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_ngood, NPY_LONG, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3774; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
__Pyx_DECREF(((PyObject *)__pyx_v_ongood));
__pyx_v_ongood = ((PyArrayObject *)__pyx_t_3);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- /* "mtrand.pyx":3738
+ /* "mtrand.pyx":3775
*
* ongood = <ndarray>PyArray_FROM_OTF(ngood, NPY_LONG, NPY_ALIGNED)
* onbad = <ndarray>PyArray_FROM_OTF(nbad, NPY_LONG, NPY_ALIGNED) # <<<<<<<<<<<<<<
* onsample = <ndarray>PyArray_FROM_OTF(nsample, NPY_LONG, NPY_ALIGNED)
* if np.any(np.less(ongood, 1)):
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_nbad, NPY_LONG, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_nbad, NPY_LONG, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
__Pyx_DECREF(((PyObject *)__pyx_v_onbad));
__pyx_v_onbad = ((PyArrayObject *)__pyx_t_3);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- /* "mtrand.pyx":3739
+ /* "mtrand.pyx":3776
* ongood = <ndarray>PyArray_FROM_OTF(ngood, NPY_LONG, NPY_ALIGNED)
* onbad = <ndarray>PyArray_FROM_OTF(nbad, NPY_LONG, NPY_ALIGNED)
* onsample = <ndarray>PyArray_FROM_OTF(nsample, NPY_LONG, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less(ongood, 1)):
* raise ValueError("ngood < 1")
*/
- __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_nsample, NPY_LONG, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyArray_FROM_OTF(__pyx_v_nsample, NPY_LONG, NPY_ALIGNED); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_3)));
__Pyx_DECREF(((PyObject *)__pyx_v_onsample));
__pyx_v_onsample = ((PyArrayObject *)__pyx_t_3);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- /* "mtrand.pyx":3740
+ /* "mtrand.pyx":3777
* onbad = <ndarray>PyArray_FROM_OTF(nbad, NPY_LONG, NPY_ALIGNED)
* onsample = <ndarray>PyArray_FROM_OTF(nsample, NPY_LONG, NPY_ALIGNED)
* if np.any(np.less(ongood, 1)): # <<<<<<<<<<<<<<
* raise ValueError("ngood < 1")
* if np.any(np.less(onbad, 1)):
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__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 = 3740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_3));
__Pyx_INCREF(((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_3, 1, __pyx_int_1);
__Pyx_GIVEREF(__pyx_int_1);
- __pyx_t_5 = PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 3777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 3740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __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 = 3777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__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_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3740; __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 = 3777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__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 = 3740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 3777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3741
+ /* "mtrand.pyx":3778
* onsample = <ndarray>PyArray_FROM_OTF(nsample, NPY_LONG, NPY_ALIGNED)
* if np.any(np.less(ongood, 1)):
* raise ValueError("ngood < 1") # <<<<<<<<<<<<<<
* if np.any(np.less(onbad, 1)):
* raise ValueError("nbad < 1")
*/
- __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_150), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3778; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_48));
- PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_48));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_48));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_5, 0, 0);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3778; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L11;
}
__pyx_L11:;
- /* "mtrand.pyx":3742
+ /* "mtrand.pyx":3779
* 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(onsample, 1)):
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3742; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3742; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3779; __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_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3742; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3742; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+ __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_5);
+ __pyx_t_2 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__less); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3779; __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 = 3742; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __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 = 3779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(((PyObject *)__pyx_v_onbad));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((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_3, 1, __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_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3742; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 3779; __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_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3742; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
+ __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 = 3779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__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_5, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3742; __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 = 3779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3742; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 3779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3743
+ /* "mtrand.pyx":3780
* raise ValueError("ngood < 1")
* if np.any(np.less(onbad, 1)):
* raise ValueError("nbad < 1") # <<<<<<<<<<<<<<
* if np.any(np.less(onsample, 1)):
* raise ValueError("nsample < 1")
*/
- __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3743; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_151), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3780; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_49));
- PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_kp_s_49));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_49));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3743; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_4, 0, 0);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3743; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3780; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L12;
}
__pyx_L12:;
- /* "mtrand.pyx":3744
+ /* "mtrand.pyx":3781
* if np.any(np.less(onbad, 1)):
* raise ValueError("nbad < 1")
* if np.any(np.less(onsample, 1)): # <<<<<<<<<<<<<<
* raise ValueError("nsample < 1")
* if np.any(np.less(np.add(ongood, onbad),onsample)):
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3781; __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_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__any); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __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 = 3744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__less); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3781; __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 = 3781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
__Pyx_INCREF(((PyObject *)__pyx_v_onsample));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_onsample));
+ PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_onsample));
__Pyx_GIVEREF(((PyObject *)__pyx_v_onsample));
__Pyx_INCREF(__pyx_int_1);
- PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_1);
+ PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_1);
__Pyx_GIVEREF(__pyx_int_1);
- __pyx_t_2 = PyObject_Call(__pyx_t_5, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 3781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_DECREF(__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 = 3744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
+ __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 = 3781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
+ 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_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 3781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __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 = 3744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3745
+ /* "mtrand.pyx":3782
* raise ValueError("nbad < 1")
* 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_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3745; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_152), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_50));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_50));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_50));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3745; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3745; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L13;
}
__pyx_L13:;
- /* "mtrand.pyx":3746
+ /* "mtrand.pyx":3783
* 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")
* return discnmN_array(self.internal_state, rk_hypergeometric, size,
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__less); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3783; __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_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__add); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_5 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __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 = 3746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__add); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3783; __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 = 3783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__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_5, __pyx_t_3, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3746; __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 = 3783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_6);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__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 = 3746; __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(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__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_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3746; __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 = 3783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_6);
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 3746; __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_5); __pyx_t_5 = 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 = 3783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__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_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3746; __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 = 3783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_6);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 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 = 3783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3747
+ /* "mtrand.pyx":3784
* raise ValueError("nsample < 1")
* if np.any(np.less(np.add(ongood, onbad),onsample)):
* raise ValueError("ngood + nbad < nsample") # <<<<<<<<<<<<<<
* return discnmN_array(self.internal_state, rk_hypergeometric, size,
* ongood, onbad, onsample)
*/
- __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3747; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_6 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_153), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_6);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_51));
- PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_kp_s_51));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_51));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3747; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_6, 0, 0);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3747; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L14;
}
__pyx_L14:;
- /* "mtrand.pyx":3748
+ /* "mtrand.pyx":3785
* if np.any(np.less(np.add(ongood, onbad),onsample)):
* raise ValueError("ngood + nbad < nsample")
* return discnmN_array(self.internal_state, rk_hypergeometric, size, # <<<<<<<<<<<<<<
@@ -16473,17 +15954,17 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_hypergeometric(PyObject *__pyx_v
*/
__Pyx_XDECREF(__pyx_r);
- /* "mtrand.pyx":3749
+ /* "mtrand.pyx":3786
* raise ValueError("ngood + nbad < nsample")
* return discnmN_array(self.internal_state, rk_hypergeometric, size,
* ongood, onbad, onsample) # <<<<<<<<<<<<<<
*
* def logseries(self, p, size=None):
*/
- __pyx_t_3 = __pyx_f_6mtrand_discnmN_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_hypergeometric, __pyx_v_size, __pyx_v_ongood, __pyx_v_onbad, __pyx_v_onsample); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_r = __pyx_t_3;
- __pyx_t_3 = 0;
+ __pyx_t_6 = __pyx_f_6mtrand_discnmN_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_hypergeometric, __pyx_v_size, __pyx_v_ongood, __pyx_v_onbad, __pyx_v_onsample); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3785; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_6);
+ __pyx_r = __pyx_t_6;
+ __pyx_t_6 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -16500,17 +15981,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_hypergeometric(PyObject *__pyx_v
__Pyx_DECREF((PyObject *)__pyx_v_ongood);
__Pyx_DECREF((PyObject *)__pyx_v_onbad);
__Pyx_DECREF((PyObject *)__pyx_v_onsample);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_ngood);
- __Pyx_DECREF(__pyx_v_nbad);
- __Pyx_DECREF(__pyx_v_nsample);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":3751
+/* "mtrand.pyx":3788
* ongood, onbad, onsample)
*
* def logseries(self, p, size=None): # <<<<<<<<<<<<<<
@@ -16518,9 +15994,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_hypergeometric(PyObject *__pyx_v
* logseries(p, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_logseries(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_logseries[] = "\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, \"Logarithmic-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 PyObject *__pyx_pf_6mtrand_11RandomState_logseries(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_46logseries(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_46logseries[] = "\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 PyObject *__pyx_pf_6mtrand_11RandomState_46logseries(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_p = 0;
PyObject *__pyx_v_size = 0;
PyArrayObject *__pyx_v_op;
@@ -16549,13 +16025,13 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_logseries(PyObject *__pyx_v_self
if (likely(values[0])) kw_args--;
else goto __pyx_L5_argtuple_error;
case 1:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[1] = value; kw_args--; }
+ if (value) { values[1] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "logseries") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3751; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "logseries") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3788; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_p = values[0];
__pyx_v_size = values[1];
@@ -16570,17 +16046,15 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_logseries(PyObject *__pyx_v_self
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("logseries", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3751; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("logseries", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3788; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.logseries");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_p);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_op = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":3828
+ /* "mtrand.pyx":3865
* cdef double fp
*
* fp = PyFloat_AsDouble(p) # <<<<<<<<<<<<<<
@@ -16589,7 +16063,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_logseries(PyObject *__pyx_v_self
*/
__pyx_v_fp = PyFloat_AsDouble(__pyx_v_p);
- /* "mtrand.pyx":3829
+ /* "mtrand.pyx":3866
*
* fp = PyFloat_AsDouble(p)
* if not PyErr_Occurred(): # <<<<<<<<<<<<<<
@@ -16599,7 +16073,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_logseries(PyObject *__pyx_v_self
__pyx_t_1 = (!PyErr_Occurred());
if (__pyx_t_1) {
- /* "mtrand.pyx":3830
+ /* "mtrand.pyx":3867
* fp = PyFloat_AsDouble(p)
* if not PyErr_Occurred():
* if fp <= 0.0: # <<<<<<<<<<<<<<
@@ -16609,29 +16083,23 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_logseries(PyObject *__pyx_v_self
__pyx_t_1 = (__pyx_v_fp <= 0.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":3831
+ /* "mtrand.pyx":3868
* if not PyErr_Occurred():
* if fp <= 0.0:
* raise ValueError("p <= 0.0") # <<<<<<<<<<<<<<
* if fp >= 1.0:
* raise ValueError("p >= 1.0")
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_155), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_52));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_52));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_52));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":3832
+ /* "mtrand.pyx":3869
* if fp <= 0.0:
* raise ValueError("p <= 0.0")
* if fp >= 1.0: # <<<<<<<<<<<<<<
@@ -16641,29 +16109,23 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_logseries(PyObject *__pyx_v_self
__pyx_t_1 = (__pyx_v_fp >= 1.0);
if (__pyx_t_1) {
- /* "mtrand.pyx":3833
+ /* "mtrand.pyx":3870
* raise ValueError("p <= 0.0")
* if fp >= 1.0:
* raise ValueError("p >= 1.0") # <<<<<<<<<<<<<<
* return discd_array_sc(self.internal_state, rk_logseries, size, fp)
*
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_53));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_53));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_53));
- __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_157), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":3834
+ /* "mtrand.pyx":3871
* if fp >= 1.0:
* raise ValueError("p >= 1.0")
* return discd_array_sc(self.internal_state, rk_logseries, size, fp) # <<<<<<<<<<<<<<
@@ -16671,7 +16133,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_logseries(PyObject *__pyx_v_self
* PyErr_Clear()
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_2 = __pyx_f_6mtrand_discd_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_logseries, __pyx_v_size, __pyx_v_fp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __pyx_f_6mtrand_discd_array_sc(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_logseries, __pyx_v_size, __pyx_v_fp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3871; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__pyx_r = __pyx_t_2;
__pyx_t_2 = 0;
@@ -16680,7 +16142,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_logseries(PyObject *__pyx_v_self
}
__pyx_L6:;
- /* "mtrand.pyx":3836
+ /* "mtrand.pyx":3873
* return discd_array_sc(self.internal_state, rk_logseries, size, fp)
*
* PyErr_Clear() # <<<<<<<<<<<<<<
@@ -16689,153 +16151,141 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_logseries(PyObject *__pyx_v_self
*/
PyErr_Clear();
- /* "mtrand.pyx":3838
+ /* "mtrand.pyx":3875
* PyErr_Clear()
*
* op = <ndarray>PyArray_FROM_OTF(p, NPY_DOUBLE, NPY_ALIGNED) # <<<<<<<<<<<<<<
* if np.any(np.less_equal(op, 0.0)):
* raise ValueError("p <= 0.0")
*/
- __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_p, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyArray_FROM_OTF(__pyx_v_p, NPY_DOUBLE, NPY_ALIGNED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_op));
__pyx_v_op = ((PyArrayObject *)__pyx_t_2);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":3839
+ /* "mtrand.pyx":3876
*
* op = <ndarray>PyArray_FROM_OTF(p, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(op, 0.0)): # <<<<<<<<<<<<<<
* raise ValueError("p <= 0.0")
* if np.any(np.greater_equal(op, 1.0)):
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3876; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3876; __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_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3876; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__less_equal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3876; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3876; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3876; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
__Pyx_INCREF(((PyObject *)__pyx_v_op));
PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_op));
__Pyx_GIVEREF(((PyObject *)__pyx_v_op));
PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
__Pyx_GIVEREF(__pyx_t_2);
__pyx_t_2 = 0;
- __pyx_t_2 = PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3876; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__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 = 3839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __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 = 3876; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_5));
PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
__Pyx_GIVEREF(__pyx_t_2);
__pyx_t_2 = 0;
- __pyx_t_2 = PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3876; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3876; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3840
+ /* "mtrand.pyx":3877
* op = <ndarray>PyArray_FROM_OTF(p, NPY_DOUBLE, NPY_ALIGNED)
* if np.any(np.less_equal(op, 0.0)):
* raise ValueError("p <= 0.0") # <<<<<<<<<<<<<<
* if np.any(np.greater_equal(op, 1.0)):
* raise ValueError("p >= 1.0")
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_158), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_52));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_52));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_52));
- __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_5, 0, 0);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L9;
}
__pyx_L9:;
- /* "mtrand.pyx":3841
+ /* "mtrand.pyx":3878
* if np.any(np.less_equal(op, 0.0)):
* raise ValueError("p <= 0.0")
* if np.any(np.greater_equal(op, 1.0)): # <<<<<<<<<<<<<<
* raise ValueError("p >= 1.0")
* return discd_array(self.internal_state, rk_logseries, size, op)
*/
- __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__any); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__any); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__greater_equal); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__greater_equal); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_5 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
__Pyx_INCREF(((PyObject *)__pyx_v_op));
PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_op));
__Pyx_GIVEREF(((PyObject *)__pyx_v_op));
- PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5);
- __Pyx_GIVEREF(__pyx_t_5);
- __pyx_t_5 = 0;
- __pyx_t_5 = PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
+ __Pyx_GIVEREF(__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 = 3878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_DECREF(__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 = 3841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
- __Pyx_GIVEREF(__pyx_t_5);
- __pyx_t_5 = 0;
- __pyx_t_5 = PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 3878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
+ 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 = 3878; __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_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_1) {
- /* "mtrand.pyx":3842
+ /* "mtrand.pyx":3879
* raise ValueError("p <= 0.0")
* if np.any(np.greater_equal(op, 1.0)):
* raise ValueError("p >= 1.0") # <<<<<<<<<<<<<<
* return discd_array(self.internal_state, rk_logseries, size, op)
*
*/
- __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_53));
- PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_53));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_53));
- __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_Raise(__pyx_t_4, 0, 0);
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_159), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3879; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3879; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L10;
}
__pyx_L10:;
- /* "mtrand.pyx":3843
+ /* "mtrand.pyx":3880
* if np.any(np.greater_equal(op, 1.0)):
* raise ValueError("p >= 1.0")
* return discd_array(self.internal_state, rk_logseries, size, op) # <<<<<<<<<<<<<<
@@ -16843,10 +16293,10 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_logseries(PyObject *__pyx_v_self
* # Multivariate distributions:
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_4 = __pyx_f_6mtrand_discd_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_logseries, __pyx_v_size, __pyx_v_op); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3843; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- __pyx_r = __pyx_t_4;
- __pyx_t_4 = 0;
+ __pyx_t_2 = __pyx_f_6mtrand_discd_array(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, rk_logseries, __pyx_v_size, __pyx_v_op); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
@@ -16860,15 +16310,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_logseries(PyObject *__pyx_v_self
__pyx_r = NULL;
__pyx_L0:;
__Pyx_DECREF((PyObject *)__pyx_v_op);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_p);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":3846
+/* "mtrand.pyx":3883
*
* # Multivariate distributions:
* def multivariate_normal(self, mean, cov, size=None): # <<<<<<<<<<<<<<
@@ -16876,9 +16323,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_logseries(PyObject *__pyx_v_self
* multivariate_normal(mean, cov[, size])
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_multivariate_normal(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_multivariate_normal[] = "\n"" multivariate_normal(mean, cov[, size])\n""\n"" Draw random samples from a multivariate normal distribution.\n""\n"" The multivariate normal, multinormal or Gaussian distribution is a\n"" generalisation of the one-dimensional normal distribution to higher\n"" dimensions.\n""\n"" Such a distribution is specified by its mean and covariance matrix,\n"" which are analogous to the mean (average or \"centre\") and variance\n"" (standard deviation squared or \"width\") of the one-dimensional normal\n"" distribution.\n""\n"" Parameters\n"" ----------\n"" mean : (N,) ndarray\n"" Mean of the N-dimensional distribution.\n"" cov : (N,N) ndarray\n"" Covariance matrix of the distribution.\n"" size : tuple of ints, optional\n"" Given a shape of, for example, (m,n,k), m*n*k samples are\n"" generated, and packed in an m-by-n-by-k arrangement. Because each\n"" sample is N-dimensional, the output shape is (m,n,k,N). If no\n"" shape is specified, a single sample is returned.\n""\n"" Returns\n"" -------\n"" out : ndarray\n"" The drawn samples, arranged according to `size`. If the\n"" shape given is (m,n,...), then the shape of `out` is is\n"" (m,n,...,N).\n""\n"" In other words, each entry ``out[i,j,...,:]`` is an N-dimensional\n"" value drawn from the distribution.\n""\n"" Notes\n"" -----\n"" The mean is a coordinate in N-dimensional space, which represents the\n"" location where samples are most likely to be generated. This is\n"" analogous to the peak of the bell curve for the one-dimensional or\n"" univariate normal distribution.\n""\n"" Covariance indicates the level to which two variables vary together.\n"" From the multivariate normal distribution, we draw N-dimensional\n"" samples, :math:`X = [x_1, x_2, ... x_N]`. The covariance matrix\n"" element :math:`C_{ij}` is the covariance of :math:`x_i` and :math:`x_j`.\n"" The element :math:`C_{ii}` is the variance of :math:`x_i` (i.e. its\n"" \"spread\").\n""\n"" Instead of specifying the full covariance matrix, popular\n"" approximations include:\n""\n"" - Spherical covariance (`cov` is a multiple of the identity matrix)\n"" - Diagonal covariance (`cov` has non-negative elements, and only on\n"" the diagonal)\n""\n"" This geometrical property can be seen in two dimensions by plotting\n"" generated data-points:\n""\n"" >>> mean = [0,0]\n"" >>> cov = [[1,0],[0,100]] # diagonal covariance, points lie on x or y-axis\n""\n"" >>> import matplotlib.pyplot as plt\n"" >>> x,y = np.random.multivariate_normal(mean,cov,5000).T\n"" >>> plt.plot(x,y,'x'); plt.axis('equal'); plt.show()\n""\n"" Note that the covariance matrix must be non-negative definite.\n""\n"" References\n"" ----------\n"" .. [1] A. Papoulis, \"Probability, Random Variables, and Stochastic\n"" Processes,\" 3rd ed., McGraw-Hill Companies, 1991\n"" .. [2] R.O. Duda, P.E. Hart, and D.G. Stork, \"Pattern Classification,\"\n"" 2nd ed., Wiley, 2001.\n""\n"" Examples\n"" --------\n"" >>> mean = (1,2)\n"" >>> cov = [[1,0],[1,0]]\n"" >>> x = np.random.multivariate_normal(mean,cov,(3,3))\n"" >>> x.shape\n"" (3, 3, 2)\n""\n"" The following is probably true, given that 0.6 is roughly twice the\n"" standard deviation:\n""\n"" >>> print list( (x[0,0,:] - mean) < 0.6 )\n"" [True, True]\n""\n"" ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_multivariate_normal(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_47multivariate_normal(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_47multivariate_normal[] = "\n multivariate_normal(mean, cov[, size])\n\n Draw random samples from a multivariate normal distribution.\n\n The multivariate normal, multinormal or Gaussian distribution is a\n generalization of the one-dimensional normal distribution to higher\n dimensions. Such a distribution is specified by its mean and\n covariance matrix. These parameters are analogous to the mean\n (average or \"center\") and variance (standard deviation, or \"width,\"\n squared) of the one-dimensional normal distribution.\n\n Parameters\n ----------\n mean : 1-D array_like, of length N\n Mean of the N-dimensional distribution.\n cov : 2-D array_like, of shape (N, N)\n Covariance matrix of the distribution. Must be symmetric and\n positive semi-definite for \"physically meaningful\" results.\n size : tuple of ints, optional\n Given a shape of, for example, ``(m,n,k)``, ``m*n*k`` samples are\n generated, and packed in an `m`-by-`n`-by-`k` arrangement. Because\n each sample is `N`-dimensional, the output shape is ``(m,n,k,N)``.\n If no shape is specified, a single (`N`-D) sample is returned.\n\n Returns\n -------\n out : ndarray\n The drawn samples, of shape *size*, if that was provided. If not,\n the shape is ``(N,)``.\n\n In other words, each entry ``out[i,j,...,:]`` is an N-dimensional\n value drawn from the distribution.\n\n Notes\n -----\n The mean is a coordinate in N-dimensional space, which represents the\n location where samples are most likely to be generated. This is\n analogous to the peak of the bell curve for the one-dimensional or\n univariate normal distribution.\n\n Covariance indicates the level to which two variables vary together.\n From the multivariate normal distribution, we draw ""N-dimensional\n samples, :math:`X = [x_1, x_2, ... x_N]`. The covariance matrix\n element :math:`C_{ij}` is the covariance of :math:`x_i` and :math:`x_j`.\n The element :math:`C_{ii}` is the variance of :math:`x_i` (i.e. its\n \"spread\").\n\n Instead of specifying the full covariance matrix, popular\n approximations include:\n\n - Spherical covariance (*cov* is a multiple of the identity matrix)\n - Diagonal covariance (*cov* has non-negative elements, and only on\n the diagonal)\n\n This geometrical property can be seen in two dimensions by plotting\n generated data-points:\n\n >>> mean = [0,0]\n >>> cov = [[1,0],[0,100]] # diagonal covariance, points lie on x or y-axis\n\n >>> import matplotlib.pyplot as plt\n >>> x,y = np.random.multivariate_normal(mean,cov,5000).T\n >>> plt.plot(x,y,'x'); plt.axis('equal'); plt.show()\n\n Note that the covariance matrix must be non-negative definite.\n\n References\n ----------\n Papoulis, A., *Probability, Random Variables, and Stochastic Processes*,\n 3rd ed., New York: McGraw-Hill, 1991.\n\n Duda, R. O., Hart, P. E., and Stork, D. G., *Pattern Classification*,\n 2nd ed., New York: Wiley, 2001.\n\n Examples\n --------\n >>> mean = (1,2)\n >>> cov = [[1,0],[1,0]]\n >>> x = np.random.multivariate_normal(mean,cov,(3,3))\n >>> x.shape\n (3, 3, 2)\n\n The following is probably true, given that 0.6 is roughly twice the\n standard deviation:\n\n >>> print list( (x[0,0,:] - mean) < 0.6 )\n [True, True]\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_47multivariate_normal(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_mean = 0;
PyObject *__pyx_v_cov = 0;
PyObject *__pyx_v_size = 0;
@@ -16897,8 +16344,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multivariate_normal(PyObject *__
Py_ssize_t __pyx_t_5;
int __pyx_t_6;
int __pyx_t_7;
- PyObject *__pyx_t_8 = NULL;
+ int __pyx_t_8;
PyObject *__pyx_t_9 = NULL;
+ PyObject *__pyx_t_10 = NULL;
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__mean,&__pyx_n_s__cov,&__pyx_n_s__size,0};
__Pyx_RefNannySetupContext("multivariate_normal");
if (unlikely(__pyx_kwds)) {
@@ -16921,16 +16369,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multivariate_normal(PyObject *__
values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__cov);
if (likely(values[1])) kw_args--;
else {
- __Pyx_RaiseArgtupleInvalid("multivariate_normal", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3846; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("multivariate_normal", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3883; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
case 2:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[2] = value; kw_args--; }
+ if (value) { values[2] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "multivariate_normal") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3846; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "multivariate_normal") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3883; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_mean = values[0];
__pyx_v_cov = values[1];
@@ -16949,74 +16397,73 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multivariate_normal(PyObject *__
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("multivariate_normal", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3846; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("multivariate_normal", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3883; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.multivariate_normal");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
__Pyx_INCREF(__pyx_v_mean);
__Pyx_INCREF(__pyx_v_cov);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_shape = Py_None; __Pyx_INCREF(Py_None);
- __pyx_v_final_shape = Py_None; __Pyx_INCREF(Py_None);
+ __pyx_v_final_shape = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_x = Py_None; __Pyx_INCREF(Py_None);
__pyx_v_svd = Py_None; __Pyx_INCREF(Py_None);
__pyx_v_u = Py_None; __Pyx_INCREF(Py_None);
__pyx_v_s = Py_None; __Pyx_INCREF(Py_None);
__pyx_v_v = Py_None; __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":3939
+ /* "mtrand.pyx":3975
* """
* # Check preconditions on arguments
* mean = np.array(mean) # <<<<<<<<<<<<<<
* cov = np.array(cov)
* if size is None:
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3975; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__array); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__array); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3975; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3975; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_1));
__Pyx_INCREF(__pyx_v_mean);
PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_mean);
__Pyx_GIVEREF(__pyx_v_mean);
- __pyx_t_3 = PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3975; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_v_mean);
__pyx_v_mean = __pyx_t_3;
__pyx_t_3 = 0;
- /* "mtrand.pyx":3940
+ /* "mtrand.pyx":3976
* # Check preconditions on arguments
* mean = np.array(mean)
* cov = np.array(cov) # <<<<<<<<<<<<<<
* if size is None:
* shape = []
*/
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3940; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3976; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__array); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3940; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__array); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3976; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__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 = 3940; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
+ __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3976; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_3));
__Pyx_INCREF(__pyx_v_cov);
PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_cov);
__Pyx_GIVEREF(__pyx_v_cov);
- __pyx_t_2 = PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3940; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3976; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
__Pyx_DECREF(__pyx_v_cov);
__pyx_v_cov = __pyx_t_2;
__pyx_t_2 = 0;
- /* "mtrand.pyx":3941
+ /* "mtrand.pyx":3977
* mean = np.array(mean)
* cov = np.array(cov)
* if size is None: # <<<<<<<<<<<<<<
@@ -17026,14 +16473,14 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multivariate_normal(PyObject *__
__pyx_t_4 = (__pyx_v_size == Py_None);
if (__pyx_t_4) {
- /* "mtrand.pyx":3942
+ /* "mtrand.pyx":3978
* cov = np.array(cov)
* if size is None:
* shape = [] # <<<<<<<<<<<<<<
* else:
* shape = size
*/
- __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3978; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_DECREF(__pyx_v_shape);
__pyx_v_shape = ((PyObject *)__pyx_t_2);
@@ -17042,7 +16489,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multivariate_normal(PyObject *__
}
/*else*/ {
- /* "mtrand.pyx":3944
+ /* "mtrand.pyx":3980
* shape = []
* else:
* shape = size # <<<<<<<<<<<<<<
@@ -17055,164 +16502,146 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multivariate_normal(PyObject *__
}
__pyx_L6:;
- /* "mtrand.pyx":3945
+ /* "mtrand.pyx":3981
* else:
* shape = size
* if len(mean.shape) != 1: # <<<<<<<<<<<<<<
* raise ValueError("mean must be 1 dimensional")
* if (len(cov.shape) != 2) or (cov.shape[0] != cov.shape[1]):
*/
- __pyx_t_2 = PyObject_GetAttr(__pyx_v_mean, __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3945; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_GetAttr(__pyx_v_mean, __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3981; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_5 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3945; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3981; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_4 = (__pyx_t_5 != 1);
if (__pyx_t_4) {
- /* "mtrand.pyx":3946
+ /* "mtrand.pyx":3982
* shape = size
* if len(mean.shape) != 1:
* raise ValueError("mean must be 1 dimensional") # <<<<<<<<<<<<<<
* if (len(cov.shape) != 2) or (cov.shape[0] != cov.shape[1]):
* raise ValueError("cov must be 2 dimensional and square")
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_161), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3982; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_54));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_54));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_54));
- __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); 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_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3982; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "mtrand.pyx":3947
+ /* "mtrand.pyx":3983
* if len(mean.shape) != 1:
* raise ValueError("mean must be 1 dimensional")
* if (len(cov.shape) != 2) or (cov.shape[0] != cov.shape[1]): # <<<<<<<<<<<<<<
* raise ValueError("cov must be 2 dimensional and square")
* if mean.shape[0] != cov.shape[0]:
*/
- __pyx_t_3 = PyObject_GetAttr(__pyx_v_cov, __pyx_n_s__shape); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3947; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3947; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_t_2 = PyObject_GetAttr(__pyx_v_cov, __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3983; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_5 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3983; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_4 = (__pyx_t_5 != 2);
if (!__pyx_t_4) {
- __pyx_t_3 = PyObject_GetAttr(__pyx_v_cov, __pyx_n_s__shape); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3947; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_3, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3947; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_GetAttr(__pyx_v_cov, __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3983; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_GetAttr(__pyx_v_cov, __pyx_n_s__shape); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3947; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3983; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_3, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3947; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_GetAttr(__pyx_v_cov, __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3983; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3983; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_RichCompare(__pyx_t_2, __pyx_t_1, Py_NE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3947; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3947; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_t_1, Py_NE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3983; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3983; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_7 = __pyx_t_6;
} else {
__pyx_t_7 = __pyx_t_4;
}
if (__pyx_t_7) {
- /* "mtrand.pyx":3948
+ /* "mtrand.pyx":3984
* raise ValueError("mean must be 1 dimensional")
* if (len(cov.shape) != 2) or (cov.shape[0] != cov.shape[1]):
* raise ValueError("cov must be 2 dimensional and square") # <<<<<<<<<<<<<<
* if mean.shape[0] != cov.shape[0]:
* raise ValueError("mean and cov must have same length")
*/
- __pyx_t_3 = PyTuple_New(1); 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_INCREF(((PyObject *)__pyx_kp_s_55));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_55));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_55));
- __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_Raise(__pyx_t_1, 0, 0);
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_163), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "mtrand.pyx":3949
+ /* "mtrand.pyx":3985
* if (len(cov.shape) != 2) or (cov.shape[0] != cov.shape[1]):
* raise ValueError("cov must be 2 dimensional and square")
* if mean.shape[0] != cov.shape[0]: # <<<<<<<<<<<<<<
* raise ValueError("mean and cov must have same length")
* # Compute shape of output
*/
- __pyx_t_1 = PyObject_GetAttr(__pyx_v_mean, __pyx_n_s__shape); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3949; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_GetAttr(__pyx_v_mean, __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_1, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3949; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_GetAttr(__pyx_v_cov, __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __pyx_t_1 = PyObject_GetAttr(__pyx_v_cov, __pyx_n_s__shape); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3949; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3949; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_t_3, Py_NE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3949; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3949; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if (__pyx_t_7) {
- /* "mtrand.pyx":3950
+ /* "mtrand.pyx":3986
* raise ValueError("cov must be 2 dimensional and square")
* if mean.shape[0] != cov.shape[0]:
* raise ValueError("mean and cov must have same length") # <<<<<<<<<<<<<<
* # Compute shape of output
* if isinstance(shape, int):
*/
- __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_56));
- PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_kp_s_56));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_56));
- __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_165), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L9;
}
__pyx_L9:;
- /* "mtrand.pyx":3952
+ /* "mtrand.pyx":3988
* raise ValueError("mean and cov must have same length")
* # Compute shape of output
* if isinstance(shape, int): # <<<<<<<<<<<<<<
* shape = [shape]
* final_shape = list(shape[:])
*/
- __pyx_t_7 = PyObject_TypeCheck(__pyx_v_shape, ((PyTypeObject *)((PyObject*)&PyInt_Type)));
+ __pyx_t_7 = PyInt_Check(__pyx_v_shape);
if (__pyx_t_7) {
- /* "mtrand.pyx":3953
+ /* "mtrand.pyx":3989
* # Compute shape of output
* if isinstance(shape, int):
* shape = [shape] # <<<<<<<<<<<<<<
* final_shape = list(shape[:])
* final_shape.append(mean.shape[0])
*/
- __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_shape);
PyList_SET_ITEM(__pyx_t_2, 0, __pyx_v_shape);
@@ -17224,311 +16653,312 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multivariate_normal(PyObject *__
}
__pyx_L10:;
- /* "mtrand.pyx":3954
+ /* "mtrand.pyx":3990
* if isinstance(shape, int):
* shape = [shape]
* final_shape = list(shape[:]) # <<<<<<<<<<<<<<
* final_shape.append(mean.shape[0])
* # Create a matrix of independent standard normally distributed random
*/
- __pyx_t_2 = PySequence_GetSlice(__pyx_v_shape, 0, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_PySequence_GetSlice(__pyx_v_shape, 0, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
+ __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_3));
+ PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
__Pyx_GIVEREF(__pyx_t_2);
__pyx_t_2 = 0;
- __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)&PyList_Type)), __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyList_Type))), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __Pyx_DECREF(__pyx_v_final_shape);
- __pyx_v_final_shape = __pyx_t_2;
+ __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_v_final_shape));
+ __pyx_v_final_shape = ((PyObject*)__pyx_t_2);
__pyx_t_2 = 0;
- /* "mtrand.pyx":3955
+ /* "mtrand.pyx":3991
* shape = [shape]
* final_shape = list(shape[:])
* final_shape.append(mean.shape[0]) # <<<<<<<<<<<<<<
* # Create a matrix of independent standard normally distributed random
* # numbers. The matrix has rows with the same length as mean and as
*/
- __pyx_t_2 = PyObject_GetAttr(__pyx_v_mean, __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = __Pyx_PyObject_Append(__pyx_v_final_shape, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(__pyx_v_final_shape == Py_None)) {
+ PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3991; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ __pyx_t_2 = PyObject_GetAttr(__pyx_v_mean, __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3991; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3991; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_8 = PyList_Append(__pyx_v_final_shape, __pyx_t_3); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3991; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- /* "mtrand.pyx":3959
+ /* "mtrand.pyx":3995
* # numbers. The matrix has rows with the same length as mean and as
* # many rows are necessary to form a matrix of shape final_shape.
* x = self.standard_normal(np.multiply.reduce(final_shape)) # <<<<<<<<<<<<<<
* x.shape = (np.multiply.reduce(final_shape[0:len(final_shape)-1]),
* mean.shape[0])
*/
- __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__standard_normal); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__multiply); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__standard_normal); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__reduce); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__multiply); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__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 = 3959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(__pyx_v_final_shape);
- PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_final_shape);
- __Pyx_GIVEREF(__pyx_v_final_shape);
- __pyx_t_8 = PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_8);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__reduce); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __Pyx_DECREF(__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 = 3959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8);
- __Pyx_GIVEREF(__pyx_t_8);
- __pyx_t_8 = 0;
- __pyx_t_8 = PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_8);
+ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_1));
+ __Pyx_INCREF(((PyObject *)__pyx_v_final_shape));
+ PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_final_shape));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_final_shape));
+ __pyx_t_9 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_9);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_1));
+ PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_9);
+ __Pyx_GIVEREF(__pyx_t_9);
+ __pyx_t_9 = 0;
+ __pyx_t_9 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_9);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_v_x);
- __pyx_v_x = __pyx_t_8;
- __pyx_t_8 = 0;
+ __pyx_v_x = __pyx_t_9;
+ __pyx_t_9 = 0;
- /* "mtrand.pyx":3960
+ /* "mtrand.pyx":3996
* # many rows are necessary to form a matrix of shape final_shape.
* x = self.standard_normal(np.multiply.reduce(final_shape))
* x.shape = (np.multiply.reduce(final_shape[0:len(final_shape)-1]), # <<<<<<<<<<<<<<
* mean.shape[0])
* # Transform matrix of standard normals into matrix where each row
*/
- __pyx_t_8 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_8);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_8, __pyx_n_s__multiply); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
- __pyx_t_8 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__reduce); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_8);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_5 = PyObject_Length(__pyx_v_final_shape); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __pyx_t_3 = PySequence_GetSlice(__pyx_v_final_shape, 0, (__pyx_t_5 - 1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_8, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_9 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3996; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_9);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_9, __pyx_n_s__multiply); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3996; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+ __pyx_t_9 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__reduce); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3996; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_9);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (unlikely(__pyx_v_final_shape == Py_None)) {
+ PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3996; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ __pyx_t_5 = PyList_GET_SIZE(((PyObject *)__pyx_v_final_shape));
+ __pyx_t_1 = __Pyx_PySequence_GetSlice(((PyObject *)__pyx_v_final_shape), 0, (__pyx_t_5 - 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3996; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_1));
+ __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3996; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_3));
+ PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
+ __pyx_t_1 = 0;
+ __pyx_t_1 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3996; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
- /* "mtrand.pyx":3961
+ /* "mtrand.pyx":3997
* x = self.standard_normal(np.multiply.reduce(final_shape))
* x.shape = (np.multiply.reduce(final_shape[0:len(final_shape)-1]),
* mean.shape[0]) # <<<<<<<<<<<<<<
* # Transform matrix of standard normals into matrix where each row
* # contains multivariate normals with the desired covariance.
*/
- __pyx_t_2 = PyObject_GetAttr(__pyx_v_mean, __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3961; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_8 = __Pyx_GetItemInt(__pyx_t_2, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3961; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_8);
- __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 = 3960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_8);
- __Pyx_GIVEREF(__pyx_t_8);
- __pyx_t_3 = 0;
- __pyx_t_8 = 0;
+ __pyx_t_3 = PyObject_GetAttr(__pyx_v_mean, __pyx_n_s__shape); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3997; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_t_9 = __Pyx_GetItemInt(__pyx_t_3, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3997; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_9);
+ __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 = 3996; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_3));
+ PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
+ __Pyx_GIVEREF(__pyx_t_1);
+ PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_9);
+ __Pyx_GIVEREF(__pyx_t_9);
+ __pyx_t_1 = 0;
+ __pyx_t_9 = 0;
- /* "mtrand.pyx":3960
+ /* "mtrand.pyx":3996
* # many rows are necessary to form a matrix of shape final_shape.
* x = self.standard_normal(np.multiply.reduce(final_shape))
* x.shape = (np.multiply.reduce(final_shape[0:len(final_shape)-1]), # <<<<<<<<<<<<<<
* mean.shape[0])
* # Transform matrix of standard normals into matrix where each row
*/
- if (PyObject_SetAttr(__pyx_v_x, __pyx_n_s__shape, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ if (PyObject_SetAttr(__pyx_v_x, __pyx_n_s__shape, ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3996; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
- /* "mtrand.pyx":3969
+ /* "mtrand.pyx":4005
* # decomposition of cov is such an A.
*
* from numpy.dual import svd # <<<<<<<<<<<<<<
* # XXX: we really should be doing this by Cholesky decomposition
* (u,s,v) = svd(cov)
*/
- __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3969; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(((PyObject *)__pyx_t_2));
+ __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_3));
__Pyx_INCREF(((PyObject *)__pyx_n_s__svd));
- PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_n_s__svd));
+ PyList_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_n_s__svd));
__Pyx_GIVEREF(((PyObject *)__pyx_n_s__svd));
- __pyx_t_8 = __Pyx_Import(((PyObject *)__pyx_n_s_57), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3969; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_8);
- __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_8, __pyx_n_s__svd); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3969; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(__pyx_t_2);
+ __pyx_t_9 = __Pyx_Import(((PyObject *)__pyx_n_s_166), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_9);
+ __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_9, __pyx_n_s__svd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_INCREF(__pyx_t_3);
__Pyx_DECREF(__pyx_v_svd);
- __pyx_v_svd = __pyx_t_2;
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+ __pyx_v_svd = __pyx_t_3;
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
- /* "mtrand.pyx":3971
+ /* "mtrand.pyx":4007
* from numpy.dual import svd
* # XXX: we really should be doing this by Cholesky decomposition
* (u,s,v) = svd(cov) # <<<<<<<<<<<<<<
* x = np.dot(x*np.sqrt(s),v)
* # The rows of x now have the correct covariance but mean 0. Add
*/
- __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3971; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_8);
+ __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_9));
__Pyx_INCREF(__pyx_v_cov);
- PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_cov);
+ PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_cov);
__Pyx_GIVEREF(__pyx_v_cov);
- __pyx_t_2 = PyObject_Call(__pyx_v_svd, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3971; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
- if (PyTuple_CheckExact(__pyx_t_2) && likely(PyTuple_GET_SIZE(__pyx_t_2) == 3)) {
- PyObject* tuple = __pyx_t_2;
- __pyx_t_8 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_8);
- __pyx_t_3 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_3);
- __pyx_t_1 = PyTuple_GET_ITEM(tuple, 2); __Pyx_INCREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_3 = PyObject_Call(__pyx_v_svd, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
+ if (PyTuple_CheckExact(__pyx_t_3) && likely(PyTuple_GET_SIZE(__pyx_t_3) == 3)) {
+ PyObject* tuple = __pyx_t_3;
+ __pyx_t_9 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_9);
+ __pyx_t_1 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_1);
+ __pyx_t_2 = PyTuple_GET_ITEM(tuple, 2); __Pyx_INCREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_DECREF(__pyx_v_u);
- __pyx_v_u = __pyx_t_8;
- __pyx_t_8 = 0;
+ __pyx_v_u = __pyx_t_9;
+ __pyx_t_9 = 0;
__Pyx_DECREF(__pyx_v_s);
- __pyx_v_s = __pyx_t_3;
- __pyx_t_3 = 0;
- __Pyx_DECREF(__pyx_v_v);
- __pyx_v_v = __pyx_t_1;
+ __pyx_v_s = __pyx_t_1;
__pyx_t_1 = 0;
+ __Pyx_DECREF(__pyx_v_v);
+ __pyx_v_v = __pyx_t_2;
+ __pyx_t_2 = 0;
} else {
- __pyx_t_9 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3971; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_10 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_10);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_t_9 = __Pyx_UnpackItem(__pyx_t_10, 0); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_9);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_8 = __Pyx_UnpackItem(__pyx_t_9, 0); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3971; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_8);
- __pyx_t_3 = __Pyx_UnpackItem(__pyx_t_9, 1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3971; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_1 = __Pyx_UnpackItem(__pyx_t_9, 2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3971; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_UnpackItem(__pyx_t_10, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- if (__Pyx_EndUnpack(__pyx_t_9) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3971; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+ __pyx_t_2 = __Pyx_UnpackItem(__pyx_t_10, 2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ if (__Pyx_EndUnpack(__pyx_t_10, 3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
__Pyx_DECREF(__pyx_v_u);
- __pyx_v_u = __pyx_t_8;
- __pyx_t_8 = 0;
+ __pyx_v_u = __pyx_t_9;
+ __pyx_t_9 = 0;
__Pyx_DECREF(__pyx_v_s);
- __pyx_v_s = __pyx_t_3;
- __pyx_t_3 = 0;
- __Pyx_DECREF(__pyx_v_v);
- __pyx_v_v = __pyx_t_1;
+ __pyx_v_s = __pyx_t_1;
__pyx_t_1 = 0;
+ __Pyx_DECREF(__pyx_v_v);
+ __pyx_v_v = __pyx_t_2;
+ __pyx_t_2 = 0;
}
- /* "mtrand.pyx":3972
+ /* "mtrand.pyx":4008
* # XXX: we really should be doing this by Cholesky decomposition
* (u,s,v) = svd(cov)
* x = np.dot(x*np.sqrt(s),v) # <<<<<<<<<<<<<<
* # The rows of x now have the correct covariance but mean 0. Add
* # mean to each row. Then each row will have mean mean.
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3972; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__dot); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3972; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3972; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__sqrt); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3972; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4008; __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(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3972; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__dot); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__sqrt); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(__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 = 4008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_3));
__Pyx_INCREF(__pyx_v_s);
- PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_s);
+ PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_s);
__Pyx_GIVEREF(__pyx_v_s);
- __pyx_t_8 = PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3972; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_8);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyNumber_Multiply(__pyx_v_x, __pyx_t_8); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3972; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
- __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3972; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_8);
- PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2);
- __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_9 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_9);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
+ __pyx_t_3 = PyNumber_Multiply(__pyx_v_x, __pyx_t_9); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+ __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_9));
+ PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_3);
+ __Pyx_GIVEREF(__pyx_t_3);
__Pyx_INCREF(__pyx_v_v);
- PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_v_v);
+ PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_v_v);
__Pyx_GIVEREF(__pyx_v_v);
- __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_Call(__pyx_t_1, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3972; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+ __pyx_t_3 = 0;
+ __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
__Pyx_DECREF(__pyx_v_x);
- __pyx_v_x = __pyx_t_2;
- __pyx_t_2 = 0;
+ __pyx_v_x = __pyx_t_3;
+ __pyx_t_3 = 0;
- /* "mtrand.pyx":3975
+ /* "mtrand.pyx":4011
* # The rows of x now have the correct covariance but mean 0. Add
* # mean to each row. Then each row will have mean mean.
* np.add(mean,x,x) # <<<<<<<<<<<<<<
* x.shape = tuple(final_shape)
* return x
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3975; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_8 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__add); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3975; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_8);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3975; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_t_9 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__add); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_9);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_3));
__Pyx_INCREF(__pyx_v_mean);
- PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_mean);
+ PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_mean);
__Pyx_GIVEREF(__pyx_v_mean);
__Pyx_INCREF(__pyx_v_x);
- PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_x);
+ PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_x);
__Pyx_GIVEREF(__pyx_v_x);
__Pyx_INCREF(__pyx_v_x);
- PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_x);
+ PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_x);
__Pyx_GIVEREF(__pyx_v_x);
- __pyx_t_1 = PyObject_Call(__pyx_t_8, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3975; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- /* "mtrand.pyx":3976
+ /* "mtrand.pyx":4012
* # mean to each row. Then each row will have mean mean.
* np.add(mean,x,x)
* x.shape = tuple(final_shape) # <<<<<<<<<<<<<<
* return x
*
*/
- __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3976; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __Pyx_INCREF(__pyx_v_final_shape);
- PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_final_shape);
- __Pyx_GIVEREF(__pyx_v_final_shape);
- __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)&PyTuple_Type)), __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3976; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- if (PyObject_SetAttr(__pyx_v_x, __pyx_n_s__shape, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3976; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ if (unlikely(__pyx_v_final_shape == Py_None)) {
+ PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4012; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ __pyx_t_2 = ((PyObject *)PyList_AsTuple(__pyx_v_final_shape)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4012; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
+ if (PyObject_SetAttr(__pyx_v_x, __pyx_n_s__shape, ((PyObject *)__pyx_t_2)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4012; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
- /* "mtrand.pyx":3977
+ /* "mtrand.pyx":4013
* np.add(mean,x,x)
* x.shape = tuple(final_shape)
* return x # <<<<<<<<<<<<<<
@@ -17546,8 +16976,8 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multivariate_normal(PyObject *__
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
- __Pyx_XDECREF(__pyx_t_8);
__Pyx_XDECREF(__pyx_t_9);
+ __Pyx_XDECREF(__pyx_t_10);
__Pyx_AddTraceback("mtrand.RandomState.multivariate_normal");
__pyx_r = NULL;
__pyx_L0:;
@@ -17558,16 +16988,14 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multivariate_normal(PyObject *__
__Pyx_DECREF(__pyx_v_u);
__Pyx_DECREF(__pyx_v_s);
__Pyx_DECREF(__pyx_v_v);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
__Pyx_DECREF(__pyx_v_mean);
__Pyx_DECREF(__pyx_v_cov);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":3979
+/* "mtrand.pyx":4015
* return x
*
* def multinomial(self, long n, object pvals, size=None): # <<<<<<<<<<<<<<
@@ -17575,9 +17003,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multivariate_normal(PyObject *__
* multinomial(n, pvals, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_multinomial(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_multinomial[] = "\n multinomial(n, pvals, size=None)\n\n Draw samples from a multinomial distribution.\n\n The multinomial distribution is a multivariate generalisation of the\n binomial distribution. Take an experiment with one of ``p``\n possible outcomes. An example of such an experiment is throwing a dice,\n where the outcome can be 1 through 6. Each sample drawn from the\n distribution represents `n` such experiments. Its values,\n ``X_i = [X_0, X_1, ..., X_p]``, represent the number of times the outcome\n was ``i``.\n\n Parameters\n ----------\n n : int\n Number of experiments.\n pvals : sequence of floats, length p\n Probabilities of each of the ``p`` different outcomes. These\n should sum to 1 (however, the last element is always assumed to\n account for the remaining probability, as long as\n ``sum(pvals[:-1]) <= 1)``.\n size : tuple of ints\n Given a `size` of ``(M, N, K)``, then ``M*N*K`` samples are drawn,\n and the output shape becomes ``(M, N, K, p)``, since each sample\n has shape ``(p,)``.\n\n Examples\n --------\n Throw a dice 20 times:\n\n >>> np.random.multinomial(20, [1/6.]*6, size=1)\n array([[4, 1, 7, 5, 2, 1]])\n\n It landed 4 times on 1, once on 2, etc.\n\n Now, throw the dice 20 times, and 20 times again:\n\n >>> np.random.multinomial(20, [1/6.]*6, size=2)\n array([[3, 4, 3, 3, 4, 3],\n [2, 4, 3, 4, 0, 7]])\n\n For the first run, we threw 3 times 1, 4 times 2, etc. For the second,\n we threw 2 times 1, 4 times 2, etc.\n\n A loaded dice is more likely to land on number 6:\n\n >>> np.random.multinomial(100, [1/7.]*5)\n array([13, 16, 13, 16, 42])\n\n ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_multinomial(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_48multinomial(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_48multinomial[] = "\n multinomial(n, pvals, size=None)\n\n Draw samples from a multinomial distribution.\n\n The multinomial distribution is a multivariate generalisation of the\n binomial distribution. Take an experiment with one of ``p``\n possible outcomes. An example of such an experiment is throwing a dice,\n where the outcome can be 1 through 6. Each sample drawn from the\n distribution represents `n` such experiments. Its values,\n ``X_i = [X_0, X_1, ..., X_p]``, represent the number of times the outcome\n was ``i``.\n\n Parameters\n ----------\n n : int\n Number of experiments.\n pvals : sequence of floats, length p\n Probabilities of each of the ``p`` different outcomes. These\n should sum to 1 (however, the last element is always assumed to\n account for the remaining probability, as long as\n ``sum(pvals[:-1]) <= 1)``.\n size : tuple of ints\n Given a `size` of ``(M, N, K)``, then ``M*N*K`` samples are drawn,\n and the output shape becomes ``(M, N, K, p)``, since each sample\n has shape ``(p,)``.\n\n Examples\n --------\n Throw a dice 20 times:\n\n >>> np.random.multinomial(20, [1/6.]*6, size=1)\n array([[4, 1, 7, 5, 2, 1]])\n\n It landed 4 times on 1, once on 2, etc.\n\n Now, throw the dice 20 times, and 20 times again:\n\n >>> np.random.multinomial(20, [1/6.]*6, size=2)\n array([[3, 4, 3, 3, 4, 3],\n [2, 4, 3, 4, 0, 7]])\n\n For the first run, we threw 3 times 1, 4 times 2, etc. For the second,\n we threw 2 times 1, 4 times 2, etc.\n\n A loaded dice is more likely to land on number 6:\n\n >>> np.random.multinomial(100, [1/7.]*5)\n array([13, 16, 13, 16, 42])\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_48multinomial(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
long __pyx_v_n;
PyObject *__pyx_v_pvals = 0;
PyObject *__pyx_v_size = 0;
@@ -17622,18 +17050,18 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multinomial(PyObject *__pyx_v_se
values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pvals);
if (likely(values[1])) kw_args--;
else {
- __Pyx_RaiseArgtupleInvalid("multinomial", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3979; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("multinomial", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4015; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
case 2:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[2] = value; kw_args--; }
+ if (value) { values[2] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "multinomial") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3979; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "multinomial") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4015; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
- __pyx_v_n = __Pyx_PyInt_AsLong(values[0]); if (unlikely((__pyx_v_n == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3979; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __pyx_v_n = __Pyx_PyInt_AsLong(values[0]); if (unlikely((__pyx_v_n == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4015; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_v_pvals = values[1];
__pyx_v_size = values[2];
} else {
@@ -17643,51 +17071,49 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multinomial(PyObject *__pyx_v_se
__pyx_v_size = PyTuple_GET_ITEM(__pyx_args, 2);
case 2:
__pyx_v_pvals = PyTuple_GET_ITEM(__pyx_args, 1);
- __pyx_v_n = __Pyx_PyInt_AsLong(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_n == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3979; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __pyx_v_n = __Pyx_PyInt_AsLong(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_n == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4015; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
break;
default: goto __pyx_L5_argtuple_error;
}
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("multinomial", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3979; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("multinomial", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4015; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.multinomial");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_pvals);
- __Pyx_INCREF(__pyx_v_size);
arrayObject_parr = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
arrayObject_mnarr = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_shape = Py_None; __Pyx_INCREF(Py_None);
__pyx_v_multin = Py_None; __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":4038
+ /* "mtrand.pyx":4074
* cdef double Sum
*
* d = len(pvals) # <<<<<<<<<<<<<<
* parr = <ndarray>PyArray_ContiguousFromObject(pvals, NPY_DOUBLE, 1, 1)
* pix = <double*>parr.data
*/
- __pyx_t_1 = PyObject_Length(__pyx_v_pvals); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4038; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyObject_Length(__pyx_v_pvals); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_v_d = __pyx_t_1;
- /* "mtrand.pyx":4039
+ /* "mtrand.pyx":4075
*
* d = len(pvals)
* parr = <ndarray>PyArray_ContiguousFromObject(pvals, NPY_DOUBLE, 1, 1) # <<<<<<<<<<<<<<
* pix = <double*>parr.data
*
*/
- __pyx_t_2 = PyArray_ContiguousFromObject(__pyx_v_pvals, NPY_DOUBLE, 1, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4039; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyArray_ContiguousFromObject(__pyx_v_pvals, NPY_DOUBLE, 1, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)arrayObject_parr));
arrayObject_parr = ((PyArrayObject *)__pyx_t_2);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4040
+ /* "mtrand.pyx":4076
* d = len(pvals)
* parr = <ndarray>PyArray_ContiguousFromObject(pvals, NPY_DOUBLE, 1, 1)
* pix = <double*>parr.data # <<<<<<<<<<<<<<
@@ -17696,39 +17122,33 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multinomial(PyObject *__pyx_v_se
*/
__pyx_v_pix = ((double *)arrayObject_parr->data);
- /* "mtrand.pyx":4042
+ /* "mtrand.pyx":4078
* pix = <double*>parr.data
*
* if kahan_sum(pix, d-1) > (1.0 + 1e-12): # <<<<<<<<<<<<<<
* raise ValueError("sum(pvals[:-1]) > 1.0")
*
*/
- __pyx_t_3 = (__pyx_f_6mtrand_kahan_sum(__pyx_v_pix, (__pyx_v_d - 1)) > (1.0 + 9.9999999999999998e-13));
+ __pyx_t_3 = (__pyx_f_6mtrand_kahan_sum(__pyx_v_pix, (__pyx_v_d - 1)) > (1.0 + 1e-12));
if (__pyx_t_3) {
- /* "mtrand.pyx":4043
+ /* "mtrand.pyx":4079
*
* if kahan_sum(pix, d-1) > (1.0 + 1e-12):
* raise ValueError("sum(pvals[:-1]) > 1.0") # <<<<<<<<<<<<<<
*
* if size is None:
*/
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4043; __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 = 4079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(((PyObject *)__pyx_kp_s_58));
- PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_58));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_58));
- __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_Raise(__pyx_t_2, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_Raise(__pyx_t_4, 0, 0);
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L6;
}
__pyx_L6:;
- /* "mtrand.pyx":4045
+ /* "mtrand.pyx":4081
* raise ValueError("sum(pvals[:-1]) > 1.0")
*
* if size is None: # <<<<<<<<<<<<<<
@@ -17738,112 +17158,112 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multinomial(PyObject *__pyx_v_se
__pyx_t_3 = (__pyx_v_size == Py_None);
if (__pyx_t_3) {
- /* "mtrand.pyx":4046
+ /* "mtrand.pyx":4082
*
* if size is None:
* shape = (d,) # <<<<<<<<<<<<<<
* elif type(size) is int:
* shape = (size, d)
*/
- __pyx_t_4 = PyInt_FromLong(__pyx_v_d); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyInt_FromLong(__pyx_v_d); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4082; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
- __Pyx_GIVEREF(__pyx_t_4);
- __pyx_t_4 = 0;
- __Pyx_DECREF(__pyx_v_shape);
- __pyx_v_shape = __pyx_t_2;
+ __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4082; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
+ PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
__pyx_t_2 = 0;
+ __Pyx_DECREF(__pyx_v_shape);
+ __pyx_v_shape = ((PyObject *)__pyx_t_4);
+ __pyx_t_4 = 0;
goto __pyx_L7;
}
- /* "mtrand.pyx":4047
+ /* "mtrand.pyx":4083
* if size is None:
* shape = (d,)
* elif type(size) is int: # <<<<<<<<<<<<<<
* shape = (size, d)
* else:
*/
- __pyx_t_3 = (((PyObject *)Py_TYPE(__pyx_v_size)) == ((PyObject *)((PyObject*)&PyInt_Type)));
+ __pyx_t_3 = (((PyObject *)Py_TYPE(__pyx_v_size)) == ((PyObject *)((PyObject*)(&PyInt_Type))));
if (__pyx_t_3) {
- /* "mtrand.pyx":4048
+ /* "mtrand.pyx":4084
* shape = (d,)
* elif type(size) is int:
* shape = (size, d) # <<<<<<<<<<<<<<
* else:
* shape = size + (d,)
*/
- __pyx_t_2 = PyInt_FromLong(__pyx_v_d); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyInt_FromLong(__pyx_v_d); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4084; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4084; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_size);
- PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_size);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_size);
__Pyx_GIVEREF(__pyx_v_size);
- PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
- __Pyx_GIVEREF(__pyx_t_2);
- __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_v_shape);
- __pyx_v_shape = __pyx_t_4;
+ PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4);
+ __Pyx_GIVEREF(__pyx_t_4);
__pyx_t_4 = 0;
+ __Pyx_DECREF(__pyx_v_shape);
+ __pyx_v_shape = ((PyObject *)__pyx_t_2);
+ __pyx_t_2 = 0;
goto __pyx_L7;
}
/*else*/ {
- /* "mtrand.pyx":4050
+ /* "mtrand.pyx":4086
* shape = (size, d)
* else:
* shape = size + (d,) # <<<<<<<<<<<<<<
*
* multin = np.zeros(shape, int)
*/
- __pyx_t_4 = PyInt_FromLong(__pyx_v_d); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyInt_FromLong(__pyx_v_d); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4086; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
- __Pyx_GIVEREF(__pyx_t_4);
- __pyx_t_4 = 0;
- __pyx_t_4 = PyNumber_Add(__pyx_v_size, __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4086; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
+ PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyNumber_Add(__pyx_v_size, ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4086; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
__Pyx_DECREF(__pyx_v_shape);
- __pyx_v_shape = __pyx_t_4;
- __pyx_t_4 = 0;
+ __pyx_v_shape = __pyx_t_2;
+ __pyx_t_2 = 0;
}
__pyx_L7:;
- /* "mtrand.pyx":4052
+ /* "mtrand.pyx":4088
* shape = size + (d,)
*
* multin = np.zeros(shape, int) # <<<<<<<<<<<<<<
* mnarr = <ndarray>multin
* mnix = <long*>mnarr.data
*/
- __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4088; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __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 = 4052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__zeros); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4088; __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 = 4088; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_shape);
- PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_shape);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_shape);
__Pyx_GIVEREF(__pyx_v_shape);
- __Pyx_INCREF(((PyObject *)((PyObject*)&PyInt_Type)));
- PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)((PyObject*)&PyInt_Type)));
- __Pyx_GIVEREF(((PyObject *)((PyObject*)&PyInt_Type)));
- __pyx_t_5 = PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_INCREF(((PyObject *)((PyObject*)(&PyInt_Type))));
+ PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)((PyObject*)(&PyInt_Type))));
+ __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyInt_Type))));
+ __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 = 4088; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
__Pyx_DECREF(__pyx_v_multin);
__pyx_v_multin = __pyx_t_5;
__pyx_t_5 = 0;
- /* "mtrand.pyx":4053
+ /* "mtrand.pyx":4089
*
* multin = np.zeros(shape, int)
* mnarr = <ndarray>multin # <<<<<<<<<<<<<<
@@ -17854,7 +17274,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multinomial(PyObject *__pyx_v_se
__Pyx_DECREF(((PyObject *)arrayObject_mnarr));
arrayObject_mnarr = ((PyArrayObject *)__pyx_v_multin);
- /* "mtrand.pyx":4054
+ /* "mtrand.pyx":4090
* multin = np.zeros(shape, int)
* mnarr = <ndarray>multin
* mnix = <long*>mnarr.data # <<<<<<<<<<<<<<
@@ -17863,7 +17283,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multinomial(PyObject *__pyx_v_se
*/
__pyx_v_mnix = ((long *)arrayObject_mnarr->data);
- /* "mtrand.pyx":4055
+ /* "mtrand.pyx":4091
* mnarr = <ndarray>multin
* mnix = <long*>mnarr.data
* i = 0 # <<<<<<<<<<<<<<
@@ -17872,7 +17292,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multinomial(PyObject *__pyx_v_se
*/
__pyx_v_i = 0;
- /* "mtrand.pyx":4056
+ /* "mtrand.pyx":4092
* mnix = <long*>mnarr.data
* i = 0
* while i < PyArray_SIZE(mnarr): # <<<<<<<<<<<<<<
@@ -17883,7 +17303,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multinomial(PyObject *__pyx_v_se
__pyx_t_3 = (__pyx_v_i < PyArray_SIZE(arrayObject_mnarr));
if (!__pyx_t_3) break;
- /* "mtrand.pyx":4057
+ /* "mtrand.pyx":4093
* i = 0
* while i < PyArray_SIZE(mnarr):
* Sum = 1.0 # <<<<<<<<<<<<<<
@@ -17892,7 +17312,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multinomial(PyObject *__pyx_v_se
*/
__pyx_v_Sum = 1.0;
- /* "mtrand.pyx":4058
+ /* "mtrand.pyx":4094
* while i < PyArray_SIZE(mnarr):
* Sum = 1.0
* dn = n # <<<<<<<<<<<<<<
@@ -17901,7 +17321,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multinomial(PyObject *__pyx_v_se
*/
__pyx_v_dn = __pyx_v_n;
- /* "mtrand.pyx":4059
+ /* "mtrand.pyx":4095
* Sum = 1.0
* dn = n
* for j from 0 <= j < d-1: # <<<<<<<<<<<<<<
@@ -17911,7 +17331,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multinomial(PyObject *__pyx_v_se
__pyx_t_6 = (__pyx_v_d - 1);
for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_6; __pyx_v_j++) {
- /* "mtrand.pyx":4060
+ /* "mtrand.pyx":4096
* dn = n
* for j from 0 <= j < d-1:
* mnix[i+j] = rk_binomial(self.internal_state, dn, pix[j]/Sum) # <<<<<<<<<<<<<<
@@ -17921,11 +17341,11 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multinomial(PyObject *__pyx_v_se
__pyx_t_7 = (__pyx_v_pix[__pyx_v_j]);
if (unlikely(__pyx_v_Sum == 0)) {
PyErr_Format(PyExc_ZeroDivisionError, "float division");
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4060; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4096; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
(__pyx_v_mnix[(__pyx_v_i + __pyx_v_j)]) = rk_binomial(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, __pyx_v_dn, (__pyx_t_7 / __pyx_v_Sum));
- /* "mtrand.pyx":4061
+ /* "mtrand.pyx":4097
* for j from 0 <= j < d-1:
* mnix[i+j] = rk_binomial(self.internal_state, dn, pix[j]/Sum)
* dn = dn - mnix[i+j] # <<<<<<<<<<<<<<
@@ -17934,7 +17354,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multinomial(PyObject *__pyx_v_se
*/
__pyx_v_dn = (__pyx_v_dn - (__pyx_v_mnix[(__pyx_v_i + __pyx_v_j)]));
- /* "mtrand.pyx":4062
+ /* "mtrand.pyx":4098
* mnix[i+j] = rk_binomial(self.internal_state, dn, pix[j]/Sum)
* dn = dn - mnix[i+j]
* if dn <= 0: # <<<<<<<<<<<<<<
@@ -17944,7 +17364,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multinomial(PyObject *__pyx_v_se
__pyx_t_3 = (__pyx_v_dn <= 0);
if (__pyx_t_3) {
- /* "mtrand.pyx":4063
+ /* "mtrand.pyx":4099
* dn = dn - mnix[i+j]
* if dn <= 0:
* break # <<<<<<<<<<<<<<
@@ -17956,7 +17376,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multinomial(PyObject *__pyx_v_se
}
__pyx_L12:;
- /* "mtrand.pyx":4064
+ /* "mtrand.pyx":4100
* if dn <= 0:
* break
* Sum = Sum - pix[j] # <<<<<<<<<<<<<<
@@ -17967,7 +17387,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multinomial(PyObject *__pyx_v_se
}
__pyx_L11_break:;
- /* "mtrand.pyx":4065
+ /* "mtrand.pyx":4101
* break
* Sum = Sum - pix[j]
* if dn > 0: # <<<<<<<<<<<<<<
@@ -17977,7 +17397,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multinomial(PyObject *__pyx_v_se
__pyx_t_3 = (__pyx_v_dn > 0);
if (__pyx_t_3) {
- /* "mtrand.pyx":4066
+ /* "mtrand.pyx":4102
* Sum = Sum - pix[j]
* if dn > 0:
* mnix[i+d-1] = dn # <<<<<<<<<<<<<<
@@ -17989,7 +17409,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multinomial(PyObject *__pyx_v_se
}
__pyx_L13:;
- /* "mtrand.pyx":4068
+ /* "mtrand.pyx":4104
* mnix[i+d-1] = dn
*
* i = i + d # <<<<<<<<<<<<<<
@@ -17999,7 +17419,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multinomial(PyObject *__pyx_v_se
__pyx_v_i = (__pyx_v_i + __pyx_v_d);
}
- /* "mtrand.pyx":4070
+ /* "mtrand.pyx":4106
* i = i + d
*
* return multin # <<<<<<<<<<<<<<
@@ -18024,15 +17444,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multinomial(PyObject *__pyx_v_se
__Pyx_DECREF((PyObject *)arrayObject_mnarr);
__Pyx_DECREF(__pyx_v_shape);
__Pyx_DECREF(__pyx_v_multin);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_pvals);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":4072
+/* "mtrand.pyx":4108
* return multin
*
* def dirichlet(self, object alpha, size=None): # <<<<<<<<<<<<<<
@@ -18040,9 +17457,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_multinomial(PyObject *__pyx_v_se
* dirichlet(alpha, size=None)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_dirichlet(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_dirichlet[] = "\n dirichlet(alpha, size=None)\n\n Draw samples from the Dirichlet distribution.\n\n Draw `size` samples of dimension k from a Dirichlet distribution. A\n Dirichlet-distributed random variable can be seen as a multivariate\n generalization of a Beta distribution. Dirichlet pdf is the conjugate\n prior of a multinomial in Bayesian inference.\n\n Parameters\n ----------\n alpha : array\n Parameter of the distribution (k dimension for sample of\n dimension k).\n size : array\n Number of samples to draw.\n\n Notes\n -----\n .. math:: X \\approx \\prod_{i=1}^{k}{x^{\\alpha_i-1}_i}\n\n Uses the following property for computation: for each dimension,\n draw a random sample y_i from a standard gamma generator of shape\n `alpha_i`, then\n :math:`X = \\frac{1}{\\sum_{i=1}^k{y_i}} (y_1, \\ldots, y_n)` is\n Dirichlet distributed.\n\n References\n ----------\n .. [1] David McKay, \"Information Theory, Inference and Learning\n Algorithms,\" chapter 23,\n http://www.inference.phy.cam.ac.uk/mackay/\n\n ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_dirichlet(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_49dirichlet(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_49dirichlet[] = "\n dirichlet(alpha, size=None)\n\n Draw samples from the Dirichlet distribution.\n\n Draw `size` samples of dimension k from a Dirichlet distribution. A\n Dirichlet-distributed random variable can be seen as a multivariate\n generalization of a Beta distribution. Dirichlet pdf is the conjugate\n prior of a multinomial in Bayesian inference.\n\n Parameters\n ----------\n alpha : array\n Parameter of the distribution (k dimension for sample of\n dimension k).\n size : array\n Number of samples to draw.\n\n Returns\n -------\n samples : ndarray,\n The drawn samples, of shape (alpha.ndim, size).\n\n Notes\n -----\n .. math:: X \\approx \\prod_{i=1}^{k}{x^{\\alpha_i-1}_i}\n\n Uses the following property for computation: for each dimension,\n draw a random sample y_i from a standard gamma generator of shape\n `alpha_i`, then\n :math:`X = \\frac{1}{\\sum_{i=1}^k{y_i}} (y_1, \\ldots, y_n)` is\n Dirichlet distributed.\n\n References\n ----------\n .. [1] David McKay, \"Information Theory, Inference and Learning\n Algorithms,\" chapter 23,\n http://www.inference.phy.cam.ac.uk/mackay/\n .. [2] Wikipedia, \"Dirichlet distribution\",\n http://en.wikipedia.org/wiki/Dirichlet_distribution\n\n Examples\n --------\n Taking an example cited in Wikipedia, this distribution can be used if\n one wanted to cut strings (each of initial length 1.0) into K pieces\n with different lengths, where each piece had, on average, a designated\n average length, but allowing some variation in the relative sizes of the\n pieces.\n\n >>> s = np.random.dirichlet((10, 5, 3), 20).transpose()\n\n >>> plt.barh(range(20), s[0])\n >>> plt.barh(range(20), s[1], left=s[0], color='g')""\n >>> plt.barh(range(20), s[2], left=s[0]+s[1], color='r')\n >>> plt.title(\"Lengths of Strings\")\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_49dirichlet(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_alpha = 0;
PyObject *__pyx_v_size = 0;
long __pyx_v_k;
@@ -18082,13 +17499,13 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_dirichlet(PyObject *__pyx_v_self
if (likely(values[0])) kw_args--;
else goto __pyx_L5_argtuple_error;
case 1:
- if (kw_args > 1) {
+ if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
- if (unlikely(value)) { values[1] = value; kw_args--; }
+ if (value) { values[1] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "dirichlet") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4072; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "dirichlet") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4108; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_alpha = values[0];
__pyx_v_size = values[1];
@@ -18103,44 +17520,42 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_dirichlet(PyObject *__pyx_v_self
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("dirichlet", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4072; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("dirichlet", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4108; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("mtrand.RandomState.dirichlet");
+ __Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_alpha);
- __Pyx_INCREF(__pyx_v_size);
__pyx_v_alpha_arr = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_val_arr = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_v_shape = Py_None; __Pyx_INCREF(Py_None);
__pyx_v_diric = Py_None; __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":4136
+ /* "mtrand.pyx":4194
* cdef double acc, invacc
*
* k = len(alpha) # <<<<<<<<<<<<<<
* alpha_arr = <ndarray>PyArray_ContiguousFromObject(alpha, NPY_DOUBLE, 1, 1)
* alpha_data = <double*>alpha_arr.data
*/
- __pyx_t_1 = PyObject_Length(__pyx_v_alpha); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyObject_Length(__pyx_v_alpha); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_v_k = __pyx_t_1;
- /* "mtrand.pyx":4137
+ /* "mtrand.pyx":4195
*
* k = len(alpha)
* alpha_arr = <ndarray>PyArray_ContiguousFromObject(alpha, NPY_DOUBLE, 1, 1) # <<<<<<<<<<<<<<
* alpha_data = <double*>alpha_arr.data
*
*/
- __pyx_t_2 = PyArray_ContiguousFromObject(__pyx_v_alpha, NPY_DOUBLE, 1, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyArray_ContiguousFromObject(__pyx_v_alpha, NPY_DOUBLE, 1, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_t_2)));
__Pyx_DECREF(((PyObject *)__pyx_v_alpha_arr));
__pyx_v_alpha_arr = ((PyArrayObject *)__pyx_t_2);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4138
+ /* "mtrand.pyx":4196
* k = len(alpha)
* alpha_arr = <ndarray>PyArray_ContiguousFromObject(alpha, NPY_DOUBLE, 1, 1)
* alpha_data = <double*>alpha_arr.data # <<<<<<<<<<<<<<
@@ -18149,7 +17564,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_dirichlet(PyObject *__pyx_v_self
*/
__pyx_v_alpha_data = ((double *)__pyx_v_alpha_arr->data);
- /* "mtrand.pyx":4140
+ /* "mtrand.pyx":4198
* alpha_data = <double*>alpha_arr.data
*
* if size is None: # <<<<<<<<<<<<<<
@@ -18159,47 +17574,47 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_dirichlet(PyObject *__pyx_v_self
__pyx_t_3 = (__pyx_v_size == Py_None);
if (__pyx_t_3) {
- /* "mtrand.pyx":4141
+ /* "mtrand.pyx":4199
*
* if size is None:
* shape = (k,) # <<<<<<<<<<<<<<
* elif type(size) is int:
* shape = (size, k)
*/
- __pyx_t_2 = PyInt_FromLong(__pyx_v_k); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyInt_FromLong(__pyx_v_k); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
__Pyx_GIVEREF(__pyx_t_2);
__pyx_t_2 = 0;
__Pyx_DECREF(__pyx_v_shape);
- __pyx_v_shape = __pyx_t_4;
+ __pyx_v_shape = ((PyObject *)__pyx_t_4);
__pyx_t_4 = 0;
goto __pyx_L6;
}
- /* "mtrand.pyx":4142
+ /* "mtrand.pyx":4200
* if size is None:
* shape = (k,)
* elif type(size) is int: # <<<<<<<<<<<<<<
* shape = (size, k)
* else:
*/
- __pyx_t_3 = (((PyObject *)Py_TYPE(__pyx_v_size)) == ((PyObject *)((PyObject*)&PyInt_Type)));
+ __pyx_t_3 = (((PyObject *)Py_TYPE(__pyx_v_size)) == ((PyObject *)((PyObject*)(&PyInt_Type))));
if (__pyx_t_3) {
- /* "mtrand.pyx":4143
+ /* "mtrand.pyx":4201
* shape = (k,)
* elif type(size) is int:
* shape = (size, k) # <<<<<<<<<<<<<<
* else:
* shape = size + (k,)
*/
- __pyx_t_4 = PyInt_FromLong(__pyx_v_k); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyInt_FromLong(__pyx_v_k); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_size);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_size);
__Pyx_GIVEREF(__pyx_v_size);
@@ -18207,69 +17622,69 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_dirichlet(PyObject *__pyx_v_self
__Pyx_GIVEREF(__pyx_t_4);
__pyx_t_4 = 0;
__Pyx_DECREF(__pyx_v_shape);
- __pyx_v_shape = __pyx_t_2;
+ __pyx_v_shape = ((PyObject *)__pyx_t_2);
__pyx_t_2 = 0;
goto __pyx_L6;
}
/*else*/ {
- /* "mtrand.pyx":4145
+ /* "mtrand.pyx":4203
* shape = (size, k)
* else:
* shape = size + (k,) # <<<<<<<<<<<<<<
*
* diric = np.zeros(shape, np.float64)
*/
- __pyx_t_2 = PyInt_FromLong(__pyx_v_k); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyInt_FromLong(__pyx_v_k); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
__Pyx_GIVEREF(__pyx_t_2);
__pyx_t_2 = 0;
- __pyx_t_2 = PyNumber_Add(__pyx_v_size, __pyx_t_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyNumber_Add(__pyx_v_size, ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
__Pyx_DECREF(__pyx_v_shape);
__pyx_v_shape = __pyx_t_2;
__pyx_t_2 = 0;
}
__pyx_L6:;
- /* "mtrand.pyx":4147
+ /* "mtrand.pyx":4205
* shape = size + (k,)
*
* diric = np.zeros(shape, np.float64) # <<<<<<<<<<<<<<
* val_arr = <ndarray>diric
* val_data= <double*>val_arr.data
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__zeros); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__zeros); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_5 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__float64); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__float64); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__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 = 4147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_shape);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_shape);
__Pyx_GIVEREF(__pyx_v_shape);
PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5);
__Pyx_GIVEREF(__pyx_t_5);
__pyx_t_5 = 0;
- __pyx_t_5 = PyObject_Call(__pyx_t_4, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __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 = 4205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
__Pyx_DECREF(__pyx_v_diric);
__pyx_v_diric = __pyx_t_5;
__pyx_t_5 = 0;
- /* "mtrand.pyx":4148
+ /* "mtrand.pyx":4206
*
* diric = np.zeros(shape, np.float64)
* val_arr = <ndarray>diric # <<<<<<<<<<<<<<
@@ -18280,7 +17695,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_dirichlet(PyObject *__pyx_v_self
__Pyx_DECREF(((PyObject *)__pyx_v_val_arr));
__pyx_v_val_arr = ((PyArrayObject *)__pyx_v_diric);
- /* "mtrand.pyx":4149
+ /* "mtrand.pyx":4207
* diric = np.zeros(shape, np.float64)
* val_arr = <ndarray>diric
* val_data= <double*>val_arr.data # <<<<<<<<<<<<<<
@@ -18289,7 +17704,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_dirichlet(PyObject *__pyx_v_self
*/
__pyx_v_val_data = ((double *)__pyx_v_val_arr->data);
- /* "mtrand.pyx":4151
+ /* "mtrand.pyx":4209
* val_data= <double*>val_arr.data
*
* i = 0 # <<<<<<<<<<<<<<
@@ -18298,7 +17713,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_dirichlet(PyObject *__pyx_v_self
*/
__pyx_v_i = 0;
- /* "mtrand.pyx":4152
+ /* "mtrand.pyx":4210
*
* i = 0
* totsize = PyArray_SIZE(val_arr) # <<<<<<<<<<<<<<
@@ -18307,7 +17722,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_dirichlet(PyObject *__pyx_v_self
*/
__pyx_v_totsize = PyArray_SIZE(__pyx_v_val_arr);
- /* "mtrand.pyx":4153
+ /* "mtrand.pyx":4211
* i = 0
* totsize = PyArray_SIZE(val_arr)
* while i < totsize: # <<<<<<<<<<<<<<
@@ -18318,7 +17733,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_dirichlet(PyObject *__pyx_v_self
__pyx_t_3 = (__pyx_v_i < __pyx_v_totsize);
if (!__pyx_t_3) break;
- /* "mtrand.pyx":4154
+ /* "mtrand.pyx":4212
* totsize = PyArray_SIZE(val_arr)
* while i < totsize:
* acc = 0.0 # <<<<<<<<<<<<<<
@@ -18327,7 +17742,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_dirichlet(PyObject *__pyx_v_self
*/
__pyx_v_acc = 0.0;
- /* "mtrand.pyx":4155
+ /* "mtrand.pyx":4213
* while i < totsize:
* acc = 0.0
* for j from 0 <= j < k: # <<<<<<<<<<<<<<
@@ -18337,7 +17752,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_dirichlet(PyObject *__pyx_v_self
__pyx_t_6 = __pyx_v_k;
for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_6; __pyx_v_j++) {
- /* "mtrand.pyx":4156
+ /* "mtrand.pyx":4214
* acc = 0.0
* for j from 0 <= j < k:
* val_data[i+j] = rk_standard_gamma(self.internal_state, alpha_data[j]) # <<<<<<<<<<<<<<
@@ -18346,7 +17761,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_dirichlet(PyObject *__pyx_v_self
*/
(__pyx_v_val_data[(__pyx_v_i + __pyx_v_j)]) = rk_standard_gamma(((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state, (__pyx_v_alpha_data[__pyx_v_j]));
- /* "mtrand.pyx":4157
+ /* "mtrand.pyx":4215
* for j from 0 <= j < k:
* val_data[i+j] = rk_standard_gamma(self.internal_state, alpha_data[j])
* acc = acc + val_data[i+j] # <<<<<<<<<<<<<<
@@ -18356,7 +17771,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_dirichlet(PyObject *__pyx_v_self
__pyx_v_acc = (__pyx_v_acc + (__pyx_v_val_data[(__pyx_v_i + __pyx_v_j)]));
}
- /* "mtrand.pyx":4158
+ /* "mtrand.pyx":4216
* val_data[i+j] = rk_standard_gamma(self.internal_state, alpha_data[j])
* acc = acc + val_data[i+j]
* invacc = 1/acc # <<<<<<<<<<<<<<
@@ -18365,11 +17780,11 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_dirichlet(PyObject *__pyx_v_self
*/
if (unlikely(__pyx_v_acc == 0)) {
PyErr_Format(PyExc_ZeroDivisionError, "float division");
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
- __pyx_v_invacc = (1 / __pyx_v_acc);
+ __pyx_v_invacc = (1.0 / __pyx_v_acc);
- /* "mtrand.pyx":4159
+ /* "mtrand.pyx":4217
* acc = acc + val_data[i+j]
* invacc = 1/acc
* for j from 0 <= j < k: # <<<<<<<<<<<<<<
@@ -18379,7 +17794,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_dirichlet(PyObject *__pyx_v_self
__pyx_t_6 = __pyx_v_k;
for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_6; __pyx_v_j++) {
- /* "mtrand.pyx":4160
+ /* "mtrand.pyx":4218
* invacc = 1/acc
* for j from 0 <= j < k:
* val_data[i+j] = val_data[i+j] * invacc # <<<<<<<<<<<<<<
@@ -18389,7 +17804,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_dirichlet(PyObject *__pyx_v_self
(__pyx_v_val_data[(__pyx_v_i + __pyx_v_j)]) = ((__pyx_v_val_data[(__pyx_v_i + __pyx_v_j)]) * __pyx_v_invacc);
}
- /* "mtrand.pyx":4161
+ /* "mtrand.pyx":4219
* for j from 0 <= j < k:
* val_data[i+j] = val_data[i+j] * invacc
* i = i + k # <<<<<<<<<<<<<<
@@ -18399,7 +17814,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_dirichlet(PyObject *__pyx_v_self
__pyx_v_i = (__pyx_v_i + __pyx_v_k);
}
- /* "mtrand.pyx":4163
+ /* "mtrand.pyx":4221
* i = i + k
*
* return diric # <<<<<<<<<<<<<<
@@ -18424,15 +17839,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_dirichlet(PyObject *__pyx_v_self
__Pyx_DECREF((PyObject *)__pyx_v_val_arr);
__Pyx_DECREF(__pyx_v_shape);
__Pyx_DECREF(__pyx_v_diric);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_alpha);
- __Pyx_DECREF(__pyx_v_size);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":4166
+/* "mtrand.pyx":4224
*
* # Shuffling and permutations:
* def shuffle(self, object x): # <<<<<<<<<<<<<<
@@ -18440,9 +17852,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_dirichlet(PyObject *__pyx_v_self
* shuffle(x)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_shuffle(PyObject *__pyx_v_self, PyObject *__pyx_v_x); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_shuffle[] = "\n shuffle(x)\n\n Modify a sequence in-place by shuffling its contents.\n\n ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_shuffle(PyObject *__pyx_v_self, PyObject *__pyx_v_x) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_50shuffle(PyObject *__pyx_v_self, PyObject *__pyx_v_x); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_50shuffle[] = "\n shuffle(x)\n\n Modify a sequence in-place by shuffling its contents.\n\n Parameters\n ----------\n x : array_like\n The array or list to be shuffled.\n\n Returns\n -------\n None\n\n Examples\n --------\n >>> arr = np.arange(10)\n >>> np.random.shuffle(arr)\n >>> arr\n [1 7 5 2 9 4 3 6 0 8]\n\n This function only shuffles the array along the first index of a\n multi-dimensional array:\n\n >>> arr = np.arange(9).reshape((3, 3))\n >>> np.random.shuffle(arr)\n >>> arr\n array([[3, 4, 5],\n [6, 7, 8],\n [0, 1, 2]])\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_50shuffle(PyObject *__pyx_v_self, PyObject *__pyx_v_x) {
long __pyx_v_i;
long __pyx_v_j;
int __pyx_v_copy;
@@ -18452,22 +17864,19 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_shuffle(PyObject *__pyx_v_self,
PyObject *__pyx_t_3 = NULL;
PyObject *__pyx_t_4 = NULL;
int __pyx_t_5;
- int __pyx_t_6;
__Pyx_RefNannySetupContext("shuffle");
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_x);
- /* "mtrand.pyx":4176
+ /* "mtrand.pyx":4260
* cdef int copy
*
* i = len(x) - 1 # <<<<<<<<<<<<<<
* try:
* j = len(x[0])
*/
- __pyx_t_1 = PyObject_Length(__pyx_v_x); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyObject_Length(__pyx_v_x); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_v_i = (__pyx_t_1 - 1);
- /* "mtrand.pyx":4177
+ /* "mtrand.pyx":4261
*
* i = len(x) - 1
* try: # <<<<<<<<<<<<<<
@@ -18482,16 +17891,16 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_shuffle(PyObject *__pyx_v_self,
__Pyx_XGOTREF(__pyx_save_exc_tb);
/*try:*/ {
- /* "mtrand.pyx":4178
+ /* "mtrand.pyx":4262
* i = len(x) - 1
* try:
* j = len(x[0]) # <<<<<<<<<<<<<<
* except:
* j = 0
*/
- __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_x, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4178; __pyx_clineno = __LINE__; goto __pyx_L5_error;}
+ __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_x, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4262; __pyx_clineno = __LINE__; goto __pyx_L5_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4178; __pyx_clineno = __LINE__; goto __pyx_L5_error;}
+ __pyx_t_1 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4262; __pyx_clineno = __LINE__; goto __pyx_L5_error;}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_v_j = __pyx_t_1;
}
@@ -18502,7 +17911,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_shuffle(PyObject *__pyx_v_self,
__pyx_L5_error:;
__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4179
+ /* "mtrand.pyx":4263
* try:
* j = len(x[0])
* except: # <<<<<<<<<<<<<<
@@ -18511,12 +17920,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_shuffle(PyObject *__pyx_v_self,
*/
/*except:*/ {
__Pyx_AddTraceback("mtrand.RandomState.shuffle");
- if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_3, &__pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4179; __pyx_clineno = __LINE__; goto __pyx_L7_except_error;}
+ if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_3, &__pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4263; __pyx_clineno = __LINE__; goto __pyx_L7_except_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_GOTREF(__pyx_t_3);
__Pyx_GOTREF(__pyx_t_4);
- /* "mtrand.pyx":4180
+ /* "mtrand.pyx":4264
* j = len(x[0])
* except:
* j = 0 # <<<<<<<<<<<<<<
@@ -18543,7 +17952,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_shuffle(PyObject *__pyx_v_self,
__pyx_L12_try_end:;
}
- /* "mtrand.pyx":4182
+ /* "mtrand.pyx":4266
* j = 0
*
* if (j == 0): # <<<<<<<<<<<<<<
@@ -18553,7 +17962,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_shuffle(PyObject *__pyx_v_self,
__pyx_t_5 = (__pyx_v_j == 0);
if (__pyx_t_5) {
- /* "mtrand.pyx":4184
+ /* "mtrand.pyx":4268
* if (j == 0):
* # adaptation of random.shuffle()
* while i > 0: # <<<<<<<<<<<<<<
@@ -18564,7 +17973,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_shuffle(PyObject *__pyx_v_self,
__pyx_t_5 = (__pyx_v_i > 0);
if (!__pyx_t_5) break;
- /* "mtrand.pyx":4185
+ /* "mtrand.pyx":4269
* # adaptation of random.shuffle()
* while i > 0:
* j = rk_interval(i, self.internal_state) # <<<<<<<<<<<<<<
@@ -18573,23 +17982,23 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_shuffle(PyObject *__pyx_v_self,
*/
__pyx_v_j = rk_interval(__pyx_v_i, ((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state);
- /* "mtrand.pyx":4186
+ /* "mtrand.pyx":4270
* while i > 0:
* j = rk_interval(i, self.internal_state)
* x[i], x[j] = x[j], x[i] # <<<<<<<<<<<<<<
* i = i - 1
* else:
*/
- __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_x, __pyx_v_j, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_x, __pyx_v_j, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_x, __pyx_v_i, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_x, __pyx_v_i, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- if (__Pyx_SetItemInt(__pyx_v_x, __pyx_v_i, __pyx_t_4, sizeof(long), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__Pyx_SetItemInt(__pyx_v_x, __pyx_v_i, __pyx_t_4, sizeof(long), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- if (__Pyx_SetItemInt(__pyx_v_x, __pyx_v_j, __pyx_t_3, sizeof(long), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__Pyx_SetItemInt(__pyx_v_x, __pyx_v_j, __pyx_t_3, sizeof(long), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- /* "mtrand.pyx":4187
+ /* "mtrand.pyx":4271
* j = rk_interval(i, self.internal_state)
* x[i], x[j] = x[j], x[i]
* i = i - 1 # <<<<<<<<<<<<<<
@@ -18602,30 +18011,29 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_shuffle(PyObject *__pyx_v_self,
}
/*else*/ {
- /* "mtrand.pyx":4190
+ /* "mtrand.pyx":4274
* else:
* # make copies
* copy = hasattr(x[0], 'copy') # <<<<<<<<<<<<<<
* if copy:
* while(i > 0):
*/
- __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_x, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_x, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyObject_HasAttr(__pyx_t_3, ((PyObject *)__pyx_n_s__copy)); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_HasAttr(__pyx_t_3, ((PyObject *)__pyx_n_s__copy)); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_v_copy = __pyx_t_5;
- /* "mtrand.pyx":4191
+ /* "mtrand.pyx":4275
* # make copies
* copy = hasattr(x[0], 'copy')
* if copy: # <<<<<<<<<<<<<<
* while(i > 0):
* j = rk_interval(i, self.internal_state)
*/
- __pyx_t_6 = __pyx_v_copy;
- if (__pyx_t_6) {
+ if (__pyx_v_copy) {
- /* "mtrand.pyx":4192
+ /* "mtrand.pyx":4276
* copy = hasattr(x[0], 'copy')
* if copy:
* while(i > 0): # <<<<<<<<<<<<<<
@@ -18636,7 +18044,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_shuffle(PyObject *__pyx_v_self,
__pyx_t_5 = (__pyx_v_i > 0);
if (!__pyx_t_5) break;
- /* "mtrand.pyx":4193
+ /* "mtrand.pyx":4277
* if copy:
* while(i > 0):
* j = rk_interval(i, self.internal_state) # <<<<<<<<<<<<<<
@@ -18645,35 +18053,35 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_shuffle(PyObject *__pyx_v_self,
*/
__pyx_v_j = rk_interval(__pyx_v_i, ((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state);
- /* "mtrand.pyx":4194
+ /* "mtrand.pyx":4278
* while(i > 0):
* j = rk_interval(i, self.internal_state)
* x[i], x[j] = x[j].copy(), x[i].copy() # <<<<<<<<<<<<<<
* i = i - 1
* else:
*/
- __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_x, __pyx_v_j, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_x, __pyx_v_j, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__copy); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__copy); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_x, __pyx_v_i, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_x, __pyx_v_i, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__copy); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__copy); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- if (__Pyx_SetItemInt(__pyx_v_x, __pyx_v_i, __pyx_t_3, sizeof(long), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__Pyx_SetItemInt(__pyx_v_x, __pyx_v_i, __pyx_t_3, sizeof(long), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (__Pyx_SetItemInt(__pyx_v_x, __pyx_v_j, __pyx_t_4, sizeof(long), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__Pyx_SetItemInt(__pyx_v_x, __pyx_v_j, __pyx_t_4, sizeof(long), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "mtrand.pyx":4195
+ /* "mtrand.pyx":4279
* j = rk_interval(i, self.internal_state)
* x[i], x[j] = x[j].copy(), x[i].copy()
* i = i - 1 # <<<<<<<<<<<<<<
@@ -18686,7 +18094,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_shuffle(PyObject *__pyx_v_self,
}
/*else*/ {
- /* "mtrand.pyx":4197
+ /* "mtrand.pyx":4281
* i = i - 1
* else:
* while(i > 0): # <<<<<<<<<<<<<<
@@ -18697,7 +18105,7 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_shuffle(PyObject *__pyx_v_self,
__pyx_t_5 = (__pyx_v_i > 0);
if (!__pyx_t_5) break;
- /* "mtrand.pyx":4198
+ /* "mtrand.pyx":4282
* else:
* while(i > 0):
* j = rk_interval(i, self.internal_state) # <<<<<<<<<<<<<<
@@ -18706,29 +18114,29 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_shuffle(PyObject *__pyx_v_self,
*/
__pyx_v_j = rk_interval(__pyx_v_i, ((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state);
- /* "mtrand.pyx":4199
+ /* "mtrand.pyx":4283
* while(i > 0):
* j = rk_interval(i, self.internal_state)
* x[i], x[j] = x[j][:], x[i][:] # <<<<<<<<<<<<<<
* i = i - 1
*
*/
- __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_x, __pyx_v_j, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_x, __pyx_v_j, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __pyx_t_3 = PySequence_GetSlice(__pyx_t_4, 0, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_PySequence_GetSlice(__pyx_t_4, 0, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_x, __pyx_v_i, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_x, __pyx_v_i, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __pyx_t_2 = PySequence_GetSlice(__pyx_t_4, 0, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_PySequence_GetSlice(__pyx_t_4, 0, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- if (__Pyx_SetItemInt(__pyx_v_x, __pyx_v_i, __pyx_t_3, sizeof(long), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__Pyx_SetItemInt(__pyx_v_x, __pyx_v_i, __pyx_t_3, sizeof(long), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (__Pyx_SetItemInt(__pyx_v_x, __pyx_v_j, __pyx_t_2, sizeof(long), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__Pyx_SetItemInt(__pyx_v_x, __pyx_v_j, __pyx_t_2, sizeof(long), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4200
+ /* "mtrand.pyx":4284
* j = rk_interval(i, self.internal_state)
* x[i], x[j] = x[j][:], x[i][:]
* i = i - 1 # <<<<<<<<<<<<<<
@@ -18751,14 +18159,12 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_shuffle(PyObject *__pyx_v_self,
__Pyx_AddTraceback("mtrand.RandomState.shuffle");
__pyx_r = NULL;
__pyx_L0:;
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_x);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "mtrand.pyx":4202
+/* "mtrand.pyx":4286
* i = i - 1
*
* def permutation(self, object x): # <<<<<<<<<<<<<<
@@ -18766,9 +18172,9 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_shuffle(PyObject *__pyx_v_self,
* permutation(x)
*/
-static PyObject *__pyx_pf_6mtrand_11RandomState_permutation(PyObject *__pyx_v_self, PyObject *__pyx_v_x); /*proto*/
-static char __pyx_doc_6mtrand_11RandomState_permutation[] = "\n permutation(x)\n\n Randomly permute a sequence, or return a permuted range.\n\n Parameters\n ----------\n x : int or array_like\n If `x` is an integer, randomly permute ``np.arange(x)``.\n If `x` is an array, make a copy and shuffle the elements\n randomly.\n\n Returns\n -------\n out : ndarray\n Permuted sequence or array range.\n\n Examples\n --------\n >>> np.random.permutation(10)\n array([1, 7, 4, 3, 0, 9, 2, 5, 8, 6])\n\n >>> np.random.permutation([1, 4, 9, 12, 15])\n array([15, 1, 9, 4, 12])\n\n ";
-static PyObject *__pyx_pf_6mtrand_11RandomState_permutation(PyObject *__pyx_v_self, PyObject *__pyx_v_x) {
+static PyObject *__pyx_pf_6mtrand_11RandomState_51permutation(PyObject *__pyx_v_self, PyObject *__pyx_v_x); /*proto*/
+static char __pyx_doc_6mtrand_11RandomState_51permutation[] = "\n permutation(x)\n\n Randomly permute a sequence, or return a permuted range.\n\n If `x` is a multi-dimensional array, it is only shuffled along its\n first index.\n\n Parameters\n ----------\n x : int or array_like\n If `x` is an integer, randomly permute ``np.arange(x)``.\n If `x` is an array, make a copy and shuffle the elements\n randomly.\n\n Returns\n -------\n out : ndarray\n Permuted sequence or array range.\n\n Examples\n --------\n >>> np.random.permutation(10)\n array([1, 7, 4, 3, 0, 9, 2, 5, 8, 6])\n\n >>> np.random.permutation([1, 4, 9, 12, 15])\n array([15, 1, 9, 4, 12])\n\n >>> arr = np.arange(9).reshape((3, 3))\n >>> np.random.permutation(arr)\n array([[6, 7, 8],\n [0, 1, 2],\n [3, 4, 5]])\n\n ";
+static PyObject *__pyx_pf_6mtrand_11RandomState_51permutation(PyObject *__pyx_v_self, PyObject *__pyx_v_x) {
PyObject *__pyx_v_arr;
PyObject *__pyx_r = NULL;
PyObject *__pyx_t_1 = NULL;
@@ -18776,58 +18182,56 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_permutation(PyObject *__pyx_v_se
int __pyx_t_3;
PyObject *__pyx_t_4 = NULL;
__Pyx_RefNannySetupContext("permutation");
- __Pyx_INCREF((PyObject *)__pyx_v_self);
- __Pyx_INCREF(__pyx_v_x);
__pyx_v_arr = Py_None; __Pyx_INCREF(Py_None);
- /* "mtrand.pyx":4229
+ /* "mtrand.pyx":4322
*
* """
* if isinstance(x, (int, long, np.integer)): # <<<<<<<<<<<<<<
* arr = np.arange(x)
* else:
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__integer); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__integer); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __Pyx_INCREF(((PyObject *)((PyObject*)&PyInt_Type)));
- PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)((PyObject*)&PyInt_Type)));
- __Pyx_GIVEREF(((PyObject *)((PyObject*)&PyInt_Type)));
- __Pyx_INCREF(((PyObject *)((PyObject*)&PyLong_Type)));
- PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)((PyObject*)&PyLong_Type)));
- __Pyx_GIVEREF(((PyObject *)((PyObject*)&PyLong_Type)));
+ __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_1));
+ __Pyx_INCREF(((PyObject *)((PyObject*)(&PyInt_Type))));
+ PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)((PyObject*)(&PyInt_Type))));
+ __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyInt_Type))));
+ __Pyx_INCREF(((PyObject *)((PyObject*)(&PyLong_Type))));
+ PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)((PyObject*)(&PyLong_Type))));
+ __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyLong_Type))));
PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_2);
__Pyx_GIVEREF(__pyx_t_2);
__pyx_t_2 = 0;
- __pyx_t_3 = PyObject_IsInstance(__pyx_v_x, __pyx_t_1); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_t_3 = PyObject_IsInstance(__pyx_v_x, ((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
if (__pyx_t_3) {
- /* "mtrand.pyx":4230
+ /* "mtrand.pyx":4323
* """
* if isinstance(x, (int, long, np.integer)):
* arr = np.arange(x) # <<<<<<<<<<<<<<
* else:
* arr = np.array(x)
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__arange); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__arange); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_1));
__Pyx_INCREF(__pyx_v_x);
PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_x);
__Pyx_GIVEREF(__pyx_v_x);
- __pyx_t_4 = PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4323; __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_1); __pyx_t_1 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_v_arr);
__pyx_v_arr = __pyx_t_4;
__pyx_t_4 = 0;
@@ -18835,54 +18239,54 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_permutation(PyObject *__pyx_v_se
}
/*else*/ {
- /* "mtrand.pyx":4232
+ /* "mtrand.pyx":4325
* arr = np.arange(x)
* else:
* arr = np.array(x) # <<<<<<<<<<<<<<
* self.shuffle(arr)
* return arr
*/
- __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__array); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__array); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__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 = 4232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
__Pyx_INCREF(__pyx_v_x);
PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_x);
__Pyx_GIVEREF(__pyx_v_x);
- __pyx_t_2 = PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
__Pyx_DECREF(__pyx_v_arr);
__pyx_v_arr = __pyx_t_2;
__pyx_t_2 = 0;
}
__pyx_L5:;
- /* "mtrand.pyx":4233
+ /* "mtrand.pyx":4326
* else:
* arr = np.array(x)
* self.shuffle(arr) # <<<<<<<<<<<<<<
* return arr
*
*/
- __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__shuffle); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__shuffle); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
__Pyx_INCREF(__pyx_v_arr);
PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_arr);
__Pyx_GIVEREF(__pyx_v_arr);
- __pyx_t_1 = PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- /* "mtrand.pyx":4234
+ /* "mtrand.pyx":4327
* arr = np.array(x)
* self.shuffle(arr)
* return arr # <<<<<<<<<<<<<<
@@ -18904,8 +18308,6 @@ static PyObject *__pyx_pf_6mtrand_11RandomState_permutation(PyObject *__pyx_v_se
__pyx_r = NULL;
__pyx_L0:;
__Pyx_DECREF(__pyx_v_arr);
- __Pyx_DECREF((PyObject *)__pyx_v_self);
- __Pyx_DECREF(__pyx_v_x);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
@@ -18922,7 +18324,7 @@ static void __pyx_tp_dealloc_6mtrand_RandomState(PyObject *o) {
PyObject *etype, *eval, *etb;
PyErr_Fetch(&etype, &eval, &etb);
++Py_REFCNT(o);
- __pyx_pf_6mtrand_11RandomState___dealloc__(o);
+ __pyx_pf_6mtrand_11RandomState_1__dealloc__(o);
if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
--Py_REFCNT(o);
PyErr_Restore(etype, eval, etb);
@@ -18930,57 +18332,57 @@ static void __pyx_tp_dealloc_6mtrand_RandomState(PyObject *o) {
(*Py_TYPE(o)->tp_free)(o);
}
-static struct PyMethodDef __pyx_methods_6mtrand_RandomState[] = {
- {__Pyx_NAMESTR("seed"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_seed, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_seed)},
- {__Pyx_NAMESTR("get_state"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_get_state, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_get_state)},
- {__Pyx_NAMESTR("set_state"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_set_state, METH_O, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_set_state)},
- {__Pyx_NAMESTR("__getstate__"), (PyCFunction)__pyx_pf_6mtrand_11RandomState___getstate__, METH_NOARGS, __Pyx_DOCSTR(0)},
- {__Pyx_NAMESTR("__setstate__"), (PyCFunction)__pyx_pf_6mtrand_11RandomState___setstate__, METH_O, __Pyx_DOCSTR(0)},
- {__Pyx_NAMESTR("__reduce__"), (PyCFunction)__pyx_pf_6mtrand_11RandomState___reduce__, METH_NOARGS, __Pyx_DOCSTR(0)},
- {__Pyx_NAMESTR("random_sample"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_random_sample, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_random_sample)},
- {__Pyx_NAMESTR("tomaxint"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_tomaxint, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_tomaxint)},
- {__Pyx_NAMESTR("randint"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_randint, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_randint)},
- {__Pyx_NAMESTR("bytes"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_bytes, METH_O, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_bytes)},
- {__Pyx_NAMESTR("uniform"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_uniform, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_uniform)},
- {__Pyx_NAMESTR("rand"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_rand, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_rand)},
- {__Pyx_NAMESTR("randn"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_randn, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_randn)},
- {__Pyx_NAMESTR("random_integers"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_random_integers, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_random_integers)},
- {__Pyx_NAMESTR("standard_normal"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_standard_normal, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_standard_normal)},
- {__Pyx_NAMESTR("normal"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_normal, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_normal)},
- {__Pyx_NAMESTR("beta"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_beta, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_beta)},
- {__Pyx_NAMESTR("exponential"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_exponential, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_exponential)},
- {__Pyx_NAMESTR("standard_exponential"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_standard_exponential, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_standard_exponential)},
- {__Pyx_NAMESTR("standard_gamma"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_standard_gamma, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_standard_gamma)},
- {__Pyx_NAMESTR("gamma"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_gamma, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_gamma)},
- {__Pyx_NAMESTR("f"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_f, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_f)},
- {__Pyx_NAMESTR("noncentral_f"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_noncentral_f, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_noncentral_f)},
- {__Pyx_NAMESTR("chisquare"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_chisquare, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_chisquare)},
- {__Pyx_NAMESTR("noncentral_chisquare"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_noncentral_chisquare, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_noncentral_chisquare)},
- {__Pyx_NAMESTR("standard_cauchy"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_standard_cauchy, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_standard_cauchy)},
- {__Pyx_NAMESTR("standard_t"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_standard_t, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_standard_t)},
- {__Pyx_NAMESTR("vonmises"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_vonmises, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_vonmises)},
- {__Pyx_NAMESTR("pareto"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_pareto, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_pareto)},
- {__Pyx_NAMESTR("weibull"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_weibull, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_weibull)},
- {__Pyx_NAMESTR("power"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_power, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_power)},
- {__Pyx_NAMESTR("laplace"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_laplace, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_laplace)},
- {__Pyx_NAMESTR("gumbel"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_gumbel, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_gumbel)},
- {__Pyx_NAMESTR("logistic"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_logistic, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_logistic)},
- {__Pyx_NAMESTR("lognormal"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_lognormal, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_lognormal)},
- {__Pyx_NAMESTR("rayleigh"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_rayleigh, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_rayleigh)},
- {__Pyx_NAMESTR("wald"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_wald, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_wald)},
- {__Pyx_NAMESTR("triangular"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_triangular, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_triangular)},
- {__Pyx_NAMESTR("binomial"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_binomial, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_binomial)},
- {__Pyx_NAMESTR("negative_binomial"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_negative_binomial, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_negative_binomial)},
- {__Pyx_NAMESTR("poisson"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_poisson, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_poisson)},
- {__Pyx_NAMESTR("zipf"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_zipf, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_zipf)},
- {__Pyx_NAMESTR("geometric"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_geometric, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_geometric)},
- {__Pyx_NAMESTR("hypergeometric"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_hypergeometric, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_hypergeometric)},
- {__Pyx_NAMESTR("logseries"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_logseries, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_logseries)},
- {__Pyx_NAMESTR("multivariate_normal"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_multivariate_normal, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_multivariate_normal)},
- {__Pyx_NAMESTR("multinomial"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_multinomial, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_multinomial)},
- {__Pyx_NAMESTR("dirichlet"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_dirichlet, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_dirichlet)},
- {__Pyx_NAMESTR("shuffle"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_shuffle, METH_O, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_shuffle)},
- {__Pyx_NAMESTR("permutation"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_permutation, METH_O, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_permutation)},
+static PyMethodDef __pyx_methods_6mtrand_RandomState[] = {
+ {__Pyx_NAMESTR("seed"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_2seed, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_2seed)},
+ {__Pyx_NAMESTR("get_state"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_3get_state, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_3get_state)},
+ {__Pyx_NAMESTR("set_state"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_4set_state, METH_O, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_4set_state)},
+ {__Pyx_NAMESTR("__getstate__"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_5__getstate__, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("__setstate__"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_6__setstate__, METH_O, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("__reduce__"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_7__reduce__, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("random_sample"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_8random_sample, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_8random_sample)},
+ {__Pyx_NAMESTR("tomaxint"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_9tomaxint, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_9tomaxint)},
+ {__Pyx_NAMESTR("randint"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_10randint, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_10randint)},
+ {__Pyx_NAMESTR("bytes"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_11bytes, METH_O, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_11bytes)},
+ {__Pyx_NAMESTR("uniform"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_12uniform, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_12uniform)},
+ {__Pyx_NAMESTR("rand"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_13rand, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_13rand)},
+ {__Pyx_NAMESTR("randn"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_14randn, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_14randn)},
+ {__Pyx_NAMESTR("random_integers"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_15random_integers, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_15random_integers)},
+ {__Pyx_NAMESTR("standard_normal"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_16standard_normal, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_16standard_normal)},
+ {__Pyx_NAMESTR("normal"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_17normal, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_17normal)},
+ {__Pyx_NAMESTR("beta"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_18beta, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_18beta)},
+ {__Pyx_NAMESTR("exponential"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_19exponential, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_19exponential)},
+ {__Pyx_NAMESTR("standard_exponential"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_20standard_exponential, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_20standard_exponential)},
+ {__Pyx_NAMESTR("standard_gamma"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_21standard_gamma, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_21standard_gamma)},
+ {__Pyx_NAMESTR("gamma"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_22gamma, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_22gamma)},
+ {__Pyx_NAMESTR("f"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_23f, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_23f)},
+ {__Pyx_NAMESTR("noncentral_f"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_24noncentral_f, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_24noncentral_f)},
+ {__Pyx_NAMESTR("chisquare"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_25chisquare, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_25chisquare)},
+ {__Pyx_NAMESTR("noncentral_chisquare"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_26noncentral_chisquare, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_26noncentral_chisquare)},
+ {__Pyx_NAMESTR("standard_cauchy"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_27standard_cauchy, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_27standard_cauchy)},
+ {__Pyx_NAMESTR("standard_t"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_28standard_t, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_28standard_t)},
+ {__Pyx_NAMESTR("vonmises"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_29vonmises, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_29vonmises)},
+ {__Pyx_NAMESTR("pareto"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_30pareto, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_30pareto)},
+ {__Pyx_NAMESTR("weibull"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_31weibull, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_31weibull)},
+ {__Pyx_NAMESTR("power"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_32power, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_32power)},
+ {__Pyx_NAMESTR("laplace"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_33laplace, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_33laplace)},
+ {__Pyx_NAMESTR("gumbel"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_34gumbel, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_34gumbel)},
+ {__Pyx_NAMESTR("logistic"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_35logistic, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_35logistic)},
+ {__Pyx_NAMESTR("lognormal"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_36lognormal, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_36lognormal)},
+ {__Pyx_NAMESTR("rayleigh"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_37rayleigh, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_37rayleigh)},
+ {__Pyx_NAMESTR("wald"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_38wald, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_38wald)},
+ {__Pyx_NAMESTR("triangular"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_39triangular, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_39triangular)},
+ {__Pyx_NAMESTR("binomial"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_40binomial, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_40binomial)},
+ {__Pyx_NAMESTR("negative_binomial"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_41negative_binomial, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_41negative_binomial)},
+ {__Pyx_NAMESTR("poisson"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_42poisson, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_42poisson)},
+ {__Pyx_NAMESTR("zipf"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_43zipf, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_43zipf)},
+ {__Pyx_NAMESTR("geometric"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_44geometric, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_44geometric)},
+ {__Pyx_NAMESTR("hypergeometric"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_45hypergeometric, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_45hypergeometric)},
+ {__Pyx_NAMESTR("logseries"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_46logseries, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_46logseries)},
+ {__Pyx_NAMESTR("multivariate_normal"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_47multivariate_normal, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_47multivariate_normal)},
+ {__Pyx_NAMESTR("multinomial"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_48multinomial, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_48multinomial)},
+ {__Pyx_NAMESTR("dirichlet"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_49dirichlet, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_49dirichlet)},
+ {__Pyx_NAMESTR("shuffle"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_50shuffle, METH_O, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_50shuffle)},
+ {__Pyx_NAMESTR("permutation"), (PyCFunction)__pyx_pf_6mtrand_11RandomState_51permutation, METH_O, __Pyx_DOCSTR(__pyx_doc_6mtrand_11RandomState_51permutation)},
{0, 0, 0, 0}
};
@@ -19008,10 +18410,10 @@ static PyNumberMethods __pyx_tp_as_number_RandomState = {
0, /*nb_coerce*/
#endif
0, /*nb_int*/
- #if PY_MAJOR_VERSION >= 3
- 0, /*reserved*/
- #else
+ #if PY_MAJOR_VERSION < 3
0, /*nb_long*/
+ #else
+ 0, /*reserved*/
#endif
0, /*nb_float*/
#if PY_MAJOR_VERSION < 3
@@ -19037,7 +18439,7 @@ static PyNumberMethods __pyx_tp_as_number_RandomState = {
0, /*nb_true_divide*/
0, /*nb_inplace_floor_divide*/
0, /*nb_inplace_true_divide*/
- #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX)
+ #if PY_VERSION_HEX >= 0x02050000
0, /*nb_index*/
#endif
};
@@ -19082,7 +18484,7 @@ static PyBufferProcs __pyx_tp_as_buffer_RandomState = {
#endif
};
-PyTypeObject __pyx_type_6mtrand_RandomState = {
+static PyTypeObject __pyx_type_6mtrand_RandomState = {
PyVarObject_HEAD_INIT(0, 0)
__Pyx_NAMESTR("mtrand.RandomState"), /*tp_name*/
sizeof(struct __pyx_obj_6mtrand_RandomState), /*tp_basicsize*/
@@ -19091,7 +18493,11 @@ PyTypeObject __pyx_type_6mtrand_RandomState = {
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
+ #if PY_MAJOR_VERSION < 3
0, /*tp_compare*/
+ #else
+ 0, /*reserved*/
+ #endif
0, /*tp_repr*/
&__pyx_tp_as_number_RandomState, /*tp_as_number*/
&__pyx_tp_as_sequence_RandomState, /*tp_as_sequence*/
@@ -19102,7 +18508,7 @@ PyTypeObject __pyx_type_6mtrand_RandomState = {
0, /*tp_getattro*/
0, /*tp_setattro*/
&__pyx_tp_as_buffer_RandomState, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/
+ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
__Pyx_DOCSTR("\n RandomState(seed=None)\n\n Container for the Mersenne Twister pseudo-random number generator.\n\n `RandomState` exposes a number of methods for generating random numbers\n drawn from a variety of probability distributions. In addition to the\n distribution-specific arguments, each method takes a keyword argument\n `size` that defaults to ``None``. If `size` is ``None``, then a single\n value is generated and returned. If `size` is an integer, then a 1-D\n array filled with generated values is returned. If `size` is a tuple,\n then an array with that shape is filled and returned.\n\n Parameters\n ----------\n seed : int or array_like, optional\n Random seed initializing the pseudo-random number generator.\n Can be an integer, an array (or other sequence) of integers of\n any length, or ``None`` (the default).\n If `seed` is ``None``, then `RandomState` will try to read data from\n ``/dev/urandom`` (or the Windows analogue) if available or seed from\n the clock otherwise.\n\n Notes\n -----\n The Python stdlib module \"random\" also contains a Mersenne Twister\n pseudo-random number generator with a number of methods that are similar\n to the ones available in `RandomState`. `RandomState`, besides being\n NumPy-aware, has the advantage that it provides a much larger number\n of probability distributions to choose from.\n\n "), /*tp_doc*/
0, /*tp_traverse*/
0, /*tp_clear*/
@@ -19134,12 +18540,10 @@ PyTypeObject __pyx_type_6mtrand_RandomState = {
#endif
};
-static struct PyMethodDef __pyx_methods[] = {
+static PyMethodDef __pyx_methods[] = {
{0, 0, 0, 0}
};
-static void __pyx_init_filenames(void); /*proto*/
-
#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
PyModuleDef_HEAD_INIT,
@@ -19156,98 +18560,136 @@ static struct PyModuleDef __pyx_moduledef = {
static __Pyx_StringTabEntry __pyx_string_tab[] = {
{&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0},
- {&__pyx_kp_s_10, __pyx_k_10, sizeof(__pyx_k_10), 0, 0, 1, 0},
- {&__pyx_kp_u_100, __pyx_k_100, sizeof(__pyx_k_100), 0, 1, 0, 0},
- {&__pyx_kp_u_101, __pyx_k_101, sizeof(__pyx_k_101), 0, 1, 0, 0},
- {&__pyx_kp_u_102, __pyx_k_102, sizeof(__pyx_k_102), 0, 1, 0, 0},
- {&__pyx_kp_u_103, __pyx_k_103, sizeof(__pyx_k_103), 0, 1, 0, 0},
- {&__pyx_kp_u_104, __pyx_k_104, sizeof(__pyx_k_104), 0, 1, 0, 0},
- {&__pyx_kp_u_105, __pyx_k_105, sizeof(__pyx_k_105), 0, 1, 0, 0},
- {&__pyx_kp_u_106, __pyx_k_106, sizeof(__pyx_k_106), 0, 1, 0, 0},
- {&__pyx_kp_u_107, __pyx_k_107, sizeof(__pyx_k_107), 0, 1, 0, 0},
+ {&__pyx_kp_s_101, __pyx_k_101, sizeof(__pyx_k_101), 0, 0, 1, 0},
+ {&__pyx_kp_s_103, __pyx_k_103, sizeof(__pyx_k_103), 0, 0, 1, 0},
+ {&__pyx_kp_s_105, __pyx_k_105, sizeof(__pyx_k_105), 0, 0, 1, 0},
{&__pyx_kp_s_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 0, 1, 0},
+ {&__pyx_kp_s_110, __pyx_k_110, sizeof(__pyx_k_110), 0, 0, 1, 0},
+ {&__pyx_kp_s_112, __pyx_k_112, sizeof(__pyx_k_112), 0, 0, 1, 0},
+ {&__pyx_kp_s_114, __pyx_k_114, sizeof(__pyx_k_114), 0, 0, 1, 0},
+ {&__pyx_kp_s_126, __pyx_k_126, sizeof(__pyx_k_126), 0, 0, 1, 0},
+ {&__pyx_kp_s_128, __pyx_k_128, sizeof(__pyx_k_128), 0, 0, 1, 0},
{&__pyx_kp_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 0},
- {&__pyx_kp_s_15, __pyx_k_15, sizeof(__pyx_k_15), 0, 0, 1, 0},
- {&__pyx_kp_s_16, __pyx_k_16, sizeof(__pyx_k_16), 0, 0, 1, 0},
- {&__pyx_kp_s_17, __pyx_k_17, sizeof(__pyx_k_17), 0, 0, 1, 0},
- {&__pyx_kp_s_18, __pyx_k_18, sizeof(__pyx_k_18), 0, 0, 1, 0},
+ {&__pyx_kp_s_131, __pyx_k_131, sizeof(__pyx_k_131), 0, 0, 1, 0},
+ {&__pyx_kp_s_133, __pyx_k_133, sizeof(__pyx_k_133), 0, 0, 1, 0},
+ {&__pyx_kp_s_136, __pyx_k_136, sizeof(__pyx_k_136), 0, 0, 1, 0},
+ {&__pyx_kp_s_138, __pyx_k_138, sizeof(__pyx_k_138), 0, 0, 1, 0},
+ {&__pyx_kp_s_142, __pyx_k_142, sizeof(__pyx_k_142), 0, 0, 1, 0},
+ {&__pyx_kp_s_144, __pyx_k_144, sizeof(__pyx_k_144), 0, 0, 1, 0},
+ {&__pyx_kp_s_146, __pyx_k_146, sizeof(__pyx_k_146), 0, 0, 1, 0},
+ {&__pyx_kp_s_148, __pyx_k_148, sizeof(__pyx_k_148), 0, 0, 1, 0},
+ {&__pyx_kp_s_154, __pyx_k_154, sizeof(__pyx_k_154), 0, 0, 1, 0},
+ {&__pyx_kp_s_156, __pyx_k_156, sizeof(__pyx_k_156), 0, 0, 1, 0},
+ {&__pyx_kp_s_160, __pyx_k_160, sizeof(__pyx_k_160), 0, 0, 1, 0},
+ {&__pyx_kp_s_162, __pyx_k_162, sizeof(__pyx_k_162), 0, 0, 1, 0},
+ {&__pyx_kp_s_164, __pyx_k_164, sizeof(__pyx_k_164), 0, 0, 1, 0},
+ {&__pyx_n_s_166, __pyx_k_166, sizeof(__pyx_k_166), 0, 0, 1, 1},
+ {&__pyx_kp_s_167, __pyx_k_167, sizeof(__pyx_k_167), 0, 0, 1, 0},
+ {&__pyx_n_s_171, __pyx_k_171, sizeof(__pyx_k_171), 0, 0, 1, 1},
+ {&__pyx_n_s_172, __pyx_k_172, sizeof(__pyx_k_172), 0, 0, 1, 1},
+ {&__pyx_kp_u_173, __pyx_k_173, sizeof(__pyx_k_173), 0, 1, 0, 0},
+ {&__pyx_kp_u_174, __pyx_k_174, sizeof(__pyx_k_174), 0, 1, 0, 0},
+ {&__pyx_kp_u_175, __pyx_k_175, sizeof(__pyx_k_175), 0, 1, 0, 0},
+ {&__pyx_kp_u_176, __pyx_k_176, sizeof(__pyx_k_176), 0, 1, 0, 0},
+ {&__pyx_kp_u_177, __pyx_k_177, sizeof(__pyx_k_177), 0, 1, 0, 0},
+ {&__pyx_kp_u_178, __pyx_k_178, sizeof(__pyx_k_178), 0, 1, 0, 0},
+ {&__pyx_kp_u_179, __pyx_k_179, sizeof(__pyx_k_179), 0, 1, 0, 0},
+ {&__pyx_kp_u_180, __pyx_k_180, sizeof(__pyx_k_180), 0, 1, 0, 0},
+ {&__pyx_kp_u_181, __pyx_k_181, sizeof(__pyx_k_181), 0, 1, 0, 0},
+ {&__pyx_kp_u_182, __pyx_k_182, sizeof(__pyx_k_182), 0, 1, 0, 0},
+ {&__pyx_kp_u_183, __pyx_k_183, sizeof(__pyx_k_183), 0, 1, 0, 0},
+ {&__pyx_kp_u_184, __pyx_k_184, sizeof(__pyx_k_184), 0, 1, 0, 0},
+ {&__pyx_kp_u_185, __pyx_k_185, sizeof(__pyx_k_185), 0, 1, 0, 0},
+ {&__pyx_kp_u_186, __pyx_k_186, sizeof(__pyx_k_186), 0, 1, 0, 0},
+ {&__pyx_kp_u_187, __pyx_k_187, sizeof(__pyx_k_187), 0, 1, 0, 0},
+ {&__pyx_kp_u_188, __pyx_k_188, sizeof(__pyx_k_188), 0, 1, 0, 0},
+ {&__pyx_kp_u_189, __pyx_k_189, sizeof(__pyx_k_189), 0, 1, 0, 0},
{&__pyx_kp_s_19, __pyx_k_19, sizeof(__pyx_k_19), 0, 0, 1, 0},
- {&__pyx_kp_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 0},
- {&__pyx_kp_s_20, __pyx_k_20, sizeof(__pyx_k_20), 0, 0, 1, 0},
- {&__pyx_kp_s_21, __pyx_k_21, sizeof(__pyx_k_21), 0, 0, 1, 0},
+ {&__pyx_kp_u_190, __pyx_k_190, sizeof(__pyx_k_190), 0, 1, 0, 0},
+ {&__pyx_kp_u_191, __pyx_k_191, sizeof(__pyx_k_191), 0, 1, 0, 0},
+ {&__pyx_kp_u_192, __pyx_k_192, sizeof(__pyx_k_192), 0, 1, 0, 0},
+ {&__pyx_kp_u_193, __pyx_k_193, sizeof(__pyx_k_193), 0, 1, 0, 0},
+ {&__pyx_kp_u_194, __pyx_k_194, sizeof(__pyx_k_194), 0, 1, 0, 0},
+ {&__pyx_kp_u_195, __pyx_k_195, sizeof(__pyx_k_195), 0, 1, 0, 0},
+ {&__pyx_kp_u_196, __pyx_k_196, sizeof(__pyx_k_196), 0, 1, 0, 0},
+ {&__pyx_kp_u_197, __pyx_k_197, sizeof(__pyx_k_197), 0, 1, 0, 0},
+ {&__pyx_kp_u_198, __pyx_k_198, sizeof(__pyx_k_198), 0, 1, 0, 0},
+ {&__pyx_kp_u_199, __pyx_k_199, sizeof(__pyx_k_199), 0, 1, 0, 0},
+ {&__pyx_kp_u_200, __pyx_k_200, sizeof(__pyx_k_200), 0, 1, 0, 0},
+ {&__pyx_kp_u_201, __pyx_k_201, sizeof(__pyx_k_201), 0, 1, 0, 0},
+ {&__pyx_kp_u_202, __pyx_k_202, sizeof(__pyx_k_202), 0, 1, 0, 0},
+ {&__pyx_kp_u_203, __pyx_k_203, sizeof(__pyx_k_203), 0, 1, 0, 0},
+ {&__pyx_kp_u_204, __pyx_k_204, sizeof(__pyx_k_204), 0, 1, 0, 0},
+ {&__pyx_kp_u_205, __pyx_k_205, sizeof(__pyx_k_205), 0, 1, 0, 0},
+ {&__pyx_kp_u_206, __pyx_k_206, sizeof(__pyx_k_206), 0, 1, 0, 0},
+ {&__pyx_kp_u_207, __pyx_k_207, sizeof(__pyx_k_207), 0, 1, 0, 0},
+ {&__pyx_kp_u_208, __pyx_k_208, sizeof(__pyx_k_208), 0, 1, 0, 0},
+ {&__pyx_kp_u_209, __pyx_k_209, sizeof(__pyx_k_209), 0, 1, 0, 0},
+ {&__pyx_kp_u_210, __pyx_k_210, sizeof(__pyx_k_210), 0, 1, 0, 0},
+ {&__pyx_kp_u_211, __pyx_k_211, sizeof(__pyx_k_211), 0, 1, 0, 0},
+ {&__pyx_kp_u_212, __pyx_k_212, sizeof(__pyx_k_212), 0, 1, 0, 0},
+ {&__pyx_kp_u_213, __pyx_k_213, sizeof(__pyx_k_213), 0, 1, 0, 0},
+ {&__pyx_kp_u_214, __pyx_k_214, sizeof(__pyx_k_214), 0, 1, 0, 0},
+ {&__pyx_kp_u_215, __pyx_k_215, sizeof(__pyx_k_215), 0, 1, 0, 0},
+ {&__pyx_kp_u_216, __pyx_k_216, sizeof(__pyx_k_216), 0, 1, 0, 0},
+ {&__pyx_kp_u_217, __pyx_k_217, sizeof(__pyx_k_217), 0, 1, 0, 0},
+ {&__pyx_kp_u_218, __pyx_k_218, sizeof(__pyx_k_218), 0, 1, 0, 0},
+ {&__pyx_kp_u_219, __pyx_k_219, sizeof(__pyx_k_219), 0, 1, 0, 0},
{&__pyx_kp_s_22, __pyx_k_22, sizeof(__pyx_k_22), 0, 0, 1, 0},
- {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0},
+ {&__pyx_kp_u_220, __pyx_k_220, sizeof(__pyx_k_220), 0, 1, 0, 0},
+ {&__pyx_kp_u_221, __pyx_k_221, sizeof(__pyx_k_221), 0, 1, 0, 0},
+ {&__pyx_kp_u_222, __pyx_k_222, sizeof(__pyx_k_222), 0, 1, 0, 0},
+ {&__pyx_kp_u_223, __pyx_k_223, sizeof(__pyx_k_223), 0, 1, 0, 0},
+ {&__pyx_kp_u_224, __pyx_k_224, sizeof(__pyx_k_224), 0, 1, 0, 0},
+ {&__pyx_kp_u_225, __pyx_k_225, sizeof(__pyx_k_225), 0, 1, 0, 0},
+ {&__pyx_kp_u_226, __pyx_k_226, sizeof(__pyx_k_226), 0, 1, 0, 0},
+ {&__pyx_kp_u_227, __pyx_k_227, sizeof(__pyx_k_227), 0, 1, 0, 0},
+ {&__pyx_kp_u_228, __pyx_k_228, sizeof(__pyx_k_228), 0, 1, 0, 0},
+ {&__pyx_kp_u_229, __pyx_k_229, sizeof(__pyx_k_229), 0, 1, 0, 0},
+ {&__pyx_kp_u_230, __pyx_k_230, sizeof(__pyx_k_230), 0, 1, 0, 0},
+ {&__pyx_kp_u_231, __pyx_k_231, sizeof(__pyx_k_231), 0, 1, 0, 0},
+ {&__pyx_kp_u_232, __pyx_k_232, sizeof(__pyx_k_232), 0, 1, 0, 0},
+ {&__pyx_kp_u_233, __pyx_k_233, sizeof(__pyx_k_233), 0, 1, 0, 0},
+ {&__pyx_kp_u_234, __pyx_k_234, sizeof(__pyx_k_234), 0, 1, 0, 0},
+ {&__pyx_kp_u_235, __pyx_k_235, sizeof(__pyx_k_235), 0, 1, 0, 0},
+ {&__pyx_kp_u_236, __pyx_k_236, sizeof(__pyx_k_236), 0, 1, 0, 0},
+ {&__pyx_kp_u_237, __pyx_k_237, sizeof(__pyx_k_237), 0, 1, 0, 0},
+ {&__pyx_kp_u_238, __pyx_k_238, sizeof(__pyx_k_238), 0, 1, 0, 0},
+ {&__pyx_kp_u_239, __pyx_k_239, sizeof(__pyx_k_239), 0, 1, 0, 0},
+ {&__pyx_kp_s_24, __pyx_k_24, sizeof(__pyx_k_24), 0, 0, 1, 0},
+ {&__pyx_kp_u_240, __pyx_k_240, sizeof(__pyx_k_240), 0, 1, 0, 0},
+ {&__pyx_kp_u_241, __pyx_k_241, sizeof(__pyx_k_241), 0, 1, 0, 0},
+ {&__pyx_kp_u_242, __pyx_k_242, sizeof(__pyx_k_242), 0, 1, 0, 0},
+ {&__pyx_kp_u_243, __pyx_k_243, sizeof(__pyx_k_243), 0, 1, 0, 0},
+ {&__pyx_kp_u_244, __pyx_k_244, sizeof(__pyx_k_244), 0, 1, 0, 0},
+ {&__pyx_kp_u_245, __pyx_k_245, sizeof(__pyx_k_245), 0, 1, 0, 0},
+ {&__pyx_kp_u_246, __pyx_k_246, sizeof(__pyx_k_246), 0, 1, 0, 0},
+ {&__pyx_kp_u_247, __pyx_k_247, sizeof(__pyx_k_247), 0, 1, 0, 0},
+ {&__pyx_kp_u_248, __pyx_k_248, sizeof(__pyx_k_248), 0, 1, 0, 0},
+ {&__pyx_kp_u_249, __pyx_k_249, sizeof(__pyx_k_249), 0, 1, 0, 0},
+ {&__pyx_kp_u_250, __pyx_k_250, sizeof(__pyx_k_250), 0, 1, 0, 0},
+ {&__pyx_kp_u_251, __pyx_k_251, sizeof(__pyx_k_251), 0, 1, 0, 0},
+ {&__pyx_kp_u_252, __pyx_k_252, sizeof(__pyx_k_252), 0, 1, 0, 0},
+ {&__pyx_kp_u_253, __pyx_k_253, sizeof(__pyx_k_253), 0, 1, 0, 0},
+ {&__pyx_kp_u_254, __pyx_k_254, sizeof(__pyx_k_254), 0, 1, 0, 0},
+ {&__pyx_kp_u_255, __pyx_k_255, sizeof(__pyx_k_255), 0, 1, 0, 0},
+ {&__pyx_kp_u_256, __pyx_k_256, sizeof(__pyx_k_256), 0, 1, 0, 0},
{&__pyx_kp_s_31, __pyx_k_31, sizeof(__pyx_k_31), 0, 0, 1, 0},
- {&__pyx_kp_s_32, __pyx_k_32, sizeof(__pyx_k_32), 0, 0, 1, 0},
- {&__pyx_kp_s_34, __pyx_k_34, sizeof(__pyx_k_34), 0, 0, 1, 0},
- {&__pyx_kp_s_35, __pyx_k_35, sizeof(__pyx_k_35), 0, 0, 1, 0},
- {&__pyx_kp_s_36, __pyx_k_36, sizeof(__pyx_k_36), 0, 0, 1, 0},
- {&__pyx_kp_s_37, __pyx_k_37, sizeof(__pyx_k_37), 0, 0, 1, 0},
- {&__pyx_kp_s_38, __pyx_k_38, sizeof(__pyx_k_38), 0, 0, 1, 0},
- {&__pyx_kp_s_39, __pyx_k_39, sizeof(__pyx_k_39), 0, 0, 1, 0},
- {&__pyx_kp_s_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 1, 0},
- {&__pyx_kp_s_40, __pyx_k_40, sizeof(__pyx_k_40), 0, 0, 1, 0},
{&__pyx_kp_s_41, __pyx_k_41, sizeof(__pyx_k_41), 0, 0, 1, 0},
- {&__pyx_kp_s_42, __pyx_k_42, sizeof(__pyx_k_42), 0, 0, 1, 0},
- {&__pyx_kp_s_44, __pyx_k_44, sizeof(__pyx_k_44), 0, 0, 1, 0},
+ {&__pyx_kp_s_43, __pyx_k_43, sizeof(__pyx_k_43), 0, 0, 1, 0},
{&__pyx_kp_s_45, __pyx_k_45, sizeof(__pyx_k_45), 0, 0, 1, 0},
- {&__pyx_kp_s_46, __pyx_k_46, sizeof(__pyx_k_46), 0, 0, 1, 0},
- {&__pyx_kp_s_47, __pyx_k_47, sizeof(__pyx_k_47), 0, 0, 1, 0},
{&__pyx_kp_s_48, __pyx_k_48, sizeof(__pyx_k_48), 0, 0, 1, 0},
- {&__pyx_kp_s_49, __pyx_k_49, sizeof(__pyx_k_49), 0, 0, 1, 0},
- {&__pyx_kp_s_50, __pyx_k_50, sizeof(__pyx_k_50), 0, 0, 1, 0},
- {&__pyx_kp_s_51, __pyx_k_51, sizeof(__pyx_k_51), 0, 0, 1, 0},
- {&__pyx_kp_s_52, __pyx_k_52, sizeof(__pyx_k_52), 0, 0, 1, 0},
{&__pyx_kp_s_53, __pyx_k_53, sizeof(__pyx_k_53), 0, 0, 1, 0},
- {&__pyx_kp_s_54, __pyx_k_54, sizeof(__pyx_k_54), 0, 0, 1, 0},
- {&__pyx_kp_s_55, __pyx_k_55, sizeof(__pyx_k_55), 0, 0, 1, 0},
- {&__pyx_kp_s_56, __pyx_k_56, sizeof(__pyx_k_56), 0, 0, 1, 0},
- {&__pyx_n_s_57, __pyx_k_57, sizeof(__pyx_k_57), 0, 0, 1, 1},
- {&__pyx_kp_s_58, __pyx_k_58, sizeof(__pyx_k_58), 0, 0, 1, 0},
- {&__pyx_n_s_59, __pyx_k_59, sizeof(__pyx_k_59), 0, 0, 1, 1},
- {&__pyx_n_s_60, __pyx_k_60, sizeof(__pyx_k_60), 0, 0, 1, 1},
- {&__pyx_kp_u_61, __pyx_k_61, sizeof(__pyx_k_61), 0, 1, 0, 0},
- {&__pyx_kp_u_62, __pyx_k_62, sizeof(__pyx_k_62), 0, 1, 0, 0},
- {&__pyx_kp_u_63, __pyx_k_63, sizeof(__pyx_k_63), 0, 1, 0, 0},
- {&__pyx_kp_u_64, __pyx_k_64, sizeof(__pyx_k_64), 0, 1, 0, 0},
- {&__pyx_kp_u_65, __pyx_k_65, sizeof(__pyx_k_65), 0, 1, 0, 0},
- {&__pyx_kp_u_66, __pyx_k_66, sizeof(__pyx_k_66), 0, 1, 0, 0},
- {&__pyx_kp_u_67, __pyx_k_67, sizeof(__pyx_k_67), 0, 1, 0, 0},
- {&__pyx_kp_u_68, __pyx_k_68, sizeof(__pyx_k_68), 0, 1, 0, 0},
- {&__pyx_kp_u_69, __pyx_k_69, sizeof(__pyx_k_69), 0, 1, 0, 0},
- {&__pyx_kp_u_70, __pyx_k_70, sizeof(__pyx_k_70), 0, 1, 0, 0},
- {&__pyx_kp_u_71, __pyx_k_71, sizeof(__pyx_k_71), 0, 1, 0, 0},
- {&__pyx_kp_u_72, __pyx_k_72, sizeof(__pyx_k_72), 0, 1, 0, 0},
- {&__pyx_kp_u_73, __pyx_k_73, sizeof(__pyx_k_73), 0, 1, 0, 0},
- {&__pyx_kp_u_74, __pyx_k_74, sizeof(__pyx_k_74), 0, 1, 0, 0},
- {&__pyx_kp_u_75, __pyx_k_75, sizeof(__pyx_k_75), 0, 1, 0, 0},
- {&__pyx_kp_u_76, __pyx_k_76, sizeof(__pyx_k_76), 0, 1, 0, 0},
- {&__pyx_kp_u_77, __pyx_k_77, sizeof(__pyx_k_77), 0, 1, 0, 0},
- {&__pyx_kp_u_78, __pyx_k_78, sizeof(__pyx_k_78), 0, 1, 0, 0},
- {&__pyx_kp_u_79, __pyx_k_79, sizeof(__pyx_k_79), 0, 1, 0, 0},
- {&__pyx_kp_u_80, __pyx_k_80, sizeof(__pyx_k_80), 0, 1, 0, 0},
- {&__pyx_kp_u_81, __pyx_k_81, sizeof(__pyx_k_81), 0, 1, 0, 0},
- {&__pyx_kp_u_82, __pyx_k_82, sizeof(__pyx_k_82), 0, 1, 0, 0},
- {&__pyx_kp_u_83, __pyx_k_83, sizeof(__pyx_k_83), 0, 1, 0, 0},
- {&__pyx_kp_u_84, __pyx_k_84, sizeof(__pyx_k_84), 0, 1, 0, 0},
- {&__pyx_kp_u_85, __pyx_k_85, sizeof(__pyx_k_85), 0, 1, 0, 0},
- {&__pyx_kp_u_86, __pyx_k_86, sizeof(__pyx_k_86), 0, 1, 0, 0},
- {&__pyx_kp_u_87, __pyx_k_87, sizeof(__pyx_k_87), 0, 1, 0, 0},
- {&__pyx_kp_u_88, __pyx_k_88, sizeof(__pyx_k_88), 0, 1, 0, 0},
- {&__pyx_kp_u_89, __pyx_k_89, sizeof(__pyx_k_89), 0, 1, 0, 0},
+ {&__pyx_kp_s_57, __pyx_k_57, sizeof(__pyx_k_57), 0, 0, 1, 0},
+ {&__pyx_kp_s_59, __pyx_k_59, sizeof(__pyx_k_59), 0, 0, 1, 0},
+ {&__pyx_kp_s_64, __pyx_k_64, sizeof(__pyx_k_64), 0, 0, 1, 0},
+ {&__pyx_kp_s_87, __pyx_k_87, sizeof(__pyx_k_87), 0, 0, 1, 0},
+ {&__pyx_kp_s_89, __pyx_k_89, sizeof(__pyx_k_89), 0, 0, 1, 0},
{&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0},
- {&__pyx_kp_u_90, __pyx_k_90, sizeof(__pyx_k_90), 0, 1, 0, 0},
- {&__pyx_kp_u_91, __pyx_k_91, sizeof(__pyx_k_91), 0, 1, 0, 0},
- {&__pyx_kp_u_92, __pyx_k_92, sizeof(__pyx_k_92), 0, 1, 0, 0},
- {&__pyx_kp_u_93, __pyx_k_93, sizeof(__pyx_k_93), 0, 1, 0, 0},
- {&__pyx_kp_u_94, __pyx_k_94, sizeof(__pyx_k_94), 0, 1, 0, 0},
- {&__pyx_kp_u_95, __pyx_k_95, sizeof(__pyx_k_95), 0, 1, 0, 0},
- {&__pyx_kp_u_96, __pyx_k_96, sizeof(__pyx_k_96), 0, 1, 0, 0},
- {&__pyx_kp_u_97, __pyx_k_97, sizeof(__pyx_k_97), 0, 1, 0, 0},
- {&__pyx_kp_u_98, __pyx_k_98, sizeof(__pyx_k_98), 0, 1, 0, 0},
- {&__pyx_kp_u_99, __pyx_k_99, sizeof(__pyx_k_99), 0, 1, 0, 0},
+ {&__pyx_kp_s_93, __pyx_k_93, sizeof(__pyx_k_93), 0, 0, 1, 0},
+ {&__pyx_kp_s_95, __pyx_k_95, sizeof(__pyx_k_95), 0, 0, 1, 0},
+ {&__pyx_kp_s_98, __pyx_k_98, sizeof(__pyx_k_98), 0, 0, 1, 0},
{&__pyx_n_s__MT19937, __pyx_k__MT19937, sizeof(__pyx_k__MT19937), 0, 0, 1, 1},
- {&__pyx_n_s__RandomState, __pyx_k__RandomState, sizeof(__pyx_k__RandomState), 0, 0, 1, 1},
{&__pyx_n_s__TypeError, __pyx_k__TypeError, sizeof(__pyx_k__TypeError), 0, 0, 1, 1},
{&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1},
{&__pyx_n_s____RandomState_ctor, __pyx_k____RandomState_ctor, sizeof(__pyx_k____RandomState_ctor), 0, 0, 1, 1},
@@ -19258,6 +18700,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
{&__pyx_n_s__add, __pyx_k__add, sizeof(__pyx_k__add), 0, 0, 1, 1},
{&__pyx_n_s__alpha, __pyx_k__alpha, sizeof(__pyx_k__alpha), 0, 0, 1, 1},
{&__pyx_n_s__any, __pyx_k__any, sizeof(__pyx_k__any), 0, 0, 1, 1},
+ {&__pyx_n_s__append, __pyx_k__append, sizeof(__pyx_k__append), 0, 0, 1, 1},
{&__pyx_n_s__arange, __pyx_k__arange, sizeof(__pyx_k__arange), 0, 0, 1, 1},
{&__pyx_n_s__array, __pyx_k__array, sizeof(__pyx_k__array), 0, 0, 1, 1},
{&__pyx_n_s__asarray, __pyx_k__asarray, sizeof(__pyx_k__asarray), 0, 0, 1, 1},
@@ -19291,10 +18734,12 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
{&__pyx_n_s__has_gauss, __pyx_k__has_gauss, sizeof(__pyx_k__has_gauss), 0, 0, 1, 1},
{&__pyx_n_s__high, __pyx_k__high, sizeof(__pyx_k__high), 0, 0, 1, 1},
{&__pyx_n_s__hypergeometric, __pyx_k__hypergeometric, sizeof(__pyx_k__hypergeometric), 0, 0, 1, 1},
+ {&__pyx_n_s__iinfo, __pyx_k__iinfo, sizeof(__pyx_k__iinfo), 0, 0, 1, 1},
{&__pyx_n_s__integer, __pyx_k__integer, sizeof(__pyx_k__integer), 0, 0, 1, 1},
{&__pyx_n_s__internal_state, __pyx_k__internal_state, sizeof(__pyx_k__internal_state), 0, 0, 1, 1},
{&__pyx_n_s__kappa, __pyx_k__kappa, sizeof(__pyx_k__kappa), 0, 0, 1, 1},
{&__pyx_n_s__key, __pyx_k__key, sizeof(__pyx_k__key), 0, 0, 1, 1},
+ {&__pyx_n_s__l, __pyx_k__l, sizeof(__pyx_k__l), 0, 0, 1, 1},
{&__pyx_n_s__lam, __pyx_k__lam, sizeof(__pyx_k__lam), 0, 0, 1, 1},
{&__pyx_n_s__laplace, __pyx_k__laplace, sizeof(__pyx_k__laplace), 0, 0, 1, 1},
{&__pyx_n_s__left, __pyx_k__left, sizeof(__pyx_k__left), 0, 0, 1, 1},
@@ -19305,6 +18750,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
{&__pyx_n_s__lognormal, __pyx_k__lognormal, sizeof(__pyx_k__lognormal), 0, 0, 1, 1},
{&__pyx_n_s__logseries, __pyx_k__logseries, sizeof(__pyx_k__logseries), 0, 0, 1, 1},
{&__pyx_n_s__low, __pyx_k__low, sizeof(__pyx_k__low), 0, 0, 1, 1},
+ {&__pyx_n_s__max, __pyx_k__max, sizeof(__pyx_k__max), 0, 0, 1, 1},
{&__pyx_n_s__mean, __pyx_k__mean, sizeof(__pyx_k__mean), 0, 0, 1, 1},
{&__pyx_n_s__mode, __pyx_k__mode, sizeof(__pyx_k__mode), 0, 0, 1, 1},
{&__pyx_n_s__mu, __pyx_k__mu, sizeof(__pyx_k__mu), 0, 0, 1, 1},
@@ -19326,6 +18772,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
{&__pyx_n_s__pareto, __pyx_k__pareto, sizeof(__pyx_k__pareto), 0, 0, 1, 1},
{&__pyx_n_s__permutation, __pyx_k__permutation, sizeof(__pyx_k__permutation), 0, 0, 1, 1},
{&__pyx_n_s__poisson, __pyx_k__poisson, sizeof(__pyx_k__poisson), 0, 0, 1, 1},
+ {&__pyx_n_s__poisson_lam_max, __pyx_k__poisson_lam_max, sizeof(__pyx_k__poisson_lam_max), 0, 0, 1, 1},
{&__pyx_n_s__pos, __pyx_k__pos, sizeof(__pyx_k__pos), 0, 0, 1, 1},
{&__pyx_n_s__power, __pyx_k__power, sizeof(__pyx_k__power), 0, 0, 1, 1},
{&__pyx_n_s__pvals, __pyx_k__pvals, sizeof(__pyx_k__pvals), 0, 0, 1, 1},
@@ -19352,7 +18799,6 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
{&__pyx_n_s__standard_t, __pyx_k__standard_t, sizeof(__pyx_k__standard_t), 0, 0, 1, 1},
{&__pyx_n_s__subtract, __pyx_k__subtract, sizeof(__pyx_k__subtract), 0, 0, 1, 1},
{&__pyx_n_s__svd, __pyx_k__svd, sizeof(__pyx_k__svd), 0, 0, 1, 1},
- {&__pyx_n_s__tomaxint, __pyx_k__tomaxint, sizeof(__pyx_k__tomaxint), 0, 0, 1, 1},
{&__pyx_n_s__triangular, __pyx_k__triangular, sizeof(__pyx_k__triangular), 0, 0, 1, 1},
{&__pyx_n_s__uint, __pyx_k__uint, sizeof(__pyx_k__uint), 0, 0, 1, 1},
{&__pyx_n_s__uint32, __pyx_k__uint32, sizeof(__pyx_k__uint32), 0, 0, 1, 1},
@@ -19366,16 +18812,1558 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
};
static int __Pyx_InitCachedBuiltins(void) {
__pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 698; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
return 0;
__pyx_L1_error:;
return -1;
}
+static int __Pyx_InitCachedConstants(void) {
+ __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants");
+
+ /* "mtrand.pyx":184
+ * <void *>oa)
+ * if (multi.size != PyArray_SIZE(array)):
+ * raise ValueError("size is not compatible with inputs") # <<<<<<<<<<<<<<
+ * for i from 0 <= i < multi.size:
+ * oa_data = <double *>PyArray_MultiIter_DATA(multi, 1)
+ */
+ __pyx_k_tuple_2 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_2));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
+ PyTuple_SET_ITEM(__pyx_k_tuple_2, 0, ((PyObject *)__pyx_kp_s_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2));
+
+ /* "mtrand.pyx":233
+ * multi = <broadcast>PyArray_MultiIterNew(3, <void*>array, <void *>oa, <void *>ob)
+ * if (multi.size != PyArray_SIZE(array)):
+ * raise ValueError("size is not compatible with inputs") # <<<<<<<<<<<<<<
+ * for i from 0 <= i < multi.size:
+ * oa_data = <double *>PyArray_MultiIter_DATA(multi, 1)
+ */
+ __pyx_k_tuple_3 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_3));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
+ PyTuple_SET_ITEM(__pyx_k_tuple_3, 0, ((PyObject *)__pyx_kp_s_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_3));
+
+ /* "mtrand.pyx":288
+ * <void *>ob, <void *>oc)
+ * if (multi.size != PyArray_SIZE(array)):
+ * raise ValueError("size is not compatible with inputs") # <<<<<<<<<<<<<<
+ * for i from 0 <= i < multi.size:
+ * oa_data = <double *>PyArray_MultiIter_DATA(multi, 1)
+ */
+ __pyx_k_tuple_4 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_4));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
+ PyTuple_SET_ITEM(__pyx_k_tuple_4, 0, ((PyObject *)__pyx_kp_s_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4));
+
+ /* "mtrand.pyx":352
+ * multi = <broadcast>PyArray_MultiIterNew(3, <void*>array, <void *>on, <void *>op)
+ * if (multi.size != PyArray_SIZE(array)):
+ * raise ValueError("size is not compatible with inputs") # <<<<<<<<<<<<<<
+ * for i from 0 <= i < multi.size:
+ * on_data = <long *>PyArray_MultiIter_DATA(multi, 1)
+ */
+ __pyx_k_tuple_5 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_5));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
+ PyTuple_SET_ITEM(__pyx_k_tuple_5, 0, ((PyObject *)__pyx_kp_s_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_5));
+
+ /* "mtrand.pyx":401
+ * multi = <broadcast>PyArray_MultiIterNew(3, <void*>array, <void *>on, <void *>op)
+ * if (multi.size != PyArray_SIZE(array)):
+ * raise ValueError("size is not compatible with inputs") # <<<<<<<<<<<<<<
+ * for i from 0 <= i < multi.size:
+ * on_data = <double *>PyArray_MultiIter_DATA(multi, 1)
+ */
+ __pyx_k_tuple_6 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_6));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
+ PyTuple_SET_ITEM(__pyx_k_tuple_6, 0, ((PyObject *)__pyx_kp_s_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_6));
+
+ /* "mtrand.pyx":455
+ * <void *>oN)
+ * if (multi.size != PyArray_SIZE(array)):
+ * raise ValueError("size is not compatible with inputs") # <<<<<<<<<<<<<<
+ * for i from 0 <= i < multi.size:
+ * on_data = <long *>PyArray_MultiIter_DATA(multi, 1)
+ */
+ __pyx_k_tuple_7 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_7));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
+ PyTuple_SET_ITEM(__pyx_k_tuple_7, 0, ((PyObject *)__pyx_kp_s_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_7));
+
+ /* "mtrand.pyx":503
+ * multi = <broadcast>PyArray_MultiIterNew(2, <void *>array, <void *>oa)
+ * if (multi.size != PyArray_SIZE(array)):
+ * raise ValueError("size is not compatible with inputs") # <<<<<<<<<<<<<<
+ * for i from 0 <= i < multi.size:
+ * oa_data = <double *>PyArray_MultiIter_DATA(multi, 1)
+ */
+ __pyx_k_tuple_8 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_8));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
+ PyTuple_SET_ITEM(__pyx_k_tuple_8, 0, ((PyObject *)__pyx_kp_s_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_8));
+
+ /* "mtrand.pyx":689
+ * algorithm_name = state[0]
+ * if algorithm_name != 'MT19937':
+ * raise ValueError("algorithm must be 'MT19937'") # <<<<<<<<<<<<<<
+ * key, pos = state[1:3]
+ * if len(state) == 3:
+ */
+ __pyx_k_tuple_10 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_10));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_9));
+ PyTuple_SET_ITEM(__pyx_k_tuple_10, 0, ((PyObject *)__pyx_kp_s_9));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_9));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_10));
+
+ /* "mtrand.pyx":702
+ * obj = <ndarray>PyArray_ContiguousFromObject(key, NPY_LONG, 1, 1)
+ * if obj.dimensions[0] != 624:
+ * raise ValueError("state must be 624 longs") # <<<<<<<<<<<<<<
+ * memcpy(<void*>(self.internal_state.key), <void*>(obj.data), 624*sizeof(long))
+ * self.internal_state.pos = pos
+ */
+ __pyx_k_tuple_12 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_12));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_11));
+ PyTuple_SET_ITEM(__pyx_k_tuple_12, 0, ((PyObject *)__pyx_kp_s_11));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_11));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_12));
+
+ /* "mtrand.pyx":874
+ *
+ * if lo >= hi :
+ * raise ValueError("low >= high") # <<<<<<<<<<<<<<
+ *
+ * diff = <unsigned long>hi - <unsigned long>lo - 1UL
+ */
+ __pyx_k_tuple_14 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 874; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_14));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_13));
+ PyTuple_SET_ITEM(__pyx_k_tuple_14, 0, ((PyObject *)__pyx_kp_s_13));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_13));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_14));
+
+ /* "mtrand.pyx":1301
+ * if not PyErr_Occurred():
+ * if fscale <= 0:
+ * raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
+ * return cont2_array_sc(self.internal_state, rk_normal, size, floc, fscale)
+ *
+ */
+ __pyx_k_tuple_20 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_20));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_19));
+ PyTuple_SET_ITEM(__pyx_k_tuple_20, 0, ((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_20));
+
+ /* "mtrand.pyx":1309
+ * oscale = <ndarray>PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
+ * if np.any(np.less_equal(oscale, 0)):
+ * raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
+ * return cont2_array(self.internal_state, rk_normal, size, oloc, oscale)
+ *
+ */
+ __pyx_k_tuple_21 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1309; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_21));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_19));
+ PyTuple_SET_ITEM(__pyx_k_tuple_21, 0, ((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_21));
+
+ /* "mtrand.pyx":1356
+ * if not PyErr_Occurred():
+ * if fa <= 0:
+ * raise ValueError("a <= 0") # <<<<<<<<<<<<<<
+ * if fb <= 0:
+ * raise ValueError("b <= 0")
+ */
+ __pyx_k_tuple_23 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_23)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_23));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_22));
+ PyTuple_SET_ITEM(__pyx_k_tuple_23, 0, ((PyObject *)__pyx_kp_s_22));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_22));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_23));
+
+ /* "mtrand.pyx":1358
+ * raise ValueError("a <= 0")
+ * if fb <= 0:
+ * raise ValueError("b <= 0") # <<<<<<<<<<<<<<
+ * return cont2_array_sc(self.internal_state, rk_beta, size, fa, fb)
+ *
+ */
+ __pyx_k_tuple_25 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_25)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_25));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_24));
+ PyTuple_SET_ITEM(__pyx_k_tuple_25, 0, ((PyObject *)__pyx_kp_s_24));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_24));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_25));
+
+ /* "mtrand.pyx":1366
+ * ob = <ndarray>PyArray_FROM_OTF(b, NPY_DOUBLE, NPY_ALIGNED)
+ * if np.any(np.less_equal(oa, 0)):
+ * raise ValueError("a <= 0") # <<<<<<<<<<<<<<
+ * if np.any(np.less_equal(ob, 0)):
+ * raise ValueError("b <= 0")
+ */
+ __pyx_k_tuple_26 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_26)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_26));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_22));
+ PyTuple_SET_ITEM(__pyx_k_tuple_26, 0, ((PyObject *)__pyx_kp_s_22));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_22));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_26));
+
+ /* "mtrand.pyx":1368
+ * raise ValueError("a <= 0")
+ * if np.any(np.less_equal(ob, 0)):
+ * raise ValueError("b <= 0") # <<<<<<<<<<<<<<
+ * return cont2_array(self.internal_state, rk_beta, size, oa, ob)
+ *
+ */
+ __pyx_k_tuple_27 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_27)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_27));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_24));
+ PyTuple_SET_ITEM(__pyx_k_tuple_27, 0, ((PyObject *)__pyx_kp_s_24));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_24));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_27));
+
+ /* "mtrand.pyx":1415
+ * if not PyErr_Occurred():
+ * if fscale <= 0:
+ * raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
+ * return cont1_array_sc(self.internal_state, rk_exponential, size, fscale)
+ *
+ */
+ __pyx_k_tuple_29 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_29)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_29));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_19));
+ PyTuple_SET_ITEM(__pyx_k_tuple_29, 0, ((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_29));
+
+ /* "mtrand.pyx":1422
+ * oscale = <ndarray> PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
+ * if np.any(np.less_equal(oscale, 0.0)):
+ * raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
+ * return cont1_array(self.internal_state, rk_exponential, size, oscale)
+ *
+ */
+ __pyx_k_tuple_30 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_30)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1422; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_30));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_19));
+ PyTuple_SET_ITEM(__pyx_k_tuple_30, 0, ((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_30));
+
+ /* "mtrand.pyx":1526
+ * if not PyErr_Occurred():
+ * if fshape <= 0:
+ * raise ValueError("shape <= 0") # <<<<<<<<<<<<<<
+ * return cont1_array_sc(self.internal_state, rk_standard_gamma, size, fshape)
+ *
+ */
+ __pyx_k_tuple_32 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_32)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_32));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_31));
+ PyTuple_SET_ITEM(__pyx_k_tuple_32, 0, ((PyObject *)__pyx_kp_s_31));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_31));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_32));
+
+ /* "mtrand.pyx":1532
+ * oshape = <ndarray> PyArray_FROM_OTF(shape, NPY_DOUBLE, NPY_ALIGNED)
+ * if np.any(np.less_equal(oshape, 0.0)):
+ * raise ValueError("shape <= 0") # <<<<<<<<<<<<<<
+ * return cont1_array(self.internal_state, rk_standard_gamma, size, oshape)
+ *
+ */
+ __pyx_k_tuple_33 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_33)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_33));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_31));
+ PyTuple_SET_ITEM(__pyx_k_tuple_33, 0, ((PyObject *)__pyx_kp_s_31));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_31));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_33));
+
+ /* "mtrand.pyx":1612
+ * if not PyErr_Occurred():
+ * if fshape <= 0:
+ * raise ValueError("shape <= 0") # <<<<<<<<<<<<<<
+ * if fscale <= 0:
+ * raise ValueError("scale <= 0")
+ */
+ __pyx_k_tuple_35 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_35)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1612; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_35));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_31));
+ PyTuple_SET_ITEM(__pyx_k_tuple_35, 0, ((PyObject *)__pyx_kp_s_31));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_31));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_35));
+
+ /* "mtrand.pyx":1614
+ * raise ValueError("shape <= 0")
+ * if fscale <= 0:
+ * raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
+ * return cont2_array_sc(self.internal_state, rk_gamma, size, fshape, fscale)
+ *
+ */
+ __pyx_k_tuple_36 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_36)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1614; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_36));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_19));
+ PyTuple_SET_ITEM(__pyx_k_tuple_36, 0, ((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_36));
+
+ /* "mtrand.pyx":1621
+ * oscale = <ndarray>PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
+ * if np.any(np.less_equal(oshape, 0.0)):
+ * raise ValueError("shape <= 0") # <<<<<<<<<<<<<<
+ * if np.any(np.less_equal(oscale, 0.0)):
+ * raise ValueError("scale <= 0")
+ */
+ __pyx_k_tuple_37 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_37)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_37));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_31));
+ PyTuple_SET_ITEM(__pyx_k_tuple_37, 0, ((PyObject *)__pyx_kp_s_31));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_31));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_37));
+
+ /* "mtrand.pyx":1623
+ * raise ValueError("shape <= 0")
+ * if np.any(np.less_equal(oscale, 0.0)):
+ * raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
+ * return cont2_array(self.internal_state, rk_gamma, size, oshape, oscale)
+ *
+ */
+ __pyx_k_tuple_38 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_38)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1623; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_38));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_19));
+ PyTuple_SET_ITEM(__pyx_k_tuple_38, 0, ((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_38));
+
+ /* "mtrand.pyx":1714
+ * if not PyErr_Occurred():
+ * if fdfnum <= 0:
+ * raise ValueError("shape <= 0") # <<<<<<<<<<<<<<
+ * if fdfden <= 0:
+ * raise ValueError("scale <= 0")
+ */
+ __pyx_k_tuple_39 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_39)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_39));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_31));
+ PyTuple_SET_ITEM(__pyx_k_tuple_39, 0, ((PyObject *)__pyx_kp_s_31));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_31));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_39));
+
+ /* "mtrand.pyx":1716
+ * raise ValueError("shape <= 0")
+ * if fdfden <= 0:
+ * raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
+ * return cont2_array_sc(self.internal_state, rk_f, size, fdfnum, fdfden)
+ *
+ */
+ __pyx_k_tuple_40 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_40)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_40));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_19));
+ PyTuple_SET_ITEM(__pyx_k_tuple_40, 0, ((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_40));
+
+ /* "mtrand.pyx":1724
+ * odfden = <ndarray>PyArray_FROM_OTF(dfden, NPY_DOUBLE, NPY_ALIGNED)
+ * if np.any(np.less_equal(odfnum, 0.0)):
+ * raise ValueError("dfnum <= 0") # <<<<<<<<<<<<<<
+ * if np.any(np.less_equal(odfden, 0.0)):
+ * raise ValueError("dfden <= 0")
+ */
+ __pyx_k_tuple_42 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_42)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_42));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_41));
+ PyTuple_SET_ITEM(__pyx_k_tuple_42, 0, ((PyObject *)__pyx_kp_s_41));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_41));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_42));
+
+ /* "mtrand.pyx":1726
+ * raise ValueError("dfnum <= 0")
+ * if np.any(np.less_equal(odfden, 0.0)):
+ * raise ValueError("dfden <= 0") # <<<<<<<<<<<<<<
+ * return cont2_array(self.internal_state, rk_f, size, odfnum, odfden)
+ *
+ */
+ __pyx_k_tuple_44 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_44)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1726; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_44));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_43));
+ PyTuple_SET_ITEM(__pyx_k_tuple_44, 0, ((PyObject *)__pyx_kp_s_43));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_43));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_44));
+
+ /* "mtrand.pyx":1801
+ * if not PyErr_Occurred():
+ * if fdfnum <= 1:
+ * raise ValueError("dfnum <= 1") # <<<<<<<<<<<<<<
+ * if fdfden <= 0:
+ * raise ValueError("dfden <= 0")
+ */
+ __pyx_k_tuple_46 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_46)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_46));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_45));
+ PyTuple_SET_ITEM(__pyx_k_tuple_46, 0, ((PyObject *)__pyx_kp_s_45));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_45));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_46));
+
+ /* "mtrand.pyx":1803
+ * raise ValueError("dfnum <= 1")
+ * if fdfden <= 0:
+ * raise ValueError("dfden <= 0") # <<<<<<<<<<<<<<
+ * if fnonc < 0:
+ * raise ValueError("nonc < 0")
+ */
+ __pyx_k_tuple_47 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_47)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_47));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_43));
+ PyTuple_SET_ITEM(__pyx_k_tuple_47, 0, ((PyObject *)__pyx_kp_s_43));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_43));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_47));
+
+ /* "mtrand.pyx":1805
+ * raise ValueError("dfden <= 0")
+ * if fnonc < 0:
+ * raise ValueError("nonc < 0") # <<<<<<<<<<<<<<
+ * return cont3_array_sc(self.internal_state, rk_noncentral_f, size,
+ * fdfnum, fdfden, fnonc)
+ */
+ __pyx_k_tuple_49 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_49)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1805; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_49));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_48));
+ PyTuple_SET_ITEM(__pyx_k_tuple_49, 0, ((PyObject *)__pyx_kp_s_48));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_48));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_49));
+
+ /* "mtrand.pyx":1816
+ *
+ * if np.any(np.less_equal(odfnum, 1.0)):
+ * raise ValueError("dfnum <= 1") # <<<<<<<<<<<<<<
+ * if np.any(np.less_equal(odfden, 0.0)):
+ * raise ValueError("dfden <= 0")
+ */
+ __pyx_k_tuple_50 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_50)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_50));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_45));
+ PyTuple_SET_ITEM(__pyx_k_tuple_50, 0, ((PyObject *)__pyx_kp_s_45));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_45));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_50));
+
+ /* "mtrand.pyx":1818
+ * raise ValueError("dfnum <= 1")
+ * if np.any(np.less_equal(odfden, 0.0)):
+ * raise ValueError("dfden <= 0") # <<<<<<<<<<<<<<
+ * if np.any(np.less(ononc, 0.0)):
+ * raise ValueError("nonc < 0")
+ */
+ __pyx_k_tuple_51 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_51)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_51));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_43));
+ PyTuple_SET_ITEM(__pyx_k_tuple_51, 0, ((PyObject *)__pyx_kp_s_43));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_43));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_51));
+
+ /* "mtrand.pyx":1820
+ * raise ValueError("dfden <= 0")
+ * if np.any(np.less(ononc, 0.0)):
+ * raise ValueError("nonc < 0") # <<<<<<<<<<<<<<
+ * return cont3_array(self.internal_state, rk_noncentral_f, size, odfnum,
+ * odfden, ononc)
+ */
+ __pyx_k_tuple_52 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_52)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_52));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_48));
+ PyTuple_SET_ITEM(__pyx_k_tuple_52, 0, ((PyObject *)__pyx_kp_s_48));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_48));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_52));
+
+ /* "mtrand.pyx":1892
+ * if not PyErr_Occurred():
+ * if fdf <= 0:
+ * raise ValueError("df <= 0") # <<<<<<<<<<<<<<
+ * return cont1_array_sc(self.internal_state, rk_chisquare, size, fdf)
+ *
+ */
+ __pyx_k_tuple_54 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_54)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1892; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_54));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_53));
+ PyTuple_SET_ITEM(__pyx_k_tuple_54, 0, ((PyObject *)__pyx_kp_s_53));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_53));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_54));
+
+ /* "mtrand.pyx":1899
+ * odf = <ndarray>PyArray_FROM_OTF(df, NPY_DOUBLE, NPY_ALIGNED)
+ * if np.any(np.less_equal(odf, 0.0)):
+ * raise ValueError("df <= 0") # <<<<<<<<<<<<<<
+ * return cont1_array(self.internal_state, rk_chisquare, size, odf)
+ *
+ */
+ __pyx_k_tuple_55 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_55)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1899; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_55));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_53));
+ PyTuple_SET_ITEM(__pyx_k_tuple_55, 0, ((PyObject *)__pyx_kp_s_53));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_53));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_55));
+
+ /* "mtrand.pyx":1977
+ * if not PyErr_Occurred():
+ * if fdf <= 1:
+ * raise ValueError("df <= 0") # <<<<<<<<<<<<<<
+ * if fnonc <= 0:
+ * raise ValueError("nonc <= 0")
+ */
+ __pyx_k_tuple_56 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_56)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1977; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_56));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_53));
+ PyTuple_SET_ITEM(__pyx_k_tuple_56, 0, ((PyObject *)__pyx_kp_s_53));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_53));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_56));
+
+ /* "mtrand.pyx":1979
+ * raise ValueError("df <= 0")
+ * if fnonc <= 0:
+ * raise ValueError("nonc <= 0") # <<<<<<<<<<<<<<
+ * return cont2_array_sc(self.internal_state, rk_noncentral_chisquare,
+ * size, fdf, fnonc)
+ */
+ __pyx_k_tuple_58 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_58)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1979; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_58));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_57));
+ PyTuple_SET_ITEM(__pyx_k_tuple_58, 0, ((PyObject *)__pyx_kp_s_57));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_57));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_58));
+
+ /* "mtrand.pyx":1988
+ * ononc = <ndarray>PyArray_FROM_OTF(nonc, NPY_DOUBLE, NPY_ALIGNED)
+ * if np.any(np.less_equal(odf, 0.0)):
+ * raise ValueError("df <= 1") # <<<<<<<<<<<<<<
+ * if np.any(np.less_equal(ononc, 0.0)):
+ * raise ValueError("nonc < 0")
+ */
+ __pyx_k_tuple_60 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_60)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_60));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_59));
+ PyTuple_SET_ITEM(__pyx_k_tuple_60, 0, ((PyObject *)__pyx_kp_s_59));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_59));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_60));
+
+ /* "mtrand.pyx":1990
+ * raise ValueError("df <= 1")
+ * if np.any(np.less_equal(ononc, 0.0)):
+ * raise ValueError("nonc < 0") # <<<<<<<<<<<<<<
+ * return cont2_array(self.internal_state, rk_noncentral_chisquare, size,
+ * odf, ononc)
+ */
+ __pyx_k_tuple_61 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_61)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_61));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_48));
+ PyTuple_SET_ITEM(__pyx_k_tuple_61, 0, ((PyObject *)__pyx_kp_s_48));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_48));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_61));
+
+ /* "mtrand.pyx":2146
+ * if not PyErr_Occurred():
+ * if fdf <= 0:
+ * raise ValueError("df <= 0") # <<<<<<<<<<<<<<
+ * return cont1_array_sc(self.internal_state, rk_standard_t, size, fdf)
+ *
+ */
+ __pyx_k_tuple_62 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_62)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_62));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_53));
+ PyTuple_SET_ITEM(__pyx_k_tuple_62, 0, ((PyObject *)__pyx_kp_s_53));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_53));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_62));
+
+ /* "mtrand.pyx":2153
+ * odf = <ndarray> PyArray_FROM_OTF(df, NPY_DOUBLE, NPY_ALIGNED)
+ * if np.any(np.less_equal(odf, 0.0)):
+ * raise ValueError("df <= 0") # <<<<<<<<<<<<<<
+ * return cont1_array(self.internal_state, rk_standard_t, size, odf)
+ *
+ */
+ __pyx_k_tuple_63 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_63)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_63));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_53));
+ PyTuple_SET_ITEM(__pyx_k_tuple_63, 0, ((PyObject *)__pyx_kp_s_53));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_53));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_63));
+
+ /* "mtrand.pyx":2239
+ * if not PyErr_Occurred():
+ * if fkappa < 0:
+ * raise ValueError("kappa < 0") # <<<<<<<<<<<<<<
+ * return cont2_array_sc(self.internal_state, rk_vonmises, size, fmu, fkappa)
+ *
+ */
+ __pyx_k_tuple_65 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_65)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_65));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_64));
+ PyTuple_SET_ITEM(__pyx_k_tuple_65, 0, ((PyObject *)__pyx_kp_s_64));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_64));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_65));
+
+ /* "mtrand.pyx":2247
+ * okappa = <ndarray> PyArray_FROM_OTF(kappa, NPY_DOUBLE, NPY_ALIGNED)
+ * if np.any(np.less(okappa, 0.0)):
+ * raise ValueError("kappa < 0") # <<<<<<<<<<<<<<
+ * return cont2_array(self.internal_state, rk_vonmises, size, omu, okappa)
+ *
+ */
+ __pyx_k_tuple_66 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_66)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_66));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_64));
+ PyTuple_SET_ITEM(__pyx_k_tuple_66, 0, ((PyObject *)__pyx_kp_s_64));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_64));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_66));
+
+ /* "mtrand.pyx":2336
+ * if not PyErr_Occurred():
+ * if fa <= 0:
+ * raise ValueError("a <= 0") # <<<<<<<<<<<<<<
+ * return cont1_array_sc(self.internal_state, rk_pareto, size, fa)
+ *
+ */
+ __pyx_k_tuple_67 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_67)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_67));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_22));
+ PyTuple_SET_ITEM(__pyx_k_tuple_67, 0, ((PyObject *)__pyx_kp_s_22));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_22));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_67));
+
+ /* "mtrand.pyx":2343
+ * oa = <ndarray>PyArray_FROM_OTF(a, NPY_DOUBLE, NPY_ALIGNED)
+ * if np.any(np.less_equal(oa, 0.0)):
+ * raise ValueError("a <= 0") # <<<<<<<<<<<<<<
+ * return cont1_array(self.internal_state, rk_pareto, size, oa)
+ *
+ */
+ __pyx_k_tuple_68 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_68)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_68));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_22));
+ PyTuple_SET_ITEM(__pyx_k_tuple_68, 0, ((PyObject *)__pyx_kp_s_22));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_22));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_68));
+
+ /* "mtrand.pyx":2436
+ * if not PyErr_Occurred():
+ * if fa <= 0:
+ * raise ValueError("a <= 0") # <<<<<<<<<<<<<<
+ * return cont1_array_sc(self.internal_state, rk_weibull, size, fa)
+ *
+ */
+ __pyx_k_tuple_69 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_69)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_69));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_22));
+ PyTuple_SET_ITEM(__pyx_k_tuple_69, 0, ((PyObject *)__pyx_kp_s_22));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_22));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_69));
+
+ /* "mtrand.pyx":2443
+ * oa = <ndarray>PyArray_FROM_OTF(a, NPY_DOUBLE, NPY_ALIGNED)
+ * if np.any(np.less_equal(oa, 0.0)):
+ * raise ValueError("a <= 0") # <<<<<<<<<<<<<<
+ * return cont1_array(self.internal_state, rk_weibull, size, oa)
+ *
+ */
+ __pyx_k_tuple_70 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_70)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2443; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_70));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_22));
+ PyTuple_SET_ITEM(__pyx_k_tuple_70, 0, ((PyObject *)__pyx_kp_s_22));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_22));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_70));
+
+ /* "mtrand.pyx":2545
+ * if not PyErr_Occurred():
+ * if fa <= 0:
+ * raise ValueError("a <= 0") # <<<<<<<<<<<<<<
+ * return cont1_array_sc(self.internal_state, rk_power, size, fa)
+ *
+ */
+ __pyx_k_tuple_71 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_71)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2545; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_71));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_22));
+ PyTuple_SET_ITEM(__pyx_k_tuple_71, 0, ((PyObject *)__pyx_kp_s_22));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_22));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_71));
+
+ /* "mtrand.pyx":2552
+ * oa = <ndarray>PyArray_FROM_OTF(a, NPY_DOUBLE, NPY_ALIGNED)
+ * if np.any(np.less_equal(oa, 0.0)):
+ * raise ValueError("a <= 0") # <<<<<<<<<<<<<<
+ * return cont1_array(self.internal_state, rk_power, size, oa)
+ *
+ */
+ __pyx_k_tuple_72 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_72)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2552; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_72));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_22));
+ PyTuple_SET_ITEM(__pyx_k_tuple_72, 0, ((PyObject *)__pyx_kp_s_22));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_22));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_72));
+
+ /* "mtrand.pyx":2635
+ * if not PyErr_Occurred():
+ * if fscale <= 0:
+ * raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
+ * return cont2_array_sc(self.internal_state, rk_laplace, size, floc, fscale)
+ *
+ */
+ __pyx_k_tuple_75 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_75)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2635; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_75));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_19));
+ PyTuple_SET_ITEM(__pyx_k_tuple_75, 0, ((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_75));
+
+ /* "mtrand.pyx":2642
+ * oscale = PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
+ * if np.any(np.less_equal(oscale, 0.0)):
+ * raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
+ * return cont2_array(self.internal_state, rk_laplace, size, oloc, oscale)
+ *
+ */
+ __pyx_k_tuple_76 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_76)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_76));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_19));
+ PyTuple_SET_ITEM(__pyx_k_tuple_76, 0, ((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_76));
+
+ /* "mtrand.pyx":2766
+ * if not PyErr_Occurred():
+ * if fscale <= 0:
+ * raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
+ * return cont2_array_sc(self.internal_state, rk_gumbel, size, floc, fscale)
+ *
+ */
+ __pyx_k_tuple_79 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_79)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_79));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_19));
+ PyTuple_SET_ITEM(__pyx_k_tuple_79, 0, ((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_79));
+
+ /* "mtrand.pyx":2773
+ * oscale = PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
+ * if np.any(np.less_equal(oscale, 0.0)):
+ * raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
+ * return cont2_array(self.internal_state, rk_gumbel, size, oloc, oscale)
+ *
+ */
+ __pyx_k_tuple_80 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_80)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_80));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_19));
+ PyTuple_SET_ITEM(__pyx_k_tuple_80, 0, ((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_80));
+
+ /* "mtrand.pyx":2854
+ * if not PyErr_Occurred():
+ * if fscale <= 0:
+ * raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
+ * return cont2_array_sc(self.internal_state, rk_logistic, size, floc, fscale)
+ *
+ */
+ __pyx_k_tuple_83 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_83)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_83));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_19));
+ PyTuple_SET_ITEM(__pyx_k_tuple_83, 0, ((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_83));
+
+ /* "mtrand.pyx":2861
+ * oscale = PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
+ * if np.any(np.less_equal(oscale, 0.0)):
+ * raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
+ * return cont2_array(self.internal_state, rk_logistic, size, oloc, oscale)
+ *
+ */
+ __pyx_k_tuple_84 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_84)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2861; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_84));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_19));
+ PyTuple_SET_ITEM(__pyx_k_tuple_84, 0, ((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_84));
+
+ /* "mtrand.pyx":2984
+ * if not PyErr_Occurred():
+ * if fsigma <= 0:
+ * raise ValueError("sigma <= 0") # <<<<<<<<<<<<<<
+ * return cont2_array_sc(self.internal_state, rk_lognormal, size, fmean, fsigma)
+ *
+ */
+ __pyx_k_tuple_88 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_88)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_88));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_87));
+ PyTuple_SET_ITEM(__pyx_k_tuple_88, 0, ((PyObject *)__pyx_kp_s_87));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_87));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_88));
+
+ /* "mtrand.pyx":2992
+ * osigma = PyArray_FROM_OTF(sigma, NPY_DOUBLE, NPY_ALIGNED)
+ * if np.any(np.less_equal(osigma, 0.0)):
+ * raise ValueError("sigma <= 0.0") # <<<<<<<<<<<<<<
+ * return cont2_array(self.internal_state, rk_lognormal, size, omean, osigma)
+ *
+ */
+ __pyx_k_tuple_90 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_90)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2992; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_90));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_89));
+ PyTuple_SET_ITEM(__pyx_k_tuple_90, 0, ((PyObject *)__pyx_kp_s_89));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_89));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_90));
+
+ /* "mtrand.pyx":3057
+ * if not PyErr_Occurred():
+ * if fscale <= 0:
+ * raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
+ * return cont1_array_sc(self.internal_state, rk_rayleigh, size, fscale)
+ *
+ */
+ __pyx_k_tuple_92 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_92)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3057; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_92));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_19));
+ PyTuple_SET_ITEM(__pyx_k_tuple_92, 0, ((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_92));
+
+ /* "mtrand.pyx":3064
+ * oscale = <ndarray>PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
+ * if np.any(np.less_equal(oscale, 0.0)):
+ * raise ValueError("scale <= 0.0") # <<<<<<<<<<<<<<
+ * return cont1_array(self.internal_state, rk_rayleigh, size, oscale)
+ *
+ */
+ __pyx_k_tuple_94 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_94)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_94));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_93));
+ PyTuple_SET_ITEM(__pyx_k_tuple_94, 0, ((PyObject *)__pyx_kp_s_93));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_93));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_94));
+
+ /* "mtrand.pyx":3137
+ * if not PyErr_Occurred():
+ * if fmean <= 0:
+ * raise ValueError("mean <= 0") # <<<<<<<<<<<<<<
+ * if fscale <= 0:
+ * raise ValueError("scale <= 0")
+ */
+ __pyx_k_tuple_96 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_96)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_96));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_95));
+ PyTuple_SET_ITEM(__pyx_k_tuple_96, 0, ((PyObject *)__pyx_kp_s_95));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_95));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_96));
+
+ /* "mtrand.pyx":3139
+ * raise ValueError("mean <= 0")
+ * if fscale <= 0:
+ * raise ValueError("scale <= 0") # <<<<<<<<<<<<<<
+ * return cont2_array_sc(self.internal_state, rk_wald, size, fmean, fscale)
+ *
+ */
+ __pyx_k_tuple_97 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_97)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_97));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_19));
+ PyTuple_SET_ITEM(__pyx_k_tuple_97, 0, ((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_97));
+
+ /* "mtrand.pyx":3146
+ * oscale = PyArray_FROM_OTF(scale, NPY_DOUBLE, NPY_ALIGNED)
+ * if np.any(np.less_equal(omean,0.0)):
+ * raise ValueError("mean <= 0.0") # <<<<<<<<<<<<<<
+ * elif np.any(np.less_equal(oscale,0.0)):
+ * raise ValueError("scale <= 0.0")
+ */
+ __pyx_k_tuple_99 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_99)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_99));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_98));
+ PyTuple_SET_ITEM(__pyx_k_tuple_99, 0, ((PyObject *)__pyx_kp_s_98));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_98));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_99));
+
+ /* "mtrand.pyx":3148
+ * raise ValueError("mean <= 0.0")
+ * elif np.any(np.less_equal(oscale,0.0)):
+ * raise ValueError("scale <= 0.0") # <<<<<<<<<<<<<<
+ * return cont2_array(self.internal_state, rk_wald, size, omean, oscale)
+ *
+ */
+ __pyx_k_tuple_100 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_100)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3148; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_100));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_93));
+ PyTuple_SET_ITEM(__pyx_k_tuple_100, 0, ((PyObject *)__pyx_kp_s_93));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_93));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_100));
+
+ /* "mtrand.pyx":3218
+ * if not PyErr_Occurred():
+ * if fleft > fmode:
+ * raise ValueError("left > mode") # <<<<<<<<<<<<<<
+ * if fmode > fright:
+ * raise ValueError("mode > right")
+ */
+ __pyx_k_tuple_102 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_102)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_102));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_101));
+ PyTuple_SET_ITEM(__pyx_k_tuple_102, 0, ((PyObject *)__pyx_kp_s_101));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_101));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_102));
+
+ /* "mtrand.pyx":3220
+ * raise ValueError("left > mode")
+ * if fmode > fright:
+ * raise ValueError("mode > right") # <<<<<<<<<<<<<<
+ * if fleft == fright:
+ * raise ValueError("left == right")
+ */
+ __pyx_k_tuple_104 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_104)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_104));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_103));
+ PyTuple_SET_ITEM(__pyx_k_tuple_104, 0, ((PyObject *)__pyx_kp_s_103));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_103));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_104));
+
+ /* "mtrand.pyx":3222
+ * raise ValueError("mode > right")
+ * if fleft == fright:
+ * raise ValueError("left == right") # <<<<<<<<<<<<<<
+ * return cont3_array_sc(self.internal_state, rk_triangular, size, fleft,
+ * fmode, fright)
+ */
+ __pyx_k_tuple_106 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_106)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_106));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_105));
+ PyTuple_SET_ITEM(__pyx_k_tuple_106, 0, ((PyObject *)__pyx_kp_s_105));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_105));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_106));
+
+ /* "mtrand.pyx":3232
+ *
+ * if np.any(np.greater(oleft, omode)):
+ * raise ValueError("left > mode") # <<<<<<<<<<<<<<
+ * if np.any(np.greater(omode, oright)):
+ * raise ValueError("mode > right")
+ */
+ __pyx_k_tuple_107 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_107)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_107));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_101));
+ PyTuple_SET_ITEM(__pyx_k_tuple_107, 0, ((PyObject *)__pyx_kp_s_101));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_101));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_107));
+
+ /* "mtrand.pyx":3234
+ * raise ValueError("left > mode")
+ * if np.any(np.greater(omode, oright)):
+ * raise ValueError("mode > right") # <<<<<<<<<<<<<<
+ * if np.any(np.equal(oleft, oright)):
+ * raise ValueError("left == right")
+ */
+ __pyx_k_tuple_108 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_108)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3234; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_108));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_103));
+ PyTuple_SET_ITEM(__pyx_k_tuple_108, 0, ((PyObject *)__pyx_kp_s_103));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_103));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_108));
+
+ /* "mtrand.pyx":3236
+ * raise ValueError("mode > right")
+ * if np.any(np.equal(oleft, oright)):
+ * raise ValueError("left == right") # <<<<<<<<<<<<<<
+ * return cont3_array(self.internal_state, rk_triangular, size, oleft,
+ * omode, oright)
+ */
+ __pyx_k_tuple_109 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_109)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_109));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_105));
+ PyTuple_SET_ITEM(__pyx_k_tuple_109, 0, ((PyObject *)__pyx_kp_s_105));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_105));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_109));
+
+ /* "mtrand.pyx":3330
+ * if not PyErr_Occurred():
+ * if ln <= 0:
+ * raise ValueError("n <= 0") # <<<<<<<<<<<<<<
+ * if fp < 0:
+ * raise ValueError("p < 0")
+ */
+ __pyx_k_tuple_111 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_111)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_111));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_110));
+ PyTuple_SET_ITEM(__pyx_k_tuple_111, 0, ((PyObject *)__pyx_kp_s_110));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_110));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_111));
+
+ /* "mtrand.pyx":3332
+ * raise ValueError("n <= 0")
+ * if fp < 0:
+ * raise ValueError("p < 0") # <<<<<<<<<<<<<<
+ * elif fp > 1:
+ * raise ValueError("p > 1")
+ */
+ __pyx_k_tuple_113 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_113)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_113));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_112));
+ PyTuple_SET_ITEM(__pyx_k_tuple_113, 0, ((PyObject *)__pyx_kp_s_112));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_112));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_113));
+
+ /* "mtrand.pyx":3334
+ * raise ValueError("p < 0")
+ * elif fp > 1:
+ * raise ValueError("p > 1") # <<<<<<<<<<<<<<
+ * return discnp_array_sc(self.internal_state, rk_binomial, size, ln, fp)
+ *
+ */
+ __pyx_k_tuple_115 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_115)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_115));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_114));
+ PyTuple_SET_ITEM(__pyx_k_tuple_115, 0, ((PyObject *)__pyx_kp_s_114));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_114));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_115));
+
+ /* "mtrand.pyx":3342
+ * op = <ndarray>PyArray_FROM_OTF(p, NPY_DOUBLE, NPY_ALIGNED)
+ * if np.any(np.less_equal(n, 0)):
+ * raise ValueError("n <= 0") # <<<<<<<<<<<<<<
+ * if np.any(np.less(p, 0)):
+ * raise ValueError("p < 0")
+ */
+ __pyx_k_tuple_116 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_116)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_116));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_110));
+ PyTuple_SET_ITEM(__pyx_k_tuple_116, 0, ((PyObject *)__pyx_kp_s_110));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_110));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_116));
+
+ /* "mtrand.pyx":3344
+ * raise ValueError("n <= 0")
+ * if np.any(np.less(p, 0)):
+ * raise ValueError("p < 0") # <<<<<<<<<<<<<<
+ * if np.any(np.greater(p, 1)):
+ * raise ValueError("p > 1")
+ */
+ __pyx_k_tuple_117 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_117)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_117));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_112));
+ PyTuple_SET_ITEM(__pyx_k_tuple_117, 0, ((PyObject *)__pyx_kp_s_112));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_112));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_117));
+
+ /* "mtrand.pyx":3346
+ * raise ValueError("p < 0")
+ * if np.any(np.greater(p, 1)):
+ * raise ValueError("p > 1") # <<<<<<<<<<<<<<
+ * return discnp_array(self.internal_state, rk_binomial, size, on, op)
+ *
+ */
+ __pyx_k_tuple_118 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_118)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_118));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_114));
+ PyTuple_SET_ITEM(__pyx_k_tuple_118, 0, ((PyObject *)__pyx_kp_s_114));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_114));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_118));
+
+ /* "mtrand.pyx":3423
+ * if not PyErr_Occurred():
+ * if fn <= 0:
+ * raise ValueError("n <= 0") # <<<<<<<<<<<<<<
+ * if fp < 0:
+ * raise ValueError("p < 0")
+ */
+ __pyx_k_tuple_119 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_119)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_119));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_110));
+ PyTuple_SET_ITEM(__pyx_k_tuple_119, 0, ((PyObject *)__pyx_kp_s_110));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_110));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_119));
+
+ /* "mtrand.pyx":3425
+ * raise ValueError("n <= 0")
+ * if fp < 0:
+ * raise ValueError("p < 0") # <<<<<<<<<<<<<<
+ * elif fp > 1:
+ * raise ValueError("p > 1")
+ */
+ __pyx_k_tuple_120 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_120)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_120));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_112));
+ PyTuple_SET_ITEM(__pyx_k_tuple_120, 0, ((PyObject *)__pyx_kp_s_112));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_112));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_120));
+
+ /* "mtrand.pyx":3427
+ * raise ValueError("p < 0")
+ * elif fp > 1:
+ * raise ValueError("p > 1") # <<<<<<<<<<<<<<
+ * return discdd_array_sc(self.internal_state, rk_negative_binomial,
+ * size, fn, fp)
+ */
+ __pyx_k_tuple_121 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_121)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3427; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_121));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_114));
+ PyTuple_SET_ITEM(__pyx_k_tuple_121, 0, ((PyObject *)__pyx_kp_s_114));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_114));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_121));
+
+ /* "mtrand.pyx":3436
+ * op = <ndarray>PyArray_FROM_OTF(p, NPY_DOUBLE, NPY_ALIGNED)
+ * if np.any(np.less_equal(n, 0)):
+ * raise ValueError("n <= 0") # <<<<<<<<<<<<<<
+ * if np.any(np.less(p, 0)):
+ * raise ValueError("p < 0")
+ */
+ __pyx_k_tuple_122 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_122)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_122));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_110));
+ PyTuple_SET_ITEM(__pyx_k_tuple_122, 0, ((PyObject *)__pyx_kp_s_110));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_110));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_122));
+
+ /* "mtrand.pyx":3438
+ * raise ValueError("n <= 0")
+ * if np.any(np.less(p, 0)):
+ * raise ValueError("p < 0") # <<<<<<<<<<<<<<
+ * if np.any(np.greater(p, 1)):
+ * raise ValueError("p > 1")
+ */
+ __pyx_k_tuple_123 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_123)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3438; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_123));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_112));
+ PyTuple_SET_ITEM(__pyx_k_tuple_123, 0, ((PyObject *)__pyx_kp_s_112));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_112));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_123));
+
+ /* "mtrand.pyx":3440
+ * raise ValueError("p < 0")
+ * if np.any(np.greater(p, 1)):
+ * raise ValueError("p > 1") # <<<<<<<<<<<<<<
+ * return discdd_array(self.internal_state, rk_negative_binomial, size,
+ * on, op)
+ */
+ __pyx_k_tuple_124 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_124)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_124));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_114));
+ PyTuple_SET_ITEM(__pyx_k_tuple_124, 0, ((PyObject *)__pyx_kp_s_114));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_114));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_124));
+
+ /* "mtrand.pyx":3501
+ * if not PyErr_Occurred():
+ * if lam < 0:
+ * raise ValueError("lam < 0") # <<<<<<<<<<<<<<
+ * if lam > self.poisson_lam_max:
+ * raise ValueError("lam value too large")
+ */
+ __pyx_k_tuple_127 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_127)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_127));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_126));
+ PyTuple_SET_ITEM(__pyx_k_tuple_127, 0, ((PyObject *)__pyx_kp_s_126));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_126));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_127));
+
+ /* "mtrand.pyx":3503
+ * raise ValueError("lam < 0")
+ * if lam > self.poisson_lam_max:
+ * raise ValueError("lam value too large") # <<<<<<<<<<<<<<
+ * return discd_array_sc(self.internal_state, rk_poisson, size, flam)
+ *
+ */
+ __pyx_k_tuple_129 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_129)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_129));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_128));
+ PyTuple_SET_ITEM(__pyx_k_tuple_129, 0, ((PyObject *)__pyx_kp_s_128));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_128));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_129));
+
+ /* "mtrand.pyx":3510
+ * olam = <ndarray>PyArray_FROM_OTF(lam, NPY_DOUBLE, NPY_ALIGNED)
+ * if np.any(np.less(olam, 0)):
+ * raise ValueError("lam < 0") # <<<<<<<<<<<<<<
+ * if np.any(np.greater(olam, self.poisson_lam_max)):
+ * raise ValueError("lam value too large.")
+ */
+ __pyx_k_tuple_130 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_130)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_130));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_126));
+ PyTuple_SET_ITEM(__pyx_k_tuple_130, 0, ((PyObject *)__pyx_kp_s_126));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_126));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_130));
+
+ /* "mtrand.pyx":3512
+ * raise ValueError("lam < 0")
+ * if np.any(np.greater(olam, self.poisson_lam_max)):
+ * raise ValueError("lam value too large.") # <<<<<<<<<<<<<<
+ * return discd_array(self.internal_state, rk_poisson, size, olam)
+ *
+ */
+ __pyx_k_tuple_132 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_132)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_132));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_131));
+ PyTuple_SET_ITEM(__pyx_k_tuple_132, 0, ((PyObject *)__pyx_kp_s_131));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_131));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_132));
+
+ /* "mtrand.pyx":3593
+ * if not PyErr_Occurred():
+ * if fa <= 1.0:
+ * raise ValueError("a <= 1.0") # <<<<<<<<<<<<<<
+ * return discd_array_sc(self.internal_state, rk_zipf, size, fa)
+ *
+ */
+ __pyx_k_tuple_134 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_134)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_134));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_133));
+ PyTuple_SET_ITEM(__pyx_k_tuple_134, 0, ((PyObject *)__pyx_kp_s_133));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_133));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_134));
+
+ /* "mtrand.pyx":3600
+ * oa = <ndarray>PyArray_FROM_OTF(a, NPY_DOUBLE, NPY_ALIGNED)
+ * if np.any(np.less_equal(oa, 1.0)):
+ * raise ValueError("a <= 1.0") # <<<<<<<<<<<<<<
+ * return discd_array(self.internal_state, rk_zipf, size, oa)
+ *
+ */
+ __pyx_k_tuple_135 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_135)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_135));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_133));
+ PyTuple_SET_ITEM(__pyx_k_tuple_135, 0, ((PyObject *)__pyx_kp_s_133));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_133));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_135));
+
+ /* "mtrand.pyx":3654
+ * if not PyErr_Occurred():
+ * if fp < 0.0:
+ * raise ValueError("p < 0.0") # <<<<<<<<<<<<<<
+ * if fp > 1.0:
+ * raise ValueError("p > 1.0")
+ */
+ __pyx_k_tuple_137 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_137)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3654; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_137));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_136));
+ PyTuple_SET_ITEM(__pyx_k_tuple_137, 0, ((PyObject *)__pyx_kp_s_136));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_136));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_137));
+
+ /* "mtrand.pyx":3656
+ * raise ValueError("p < 0.0")
+ * if fp > 1.0:
+ * raise ValueError("p > 1.0") # <<<<<<<<<<<<<<
+ * return discd_array_sc(self.internal_state, rk_geometric, size, fp)
+ *
+ */
+ __pyx_k_tuple_139 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_139)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_139));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_138));
+ PyTuple_SET_ITEM(__pyx_k_tuple_139, 0, ((PyObject *)__pyx_kp_s_138));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_138));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_139));
+
+ /* "mtrand.pyx":3664
+ * op = <ndarray>PyArray_FROM_OTF(p, NPY_DOUBLE, NPY_ALIGNED)
+ * if np.any(np.less(op, 0.0)):
+ * raise ValueError("p < 0.0") # <<<<<<<<<<<<<<
+ * if np.any(np.greater(op, 1.0)):
+ * raise ValueError("p > 1.0")
+ */
+ __pyx_k_tuple_140 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_140)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3664; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_140));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_136));
+ PyTuple_SET_ITEM(__pyx_k_tuple_140, 0, ((PyObject *)__pyx_kp_s_136));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_136));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_140));
+
+ /* "mtrand.pyx":3666
+ * raise ValueError("p < 0.0")
+ * if np.any(np.greater(op, 1.0)):
+ * raise ValueError("p > 1.0") # <<<<<<<<<<<<<<
+ * return discd_array(self.internal_state, rk_geometric, size, op)
+ *
+ */
+ __pyx_k_tuple_141 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_141)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_141));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_138));
+ PyTuple_SET_ITEM(__pyx_k_tuple_141, 0, ((PyObject *)__pyx_kp_s_138));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_138));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_141));
+
+ /* "mtrand.pyx":3761
+ * if not PyErr_Occurred():
+ * if ngood < 1:
+ * raise ValueError("ngood < 1") # <<<<<<<<<<<<<<
+ * if nbad < 1:
+ * raise ValueError("nbad < 1")
+ */
+ __pyx_k_tuple_143 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_143)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3761; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_143));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_142));
+ PyTuple_SET_ITEM(__pyx_k_tuple_143, 0, ((PyObject *)__pyx_kp_s_142));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_142));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_143));
+
+ /* "mtrand.pyx":3763
+ * raise ValueError("ngood < 1")
+ * if nbad < 1:
+ * raise ValueError("nbad < 1") # <<<<<<<<<<<<<<
+ * if nsample < 1:
+ * raise ValueError("nsample < 1")
+ */
+ __pyx_k_tuple_145 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_145)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_145));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_144));
+ PyTuple_SET_ITEM(__pyx_k_tuple_145, 0, ((PyObject *)__pyx_kp_s_144));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_144));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_145));
+
+ /* "mtrand.pyx":3765
+ * raise ValueError("nbad < 1")
+ * if nsample < 1:
+ * raise ValueError("nsample < 1") # <<<<<<<<<<<<<<
+ * if ngood + nbad < nsample:
+ * raise ValueError("ngood + nbad < nsample")
+ */
+ __pyx_k_tuple_147 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_147)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_147));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_146));
+ PyTuple_SET_ITEM(__pyx_k_tuple_147, 0, ((PyObject *)__pyx_kp_s_146));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_146));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_147));
+
+ /* "mtrand.pyx":3767
+ * raise ValueError("nsample < 1")
+ * if ngood + nbad < nsample:
+ * raise ValueError("ngood + nbad < nsample") # <<<<<<<<<<<<<<
+ * return discnmN_array_sc(self.internal_state, rk_hypergeometric, size,
+ * lngood, lnbad, lnsample)
+ */
+ __pyx_k_tuple_149 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_149)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3767; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_149));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_148));
+ PyTuple_SET_ITEM(__pyx_k_tuple_149, 0, ((PyObject *)__pyx_kp_s_148));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_148));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_149));
+
+ /* "mtrand.pyx":3778
+ * onsample = <ndarray>PyArray_FROM_OTF(nsample, NPY_LONG, NPY_ALIGNED)
+ * if np.any(np.less(ongood, 1)):
+ * raise ValueError("ngood < 1") # <<<<<<<<<<<<<<
+ * if np.any(np.less(onbad, 1)):
+ * raise ValueError("nbad < 1")
+ */
+ __pyx_k_tuple_150 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_150)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3778; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_150));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_142));
+ PyTuple_SET_ITEM(__pyx_k_tuple_150, 0, ((PyObject *)__pyx_kp_s_142));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_142));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_150));
+
+ /* "mtrand.pyx":3780
+ * raise ValueError("ngood < 1")
+ * if np.any(np.less(onbad, 1)):
+ * raise ValueError("nbad < 1") # <<<<<<<<<<<<<<
+ * if np.any(np.less(onsample, 1)):
+ * raise ValueError("nsample < 1")
+ */
+ __pyx_k_tuple_151 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_151)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3780; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_151));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_144));
+ PyTuple_SET_ITEM(__pyx_k_tuple_151, 0, ((PyObject *)__pyx_kp_s_144));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_144));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_151));
+
+ /* "mtrand.pyx":3782
+ * raise ValueError("nbad < 1")
+ * 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_k_tuple_152 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_152)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_152));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_146));
+ PyTuple_SET_ITEM(__pyx_k_tuple_152, 0, ((PyObject *)__pyx_kp_s_146));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_146));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_152));
+
+ /* "mtrand.pyx":3784
+ * raise ValueError("nsample < 1")
+ * if np.any(np.less(np.add(ongood, onbad),onsample)):
+ * raise ValueError("ngood + nbad < nsample") # <<<<<<<<<<<<<<
+ * return discnmN_array(self.internal_state, rk_hypergeometric, size,
+ * ongood, onbad, onsample)
+ */
+ __pyx_k_tuple_153 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_153)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_153));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_148));
+ PyTuple_SET_ITEM(__pyx_k_tuple_153, 0, ((PyObject *)__pyx_kp_s_148));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_148));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_153));
+
+ /* "mtrand.pyx":3868
+ * if not PyErr_Occurred():
+ * if fp <= 0.0:
+ * raise ValueError("p <= 0.0") # <<<<<<<<<<<<<<
+ * if fp >= 1.0:
+ * raise ValueError("p >= 1.0")
+ */
+ __pyx_k_tuple_155 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_155)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_155));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_154));
+ PyTuple_SET_ITEM(__pyx_k_tuple_155, 0, ((PyObject *)__pyx_kp_s_154));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_154));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_155));
+
+ /* "mtrand.pyx":3870
+ * raise ValueError("p <= 0.0")
+ * if fp >= 1.0:
+ * raise ValueError("p >= 1.0") # <<<<<<<<<<<<<<
+ * return discd_array_sc(self.internal_state, rk_logseries, size, fp)
+ *
+ */
+ __pyx_k_tuple_157 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_157)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_157));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_156));
+ PyTuple_SET_ITEM(__pyx_k_tuple_157, 0, ((PyObject *)__pyx_kp_s_156));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_156));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_157));
+
+ /* "mtrand.pyx":3877
+ * op = <ndarray>PyArray_FROM_OTF(p, NPY_DOUBLE, NPY_ALIGNED)
+ * if np.any(np.less_equal(op, 0.0)):
+ * raise ValueError("p <= 0.0") # <<<<<<<<<<<<<<
+ * if np.any(np.greater_equal(op, 1.0)):
+ * raise ValueError("p >= 1.0")
+ */
+ __pyx_k_tuple_158 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_158)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_158));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_154));
+ PyTuple_SET_ITEM(__pyx_k_tuple_158, 0, ((PyObject *)__pyx_kp_s_154));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_154));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_158));
+
+ /* "mtrand.pyx":3879
+ * raise ValueError("p <= 0.0")
+ * if np.any(np.greater_equal(op, 1.0)):
+ * raise ValueError("p >= 1.0") # <<<<<<<<<<<<<<
+ * return discd_array(self.internal_state, rk_logseries, size, op)
+ *
+ */
+ __pyx_k_tuple_159 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_159)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3879; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_159));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_156));
+ PyTuple_SET_ITEM(__pyx_k_tuple_159, 0, ((PyObject *)__pyx_kp_s_156));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_156));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_159));
+
+ /* "mtrand.pyx":3982
+ * shape = size
+ * if len(mean.shape) != 1:
+ * raise ValueError("mean must be 1 dimensional") # <<<<<<<<<<<<<<
+ * if (len(cov.shape) != 2) or (cov.shape[0] != cov.shape[1]):
+ * raise ValueError("cov must be 2 dimensional and square")
+ */
+ __pyx_k_tuple_161 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_161)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3982; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_161));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_160));
+ PyTuple_SET_ITEM(__pyx_k_tuple_161, 0, ((PyObject *)__pyx_kp_s_160));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_160));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_161));
+
+ /* "mtrand.pyx":3984
+ * raise ValueError("mean must be 1 dimensional")
+ * if (len(cov.shape) != 2) or (cov.shape[0] != cov.shape[1]):
+ * raise ValueError("cov must be 2 dimensional and square") # <<<<<<<<<<<<<<
+ * if mean.shape[0] != cov.shape[0]:
+ * raise ValueError("mean and cov must have same length")
+ */
+ __pyx_k_tuple_163 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_163)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_163));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_162));
+ PyTuple_SET_ITEM(__pyx_k_tuple_163, 0, ((PyObject *)__pyx_kp_s_162));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_162));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_163));
+
+ /* "mtrand.pyx":3986
+ * raise ValueError("cov must be 2 dimensional and square")
+ * if mean.shape[0] != cov.shape[0]:
+ * raise ValueError("mean and cov must have same length") # <<<<<<<<<<<<<<
+ * # Compute shape of output
+ * if isinstance(shape, int):
+ */
+ __pyx_k_tuple_165 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_165)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_165));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_164));
+ PyTuple_SET_ITEM(__pyx_k_tuple_165, 0, ((PyObject *)__pyx_kp_s_164));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_164));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_165));
+
+ /* "mtrand.pyx":4079
+ *
+ * if kahan_sum(pix, d-1) > (1.0 + 1e-12):
+ * raise ValueError("sum(pvals[:-1]) > 1.0") # <<<<<<<<<<<<<<
+ *
+ * if size is None:
+ */
+ __pyx_k_tuple_168 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_168)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_168));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_167));
+ PyTuple_SET_ITEM(__pyx_k_tuple_168, 0, ((PyObject *)__pyx_kp_s_167));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_167));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_168));
+
+ /* "mtrand.pyx":556
+ * """
+ * cdef rk_state *internal_state
+ * poisson_lam_max = np.iinfo('l').max - np.sqrt(np.iinfo('l').max)*10 # <<<<<<<<<<<<<<
+ *
+ * def __init__(self, seed=None):
+ */
+ __pyx_k_tuple_169 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_169)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_169));
+ __Pyx_INCREF(((PyObject *)__pyx_n_s__l));
+ PyTuple_SET_ITEM(__pyx_k_tuple_169, 0, ((PyObject *)__pyx_n_s__l));
+ __Pyx_GIVEREF(((PyObject *)__pyx_n_s__l));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_169));
+ __pyx_k_tuple_170 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_170)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_170));
+ __Pyx_INCREF(((PyObject *)__pyx_n_s__l));
+ PyTuple_SET_ITEM(__pyx_k_tuple_170, 0, ((PyObject *)__pyx_n_s__l));
+ __Pyx_GIVEREF(((PyObject *)__pyx_n_s__l));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_170));
+ __Pyx_RefNannyFinishContext();
+ return 0;
+ __pyx_L1_error:;
+ __Pyx_RefNannyFinishContext();
+ return -1;
+}
+
static int __Pyx_InitGlobals(void) {
if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
__pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
__pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ __pyx_int_10 = PyInt_FromLong(10); if (unlikely(!__pyx_int_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
__pyx_int_624 = PyInt_FromLong(624); if (unlikely(!__pyx_int_624)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
return 0;
__pyx_L1_error:;
@@ -19393,6 +20381,7 @@ PyMODINIT_FUNC PyInit_mtrand(void)
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
PyObject *__pyx_t_3 = NULL;
+ PyObject *__pyx_t_4 = NULL;
#if CYTHON_REFNANNY
void* __pyx_refnanny = NULL;
__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
@@ -19404,12 +20393,10 @@ PyMODINIT_FUNC PyInit_mtrand(void)
}
__pyx_refnanny = __Pyx_RefNanny->SetupContext("PyMODINIT_FUNC PyInit_mtrand(void)", __LINE__, __FILE__);
#endif
- __pyx_init_filenames();
__pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- #if PY_MAJOR_VERSION < 3
- __pyx_empty_bytes = PyString_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- #else
__pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #ifdef __pyx_binding_PyCFunctionType_USED
+ if (__pyx_binding_PyCFunctionType_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#endif
/*--- Library function declarations ---*/
/*--- Threads initialization code ---*/
@@ -19438,6 +20425,8 @@ PyMODINIT_FUNC PyInit_mtrand(void)
}
/*--- Builtin init code ---*/
if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ /*--- Constants init code ---*/
+ if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
/*--- Global init code ---*/
/*--- Function export code ---*/
/*--- Type init code ---*/
@@ -19473,1349 +20462,976 @@ PyMODINIT_FUNC PyInit_mtrand(void)
if (PyObject_SetAttr(__pyx_m, __pyx_n_s__np, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- /* "mtrand.pyx":893
+ /* "mtrand.pyx":556
+ * """
+ * cdef rk_state *internal_state
+ * poisson_lam_max = np.iinfo('l').max - np.sqrt(np.iinfo('l').max)*10 # <<<<<<<<<<<<<<
+ *
+ * def __init__(self, seed=None):
+ */
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__iinfo); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_169), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__max); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__sqrt); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__iinfo); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_170), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__max); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_1));
+ PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
+ __Pyx_GIVEREF(__pyx_t_4);
+ __pyx_t_4 = 0;
+ __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+ __pyx_t_1 = PyNumber_Multiply(__pyx_t_4, __pyx_int_10); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __pyx_t_4 = PyNumber_Subtract(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; __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_1); __pyx_t_1 = 0;
+ if (PyDict_SetItem((PyObject *)__pyx_ptype_6mtrand_RandomState->tp_dict, __pyx_n_s__poisson_lam_max, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ PyType_Modified(__pyx_ptype_6mtrand_RandomState);
+
+ /* "mtrand.pyx":916
* return bytestring
*
* def uniform(self, low=0.0, high=1.0, size=None): # <<<<<<<<<<<<<<
* """
* uniform(low=0.0, high=1.0, size=1)
*/
- __pyx_t_1 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 893; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_k_5 = __pyx_t_1;
- __Pyx_GIVEREF(__pyx_t_1);
- __pyx_t_1 = 0;
- __pyx_t_1 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 893; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_k_6 = __pyx_t_1;
- __Pyx_GIVEREF(__pyx_t_1);
- __pyx_t_1 = 0;
+ __pyx_t_4 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 916; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_k_15 = __pyx_t_4;
+ __Pyx_GIVEREF(__pyx_t_4);
+ __pyx_t_4 = 0;
+ __pyx_t_4 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 916; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_k_16 = __pyx_t_4;
+ __Pyx_GIVEREF(__pyx_t_4);
+ __pyx_t_4 = 0;
- /* "mtrand.pyx":1190
+ /* "mtrand.pyx":1212
* return cont0_array(self.internal_state, rk_gauss, size)
*
* def normal(self, loc=0.0, scale=1.0, size=None): # <<<<<<<<<<<<<<
* """
* normal(loc=0.0, scale=1.0, size=None)
*/
- __pyx_t_1 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_k_7 = __pyx_t_1;
- __Pyx_GIVEREF(__pyx_t_1);
- __pyx_t_1 = 0;
- __pyx_t_1 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_k_8 = __pyx_t_1;
- __Pyx_GIVEREF(__pyx_t_1);
- __pyx_t_1 = 0;
+ __pyx_t_4 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_k_17 = __pyx_t_4;
+ __Pyx_GIVEREF(__pyx_t_4);
+ __pyx_t_4 = 0;
+ __pyx_t_4 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_k_18 = __pyx_t_4;
+ __Pyx_GIVEREF(__pyx_t_4);
+ __pyx_t_4 = 0;
- /* "mtrand.pyx":1349
+ /* "mtrand.pyx":1371
* return cont2_array(self.internal_state, rk_beta, size, oa, ob)
*
* def exponential(self, scale=1.0, size=None): # <<<<<<<<<<<<<<
* """
* exponential(scale=1.0, size=None)
*/
- __pyx_t_1 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_k_12 = __pyx_t_1;
- __Pyx_GIVEREF(__pyx_t_1);
- __pyx_t_1 = 0;
+ __pyx_t_4 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_k_28 = __pyx_t_4;
+ __Pyx_GIVEREF(__pyx_t_4);
+ __pyx_t_4 = 0;
- /* "mtrand.pyx":1513
+ /* "mtrand.pyx":1535
* return cont1_array(self.internal_state, rk_standard_gamma, size, oshape)
*
* def gamma(self, shape, scale=1.0, size=None): # <<<<<<<<<<<<<<
* """
* gamma(shape, scale=1.0, size=None)
*/
- __pyx_t_1 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_k_14 = __pyx_t_1;
- __Pyx_GIVEREF(__pyx_t_1);
- __pyx_t_1 = 0;
+ __pyx_t_4 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_k_34 = __pyx_t_4;
+ __Pyx_GIVEREF(__pyx_t_4);
+ __pyx_t_4 = 0;
- /* "mtrand.pyx":2529
+ /* "mtrand.pyx":2555
* return cont1_array(self.internal_state, rk_power, size, oa)
*
* def laplace(self, loc=0.0, scale=1.0, size=None): # <<<<<<<<<<<<<<
* """
* laplace(loc=0.0, scale=1.0, size=None)
*/
- __pyx_t_1 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2529; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_k_23 = __pyx_t_1;
- __Pyx_GIVEREF(__pyx_t_1);
- __pyx_t_1 = 0;
- __pyx_t_1 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2529; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_k_24 = __pyx_t_1;
- __Pyx_GIVEREF(__pyx_t_1);
- __pyx_t_1 = 0;
+ __pyx_t_4 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2555; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_k_73 = __pyx_t_4;
+ __Pyx_GIVEREF(__pyx_t_4);
+ __pyx_t_4 = 0;
+ __pyx_t_4 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2555; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_k_74 = __pyx_t_4;
+ __Pyx_GIVEREF(__pyx_t_4);
+ __pyx_t_4 = 0;
- /* "mtrand.pyx":2619
+ /* "mtrand.pyx":2645
* return cont2_array(self.internal_state, rk_laplace, size, oloc, oscale)
*
* def gumbel(self, loc=0.0, scale=1.0, size=None): # <<<<<<<<<<<<<<
* """
* gumbel(loc=0.0, scale=1.0, size=None)
*/
- __pyx_t_1 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2619; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_k_25 = __pyx_t_1;
- __Pyx_GIVEREF(__pyx_t_1);
- __pyx_t_1 = 0;
- __pyx_t_1 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2619; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_k_26 = __pyx_t_1;
- __Pyx_GIVEREF(__pyx_t_1);
- __pyx_t_1 = 0;
+ __pyx_t_4 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_k_77 = __pyx_t_4;
+ __Pyx_GIVEREF(__pyx_t_4);
+ __pyx_t_4 = 0;
+ __pyx_t_4 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_k_78 = __pyx_t_4;
+ __Pyx_GIVEREF(__pyx_t_4);
+ __pyx_t_4 = 0;
- /* "mtrand.pyx":2743
+ /* "mtrand.pyx":2776
* return cont2_array(self.internal_state, rk_gumbel, size, oloc, oscale)
*
* def logistic(self, loc=0.0, scale=1.0, size=None): # <<<<<<<<<<<<<<
* """
* logistic(loc=0.0, scale=1.0, size=None)
*/
- __pyx_t_1 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2743; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_k_27 = __pyx_t_1;
- __Pyx_GIVEREF(__pyx_t_1);
- __pyx_t_1 = 0;
- __pyx_t_1 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2743; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_k_28 = __pyx_t_1;
- __Pyx_GIVEREF(__pyx_t_1);
- __pyx_t_1 = 0;
+ __pyx_t_4 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_k_81 = __pyx_t_4;
+ __Pyx_GIVEREF(__pyx_t_4);
+ __pyx_t_4 = 0;
+ __pyx_t_4 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_k_82 = __pyx_t_4;
+ __Pyx_GIVEREF(__pyx_t_4);
+ __pyx_t_4 = 0;
- /* "mtrand.pyx":2831
+ /* "mtrand.pyx":2864
* return cont2_array(self.internal_state, rk_logistic, size, oloc, oscale)
*
* def lognormal(self, mean=0.0, sigma=1.0, size=None): # <<<<<<<<<<<<<<
* """
* lognormal(mean=0.0, sigma=1.0, size=None)
*/
- __pyx_t_1 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_k_29 = __pyx_t_1;
- __Pyx_GIVEREF(__pyx_t_1);
- __pyx_t_1 = 0;
- __pyx_t_1 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_k_30 = __pyx_t_1;
- __Pyx_GIVEREF(__pyx_t_1);
- __pyx_t_1 = 0;
+ __pyx_t_4 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2864; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_k_85 = __pyx_t_4;
+ __Pyx_GIVEREF(__pyx_t_4);
+ __pyx_t_4 = 0;
+ __pyx_t_4 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2864; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_k_86 = __pyx_t_4;
+ __Pyx_GIVEREF(__pyx_t_4);
+ __pyx_t_4 = 0;
- /* "mtrand.pyx":2962
+ /* "mtrand.pyx":2995
* return cont2_array(self.internal_state, rk_lognormal, size, omean, osigma)
*
* def rayleigh(self, scale=1.0, size=None): # <<<<<<<<<<<<<<
* """
* rayleigh(scale=1.0, size=None)
*/
- __pyx_t_1 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2962; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_k_33 = __pyx_t_1;
- __Pyx_GIVEREF(__pyx_t_1);
- __pyx_t_1 = 0;
+ __pyx_t_4 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_k_91 = __pyx_t_4;
+ __Pyx_GIVEREF(__pyx_t_4);
+ __pyx_t_4 = 0;
- /* "mtrand.pyx":3411
+ /* "mtrand.pyx":3444
* on, op)
*
* def poisson(self, lam=1.0, size=None): # <<<<<<<<<<<<<<
* """
* poisson(lam=1.0, size=None)
*/
- __pyx_t_1 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3411; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_k_43 = __pyx_t_1;
- __Pyx_GIVEREF(__pyx_t_1);
- __pyx_t_1 = 0;
+ __pyx_t_4 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_k_125 = __pyx_t_4;
+ __Pyx_GIVEREF(__pyx_t_4);
+ __pyx_t_4 = 0;
- /* "mtrand.pyx":4236
+ /* "mtrand.pyx":4329
* return arr
*
* _rand = RandomState() # <<<<<<<<<<<<<<
* seed = _rand.seed
* get_state = _rand.get_state
*/
- __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6mtrand_RandomState)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_1);
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s___rand, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6mtrand_RandomState)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s___rand, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "mtrand.pyx":4237
+ /* "mtrand.pyx":4330
*
* _rand = RandomState()
* seed = _rand.seed # <<<<<<<<<<<<<<
* get_state = _rand.get_state
* set_state = _rand.set_state
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__seed); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__seed); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__seed, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__seed, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4238
+ /* "mtrand.pyx":4331
* _rand = RandomState()
* seed = _rand.seed
* get_state = _rand.get_state # <<<<<<<<<<<<<<
* set_state = _rand.set_state
* random_sample = _rand.random_sample
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__get_state); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4331; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__get_state, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__get_state); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4331; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__get_state, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4331; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "mtrand.pyx":4239
+ /* "mtrand.pyx":4332
* seed = _rand.seed
* get_state = _rand.get_state
* set_state = _rand.set_state # <<<<<<<<<<<<<<
* random_sample = _rand.random_sample
* randint = _rand.randint
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__set_state); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__set_state); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__set_state, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__set_state, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4240
+ /* "mtrand.pyx":4333
* get_state = _rand.get_state
* set_state = _rand.set_state
* random_sample = _rand.random_sample # <<<<<<<<<<<<<<
* randint = _rand.randint
* bytes = _rand.bytes
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4240; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__random_sample); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4240; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__random_sample, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4240; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__random_sample); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__random_sample, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "mtrand.pyx":4241
+ /* "mtrand.pyx":4334
* set_state = _rand.set_state
* random_sample = _rand.random_sample
* randint = _rand.randint # <<<<<<<<<<<<<<
* bytes = _rand.bytes
* uniform = _rand.uniform
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__randint); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__randint); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__randint, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__randint, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4242
+ /* "mtrand.pyx":4335
* random_sample = _rand.random_sample
* randint = _rand.randint
* bytes = _rand.bytes # <<<<<<<<<<<<<<
* uniform = _rand.uniform
* rand = _rand.rand
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__bytes); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__bytes, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__bytes); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__bytes, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "mtrand.pyx":4243
+ /* "mtrand.pyx":4336
* randint = _rand.randint
* bytes = _rand.bytes
* uniform = _rand.uniform # <<<<<<<<<<<<<<
* rand = _rand.rand
* randn = _rand.randn
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4243; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__uniform); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__uniform); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4243; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__uniform, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__uniform, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4243; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4244
+ /* "mtrand.pyx":4337
* bytes = _rand.bytes
* uniform = _rand.uniform
* rand = _rand.rand # <<<<<<<<<<<<<<
* randn = _rand.randn
* random_integers = _rand.random_integers
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__rand, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__rand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__rand, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "mtrand.pyx":4245
+ /* "mtrand.pyx":4338
* uniform = _rand.uniform
* rand = _rand.rand
* randn = _rand.randn # <<<<<<<<<<<<<<
* random_integers = _rand.random_integers
* standard_normal = _rand.standard_normal
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__randn); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__randn); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__randn, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__randn, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4246
+ /* "mtrand.pyx":4339
* rand = _rand.rand
* randn = _rand.randn
* random_integers = _rand.random_integers # <<<<<<<<<<<<<<
* standard_normal = _rand.standard_normal
* normal = _rand.normal
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__random_integers); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__random_integers, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__random_integers); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__random_integers, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "mtrand.pyx":4247
+ /* "mtrand.pyx":4340
* randn = _rand.randn
* random_integers = _rand.random_integers
* standard_normal = _rand.standard_normal # <<<<<<<<<<<<<<
* normal = _rand.normal
* beta = _rand.beta
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__standard_normal); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__standard_normal); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__standard_normal, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__standard_normal, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4248
+ /* "mtrand.pyx":4341
* random_integers = _rand.random_integers
* standard_normal = _rand.standard_normal
* normal = _rand.normal # <<<<<<<<<<<<<<
* beta = _rand.beta
* exponential = _rand.exponential
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__normal); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__normal, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__normal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__normal, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "mtrand.pyx":4249
+ /* "mtrand.pyx":4342
* standard_normal = _rand.standard_normal
* normal = _rand.normal
* beta = _rand.beta # <<<<<<<<<<<<<<
* exponential = _rand.exponential
* standard_exponential = _rand.standard_exponential
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__beta); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__beta); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__beta, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__beta, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4250
+ /* "mtrand.pyx":4343
* normal = _rand.normal
* beta = _rand.beta
* exponential = _rand.exponential # <<<<<<<<<<<<<<
* standard_exponential = _rand.standard_exponential
* standard_gamma = _rand.standard_gamma
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__exponential); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__exponential, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__exponential); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__exponential, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "mtrand.pyx":4251
+ /* "mtrand.pyx":4344
* beta = _rand.beta
* exponential = _rand.exponential
* standard_exponential = _rand.standard_exponential # <<<<<<<<<<<<<<
* standard_gamma = _rand.standard_gamma
* gamma = _rand.gamma
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s_171); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s_59); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s_171, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s_59, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4252
+ /* "mtrand.pyx":4345
* exponential = _rand.exponential
* standard_exponential = _rand.standard_exponential
* standard_gamma = _rand.standard_gamma # <<<<<<<<<<<<<<
* gamma = _rand.gamma
* f = _rand.f
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4252; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__standard_gamma); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4252; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__standard_gamma, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4252; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__standard_gamma); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__standard_gamma, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "mtrand.pyx":4253
+ /* "mtrand.pyx":4346
* standard_exponential = _rand.standard_exponential
* standard_gamma = _rand.standard_gamma
* gamma = _rand.gamma # <<<<<<<<<<<<<<
* f = _rand.f
* noncentral_f = _rand.noncentral_f
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__gamma); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__gamma); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__gamma, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__gamma, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4254
+ /* "mtrand.pyx":4347
* standard_gamma = _rand.standard_gamma
* gamma = _rand.gamma
* f = _rand.f # <<<<<<<<<<<<<<
* noncentral_f = _rand.noncentral_f
* chisquare = _rand.chisquare
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__f, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__f); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__f, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "mtrand.pyx":4255
+ /* "mtrand.pyx":4348
* gamma = _rand.gamma
* f = _rand.f
* noncentral_f = _rand.noncentral_f # <<<<<<<<<<<<<<
* chisquare = _rand.chisquare
* noncentral_chisquare = _rand.noncentral_chisquare
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__noncentral_f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__noncentral_f); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__noncentral_f, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__noncentral_f, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4256
+ /* "mtrand.pyx":4349
* f = _rand.f
* noncentral_f = _rand.noncentral_f
* chisquare = _rand.chisquare # <<<<<<<<<<<<<<
* noncentral_chisquare = _rand.noncentral_chisquare
* standard_cauchy = _rand.standard_cauchy
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__chisquare); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__chisquare, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__chisquare); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__chisquare, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "mtrand.pyx":4257
+ /* "mtrand.pyx":4350
* noncentral_f = _rand.noncentral_f
* chisquare = _rand.chisquare
* noncentral_chisquare = _rand.noncentral_chisquare # <<<<<<<<<<<<<<
* standard_cauchy = _rand.standard_cauchy
* standard_t = _rand.standard_t
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s_172); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s_60); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s_172, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s_60, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4258
+ /* "mtrand.pyx":4351
* chisquare = _rand.chisquare
* noncentral_chisquare = _rand.noncentral_chisquare
* standard_cauchy = _rand.standard_cauchy # <<<<<<<<<<<<<<
* standard_t = _rand.standard_t
* vonmises = _rand.vonmises
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__standard_cauchy); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__standard_cauchy, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__standard_cauchy); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__standard_cauchy, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "mtrand.pyx":4259
+ /* "mtrand.pyx":4352
* noncentral_chisquare = _rand.noncentral_chisquare
* standard_cauchy = _rand.standard_cauchy
* standard_t = _rand.standard_t # <<<<<<<<<<<<<<
* vonmises = _rand.vonmises
* pareto = _rand.pareto
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__standard_t); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__standard_t); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__standard_t, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__standard_t, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4260
+ /* "mtrand.pyx":4353
* standard_cauchy = _rand.standard_cauchy
* standard_t = _rand.standard_t
* vonmises = _rand.vonmises # <<<<<<<<<<<<<<
* pareto = _rand.pareto
* weibull = _rand.weibull
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__vonmises); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__vonmises, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__vonmises); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__vonmises, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "mtrand.pyx":4261
+ /* "mtrand.pyx":4354
* standard_t = _rand.standard_t
* vonmises = _rand.vonmises
* pareto = _rand.pareto # <<<<<<<<<<<<<<
* weibull = _rand.weibull
* power = _rand.power
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__pareto); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__pareto); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__pareto, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__pareto, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4262
+ /* "mtrand.pyx":4355
* vonmises = _rand.vonmises
* pareto = _rand.pareto
* weibull = _rand.weibull # <<<<<<<<<<<<<<
* power = _rand.power
* laplace = _rand.laplace
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__weibull); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__weibull, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__weibull); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__weibull, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "mtrand.pyx":4263
+ /* "mtrand.pyx":4356
* pareto = _rand.pareto
* weibull = _rand.weibull
* power = _rand.power # <<<<<<<<<<<<<<
* laplace = _rand.laplace
* gumbel = _rand.gumbel
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4263; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__power); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__power); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4263; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__power, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__power, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4263; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4264
+ /* "mtrand.pyx":4357
* weibull = _rand.weibull
* power = _rand.power
* laplace = _rand.laplace # <<<<<<<<<<<<<<
* gumbel = _rand.gumbel
* logistic = _rand.logistic
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__laplace); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__laplace, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__laplace); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__laplace, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "mtrand.pyx":4265
+ /* "mtrand.pyx":4358
* power = _rand.power
* laplace = _rand.laplace
* gumbel = _rand.gumbel # <<<<<<<<<<<<<<
* logistic = _rand.logistic
* lognormal = _rand.lognormal
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__gumbel); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__gumbel); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__gumbel, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__gumbel, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4266
+ /* "mtrand.pyx":4359
* laplace = _rand.laplace
* gumbel = _rand.gumbel
* logistic = _rand.logistic # <<<<<<<<<<<<<<
* lognormal = _rand.lognormal
* rayleigh = _rand.rayleigh
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__logistic); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__logistic, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__logistic); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__logistic, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "mtrand.pyx":4267
+ /* "mtrand.pyx":4360
* gumbel = _rand.gumbel
* logistic = _rand.logistic
* lognormal = _rand.lognormal # <<<<<<<<<<<<<<
* rayleigh = _rand.rayleigh
* wald = _rand.wald
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__lognormal); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__lognormal); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__lognormal, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__lognormal, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4268
+ /* "mtrand.pyx":4361
* logistic = _rand.logistic
* lognormal = _rand.lognormal
* rayleigh = _rand.rayleigh # <<<<<<<<<<<<<<
* wald = _rand.wald
* triangular = _rand.triangular
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__rayleigh); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__rayleigh, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__rayleigh); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__rayleigh, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "mtrand.pyx":4269
+ /* "mtrand.pyx":4362
* lognormal = _rand.lognormal
* rayleigh = _rand.rayleigh
* wald = _rand.wald # <<<<<<<<<<<<<<
* triangular = _rand.triangular
*
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__wald); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__wald); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__wald, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__wald, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4270
+ /* "mtrand.pyx":4363
* rayleigh = _rand.rayleigh
* wald = _rand.wald
* triangular = _rand.triangular # <<<<<<<<<<<<<<
*
* binomial = _rand.binomial
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__triangular); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__triangular, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__triangular); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__triangular, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "mtrand.pyx":4272
+ /* "mtrand.pyx":4365
* triangular = _rand.triangular
*
* binomial = _rand.binomial # <<<<<<<<<<<<<<
* negative_binomial = _rand.negative_binomial
* poisson = _rand.poisson
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4272; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__binomial); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__binomial); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4272; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__binomial, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__binomial, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4272; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4273
+ /* "mtrand.pyx":4366
*
* binomial = _rand.binomial
* negative_binomial = _rand.negative_binomial # <<<<<<<<<<<<<<
* poisson = _rand.poisson
* zipf = _rand.zipf
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__negative_binomial); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__negative_binomial, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__negative_binomial); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__negative_binomial, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "mtrand.pyx":4274
+ /* "mtrand.pyx":4367
* binomial = _rand.binomial
* negative_binomial = _rand.negative_binomial
* poisson = _rand.poisson # <<<<<<<<<<<<<<
* zipf = _rand.zipf
* geometric = _rand.geometric
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__poisson); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__poisson); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__poisson, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__poisson, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4275
+ /* "mtrand.pyx":4368
* negative_binomial = _rand.negative_binomial
* poisson = _rand.poisson
* zipf = _rand.zipf # <<<<<<<<<<<<<<
* geometric = _rand.geometric
* hypergeometric = _rand.hypergeometric
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__zipf); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__zipf, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__zipf); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__zipf, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "mtrand.pyx":4276
+ /* "mtrand.pyx":4369
* poisson = _rand.poisson
* zipf = _rand.zipf
* geometric = _rand.geometric # <<<<<<<<<<<<<<
* hypergeometric = _rand.hypergeometric
* logseries = _rand.logseries
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__geometric); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__geometric); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__geometric, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__geometric, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4277
+ /* "mtrand.pyx":4370
* zipf = _rand.zipf
* geometric = _rand.geometric
* hypergeometric = _rand.hypergeometric # <<<<<<<<<<<<<<
* logseries = _rand.logseries
*
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4277; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__hypergeometric); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4277; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__hypergeometric, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4277; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__hypergeometric); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__hypergeometric, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "mtrand.pyx":4278
+ /* "mtrand.pyx":4371
* geometric = _rand.geometric
* hypergeometric = _rand.hypergeometric
* logseries = _rand.logseries # <<<<<<<<<<<<<<
*
* multivariate_normal = _rand.multivariate_normal
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__logseries); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__logseries); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__logseries, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__logseries, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4280
+ /* "mtrand.pyx":4373
* logseries = _rand.logseries
*
* multivariate_normal = _rand.multivariate_normal # <<<<<<<<<<<<<<
* multinomial = _rand.multinomial
* dirichlet = _rand.dirichlet
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__multivariate_normal); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__multivariate_normal, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__multivariate_normal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__multivariate_normal, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "mtrand.pyx":4281
+ /* "mtrand.pyx":4374
*
* multivariate_normal = _rand.multivariate_normal
* multinomial = _rand.multinomial # <<<<<<<<<<<<<<
* dirichlet = _rand.dirichlet
*
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4281; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__multinomial); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__multinomial); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4281; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__multinomial, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__multinomial, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4281; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4282
+ /* "mtrand.pyx":4375
* multivariate_normal = _rand.multivariate_normal
* multinomial = _rand.multinomial
* dirichlet = _rand.dirichlet # <<<<<<<<<<<<<<
*
* shuffle = _rand.shuffle
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__dirichlet); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__dirichlet, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__dirichlet); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__dirichlet, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "mtrand.pyx":4284
+ /* "mtrand.pyx":4377
* dirichlet = _rand.dirichlet
*
* shuffle = _rand.shuffle # <<<<<<<<<<<<<<
* permutation = _rand.permutation
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4284; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__shuffle); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__shuffle); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4284; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__shuffle, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__shuffle, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4284; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "mtrand.pyx":4285
+ /* "mtrand.pyx":4378
*
* shuffle = _rand.shuffle
* permutation = _rand.permutation # <<<<<<<<<<<<<<
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__permutation); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___rand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__permutation, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__permutation); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__permutation, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "mtrand.pyx":1
* # mtrand.pyx -- A Pyrex wrapper of Jean-Sebastien Roy's RandomKit # <<<<<<<<<<<<<<
* #
* # Copyright 2005 Robert Kern (robert.kern@gmail.com)
*/
- __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(((PyObject *)__pyx_t_1));
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__seed); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_61), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__get_state); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_62), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__set_state); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_63), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__random_sample); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_64), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__tomaxint); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_65), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__randint); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_66), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__bytes); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_67), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__uniform); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_68), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__rand); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_69), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__randn); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_70), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__random_integers); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_71), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__standard_normal); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_72), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__normal); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_73), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__beta); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_74), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__exponential); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_75), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s_59); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_76), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__standard_gamma); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_77), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__gamma); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_78), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__f); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_79), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__noncentral_f); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_80), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__chisquare); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_81), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s_60); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_82), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__standard_cauchy); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_83), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__standard_t); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_84), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__vonmises); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_85), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__pareto); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_86), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__weibull); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_87), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__power); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_88), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__laplace); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_89), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__gumbel); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_90), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__logistic); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_91), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__lognormal); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_92), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__rayleigh); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_93), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__wald); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_94), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__triangular); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_95), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__binomial); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_96), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__negative_binomial); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_97), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__poisson); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_98), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__zipf); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_99), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__geometric); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_100), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__hypergeometric); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_101), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__logseries); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_102), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__multivariate_normal); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_103), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__multinomial); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_104), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__dirichlet); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_105), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__shuffle); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_106), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__RandomState); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__permutation); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __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_GetAttrString(__pyx_t_3, "__doc__");
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_107), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+ __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_173), ((PyObject *)__pyx_kp_u_174)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_175), ((PyObject *)__pyx_kp_u_176)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_177), ((PyObject *)__pyx_kp_u_178)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_179), ((PyObject *)__pyx_kp_u_180)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_181), ((PyObject *)__pyx_kp_u_182)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_183), ((PyObject *)__pyx_kp_u_184)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_185), ((PyObject *)__pyx_kp_u_186)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_187), ((PyObject *)__pyx_kp_u_188)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_189), ((PyObject *)__pyx_kp_u_190)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_191), ((PyObject *)__pyx_kp_u_192)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_193), ((PyObject *)__pyx_kp_u_194)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_195), ((PyObject *)__pyx_kp_u_196)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_197), ((PyObject *)__pyx_kp_u_198)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_199), ((PyObject *)__pyx_kp_u_200)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_201), ((PyObject *)__pyx_kp_u_202)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_203), ((PyObject *)__pyx_kp_u_204)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_205), ((PyObject *)__pyx_kp_u_206)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_207), ((PyObject *)__pyx_kp_u_208)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_209), ((PyObject *)__pyx_kp_u_210)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_211), ((PyObject *)__pyx_kp_u_212)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_213), ((PyObject *)__pyx_kp_u_214)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_215), ((PyObject *)__pyx_kp_u_216)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_217), ((PyObject *)__pyx_kp_u_218)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_219), ((PyObject *)__pyx_kp_u_220)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_221), ((PyObject *)__pyx_kp_u_222)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_223), ((PyObject *)__pyx_kp_u_224)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_225), ((PyObject *)__pyx_kp_u_226)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_227), ((PyObject *)__pyx_kp_u_228)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_229), ((PyObject *)__pyx_kp_u_230)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_231), ((PyObject *)__pyx_kp_u_232)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_233), ((PyObject *)__pyx_kp_u_234)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_235), ((PyObject *)__pyx_kp_u_236)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_237), ((PyObject *)__pyx_kp_u_238)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_239), ((PyObject *)__pyx_kp_u_240)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_241), ((PyObject *)__pyx_kp_u_242)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_243), ((PyObject *)__pyx_kp_u_244)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_245), ((PyObject *)__pyx_kp_u_246)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_247), ((PyObject *)__pyx_kp_u_248)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_249), ((PyObject *)__pyx_kp_u_250)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_251), ((PyObject *)__pyx_kp_u_252)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_253), ((PyObject *)__pyx_kp_u_254)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_255), ((PyObject *)__pyx_kp_u_256)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_4)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
+ __Pyx_XDECREF(__pyx_t_4);
if (__pyx_m) {
__Pyx_AddTraceback("init mtrand");
Py_DECREF(__pyx_m); __pyx_m = 0;
@@ -20831,16 +21447,152 @@ PyMODINIT_FUNC PyInit_mtrand(void)
#endif
}
-static const char *__pyx_filenames[] = {
- "mtrand.pyx",
- "numpy.pxi",
-};
-
/* Runtime support code */
-static void __pyx_init_filenames(void) {
- __pyx_f = __pyx_filenames;
+static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
+ PyObject *result;
+ result = PyObject_GetAttr(dict, name);
+ if (!result)
+ PyErr_SetObject(PyExc_NameError, name);
+ return result;
+}
+
+static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
+ PyObject *tmp_type, *tmp_value, *tmp_tb;
+ PyThreadState *tstate = PyThreadState_GET();
+
+ tmp_type = tstate->curexc_type;
+ tmp_value = tstate->curexc_value;
+ tmp_tb = tstate->curexc_traceback;
+ tstate->curexc_type = type;
+ tstate->curexc_value = value;
+ tstate->curexc_traceback = tb;
+ Py_XDECREF(tmp_type);
+ Py_XDECREF(tmp_value);
+ Py_XDECREF(tmp_tb);
+}
+
+static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
+ PyThreadState *tstate = PyThreadState_GET();
+ *type = tstate->curexc_type;
+ *value = tstate->curexc_value;
+ *tb = tstate->curexc_traceback;
+
+ tstate->curexc_type = 0;
+ tstate->curexc_value = 0;
+ tstate->curexc_traceback = 0;
+}
+
+
+#if PY_MAJOR_VERSION < 3
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
+ Py_XINCREF(type);
+ Py_XINCREF(value);
+ Py_XINCREF(tb);
+ /* First, check the traceback argument, replacing None with NULL. */
+ if (tb == Py_None) {
+ Py_DECREF(tb);
+ tb = 0;
+ }
+ else if (tb != NULL && !PyTraceBack_Check(tb)) {
+ PyErr_SetString(PyExc_TypeError,
+ "raise: arg 3 must be a traceback or None");
+ goto raise_error;
+ }
+ /* Next, replace a missing value with None */
+ if (value == NULL) {
+ value = Py_None;
+ Py_INCREF(value);
+ }
+ #if PY_VERSION_HEX < 0x02050000
+ if (!PyClass_Check(type))
+ #else
+ if (!PyType_Check(type))
+ #endif
+ {
+ /* Raising an instance. The value should be a dummy. */
+ if (value != Py_None) {
+ PyErr_SetString(PyExc_TypeError,
+ "instance exception may not have a separate value");
+ goto raise_error;
+ }
+ /* Normalize to raise <class>, <instance> */
+ Py_DECREF(value);
+ value = type;
+ #if PY_VERSION_HEX < 0x02050000
+ if (PyInstance_Check(type)) {
+ type = (PyObject*) ((PyInstanceObject*)type)->in_class;
+ Py_INCREF(type);
+ }
+ else {
+ type = 0;
+ PyErr_SetString(PyExc_TypeError,
+ "raise: exception must be an old-style class or instance");
+ goto raise_error;
+ }
+ #else
+ type = (PyObject*) Py_TYPE(type);
+ Py_INCREF(type);
+ if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
+ PyErr_SetString(PyExc_TypeError,
+ "raise: exception class must be a subclass of BaseException");
+ goto raise_error;
+ }
+ #endif
+ }
+
+ __Pyx_ErrRestore(type, value, tb);
+ return;
+raise_error:
+ Py_XDECREF(value);
+ Py_XDECREF(type);
+ Py_XDECREF(tb);
+ return;
+}
+
+#else /* Python 3+ */
+
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
+ if (tb == Py_None) {
+ tb = 0;
+ } else if (tb && !PyTraceBack_Check(tb)) {
+ PyErr_SetString(PyExc_TypeError,
+ "raise: arg 3 must be a traceback or None");
+ goto bad;
+ }
+ if (value == Py_None)
+ value = 0;
+
+ if (PyExceptionInstance_Check(type)) {
+ if (value) {
+ PyErr_SetString(PyExc_TypeError,
+ "instance exception may not have a separate value");
+ goto bad;
+ }
+ value = type;
+ type = (PyObject*) Py_TYPE(value);
+ } else if (!PyExceptionClass_Check(type)) {
+ PyErr_SetString(PyExc_TypeError,
+ "raise: exception class must be a subclass of BaseException");
+ goto bad;
+ }
+
+ PyErr_SetObject(type, value);
+
+ if (tb) {
+ PyThreadState *tstate = PyThreadState_GET();
+ PyObject* tmp_tb = tstate->curexc_traceback;
+ if (tb != tmp_tb) {
+ Py_INCREF(tb);
+ tstate->curexc_traceback = tb;
+ Py_XDECREF(tmp_tb);
+ }
+ }
+
+bad:
+ return;
}
+#endif
static void __Pyx_RaiseDoubleKeywordsError(
const char* func_name,
@@ -20855,36 +21607,6 @@ static void __Pyx_RaiseDoubleKeywordsError(
#endif
}
-static void __Pyx_RaiseArgtupleInvalid(
- const char* func_name,
- int exact,
- Py_ssize_t num_min,
- Py_ssize_t num_max,
- Py_ssize_t num_found)
-{
- Py_ssize_t num_expected;
- const char *number, *more_or_less;
-
- if (num_found < num_min) {
- num_expected = num_min;
- more_or_less = "at least";
- } else {
- num_expected = num_max;
- more_or_less = "at most";
- }
- if (exact) {
- more_or_less = "exactly";
- }
- number = (num_expected == 1) ? "" : "s";
- PyErr_Format(PyExc_TypeError,
- #if PY_VERSION_HEX < 0x02050000
- "%s() takes %s %d positional argument%s (%d given)",
- #else
- "%s() takes %s %zd positional argument%s (%zd given)",
- #endif
- func_name, more_or_less, num_expected, number, num_found);
-}
-
static int __Pyx_ParseOptionalKeywords(
PyObject *kwds,
PyObject **argnames[],
@@ -20964,6 +21686,36 @@ bad:
return -1;
}
+static void __Pyx_RaiseArgtupleInvalid(
+ const char* func_name,
+ int exact,
+ Py_ssize_t num_min,
+ Py_ssize_t num_max,
+ Py_ssize_t num_found)
+{
+ Py_ssize_t num_expected;
+ const char *number, *more_or_less;
+
+ if (num_found < num_min) {
+ num_expected = num_min;
+ more_or_less = "at least";
+ } else {
+ num_expected = num_max;
+ more_or_less = "at most";
+ }
+ if (exact) {
+ more_or_less = "exactly";
+ }
+ number = (num_expected == 1) ? "" : "s";
+ PyErr_Format(PyExc_TypeError,
+ #if PY_VERSION_HEX < 0x02050000
+ "%s() takes %s %d positional argument%s (%d given)",
+ #else
+ "%s() takes %s %zd positional argument%s (%zd given)",
+ #endif
+ func_name, more_or_less, num_expected, number, num_found);
+}
+
static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
PyErr_Format(PyExc_ValueError,
@@ -20975,8 +21727,13 @@ static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
(index == 1) ? "" : "s");
}
-static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(void) {
- PyErr_SetString(PyExc_ValueError, "too many values to unpack");
+static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
+ PyErr_Format(PyExc_ValueError,
+ #if PY_VERSION_HEX < 0x02050000
+ "too many values to unpack (expected %d)", (int)expected);
+ #else
+ "too many values to unpack (expected %zd)", expected);
+ #endif
}
static PyObject *__Pyx_UnpackItem(PyObject *iter, Py_ssize_t index) {
@@ -20989,11 +21746,11 @@ static PyObject *__Pyx_UnpackItem(PyObject *iter, Py_ssize_t index) {
return item;
}
-static int __Pyx_EndUnpack(PyObject *iter) {
+static int __Pyx_EndUnpack(PyObject *iter, Py_ssize_t expected) {
PyObject *item;
if ((item = PyIter_Next(iter))) {
Py_DECREF(item);
- __Pyx_RaiseTooManyValuesError();
+ __Pyx_RaiseTooManyValuesError(expected);
return -1;
}
else if (!PyErr_Occurred())
@@ -21120,14 +21877,14 @@ static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb)
}
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
- PyObject *__import__ = 0;
+ PyObject *py_import = 0;
PyObject *empty_list = 0;
PyObject *module = 0;
PyObject *global_dict = 0;
PyObject *empty_dict = 0;
PyObject *list;
- __import__ = __Pyx_GetAttrString(__pyx_b, "__import__");
- if (!__import__)
+ py_import = __Pyx_GetAttrString(__pyx_b, "__import__");
+ if (!py_import)
goto bad;
if (from_list)
list = from_list;
@@ -21143,160 +21900,15 @@ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
empty_dict = PyDict_New();
if (!empty_dict)
goto bad;
- module = PyObject_CallFunctionObjArgs(__import__,
+ module = PyObject_CallFunctionObjArgs(py_import,
name, global_dict, empty_dict, list, NULL);
bad:
Py_XDECREF(empty_list);
- Py_XDECREF(__import__);
+ Py_XDECREF(py_import);
Py_XDECREF(empty_dict);
return module;
}
-static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
- PyObject *result;
- result = PyObject_GetAttr(dict, name);
- if (!result)
- PyErr_SetObject(PyExc_NameError, name);
- return result;
-}
-
-static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
- PyObject *tmp_type, *tmp_value, *tmp_tb;
- PyThreadState *tstate = PyThreadState_GET();
-
- tmp_type = tstate->curexc_type;
- tmp_value = tstate->curexc_value;
- tmp_tb = tstate->curexc_traceback;
- tstate->curexc_type = type;
- tstate->curexc_value = value;
- tstate->curexc_traceback = tb;
- Py_XDECREF(tmp_type);
- Py_XDECREF(tmp_value);
- Py_XDECREF(tmp_tb);
-}
-
-static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
- PyThreadState *tstate = PyThreadState_GET();
- *type = tstate->curexc_type;
- *value = tstate->curexc_value;
- *tb = tstate->curexc_traceback;
-
- tstate->curexc_type = 0;
- tstate->curexc_value = 0;
- tstate->curexc_traceback = 0;
-}
-
-
-#if PY_MAJOR_VERSION < 3
-static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
- Py_XINCREF(type);
- Py_XINCREF(value);
- Py_XINCREF(tb);
- /* First, check the traceback argument, replacing None with NULL. */
- if (tb == Py_None) {
- Py_DECREF(tb);
- tb = 0;
- }
- else if (tb != NULL && !PyTraceBack_Check(tb)) {
- PyErr_SetString(PyExc_TypeError,
- "raise: arg 3 must be a traceback or None");
- goto raise_error;
- }
- /* Next, replace a missing value with None */
- if (value == NULL) {
- value = Py_None;
- Py_INCREF(value);
- }
- #if PY_VERSION_HEX < 0x02050000
- if (!PyClass_Check(type))
- #else
- if (!PyType_Check(type))
- #endif
- {
- /* Raising an instance. The value should be a dummy. */
- if (value != Py_None) {
- PyErr_SetString(PyExc_TypeError,
- "instance exception may not have a separate value");
- goto raise_error;
- }
- /* Normalize to raise <class>, <instance> */
- Py_DECREF(value);
- value = type;
- #if PY_VERSION_HEX < 0x02050000
- if (PyInstance_Check(type)) {
- type = (PyObject*) ((PyInstanceObject*)type)->in_class;
- Py_INCREF(type);
- }
- else {
- type = 0;
- PyErr_SetString(PyExc_TypeError,
- "raise: exception must be an old-style class or instance");
- goto raise_error;
- }
- #else
- type = (PyObject*) Py_TYPE(type);
- Py_INCREF(type);
- if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
- PyErr_SetString(PyExc_TypeError,
- "raise: exception class must be a subclass of BaseException");
- goto raise_error;
- }
- #endif
- }
-
- __Pyx_ErrRestore(type, value, tb);
- return;
-raise_error:
- Py_XDECREF(value);
- Py_XDECREF(type);
- Py_XDECREF(tb);
- return;
-}
-
-#else /* Python 3+ */
-
-static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
- if (tb == Py_None) {
- tb = 0;
- } else if (tb && !PyTraceBack_Check(tb)) {
- PyErr_SetString(PyExc_TypeError,
- "raise: arg 3 must be a traceback or None");
- goto bad;
- }
- if (value == Py_None)
- value = 0;
-
- if (PyExceptionInstance_Check(type)) {
- if (value) {
- PyErr_SetString(PyExc_TypeError,
- "instance exception may not have a separate value");
- goto bad;
- }
- value = type;
- type = (PyObject*) Py_TYPE(value);
- } else if (!PyExceptionClass_Check(type)) {
- PyErr_SetString(PyExc_TypeError,
- "raise: exception class must be a subclass of BaseException");
- goto bad;
- }
-
- PyErr_SetObject(type, value);
-
- if (tb) {
- PyThreadState *tstate = PyThreadState_GET();
- PyObject* tmp_tb = tstate->curexc_traceback;
- if (tb != tmp_tb) {
- Py_INCREF(tb);
- tstate->curexc_traceback = tb;
- Py_XDECREF(tmp_tb);
- }
- }
-
-bad:
- return;
-}
-#endif
-
static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
const unsigned char neg_one = (unsigned char)-1, const_zero = 0;
const int is_unsigned = neg_one > const_zero;
@@ -21468,6 +22080,25 @@ static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
return (signed int)__Pyx_PyInt_AsSignedLong(x);
}
+static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) {
+ const int neg_one = (int)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(int) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(int)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to int" :
+ "value too large to convert to int");
+ }
+ return (int)-1;
+ }
+ return (int)val;
+ }
+ return (int)__Pyx_PyInt_AsLong(x);
+}
+
static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
const unsigned long neg_one = (unsigned long)-1, const_zero = 0;
const int is_unsigned = neg_one > const_zero;
@@ -21706,19 +22337,23 @@ static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class
if (!result)
goto bad;
if (!PyType_Check(result)) {
- PyErr_Format(PyExc_TypeError,
+ PyErr_Format(PyExc_TypeError,
"%s.%s is not a type object",
module_name, class_name);
goto bad;
}
if (!strict && ((PyTypeObject *)result)->tp_basicsize > size) {
- PyOS_snprintf(warning, sizeof(warning),
+ PyOS_snprintf(warning, sizeof(warning),
"%s.%s size changed, may indicate binary incompatibility",
module_name, class_name);
+ #if PY_VERSION_HEX < 0x02050000
+ PyErr_Warn(NULL, warning);
+ #else
PyErr_WarnEx(NULL, warning, 0);
+ #endif
}
else if (((PyTypeObject *)result)->tp_basicsize != size) {
- PyErr_Format(PyExc_ValueError,
+ PyErr_Format(PyExc_ValueError,
"%s.%s has the wrong size, try recompiling",
module_name, class_name);
goto bad;
@@ -21856,8 +22491,8 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
/* Type Conversion Functions */
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
- if (x == Py_True) return 1;
- else if ((x == Py_False) | (x == Py_None)) return 0;
+ int is_true = x == Py_True;
+ if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
else return PyObject_IsTrue(x);
}
diff --git a/numpy/random/mtrand/mtrand.pyx b/numpy/random/mtrand/mtrand.pyx
index f3caac14b..13c743cd3 100644
--- a/numpy/random/mtrand/mtrand.pyx
+++ b/numpy/random/mtrand/mtrand.pyx
@@ -553,6 +553,7 @@ cdef class RandomState:
"""
cdef rk_state *internal_state
+ poisson_lam_max = np.iinfo('l').max - np.sqrt(np.iinfo('l').max)*10
def __init__(self, seed=None):
self.internal_state = <rk_state*>PyMem_Malloc(sizeof(rk_state))
@@ -855,7 +856,8 @@ cdef class RandomState:
[3, 2, 2, 0]])
"""
- cdef long lo, hi, diff
+ cdef long lo, hi, rv
+ cdef unsigned long diff
cdef long *array_data
cdef ndarray array "arrayObject"
cdef long length
@@ -868,18 +870,20 @@ cdef class RandomState:
lo = low
hi = high
- diff = hi - lo - 1
- if diff < 0:
+ if lo >= hi :
raise ValueError("low >= high")
+ diff = <unsigned long>hi - <unsigned long>lo - 1UL
if size is None:
- return <long>rk_interval(diff, self.internal_state) + lo
+ rv = lo + <long>rk_interval(diff, self. internal_state)
+ return rv
else:
array = <ndarray>np.empty(size, int)
length = PyArray_SIZE(array)
array_data = <long *>array.data
for i from 0 <= i < length:
- array_data[i] = lo + <long>rk_interval(diff, self.internal_state)
+ rv = lo + <long>rk_interval(diff, self. internal_state)
+ array_data[i] = rv
return array
def bytes(self, unsigned int length):
@@ -896,7 +900,7 @@ cdef class RandomState:
Returns
-------
out : str
- String of length `N`.
+ String of length `length`.
Examples
--------
@@ -928,7 +932,7 @@ cdef class RandomState:
high : float
Upper boundary of the output interval. All values generated will be
less than high. The default value is 1.0.
- size : tuple of ints, int, optional
+ size : int or tuple of ints, optional
Shape of output. If the given size is, for example, (m,n,k),
m*n*k samples are generated. If no shape is specified, a single sample
is returned.
@@ -941,13 +945,13 @@ cdef class RandomState:
See Also
--------
randint : Discrete uniform distribution, yielding integers.
- random_integers : Discrete uniform distribution over the closed interval
- ``[low, high]``.
+ random_integers : Discrete uniform distribution over the closed
+ interval ``[low, high]``.
random_sample : Floats uniformly distributed over ``[0, 1)``.
random : Alias for `random_sample`.
rand : Convenience function that accepts dimensions as input, e.g.,
- ``rand(2,2)`` would generate a 2-by-2 array of floats, uniformly
- distributed over ``[0, 1)``.
+ ``rand(2,2)`` would generate a 2-by-2 array of floats,
+ uniformly distributed over ``[0, 1)``.
Notes
-----
@@ -967,7 +971,6 @@ cdef class RandomState:
>>> np.all(s >= -1)
True
-
>>> np.all(s < 0)
True
@@ -2248,11 +2251,16 @@ cdef class RandomState:
"""
pareto(a, size=None)
- Draw samples from a Pareto distribution with specified shape.
+ Draw samples from a Pareto II or Lomax distribution with specified shape.
- This is a simplified version of the Generalized Pareto distribution
- (available in SciPy), with the scale set to one and the location set to
- zero. Most authors default the location to one.
+ The Lomax or Pareto II distribution is a shifted Pareto distribution. The
+ classical Pareto distribution can be obtained from the Lomax distribution
+ by adding the location parameter m, see below. The smallest value of the
+ Lomax distribution is zero while for the classical Pareto distribution it
+ is m, where the standard Pareto distribution has location m=1.
+ Lomax can also be considered as a simplified version of the Generalized
+ Pareto distribution (available in SciPy), with the scale set to one and
+ the location set to zero.
The Pareto distribution must be greater than zero, and is unbounded above.
It is also known as the "80-20 rule". In this distribution, 80 percent of
@@ -2269,6 +2277,8 @@ cdef class RandomState:
See Also
--------
+ scipy.stats.distributions.lomax.pdf : probability density function,
+ distribution or cumulative density function, etc.
scipy.stats.distributions.genpareto.pdf : probability density function,
distribution or cumulative density function, etc.
@@ -2340,7 +2350,7 @@ cdef class RandomState:
Weibull distribution.
Draw samples from a 1-parameter Weibull distribution with the given
- shape parameter.
+ shape parameter `a`.
.. math:: X = (-ln(U))^{1/a}
@@ -2349,11 +2359,6 @@ cdef class RandomState:
The more common 2-parameter Weibull, including a scale parameter
:math:`\\lambda` is just :math:`X = \\lambda(-ln(U))^{1/a}`.
- The Weibull (or Type III asymptotic extreme value distribution for smallest
- values, SEV Type III, or Rosin-Rammler distribution) is one of a class of
- Generalized Extreme Value (GEV) distributions used in modeling extreme
- value problems. This class includes the Gumbel and Frechet distributions.
-
Parameters
----------
a : float
@@ -2371,6 +2376,11 @@ cdef class RandomState:
Notes
-----
+ The Weibull (or Type III asymptotic extreme value distribution for smallest
+ values, SEV Type III, or Rosin-Rammler distribution) is one of a class of
+ Generalized Extreme Value (GEV) distributions used in modeling extreme
+ value problems. This class includes the Gumbel and Frechet distributions.
+
The probability density for the Weibull distribution is
.. math:: p(x) = \\frac{a}
@@ -2638,16 +2648,9 @@ cdef class RandomState:
Gumbel distribution.
- Draw samples from a Gumbel distribution with specified location (or mean)
- and scale (or standard deviation).
-
- The Gumbel (or Smallest Extreme Value (SEV) or the Smallest Extreme Value
- Type I) distribution is one of a class of Generalized Extreme Value (GEV)
- distributions used in modeling extreme value problems. The Gumbel is a
- special case of the Extreme Value Type I distribution for maximums from
- distributions with "exponential-like" tails, it may be derived by
- considering a Gaussian process of measurements, and generating the pdf for
- the maximum values from that set of measurements (see examples).
+ Draw samples from a Gumbel distribution with specified location and scale.
+ For more information on the Gumbel distribution, see Notes and References
+ below.
Parameters
----------
@@ -2659,21 +2662,35 @@ cdef class RandomState:
Output shape. If the given shape is, e.g., ``(m, n, k)``, then
``m * n * k`` samples are drawn.
+ Returns
+ -------
+ out : ndarray
+ The samples
+
See Also
--------
- scipy.stats.gumbel : probability density function,
- distribution or cumulative density function, etc.
- weibull, scipy.stats.genextreme
+ scipy.stats.gumbel_l
+ scipy.stats.gumbel_r
+ scipy.stats.genextreme
+ probability density function, distribution, or cumulative density
+ function, etc. for each of the above
+ weibull
Notes
-----
+ The Gumbel (or Smallest Extreme Value (SEV) or the Smallest Extreme Value
+ Type I) distribution is one of a class of Generalized Extreme Value (GEV)
+ distributions used in modeling extreme value problems. The Gumbel is a
+ special case of the Extreme Value Type I distribution for maximums from
+ distributions with "exponential-like" tails.
+
The probability density for the Gumbel distribution is
.. math:: p(x) = \\frac{e^{-(x - \\mu)/ \\beta}}{\\beta} e^{ -e^{-(x - \\mu)/
\\beta}},
- where :math:`\\mu` is the mode, a location parameter, and :math:`\\beta`
- is the scale parameter.
+ where :math:`\\mu` is the mode, a location parameter, and :math:`\\beta` is
+ the scale parameter.
The Gumbel (named for German mathematician Emil Julius Gumbel) was used
very early in the hydrology literature, for modeling the occurrence of
@@ -2684,6 +2701,7 @@ cdef class RandomState:
initially modeled as a Gaussian process, which underestimated the frequency
of extreme events.
+
It is one of a class of extreme value distributions, the Generalized
Extreme Value (GEV) distributions, which also includes the Weibull and
Frechet.
@@ -2693,13 +2711,12 @@ cdef class RandomState:
References
----------
- .. [1] Gumbel, E.J. (1958). Statistics of Extremes. Columbia University
- Press.
- .. [2] Reiss, R.-D. and Thomas M. (2001), Statistical Analysis of Extreme
- Values, from Insurance, Finance, Hydrology and Other Fields,
- Birkhauser Verlag, Basel: Boston : Berlin.
- .. [3] Wikipedia, "Gumbel distribution",
- http://en.wikipedia.org/wiki/Gumbel_distribution
+ Gumbel, E. J., *Statistics of Extremes*, New York: Columbia University
+ Press, 1958.
+
+ Reiss, R.-D. and Thomas, M., *Statistical Analysis of Extreme Values from
+ Insurance, Finance, Hydrology and Other Fields*, Basel: Birkhauser Verlag,
+ 2001.
Examples
--------
@@ -3451,6 +3468,10 @@ cdef class RandomState:
distribution :math:`f(k; \\lambda)` describes the probability of
:math:`k` events occurring within the observed interval :math:`\\lambda`.
+ Because the output is limited to the range of the C long type, a
+ ValueError is raised when `lam` is within 10 sigma of the maximum
+ representable value.
+
References
----------
.. [1] Weisstein, Eric W. "Poisson Distribution." From MathWorld--A Wolfram
@@ -3478,6 +3499,8 @@ cdef class RandomState:
if not PyErr_Occurred():
if lam < 0:
raise ValueError("lam < 0")
+ if lam > self.poisson_lam_max:
+ raise ValueError("lam value too large")
return discd_array_sc(self.internal_state, rk_poisson, size, flam)
PyErr_Clear()
@@ -3485,6 +3508,8 @@ cdef class RandomState:
olam = <ndarray>PyArray_FROM_OTF(lam, NPY_DOUBLE, NPY_ALIGNED)
if np.any(np.less(olam, 0)):
raise ValueError("lam < 0")
+ if np.any(np.greater(olam, self.poisson_lam_max)):
+ raise ValueError("lam value too large.")
return discd_array(self.internal_state, rk_poisson, size, olam)
def zipf(self, a, size=None):
@@ -3862,32 +3887,30 @@ cdef class RandomState:
Draw random samples from a multivariate normal distribution.
The multivariate normal, multinormal or Gaussian distribution is a
- generalisation of the one-dimensional normal distribution to higher
- dimensions.
-
- Such a distribution is specified by its mean and covariance matrix,
- which are analogous to the mean (average or "centre") and variance
- (standard deviation squared or "width") of the one-dimensional normal
- distribution.
+ generalization of the one-dimensional normal distribution to higher
+ dimensions. Such a distribution is specified by its mean and
+ covariance matrix. These parameters are analogous to the mean
+ (average or "center") and variance (standard deviation, or "width,"
+ squared) of the one-dimensional normal distribution.
Parameters
----------
- mean : (N,) ndarray
+ mean : 1-D array_like, of length N
Mean of the N-dimensional distribution.
- cov : (N,N) ndarray
- Covariance matrix of the distribution.
+ cov : 2-D array_like, of shape (N, N)
+ Covariance matrix of the distribution. Must be symmetric and
+ positive semi-definite for "physically meaningful" results.
size : tuple of ints, optional
- Given a shape of, for example, (m,n,k), m*n*k samples are
- generated, and packed in an m-by-n-by-k arrangement. Because each
- sample is N-dimensional, the output shape is (m,n,k,N). If no
- shape is specified, a single sample is returned.
+ Given a shape of, for example, ``(m,n,k)``, ``m*n*k`` samples are
+ generated, and packed in an `m`-by-`n`-by-`k` arrangement. Because
+ each sample is `N`-dimensional, the output shape is ``(m,n,k,N)``.
+ If no shape is specified, a single (`N`-D) sample is returned.
Returns
-------
out : ndarray
- The drawn samples, arranged according to `size`. If the
- shape given is (m,n,...), then the shape of `out` is is
- (m,n,...,N).
+ The drawn samples, of shape *size*, if that was provided. If not,
+ the shape is ``(N,)``.
In other words, each entry ``out[i,j,...,:]`` is an N-dimensional
value drawn from the distribution.
@@ -3909,8 +3932,8 @@ cdef class RandomState:
Instead of specifying the full covariance matrix, popular
approximations include:
- - Spherical covariance (`cov` is a multiple of the identity matrix)
- - Diagonal covariance (`cov` has non-negative elements, and only on
+ - Spherical covariance (*cov* is a multiple of the identity matrix)
+ - Diagonal covariance (*cov* has non-negative elements, and only on
the diagonal)
This geometrical property can be seen in two dimensions by plotting
@@ -3927,10 +3950,11 @@ cdef class RandomState:
References
----------
- .. [1] A. Papoulis, "Probability, Random Variables, and Stochastic
- Processes," 3rd ed., McGraw-Hill Companies, 1991
- .. [2] R.O. Duda, P.E. Hart, and D.G. Stork, "Pattern Classification,"
- 2nd ed., Wiley, 2001.
+ Papoulis, A., *Probability, Random Variables, and Stochastic Processes*,
+ 3rd ed., New York: McGraw-Hill, 1991.
+
+ Duda, R. O., Hart, P. E., and Stork, D. G., *Pattern Classification*,
+ 2nd ed., New York: Wiley, 2001.
Examples
--------
@@ -4100,6 +4124,11 @@ cdef class RandomState:
size : array
Number of samples to draw.
+ Returns
+ -------
+ samples : ndarray,
+ The drawn samples, of shape (alpha.ndim, size).
+
Notes
-----
.. math:: X \\approx \\prod_{i=1}^{k}{x^{\\alpha_i-1}_i}
@@ -4115,6 +4144,23 @@ cdef class RandomState:
.. [1] David McKay, "Information Theory, Inference and Learning
Algorithms," chapter 23,
http://www.inference.phy.cam.ac.uk/mackay/
+ .. [2] Wikipedia, "Dirichlet distribution",
+ http://en.wikipedia.org/wiki/Dirichlet_distribution
+
+ Examples
+ --------
+ Taking an example cited in Wikipedia, this distribution can be used if
+ one wanted to cut strings (each of initial length 1.0) into K pieces
+ with different lengths, where each piece had, on average, a designated
+ average length, but allowing some variation in the relative sizes of the
+ pieces.
+
+ >>> s = np.random.dirichlet((10, 5, 3), 20).transpose()
+
+ >>> plt.barh(range(20), s[0])
+ >>> plt.barh(range(20), s[1], left=s[0], color='g')
+ >>> plt.barh(range(20), s[2], left=s[0]+s[1], color='r')
+ >>> plt.title("Lengths of Strings")
"""
@@ -4181,6 +4227,32 @@ cdef class RandomState:
Modify a sequence in-place by shuffling its contents.
+ Parameters
+ ----------
+ x : array_like
+ The array or list to be shuffled.
+
+ Returns
+ -------
+ None
+
+ Examples
+ --------
+ >>> arr = np.arange(10)
+ >>> np.random.shuffle(arr)
+ >>> arr
+ [1 7 5 2 9 4 3 6 0 8]
+
+ This function only shuffles the array along the first index of a
+ multi-dimensional array:
+
+ >>> arr = np.arange(9).reshape((3, 3))
+ >>> np.random.shuffle(arr)
+ >>> arr
+ array([[3, 4, 5],
+ [6, 7, 8],
+ [0, 1, 2]])
+
"""
cdef long i, j
cdef int copy
@@ -4217,6 +4289,9 @@ cdef class RandomState:
Randomly permute a sequence, or return a permuted range.
+ If `x` is a multi-dimensional array, it is only shuffled along its
+ first index.
+
Parameters
----------
x : int or array_like
@@ -4237,6 +4312,12 @@ cdef class RandomState:
>>> np.random.permutation([1, 4, 9, 12, 15])
array([15, 1, 9, 4, 12])
+ >>> arr = np.arange(9).reshape((3, 3))
+ >>> np.random.permutation(arr)
+ array([[6, 7, 8],
+ [0, 1, 2],
+ [3, 4, 5]])
+
"""
if isinstance(x, (int, long, np.integer)):
arr = np.arange(x)
diff --git a/numpy/random/tests/test_random.py b/numpy/random/tests/test_random.py
index 8b5d083a3..8acb0680e 100644
--- a/numpy/random/tests/test_random.py
+++ b/numpy/random/tests/test_random.py
@@ -1,45 +1,8 @@
-from numpy.testing import *
+from numpy.testing import TestCase, run_module_suite, assert_,\
+ assert_raises
from numpy import random
import numpy as np
-class TestRegression(TestCase):
-
- def test_VonMises_range(self):
- """Make sure generated random variables are in [-pi, pi].
-
- Regression test for ticket #986.
- """
- for mu in np.linspace(-7., 7., 5):
- r = random.mtrand.vonmises(mu,1,50)
- assert np.all(r > -np.pi) and np.all(r <= np.pi)
-
- def test_hypergeometric_range(self) :
- """Test for ticket #921"""
- assert_(np.all(np.random.hypergeometric(3, 18, 11, size=10) < 4))
- assert_(np.all(np.random.hypergeometric(18, 3, 11, size=10) > 0))
-
- def test_logseries_convergence(self) :
- """Test for ticket #923"""
- N = 1000
- np.random.seed(0)
- rvsn = np.random.logseries(0.8, size=N)
- # these two frequency counts should be close to theoretical
- # numbers with this large sample
- # theoretical large N result is 0.49706795
- freq = np.sum(rvsn == 1) / float(N)
- msg = "Frequency was %f, should be > 0.45" % freq
- assert_(freq > 0.45, msg)
- # theoretical large N result is 0.19882718
- freq = np.sum(rvsn == 2) / float(N)
- msg = "Frequency was %f, should be < 0.23" % freq
- assert_(freq < 0.23, msg)
-
- def test_permutation_longs(self):
- np.random.seed(1234)
- a = np.random.permutation(12)
- np.random.seed(1234)
- b = np.random.permutation(12L)
- assert_array_equal(a, b)
class TestMultinomial(TestCase):
def test_basic(self):
@@ -49,11 +12,10 @@ class TestMultinomial(TestCase):
random.multinomial(100, [0.2, 0.8, 0.0, 0.0, 0.0])
def test_int_negative_interval(self):
- assert -5 <= random.randint(-5,-1) < -1
+ assert_( -5 <= random.randint(-5,-1) < -1)
x = random.randint(-5,-1,5)
- assert np.all(-5 <= x)
- assert np.all(x < -1)
-
+ assert_(np.all(-5 <= x))
+ assert_(np.all(x < -1))
class TestSetState(TestCase):
@@ -66,7 +28,7 @@ class TestSetState(TestCase):
old = self.prng.tomaxint(16)
self.prng.set_state(self.state)
new = self.prng.tomaxint(16)
- assert np.all(old == new)
+ assert_(np.all(old == new))
def test_gaussian_reset(self):
""" Make sure the cached every-other-Gaussian is reset.
@@ -74,7 +36,7 @@ class TestSetState(TestCase):
old = self.prng.standard_normal(size=3)
self.prng.set_state(self.state)
new = self.prng.standard_normal(size=3)
- assert np.all(old == new)
+ assert_(np.all(old == new))
def test_gaussian_reset_in_media_res(self):
""" When the state is saved with a cached Gaussian, make sure the cached
@@ -85,7 +47,7 @@ class TestSetState(TestCase):
old = self.prng.standard_normal(size=3)
self.prng.set_state(state)
new = self.prng.standard_normal(size=3)
- assert np.all(old == new)
+ assert_(np.all(old == new))
def test_backwards_compatibility(self):
""" Make sure we can accept old state tuples that do not have the cached
@@ -97,8 +59,8 @@ class TestSetState(TestCase):
x2 = self.prng.standard_normal(size=16)
self.prng.set_state(self.state)
x3 = self.prng.standard_normal(size=16)
- assert np.all(x1 == x2)
- assert np.all(x1 == x3)
+ assert_(np.all(x1 == x2))
+ assert_(np.all(x1 == x3))
def test_negative_binomial(self):
""" Ensure that the negative binomial results take floating point
@@ -106,6 +68,370 @@ class TestSetState(TestCase):
"""
self.prng.negative_binomial(0.5, 0.5)
+class TestRandomDist(TestCase):
+ """ Make sure the random distrobution return the correct value for a
+ given seed
+ """
+ def setUp(self):
+ self.seed = 1234567890
+
+ def test_rand(self):
+ np.random.seed(self.seed)
+ actual = np.random.rand(3, 2)
+ desired = np.array([[ 0.61879477158567997, 0.59162362775974664],
+ [ 0.88868358904449662, 0.89165480011560816],
+ [ 0.4575674820298663 , 0.7781880808593471 ]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_randn(self):
+ np.random.seed(self.seed)
+ actual = np.random.randn(3, 2)
+ desired = np.array([[ 1.34016345771863121, 1.73759122771936081],
+ [ 1.498988344300628 , -0.2286433324536169 ],
+ [ 2.031033998682787 , 2.17032494605655257]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_randint(self):
+ np.random.seed(self.seed)
+ actual = np.random.randint(-99, 99, size=(3,2))
+ desired = np.array([[ 31, 3],
+ [-52, 41],
+ [-48, -66]])
+ np.testing.assert_array_equal(actual, desired)
+
+ def test_random_integers(self):
+ np.random.seed(self.seed)
+ actual = np.random.random_integers(-99, 99, size=(3,2))
+ desired = np.array([[ 31, 3],
+ [-52, 41],
+ [-48, -66]])
+ np.testing.assert_array_equal(actual, desired)
+
+ def test_random_sample(self):
+ np.random.seed(self.seed)
+ actual = np.random.random_sample((3, 2))
+ desired = np.array([[ 0.61879477158567997, 0.59162362775974664],
+ [ 0.88868358904449662, 0.89165480011560816],
+ [ 0.4575674820298663 , 0.7781880808593471 ]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_bytes(self):
+ np.random.seed(self.seed)
+ actual = np.random.bytes(10)
+ desired = '\x82Ui\x9e\xff\x97+Wf\xa5'
+ np.testing.assert_string_equal(actual, desired)
+
+ def test_shuffle(self):
+ np.random.seed(self.seed)
+ alist = [1,2,3,4,5,6,7,8,9,0]
+ np.random.shuffle(alist)
+ actual = alist
+ desired = [0, 1, 9, 6, 2, 4, 5, 8, 7, 3]
+ np.testing.assert_array_equal(actual, desired)
+
+ def test_beta(self):
+ np.random.seed(self.seed)
+ actual = np.random.beta(.1, .9, size=(3, 2))
+ desired = np.array([[ 1.45341850513746058e-02, 5.31297615662868145e-04],
+ [ 1.85366619058432324e-06, 4.19214516800110563e-03],
+ [ 1.58405155108498093e-04, 1.26252891949397652e-04]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_binomial(self):
+ np.random.seed(self.seed)
+ actual = np.random.binomial(100.123, .456, size=(3, 2))
+ desired = np.array([[37, 43],
+ [42, 48],
+ [46, 45]])
+ np.testing.assert_array_equal(actual, desired)
+
+ def test_chisquare(self):
+ np.random.seed(self.seed)
+ actual = np.random.chisquare(50, size=(3, 2))
+ desired = np.array([[ 63.87858175501090585, 68.68407748911370447],
+ [ 65.77116116901505904, 47.09686762438974483],
+ [ 72.3828403199695174 , 74.18408615260374006]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_dirichlet(self):
+ np.random.seed(self.seed)
+ alpha = np.array([51.72840233779265162, 39.74494232180943953])
+ actual = np.random.mtrand.dirichlet(alpha, size=(3, 2))
+ desired = np.array([[[ 0.54539444573611562, 0.45460555426388438],
+ [ 0.62345816822039413, 0.37654183177960598]],
+ [[ 0.55206000085785778, 0.44793999914214233],
+ [ 0.58964023305154301, 0.41035976694845688]],
+ [[ 0.59266909280647828, 0.40733090719352177],
+ [ 0.56974431743975207, 0.43025568256024799]]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_exponential(self):
+ np.random.seed(self.seed)
+ actual = np.random.exponential(1.1234, size=(3, 2))
+ desired = np.array([[ 1.08342649775011624, 1.00607889924557314],
+ [ 2.46628830085216721, 2.49668106809923884],
+ [ 0.68717433461363442, 1.69175666993575979]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_f(self):
+ np.random.seed(self.seed)
+ actual = np.random.f(12, 77, size=(3, 2))
+ desired = np.array([[ 1.21975394418575878, 1.75135759791559775],
+ [ 1.44803115017146489, 1.22108959480396262],
+ [ 1.02176975757740629, 1.34431827623300415]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_gamma(self):
+ np.random.seed(self.seed)
+ actual = np.random.gamma(5, 3, size=(3, 2))
+ desired = np.array([[ 24.60509188649287182, 28.54993563207210627],
+ [ 26.13476110204064184, 12.56988482927716078],
+ [ 31.71863275789960568, 33.30143302795922011]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_geometric(self):
+ np.random.seed(self.seed)
+ actual = np.random.geometric(.123456789, size=(3, 2))
+ desired = np.array([[ 8, 7],
+ [17, 17],
+ [ 5, 12]])
+ np.testing.assert_array_equal(actual, desired)
+
+ def test_gumbel(self):
+ np.random.seed(self.seed)
+ actual = np.random.gumbel(loc = .123456789, scale = 2.0, size = (3, 2))
+ desired = np.array([[ 0.19591898743416816, 0.34405539668096674],
+ [-1.4492522252274278 , -1.47374816298446865],
+ [ 1.10651090478803416, -0.69535848626236174]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_hypergeometric(self):
+ np.random.seed(self.seed)
+ actual = np.random.hypergeometric(10.1, 5.5, 14, size=(3, 2))
+ desired = np.array([[10, 10],
+ [10, 10],
+ [ 9, 9]])
+ 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))
+ desired = np.array([[ 0.66599721112760157, 0.52829452552221945],
+ [ 3.12791959514407125, 3.18202813572992005],
+ [-0.05391065675859356, 1.74901336242837324]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_logistic(self):
+ np.random.seed(self.seed)
+ actual = np.random.logistic(loc=.123456789, scale=2.0, size=(3, 2))
+ desired = np.array([[ 1.09232835305011444, 0.8648196662399954 ],
+ [ 4.27818590694950185, 4.33897006346929714],
+ [-0.21682183359214885, 2.63373365386060332]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_lognormal(self):
+ np.random.seed(self.seed)
+ actual = np.random.lognormal(mean=.123456789, sigma=2.0, size=(3, 2))
+ desired = np.array([[ 16.50698631688883822, 36.54846706092654784],
+ [ 22.67886599981281748, 0.71617561058995771],
+ [ 65.72798501792723869, 86.84341601437161273]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_logseries(self):
+ np.random.seed(self.seed)
+ actual = np.random.logseries(p=.923456789, size=(3, 2))
+ desired = np.array([[ 2, 2],
+ [ 6, 17],
+ [ 3, 6]])
+ np.testing.assert_array_equal(actual, desired)
+
+ def test_multinomial(self):
+ np.random.seed(self.seed)
+ actual = np.random.multinomial(20, [1/6.]*6, size=(3, 2))
+ desired = np.array([[[4, 3, 5, 4, 2, 2],
+ [5, 2, 8, 2, 2, 1]],
+ [[3, 4, 3, 6, 0, 4],
+ [2, 1, 4, 3, 6, 4]],
+ [[4, 4, 2, 5, 2, 3],
+ [4, 3, 4, 2, 3, 4]]])
+ np.testing.assert_array_equal(actual, desired)
+
+ def test_multivariate_normal(self):
+ np.random.seed(self.seed)
+ mean= (.123456789, 10)
+ cov = [[1,0],[1,0]]
+ size = (3, 2)
+ actual = np.random.multivariate_normal(mean, cov, size)
+ desired = np.array([[[ -1.47027513018564449, 10. ],
+ [ -1.65915081534845532, 10. ]],
+ [[ -2.29186329304599745, 10. ],
+ [ -1.77505606019580053, 10. ]],
+ [[ -0.54970369430044119, 10. ],
+ [ 0.29768848031692957, 10. ]]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_negative_binomial(self):
+ np.random.seed(self.seed)
+ actual = np.random.negative_binomial(n = 100, p = .12345, size = (3, 2))
+ desired = np.array([[848, 841],
+ [892, 611],
+ [779, 647]])
+ np.testing.assert_array_equal(actual, desired)
+
+ def test_noncentral_chisquare(self):
+ np.random.seed(self.seed)
+ actual = np.random.noncentral_chisquare(df = 5, nonc = 5, size = (3, 2))
+ desired = np.array([[ 23.91905354498517511, 13.35324692733826346],
+ [ 31.22452661329736401, 16.60047399466177254],
+ [ 5.03461598262724586, 17.94973089023519464]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_noncentral_f(self):
+ np.random.seed(self.seed)
+ actual = np.random.noncentral_f(dfnum = 5, dfden = 2, nonc = 1,
+ size = (3, 2))
+ desired = np.array([[ 1.40598099674926669, 0.34207973179285761],
+ [ 3.57715069265772545, 7.92632662577829805],
+ [ 0.43741599463544162, 1.1774208752428319 ]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_normal(self):
+ np.random.seed(self.seed)
+ actual = np.random.normal(loc = .123456789, scale = 2.0, size = (3, 2))
+ desired = np.array([[ 2.80378370443726244, 3.59863924443872163],
+ [ 3.121433477601256 , -0.33382987590723379],
+ [ 4.18552478636557357, 4.46410668111310471]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_pareto(self):
+ np.random.seed(self.seed)
+ actual = np.random.pareto(a =.123456789, size = (3, 2))
+ desired = np.array([[ 2.46852460439034849e+03, 1.41286880810518346e+03],
+ [ 5.28287797029485181e+07, 6.57720981047328785e+07],
+ [ 1.40840323350391515e+02, 1.98390255135251704e+05]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_poisson(self):
+ np.random.seed(self.seed)
+ actual = np.random.poisson(lam = .123456789, size=(3, 2))
+ desired = np.array([[0, 0],
+ [1, 0],
+ [0, 0]])
+ np.testing.assert_array_equal(actual, desired)
+
+ def test_poisson_exceptions(self):
+ lambig = np.iinfo('l').max
+ lamneg = -1
+ assert_raises(ValueError, np.random.poisson, lamneg)
+ assert_raises(ValueError, np.random.poisson, [lamneg]*10)
+ assert_raises(ValueError, np.random.poisson, lambig)
+ assert_raises(ValueError, np.random.poisson, [lambig]*10)
+
+ def test_power(self):
+ np.random.seed(self.seed)
+ actual = np.random.power(a =.123456789, size = (3, 2))
+ desired = np.array([[ 0.02048932883240791, 0.01424192241128213],
+ [ 0.38446073748535298, 0.39499689943484395],
+ [ 0.00177699707563439, 0.13115505880863756]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_rayleigh(self):
+ np.random.seed(self.seed)
+ actual = np.random.rayleigh(scale = 10, size = (3, 2))
+ desired = np.array([[ 13.8882496494248393 , 13.383318339044731 ],
+ [ 20.95413364294492098, 21.08285015800712614],
+ [ 11.06066537006854311, 17.35468505778271009]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_standard_cauchy(self):
+ np.random.seed(self.seed)
+ actual = np.random.standard_cauchy(size = (3, 2))
+ desired = np.array([[ 0.77127660196445336, -6.55601161955910605],
+ [ 0.93582023391158309, -2.07479293013759447],
+ [-4.74601644297011926, 0.18338989290760804]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_standard_exponential(self):
+ np.random.seed(self.seed)
+ actual = np.random.standard_exponential(size = (3, 2))
+ desired = np.array([[ 0.96441739162374596, 0.89556604882105506],
+ [ 2.1953785836319808 , 2.22243285392490542],
+ [ 0.6116915921431676 , 1.50592546727413201]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_standard_gamma(self):
+ np.random.seed(self.seed)
+ actual = np.random.standard_gamma(shape = 3, size = (3, 2))
+ desired = np.array([[ 5.50841531318455058, 6.62953470301903103],
+ [ 5.93988484943779227, 2.31044849402133989],
+ [ 7.54838614231317084, 8.012756093271868 ]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_standard_normal(self):
+ np.random.seed(self.seed)
+ actual = np.random.standard_normal(size = (3, 2))
+ desired = np.array([[ 1.34016345771863121, 1.73759122771936081],
+ [ 1.498988344300628 , -0.2286433324536169 ],
+ [ 2.031033998682787 , 2.17032494605655257]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_standard_t(self):
+ np.random.seed(self.seed)
+ actual = np.random.standard_t(df = 10, size = (3, 2))
+ desired = np.array([[ 0.97140611862659965, -0.08830486548450577],
+ [ 1.36311143689505321, -0.55317463909867071],
+ [-0.18473749069684214, 0.61181537341755321]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_triangular(self):
+ np.random.seed(self.seed)
+ actual = np.random.triangular(left = 5.12, mode = 10.23, right = 20.34,
+ size = (3, 2))
+ desired = np.array([[ 12.68117178949215784, 12.4129206149193152 ],
+ [ 16.20131377335158263, 16.25692138747600524],
+ [ 11.20400690911820263, 14.4978144835829923 ]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_uniform(self):
+ np.random.seed(self.seed)
+ actual = np.random.uniform(low = 1.23, high=10.54, size = (3, 2))
+ desired = np.array([[ 6.99097932346268003, 6.73801597444323974],
+ [ 9.50364421400426274, 9.53130618907631089],
+ [ 5.48995325769805476, 8.47493103280052118]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+
+ def test_vonmises(self):
+ np.random.seed(self.seed)
+ actual = np.random.vonmises(mu = 1.23, kappa = 1.54, size = (3, 2))
+ desired = np.array([[ 2.28567572673902042, 2.89163838442285037],
+ [ 0.38198375564286025, 2.57638023113890746],
+ [ 1.19153771588353052, 1.83509849681825354]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_wald(self):
+ np.random.seed(self.seed)
+ actual = np.random.wald(mean = 1.23, scale = 1.54, size = (3, 2))
+ desired = np.array([[ 3.82935265715889983, 5.13125249184285526],
+ [ 0.35045403618358717, 1.50832396872003538],
+ [ 0.24124319895843183, 0.22031101461955038]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_weibull(self):
+ np.random.seed(self.seed)
+ actual = np.random.weibull(a = 1.23, size = (3, 2))
+ desired = np.array([[ 0.97097342648766727, 0.91422896443565516],
+ [ 1.89517770034962929, 1.91414357960479564],
+ [ 0.67057783752390987, 1.39494046635066793]])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ def test_zipf(self):
+ np.random.seed(self.seed)
+ actual = np.random.zipf(a = 1.23, size = (3, 2))
+ desired = np.array([[66, 29],
+ [ 1, 1],
+ [ 3, 13]])
+ np.testing.assert_array_equal(actual, desired)
if __name__ == "__main__":
run_module_suite()
diff --git a/numpy/random/tests/test_regression.py b/numpy/random/tests/test_regression.py
new file mode 100644
index 000000000..f5039c09a
--- /dev/null
+++ b/numpy/random/tests/test_regression.py
@@ -0,0 +1,57 @@
+from numpy.testing import TestCase, run_module_suite, assert_,\
+ assert_array_equal
+from numpy import random
+import numpy as np
+
+
+class TestRegression(TestCase):
+
+ def test_VonMises_range(self):
+ """Make sure generated random variables are in [-pi, pi].
+
+ Regression test for ticket #986.
+ """
+ for mu in np.linspace(-7., 7., 5):
+ r = random.mtrand.vonmises(mu,1,50)
+ assert_(np.all(r > -np.pi) and np.all(r <= np.pi))
+
+ def test_hypergeometric_range(self) :
+ """Test for ticket #921"""
+ assert_(np.all(np.random.hypergeometric(3, 18, 11, size=10) < 4))
+ assert_(np.all(np.random.hypergeometric(18, 3, 11, size=10) > 0))
+
+ def test_logseries_convergence(self) :
+ """Test for ticket #923"""
+ N = 1000
+ np.random.seed(0)
+ rvsn = np.random.logseries(0.8, size=N)
+ # these two frequency counts should be close to theoretical
+ # numbers with this large sample
+ # theoretical large N result is 0.49706795
+ freq = np.sum(rvsn == 1) / float(N)
+ msg = "Frequency was %f, should be > 0.45" % freq
+ assert_(freq > 0.45, msg)
+ # theoretical large N result is 0.19882718
+ freq = np.sum(rvsn == 2) / float(N)
+ msg = "Frequency was %f, should be < 0.23" % freq
+ assert_(freq < 0.23, msg)
+
+ def test_permutation_longs(self):
+ np.random.seed(1234)
+ a = np.random.permutation(12)
+ np.random.seed(1234)
+ b = np.random.permutation(12L)
+ assert_array_equal(a, b)
+
+ def test_hypergeometric_range(self) :
+ """Test for ticket #1690"""
+ lmax = np.iinfo('l').max
+ lmin = np.iinfo('l').min
+ try:
+ random.randint(lmin, lmax)
+ except:
+ raise AssertionError
+
+
+if __name__ == "__main__":
+ run_module_suite()
diff --git a/numpy/testing/print_coercion_tables.py b/numpy/testing/print_coercion_tables.py
index 0c8a87d9a..7b5320d7e 100755
--- a/numpy/testing/print_coercion_tables.py
+++ b/numpy/testing/print_coercion_tables.py
@@ -14,6 +14,8 @@ class GenericObject:
def __radd__(self, other):
return self
+ dtype = np.dtype('O')
+
def print_cancast_table(ntypes):
print 'X',
for char in ntypes: print char,
@@ -24,7 +26,7 @@ def print_cancast_table(ntypes):
print int(np.can_cast(row, col)),
print
-def print_coercion_table(ntypes, inputfirstvalue, inputsecondvalue, firstarray):
+def print_coercion_table(ntypes, inputfirstvalue, inputsecondvalue, firstarray, use_promote_types=False):
print '+',
for char in ntypes: print char,
print
@@ -46,11 +48,14 @@ def print_coercion_table(ntypes, inputfirstvalue, inputsecondvalue, firstarray):
else:
rowvalue = rowtype(inputfirstvalue)
colvalue = coltype(inputsecondvalue)
- value = np.add(rowvalue,colvalue)
- if isinstance(value, np.ndarray):
- char = value.dtype.char
+ if use_promote_types:
+ char = np.promote_types(rowvalue.dtype, colvalue.dtype).char
else:
- char = np.dtype(type(value)).char
+ value = np.add(rowvalue,colvalue)
+ if isinstance(value, np.ndarray):
+ char = value.dtype.char
+ else:
+ char = np.dtype(type(value)).char
except ValueError:
char = '!'
except OverflowError:
@@ -76,4 +81,6 @@ print_coercion_table(np.typecodes['All'], 0, 0, True)
print
print "array + neg scalar"
print_coercion_table(np.typecodes['All'], 0, -1, True)
-
+print
+print "promote_types"
+print_coercion_table(np.typecodes['All'], 0, 0, False, True)
diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py
index 5106c1184..9798a25be 100644
--- a/numpy/testing/tests/test_utils.py
+++ b/numpy/testing/tests/test_utils.py
@@ -413,7 +413,7 @@ class TestULP(unittest.TestCase):
def test_double(self):
# Generate 1 + small deviation, check that adding eps gives a few UNL
- x = np.ones(10).astype(np.float32)
+ x = np.ones(10).astype(np.float64)
x += 0.01 * np.random.randn(10).astype(np.float64)
eps = np.finfo(np.float64).eps
assert_array_max_ulp(x, x+eps, maxulp=200)
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py
index 6f18b5468..0c0483f39 100644
--- a/numpy/testing/utils.py
+++ b/numpy/testing/utils.py
@@ -205,25 +205,25 @@ def assert_equal(actual,desired,err_msg='',verbose=True):
"""
Raise an assertion if two objects are not equal.
- Given two objects (lists, tuples, dictionaries or numpy arrays), check
- that all elements of these objects are equal. An exception is raised at
- the first conflicting values.
+ Given two objects (scalars, lists, tuples, dictionaries or numpy arrays),
+ check that all elements of these objects are equal. An exception is raised
+ at the first conflicting values.
Parameters
----------
- actual : list, tuple, dict or ndarray
- The object to check.
- desired : list, tuple, dict or ndarray
- The expected object.
- err_msg : string
- The error message to be printed in case of failure.
- verbose : bool
- If True, the conflicting values are appended to the error message.
+ actual : array_like
+ The object to check.
+ desired : array_like
+ The expected object.
+ err_msg : str, optional
+ The error message to be printed in case of failure.
+ verbose : bool, optional
+ If True, the conflicting values are appended to the error message.
Raises
------
AssertionError
- If actual and desired are not equal.
+ If actual and desired are not equal.
Examples
--------
@@ -357,7 +357,12 @@ def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True):
"""
Raise an assertion if two items are not equal up to desired precision.
- The test is equivalent to abs(desired-actual) < 0.5 * 10**(-decimal)
+ .. note:: It is recommended to use one of `assert_allclose`,
+ `assert_array_almost_equal_nulp` or `assert_array_max_ulp`
+ instead of this function for more consistent floating point
+ comparisons.
+
+ The test is equivalent to ``abs(desired-actual) < 0.5 * 10**(-decimal)``.
Given two objects (numbers or ndarrays), check that all elements of these
objects are almost equal. An exception is raised at conflicting values.
@@ -365,16 +370,16 @@ def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True):
Parameters
----------
- actual : number or ndarray
- The object to check.
- desired : number or ndarray
- The expected object.
- decimal : integer (decimal=7)
- desired precision
- err_msg : string
- The error message to be printed in case of failure.
- verbose : bool
- If True, the conflicting values are appended to the error message.
+ actual : array_like
+ The object to check.
+ desired : array_like
+ The expected object.
+ decimal : int, optional
+ Desired precision, default is 7.
+ err_msg : str, optional
+ The error message to be printed in case of failure.
+ verbose : bool, optional
+ If True, the conflicting values are appended to the error message.
Raises
------
@@ -383,9 +388,9 @@ def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True):
See Also
--------
- assert_array_almost_equal: compares array_like objects
- assert_equal: tests objects for equality
-
+ assert_allclose: Compare two array_like objects for equality with desired
+ relative and/or absolute precision.
+ assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal
Examples
--------
@@ -399,7 +404,7 @@ def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True):
DESIRED: 2.3333333399999998
>>> npt.assert_almost_equal(np.array([1.0,2.3333333333333]),
- \t\t\tnp.array([1.0,2.33333334]), decimal=9)
+ ... np.array([1.0,2.33333334]), decimal=9)
...
<type 'exceptions.AssertionError'>:
Arrays are not almost equal
@@ -421,7 +426,7 @@ def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True):
usecomplex = False
msg = build_err_msg([actual, desired], err_msg, verbose=verbose,
- header='Arrays are not almost equal')
+ header=('Arrays are not almost equal to %d decimals' % decimal))
if usecomplex:
if iscomplexobj(actual):
@@ -467,22 +472,27 @@ def assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=True):
"""
Raise an assertion if two items are not equal up to significant digits.
+ .. note:: It is recommended to use one of `assert_allclose`,
+ `assert_array_almost_equal_nulp` or `assert_array_max_ulp`
+ instead of this function for more consistent floating point
+ comparisons.
+
Given two numbers, check that they are approximately equal.
Approximately equal is defined as the number of significant digits
that agree.
Parameters
----------
- actual : number
- The object to check.
- desired : number
- The expected object.
- significant : integer (significant=7)
- desired precision
- err_msg : string
- The error message to be printed in case of failure.
- verbose : bool
- If True, the conflicting values are appended to the error message.
+ actual : scalar
+ The object to check.
+ desired : scalar
+ The expected object.
+ significant : int, optional
+ Desired precision, default is 7.
+ err_msg : str, optional
+ The error message to be printed in case of failure.
+ verbose : bool, optional
+ If True, the conflicting values are appended to the error message.
Raises
------
@@ -491,10 +501,9 @@ def assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=True):
See Also
--------
- assert_almost_equal: compares objects by decimals
- assert_array_almost_equal: compares array_like objects by decimals
- assert_equal: tests objects for equality
-
+ assert_allclose: Compare two array_like objects for equality with desired
+ relative and/or absolute precision.
+ assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal
Examples
--------
@@ -616,7 +625,8 @@ def assert_array_compare(comparison, x, y, err_msg='', verbose=True,
names=('x', 'y'))
if not cond :
raise AssertionError(msg)
- except ValueError:
+ except ValueError, e:
+ header = 'error during assertion:\n%s\n\n%s' % (e, header)
msg = build_err_msg([x, y], err_msg, verbose=verbose, header=header,
names=('x', 'y'))
raise ValueError(msg)
@@ -637,36 +647,36 @@ def assert_array_equal(x, y, err_msg='', verbose=True):
Parameters
----------
x : array_like
- The actual object to check.
+ The actual object to check.
y : array_like
- The desired, expected object.
- err_msg : string
- The error message to be printed in case of failure.
- verbose : bool
+ The desired, expected object.
+ err_msg : str, optional
+ The error message to be printed in case of failure.
+ verbose : bool, optional
If True, the conflicting values are appended to the error message.
Raises
------
AssertionError
- If actual and desired objects are not equal.
+ If actual and desired objects are not equal.
See Also
--------
- assert_array_almost_equal: test objects for equality up to precision
- assert_equal: tests objects for equality
-
+ assert_allclose: Compare two array_like objects for equality with desired
+ relative and/or absolute precision.
+ assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal
Examples
--------
- the first assert does not raise an exception
+ The first assert does not raise an exception:
>>> np.testing.assert_array_equal([1.0,2.33333,np.nan],
- \t\t\t[np.exp(0),2.33333, np.nan])
+ ... [np.exp(0),2.33333, np.nan])
- assert fails with numerical inprecision with floats
+ Assert fails with numerical inprecision with floats:
>>> np.testing.assert_array_equal([1.0,np.pi,np.nan],
- \t\t\t[1, np.sqrt(np.pi)**2, np.nan])
+ ... [1, np.sqrt(np.pi)**2, np.nan])
...
<type 'exceptions.ValueError'>:
AssertionError:
@@ -676,10 +686,12 @@ def assert_array_equal(x, y, err_msg='', verbose=True):
x: array([ 1. , 3.14159265, NaN])
y: array([ 1. , 3.14159265, NaN])
- use assert_array_almost_equal for these cases instead
+ Use `assert_allclose` or one of the nulp (number of floating point values)
+ functions for these cases instead:
- >>> np.testing.assert_array_almost_equal([1.0,np.pi,np.nan],
- \t\t\t[1, np.sqrt(np.pi)**2, np.nan], decimal=15)
+ >>> np.testing.assert_allclose([1.0,np.pi,np.nan],
+ ... [1, np.sqrt(np.pi)**2, np.nan],
+ ... rtol=1e-10, atol=0)
"""
assert_array_compare(operator.__eq__, x, y, err_msg=err_msg,
@@ -689,8 +701,13 @@ def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True):
"""
Raise an assertion if two objects are not equal up to desired precision.
+ .. note:: It is recommended to use one of `assert_allclose`,
+ `assert_array_almost_equal_nulp` or `assert_array_max_ulp`
+ instead of this function for more consistent floating point
+ comparisons.
+
The test verifies identical shapes and verifies values with
- abs(desired-actual) < 0.5 * 10**(-decimal)
+ ``abs(desired-actual) < 0.5 * 10**(-decimal)``.
Given two array_like objects, check that the shape is equal and all
elements of these objects are almost equal. An exception is raised at
@@ -701,26 +718,26 @@ def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True):
Parameters
----------
x : array_like
- The actual object to check.
+ The actual object to check.
y : array_like
- The desired, expected object.
- decimal : integer (decimal=6)
- desired precision
- err_msg : string
+ The desired, expected object.
+ decimal : int, optional
+ Desired precision, default is 6.
+ err_msg : str, optional
The error message to be printed in case of failure.
- verbose : bool
+ verbose : bool, optional
If True, the conflicting values are appended to the error message.
Raises
------
AssertionError
- If actual and desired are not equal up to specified precision.
+ If actual and desired are not equal up to specified precision.
See Also
--------
- assert_almost_equal: simple version for comparing numbers
- assert_array_equal: tests objects for equality
-
+ assert_allclose: Compare two array_like objects for equality with desired
+ relative and/or absolute precision.
+ assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal
Examples
--------
@@ -730,7 +747,7 @@ def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True):
[1.0,2.333,np.nan])
>>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan],
- \t\t\t[1.0,2.33339,np.nan], decimal=5)
+ ... [1.0,2.33339,np.nan], decimal=5)
...
<type 'exceptions.AssertionError'>:
AssertionError:
@@ -741,7 +758,7 @@ def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True):
y: array([ 1. , 2.33339, NaN])
>>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan],
- \t\t\t[1.0,2.33333, 5], decimal=5)
+ ... [1.0,2.33333, 5], decimal=5)
<type 'exceptions.ValueError'>:
ValueError:
Arrays are not almost equal
@@ -771,7 +788,7 @@ def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True):
z = z.astype(float_) # handle object arrays
return around(z, decimal) <= 10.0**(-decimal)
assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose,
- header='Arrays are not almost equal')
+ header=('Arrays are not almost equal to %d decimals' % decimal))
def assert_array_less(x, y, err_msg='', verbose=True):
"""
@@ -1098,21 +1115,23 @@ def assert_allclose(actual, desired, rtol=1e-7, atol=0,
"""
Raise an assertion if two objects are not equal up to desired tolerance.
- The test is equivalent to ``allclose(actual, desired, rtol, atol)``
+ The test is equivalent to ``allclose(actual, desired, rtol, atol)``.
+ It compares the difference between `actual` and `desired` to
+ ``atol + rtol * abs(desired)``.
Parameters
----------
actual : array_like
Array obtained.
desired : array_like
- Array desired
+ Array desired.
rtol : float, optional
- Relative tolerance
+ Relative tolerance.
atol : float, optional
- Absolute tolerance
- err_msg : string
+ Absolute tolerance.
+ err_msg : str, optional
The error message to be printed in case of failure.
- verbose : bool
+ verbose : bool, optional
If True, the conflicting values are appended to the error message.
Raises
@@ -1120,6 +1139,16 @@ def assert_allclose(actual, desired, rtol=1e-7, atol=0,
AssertionError
If actual and desired are not equal up to specified precision.
+ See Also
+ --------
+ assert_array_almost_equal_nulp, assert_array_max_ulp
+
+ Examples
+ --------
+ >>> x = [1e-5, 1e-3, 1e-1]
+ >>> y = np.arccos(np.cos(x))
+ >>> assert_allclose(x, y, rtol=1e-5, atol=0)
+
"""
import numpy as np
def compare(x, y):
@@ -1235,7 +1264,7 @@ def assert_array_max_ulp(a, b, maxulp=1, dtype=None):
return ret
def nulp_diff(x, y, dtype=None):
- """For each item in x and y, eeturn the number of representable floating
+ """For each item in x and y, return the number of representable floating
points between them.
Parameters
diff --git a/numpy/tests/test_ctypeslib.py b/numpy/tests/test_ctypeslib.py
index 832ce683c..78403df9e 100644
--- a/numpy/tests/test_ctypeslib.py
+++ b/numpy/tests/test_ctypeslib.py
@@ -31,6 +31,10 @@ class TestLoadLibrary(TestCase):
try:
from distutils import sysconfig
so = sysconfig.get_config_var('SO')
+ # fix long extension for Python >=3.2, see PEP 3149.
+ if 'SOABI' in sysconfig.get_config_vars():
+ so = so.replace('.'+sysconfig.get_config_var('SOABI'), '', 1)
+
cdll = load_library('multiarray%s' % so,
np.core.multiarray.__file__)
except ImportError:
diff --git a/pavement.py b/pavement.py
index 5bef2253b..c52402e99 100644
--- a/pavement.py
+++ b/pavement.py
@@ -81,6 +81,22 @@ try:
finally:
sys.path.pop(0)
+
+#-----------------------------------
+# Things to be changed for a release
+#-----------------------------------
+
+# Source of the release notes
+RELEASE_NOTES = 'doc/release/2.0.0-notes.rst'
+
+# Start/end of the log (from git)
+LOG_START = 'svn/tags/1.5.0'
+LOG_END = 'master'
+
+
+#-------------------------------------------------------
+# Hardcoded build/install dirs, virtualenv options, etc.
+#-------------------------------------------------------
DEFAULT_PYTHON = "2.6"
# Where to put the final installers, as put on sourceforge
@@ -109,6 +125,7 @@ MPKG_PYTHON = {
"2.6": ["/Library/Frameworks/Python.framework/Versions/2.6/bin/python"],
"2.7": ["/Library/Frameworks/Python.framework/Versions/2.7/bin/python"],
"3.1": ["/Library/Frameworks/Python.framework/Versions/3.1/bin/python3"],
+ "3.2": ["/Library/Frameworks/Python.framework/Versions/3.2/bin/python3"],
}
SSE3_CFG = {'ATLAS': r'C:\local\lib\yop\sse3'}
@@ -119,6 +136,7 @@ SITECFG = {"sse2" : SSE2_CFG, "sse3" : SSE3_CFG, "nosse" : NOSSE_CFG}
if sys.platform =="darwin":
WINDOWS_PYTHON = {
+ "3.2": ["wine", os.environ['HOME'] + "/.wine/drive_c/Python32/python.exe"],
"3.1": ["wine", os.environ['HOME'] + "/.wine/drive_c/Python31/python.exe"],
"2.7": ["wine", os.environ['HOME'] + "/.wine/drive_c/Python27/python.exe"],
"2.6": ["wine", os.environ['HOME'] + "/.wine/drive_c/Python26/python.exe"],
@@ -129,7 +147,8 @@ if sys.platform =="darwin":
MAKENSIS = ["wine", "makensis"]
elif sys.platform == "win32":
WINDOWS_PYTHON = {
- "3.1": ["C:\Python31\python3.exe"],
+ "3.2": ["C:\Python32\python.exe"],
+ "3.1": ["C:\Python31\python.exe"],
"2.7": ["C:\Python27\python.exe"],
"2.6": ["C:\Python26\python.exe"],
"2.5": ["C:\Python25\python.exe"],
@@ -140,6 +159,7 @@ elif sys.platform == "win32":
MAKENSIS = ["makensis"]
else:
WINDOWS_PYTHON = {
+ "3.2": ["wine", os.environ['HOME'] + "/.wine/drive_c/Python32/python.exe"],
"3.1": ["wine", os.environ['HOME'] + "/.wine/drive_c/Python31/python.exe"],
"2.7": ["wine", os.environ['HOME'] + "/.wine/drive_c/Python27/python.exe"],
"2.6": ["wine", os.environ['HOME'] + "/.wine/drive_c/Python26/python.exe"],
@@ -148,10 +168,6 @@ else:
WINDOWS_ENV = os.environ
MAKENSIS = ["wine", "makensis"]
-# Start/end of the log (from git)
-LOG_START = 'svn/tags/1.4.0'
-LOG_END = 'master'
-RELEASE_NOTES = 'doc/release/1.5.0-notes.rst'
#-------------------
# Windows installers
@@ -211,7 +227,15 @@ def bdist_superpack(options):
os.remove(target)
if not os.path.exists(os.path.dirname(target)):
os.makedirs(os.path.dirname(target))
- os.rename(source, target)
+ try:
+ os.rename(source, target)
+ except OSError:
+ # When git is installed on OS X but not under Wine, the name of the
+ # .exe has "-Unknown" in it instead of the correct git revision.
+ # Try to fix this here:
+ revidx = source.index(".dev-") + 5
+ gitrev = source[revidx:revidx+7]
+ os.rename(source.replace(gitrev, "Unknown"), target)
bdist_wininst_arch(pyver, 'nosse')
copy_bdist("nosse")
@@ -378,11 +402,20 @@ def macosx_version():
def mpkg_name(pyver):
maj, min = macosx_version()[:2]
+ # Note that bdist_mpkg breaks this if building a dev version with a git
+ # commit string attached. make_fullplatcomponents() in
+ # bdist_mpkg/cmd_bdist_mpkg.py replaces '-' with '_', comment this out if
+ # needed.
return "numpy-%s-py%s-macosx%s.%s.mpkg" % (FULLVERSION, pyver, maj, min)
def _build_mpkg(pyver):
- ldflags = "-undefined dynamic_lookup -bundle -arch i386 -arch ppc -Wl,-search_paths_first"
+ # account for differences between Python 2.7.1 versions from python.org
+ if os.environ.get('MACOSX_DEPLOYMENT_TARGET', None) == "10.6":
+ ldflags = "-undefined dynamic_lookup -bundle -arch i386 -arch x86_64 -Wl,-search_paths_first"
+ else:
+ ldflags = "-undefined dynamic_lookup -bundle -arch i386 -arch ppc -Wl,-search_paths_first"
ldflags += " -L%s" % os.path.join(os.path.dirname(__file__), "build")
+
if pyver == "2.5":
sh("CC=gcc-4.0 LDFLAGS='%s' %s setupegg.py bdist_mpkg" % (ldflags, " ".join(MPKG_PYTHON[pyver])))
else:
@@ -428,7 +461,6 @@ def _create_dmg(pyver, src_dir, volname=None):
sh(" ".join(cmd))
@task
-@needs("pdf")
@cmdopts([("python-version=", "p", "python version")])
def dmg(options):
try:
@@ -437,11 +469,17 @@ def dmg(options):
pyver = DEFAULT_PYTHON
idirs = options.installers.installersdir
+ # Check if docs exist. If not, say so and quit.
+ ref = os.path.join(options.doc.destdir_pdf, "reference.pdf")
+ user = os.path.join(options.doc.destdir_pdf, "userguide.pdf")
+ if (not os.path.exists(ref)) or (not os.path.exists(user)):
+ warnings.warn("Docs need to be built first! Can't find them.")
+
+ # Build the mpkg package
call_task("clean")
_build_mpkg(pyver)
macosx_installer_dir = "tools/numpy-macosx-installer"
-
dmg = os.path.join(macosx_installer_dir, dmg_name(FULLVERSION, pyver))
if os.path.exists(dmg):
os.remove(dmg)
@@ -462,10 +500,7 @@ def dmg(options):
if os.path.exists(pdf_docs):
shutil.rmtree(pdf_docs)
os.makedirs(pdf_docs)
-
- user = os.path.join(options.doc.destdir_pdf, "userguide.pdf")
shutil.copy(user, os.path.join(pdf_docs, "userguide.pdf"))
- ref = os.path.join(options.doc.destdir_pdf, "reference.pdf")
shutil.copy(ref, os.path.join(pdf_docs, "reference.pdf"))
# Build the dmg
diff --git a/release.sh b/release.sh
index 060cbc526..bb5a375db 100644
--- a/release.sh
+++ b/release.sh
@@ -1,11 +1,41 @@
#! /bin/sh
-# script to build tarballs, mac os x and windows installers on mac os x
+# Script to build tarballs, windows and OS X installers on OS X
+
+# Note that we build the corresponding set of OS X binaries to the python.org
+# downloads, i.e. two versions for Python 2.7. The Intel 32/64-bit version is
+# for OS X 10.6+, the other dmg installers are for 10.3+ and are built on 10.5
+
+# bootstrap needed to ensure we build the docs from the right scipy version
paver bootstrap
source bootstrap/bin/activate
-CFLAGS="-arch x86_64" FFLAGS="-arch x86_64" python setupsconsegg.py install
+python setupsconsegg.py install
+
+# build docs
+paver pdf
+
+#------------------------------------------------------------------
+# Build tarballs, Windows and 64-bit OS X installers (on OS X 10.6)
+#------------------------------------------------------------------
paver sdist
-paver dmg -p 2.5
-paver dmg -p 2.6
-paver bdist_superpack -p 2.5
+
+export MACOSX_DEPLOYMENT_TARGET=10.6
+paver dmg -p 2.7 # 32/64-bit version
+
+paver bdist_superpack -p 3.2
+paver bdist_superpack -p 3.1
+paver bdist_superpack -p 2.7
paver bdist_superpack -p 2.6
+paver bdist_superpack -p 2.5
+
+
+#--------------------------------------------
+# Build 32-bit OS X installers (on OS X 10.5)
+#--------------------------------------------
+#export MACOSX_DEPLOYMENT_TARGET=10.3
+#paver dmg -p 2.6
+#paver dmg -p 2.7 # 32-bit version
+#export CC=/usr/bin/gcc-4.0 # necessary on 10.6, not sure about 10.5
+#paver dmg -p 2.5
+
+
paver write_release_and_log
diff --git a/setup.py b/setup.py
index 1083f0048..318633beb 100755
--- a/setup.py
+++ b/setup.py
@@ -33,6 +33,7 @@ Intended Audience :: Developers
License :: OSI Approved
Programming Language :: C
Programming Language :: Python
+Programming Language :: Python :: 3
Topic :: Software Development
Topic :: Scientific/Engineering
Operating System :: Microsoft :: Windows
@@ -53,8 +54,8 @@ CLASSIFIERS = filter(None, CLASSIFIERS.split('\n'))
AUTHOR = "Travis E. Oliphant, et.al."
AUTHOR_EMAIL = "oliphant@enthought.com"
PLATFORMS = ["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"]
-MAJOR = 2
-MINOR = 0
+MAJOR = 1
+MINOR = 6
MICRO = 0
ISRELEASED = False
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
@@ -93,6 +94,20 @@ if os.path.exists('MANIFEST'): os.remove('MANIFEST')
# a lot more robust than what was previously being used.
builtins.__NUMPY_SETUP__ = True
+# Construct full version info. Needs to be in setup.py namespace, otherwise it
+# can't be accessed from pavement.py at build time.
+FULLVERSION = VERSION
+if not ISRELEASED:
+ if os.path.exists('.git'):
+ GIT_REVISION = git_version()
+ elif os.path.exists('numpy/version.py'):
+ # must be a source distribution, use existing version file
+ from numpy.version import git_revision as GIT_REVISION
+ else:
+ GIT_REVISION = "Unknown"
+
+ FULLVERSION += '.dev-' + GIT_REVISION[:7]
+
def write_version_py(filename='numpy/version.py'):
cnt = """
# THIS FILE IS GENERATED FROM NUMPY SETUP.PY
@@ -105,22 +120,10 @@ release = %(isrelease)s
if not release:
version = full_version
"""
- FULL_VERSION = VERSION
- if not ISRELEASED:
- if os.path.exists('.git'):
- GIT_REVISION = git_version()
- elif os.path.exists(filename):
- # must be a source distribution, use existing version file
- from numpy.version import git_revision as GIT_REVISION
- else:
- GIT_REVISION = "Unknown"
-
- FULL_VERSION += '.dev-' + GIT_REVISION[:7]
-
a = open(filename, 'w')
try:
a.write(cnt % {'version': VERSION,
- 'full_version' : FULL_VERSION,
+ 'full_version' : FULLVERSION,
'git_revision' : GIT_REVISION,
'isrelease': str(ISRELEASED)})
finally:
diff --git a/site.cfg.example b/site.cfg.example
index 53f282998..89d108739 100644
--- a/site.cfg.example
+++ b/site.cfg.example
@@ -24,11 +24,15 @@
# library_dirs
# List of directories to add to the library search path when compiling
# extensions with this dependency. Use the character given by os.pathsep
-# to separate the items in the list. On UN*X-type systems (Linux, FreeBSD,
-# OS X):
+# to separate the items in the list. Note that this character is known to
+# vary on some unix-like systems; if a colon does not work, try a comma.
+# This also applies to include_dirs and src_dirs (see below).
+# On UN*X-type systems (OS X, most BSD and Linux systems):
# library_dirs = /usr/lib:/usr/local/lib
# On Windows:
# library_dirs = c:\mingw\lib,c:\atlas\lib
+# On some BSD and Linux systems:
+# library_dirs = /usr/lib,/usr/local/lib
#
# include_dirs
# List of directories to add to the header file earch path.
@@ -86,15 +90,19 @@
#[lapack_opt]
#libraries = lapack, ptf77blas, ptcblas, atlas
+
# UMFPACK
# -------
-# The UMFPACK library is used to factor large sparse matrices. It, in turn,
-# depends on the AMD library for reordering the matrices for better performance.
-# Note that the AMD library has nothing to do with AMD (Advanced Micro Devices),
-# the CPU company.
+# The UMFPACK library is used in scikits.umfpack to factor large sparse matrices.
+# It, in turn, depends on the AMD library for reordering the matrices for
+# better performance. Note that the AMD library has nothing to do with AMD
+# (Advanced Micro Devices), the CPU company.
+#
+# UMFPACK is not needed for numpy or scipy.
#
# http://www.cise.ufl.edu/research/sparse/umfpack/
# http://www.cise.ufl.edu/research/sparse/amd/
+# http://scikits.appspot.com/umfpack
#
#[amd]
#amd_libs = amd
@@ -102,9 +110,11 @@
#[umfpack]
#umfpack_libs = umfpack
+
# FFT libraries
# -------------
# There are two FFT libraries that we can configure here: FFTW (2 and 3) and djbfft.
+# Note that these libraries are not needed for numpy or scipy.
#
# http://fftw.org/
# http://cr.yp.to/djbfft.html