Metadata-Version: 1.2
Name: numpy
-Version: 1.21.2
+Version: 1.21.3
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
--- /dev/null
+
+Contributors
+============
+
+A total of 7 people contributed to this release. People with a "+" by their
+names contributed a patch for the first time.
+
+* Aaron Meurer
+* Bas van Beek
+* Charles Harris
+* Developer-Ecosystem-Engineering +
+* Kevin Sheppard
+* Sebastian Berg
+* Warren Weckesser
+
+Pull requests merged
+====================
+
+A total of 8 pull requests were merged for this release.
+
+* `#19745 <https://github.com/numpy/numpy/pull/19745>`__: ENH: Add dtype-support to 3 `generic`/`ndarray` methods
+* `#19955 <https://github.com/numpy/numpy/pull/19955>`__: BUG: Resolve Divide by Zero on Apple silicon + test failures...
+* `#19958 <https://github.com/numpy/numpy/pull/19958>`__: MAINT: Mark type-check-only ufunc subclasses as ufunc aliases...
+* `#19994 <https://github.com/numpy/numpy/pull/19994>`__: BUG: np.tan(np.inf) test failure
+* `#20080 <https://github.com/numpy/numpy/pull/20080>`__: BUG: Correct incorrect advance in PCG with emulated int128
+* `#20081 <https://github.com/numpy/numpy/pull/20081>`__: BUG: Fix NaT handling in the PyArray_CompareFunc for datetime...
+* `#20082 <https://github.com/numpy/numpy/pull/20082>`__: DOC: Ensure that we add documentation also as to the dict for...
+* `#20106 <https://github.com/numpy/numpy/pull/20106>`__: BUG: core: result_type(0, np.timedelta64(4)) would seg. fault.
--- /dev/null
+Corrected ``advance`` in ``PCG64DSXM`` and ``PCG64``
+----------------------------------------------------
+Fixed a bug in the ``advance`` method of ``PCG64DSXM`` and ``PCG64``. The bug only
+affects results when the step was larger than :math:`2^{64}` on platforms
+that do not support 128-bit integers(e.g., Windows and 32-bit Linux).
.. toctree::
:maxdepth: 3
+ 1.21.3 <release/1.21.3-notes>
1.21.2 <release/1.21.2-notes>
1.21.1 <release/1.21.1-notes>
1.21.0 <release/1.21.0-notes>
--- /dev/null
+.. currentmodule:: numpy
+
+==========================
+NumPy 1.21.3 Release Notes
+==========================
+
+The NumPy 1.21.3 is a maintenance release the fixes a few bugs discovered after
+1.21.2. It also provides 64 bit Python 3.10.0 wheels. Note a few oddities about
+Python 3.10:
+
+* There are no 32 bit wheels for Windows, Mac, or Linux.
+* The Mac Intel builds are only available in universal2 wheels.
+
+The Python versions supported in this release are 3.7-3.10. If you want to
+compile your own version using gcc-11 you will need to use gcc-11.2+ to avoid
+problems.
+
+Contributors
+============
+
+A total of 7 people contributed to this release. People with a "+" by their
+names contributed a patch for the first time.
+
+* Aaron Meurer
+* Bas van Beek
+* Charles Harris
+* Developer-Ecosystem-Engineering +
+* Kevin Sheppard
+* Sebastian Berg
+* Warren Weckesser
+
+Pull requests merged
+====================
+
+A total of 8 pull requests were merged for this release.
+
+* `#19745 <https://github.com/numpy/numpy/pull/19745>`__: ENH: Add dtype-support to 3 ```generic``/``ndarray`` methods
+* `#19955 <https://github.com/numpy/numpy/pull/19955>`__: BUG: Resolve Divide by Zero on Apple silicon + test failures...
+* `#19958 <https://github.com/numpy/numpy/pull/19958>`__: MAINT: Mark type-check-only ufunc subclasses as ufunc aliases...
+* `#19994 <https://github.com/numpy/numpy/pull/19994>`__: BUG: np.tan(np.inf) test failure
+* `#20080 <https://github.com/numpy/numpy/pull/20080>`__: BUG: Correct incorrect advance in PCG with emulated int128
+* `#20081 <https://github.com/numpy/numpy/pull/20081>`__: BUG: Fix NaT handling in the PyArray_CompareFunc for datetime...
+* `#20082 <https://github.com/numpy/numpy/pull/20082>`__: DOC: Ensure that we add documentation also as to the dict for...
+* `#20106 <https://github.com/numpy/numpy/pull/20106>`__: BUG: core: result_type(0, np.timedelta64(4)) would seg. fault.
def __deepcopy__(self: _ArraySelf, __memo: Optional[dict] = ...) -> _ArraySelf: ...
def __eq__(self, other): ...
def __ne__(self, other): ...
- def astype(
- self: _ArraySelf,
- dtype: DTypeLike,
- order: _OrderKACF = ...,
- casting: _Casting = ...,
- subok: bool = ...,
- copy: bool = ...,
- ) -> _ArraySelf: ...
def copy(self: _ArraySelf, order: _OrderKACF = ...) -> _ArraySelf: ...
def dump(self, file: str) -> None: ...
def dumps(self) -> bytes: ...
- def getfield(
- self: _ArraySelf, dtype: DTypeLike, offset: int = ...
- ) -> _ArraySelf: ...
def tobytes(self, order: _OrderKACF = ...) -> bytes: ...
# NOTE: `tostring()` is deprecated and therefore excluded
# def tostring(self, order=...): ...
) -> None: ...
# generics and 0d arrays return builtin scalars
def tolist(self) -> Any: ...
- @overload
- def view(self, type: Type[_NdArraySubClass]) -> _NdArraySubClass: ...
- @overload
- def view(self: _ArraySelf, dtype: DTypeLike = ...) -> _ArraySelf: ...
- @overload
- def view(
- self, dtype: DTypeLike, type: Type[_NdArraySubClass]
- ) -> _NdArraySubClass: ...
# TODO: Add proper signatures
def __getitem__(self, key) -> Any: ...
_2Tuple = Tuple[_T, _T]
_Casting = L["no", "equiv", "safe", "same_kind", "unsafe"]
+_DTypeLike = Union[
+ dtype[_ScalarType],
+ Type[_ScalarType],
+ _SupportsDType[dtype[_ScalarType]],
+]
+
_ArrayUInt_co = NDArray[Union[bool_, unsignedinteger[Any]]]
_ArrayInt_co = NDArray[Union[bool_, integer[Any]]]
_ArrayFloat_co = NDArray[Union[bool_, integer[Any], floating[Any]]]
self, *shape: SupportsIndex, order: _OrderACF = ...
) -> ndarray[Any, _DType_co]: ...
+ @overload
+ def astype(
+ self,
+ dtype: _DTypeLike[_ScalarType],
+ order: _OrderKACF = ...,
+ casting: _Casting = ...,
+ subok: bool = ...,
+ copy: bool = ...,
+ ) -> NDArray[_ScalarType]: ...
+ @overload
+ def astype(
+ self,
+ dtype: DTypeLike,
+ order: _OrderKACF = ...,
+ casting: _Casting = ...,
+ subok: bool = ...,
+ copy: bool = ...,
+ ) -> NDArray[Any]: ...
+
+ @overload
+ def view(self: _ArraySelf) -> _ArraySelf: ...
+ @overload
+ def view(self, type: Type[_NdArraySubClass]) -> _NdArraySubClass: ...
+ @overload
+ def view(self, dtype: _DTypeLike[_ScalarType]) -> NDArray[_ScalarType]: ...
+ @overload
+ def view(self, dtype: DTypeLike) -> NDArray[Any]: ...
+ @overload
+ def view(
+ self,
+ dtype: DTypeLike,
+ type: Type[_NdArraySubClass],
+ ) -> _NdArraySubClass: ...
+
+ @overload
+ def getfield(
+ self,
+ dtype: _DTypeLike[_ScalarType],
+ offset: SupportsIndex = ...
+ ) -> NDArray[_ScalarType]: ...
+ @overload
+ def getfield(
+ self,
+ dtype: DTypeLike,
+ offset: SupportsIndex = ...
+ ) -> NDArray[Any]: ...
+
# Dispatch to the underlying `generic` via protocols
def __int__(
self: ndarray[Any, dtype[SupportsInt]], # type: ignore[type-var]
def byteswap(self: _ScalarType, inplace: L[False] = ...) -> _ScalarType: ...
@property
def flat(self: _ScalarType) -> flatiter[ndarray[Any, dtype[_ScalarType]]]: ...
+
+ @overload
+ def astype(
+ self,
+ dtype: _DTypeLike[_ScalarType],
+ order: _OrderKACF = ...,
+ casting: _Casting = ...,
+ subok: bool = ...,
+ copy: bool = ...,
+ ) -> _ScalarType: ...
+ @overload
+ def astype(
+ self,
+ dtype: DTypeLike,
+ order: _OrderKACF = ...,
+ casting: _Casting = ...,
+ subok: bool = ...,
+ copy: bool = ...,
+ ) -> Any: ...
+
+ # NOTE: `view` will perform a 0D->scalar cast,
+ # thus the array `type` is irrelevant to the output type
+ @overload
+ def view(
+ self: _ScalarType,
+ type: Type[ndarray[Any, Any]] = ...,
+ ) -> _ScalarType: ...
+ @overload
+ def view(
+ self,
+ dtype: _DTypeLike[_ScalarType],
+ type: Type[ndarray[Any, Any]] = ...,
+ ) -> _ScalarType: ...
+ @overload
+ def view(
+ self,
+ dtype: DTypeLike,
+ type: Type[ndarray[Any, Any]] = ...,
+ ) -> Any: ...
+
+ @overload
+ def getfield(
+ self,
+ dtype: _DTypeLike[_ScalarType],
+ offset: SupportsIndex = ...
+ ) -> _ScalarType: ...
+ @overload
+ def getfield(
+ self,
+ dtype: DTypeLike,
+ offset: SupportsIndex = ...
+ ) -> Any: ...
+
def item(
self,
__args: Union[L[0], Tuple[()], Tuple[L[0]]] = ...,
version_json = '''
{
- "date": "2021-08-15T12:15:47-0600",
+ "date": "2021-10-19T18:45:47-0600",
"dirty": false,
"error": null,
- "full-revisionid": "2fe48d2d98a85c8ea3f3d5caffd952ea69e99335",
- "version": "1.21.2"
+ "full-revisionid": "d4d0584ccb508cad69288b504e6c8b04aa0d5caf",
+ "version": "1.21.3"
}
''' # END VERSION_JSON
/**begin repeat
* #TYPE = BYTE, UBYTE, SHORT, USHORT, INT, UINT,
- * LONG, ULONG, LONGLONG, ULONGLONG,
- * DATETIME, TIMEDELTA#
+ * LONG, ULONG, LONGLONG, ULONGLONG#
* #type = npy_byte, npy_ubyte, npy_short, npy_ushort, npy_int, npy_uint,
- * npy_long, npy_ulong, npy_longlong, npy_ulonglong,
- * npy_datetime, npy_timedelta#
+ * npy_long, npy_ulong, npy_longlong, npy_ulonglong#
*/
static int
/**end repeat**/
+/**begin repeat
+ * #TYPE = DATETIME, TIMEDELTA#
+ * #type = npy_datetime, npy_timedelta#
+ */
+
+static int
+@TYPE@_compare(@type@ *pa, @type@ *pb)
+{
+ const @type@ a = *pa;
+ const @type@ b = *pb;
+ int ret;
+
+ if (a == NPY_DATETIME_NAT) {
+ if (b == NPY_DATETIME_NAT) {
+ ret = 0;
+ }
+ else {
+ ret = 1;
+ }
+ }
+ else if (b == NPY_DATETIME_NAT) {
+ ret = -1;
+ }
+ else {
+ ret = a < b ? -1 : a == b ? 0 : 1;
+ }
+ return ret;
+}
+
+/**end repeat**/
+
static int
HALF_compare (npy_half *pa, npy_half *pb, PyArrayObject *NPY_UNUSED(ap))
{
PyCFunctionObject *new = (PyCFunctionObject *)obj;
_ADDDOC(new->m_ml->ml_doc, new->m_ml->ml_name);
}
- else if (Py_TYPE(obj) == &PyType_Type) {
+ else if (PyObject_TypeCheck(obj, &PyType_Type)) {
+ /*
+ * We add it to both `tp_doc` and `__doc__` here. Note that in theory
+ * `tp_doc` extracts the signature line, but we currently do not use
+ * it. It may make sense to only add it as `__doc__` and
+ * `__text_signature__` to the dict in the future.
+ * The dictionary path is only necessary for heaptypes (currently not
+ * used) and metaclasses.
+ * If `__doc__` as stored in `tp_dict` is None, we assume this was
+ * filled in by `PyType_Ready()` and should also be replaced.
+ */
PyTypeObject *new = (PyTypeObject *)obj;
_ADDDOC(new->tp_doc, new->tp_name);
+ if (new->tp_dict != NULL && PyDict_CheckExact(new->tp_dict) &&
+ PyDict_GetItemString(new->tp_dict, "__doc__") == Py_None) {
+ /* Warning: Modifying `tp_dict` is not generally safe! */
+ if (PyDict_SetItemString(new->tp_dict, "__doc__", str) < 0) {
+ return NULL;
+ }
+ }
}
else if (Py_TYPE(obj) == &PyMemberDescr_Type) {
PyMemberDescrObject *new = (PyMemberDescrObject *)obj;
}
+/*
+ * Utility function used only in PyArray_ResultType for value-based logic.
+ * See that function for the meaning and contents of the parameters.
+ */
+static PyArray_Descr *
+get_descr_from_cast_or_value(
+ npy_intp i,
+ PyArrayObject *arrs[],
+ npy_intp ndtypes,
+ PyArray_Descr *descriptor,
+ PyArray_DTypeMeta *common_dtype)
+{
+ PyArray_Descr *curr;
+ if (NPY_LIKELY(i < ndtypes ||
+ !(PyArray_FLAGS(arrs[i-ndtypes]) & _NPY_ARRAY_WAS_PYSCALAR))) {
+ curr = PyArray_CastDescrToDType(descriptor, common_dtype);
+ }
+ else {
+ /*
+ * Unlike `PyArray_CastToDTypeAndPromoteDescriptors`, deal with
+ * plain Python values "graciously". This recovers the original
+ * value the long route, but it should almost never happen...
+ */
+ PyObject *tmp = PyArray_GETITEM(arrs[i-ndtypes],
+ PyArray_BYTES(arrs[i-ndtypes]));
+ if (tmp == NULL) {
+ return NULL;
+ }
+ curr = common_dtype->discover_descr_from_pyobject(common_dtype, tmp);
+ Py_DECREF(tmp);
+ }
+ return curr;
+}
+
/*NUMPY_API
*
* Produces the result type of a bunch of inputs, using the same rules
result = common_dtype->default_descr(common_dtype);
}
else {
- result = PyArray_CastDescrToDType(all_descriptors[0], common_dtype);
+ result = get_descr_from_cast_or_value(
+ 0, arrs, ndtypes, all_descriptors[0], common_dtype);
+ if (result == NULL) {
+ goto error;
+ }
for (npy_intp i = 1; i < ndtypes+narrs; i++) {
- PyArray_Descr *curr;
- if (NPY_LIKELY(i < ndtypes ||
- !(PyArray_FLAGS(arrs[i-ndtypes]) & _NPY_ARRAY_WAS_PYSCALAR))) {
- curr = PyArray_CastDescrToDType(all_descriptors[i], common_dtype);
- }
- else {
- /*
- * Unlike `PyArray_CastToDTypeAndPromoteDescriptors` deal with
- * plain Python values "graciously". This recovers the original
- * value the long route, but it should almost never happen...
- */
- PyObject *tmp = PyArray_GETITEM(
- arrs[i-ndtypes], PyArray_BYTES(arrs[i-ndtypes]));
- if (tmp == NULL) {
- goto error;
- }
- curr = common_dtype->discover_descr_from_pyobject(common_dtype, tmp);
- Py_DECREF(tmp);
- }
+ PyArray_Descr *curr = get_descr_from_cast_or_value(
+ i, arrs, ndtypes, all_descriptors[i], common_dtype);
if (curr == NULL) {
goto error;
}
* #c = l,,f#
* #C = L,,F#
*/
+
+/*
+ * On arm64 macOS, there's a bug with sin, cos, and tan where they don't
+ * raise "invalid" when given INFINITY as input.
+ */
+#if defined(__APPLE__) && defined(__arm64__)
+#define WORKAROUND_APPLE_TRIG_BUG 1
+#else
+#define WORKAROUND_APPLE_TRIG_BUG 0
+#endif
+
/**begin repeat1
* #kind = sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,rint,trunc,sqrt,log10,
* log,exp,expm1,asin,acos,atan,asinh,acosh,atanh,log1p,exp2,log2#
* #KIND = SIN,COS,TAN,SINH,COSH,TANH,FABS,FLOOR,CEIL,RINT,TRUNC,SQRT,LOG10,
* LOG,EXP,EXPM1,ASIN,ACOS,ATAN,ASINH,ACOSH,ATANH,LOG1P,EXP2,LOG2#
+ * #TRIG_WORKAROUND = WORKAROUND_APPLE_TRIG_BUG*3, 0*22#
*/
#ifdef HAVE_@KIND@@C@
NPY_INPLACE @type@ npy_@kind@@c@(@type@ x)
{
+#if @TRIG_WORKAROUND@
+ if (!npy_isfinite(x)) {
+ return (x - x);
+ }
+#endif
return @kind@@c@(x);
}
#endif
/**end repeat1**/
+#undef WORKAROUND_APPLE_TRIG_BUG
+
/**begin repeat1
* #kind = atan2,hypot,pow,copysign#
* #KIND = ATAN2,HYPOT,POW,COPYSIGN#
*/
#define CONTIG 0
#define NCONTIG 1
+
+/*
+ * clang has a bug that's present at -O1 or greater. When partially loading a
+ * vector register for a reciprocal operation, the remaining elements are set
+ * to 1 to avoid divide-by-zero. The partial load is paired with a partial
+ * store after the reciprocal operation. clang notices that the entire register
+ * is not needed for the store and optimizes out the fill of 1 to the remaining
+ * elements. This causes either a divide-by-zero or 0/0 with invalid exception
+ * that we were trying to avoid by filling.
+ *
+ * Using a dummy variable marked 'volatile' convinces clang not to ignore
+ * the explicit fill of remaining elements. If `-ftrapping-math` is
+ * supported, then it'll also avoid the bug. `-ftrapping-math` is supported
+ * on Apple clang v12+ for x86_64. It is not currently supported for arm64.
+ * `-ftrapping-math` is set by default of Numpy builds in
+ * numpy/distutils/ccompiler.py.
+ *
+ * Note: Apple clang and clang upstream have different versions that overlap
+ */
+#if defined(__clang__)
+ #if defined(__apple_build_version__)
+ // Apple Clang
+ #if __apple_build_version__ < 12000000
+ // Apple Clang before v12
+ #define WORKAROUND_CLANG_RECIPROCAL_BUG 1
+ #elif defined(NPY_CPU_X86) || defined(NPY_CPU_AMD64)
+ // Apple Clang after v12, targeting i386 or x86_64
+ #define WORKAROUND_CLANG_RECIPROCAL_BUG 0
+ #else
+ // Apple Clang after v12, not targeting i386 or x86_64
+ #define WORKAROUND_CLANG_RECIPROCAL_BUG 1
+ #endif
+ #else
+ // Clang, not Apple Clang
+ #if __clang_major__ < 10
+ // Clang before v10
+ #define WORKAROUND_CLANG_RECIPROCAL_BUG 1
+ #elif defined(NPY_CPU_X86) || defined(NPY_CPU_AMD64)
+ // Clang v10+, targeting i386 or x86_64
+ #define WORKAROUND_CLANG_RECIPROCAL_BUG 0
+ #else
+ // Clang v10+, not targeting i386 or x86_64
+ #define WORKAROUND_CLANG_RECIPROCAL_BUG 1
+ #endif
+ #endif
+#else
+// Not a Clang compiler
+#define WORKAROUND_CLANG_RECIPROCAL_BUG 0
+#endif
+
/**begin repeat
* #TYPE = FLOAT, DOUBLE#
* #sfx = f32, f64#
* #kind = sqrt, absolute, square, reciprocal#
* #intr = sqrt, abs, square, recip#
* #repl_0w1 = 0, 0, 0, 1#
+ * #RECIP_WORKAROUND = 0, 0, 0, WORKAROUND_CLANG_RECIPROCAL_BUG#
*/
/**begin repeat2
* #STYPE = CONTIG, NCONTIG, CONTIG, NCONTIG#
const int vstep = npyv_nlanes_@sfx@;
const int wstep = vstep * @unroll@;
+
+ // unrolled iterations
for (; len >= wstep; len -= wstep, src += ssrc*wstep, dst += sdst*wstep) {
/**begin repeat3
* #N = 0, 1, 2, 3#
#endif
/**end repeat3**/
}
- for (; len > 0; len -= vstep, src += ssrc*vstep, dst += sdst*vstep) {
+
+ // vector-sized iterations
+ for (; len >= vstep; len -= vstep, src += ssrc*vstep, dst += sdst*vstep) {
+ #if @STYPE@ == CONTIG
+ npyv_@sfx@ v_src0 = npyv_load_@sfx@(src);
+ #else
+ npyv_@sfx@ v_src0 = npyv_loadn_@sfx@(src, ssrc);
+ #endif
+ npyv_@sfx@ v_unary0 = npyv_@intr@_@sfx@(v_src0);
+ #if @DTYPE@ == CONTIG
+ npyv_store_@sfx@(dst, v_unary0);
+ #else
+ npyv_storen_@sfx@(dst, sdst, v_unary0);
+ #endif
+ }
+
+ // last partial iteration, if needed
+ if(len > 0){
#if @STYPE@ == CONTIG
#if @repl_0w1@
npyv_@sfx@ v_src0 = npyv_load_till_@sfx@(src, len, 1);
npyv_@sfx@ v_src0 = npyv_loadn_tillz_@sfx@(src, ssrc, len);
#endif
#endif
+ #if @RECIP_WORKAROUND@
+ /*
+ * Workaround clang bug. We use a dummy variable marked 'volatile'
+ * to convince clang that the entire vector is needed. We only
+ * want to do this for the last iteration / partial load-store of
+ * the loop since 'volatile' forces a refresh of the contents.
+ */
+ volatile npyv_@sfx@ unused_but_workaround_bug = v_src0;
+ #endif // @RECIP_WORKAROUND@
npyv_@sfx@ v_unary0 = npyv_@intr@_@sfx@(v_src0);
#if @DTYPE@ == CONTIG
npyv_store_till_@sfx@(dst, len, v_unary0);
npyv_storen_till_@sfx@(dst, sdst, len, v_unary0);
#endif
}
+
npyv_cleanup();
}
/**end repeat2**/
#endif // @VCHK@
/**end repeat**/
+#undef WORKAROUND_CLANG_RECIPROCAL_BUG
+
/********************************************************************************
** Defining ufunc inner functions
********************************************************************************/
# Tests that a dtype must have its type field set up to np.dtype
# or in this case a builtin instance.
create_custom_field_dtype(blueprint, mytype, 2)
+
+
+def test_result_type_integers_and_unitless_timedelta64():
+ # Regression test for gh-20077. The following call of `result_type`
+ # would cause a seg. fault.
+ td = np.timedelta64(4)
+ result = np.result_type(0, td)
+ assert_dtype_equal(result, td.dtype)
cur_plus = pcg128_mult(pcg128_add(cur_mult, PCG_128BIT_CONSTANT(0u, 1u)),
cur_plus);
cur_mult = pcg128_mult(cur_mult, cur_mult);
- delta.low >>= 1;
- delta.low += delta.high & 1;
+ delta.low = (delta.low >> 1) | (delta.high << 63);
delta.high >>= 1;
}
return pcg128_add(pcg128_mult(acc_mult, state), acc_plus);
assert val_neg == val_pos
assert val_big == val_pos
+ def test_advange_large(self):
+ rs = Generator(self.bit_generator(38219308213743))
+ pcg = rs.bit_generator
+ state = pcg.state["state"]
+ initial_state = 287608843259529770491897792873167516365
+ assert state["state"] == initial_state
+ pcg.advance(sum(2**i for i in (96, 64, 32, 16, 8, 4, 2, 1)))
+ state = pcg.state["state"]
+ advanced_state = 135275564607035429730177404003164635391
+ assert state["state"] == advanced_state
+
class TestPCG64DXSM(Base):
@classmethod
assert val_neg == val_pos
assert val_big == val_pos
+ def test_advange_large(self):
+ rs = Generator(self.bit_generator(38219308213743))
+ pcg = rs.bit_generator
+ state = pcg.state
+ initial_state = 287608843259529770491897792873167516365
+ assert state["state"]["state"] == initial_state
+ pcg.advance(sum(2**i for i in (96, 64, 32, 16, 8, 4, 2, 1)))
+ state = pcg.state["state"]
+ advanced_state = 277778083536782149546677086420637664879
+ assert state["state"] == advanced_state
+
class TestMT19937(Base):
@classmethod
# NOTE: The API section will be appended with additional entries
# further down in this file
-from typing import TYPE_CHECKING, List, Any
+from numpy import ufunc
+from typing import TYPE_CHECKING, List
if TYPE_CHECKING:
import sys
_GUFunc_Nin2_Nout1,
)
else:
- _UFunc_Nin1_Nout1 = Any
- _UFunc_Nin2_Nout1 = Any
- _UFunc_Nin1_Nout2 = Any
- _UFunc_Nin2_Nout2 = Any
- _GUFunc_Nin2_Nout1 = Any
+ # Declare the (type-check-only) ufunc subclasses as ufunc aliases during
+ # runtime; this helps autocompletion tools such as Jedi (numpy/numpy#19834)
+ _UFunc_Nin1_Nout1 = ufunc
+ _UFunc_Nin2_Nout1 = ufunc
+ _UFunc_Nin1_Nout2 = ufunc
+ _UFunc_Nin2_Nout2 = ufunc
+ _GUFunc_Nin2_Nout1 = ufunc
# Clean up the namespace
-del TYPE_CHECKING, final, List, Any
+del TYPE_CHECKING, final, List, ufunc
if __doc__ is not None:
from ._add_docstring import _docstrings
import numpy as np
+import numpy.typing as npt
-nd = np.array([[1, 2], [3, 4]])
+nd: npt.NDArray[np.int_] = np.array([[1, 2], [3, 4]])
# item
-reveal_type(nd.item()) # E: Any
-reveal_type(nd.item(1)) # E: Any
-reveal_type(nd.item(0, 1)) # E: Any
-reveal_type(nd.item((0, 1))) # E: Any
+reveal_type(nd.item()) # E: int
+reveal_type(nd.item(1)) # E: int
+reveal_type(nd.item(0, 1)) # E: int
+reveal_type(nd.item((0, 1))) # E: int
# tolist
reveal_type(nd.tolist()) # E: Any
# dumps is pretty simple
# astype
-reveal_type(nd.astype("float")) # E: numpy.ndarray
-reveal_type(nd.astype(float)) # E: numpy.ndarray
-reveal_type(nd.astype(float, "K")) # E: numpy.ndarray
-reveal_type(nd.astype(float, "K", "unsafe")) # E: numpy.ndarray
-reveal_type(nd.astype(float, "K", "unsafe", True)) # E: numpy.ndarray
-reveal_type(nd.astype(float, "K", "unsafe", True, True)) # E: numpy.ndarray
+reveal_type(nd.astype("float")) # E: numpy.ndarray[Any, numpy.dtype[Any]]
+reveal_type(nd.astype(float)) # E: numpy.ndarray[Any, numpy.dtype[Any]]
+reveal_type(nd.astype(np.float64)) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
+reveal_type(nd.astype(np.float64, "K")) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
+reveal_type(nd.astype(np.float64, "K", "unsafe")) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
+reveal_type(nd.astype(np.float64, "K", "unsafe", True)) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
+reveal_type(nd.astype(np.float64, "K", "unsafe", True, True)) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
# byteswap
-reveal_type(nd.byteswap()) # E: numpy.ndarray
-reveal_type(nd.byteswap(True)) # E: numpy.ndarray
+reveal_type(nd.byteswap()) # E: numpy.ndarray[Any, numpy.dtype[{int_}]]
+reveal_type(nd.byteswap(True)) # E: numpy.ndarray[Any, numpy.dtype[{int_}]]
# copy
-reveal_type(nd.copy()) # E: numpy.ndarray
-reveal_type(nd.copy("C")) # E: numpy.ndarray
+reveal_type(nd.copy()) # E: numpy.ndarray[Any, numpy.dtype[{int_}]]
+reveal_type(nd.copy("C")) # E: numpy.ndarray[Any, numpy.dtype[{int_}]]
-# view
-class SubArray(np.ndarray):
- pass
-
-
-reveal_type(nd.view()) # E: numpy.ndarray
-reveal_type(nd.view(np.int64)) # E: numpy.ndarray
-# replace `Any` with `numpy.matrix` when `matrix` will be added to stubs
-reveal_type(nd.view(np.int64, np.matrix)) # E: Any
-reveal_type(nd.view(np.int64, SubArray)) # E: SubArray
+reveal_type(nd.view()) # E: numpy.ndarray[Any, numpy.dtype[{int_}]]
+reveal_type(nd.view(np.float64)) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
+reveal_type(nd.view(float)) # E: numpy.ndarray[Any, numpy.dtype[Any]]
+reveal_type(nd.view(np.float64, np.matrix)) # E: numpy.matrix[Any, Any]
# getfield
-reveal_type(nd.getfield("float")) # E: numpy.ndarray
-reveal_type(nd.getfield(float)) # E: numpy.ndarray
-reveal_type(nd.getfield(float, 8)) # E: numpy.ndarray
+reveal_type(nd.getfield("float")) # E: numpy.ndarray[Any, numpy.dtype[Any]]
+reveal_type(nd.getfield(float)) # E: numpy.ndarray[Any, numpy.dtype[Any]]
+reveal_type(nd.getfield(np.float64)) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
+reveal_type(nd.getfield(np.float64, 8)) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
# setflags does not return a value
# fill does not return a value
if sys.version_info >= (3, 9):
reveal_type(f8.__ceil__()) # E: int
reveal_type(f8.__floor__()) # E: int
+
+reveal_type(i8.astype(float)) # E: Any
+reveal_type(i8.astype(np.float64)) # E: {float64}
+
+reveal_type(i8.view()) # E: {int64}
+reveal_type(i8.view(np.float64)) # E: {float64}
+reveal_type(i8.view(float)) # E: Any
+reveal_type(i8.view(np.float64, np.ndarray)) # E: {float64}
+
+reveal_type(i8.getfield(float)) # E: Any
+reveal_type(i8.getfield(np.float64)) # E: {float64}
+reveal_type(i8.getfield(np.float64, 8)) # E: {float64}
#-----------------------------------
# Path to the release notes
-RELEASE_NOTES = 'doc/source/release/1.21.2-notes.rst'
+RELEASE_NOTES = 'doc/source/release/1.21.3-notes.rst'
#-------------------------------------------------------