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

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

[Octave-bug-tracker] [bug #47515] median(integers) returns a floating po


From: Lachlan Andrew
Subject: [Octave-bug-tracker] [bug #47515] median(integers) returns a floating point answer
Date: Thu, 24 Mar 2016 02:46:04 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0

URL:
  <http://savannah.gnu.org/bugs/?47515>

                 Summary: median(integers) returns a floating point answer
                 Project: GNU Octave
            Submitted by: lachlan
            Submitted on: Thu 24 Mar 2016 02:46:02 AM GMT
                Category: Octave Function
                Severity: 2 - Minor
                Priority: 5 - Normal
              Item Group: Matlab Compatibility
                  Status: Patch Submitted
             Assigned to: lachlan
         Originator Name: Lachlan
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: dev
        Operating System: Any

    _______________________________________________________

Details:

In Matlab, median preserves the type of the input, so


median (uint8([1 4])) == 3
median ([true, false]) == true


In Octave,

>> median ([1 4])
ans =  2.5000
>> median ([true, false])
error: nth_element: wrong type argument 'bool matrix'


The attached patch fixes both of these, as follows.

0 nth_element treats logical as an integer type

0 the case of an even number of elements uses sum(_,_,"native")

0 Assignment of NaN (even to an empty range) is avoided for logical and
integer types.

An alternative to the last point would simply be to do the assignment only if
any (any (isnan (x, dim))).  That avoids the explicit test for integrality.  I
have no idea which is faster.



    _______________________________________________________

File Attachments:


-------------------------------------------------------
Date: Thu 24 Mar 2016 02:46:02 AM GMT  Name: discrete_media.cset  Size: 3kB  
By: lachlan

<http://savannah.gnu.org/bugs/download.php?file_id=36741>

    _______________________________________________________

Reply to this item at:

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

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




reply via email to

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