Skip to content

Commit

Permalink
ENH: improve bool argmin performance
Browse files Browse the repository at this point in the history
in glibc memchr using SSE2 is about 18 times faster than our current
code.
  • Loading branch information
juliantaylor committed Aug 27, 2014
1 parent ad42ea6 commit c12c31f
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions numpy/core/src/multiarray/arraytypes.c.src
Expand Up @@ -21,6 +21,7 @@
#include "alloc.h"

#include "numpyos.h"
#include <string.h>


/*
Expand Down Expand Up @@ -2851,26 +2852,37 @@ static int

/**end repeat**/

static int
BOOL_argmin(npy_bool *ip, npy_intp n, npy_intp *min_ind,
PyArrayObject *NPY_UNUSED(aip))

{
npy_bool * p = memchr(ip, 0, n * sizeof(*ip));
if (p == NULL) {
*min_ind = 0;
return 0;
}
*min_ind = p - ip;
return 0;
}

/**begin repeat
*
* #fname = BOOL,
* BYTE, UBYTE, SHORT, USHORT, INT, UINT,
* #fname = BYTE, UBYTE, SHORT, USHORT, INT, UINT,
* LONG, ULONG, LONGLONG, ULONGLONG,
* HALF, FLOAT, DOUBLE, LONGDOUBLE,
* CFLOAT, CDOUBLE, CLONGDOUBLE,
* DATETIME, TIMEDELTA#
* #type = npy_bool,
* npy_byte, npy_ubyte, npy_short, npy_ushort, npy_int, npy_uint,
* #type = npy_byte, npy_ubyte, npy_short, npy_ushort, npy_int, npy_uint,
* npy_long, npy_ulong, npy_longlong, npy_ulonglong,
* npy_half, npy_float, npy_double, npy_longdouble,
* npy_float, npy_double, npy_longdouble,
* npy_datetime, npy_timedelta#
* #isbool = 1, 0*19#
* #isfloat = 0*11, 1*7, 0*2#
* #isnan = nop*11, npy_half_isnan, npy_isnan*6, nop*2#
* #le = _LESS_THAN_OR_EQUAL*11, npy_half_le, _LESS_THAN_OR_EQUAL*8#
* #iscomplex = 0*15, 1*3, 0*2#
* #incr = ip++*15, ip+=2*3, ip++*2#
* #isfloat = 0*10, 1*7, 0*2#
* #isnan = nop*10, npy_half_isnan, npy_isnan*6, nop*2#
* #le = _LESS_THAN_OR_EQUAL*10, npy_half_le, _LESS_THAN_OR_EQUAL*8#
* #iscomplex = 0*14, 1*3, 0*2#
* #incr = ip++*14, ip+=2*3, ip++*2#
*/
static int
@fname@_argmin(@type@ *ip, npy_intp n, npy_intp *min_ind,
Expand All @@ -2896,12 +2908,6 @@ static int
return 0;
}
#endif
#if @isbool@
if (!mp) {
/* False encountered; it's minimal */
return 0;
}
#endif

for (i = 1; i < n; i++) {
@incr@;
Expand Down Expand Up @@ -2929,12 +2935,6 @@ static int
/* nan encountered, it's minimal */
break;
}
#endif
#if @isbool@
if (!mp) {
/* False encountered; it's minimal */
break;
}
#endif
}
#endif
Expand Down

0 comments on commit c12c31f

Please sign in to comment.