Mercurial > octave-libtiff
annotate scripts/statistics/median.m @ 30875:5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
For new users of Octave it is best to show explicit calling forms
in the documentation and to show a return argument when it exists.
* bp-table.cc, shift.m, accumarray.m, accumdim.m, bincoeff.m, bitcmp.m,
bitget.m, bitset.m, blkdiag.m, celldisp.m, cplxpair.m, dblquad.m, flip.m,
fliplr.m, flipud.m, idivide.m, int2str.m, interpft.m, logspace.m, num2str.m,
polyarea.m, postpad.m, prepad.m, randi.m, repmat.m, rng.m, rot90.m, rotdim.m,
structfun.m, triplequad.m, uibuttongroup.m, uicontrol.m, uipanel.m,
uipushtool.m, uitoggletool.m, uitoolbar.m, waitforbuttonpress.m, help.m,
__additional_help_message__.m, hsv.m, im2double.m, im2frame.m, javachk.m,
usejava.m, argnames.m, char.m, formula.m, inline.m, __vectorize__.m, findstr.m,
flipdim.m, strmatch.m, vectorize.m, commutation_matrix.m, cond.m, cross.m,
duplication_matrix.m, expm.m, orth.m, rank.m, rref.m, trace.m, vech.m, cast.m,
compare_versions.m, delete.m, dir.m, fileattrib.m, grabcode.m, gunzip.m,
inputname.m, license.m, list_primes.m, ls.m, mexext.m, movefile.m,
namelengthmax.m, nargoutchk.m, nthargout.m, substruct.m, swapbytes.m, ver.m,
verLessThan.m, what.m, fminunc.m, fsolve.m, fzero.m, optimget.m, __fdjac__.m,
matlabroot.m, savepath.m, campos.m, camroll.m, camtarget.m, camup.m, camva.m,
camzoom.m, clabel.m, diffuse.m, legend.m, orient.m, rticks.m, specular.m,
thetaticks.m, xlim.m, xtickangle.m, xticklabels.m, xticks.m, ylim.m,
ytickangle.m, yticklabels.m, yticks.m, zlim.m, ztickangle.m, zticklabels.m,
zticks.m, ellipsoid.m, isocolors.m, isonormals.m, stairs.m, surfnorm.m,
__actual_axis_position__.m, __pltopt__.m, close.m, graphics_toolkit.m, pan.m,
print.m, printd.m, __ghostscript__.m, __gnuplot_print__.m, __opengl_print__.m,
rotate3d.m, subplot.m, zoom.m, compan.m, conv.m, poly.m, polyaffine.m,
polyder.m, polyint.m, polyout.m, polyreduce.m, polyvalm.m, roots.m, prefdir.m,
prefsfile.m, profexplore.m, profexport.m, profshow.m, powerset.m, unique.m,
arch_rnd.m, arma_rnd.m, autoreg_matrix.m, bartlett.m, blackman.m, detrend.m,
durbinlevinson.m, fftconv.m, fftfilt.m, fftshift.m, fractdiff.m, hamming.m,
hanning.m, hurst.m, ifftshift.m, rectangle_lw.m, rectangle_sw.m, triangle_lw.m,
sinc.m, sinetone.m, sinewave.m, spectral_adf.m, spectral_xdf.m, spencer.m,
ilu.m, __sprand__.m, sprand.m, sprandn.m, sprandsym.m, treelayout.m, beta.m,
betainc.m, betaincinv.m, betaln.m, cosint.m, expint.m, factorial.m, gammainc.m,
gammaincinv.m, lcm.m, nthroot.m, perms.m, reallog.m, realpow.m, realsqrt.m,
sinint.m, hadamard.m, hankel.m, hilb.m, invhilb.m, magic.m, pascal.m, rosser.m,
toeplitz.m, vander.m, wilkinson.m, center.m, corr.m, cov.m, discrete_cdf.m,
discrete_inv.m, discrete_pdf.m, discrete_rnd.m, empirical_cdf.m,
empirical_inv.m, empirical_pdf.m, empirical_rnd.m, kendall.m, kurtosis.m,
mad.m, mean.m, meansq.m, median.m, mode.m, moment.m, range.m, ranks.m,
run_count.m, skewness.m, spearman.m, statistics.m, std.m, base2dec.m,
bin2dec.m, blanks.m, cstrcat.m, deblank.m, dec2base.m, dec2bin.m, dec2hex.m,
hex2dec.m, index.m, regexptranslate.m, rindex.m, strcat.m, strjust.m,
strtrim.m, strtrunc.m, substr.m, untabify.m, __have_feature__.m,
__prog_output_assert__.m, __run_test_suite__.m, example.m, fail.m, asctime.m,
calendar.m, ctime.m, date.m, etime.m:
Add return arguments to @deftypefn macros where they were missing. Rename
variables in functions (particularly generic "retval") to match documentation.
Rename some return variables for (hopefully) better clarity (e.g., 'ax' to 'hax'
to indicate it is a graphics handle to an axes object).
author | Rik <rik@octave.org> |
---|---|
date | Wed, 30 Mar 2022 20:40:27 -0700 |
parents | 796f54d4ddbf |
children |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
3 ## Copyright (C) 1996-2022 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27898
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
3200 | 7 ## |
8 ## This file is part of Octave. | |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24512
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
3200 | 11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24512
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
13 ## (at your option) any later version. |
3200 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
18 ## GNU General Public License for more details. |
3200 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24512
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
3200 | 25 |
3367 | 26 ## -*- texinfo -*- |
30875
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
27 ## @deftypefn {} {@var{y} =} median (@var{x}) |
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
28 ## @deftypefnx {} {@var{y} =} median (@var{x}, @var{dim}) |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11360
diff
changeset
|
29 ## Compute the median value of the elements of the vector @var{x}. |
20174
d9341b422488
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
30 ## |
24985
d85b2485af9e
doc: grammarcheck m-files ahead of 4.4 release.
Rik <rik@octave.org>
parents:
24817
diff
changeset
|
31 ## When the elements of @var{x} are sorted, say |
d85b2485af9e
doc: grammarcheck m-files ahead of 4.4 release.
Rik <rik@octave.org>
parents:
24817
diff
changeset
|
32 ## @code{@var{s} = sort (@var{x})}, the median is defined as |
3367 | 33 ## @tex |
34 ## $$ | |
35 ## {\rm median} (x) = | |
24511
4f0e6ee6c9b8
Make documentation Sec 26.1 more consistent and Sec 25.4 clearer (bug #52685)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
36 ## \cases{s(\lceil N/2\rceil), & $N$ odd;\cr |
4f0e6ee6c9b8
Make documentation Sec 26.1 more consistent and Sec 25.4 clearer (bug #52685)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
37 ## (s(N/2)+s(N/2+1))/2, & $N$ even.} |
3367 | 38 ## $$ |
24511
4f0e6ee6c9b8
Make documentation Sec 26.1 more consistent and Sec 25.4 clearer (bug #52685)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
39 ## where $N$ is the number of elements of @var{x}. |
4f0e6ee6c9b8
Make documentation Sec 26.1 more consistent and Sec 25.4 clearer (bug #52685)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
40 ## |
3367 | 41 ## @end tex |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
42 ## @ifnottex |
3426 | 43 ## |
3367 | 44 ## @example |
45 ## @group | |
24511
4f0e6ee6c9b8
Make documentation Sec 26.1 more consistent and Sec 25.4 clearer (bug #52685)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
46 ## | @var{s}(ceil(N/2)) N odd |
4f0e6ee6c9b8
Make documentation Sec 26.1 more consistent and Sec 25.4 clearer (bug #52685)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
47 ## median (@var{x}) = | |
4f0e6ee6c9b8
Make documentation Sec 26.1 more consistent and Sec 25.4 clearer (bug #52685)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
48 ## | (@var{s}(N/2) + @var{s}(N/2+1))/2 N even |
3367 | 49 ## @end group |
50 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
51 ## |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
52 ## @end ifnottex |
21540
ffb4770ba079
Make median preserve discrete types (bug #47515).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21317
diff
changeset
|
53 ## If @var{x} is of a discrete type such as integer or logical, then |
24511
4f0e6ee6c9b8
Make documentation Sec 26.1 more consistent and Sec 25.4 clearer (bug #52685)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
54 ## the case of even @math{N} rounds up (or toward @code{true}). |
21540
ffb4770ba079
Make median preserve discrete types (bug #47515).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21317
diff
changeset
|
55 ## |
20174
d9341b422488
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
56 ## If @var{x} is a matrix, compute the median value for each column and |
d9341b422488
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
57 ## return them in a row vector. |
d9341b422488
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
58 ## |
d9341b422488
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
59 ## If the optional @var{dim} argument is given, operate along this dimension. |
12575
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
60 ## @seealso{mean, mode} |
3367 | 61 ## @end deftypefn |
3200 | 62 |
30875
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
63 function y = median (x, dim) |
3200 | 64 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
65 if (nargin < 1) |
6046 | 66 print_usage (); |
4852 | 67 endif |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11360
diff
changeset
|
68 |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
69 if (! (isnumeric (x) || islogical (x))) |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11360
diff
changeset
|
70 error ("median: X must be a numeric vector or matrix"); |
3200 | 71 endif |
72 | |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
73 if (isempty (x)) |
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
74 error ("median: X cannot be an empty matrix"); |
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
75 endif |
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
76 |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11360
diff
changeset
|
77 nd = ndims (x); |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11360
diff
changeset
|
78 sz = size (x); |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
79 if (nargin < 2) |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11360
diff
changeset
|
80 ## Find the first non-singleton dimension. |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
81 (dim = find (sz > 1, 1)) || (dim = 1); |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11360
diff
changeset
|
82 else |
21309
7fbecef105ca
Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
83 if (! (isscalar (dim) && dim == fix (dim) && dim > 0)) |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11360
diff
changeset
|
84 error ("median: DIM must be an integer and a valid dimension"); |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11360
diff
changeset
|
85 endif |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11360
diff
changeset
|
86 endif |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11360
diff
changeset
|
87 |
21309
7fbecef105ca
Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
88 n = size (x, dim); |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
89 k = floor ((n+1) / 2); |
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
90 if (mod (n, 2) == 1) |
30875
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
91 y = nth_element (x, k, dim); |
3200 | 92 else |
30875
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
93 y = sum (nth_element (x, k:k+1, dim), dim, "native") / 2; |
21540
ffb4770ba079
Make median preserve discrete types (bug #47515).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21317
diff
changeset
|
94 if (islogical (x)) |
30875
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
95 y = logical (y); |
21540
ffb4770ba079
Make median preserve discrete types (bug #47515).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21317
diff
changeset
|
96 endif |
3200 | 97 endif |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
98 ## Inject NaNs where needed, to be consistent with Matlab. |
21540
ffb4770ba079
Make median preserve discrete types (bug #47515).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21317
diff
changeset
|
99 if (isfloat (x)) |
30875
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
100 y(any (isnan (x), dim)) = NaN; |
21540
ffb4770ba079
Make median preserve discrete types (bug #47515).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21317
diff
changeset
|
101 endif |
3200 | 102 |
103 endfunction | |
7411 | 104 |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
105 |
7411 | 106 %!test |
107 %! x = [1, 2, 3, 4, 5, 6]; | |
108 %! x2 = x'; | |
109 %! y = [1, 2, 3, 4, 5, 6, 7]; | |
110 %! y2 = y'; | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
111 %! |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
112 %! assert (median (x) == median (x2) && median (x) == 3.5); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
113 %! assert (median (y) == median (y2) && median (y) == 4); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
114 %! assert (median ([x2, 2*x2]), [3.5, 7]); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
115 %! assert (median ([y2, 3*y2]), [4, 12]); |
7411 | 116 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
117 %!assert (median (single ([1,2,3])), single (2)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
118 %!assert (median ([1,2,NaN;4,5,6;NaN,8,9]), [NaN, 5, NaN]) |
21309
7fbecef105ca
Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
119 %!assert (median ([1,2], 3), [1,2]) |
7411 | 120 |
22489
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
121 ## Test multidimensional arrays |
14440
3d4bea9accd7
Fix segfault on multidimensional median call (bug #35679).
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14327
diff
changeset
|
122 %!shared a, b, x, y |
24816
261d23b8933b
test: ensure all unit tests restore global random state after setting it
Mike Miller <mtmiller@octave.org>
parents:
24511
diff
changeset
|
123 %! old_state = rand ("state"); |
261d23b8933b
test: ensure all unit tests restore global random state after setting it
Mike Miller <mtmiller@octave.org>
parents:
24511
diff
changeset
|
124 %! restore_state = onCleanup (@() rand ("state", old_state)); |
261d23b8933b
test: ensure all unit tests restore global random state after setting it
Mike Miller <mtmiller@octave.org>
parents:
24511
diff
changeset
|
125 %! rand ("state", 2); |
14440
3d4bea9accd7
Fix segfault on multidimensional median call (bug #35679).
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14327
diff
changeset
|
126 %! a = rand (2,3,4,5); |
3d4bea9accd7
Fix segfault on multidimensional median call (bug #35679).
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14327
diff
changeset
|
127 %! b = rand (3,4,6,5); |
3d4bea9accd7
Fix segfault on multidimensional median call (bug #35679).
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14327
diff
changeset
|
128 %! x = sort (a, 4); |
3d4bea9accd7
Fix segfault on multidimensional median call (bug #35679).
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14327
diff
changeset
|
129 %! y = sort (b, 3); |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
130 %!assert <*35679> (median (a, 4), x(:, :, :, 3)) |
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
131 %!assert <*35679> (median (b, 3), (y(:, :, 3, :) + y(:, :, 4, :))/2) |
14440
3d4bea9accd7
Fix segfault on multidimensional median call (bug #35679).
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14327
diff
changeset
|
132 |
21540
ffb4770ba079
Make median preserve discrete types (bug #47515).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21317
diff
changeset
|
133 ## Test non-floating point types |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21540
diff
changeset
|
134 %!assert (median ([true, false]), true) |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21540
diff
changeset
|
135 %!assert (median (uint8 ([1, 3])), uint8 (2)) |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21540
diff
changeset
|
136 %!assert (median (int8 ([1, 3, 4])), int8 (3)) |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21540
diff
changeset
|
137 %!assert (median (single ([1, 3, 4])), single (3)) |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21540
diff
changeset
|
138 %!assert (median (single ([1, 3, NaN])), single (NaN)) |
21540
ffb4770ba079
Make median preserve discrete types (bug #47515).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21317
diff
changeset
|
139 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
140 ## Test input validation |
28886
d8318c12d903
test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
141 %!error <Invalid call> median () |
21309
7fbecef105ca
Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
142 %!error <X must be a numeric> median ({1:5}) |
7fbecef105ca
Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
143 %!error <X cannot be an empty matrix> median ([]) |
7fbecef105ca
Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
144 %!error <DIM must be an integer> median (1, ones (2,2)) |
7fbecef105ca
Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
145 %!error <DIM must be an integer> median (1, 1.5) |
7fbecef105ca
Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
146 %!error <DIM must be .* a valid dimension> median (1, 0) |