8000 ENH: Remove looping definitions | Renamed fast loop macros · numpy/numpy@285d810 · GitHub
[go: up one dir, main page]

Skip to content

Commit 285d810

Browse files
committed
ENH: Remove looping definitions | Renamed fast loop macros
1 parent f93ca93 commit 285d810

File tree

2 files changed

+19
-28
lines changed

2 files changed

+19
-28
lines changed

numpy/core/src/umath/fast_loop_macros.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ abs_ptrdiff(char *a, char *b)
4646
npy_intp i;\
4747
for(i = 0; i < n; i++, ip1 += is1, op1 += os1, op2 += os2)
4848

49-
#define BINARY_LOOP_BASE\
49+
#define BINARY_DEFS\
5050
char *ip1 = args[0], *ip2 = args[1], *op1 = args[2];\
5151
npy_intp is1 = steps[0], is2 = steps[1], os1 = steps[2];\
5252
npy_intp n = dimensions[0];\
@@ -55,15 +55,9 @@ abs_ptrdiff(char *a, char *b)
5555
#define BINARY_LOOP_SLIDING\
5656
for(i = 0; i < n; i++, ip1 += is1, ip2 += is2, op1 += os1)
5757

58-
#define BINARY_LOOP_FIXED\
59-
for(i = 0; i < n; i++, ip1 += is1, op1 += os1)
60-
61-
#define BINARY_LOOP_ZERO\
62-
for(i = 0; i < n; i++, op1 += os1)
63-
6458
/** (ip1, ip2) -> (op1) */
6559
#define BINARY_LOOP\
66-
BINARY_LOOP_BASE\
60+
BINARY_DEFS\
6761
BINARY_LOOP_SLIDING
6862

6963
/** (ip1, ip2) -> (op1, op2) */
@@ -167,10 +161,7 @@ abs_ptrdiff(char *a, char *b)
167161
#define IVDEP_LOOP
168162
#endif
169163
#define BASE_BINARY_LOOP_INP(tin, tout, op) \
170-
char *ip1 = args[0], *ip2 = args[1], *op1 = args[2];\
171-
npy_intp is1 = steps[0], is2 = steps[1], os1 = steps[2];\
172-
npy_intp n = dimensions[0];\
173-
npy_intp i;\
164+
BINARY_DEFS\
174165
IVDEP_LOOP \
175166
for(i = 0; i < n; i++, ip1 += is1, ip2 += is2, op1 += os1) { \
176167
const tin in1 = *(tin *)ip1; \

numpy/core/src/umath/loops.c.src

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -847,35 +847,35 @@ NPY_NO_EXPORT NPY_GCC_OPT_3 void
847847

848848
/* Libdivide only supports 32 and 64 bit types
849849
* We try to pick the best possible one */
850-
/**begin repeat1
851-
* #kind = t, gen, do#
852-
*/
853850
#if NPY_BITSOF_@TYPE@ <= 32
854-
#define libdivide_@type@_@kind@ libdivide_s32_@kind@
851+
#define libdivide_@type@_t libdivide_s32_t
852+
#define libdivide_@type@_gen libdivide_s32_gen
853+
#define libdivide_@type@_do libdivide_s32_do
855854
#else
856-
#define libdivide_@type@_@kind@ libdivide_s64_@kind@
855+
#define libdivide_@type@_t libdivide_s64_t
856+
#define libdivide_@type@_gen libdivide_s64_gen
857+
#define libdivide_@type@_do libdivide_s64_do
857858
#endif
858-
/**end repeat1**/
859859

860860
NPY_NO_EXPORT void
861861
@TYPE@_divide(char **args, npy_intp const *dimensions, npy_intp const *steps, void *NPY_UNUSED(func))
862862
{
863-
BINARY_LOOP_BASE
863+
BINARY_DEFS
864864

865865
/* When the divisor is a constant, use libdivde for faster division */
866866
if (steps[1] == 0) {
867867
const @type@ in2 = *(@type@ *)ip2;
868868

869869
/* If divisor is 0, we need not compute anything*/
870870
if (in2 == 0) {
871-
BINARY_LOOP_ZERO {
871+
BINARY_LOOP_SLIDING {
872872
npy_set_floatstatus_divbyzero();
873873
*((@type@ *)op1) = 0;
874874
}
875875
}
876876
else {
877877
struct libdivide_@type@_t fast_d = libdivide_@type@_gen(in2);
878-
BINARY_LOOP_FIXED {
878+
BINARY_LOOP_SLIDING {
879879
const @type@ in1 = *(@type@ *)ip1;
880880
/*
881881
* FIXME: On x86 at least, dividing the smallest representable integer
@@ -1412,22 +1412,22 @@ TIMEDELTA_dm_m_multiply(char **args, npy_intp const *dimensions, npy_intp const
14121412
NPY_NO_EXPORT void
14131413
TIMEDELTA_mq_m_divide(char **args, npy_intp const *dimensions, npy_intp const *steps, void *NPY_UNUSED(func))
14141414
{
1415-
BINARY_LOOP_BASE
1415+
BINARY_DEFS
14161416

14171417
/* When the divisor is a constant, use libdivde for faster division */
14181418
if (steps[1] == 0) {
14191419
const npy_int64 in2 = *(npy_int64 *)ip2;
14201420

14211421
/* If divisor is 0, we need not compute anything */
14221422
if (in2 == 0) {
1423-
BINARY_LOOP_ZERO {
1423+
BINARY_LOOP_SLIDING {
14241424
npy_set_floatstatus_divbyzero();
14251425
*((npy_timedelta *)op1) = NPY_DATETIME_NAT;
14261426
}
14271427
}
14281428
else {
14291429
struct libdivide_s64_t fast_d = libdivide_s64_gen(in2);
1430-
BINARY_LOOP_FIXED {
1430+
BINARY_LOOP_SLIDING {
14311431
const npy_timedelta in1 = *(npy_timedelta *)ip1;
14321432
if (in1 == NPY_DATETIME_NAT) {
14331433
*((npy_timedelta *)op1) = NPY_DATETIME_NAT;
@@ -1520,28 +1520,28 @@ NPY_NO_EXPORT void
15201520
TIMEDELTA_mm_q_floor_divide(char **args, npy_intp const *dimensions, npy_intp const *steps, void *NPY_UNUSED(func))
15211521
{
15221522
/* NOTE: This code is similar to array floor divide*/
1523-
BINARY_LOOP_BASE
1523+
BINARY_DEFS
15241524

15251525
/* When the divisor is a constant, use libdivde for faster division */
15261526
if (steps[1] == 0) {
15271527
const npy_timedelta in2 = *(npy_timedelta *)ip2;
15281528

15291529
/* If divisor is 0 or NAT, we need not compute anything */
15301530
if (in2 == 0) {
1531-
BINARY_LOOP_ZERO {
1531+
BINARY_LOOP_SLIDING {
15321532
npy_set_floatstatus_divbyzero();
15331533
*((npy_int64 *)op1) = 0;
15341534
}
15351535
}
15361536
else if (in2 == NPY_DATETIME_NAT) {
1537-
BINARY_LOOP_ZERO {
1537+
BINARY_LOOP_SLIDING {
15381538
npy_set_floatstatus_invalid();
15391539
*((npy_int64 *)op1) = 0;
15401540
}
15411541
}
15421542
else {
15431543
struct libdivide_s64_t fast_d = libdivide_s64_gen(in2);
1544-
BINARY_LOOP_FIXED {
1544+
BINARY_LOOP_SLIDING {
15451545
const npy_timedelta in1 = *(npy_timedelta *)ip1;
15461546
if (in1 == NPY_DATETIME_NAT) {
15471547
npy_set_floatstatus_invalid();

0 commit comments

Comments
 (0)
0