diff liboctave/bsxfun.h @ 13139:aa4a23337a0f

Enable BSX in-place for missing assignment operators * bsxfun-defs.cc (do_inplace_bsxfun_op): New function. * bsxfun.h (is_valid_bsxfun): Fix logic, had bug with empty dimensions. (is_valid_inplace_bsxfun): New function. * mx-inlines.cc (DEFMXBOOLOPEQ): Add missing function for vector-by-scalar operation. (do_mm_inplace_op): Call new inplace_bsxfun functions. * MArray.cc (MArray::operator+, MArray::operator-, MArray::product_eq, MArray::quotient_eq): Change calling form for do_mm_in_place_op. * boolNDArray.cc (boolNDArray::mx_el_and_assign, boolNDArray::mx_el_or_assign): Ditto
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Thu, 15 Sep 2011 05:11:46 -0500
parents 61be447052c3
children c3d401562410
line wrap: on
line diff
--- a/liboctave/bsxfun.h	Wed Sep 14 19:59:24 2011 -0400
+++ b/liboctave/bsxfun.h	Thu Sep 15 05:11:46 2011 -0500
@@ -33,7 +33,31 @@
 {
   for (int i = 0; i < std::min (dx.length (), dy.length ()); i++)
     {
-      if ( dx(i) > 1 && dy(i) > 1 && dx(i) != dy(i))
+      octave_idx_type xk = dx(i), yk = dy(i);
+      // Check the three conditions for valid bsxfun dims
+      if (! ( (xk == yk) || (xk == 1 && yk > 1) || (xk > 1 && yk == 1)))
+        return false;
+    }
+  return true;
+}
+
+// since we can't change the size of the assigned-to matrix, we cannot
+// apply singleton expansion to it, so the conditions to check are
+// different here.
+inline
+bool
+is_valid_inplace_bsxfun (const dim_vector& dr, const dim_vector& dx)
+{
+  octave_idx_type drl = dr.length (), dxl = dx.length ();
+  if (drl < dxl)
+    return false;
+
+  for (int i = 0; i < drl; i++)
+    {
+      octave_idx_type rk = dr(i), xk = dx(i);
+
+      // Only two valid canditions to check; can't stretch rk
+      if (! ( (rk == xk) || (rk > 1 && xk == 1)))
         return false;
     }
   return true;