diff options
-rw-r--r-- | LICENSES_bundled.txt | 2 | ||||
-rw-r--r-- | doc/source/reference/arrays.dtypes.rst | 1 | ||||
-rw-r--r-- | doc/source/reference/c-api.types-and-structures.rst | 122 | ||||
-rw-r--r-- | numpy/core/_add_newdocs.py | 119 | ||||
-rw-r--r-- | numpy/core/src/multiarray/dragon4.c | 38 | ||||
-rw-r--r-- | numpy/core/src/multiarray/dragon4.h | 38 | ||||
-rw-r--r-- | numpy/random/src/distributions/distributions.c | 8 | ||||
-rw-r--r-- | numpy/random/src/xoshiro256/xoshiro256.c | 3 | ||||
-rw-r--r-- | numpy/random/src/xoshiro512/xoshiro512.c | 3 |
9 files changed, 250 insertions, 84 deletions
diff --git a/LICENSES_bundled.txt b/LICENSES_bundled.txt index 03d22521a..ea349c7ee 100644 --- a/LICENSES_bundled.txt +++ b/LICENSES_bundled.txt @@ -23,5 +23,5 @@ License: BSD derived Name: dragon4 Files: numpy/core/src/multiarray/dragon4.c -License: One of a kind +License: MIT For license text, see numpy/core/src/multiarray/dragon4.c diff --git a/doc/source/reference/arrays.dtypes.rst b/doc/source/reference/arrays.dtypes.rst index b55feb247..ab743a8ee 100644 --- a/doc/source/reference/arrays.dtypes.rst +++ b/doc/source/reference/arrays.dtypes.rst @@ -538,6 +538,7 @@ Attributes providing additional information: dtype.isnative dtype.descr dtype.alignment + dtype.base Methods diff --git a/doc/source/reference/c-api.types-and-structures.rst b/doc/source/reference/c-api.types-and-structures.rst index b72d9f902..a716b5a06 100644 --- a/doc/source/reference/c-api.types-and-structures.rst +++ b/doc/source/reference/c-api.types-and-structures.rst @@ -57,8 +57,8 @@ types are place holders that allow the array scalars to fit into a hierarchy of actual Python types. -PyArray_Type ------------- +PyArray_Type and PyArrayObject +------------------------------ .. c:var:: PyArray_Type @@ -74,7 +74,7 @@ PyArray_Type subclasses) will have this structure. For future compatibility, these structure members should normally be accessed using the provided macros. If you need a shorter name, then you can make use - of :c:type:`NPY_AO` which is defined to be equivalent to + of :c:type:`NPY_AO` (deprecated) which is defined to be equivalent to :c:type:`PyArrayObject`. .. code-block:: c @@ -91,7 +91,7 @@ PyArray_Type PyObject *weakreflist; } PyArrayObject; -.. c:macro: PyArrayObject.PyObject_HEAD +.. c:macro:: PyArrayObject.PyObject_HEAD This is needed by all Python objects. It consists of (at least) a reference count member ( ``ob_refcnt`` ) and a pointer to the @@ -130,14 +130,16 @@ PyArray_Type .. c:member:: PyObject *PyArrayObject.base This member is used to hold a pointer to another Python object that - is related to this array. There are two use cases: 1) If this array - does not own its own memory, then base points to the Python object - that owns it (perhaps another array object), 2) If this array has - the (deprecated) :c:data:`NPY_ARRAY_UPDATEIFCOPY` or - :c:data:NPY_ARRAY_WRITEBACKIFCOPY`: flag set, then this array is - a working copy of a "misbehaved" array. When - ``PyArray_ResolveWritebackIfCopy`` is called, the array pointed to by base - will be updated with the contents of this array. + is related to this array. There are two use cases: + + - If this array does not own its own memory, then base points to the + Python object that owns it (perhaps another array object) + - If this array has the (deprecated) :c:data:`NPY_ARRAY_UPDATEIFCOPY` or + :c:data:`NPY_ARRAY_WRITEBACKIFCOPY` flag set, then this array is a working + copy of a "misbehaved" array. + + When ``PyArray_ResolveWritebackIfCopy`` is called, the array pointed to + by base will be updated with the contents of this array. .. c:member:: PyArray_Descr *PyArrayObject.descr @@ -163,8 +165,8 @@ PyArray_Type weakref module). -PyArrayDescr_Type ------------------ +PyArrayDescr_Type and PyArray_Descr +----------------------------------- .. c:var:: PyArrayDescr_Type @@ -253,11 +255,13 @@ PyArrayDescr_Type .. c:var:: NPY_ITEM_REFCOUNT - .. c:var:: NPY_ITEM_HASOBJECT - Indicates that items of this data-type must be reference counted (using :c:func:`Py_INCREF` and :c:func:`Py_DECREF` ). + .. c:var:: NPY_ITEM_HASOBJECT + + Same as :c:data:`NPY_ITEM_REFCOUNT`. + .. c:var:: NPY_LIST_PICKLE Indicates arrays of this data-type must be converted to a list @@ -676,25 +680,28 @@ PyArrayDescr_Type The :c:data:`PyArray_Type` typeobject implements many of the features of -Python objects including the tp_as_number, tp_as_sequence, -tp_as_mapping, and tp_as_buffer interfaces. The rich comparison -(tp_richcompare) is also used along with new-style attribute lookup -for methods (tp_methods) and properties (tp_getset). The -:c:data:`PyArray_Type` can also be sub-typed. +:c:type:`Python objects <PyTypeObject>` including the :c:member:`tp_as_number +<PyTypeObject.tp_as_number>`, :c:member:`tp_as_sequence +<PyTypeObject.tp_as_sequence>`, :c:member:`tp_as_mapping +<PyTypeObject.tp_as_mapping>`, and :c:member:`tp_as_buffer +<PyTypeObject.tp_as_buffer>` interfaces. The :c:type:`rich comparison +<richcmpfunc>`) is also used along with new-style attribute lookup for +member (:c:member:`tp_members <PyTypeObject.tp_members>`) and properties +(:c:member:`tp_getset <PyTypeObject.tp_getset>`). +The :c:data:`PyArray_Type` can also be sub-typed. .. tip:: - The tp_as_number methods use a generic approach to call whatever - function has been registered for handling the operation. The - function PyNumeric_SetOps(..) can be used to register functions to - handle particular mathematical operations (for all arrays). When - the umath module is imported, it sets the numeric operations for - all arrays to the corresponding ufuncs. The tp_str and tp_repr - methods can also be altered using PyString_SetStringFunction(...). + The ``tp_as_number`` methods use a generic approach to call whatever + function has been registered for handling the operation. When the + ``_multiarray_umath module`` is imported, it sets the numeric operations + for all arrays to the corresponding ufuncs. This choice can be changed with + :c:func:`PyUFunc_ReplaceLoopBySignature` The ``tp_str`` and ``tp_repr`` + methods can also be altered using :c:func:`PyArray_SetStringFunction`. -PyUFunc_Type ------------- +PyUFunc_Type and PyUFuncObject +------------------------------ .. c:var:: PyUFunc_Type @@ -786,8 +793,8 @@ PyUFunc_Type the identity for this operation. It is only used for a reduce-like call on an empty array. - .. c:member:: void PyUFuncObject.functions(char** args, npy_intp* dims, - npy_intp* steps, void* extradata) + .. c:member:: void PyUFuncObject.functions( \ + char** args, npy_intp* dims, npy_intp* steps, void* extradata) An array of function pointers --- one for each data type supported by the ufunc. This is the vector loop that is called @@ -932,8 +939,8 @@ PyUFunc_Type - :c:data:`UFUNC_CORE_DIM_SIZE_INFERRED` if the dim size will be determined from the operands and not from a :ref:`frozen <frozen>` signature -PyArrayIter_Type ----------------- +PyArrayIter_Type and PyArrayIterObject +-------------------------------------- .. c:var:: PyArrayIter_Type @@ -1042,8 +1049,8 @@ with it through the use of the macros :c:func:`PyArray_ITER_NEXT` (it), :c:type:`PyArrayIterObject *`. -PyArrayMultiIter_Type ---------------------- +PyArrayMultiIter_Type and PyArrayMultiIterObject +------------------------------------------------ .. c:var:: PyArrayMultiIter_Type @@ -1104,8 +1111,8 @@ PyArrayMultiIter_Type arrays to be broadcast together. On return, the iterators are adjusted for broadcasting. -PyArrayNeighborhoodIter_Type ----------------------------- +PyArrayNeighborhoodIter_Type and PyArrayNeighborhoodIterObject +-------------------------------------------------------------- .. c:var:: PyArrayNeighborhoodIter_Type @@ -1118,8 +1125,33 @@ PyArrayNeighborhoodIter_Type :c:data:`PyArrayNeighborhoodIter_Type` is the :c:type:`PyArrayNeighborhoodIterObject`. -PyArrayFlags_Type ------------------ + .. code-block:: c + + typedef struct { + PyObject_HEAD + int nd_m1; + npy_intp index, size; + npy_intp coordinates[NPY_MAXDIMS] + npy_intp dims_m1[NPY_MAXDIMS]; + npy_intp strides[NPY_MAXDIMS]; + npy_intp backstrides[NPY_MAXDIMS]; + npy_intp factors[NPY_MAXDIMS]; + PyArrayObject *ao; + char *dataptr; + npy_bool contiguous; + npy_intp bounds[NPY_MAXDIMS][2]; + npy_intp limits[NPY_MAXDIMS][2]; + npy_intp limits_sizes[NPY_MAXDIMS]; + npy_iter_get_dataptr_t translate; + npy_intp nd; + npy_intp dimensions[NPY_MAXDIMS]; + PyArrayIterObject* _internal_iter; + char* constant; + int mode; + } PyArrayNeighborhoodIterObject; + +PyArrayFlags_Type and PyArrayFlagsObject +---------------------------------------- .. c:var:: PyArrayFlags_Type @@ -1129,6 +1161,16 @@ PyArrayFlags_Type attributes or by accessing them as if the object were a dictionary with the flag names as entries. +.. c:type:: PyArrayFlagsObject + + .. code-block:: c + + typedef struct PyArrayFlagsObject { + PyObject_HEAD + PyObject *arr; + int flags; + } PyArrayFlagsObject; + ScalarArrayTypes ---------------- diff --git a/numpy/core/_add_newdocs.py b/numpy/core/_add_newdocs.py index 5a3ec0dab..fafe29482 100644 --- a/numpy/core/_add_newdocs.py +++ b/numpy/core/_add_newdocs.py @@ -5390,6 +5390,17 @@ add_newdoc('numpy.core.multiarray', 'dtype', ('alignment', More information is available in the C-API section of the manual. + Examples + -------- + + >>> x = np.dtype('i4') + >>> x.alignment + 4 + + >>> x = np.dtype(float) + >>> x.alignment + 8 + """)) add_newdoc('numpy.core.multiarray', 'dtype', ('byteorder', @@ -5436,7 +5447,16 @@ add_newdoc('numpy.core.multiarray', 'dtype', ('byteorder', """)) add_newdoc('numpy.core.multiarray', 'dtype', ('char', - """A unique character code for each of the 21 different built-in types.""")) + """A unique character code for each of the 21 different built-in types. + + Examples + -------- + + >>> x = np.dtype(float) + >>> x.char + 'd' + + """)) add_newdoc('numpy.core.multiarray', 'dtype', ('descr', """ @@ -5447,6 +5467,18 @@ add_newdoc('numpy.core.multiarray', 'dtype', ('descr', Warning: This attribute exists specifically for `__array_interface__`, and is not a datatype description compatible with `np.dtype`. + + Examples + -------- + + >>> x = np.dtype(float) + >>> x.descr + [('', '<f8')] + + >>> dt = np.dtype([('name', np.str_, 16), ('grades', np.float64, (2,))]) + >>> dt.descr + [('name', '<U16'), ('grades', '<f8', (2,))] + """)) add_newdoc('numpy.core.multiarray', 'dtype', ('fields', @@ -5487,6 +5519,18 @@ add_newdoc('numpy.core.multiarray', 'dtype', ('flags', of these flags is in C-API documentation; they are largely useful for user-defined data-types. + The following example demonstrates that operations on this particular + dtype requires Python C-API. + + Examples + -------- + + >>> x = np.dtype([('a', np.int32, 8), ('b', np.float64, 6)]) + >>> x.flags + 16 + >>> np.core.multiarray.NEEDS_PYAPI + 16 + """)) add_newdoc('numpy.core.multiarray', 'dtype', ('hasobject', @@ -5544,6 +5588,7 @@ add_newdoc('numpy.core.multiarray', 'dtype', ('isalignedstruct', field alignment. This flag is sticky, so when combining multiple structs together, it is preserved and produces new dtypes which are also aligned. + """)) add_newdoc('numpy.core.multiarray', 'dtype', ('itemsize', @@ -5553,6 +5598,19 @@ add_newdoc('numpy.core.multiarray', 'dtype', ('itemsize', For 18 of the 21 types this number is fixed by the data-type. For the flexible data-types, this number can be anything. + Examples + -------- + + >>> arr = np.array([[1, 2], [3, 4]]) + >>> arr.dtype + dtype('int64') + >>> arr.itemsize + 8 + + >>> dt = np.dtype([('name', np.str_, 16), ('grades', np.float64, (2,))]) + >>> dt.itemsize + 80 + """)) add_newdoc('numpy.core.multiarray', 'dtype', ('kind', @@ -5573,6 +5631,19 @@ add_newdoc('numpy.core.multiarray', 'dtype', ('kind', V void = ====================== + Examples + -------- + + >>> dt = np.dtype('i4') + >>> dt.kind + 'i' + >>> dt = np.dtype('f8') + >>> dt.kind + 'f' + >>> dt = np.dtype([('field1', 'f8')]) + >>> dt.kind + 'V' + """)) add_newdoc('numpy.core.multiarray', 'dtype', ('name', @@ -5581,6 +5652,16 @@ add_newdoc('numpy.core.multiarray', 'dtype', ('name', Un-sized flexible data-type objects do not have this attribute. + Examples + -------- + + >>> x = np.dtype(float) + >>> x.name + 'float64' + >>> x = np.dtype([('a', np.int32, 8), ('b', np.float64, 6)]) + >>> x.name + 'void640' + """)) add_newdoc('numpy.core.multiarray', 'dtype', ('names', @@ -5604,6 +5685,17 @@ add_newdoc('numpy.core.multiarray', 'dtype', ('num', These are roughly ordered from least-to-most precision. + Examples + -------- + + >>> dt = np.dtype(str) + >>> dt.num + 19 + + >>> dt = np.dtype(float) + >>> dt.num + 12 + """)) add_newdoc('numpy.core.multiarray', 'dtype', ('shape', @@ -5611,6 +5703,17 @@ add_newdoc('numpy.core.multiarray', 'dtype', ('shape', Shape tuple of the sub-array if this data type describes a sub-array, and ``()`` otherwise. + Examples + -------- + + >>> dt = np.dtype(('i4', 4)) + >>> dt.shape + (4,) + + >>> dt = np.dtype(('i4', (2, 3))) + >>> dt.shape + (2, 3) + """)) add_newdoc('numpy.core.multiarray', 'dtype', ('ndim', @@ -5620,6 +5723,20 @@ add_newdoc('numpy.core.multiarray', 'dtype', ('ndim', .. versionadded:: 1.13.0 + Examples + -------- + >>> x = np.dtype(float) + >>> x.ndim + 0 + + >>> x = np.dtype((float, 8)) + >>> x.ndim + 1 + + >>> x = np.dtype(('i4', (3, 4))) + >>> x.ndim + 2 + """)) add_newdoc('numpy.core.multiarray', 'dtype', ('str', diff --git a/numpy/core/src/multiarray/dragon4.c b/numpy/core/src/multiarray/dragon4.c index 8d52672e3..1694596e9 100644 --- a/numpy/core/src/multiarray/dragon4.c +++ b/numpy/core/src/multiarray/dragon4.c @@ -1,31 +1,33 @@ /* * Copyright (c) 2014 Ryan Juckett - * http://www.ryanjuckett.com/ * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /* * This file contains a modified version of Ryan Juckett's Dragon4 - * implementation, which has been ported from C++ to C and which has + * implementation, obtained from http://www.ryanjuckett.com, + * which has been ported from C++ to C and which has * modifications specific to printing floats in numpy. + * + * Ryan Juckett's original code was under the Zlib license; he gave numpy + * permission to include it under the MIT license instead. */ #include "dragon4.h" diff --git a/numpy/core/src/multiarray/dragon4.h b/numpy/core/src/multiarray/dragon4.h index 2b8b4cef4..3a99bde6c 100644 --- a/numpy/core/src/multiarray/dragon4.h +++ b/numpy/core/src/multiarray/dragon4.h @@ -1,31 +1,33 @@ /* * Copyright (c) 2014 Ryan Juckett - * http://www.ryanjuckett.com/ * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /* * This file contains a modified version of Ryan Juckett's Dragon4 - * implementation, which has been ported from C++ to C and which has + * implementation, obtained from http://www.ryanjuckett.com, + * which has been ported from C++ to C and which has * modifications specific to printing floats in numpy. + * + * Ryan Juckett's original code was under the Zlib license; he gave numpy + * permission to include it under the MIT license instead. */ #ifndef _NPY_DRAGON4_H_ diff --git a/numpy/random/src/distributions/distributions.c b/numpy/random/src/distributions/distributions.c index c0550ad8e..65257ecbf 100644 --- a/numpy/random/src/distributions/distributions.c +++ b/numpy/random/src/distributions/distributions.c @@ -170,7 +170,7 @@ float random_standard_exponential_zig_f(bitgen_t *bitgen_state) { static NPY_INLINE double next_gauss_zig(bitgen_t *bitgen_state) { uint64_t r; int sign; - int64_t rabs; + uint64_t rabs; int idx; double x, xx, yy; for (;;) { @@ -179,7 +179,7 @@ static NPY_INLINE double next_gauss_zig(bitgen_t *bitgen_state) { idx = r & 0xff; r >>= 8; sign = r & 0x1; - rabs = (int64_t)((r >> 1) & 0x000fffffffffffff); + rabs = (r >> 1) & 0x000fffffffffffff; x = rabs * wi_double[idx]; if (sign & 0x1) x = -x; @@ -216,7 +216,7 @@ void random_gauss_zig_fill(bitgen_t *bitgen_state, npy_intp cnt, double *out) { float random_gauss_zig_f(bitgen_t *bitgen_state) { uint32_t r; int sign; - int32_t rabs; + uint32_t rabs; int idx; float x, xx, yy; for (;;) { @@ -224,7 +224,7 @@ float random_gauss_zig_f(bitgen_t *bitgen_state) { r = next_uint32(bitgen_state); idx = r & 0xff; sign = (r >> 8) & 0x1; - rabs = (int32_t)((r >> 9) & 0x0007fffff); + rabs = (r >> 9) & 0x0007fffff; x = rabs * wi_float[idx]; if (sign & 0x1) x = -x; diff --git a/numpy/random/src/xoshiro256/xoshiro256.c b/numpy/random/src/xoshiro256/xoshiro256.c index f5cda2721..a9ac49aa6 100644 --- a/numpy/random/src/xoshiro256/xoshiro256.c +++ b/numpy/random/src/xoshiro256/xoshiro256.c @@ -6,6 +6,7 @@ worldwide. This software is distributed without any warranty. See <http://creativecommons.org/publicdomain/zero/1.0/>. */ +#include <stddef.h> #include "xoshiro256.h" /* This is xoshiro256** 1.0, our all-purpose, rock-solid generator. It has @@ -29,7 +30,7 @@ extern NPY_INLINE uint32_t xoshiro256_next32(xoshiro256_state *state); void xoshiro256_jump(xoshiro256_state *state) { - int i, b; + size_t i, b; static const uint64_t JUMP[] = {0x180ec6d33cfd0aba, 0xd5a61266f0c9392c, 0xa9582618e03fc9aa, 0x39abdc4529b1661c}; uint64_t s0 = 0; diff --git a/numpy/random/src/xoshiro512/xoshiro512.c b/numpy/random/src/xoshiro512/xoshiro512.c index 9fdbed125..4f4af86f0 100644 --- a/numpy/random/src/xoshiro512/xoshiro512.c +++ b/numpy/random/src/xoshiro512/xoshiro512.c @@ -6,6 +6,7 @@ worldwide. This software is distributed without any warranty. See <http://creativecommons.org/publicdomain/zero/1.0/>. */ +#include <stddef.h> #include "xoshiro512.h" /* This is xoshiro512** 1.0, an all-purpose, rock-solid generator. It has @@ -32,7 +33,7 @@ static uint64_t s_placeholder[8]; void xoshiro512_jump(xoshiro512_state *state) { - int i, b, w; + size_t i, b, w; static const uint64_t JUMP[] = {0x33ed89b6e7a353f9, 0x760083d7955323be, 0x2837f2fbb5f22fae, 0x4b8c5674d309511c, 0xb11ac47a7ba28c25, 0xf1be7667092bcc1c, |