changeset 23900:5621aae74d1a

maint: merge stable to default.
author Rik <rik@octave.org>
date Sat, 12 Aug 2017 11:29:36 -0700
parents a490e729f2f2 (current diff) 437ba51e8bcf (diff)
children b590c674e27d
files libinterp/corefcn/__ichol__.cc
diffstat 1 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/__ichol__.cc	Sat Aug 12 12:33:32 2017 -0400
+++ b/libinterp/corefcn/__ichol__.cc	Sat Aug 12 11:29:36 2017 -0700
@@ -254,8 +254,8 @@
   OCTAVE_LOCAL_BUFFER (octave_idx_type, Lfirst, n);
   OCTAVE_LOCAL_BUFFER (octave_idx_type, Llist, n);
   OCTAVE_LOCAL_BUFFER (T, col_drops, n);
-  std::vector <octave_idx_type> vec;
-  vec.resize (n);
+  std::vector<octave_idx_type> vec (n, 0);
+  std::vector<bool> mark (n, false);
 
   T zero = T (0);
   cidx_l[0] = cidx[0];
@@ -265,7 +265,6 @@
       Lfirst[i] = -1;
       w_data[i] = 0;
       col_drops[i] = zero;
-      vec[i] = 0;
     }
 
   total_len = 0;
@@ -275,6 +274,9 @@
       for (j = cidx[k]; j < cidx[k+1]; j++)
         {
           w_data[ridx[j]] = data[j];
+          // Mark column index, intentionally outside the if-clause to ensure
+          // that mark[k] will be set to true as well.
+          mark[ridx[j]] = true;
           if (ridx[j] != k)
             {
               vec[ind] = ridx[j];
@@ -292,8 +294,9 @@
               // If the element in the j position of the row is zero,
               // then it will become non-zero, so we add it to the
               // vector that tracks non-zero elements in the working row.
-              if (w_data[j] == zero)
+              if (! mark[j])
                 {
+                  mark[j] = true;
                   vec[ind] = j;
                   ind++;
                 }
@@ -355,8 +358,10 @@
                   ridx_l[total_len + w_len] = jrow;
                   w_len++;
                 }
-              vec[i] = 0;
             }
+          // Clear mark, vec, and w_data.  However, mark[k] is not set to zero.
+          mark[jrow] = false;
+          vec[i] = 0;
           w_data[jrow] = zero;
         }