[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #47515] median(integers) returns a floating po
From: |
Rik |
Subject: |
[Octave-bug-tracker] [bug #47515] median(integers) returns a floating point answer |
Date: |
Sat, 26 Mar 2016 02:00:58 +0000 |
User-agent: |
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0 |
Update of bug #47515 (project octave):
Status: Patch Submitted => Fixed
Open/Closed: Open => Closed
_______________________________________________________
Follow-up 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).
## return them in a row vector.
##
## If the optional @var{dim} argument is given, operate along this
dimension.
-##
-## If @var{x} is a multi-dimensional array and @var{dim} is not specified,
-## the median is taken along the first non-singleton dimension.
## @seealso{mean, mode}
## @end deftypefn
@@ -85,14 +82,14 @@ function retval = median (x, dim)
k = floor ((n+1) / 2);
if (mod (n, 2) == 1)
retval = nth_element (x, k, dim);
- elseif (islogical (x))
- retval = max (nth_element (x, k:k+1, dim), [], dim);
else
retval = sum (nth_element (x, k:k+1, dim), dim, "native") / 2;
+ if (islogical (x))
+ retval = logical (retval);
+ endif
endif
## Inject NaNs where needed, to be consistent with Matlab.
- if (!(isinteger (x) || islogical (x)))
- ## This converts from discrete types, even if isnan(x) is empty
+ if (isfloat (x))
retval(any (isnan (x), dim)) = NaN;
endif
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?47515>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/