summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattip <matti.picus@gmail.com>2018-10-07 18:48:54 +0300
committermattip <matti.picus@gmail.com>2018-10-07 18:48:54 +0300
commit1462362754f2053561d08eba5bc12960056104af (patch)
tree8b03f0d29c75980ac03292720a88715f17508c1e
parenta6a0b0f6f75a3f00879506191e42328e1314016b (diff)
downloadnumpy-1462362754f2053561d08eba5bc12960056104af.tar.gz
ENH: increment and use NPY_API_VERSION in PyUFuncObject->version
-rw-r--r--doc/release/1.16.0-notes.rst2
-rw-r--r--numpy/core/code_generators/cversions.txt2
-rw-r--r--numpy/core/include/numpy/ufuncobject.h42
-rw-r--r--numpy/core/setup_common.py3
-rw-r--r--numpy/core/src/umath/_umath_tests.c.src8
-rw-r--r--numpy/core/src/umath/ufunc_object.c44
6 files changed, 47 insertions, 54 deletions
diff --git a/doc/release/1.16.0-notes.rst b/doc/release/1.16.0-notes.rst
index 8d068079e..8c14e0070 100644
--- a/doc/release/1.16.0-notes.rst
+++ b/doc/release/1.16.0-notes.rst
@@ -72,6 +72,8 @@ comparisons.
C API changes
=============
+The ``NPY_API_VERSION`` was incremented to 0x0000D since the `PyUFuncObject`'s
+size changed.
New Features
============
diff --git a/numpy/core/code_generators/cversions.txt b/numpy/core/code_generators/cversions.txt
index 43c32eac6..641857070 100644
--- a/numpy/core/code_generators/cversions.txt
+++ b/numpy/core/code_generators/cversions.txt
@@ -43,3 +43,5 @@
# PyArray_SetWritebackIfCopyBase and deprecated PyArray_SetUpdateIfCopyBase.
0x0000000c = a1bc756c5782853ec2e3616cf66869d8
+# Version 13 (Numpy 1.16) Size of PyUFuncObject changed
+0x0000000d = a1bc756c5782853ec2e3616cf66869d8
diff --git a/numpy/core/include/numpy/ufuncobject.h b/numpy/core/include/numpy/ufuncobject.h
index 430c1873e..e24da04af 100644
--- a/numpy/core/include/numpy/ufuncobject.h
+++ b/numpy/core/include/numpy/ufuncobject.h
@@ -111,24 +111,6 @@ typedef int (PyUFunc_MaskedInnerLoopSelectionFunc)(
NpyAuxData **out_innerloopdata,
int *out_needs_api);
-typedef struct _ufunc_extension {
- /* New in PyUFuncObject version 1 and above */
-
- /*
- * for each core_num_dim_ix distinct dimension names,
- * the possible "frozen" size (-1 if not frozen).
- */
- npy_intp *core_dim_sizes;
-
- /*
- * for each distinct core dimension, a set of flags OR'd together
- * e.g., UFUNC_CORE_DIM_CAN_IGNORE if signature has ?
- * UFUNC_CORE_DIM_SIZE_UNSET for non-frozen dimensions.
- */
- npy_uint32 *core_dim_flags;
-
-} ufunc_extension;
-
typedef struct _tagPyUFuncObject {
PyObject_HEAD
/*
@@ -206,10 +188,9 @@ typedef struct _tagPyUFuncObject {
/*
* This was blocked off to be the "new" inner loop selector in 1.7,
* but this was never implemented. (This is also why the above
- * selector is called the "legacy" selector.) Repurposed in 1.16 to
- * point to s_extension
+ * selector is called the "legacy" selector.)
*/
- ufunc_extension * extension;
+ void *reserved2;
/*
* A function which returns a masked inner loop for the ufunc.
*/
@@ -229,11 +210,24 @@ typedef struct _tagPyUFuncObject {
*/
npy_uint32 iter_flags;
- ufunc_extension s_extension;
+ /* New in NPY_API_VERSION 0x0000000D and above */
-} PyUFuncObject;
+ /*
+ * for each core_num_dim_ix distinct dimension names,
+ * the possible "frozen" size (-1 if not frozen).
+ */
+ npy_intp *core_dim_sizes;
-#define UFUNC_VERSION 1
+ /*
+ * for each distinct core dimension, a set of flags OR'd together
+ * e.g., UFUNC_CORE_DIM_CAN_IGNORE if signature has ?
+ * UFUNC_CORE_DIM_SIZE_UNSET for non-frozen dimensions.
+ */
+ npy_uint32 *core_dim_flags;
+
+
+
+} PyUFuncObject;
#include "arrayobject.h"
/* Generalized ufunc; 0x0001 reserved for possible use as CORE_ENABLED */
diff --git a/numpy/core/setup_common.py b/numpy/core/setup_common.py
index 356482b07..14fc94501 100644
--- a/numpy/core/setup_common.py
+++ b/numpy/core/setup_common.py
@@ -41,7 +41,8 @@ C_ABI_VERSION = 0x01000009
# 0x0000000b - 1.13.x
# 0x0000000c - 1.14.x
# 0x0000000c - 1.15.x
-C_API_VERSION = 0x0000000c
+# 0x0000000d - 1.16.x
+C_API_VERSION = 0x0000000d
class MismatchCAPIWarning(Warning):
pass
diff --git a/numpy/core/src/umath/_umath_tests.c.src b/numpy/core/src/umath/_umath_tests.c.src
index e03ab12ec..f0347cef8 100644
--- a/numpy/core/src/umath/_umath_tests.c.src
+++ b/numpy/core/src/umath/_umath_tests.c.src
@@ -535,13 +535,13 @@ UMath_Tests_test_signature(PyObject *NPY_UNUSED(dummy), PyObject *args)
Py_INCREF(Py_None);
core_dim_ixs = Py_None;
}
- if (f->extension->core_dim_flags != NULL) {
+ if (f->core_dim_flags != NULL) {
core_dim_flags = PyTuple_New(f->core_num_dim_ix);
if (core_dim_flags == NULL) {
goto fail;
}
for (i = 0; i < f->core_num_dim_ix; i++) {
- PyObject * val = PyLong_FromLong(f->extension->core_dim_flags[i]);
+ PyObject * val = PyLong_FromLong(f->core_dim_flags[i]);
PyTuple_SET_ITEM(core_dim_flags, i, val);
}
}
@@ -549,13 +549,13 @@ UMath_Tests_test_signature(PyObject *NPY_UNUSED(dummy), PyObject *args)
Py_INCREF(Py_None);
core_dim_flags = Py_None;
}
- if (f->extension->core_dim_sizes != NULL) {
+ if (f->core_dim_sizes != NULL) {
core_dim_sizes = PyTuple_New(f->core_num_dim_ix);
if (core_dim_sizes == NULL) {
goto fail;
}
for (i = 0; i < f->core_num_dim_ix; i++) {
- PyObject * val = PyLong_FromLong(f->extension->core_dim_sizes[i]);
+ PyObject * val = PyLong_FromLong(f->core_dim_sizes[i]);
PyTuple_SET_ITEM(core_dim_sizes, i, val);
}
}
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
index 9f2bb3fb6..c3e1c62a8 100644
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -572,18 +572,18 @@ _parse_signature(PyUFuncObject *ufunc, const char *signature)
ufunc->core_offsets = PyArray_malloc(sizeof(int) * ufunc->nargs);
/* The next three items will be shrunk later */
ufunc->core_dim_ixs = PyArray_malloc(sizeof(int) * len);
- ufunc->extension->core_dim_sizes = PyArray_malloc(sizeof(npy_intp) * len);
- ufunc->extension->core_dim_flags = PyArray_malloc(sizeof(npy_uint32) * len);
+ ufunc->core_dim_sizes = PyArray_malloc(sizeof(npy_intp) * len);
+ ufunc->core_dim_flags = PyArray_malloc(sizeof(npy_uint32) * len);
if (ufunc->core_num_dims == NULL || ufunc->core_dim_ixs == NULL ||
ufunc->core_offsets == NULL ||
- ufunc->extension->core_dim_sizes == NULL ||
- ufunc->extension->core_dim_flags == NULL) {
+ ufunc->core_dim_sizes == NULL ||
+ ufunc->core_dim_flags == NULL) {
PyErr_NoMemory();
goto fail;
}
for (i = 0; i < len; i++) {
- ufunc->extension->core_dim_flags[i] = 0;
+ ufunc->core_dim_flags[i] = 0;
}
i = _next_non_white_space(signature, 0);
@@ -639,7 +639,7 @@ _parse_signature(PyUFuncObject *ufunc, const char *signature)
*/
for(ix = 0; ix < ufunc->core_num_dim_ix; ix++) {
if (frozen_size > 0 ?
- frozen_size == ufunc->extension->core_dim_sizes[ix] :
+ frozen_size == ufunc->core_dim_sizes[ix] :
_is_same_name(signature + i, var_names[ix])) {
break;
}
@@ -650,20 +650,20 @@ _parse_signature(PyUFuncObject *ufunc, const char *signature)
if (ix == ufunc->core_num_dim_ix) {
ufunc->core_num_dim_ix++;
var_names[ix] = signature + i;
- ufunc->extension->core_dim_sizes[ix] = frozen_size;
+ ufunc->core_dim_sizes[ix] = frozen_size;
if (frozen_size < 0) {
- ufunc->extension->core_dim_flags[ix] |= UFUNC_CORE_DIM_SIZE_UNSET;
+ ufunc->core_dim_flags[ix] |= UFUNC_CORE_DIM_SIZE_UNSET;
}
if (can_ignore) {
- ufunc->extension->core_dim_flags[ix] |= UFUNC_CORE_DIM_CAN_IGNORE;
+ ufunc->core_dim_flags[ix] |= UFUNC_CORE_DIM_CAN_IGNORE;
}
} else {
- if (can_ignore && !(ufunc->extension->core_dim_flags[ix] &
+ if (can_ignore && !(ufunc->core_dim_flags[ix] &
UFUNC_CORE_DIM_CAN_IGNORE)) {
parse_error = "? cannot be used, name already seen without ?";
goto fail;
}
- if (!can_ignore && (ufunc->extension->core_dim_flags[ix] &
+ if (!can_ignore && (ufunc->core_dim_flags[ix] &
UFUNC_CORE_DIM_CAN_IGNORE)) {
parse_error = "? must be used, name already seen with ?";
goto fail;
@@ -710,11 +710,11 @@ _parse_signature(PyUFuncObject *ufunc, const char *signature)
}
ufunc->core_dim_ixs = PyArray_realloc(ufunc->core_dim_ixs,
sizeof(int) * cur_core_dim);
- ufunc->extension->core_dim_sizes = PyArray_realloc(
- ufunc->extension->core_dim_sizes,
+ ufunc->core_dim_sizes = PyArray_realloc(
+ ufunc->core_dim_sizes,
sizeof(npy_intp) * ufunc->core_num_dim_ix);
- ufunc->extension->core_dim_flags = PyArray_realloc(
- ufunc->extension->core_dim_flags,
+ ufunc->core_dim_flags = PyArray_realloc(
+ ufunc->core_dim_flags,
sizeof(npy_uint32) * ufunc->core_num_dim_ix);
/* check for trivial core-signature, e.g. "(),()->()" */
@@ -2492,10 +2492,10 @@ _initialize_variable_parts(PyUFuncObject *ufunc,
for (i = 0; i < ufunc->nargs; i++) {
op_core_num_dims[i] = ufunc->core_num_dims[i];
}
- if (ufunc->version == 1 && ufunc->extension != NULL) {
+ if (ufunc->version >= 0x0000d) {
for (i = 0; i < ufunc->core_num_dim_ix; i++) {
- core_dim_sizes[i] = ufunc->extension->core_dim_sizes[i];
- core_dim_flags[i] = ufunc->extension->core_dim_flags[i];
+ core_dim_sizes[i] = ufunc->core_dim_sizes[i];
+ core_dim_flags[i] = ufunc->core_dim_flags[i];
}
}
else if (ufunc->version == 0) {
@@ -4855,9 +4855,6 @@ PyUFunc_FromFuncAndDataAndSignature(PyUFuncGenericFunction *func, void **data,
int unused, const char *signature)
{
PyUFuncObject *ufunc;
- /*
- * The version field is a constant and cannot be initialzed in C directly
- */
if (nin + nout > NPY_MAXARGS) {
PyErr_Format(PyExc_ValueError,
"Cannot construct a ufunc with more than %d operands "
@@ -4871,9 +4868,8 @@ PyUFunc_FromFuncAndDataAndSignature(PyUFuncGenericFunction *func, void **data,
return NULL;
}
memset(ufunc, 0, sizeof(PyUFuncObject));
- *((int*)&ufunc->version) = UFUNC_VERSION;
+ *((int*)&ufunc->version) = NPY_API_VERSION;
PyObject_Init((PyObject *)ufunc, &PyUFunc_Type);
- ufunc->extension = &ufunc->s_extension;
ufunc->nin = nin;
ufunc->nout = nout;
@@ -5250,8 +5246,6 @@ ufunc_dealloc(PyUFuncObject *ufunc)
{
PyArray_free(ufunc->core_num_dims);
PyArray_free(ufunc->core_dim_ixs);
- PyArray_free(ufunc->extension->core_dim_sizes);
- PyArray_free(ufunc->extension->core_dim_flags);
PyArray_free(ufunc->core_offsets);
PyArray_free(ufunc->core_signature);
PyArray_free(ufunc->ptr);