|
| 1 | +diff --git a/numpy/core/src/_simd/_simd_convert.inc b/numpy/core/src/_simd/_simd_convert.inc |
| 2 | +index 46e0444..261cf5b 100644 |
| 3 | +--- a/numpy/core/src/_simd/_simd_convert.inc |
| 4 | ++++ b/numpy/core/src/_simd/_simd_convert.inc |
| 5 | +@@ -101,9 +101,8 @@ simd_sequence_from_iterable(PyObject *obj, simd_data_type dtype, Py_ssize_t min_ |
| 6 | + if (dst == NULL) { |
| 7 | + return NULL; |
| 8 | + } |
| 9 | +- PyObject **seq_items = PySequence_Fast_ITEMS(seq_obj); |
| 10 | + for (Py_ssize_t i = 0; i < seq_size; ++i) { |
| 11 | +- simd_data data = simd_scalar_from_number(seq_items[i], info->to_scalar); |
| 12 | ++ simd_data data = simd_scalar_from_number(PySequence_Fast_GET_ITEM(seq_obj, i), info->to_scalar); |
| 13 | + npyv_lanetype_u8 *sdst = dst + i * info->lane_size; |
| 14 | + memcpy(sdst, &data.u64, info->lane_size); |
| 15 | + } |
| 16 | +diff --git a/numpy/core/src/common/ufunc_override.c b/numpy/core/src/common/ufunc_override.c |
| 17 | +index 4fb4d4b..06552f0 100644 |
| 18 | +--- a/numpy/core/src/common/ufunc_override.c |
| 19 | ++++ b/numpy/core/src/common/ufunc_override.c |
| 20 | +@@ -79,13 +79,12 @@ PyUFunc_HasOverride(PyObject * obj) |
| 21 | + /* |
| 22 | + * Get possible out argument from kwds, and returns the number of outputs |
| 23 | + * contained within it: if a tuple, the number of elements in it, 1 otherwise. |
| 24 | +- * The out argument itself is returned in out_kwd_obj, and the outputs |
| 25 | +- * in the out_obj array (as borrowed references). |
| 26 | ++ * The out argument itself is returned in out_kwd_obj. |
| 27 | + * |
| 28 | + * Returns 0 if no outputs found, -1 if kwds is not a dict (with an error set). |
| 29 | + */ |
| 30 | + NPY_NO_EXPORT int |
| 31 | +-PyUFuncOverride_GetOutObjects(PyObject *kwds, PyObject **out_kwd_obj, PyObject ***out_objs) |
| 32 | ++PyUFuncOverride_GetOutObjects(PyObject *kwds, PyObject **out_kwd_obj) |
| 33 | + { |
| 34 | + if (kwds == NULL) { |
| 35 | + Py_INCREF(Py_None); |
| 36 | +@@ -121,13 +120,11 @@ PyUFuncOverride_GetOutObjects(PyObject *kwds, PyObject **out_kwd_obj, PyObject * |
| 37 | + *out_kwd_obj = NULL; |
| 38 | + return -1; |
| 39 | + } |
| 40 | +- *out_objs = PySequence_Fast_ITEMS(seq); |
| 41 | + *out_kwd_obj = seq; |
| 42 | + return PySequence_Fast_GET_SIZE(seq); |
| 43 | + } |
| 44 | + else { |
| 45 | +- Py_INCREF(*out_kwd_obj); |
| 46 | +- *out_objs = out_kwd_obj; |
| 47 | ++ *out_kwd_obj = PyTuple_Pack(1, *out_kwd_obj); |
| 48 | + return 1; |
| 49 | + } |
| 50 | + } |
| 51 | +diff --git a/numpy/core/src/common/ufunc_override.h b/numpy/core/src/common/ufunc_override.h |
| 52 | +index 5da95fb..3879016 100644 |
| 53 | +--- a/numpy/core/src/common/ufunc_override.h |
| 54 | ++++ b/numpy/core/src/common/ufunc_override.h |
| 55 | +@@ -27,12 +27,11 @@ PyUFunc_HasOverride(PyObject *obj); |
| 56 | + /* |
| 57 | + * Get possible out argument from kwds, and returns the number of outputs |
| 58 | + * contained within it: if a tuple, the number of elements in it, 1 otherwise. |
| 59 | +- * The out argument itself is returned in out_kwd_obj, and the outputs |
| 60 | +- * in the out_obj array (as borrowed references). |
| 61 | ++ * The out argument itself is returned in out_kwd_obj. |
| 62 | + * |
| 63 | + * Returns 0 if no outputs found, -1 if kwds is not a dict (with an error set). |
| 64 | + */ |
| 65 | + NPY_NO_EXPORT int |
| 66 | +-PyUFuncOverride_GetOutObjects(PyObject *kwds, PyObject **out_kwd_obj, PyObject ***out_objs); |
| 67 | ++PyUFuncOverride_GetOutObjects(PyObject *kwds, PyObject **out_kwd_obj); |
| 68 | + |
| 69 | + #endif /* NUMPY_CORE_SRC_COMMON_UFUNC_OVERRIDE_H_ */ |
| 70 | +diff --git a/numpy/core/src/multiarray/array_coercion.c b/numpy/core/src/multiarray/array_coercion.c |
| 71 | +index 562e4f0..1ed009b 100644 |
| 72 | +--- a/numpy/core/src/multiarray/array_coercion.c |
| 73 | ++++ b/numpy/core/src/multiarray/array_coercion.c |
| 74 | +@@ -1106,7 +1106,6 @@ PyArray_DiscoverDTypeAndShape_Recursive( |
| 75 | + } |
| 76 | + |
| 77 | + npy_intp size = PySequence_Fast_GET_SIZE(seq); |
| 78 | +- PyObject **objects = PySequence_Fast_ITEMS(seq); |
| 79 | + |
| 80 | + if (update_shape(curr_dims, &max_dims, |
| 81 | + out_shape, 1, &size, NPY_TRUE, flags) < 0) { |
| 82 | +@@ -1128,7 +1127,7 @@ PyArray_DiscoverDTypeAndShape_Recursive( |
| 83 | + /* Recursive call for each sequence item */ |
| 84 | + for (Py_ssize_t i = 0; i < size; i++) { |
| 85 | + max_dims = PyArray_DiscoverDTypeAndShape_Recursive( |
| 86 | +- objects[i], curr_dims + 1, max_dims, |
| 87 | ++ PySequence_Fast_GET_ITEM(seq, i), curr_dims + 1, max_dims, |
| 88 | + out_descr, out_shape, coercion_cache_tail_ptr, fixed_DType, |
| 89 | + flags, never_copy); |
| 90 | + |
| 91 | +diff --git a/numpy/core/src/multiarray/arrayfunction_override.c b/numpy/core/src/multiarray/arrayfunction_override.c |
| 92 | +index af53d78..1fcd6d3 100644 |
| 93 | +--- a/numpy/core/src/multiarray/arrayfunction_override.c |
| 94 | ++++ b/numpy/core/src/multiarray/arrayfunction_override.c |
| 95 | +@@ -72,12 +72,11 @@ get_implementing_args_and_methods(PyObject *relevant_args, |
| 96 | + { |
| 97 | + int num_implementing_args = 0; |
| 98 | + |
| 99 | +- PyObject **items = PySequence_Fast_ITEMS(relevant_args); |
| 100 | + Py_ssize_t length = PySequence_Fast_GET_SIZE(relevant_args); |
| 101 | + |
| 102 | + for (Py_ssize_t i = 0; i < length; i++) { |
| 103 | + int new_class = 1; |
| 104 | +- PyObject *argument = items[i]; |
| 105 | ++ PyObject *argument = PySequence_Fast_GET_ITEM(relevant_args, i); |
| 106 | + |
| 107 | + /* Have we seen this type before? */ |
| 108 | + for (int j = 0; j < num_implementing_args; j++) { |
| 109 | +@@ -156,12 +155,11 @@ NPY_NO_EXPORT PyObject * |
| 110 | + array_function_method_impl(PyObject *func, PyObject *types, PyObject *args, |
| 111 | + PyObject *kwargs) |
| 112 | + { |
| 113 | +- PyObject **items = PySequence_Fast_ITEMS(types); |
| 114 | + Py_ssize_t length = PySequence_Fast_GET_SIZE(types); |
| 115 | + |
| 116 | + for (Py_ssize_t j = 0; j < length; j++) { |
| 117 | + int is_subclass = PyObject_IsSubclass( |
| 118 | +- items[j], (PyObject *)&PyArray_Type); |
| 119 | ++ PySequence_Fast_GET_ITEM(types, j), (PyObject *)&PyArray_Type); |
| 120 | + if (is_subclass == -1) { |
| 121 | + return NULL; |
| 122 | + } |
| 123 | +diff --git a/numpy/core/src/multiarray/compiled_base.c b/numpy/core/src/multiarray/compiled_base.c |
| 124 | +index 2b82aca..7260b1b 100644 |
| 125 | +--- a/numpy/core/src/multiarray/compiled_base.c |
| 126 | ++++ b/numpy/core/src/multiarray/compiled_base.c |
| 127 | +@@ -1414,78 +1414,78 @@ arr_add_docstring(PyObject *NPY_UNUSED(dummy), PyObject *args) |
| 128 | + return NULL; |
| 129 | + } |
| 130 | + |
| 131 | +-#define _ADDDOC(doc, name) \ |
| 132 | +- if (!(doc)) { \ |
| 133 | +- doc = docstr; \ |
| 134 | +- Py_INCREF(str); /* hold on to string (leaks reference) */ \ |
| 135 | +- } \ |
| 136 | +- else if (strcmp(doc, docstr) != 0) { \ |
| 137 | +- PyErr_Format(PyExc_RuntimeError, "%s method %s", name, msg); \ |
| 138 | +- return NULL; \ |
| 139 | +- } |
| 140 | +- |
| 141 | +- if (Py_TYPE(obj) == &PyCFunction_Type) { |
| 142 | +- PyCFunctionObject *new = (PyCFunctionObject *)obj; |
| 143 | +- _ADDDOC(PyObject_GetDoc((PyObject*)(new)), new->m_ml->ml_name); |
| 144 | +- } |
| 145 | +- else if (PyObject_TypeCheck(obj, &PyType_Type)) { |
| 146 | +- /* |
| 147 | +- * We add it to both `tp_doc` and `__doc__` here. Note that in theory |
| 148 | +- * `tp_doc` extracts the signature line, but we currently do not use |
| 149 | +- * it. It may make sense to only add it as `__doc__` and |
| 150 | +- * `__text_signature__` to the dict in the future. |
| 151 | +- * The dictionary path is only necessary for heaptypes (currently not |
| 152 | +- * used) and metaclasses. |
| 153 | +- * If `__doc__` as stored in `tp_dict` is None, we assume this was |
| 154 | +- * filled in by `PyType_Ready()` and should also be replaced. |
| 155 | +- */ |
| 156 | +- PyTypeObject *new = (PyTypeObject *)obj; |
| 157 | +- _ADDDOC(new->tp_doc, new->tp_name); |
| 158 | +- if (new->tp_dict != NULL && PyDict_CheckExact(new->tp_dict) && |
| 159 | +- PyDict_GetItemString(new->tp_dict, "__doc__") == Py_None) { |
| 160 | +- /* Warning: Modifying `tp_dict` is not generally safe! */ |
| 161 | +- if (PyDict_SetItemString(new->tp_dict, "__doc__", str) < 0) { |
| 162 | +- return NULL; |
| 163 | +- } |
| 164 | +- } |
| 165 | +- } |
| 166 | +- else if (Py_TYPE(obj) == &PyMemberDescr_Type) { |
| 167 | +- PyMemberDescrObject *new = (PyMemberDescrObject *)obj; |
| 168 | +- _ADDDOC(new->d_member->doc, new->d_member->name); |
| 169 | +- } |
| 170 | +- else if (Py_TYPE(obj) == &PyGetSetDescr_Type) { |
| 171 | +- PyGetSetDescrObject *new = (PyGetSetDescrObject *)obj; |
| 172 | +- _ADDDOC(new->d_getset->doc, new->d_getset->name); |
| 173 | +- } |
| 174 | +- else if (Py_TYPE(obj) == &PyMethodDescr_Type) { |
| 175 | +- PyMethodDescrObject *new = (PyMethodDescrObject *)obj; |
| 176 | +- _ADDDOC(new->d_method->ml_doc, new->d_method->ml_name); |
| 177 | +- } |
| 178 | +- else { |
| 179 | +- PyObject *doc_attr; |
| 180 | +- |
| 181 | +- doc_attr = PyObject_GetAttrString(obj, "__doc__"); |
| 182 | +- if (doc_attr != NULL && doc_attr != Py_None && |
| 183 | +- (PyUnicode_Compare(doc_attr, str) != 0)) { |
| 184 | +- Py_DECREF(doc_attr); |
| 185 | +- if (PyErr_Occurred()) { |
| 186 | +- /* error during PyUnicode_Compare */ |
| 187 | +- return NULL; |
| 188 | +- } |
| 189 | +- PyErr_Format(PyExc_RuntimeError, "object %s", msg); |
| 190 | +- return NULL; |
| 191 | +- } |
| 192 | +- Py_XDECREF(doc_attr); |
| 193 | +- |
| 194 | +- if (PyObject_SetAttrString(obj, "__doc__", str) < 0) { |
| 195 | +- PyErr_SetString(PyExc_TypeError, |
| 196 | +- "Cannot set a docstring for that object"); |
| 197 | +- return NULL; |
| 198 | +- } |
| 199 | +- Py_RETURN_NONE; |
| 200 | +- } |
| 201 | +- |
| 202 | +-#undef _ADDDOC |
| 203 | ++// #define _ADDDOC(doc, name) \ |
| 204 | ++// if (!(doc)) { \ |
| 205 | ++// doc = docstr; \ |
| 206 | ++// Py_INCREF(str); /* hold on to string (leaks reference) */ \ |
| 207 | ++// } \ |
| 208 | ++// else if (strcmp(doc, docstr) != 0) { \ |
| 209 | ++// PyErr_Format(PyExc_RuntimeError, "%s method %s", name, msg); \ |
| 210 | ++// return NULL; \ |
| 211 | ++// } |
| 212 | ++// |
| 213 | ++// if (Py_TYPE(obj) == &PyCFunction_Type) { |
| 214 | ++// PyCFunctionObject *new = (PyCFunctionObject *)obj; |
| 215 | ++// _ADDDOC(PyObject_GetDoc((PyObject*)(new)), new->m_ml->ml_name); |
| 216 | ++// } |
| 217 | ++// else if (PyObject_TypeCheck(obj, &PyType_Type)) { |
| 218 | ++// /* |
| 219 | ++// * We add it to both `tp_doc` and `__doc__` here. Note that in theory |
| 220 | ++// * `tp_doc` extracts the signature line, but we currently do not use |
| 221 | ++// * it. It may make sense to only add it as `__doc__` and |
| 222 | ++// * `__text_signature__` to the dict in the future. |
| 223 | ++// * The dictionary path is only necessary for heaptypes (currently not |
| 224 | ++// * used) and metaclasses. |
| 225 | ++// * If `__doc__` as stored in `tp_dict` is None, we assume this was |
| 226 | ++// * filled in by `PyType_Ready()` and should also be replaced. |
| 227 | ++// */ |
| 228 | ++// PyTypeObject *new = (PyTypeObject *)obj; |
| 229 | ++// _ADDDOC(new->tp_doc, new->tp_name); |
| 230 | ++// if (new->tp_dict != NULL && PyDict_CheckExact(new->tp_dict) && |
| 231 | ++// PyDict_GetItemString(new->tp_dict, "__doc__") == Py_None) { |
| 232 | ++// /* Warning: Modifying `tp_dict` is not generally safe! */ |
| 233 | ++// if (PyDict_SetItemString(new->tp_dict, "__doc__", str) < 0) { |
| 234 | ++// return NULL; |
| 235 | ++// } |
| 236 | ++// } |
| 237 | ++// } |
| 238 | ++// else if (Py_TYPE(obj) == &PyMemberDescr_Type) { |
| 239 | ++// PyMemberDescrObject *new = (PyMemberDescrObject *)obj; |
| 240 | ++// _ADDDOC(new->d_member->doc, new->d_member->name); |
| 241 | ++// } |
| 242 | ++// else if (Py_TYPE(obj) == &PyGetSetDescr_Type) { |
| 243 | ++// PyGetSetDescrObject *new = (PyGetSetDescrObject *)obj; |
| 244 | ++// _ADDDOC(new->d_getset->doc, new->d_getset->name); |
| 245 | ++// } |
| 246 | ++// else if (Py_TYPE(obj) == &PyMethodDescr_Type) { |
| 247 | ++// PyMethodDescrObject *new = (PyMethodDescrObject *)obj; |
| 248 | ++// _ADDDOC(new->d_method->ml_doc, new->d_method->ml_name); |
| 249 | ++// } |
| 250 | ++// else { |
| 251 | ++// PyObject *doc_attr; |
| 252 | ++// |
| 253 | ++// doc_attr = PyObject_GetAttrString(obj, "__doc__"); |
| 254 | ++// if (doc_attr != NULL && doc_attr != Py_None && |
| 255 | ++// (PyUnicode_Compare(doc_attr, str) != 0)) { |
| 256 | ++// Py_DECREF(doc_attr); |
| 257 | ++// if (PyErr_Occurred()) { |
| 258 | ++// /* error during PyUnicode_Compare */ |
| 259 | ++// return NULL; |
| 260 | ++// } |
| 261 | ++// PyErr_Format(PyExc_RuntimeError, "object %s", msg); |
| 262 | ++// return NULL; |
| 263 | ++// } |
| 264 | ++// Py_XDECREF(doc_attr); |
| 265 | ++// |
| 266 | ++// if (PyObject_SetAttrString(obj, "__doc__", str) < 0) { |
| 267 | ++// PyErr_SetString(PyExc_TypeError, |
| 268 | ++// "Cannot set a docstring for that object"); |
| 269 | ++// return NULL; |
| 270 | ++// } |
| 271 | ++// Py_RETURN_NONE; |
| 272 | ++// } |
| 273 | ++// |
| 274 | ++// #undef _ADDDOC |
| 275 | + |
| 276 | + Py_RETURN_NONE; |
| 277 | + } |
| 278 | +diff --git a/numpy/core/src/multiarray/iterators.c b/numpy/core/src/multiarray/iterators.c |
| 279 | +index f959162..2ef579b 100644 |
| 280 | +--- a/numpy/core/src/multiarray/iterators.c |
| 281 | ++++ b/numpy/core/src/multiarray/iterators.c |
| 282 | +@@ -1400,7 +1400,11 @@ arraymultiter_new(PyTypeObject *NPY_UNUSED(subtype), PyObject *args, |
| 283 | + Py_DECREF(fast_seq); |
| 284 | + return multiiter_wrong_number_of_args(); |
| 285 | + } |
| 286 | +- ret = multiiter_new_impl(n, PySequence_Fast_ITEMS(fast_seq)); |
| 287 | ++ PyObject* seq[n]; |
| 288 | ++ for (int i = 0; i < n; i++) { |
| 289 | ++ seq[i] = PySequence_Fast_GET_ITEM(fast_seq, i); |
| 290 | ++ } |
| 291 | ++ ret = multiiter_new_impl(n, seq); |
| 292 | + Py_DECREF(fast_seq); |
| 293 | + return ret; |
| 294 | + } |
| 295 | +diff --git a/numpy/core/src/multiarray/methods.c b/numpy/core/src/multiarray/methods.c |
| 296 | +index 161dca1..bedca0c 100644 |
| 297 | +--- a/numpy/core/src/multiarray/methods.c |
| 298 | ++++ b/numpy/core/src/multiarray/methods.c |
| 299 | +@@ -1095,7 +1095,6 @@ any_array_ufunc_overrides(PyObject *args, PyObject *kwds) |
| 300 | + int nin, nout; |
| 301 | + PyObject *out_kwd_obj; |
| 302 | + PyObject *fast; |
| 303 | +- PyObject **in_objs, **out_objs; |
| 304 | + |
| 305 | + /* check inputs */ |
| 306 | + nin = PyTuple_Size(args); |
| 307 | +@@ -1106,21 +1105,20 @@ any_array_ufunc_overrides(PyObject *args, PyObject *kwds) |
| 308 | + if (fast == NULL) { |
| 309 | + return -1; |
| 310 | + } |
| 311 | +- in_objs = PySequence_Fast_ITEMS(fast); |
| 312 | + for (i = 0; i < nin; ++i) { |
| 313 | +- if (PyUFunc_HasOverride(in_objs[i])) { |
| 314 | ++ if (PyUFunc_HasOverride(PySequence_Fast_GET_ITEM(fast, i))) { |
| 315 | + Py_DECREF(fast); |
| 316 | + return 1; |
| 317 | + } |
| 318 | + } |
| 319 | + Py_DECREF(fast); |
| 320 | + /* check outputs, if any */ |
| 321 | +- nout = PyUFuncOverride_GetOutObjects(kwds, &out_kwd_obj, &out_objs); |
| 322 | ++ nout = PyUFuncOverride_GetOutObjects(kwds, &out_kwd_obj); |
| 323 | + if (nout < 0) { |
| 324 | + return -1; |
| 325 | + } |
| 326 | + for (i = 0; i < nout; i++) { |
| 327 | +- if (PyUFunc_HasOverride(out_objs[i])) { |
| 328 | ++ if (PyUFunc_HasOverride(PySequence_Fast_GET_ITEM(out_kwd_obj, i))) { |
| 329 | + Py_DECREF(out_kwd_obj); |
| 330 | + return 1; |
| 331 | + } |
| 332 | +diff --git a/numpy/core/src/umath/extobj.c b/numpy/core/src/umath/extobj.c |
| 333 | +index 6b9a27e..8de94fb 100644 |
| 334 | +--- a/numpy/core/src/umath/extobj.c |
| 335 | ++++ b/numpy/core/src/umath/extobj.c |
| 336 | +@@ -283,7 +283,7 @@ _check_ufunc_fperr(int errmask, PyObject *extobj, const char *ufunc_name) { |
| 337 | + if (!errmask) { |
| 338 | + return 0; |
| 339 | + } |
| 340 | +- fperr = npy_get_floatstatus_barrier((char*)extobj); |
| 341 | ++ fperr = npy_get_floatstatus_barrier((char*)ufunc_name); |
| 342 | + if (!fperr) { |
| 343 | + return 0; |
| 344 | + } |
| 345 | +diff --git a/tools/cythonize.py b/tools/cythonize.py |
| 346 | +index 002b2fa..fd05e01 100755 |
| 347 | +--- a/tools/cythonize.py |
| 348 | ++++ b/tools/cythonize.py |
| 349 | +@@ -48,9 +48,14 @@ def process_pyx(fromfile, tofile): |
| 350 | + if tofile.endswith('.cxx'): |
| 351 | + flags.append('--cplus') |
| 352 | + |
| 353 | +- subprocess.check_call( |
| 354 | +- [sys.executable, '-m', 'cython'] + flags + ["-o", tofile, fromfile]) |
| 355 | ++ print("processing: " + (" ".join(flags + ["-o", tofile, fromfile]))) |
| 356 | ++ from Cython.Compiler.CmdLine import parse_command_line |
| 357 | ++ from Cython.Compiler.Main import compile |
| 358 | + |
| 359 | ++ options, sources = parse_command_line(flags + ["-o", tofile, fromfile]) |
| 360 | ++ result = compile(sources, options) |
| 361 | ++ if result.num_errors > 0: |
| 362 | ++ raise Exception("Cython either isn't installed or it failed.") from e |
| 363 | + |
| 364 | + def process_tempita_pyx(fromfile, tofile): |
| 365 | + import npy_tempita as tempita |
0 commit comments