Skip to content

Commit 364d295

Browse files
rewrite divide indexed
1 parent 24fa4cd commit 364d295

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

numpy/_core/src/umath/loops_arithmetic.dispatch.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -259,49 +259,51 @@ void TYPE_divide_unsigned(char **args, npy_intp const *dimensions, npy_intp cons
259259

260260
// Indexed division for signed integers
261261
template <typename T>
262-
int TYPE_divide_indexed(char * const*args, npy_intp const *dimensions, npy_intp const *steps, NpyAuxData *NPY_UNUSED(func)) {
262+
int TYPE_divide_indexed(char * const*args, npy_intp const *dimensions,
263+
npy_intp const *steps, NpyAuxData *NPY_UNUSED(func)) {
263264
char *ip1 = args[0];
264265
char *indxp = args[1];
265266
char *value = args[2];
266267
npy_intp is1 = steps[0], isindex = steps[1], isb = steps[2];
267268
npy_intp shape = steps[3];
268269
npy_intp n = dimensions[0];
269-
npy_intp i;
270-
T *indexed;
271-
for(i = 0; i < n; i++, indxp += isindex, value += isb) {
270+
271+
for(npy_intp i = 0; i < n; i++, indxp += isindex, value += isb) {
272272
npy_intp indx = *(npy_intp *)indxp;
273273
if (indx < 0) {
274274
indx += shape;
275275
}
276-
indexed = (T *)(ip1 + is1 * indx);
277-
*indexed = floor_div(*indexed, *(T *)value);
276+
T* indexed = reinterpret_cast<T*>(ip1 + is1 * indx);
277+
T divisor = *reinterpret_cast<T*>(value);
278+
*indexed = floor_div(*indexed, divisor);
278279
}
279280
return 0;
280281
}
281282

282283
// Indexed division for unsigned integers
283284
template <typename T>
284-
int TYPE_divide_unsigned_indexed(char * const*args, npy_intp const *dimensions, npy_intp const *steps, NpyAuxData *NPY_UNUSED(func)) {
285+
int TYPE_divide_unsigned_indexed(char * const*args, npy_intp const *dimensions,
286+
npy_intp const *steps, NpyAuxData *NPY_UNUSED(func)) {
285287
char *ip1 = args[0];
286288
char *indxp = args[1];
287289
char *value = args[2];
288290
npy_intp is1 = steps[0], isindex = steps[1], isb = steps[2];
289291
npy_intp shape = steps[3];
290292
npy_intp n = dimensions[0];
291-
npy_intp i;
292-
T *indexed;
293-
for(i = 0; i < n; i++, indxp += isindex, value += isb) {
293+
294+
for(npy_intp i = 0; i < n; i++, indxp += isindex, value += isb) {
294295
npy_intp indx = *(npy_intp *)indxp;
295296
if (indx < 0) {
296297
indx += shape;
297298
}
298-
indexed = (T *)(ip1 + is1 * indx);
299-
T in2 = *(T *)value;
300-
if (HWY_UNLIKELY(in2 == 0)) {
299+
T* indexed = reinterpret_cast<T*>(ip1 + is1 * indx);
300+
T divisor = *reinterpret_cast<T*>(value);
301+
302+
if (HWY_UNLIKELY(divisor == 0)) {
301303
npy_set_floatstatus_divbyzero();
302304
*indexed = 0;
303305
} else {
304-
*indexed = *indexed / in2;
306+
*indexed = *indexed / divisor;
305307
}
306308
}
307309
return 0;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy