@@ -400,14 +400,19 @@ NPY_NO_EXPORT int NPY_CPU_DISPATCH_CURFX(@TYPE@_divide_indexed)
400400(PyArrayMethod_Context *NPY_UNUSED(context), char * const*args, npy_intp const *dimensions, npy_intp const *steps, NpyAuxData *NPY_UNUSED(func))
401401{
402402 char *ip1 = args[0];
403- char *indx = args[1];
403+ char *indxp = args[1];
404404 char *value = args[2];
405405 npy_intp is1 = steps[0], isindex = steps[1], isb = steps[2];
406+ npy_intp shape = steps[3];
406407 npy_intp n = dimensions[0];
407408 npy_intp i;
408409 @type@ *indexed;
409- for(i = 0; i < n; i++, indx += isindex, value += isb) {
410- indexed = (@type@ *)(ip1 + is1 * *(npy_intp *)indx);
410+ for(i = 0; i < n; i++, indxp += isindex, value += isb) {
411+ npy_intp indx = *(npy_intp *)indxp;
412+ if (indx < 0) {
413+ indx += shape;
414+ }
415+ indexed = (@type@ *)(ip1 + is1 * indx);
411416 *indexed = floor_div_@TYPE@(*indexed, *(@type@ *)value);
412417 }
413418 return 0;
@@ -486,14 +491,19 @@ NPY_NO_EXPORT int NPY_CPU_DISPATCH_CURFX(@TYPE@_divide_indexed)
486491(PyArrayMethod_Context *NPY_UNUSED(context), char * const*args, npy_intp const *dimensions, npy_intp const *steps, NpyAuxData *NPY_UNUSED(func))
487492{
488493 char *ip1 = args[0];
489- char *indx = args[1];
494+ char *indxp = args[1];
490495 char *value = args[2];
491496 npy_intp is1 = steps[0], isindex = steps[1], isb = steps[2];
497+ npy_intp shape = steps[3];
492498 npy_intp n = dimensions[0];
493499 npy_intp i;
494500 @type@ *indexed;
495- for(i = 0; i < n; i++, indx += isindex, value += isb) {
496- indexed = (@type@ *)(ip1 + is1 * *(npy_intp *)indx);
501+ for(i = 0; i < n; i++, indxp += isindex, value += isb) {
502+ npy_intp indx = *(npy_intp *)indxp;
503+ if (indx < 0) {
504+ indx += shape;
505+ }
506+ indexed = (@type@ *)(ip1 + is1 * indx);
497507 @type@ in2 = *(@type@ *)value;
498508 if (NPY_UNLIKELY(in2 == 0)) {
499509 npy_set_floatstatus_divbyzero();
0 commit comments