bugGNU Octave - Bugs: bug #47515, median(integers) returns a...

 
 

bug #47515: median(integers) returns a floating point answer

Submitted by:  Lachlan Andrew <lachlan>
Submitted on:  Thu 24 Mar 2016 02:46:02 AM UTC  
 
Category: Octave FunctionSeverity: 2 - Minor
Priority: 5 - NormalItem Group: Matlab Compatibility
Status: FixedAssigned to: Lachlan Andrew <lachlan>
Originator Name: LachlanOpen/Closed: Closed
Release: devOperating System: Any

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Sat 26 Mar 2016 02:00:58 AM UTC, comment #1:

This is good. I made a few changes that are shown below so you can get the flavor of what I was doing. The extra documentation is correct, but not really necessary. Pretty much all functions operate along the first non-singleton dimension unless specified differently. Rather than using elseif, it felt better to contain all the code that belonged to the else block in a single else block. I then re-used the existing sum code rather than using a different function for logicals. I got away with a single isfloat() test rather than two tests. Checked in here (http://hg.savannah.gnu.org/hgweb/octave/rev/ffb4770ba079).

Rik <rik5>
Project Administrator
Thu 24 Mar 2016 02:46:02 AM UTC, original submission:

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

In Octave,

The attached patch fixes both of these, as follows.

  1. nth_element treats logical as an integer type
  1. the case of an even number of elements uses sum(,,"native")
  1. 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.

Lachlan Andrew <lachlan>
Project MemberIn charge of this item.

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

Attached Files
file #36741:  discrete_media.cset added by lachlan (3KiB - text/x-diff)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by lachlan (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sat 26 Mar 2016 02:00:58 AM UTCrik5StatusPatch Submitted=>Fixed
      Open/ClosedOpen=>Closed
    Thu 24 Mar 2016 02:46:02 AM UTClachlanAttached File-=>Added discrete_media.cset, #36741

    Back to the top


    Powered by Savane 3.1-cleanup1