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: Wed, 28 Jun 2017 20:59:22 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36

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

This works as we seem to expect, thanks for showing me the test command.


diff --git a/liboctave/array/Array.cc b/liboctave/array/Array.cc
--- a/liboctave/array/Array.cc
+++ b/liboctave/array/Array.cc
@@ -2337,6 +2337,30 @@ Array<T>::nth_element (const idx_vector&
       mode = ASCENDING;
       lo = n(0);
       break;
+    case idx_vector::class_vector:
+      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);
+        }
+      else
+        break;
+
+      for (int i = 1; i < n.length() - 1; ++i)
+        {
+          if ((mode == ASCENDING && n(i+1) - n(i) != 1) ||
+             (mode == DESCENDING && n(i+1) - n(i) != -1))
+            {
+              mode = UNSORTED;
+              break;
+            }
+        }
+      break;
     case idx_vector::class_range:
       {
         octave_idx_type inc = n.increment ();



Provides

>> median([1,2,3,4,5,6])
ans =  3.5000
>> test('median')
PASSES 18 out of 18 tests
>> nth_element([1,2,3,4], [1,2,4])
error: nth_element: n must be a scalar or a contiguous range


- OP

    _______________________________________________________

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]