diff options
| author | Sebastian Berg <sebastianb@nvidia.com> | 2023-01-05 12:10:10 +0100 |
|---|---|---|
| committer | Sebastian Berg <sebastianb@nvidia.com> | 2023-02-19 19:52:05 +0100 |
| commit | 65340d930d1e58c5f8a10a892a2aa03ca54400e0 (patch) | |
| tree | d46680fc555bcf60e059754f489347b4722e999a /numpy/core/src/multiarray | |
| parent | 4d7c29d9cc81a528717692bd796da3e55f7c7866 (diff) | |
| download | numpy-65340d930d1e58c5f8a10a892a2aa03ca54400e0.tar.gz | |
MAINT: Address review comments
Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
Diffstat (limited to 'numpy/core/src/multiarray')
| -rw-r--r-- | numpy/core/src/multiarray/array_method.c | 24 | ||||
| -rw-r--r-- | numpy/core/src/multiarray/dtype_traversal.c | 14 | ||||
| -rw-r--r-- | numpy/core/src/multiarray/dtype_traversal.h | 19 | ||||
| -rw-r--r-- | numpy/core/src/multiarray/dtypemeta.h | 6 | ||||
| -rw-r--r-- | numpy/core/src/multiarray/nditer_constr.c | 1 |
5 files changed, 37 insertions, 27 deletions
diff --git a/numpy/core/src/multiarray/array_method.c b/numpy/core/src/multiarray/array_method.c index ef5a28ceb..c64a4bde8 100644 --- a/numpy/core/src/multiarray/array_method.c +++ b/numpy/core/src/multiarray/array_method.c @@ -344,13 +344,23 @@ fill_arraymethod_from_slots( } /* Check whether the provided loops make sense. */ - if ((meth->unaligned_strided_loop == NULL) != - !(meth->flags & NPY_METH_SUPPORTS_UNALIGNED)) { - PyErr_Format(PyExc_TypeError, - "Must provide unaligned strided inner loop for method to " - "indicate unaligned support (method: %s)", - spec->name); - return -1; + if (meth->flags & NPY_METH_SUPPORTS_UNALIGNED) { + if (meth->unaligned_strided_loop == NULL) { + PyErr_Format(PyExc_TypeError, + "Must provide unaligned strided inner loop for method to " + "indicate unaligned support (method: %s)", + spec->name); + return -1; + } + } + else { + if (meth->unaligned_strided_loop != NULL) { + PyErr_Format(PyExc_TypeError, + "Method indicates unaligned support but provides no " + "unaligned strided loop (method: %s)", + spec->name); + return -1; + } } /* Fill in the blanks: */ if (meth->unaligned_contiguous_loop == NULL) { diff --git a/numpy/core/src/multiarray/dtype_traversal.c b/numpy/core/src/multiarray/dtype_traversal.c index 3906cd996..6a1d31b8f 100644 --- a/numpy/core/src/multiarray/dtype_traversal.c +++ b/numpy/core/src/multiarray/dtype_traversal.c @@ -7,7 +7,7 @@ * Python object DECREF/dealloc followed by NULL'ing the data * (to support double clearing on errors). * However, memory initialization and traverse follows similar - * protocols (although traversal needs additional arguments. + * protocols (although traversal needs additional arguments). */ #define NPY_NO_DEPRECATED_API NPY_API_VERSION @@ -46,7 +46,7 @@ get_clear_function( /* not that cleanup code bothers to check e.g. for floating point flags */ *flags = PyArrayMethod_MINIMAL_FLAGS; - get_simple_loop_function *get_clear = NPY_DT_SLOTS(NPY_DTYPE(dtype))->get_clear_loop; + get_traverse_loop_function *get_clear = NPY_DT_SLOTS(NPY_DTYPE(dtype))->get_clear_loop; if (get_clear == NULL) { PyErr_Format(PyExc_RuntimeError, "Internal error, tried to fetch decref/clear function for the " @@ -112,7 +112,7 @@ NPY_NO_EXPORT int npy_get_clear_object_strided_loop( void *NPY_UNUSED(traverse_context), PyArray_Descr *NPY_UNUSED(descr), int NPY_UNUSED(aligned), npy_intp NPY_UNUSED(fixed_stride), - simple_loop_function **out_loop, NpyAuxData **out_auxdata, + traverse_loop_function **out_loop, NpyAuxData **out_auxdata, NPY_ARRAYMETHOD_FLAGS *flags) { *flags = NPY_METH_REQUIRES_PYAPI|NPY_METH_NO_FLOATINGPOINT_ERRORS; @@ -237,7 +237,7 @@ traverse_fields_function( static int get_clear_fields_transfer_function( void *traverse_context, PyArray_Descr *dtype, int NPY_UNUSED(aligned), - npy_intp stride, simple_loop_function **out_func, + npy_intp stride, traverse_loop_function **out_func, NpyAuxData **out_auxdata, NPY_ARRAYMETHOD_FLAGS *flags) { PyObject *names, *key, *tup, *title; @@ -342,7 +342,7 @@ traverse_subarray_func( { subarray_clear_data *subarr_data = (subarray_clear_data *)auxdata; - simple_loop_function *func = subarr_data->info.func; + traverse_loop_function *func = subarr_data->info.func; PyArray_Descr *sub_descr = subarr_data->info.descr; npy_intp sub_N = subarr_data->count; NpyAuxData *sub_auxdata = subarr_data->info.auxdata; @@ -362,7 +362,7 @@ traverse_subarray_func( static int get_subarray_clear_func( void *traverse_context, PyArray_Descr *dtype, int aligned, - npy_intp size, npy_intp stride, simple_loop_function **out_func, + npy_intp size, npy_intp stride, traverse_loop_function **out_func, NpyAuxData **out_auxdata, NPY_ARRAYMETHOD_FLAGS *flags) { subarray_clear_data *auxdata = PyMem_Malloc(sizeof(subarray_clear_data)); @@ -401,7 +401,7 @@ clear_no_op( NPY_NO_EXPORT int npy_get_clear_void_and_legacy_user_dtype_loop( void *traverse_context, PyArray_Descr *dtype, int aligned, - npy_intp stride, simple_loop_function **out_func, + npy_intp stride, traverse_loop_function **out_func, NpyAuxData **out_auxdata, NPY_ARRAYMETHOD_FLAGS *flags) { /* diff --git a/numpy/core/src/multiarray/dtype_traversal.h b/numpy/core/src/multiarray/dtype_traversal.h index 6559b1023..d574657fb 100644 --- a/numpy/core/src/multiarray/dtype_traversal.h +++ b/numpy/core/src/multiarray/dtype_traversal.h @@ -4,25 +4,26 @@ #include "array_method.h" /* - * A simplified loop, similar to a general strided-loop function. - * Using a `void *reserved`, because I think we probably need to pass in + * A traverse loop working on a single array. This is similar to the general + * strided-loop function. + * Using a `void *traverse_context`, because I we may need to pass in * Intepreter state or similar in the future. But I don't want to pass in * a full context (with pointers to dtypes, method, caller which all make - * no sense for a simple function). + * no sense for a traverse function). * * We assume for now that this context can be just passed through in the * the future (for structured dtypes). */ -typedef int (simple_loop_function)( +typedef int (traverse_loop_function)( void *traverse_context, PyArray_Descr *descr, char *data, npy_intp size, npy_intp stride, NpyAuxData *auxdata); /* Simplified get_loop function specific to dtype traversal */ -typedef int (get_simple_loop_function)( +typedef int (get_traverse_loop_function)( void *traverse_context, PyArray_Descr *descr, int aligned, npy_intp fixed_stride, - simple_loop_function **out_loop, NpyAuxData **out_auxdata, + traverse_loop_function **out_loop, NpyAuxData **out_auxdata, NPY_ARRAYMETHOD_FLAGS *flags); @@ -32,21 +33,21 @@ NPY_NO_EXPORT int npy_get_clear_object_strided_loop( void *traverse_context, PyArray_Descr *descr, int aligned, npy_intp fixed_stride, - simple_loop_function **out_loop, NpyAuxData **out_transferdata, + traverse_loop_function **out_loop, NpyAuxData **out_traversedata, NPY_ARRAYMETHOD_FLAGS *flags); NPY_NO_EXPORT int npy_get_clear_void_and_legacy_user_dtype_loop( void *traverse_context, PyArray_Descr *descr, int aligned, npy_intp fixed_stride, - simple_loop_function **out_loop, NpyAuxData **out_transferdata, + traverse_loop_function **out_loop, NpyAuxData **out_traversedata, NPY_ARRAYMETHOD_FLAGS *flags); /* Helper to deal with calling or nesting simple strided loops */ typedef struct { - simple_loop_function *func; + traverse_loop_function *func; NpyAuxData *auxdata; PyArray_Descr *descr; } NPY_traverse_info; diff --git a/numpy/core/src/multiarray/dtypemeta.h b/numpy/core/src/multiarray/dtypemeta.h index 401163c46..3acbcb561 100644 --- a/numpy/core/src/multiarray/dtypemeta.h +++ b/numpy/core/src/multiarray/dtypemeta.h @@ -36,10 +36,10 @@ typedef struct { PyArrayMethodObject *within_dtype_castingimpl; /* * Implementation which clears a dtype or NULL. If not given, setting - * HASREF on the dtype is invalid. We only use the loop getting, not - * any resolution. + * NPY_ITEM_REFCOUNT on the dtype is invalid. Note that NPY_ITEM_REFCOUNT + * may inidicate references that are not Python objects. */ - get_simple_loop_function *get_clear_loop; + get_traverse_loop_function *get_clear_loop; /* * Dictionary of ArrayMethods representing most possible casts * (structured and object are exceptions). diff --git a/numpy/core/src/multiarray/nditer_constr.c b/numpy/core/src/multiarray/nditer_constr.c index baa6dc746..0ed475c5b 100644 --- a/numpy/core/src/multiarray/nditer_constr.c +++ b/numpy/core/src/multiarray/nditer_constr.c @@ -3216,7 +3216,6 @@ npyiter_allocate_transfer_functions(NpyIter *iter) (flags & NPY_OP_ITFLAG_ALIGNED) != 0, op_dtype[iop]->elsize, op_dtype[iop], &transferinfo[iop].clear, &nc_flags) < 0) { - printf("ahhhhh!\n"); goto fail; } cflags = PyArrayMethod_COMBINED_FLAGS(cflags, nc_flags); |
