diff options
| author | Sebastian Berg <sebastianb@nvidia.com> | 2022-11-04 15:23:54 +0100 |
|---|---|---|
| committer | Sebastian Berg <sebastianb@nvidia.com> | 2023-01-20 15:28:48 +0100 |
| commit | 83a321cac12970b975fd66011db87dee291edf2c (patch) | |
| tree | d3937efdbc7ac3d93d9d001b7b9d5a7ee93ad00d /numpy | |
| parent | b6d8549f1250fd8a537328f3a5166e730423313a (diff) | |
| download | numpy-83a321cac12970b975fd66011db87dee291edf2c.tar.gz | |
BUG: Fixup copying the wrong size in the cached path mostly
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/core/src/umath/legacy_array_method.c | 10 | ||||
| -rw-r--r-- | numpy/core/src/umath/reduction.c | 6 |
2 files changed, 8 insertions, 8 deletions
diff --git a/numpy/core/src/umath/legacy_array_method.c b/numpy/core/src/umath/legacy_array_method.c index 435afd6e6..88e55fcb2 100644 --- a/numpy/core/src/umath/legacy_array_method.c +++ b/numpy/core/src/umath/legacy_array_method.c @@ -246,8 +246,8 @@ copy_cached_initial( PyArrayMethod_Context *context, char *initial, npy_bool NPY_UNUSED(reduction_is_empty)) { - memcpy(initial, context->method->initial, sizeof(context->descriptors[0]->elsize)); - return 0; + memcpy(initial, context->method->initial, context->descriptors[0]->elsize); + return 1; } @@ -279,7 +279,7 @@ get_initial_from_ufunc( Py_DECREF(identity_obj); return 0; } - if (PyTypeNum_ISUNSIGNED(context->descriptors[0]->type_num) + if (PyTypeNum_ISUNSIGNED(context->descriptors[1]->type_num) && PyLong_CheckExact(identity_obj)) { /* * This is a bit of a hack until we have truly loop specific @@ -297,7 +297,7 @@ get_initial_from_ufunc( } else if (context->descriptors[0]->type_num == NPY_OBJECT && !reduction_is_empty) { - /* Allow `sum([object()])` to work, but use 0 when empty */ + /* Allows `sum([object()])` to work, but use 0 when empty. */ Py_DECREF(identity_obj); return 0; } @@ -309,7 +309,7 @@ get_initial_from_ufunc( } if (PyTypeNum_ISNUMBER(context->descriptors[0]->type_num)) { - /* From now on, simply use the cached version */ + /* For numbers we can cache to avoid going via Python ints */ memcpy(context->method->initial, initial, context->descriptors[0]->elsize); context->method->get_reduction_initial = ©_cached_initial; } diff --git a/numpy/core/src/umath/reduction.c b/numpy/core/src/umath/reduction.c index f5fad83dc..c796795f7 100644 --- a/numpy/core/src/umath/reduction.c +++ b/numpy/core/src/umath/reduction.c @@ -319,12 +319,12 @@ PyUFunc_ReduceWrapper(PyArrayMethod_Context *context, * empty when the iteration is. This may be wrong, but when it is, * we will not need the identity as the result is also empty. */ - int res = context->method->get_reduction_initial( + int has_initial = context->method->get_reduction_initial( context, initial_buf, empty_iteration); - if (res < 0) { + if (has_initial < 0) { goto fail; } - if (!res) { + if (!has_initial) { /* We have no initial value available, free buffer to indicate */ PyMem_FREE(initial_buf); initial_buf = NULL; |
