summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2010-11-19 21:47:33 -0700
committerCharles Harris <charlesr.harris@gmail.com>2011-03-07 20:44:19 -0700
commitc2747b0134057e687a9772846384a967c410e84e (patch)
treeb0cd7f041c8a90329245118cbb6a0cf83b13ddbf /numpy
parentb28b1158fc58459b80b22b6e5a7b8d446ed31035 (diff)
downloadnumpy-c2747b0134057e687a9772846384a967c410e84e.tar.gz
ENH: Speed up reduce for maximum/minimum type ufuncs.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/umath/loops.c.src60
1 files changed, 48 insertions, 12 deletions
diff --git a/numpy/core/src/umath/loops.c.src b/numpy/core/src/umath/loops.c.src
index 79d9da077..5212207da 100644
--- a/numpy/core/src/umath/loops.c.src
+++ b/numpy/core/src/umath/loops.c.src
@@ -760,10 +760,19 @@ NPY_NO_EXPORT void
NPY_NO_EXPORT void
@S@@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
{
- BINARY_LOOP {
- const @s@@type@ in1 = *(@s@@type@ *)ip1;
- const @s@@type@ in2 = *(@s@@type@ *)ip2;
- *((@s@@type@ *)op1) = (in1 @OP@ in2) ? in1 : in2;
+ if (IS_BINARY_REDUCE) {
+ BINARY_REDUCE_LOOP(@s@@type@) {
+ const @s@@type@ in2 = *(@type@ *)ip2;
+ io1 = (io1 @OP@ in2) ? io1 : in2;
+ }
+ *((@s@@type@ *)iop1) = io1;
+ }
+ else {
+ BINARY_LOOP {
+ const @s@@type@ in1 = *(@s@@type@ *)ip1;
+ const @s@@type@ in2 = *(@s@@type@ *)ip2;
+ *((@s@@type@ *)op1) = (in1 @OP@ in2) ? in1 : in2;
+ }
}
}
/**end repeat2**/
@@ -998,11 +1007,20 @@ NPY_NO_EXPORT void
NPY_NO_EXPORT void
@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
{
+ if (IS_BINARY_REDUCE) {
+ BINARY_REDUCE_LOOP(@type@) {
+ const @type@ in2 = *(@type@ *)ip2;
+ io1 = (io1 @OP@ in2) ? io1 : in2;
+ }
+ *((@type@ *)iop1) = io1;
+ }
+ else {
BINARY_LOOP {
const @type@ in1 = *(@type@ *)ip1;
const @type@ in2 = *(@type@ *)ip2;
*((@type@ *)op1) = (in1 @OP@ in2) ? in1 : in2;
}
+ }
}
/**end repeat1**/
@@ -1216,10 +1234,19 @@ NPY_NO_EXPORT void
@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
{
/* */
- BINARY_LOOP {
- const @type@ in1 = *(@type@ *)ip1;
- const @type@ in2 = *(@type@ *)ip2;
- *((@type@ *)op1) = (in1 @OP@ in2 || npy_isnan(in1)) ? in1 : in2;
+ if (IS_BINARY_REDUCE) {
+ BINARY_REDUCE_LOOP(@type@) {
+ const @type@ in2 = *(@type@ *)ip2;
+ io1 = (io1 @OP@ in2 || npy_isnan(io1)) ? io1 : in2;
+ }
+ *((@type@ *)iop1) = io1;
+ }
+ else {
+ BINARY_LOOP {
+ const @type@ in1 = *(@type@ *)ip1;
+ const @type@ in2 = *(@type@ *)ip2;
+ *((@type@ *)op1) = (in1 @OP@ in2 || npy_isnan(in1)) ? in1 : in2;
+ }
}
}
/**end repeat1**/
@@ -1232,10 +1259,19 @@ NPY_NO_EXPORT void
@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
{
/* */
- BINARY_LOOP {
- const @type@ in1 = *(@type@ *)ip1;
- const @type@ in2 = *(@type@ *)ip2;
- *((@type@ *)op1) = (in1 @OP@ in2 || npy_isnan(in2)) ? in1 : in2;
+ if (IS_BINARY_REDUCE) {
+ BINARY_REDUCE_LOOP(@type@) {
+ const @type@ in2 = *(@type@ *)ip2;
+ io1 = (io1 @OP@ in2 || npy_isnan(in2)) ? io1 : in2;
+ }
+ *((@type@ *)iop1) = io1;
+ }
+ else {
+ BINARY_LOOP {
+ const @type@ in1 = *(@type@ *)ip1;
+ const @type@ in2 = *(@type@ *)ip2;
+ *((@type@ *)op1) = (in1 @OP@ in2 || npy_isnan(in2)) ? in1 : in2;
+ }
}
}
/**end repeat1**/