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 01:28:30 -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 #16, bug #51329 (project octave):

Usually, n in this case will be always two elements when used in
median([1,2,3,4,5,6]) for instance. Unless you call nth_element(X, N) with a
long vector for the second argument you usually will exit out of the for loop
immediately 2 < length(2). If we use #14, which I agree is better for the most
part.

w/r/t the breaks:

Removing the first break precludes the ability to exit out of the block over n
if it finds that 
[1, 3, 4, 5, 6, ..., 300] has a difference of 2 at index 1. 

Similarly, the for loop break precludes the ability to exit out of the loop if
index 2 has a difference of 2...
n = [1, 2, 4, 5, 6, ..., 300]

Knowing that my current patch #12 performs as such:

octave:18> tic, for i=1:1000, nth_element([1:10000], 500:501); end, toc
Elapsed time is 0.355964 seconds.
octave:19> tic, for i=1:1000, nth_element([1:10000], [500:501]); end, toc
Elapsed time is 0.344377 seconds.
octave:20> tic, for i=1:1000, nth_element([1:10000], 500:501); end, toc
Elapsed time is 0.341058 seconds.
octave:21> tic, for i=1:1000, nth_element([1:10000], [500:501]); end, toc
Elapsed time is 0.344234 seconds.


Which makes sense, seems to be within acceptable limits.

I will gladly add a comment and please, consider the breaks once more. In
practice it might not matter, since code that raises errors probably doesn't
need to perform quickly anyway.

- 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]