changeset 14977:d3f9801b1f29

src/pt-jit.cc: Take into account step for matrix range subsasgn in JIT
author Max Brister <max@2bass.com>
date Wed, 27 Jun 2012 18:50:59 -0500
parents 2d7c0c86e712
children f649b66ef1af
files src/pt-jit.cc
diffstat 1 files changed, 20 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/pt-jit.cc	Wed Jun 27 18:19:41 2012 -0500
+++ b/src/pt-jit.cc	Wed Jun 27 18:50:59 2012 -0500
@@ -263,13 +263,30 @@
   if (*array->jit_ref_count () == 1
       && index->all_elements_are_ints ())
     {
-      octave_idx_type base = static_cast<octave_idx_type> (index->base);
+      // this code is similar to idx_vector::fill, but we avoid allocating an
+      // idx_vector and its associated rep
+      octave_idx_type start = static_cast<octave_idx_type> (index->base) - 1;
+      octave_idx_type step = static_cast<octave_idx_type> (index->inc);
       octave_idx_type nelem = index->nelem;
-      if (base > 0 && base + nelem <= array->nelem ())
+      octave_idx_type final = start + nelem * step;
+      if (step < 0)
+        {
+          step = -step;
+          std::swap (final, start);
+        }
+
+      if (start >= 0 && final < mat->slice_len)
         {
           done = true;
+
           double *data = array->jit_slice_data ();
-          std::fill (data + base - 1, data + base + nelem - 1, value);
+          if (step == 1)
+            std::fill (data + start, data + start + nelem, value);
+          else
+            {
+              for (octave_idx_type i = start; i < final; i += step)
+                data[i] = value;
+            }
         }
     }