octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #51329] nth_element / median function fail wit


From: anonymous
Subject: [Octave-bug-tracker] [bug #51329] nth_element / median function fail with disable_range(true) (or with --traditional)
Date: Thu, 29 Jun 2017 10:22:53 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36

Follow-up Comment #18, bug #51329 (project octave):

This patch passes the median tests and the other tests I've put in this bug.

This is the extent of my knowledge of the GNU style so someone else will have
to fix it up as necessary.


diff -r 251cb33c6570 liboctave/array/Array.cc
--- a/liboctave/array/Array.cc  Thu Jun 29 02:40:21 2017 -0400
+++ b/liboctave/array/Array.cc  Thu Jun 29 10:19:42 2017 -0400
@@ -2351,6 +2351,25 @@ Array<T>::nth_element (const idx_vector&
             lo = ns - 1 - n(0);
           }
       }
+    case idx_vector::class_vector:
+      // This case resolves bug #51329, it is used for when
+      // disable_range() == true, as in --traditional
+      if (n(1) - n(0) == 1)
+        {
+          mode = ASCENDING;
+          lo = n(0);
+        }
+      else if (n(1) - n(0) == -1)
+        {
+          mode = DESCENDING;
+          lo = ns - 1 - n(0);
+        }
+      // This loop ensures that the vector is range-like i.e. arithmetic
series
+      for (int i = 2; (i < n.length()) && (mode != UNSORTED); ++i)
+        if ((mode == ASCENDING && n(i) - n(i-1) != 1)
+            || (mode == DESCENDING && n(i) - n(i-1) != -1))
+          mode = UNSORTED;
+      break;
     default:
       break;
     }


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?51329>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]