changeset 10147:adc0143e9419

optimize any/all (x, 2) with small number of rows
author Jaroslav Hajek <highegg@gmail.com>
date Wed, 20 Jan 2010 17:50:56 +0100
parents 9597eea7fa36
children deba43069023
files liboctave/ChangeLog liboctave/mx-inlines.cc
diffstat 2 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/ChangeLog	Wed Jan 20 13:56:52 2010 +0100
+++ b/liboctave/ChangeLog	Wed Jan 20 17:50:56 2010 +0100
@@ -1,3 +1,10 @@
+2010-01-20  Jaroslav Hajek  <highegg@gmail.com>
+
+	* mx-inlines.cc (mx_inline_any_r, mx_inline_all_r): New helper
+	reductors. 
+	(mx_inline_any, mx_inline_all): Call the here in row-wise reduction
+	with few enough columns.
+
 2010-01-20  Jaroslav Hajek  <highegg@gmail.com>
 
 	* lo-mappers.h (xmin (double, double), xmax (double, double),
--- a/liboctave/mx-inlines.cc	Wed Jan 20 13:56:52 2010 +0100
+++ b/liboctave/mx-inlines.cc	Wed Jan 20 17:50:56 2010 +0100
@@ -553,6 +553,12 @@
 OP_RED_FCN2 (mx_inline_sumsq, T, T, OP_RED_SUMSQ, 0)
 OP_RED_FCN2 (mx_inline_sumsq, std::complex<T>, T, OP_RED_SUMSQC, 0)
 
+#define OP_RED_ANYR(ac, el) ac |= xis_true (el)
+#define OP_RED_ALLR(ac, el) ac &= xis_true (el)
+
+OP_RED_FCN2 (mx_inline_any_r, T, bool, OP_RED_ANYR, false)
+OP_RED_FCN2 (mx_inline_all_r, T, bool, OP_RED_ALLR, true)
+
 // Using the general code for any/all would sacrifice short-circuiting.
 // OTOH, going by rows would sacrifice cache-coherence. The following algorithm
 // will achieve both, at the cost of a temporary octave_idx_type array.
@@ -562,6 +568,9 @@
 inline void \
 F (const T* v, bool *r, octave_idx_type m, octave_idx_type n) \
 { \
+  if (n <= 8) \
+    return F ## _r (v, r, m, n); \
+  \
   /* FIXME: it may be sub-optimal to allocate the buffer here. */ \
   OCTAVE_LOCAL_BUFFER (octave_idx_type, iact, m); \
   for (octave_idx_type i = 0; i < m; i++) iact[i] = i; \