Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ef0f010

Browse files
change dispatch logic
1 parent 3a4bf6e commit ef0f010

File tree

1 file changed

+28
-31
lines changed

1 file changed

+28
-31
lines changed

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

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
#define _MULTIARRAYMODULE
33
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
44

5+
#include "numpy/npy_common.h"
6+
#include "numpy/npy_math.h"
7+
58
#include "loops_utils.h"
69
#include "loops.h"
7-
#include <cstring> // for memcpy
810
#include "fast_loop_macros.h"
9-
#include <limits>
1011
#include "simd/simd.h"
1112
#include "lowlevel_strided_loops.h"
12-
#include "numpy/npy_math.h"
13+
#include "common.hpp"
14+
15+
#include <cstring> // for memcpy
16+
#include <limits>
1317
#include <cstdio>
1418

1519
#include <hwy/highway.h>
@@ -308,6 +312,7 @@ int TYPE_divide_unsigned_indexed(PyArrayMethod_Context *NPY_UNUSED(context),
308312
return 0;
309313
}
310314

315+
// Macro to define the dispatch functions for signed types
311316
#define DEFINE_DIVIDE_FUNCTION(TYPE, SCALAR_TYPE) \
312317
extern "C" { \
313318
NPY_NO_EXPORT void NPY_CPU_DISPATCH_CURFX(TYPE##_divide)(char **args, npy_intp const *dimensions, npy_intp const *steps, void *func) { \
@@ -318,24 +323,7 @@ int TYPE_divide_unsigned_indexed(PyArrayMethod_Context *NPY_UNUSED(context),
318323
} \
319324
} // extern "C"
320325

321-
322-
#ifdef NPY_CPU_DISPATCH_CURFX
323-
// On Linux and macOS (LP64 model), long is 64 bits, but on 32-bit Windows (LLP64 model), long is 32 bits. Meanwhile, long long is guaranteed at least 64 bits
324-
#if defined(_WIN32) || defined(__EMSCRIPTEN__) || (defined(__arm__) && !defined(__aarch64__)) || (defined(__linux__) && ((defined(__i386__) || defined(__i686__))))
325-
DEFINE_DIVIDE_FUNCTION(BYTE, int8_t)
326-
DEFINE_DIVIDE_FUNCTION(SHORT, int16_t)
327-
DEFINE_DIVIDE_FUNCTION(INT, int32_t)
328-
DEFINE_DIVIDE_FUNCTION(LONG, int32_t) // LONG is 32-bit on 32-bit platforms
329-
DEFINE_DIVIDE_FUNCTION(LONGLONG, int64_t)
330-
#else
331-
DEFINE_DIVIDE_FUNCTION(BYTE, int8_t)
332-
DEFINE_DIVIDE_FUNCTION(SHORT, int16_t)
333-
DEFINE_DIVIDE_FUNCTION(INT, int32_t)
334-
DEFINE_DIVIDE_FUNCTION(LONG, int64_t) // LONG is 64-bit on 64-bit platforms
335-
DEFINE_DIVIDE_FUNCTION(LONGLONG, int64_t)
336-
#endif
337-
#endif
338-
326+
// Macro to define the dispatch functions for unsigned types
339327
#define DEFINE_DIVIDE_FUNCTION_UNSIGNED(TYPE, SCALAR_TYPE) \
340328
extern "C" { \
341329
NPY_NO_EXPORT void NPY_CPU_DISPATCH_CURFX(TYPE##_divide)(char **args, npy_intp const *dimensions, npy_intp const *steps, void *func) { \
@@ -344,23 +332,32 @@ int TYPE_divide_unsigned_indexed(PyArrayMethod_Context *NPY_UNUSED(context),
344332
NPY_NO_EXPORT int NPY_CPU_DISPATCH_CURFX(TYPE##_divide_indexed)(PyArrayMethod_Context *context, char * const*args, npy_intp const *dimensions, npy_intp const *steps, NpyAuxData *func) { \
345333
return TYPE_divide_unsigned_indexed<SCALAR_TYPE>(context, args, dimensions, steps, func); \
346334
} \
347-
}
335+
} // extern "C"
336+
337+
338+
#ifdef NPY_CPU_DISPATCH_CURFX
339+
DEFINE_DIVIDE_FUNCTION(BYTE, int8_t)
340+
DEFINE_DIVIDE_FUNCTION(SHORT, int16_t)
341+
DEFINE_DIVIDE_FUNCTION(INT, int32_t)
342+
#if NPY_SIZEOF_LONG == 4
343+
DEFINE_DIVIDE_FUNCTION(LONG, int32_t)
344+
#elif NPY_SIZEOF_LONG == 8
345+
DEFINE_DIVIDE_FUNCTION(LONG, int64_t)
346+
#endif
347+
DEFINE_DIVIDE_FUNCTION(LONGLONG, int64_t)
348+
#endif
348349

349350
#ifdef NPY_CPU_DISPATCH_CURFX
350-
#if defined(_WIN32) || defined(__EMSCRIPTEN__) || (defined(__arm__) && !defined(__aarch64__)) || (defined(__linux__) && ((defined(__i386__) || defined(__i686__))))
351-
DEFINE_DIVIDE_FUNCTION_UNSIGNED(UBYTE, uint8_t)
352-
DEFINE_DIVIDE_FUNCTION_UNSIGNED(USHORT, uint16_t)
353-
DEFINE_DIVIDE_FUNCTION_UNSIGNED(UINT, uint32_t)
354-
DEFINE_DIVIDE_FUNCTION_UNSIGNED(ULONG, uint32_t) // ULONG is 32-bit on 32-bit platforms
355-
DEFINE_DIVIDE_FUNCTION_UNSIGNED(ULONGLONG, uint64_t)
356-
#else
357351
DEFINE_DIVIDE_FUNCTION_UNSIGNED(UBYTE, uint8_t)
358352
DEFINE_DIVIDE_FUNCTION_UNSIGNED(USHORT, uint16_t)
359353
DEFINE_DIVIDE_FUNCTION_UNSIGNED(UINT, uint32_t)
360-
DEFINE_DIVIDE_FUNCTION_UNSIGNED(ULONG, uint64_t) // ULONG is 64-bit on 64-bit platforms
354+
#if NPY_SIZEOF_LONG == 4
355+
DEFINE_DIVIDE_FUNCTION_UNSIGNED(ULONG, uint32_t)
356+
#elif NPY_SIZEOF_LONG == 8
357+
DEFINE_DIVIDE_FUNCTION_UNSIGNED(ULONG, uint64_t)
358+
#endif
361359
DEFINE_DIVIDE_FUNCTION_UNSIGNED(ULONGLONG, uint64_t)
362360
#endif
363-
#endif
364361

365362
#undef DEFINE_DIVIDE_FUNCTION
366363
#undef DEFINE_DIVIDE_FUNCTION_UNSIGNED

0 commit comments

Comments
 (0)