annotate libinterp/corefcn/max.cc @ 18076:42e6cdc76f4b

max.cc: Add %!test for bug #40743. * max.cc: Add %!test for bug #40743.
author Rik <rik@octave.org>
date Wed, 04 Dec 2013 08:57:05 -0800
parents 175b392e91fe
children 6a71e5030df5 9a0f996a358a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
1 /*
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
2
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 17403
diff changeset
3 Copyright (C) 1996-2013 John W. Eaton
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
4 Copyright (C) 2009 VZLU Prague
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
5
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
7
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6711
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6711
diff changeset
11 option) any later version.
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
12
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
16 for more details.
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
17
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6711
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6711
diff changeset
20 <http://www.gnu.org/licenses/>.
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
21
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
22 */
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
23
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
25 #include <config.h>
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
26 #endif
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
27
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
28 #include "lo-ieee.h"
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3243
diff changeset
29 #include "lo-mappers.h"
7231
2eb392d058bb [project @ 2007-11-30 18:53:29 by jwe]
jwe
parents: 7189
diff changeset
30 #include "lo-math.h"
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4522
diff changeset
31 #include "dNDArray.h"
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4522
diff changeset
32 #include "CNDArray.h"
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4102
diff changeset
33 #include "quit.h"
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
34
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
35 #include "defun.h"
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
36 #include "error.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
37 #include "gripes.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
38 #include "oct-obj.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
39
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4522
diff changeset
40 #include "ov-cx-mat.h"
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7231
diff changeset
41 #include "ov-re-sparse.h"
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7231
diff changeset
42 #include "ov-cx-sparse.h"
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4522
diff changeset
43
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
44 template <class ArrayType>
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
45 static octave_value_list
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
46 do_minmax_red_op (const octave_value& arg,
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
47 int nargout, int dim, bool ismin)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
48 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
49 octave_value_list retval;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
50 ArrayType array = octave_value_extract<ArrayType> (arg);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
51
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
52 if (error_state)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
53 return retval;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
54
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
55 if (nargout == 2)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
56 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
57 retval.resize (2);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
58 Array<octave_idx_type> idx;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
59 if (ismin)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
60 retval(0) = array.min (idx, dim);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
61 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
62 retval(0) = array.max (idx, dim);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
63
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
64 retval(1) = octave_value (idx, true, true);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
65 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
66 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
67 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
68 if (ismin)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
69 retval(0) = array.min (dim);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
70 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
71 retval(0) = array.max (dim);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
72 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
73
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
74 return retval;
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
75 }
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
76
16370
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
77 // Matlab returns double arrays for min/max operations on character
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
78 // arrays, so we specialize here to get that behavior. Other possible
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
79 // solutions are to convert the argument to double here and call the
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
80 // code for double, but that could waste memory, or to have the
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
81 // underlying charNDArray::min/max functions return NDArray instead of
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
82 // charNDArray, but that is inconsistent with the way other min/max
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
83 // functions work.
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
84
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
85 template <>
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
86 octave_value_list
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
87 do_minmax_red_op<charNDArray> (const octave_value& arg,
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
88 int nargout, int dim, bool ismin)
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
89 {
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
90 octave_value_list retval;
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
91 charNDArray array = octave_value_extract<charNDArray> (arg);
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
92
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
93 if (error_state)
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
94 return retval;
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
95
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
96 if (nargout == 2)
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
97 {
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
98 retval.resize (2);
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
99 Array<octave_idx_type> idx;
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
100 if (ismin)
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
101 retval(0) = NDArray (array.min (idx, dim));
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
102 else
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
103 retval(0) = NDArray (array.max (idx, dim));
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
104
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
105 retval(1) = octave_value (idx, true, true);
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
106 }
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
107 else
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
108 {
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
109 if (ismin)
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
110 retval(0) = NDArray (array.min (dim));
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
111 else
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
112 retval(0) = NDArray (array.max (dim));
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
113 }
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
114
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
115 return retval;
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
116 }
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
117
9993
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
118 // Specialization for bool arrays.
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
119 template <>
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
120 octave_value_list
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
121 do_minmax_red_op<boolNDArray> (const octave_value& arg,
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
122 int nargout, int dim, bool ismin)
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
123 {
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
124 octave_value_list retval;
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
125
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
126 if (nargout <= 1)
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
127 {
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
128 // This case can be handled using any/all.
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
129 boolNDArray array = arg.bool_array_value ();
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
130
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
131 if (array.is_empty ())
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
132 retval(0) = array;
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
133 else if (ismin)
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
134 retval(0) = array.all (dim);
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
135 else
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
136 retval(0) = array.any (dim);
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
137 }
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
138 else
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
139 {
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
140 // any/all don't have indexed versions, so do it via a conversion.
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
141 retval = do_minmax_red_op<int8NDArray> (arg, nargout, dim, ismin);
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
142 if (! error_state)
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
143 retval(0) = retval(0).bool_array_value ();
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
144 }
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
145
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
146 return retval;
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
147 }
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
148
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
149 template <class ArrayType>
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
150 static octave_value
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
151 do_minmax_bin_op (const octave_value& argx, const octave_value& argy,
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
152 bool ismin)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
153 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
154 typedef typename ArrayType::element_type ScalarType;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
155
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
156 octave_value retval;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
157
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
158 if (argx.is_scalar_type () == 1)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
159 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
160 ScalarType x = octave_value_extract<ScalarType> (argx);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
161 ArrayType y = octave_value_extract<ArrayType> (argy);
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7017
diff changeset
162
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
163 if (error_state)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
164 ;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
165 else if (ismin)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
166 retval = min (x, y);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
167 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
168 retval = max (x, y);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
169 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
170 else if (argy.is_scalar_type () == 1)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
171 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
172 ArrayType x = octave_value_extract<ArrayType> (argx);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
173 ScalarType y = octave_value_extract<ScalarType> (argy);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
174
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
175 if (error_state)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
176 ;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
177 else if (ismin)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
178 retval = min (x, y);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
179 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
180 retval = max (x, y);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
181 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
182 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
183 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
184 ArrayType x = octave_value_extract<ArrayType> (argx);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
185 ArrayType y = octave_value_extract<ArrayType> (argy);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
186
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
187 if (error_state)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
188 ;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
189 else if (ismin)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
190 retval = min (x, y);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
191 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
192 retval = max (x, y);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
193 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
194
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
195 return retval;
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
196 }
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
197
16370
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
198 // Matlab returns double arrays for min/max operations on character
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
199 // arrays, so we specialize here to get that behavior. Other possible
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
200 // solutions are to convert the arguments to double here and call the
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
201 // code for double, but that could waste a lot of memory, or to have the
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
202 // underlying charNDArray::min/max functions return NDArray instead of
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
203 // charNDArray, but that is inconsistent with the way other min/max
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
204 // functions work.
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
205
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
206 template <>
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
207 octave_value
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
208 do_minmax_bin_op<charNDArray> (const octave_value& argx,
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
209 const octave_value& argy, bool ismin)
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
210 {
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
211 octave_value retval;
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
212
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
213 if (argx.is_scalar_type () == 1)
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
214 {
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
215 char x = octave_value_extract<char> (argx);
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
216 charNDArray y = octave_value_extract<charNDArray> (argy);
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
217
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
218 if (error_state)
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
219 ;
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
220 else if (ismin)
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
221 retval = NDArray (min (x, y));
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
222 else
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
223 retval = NDArray (max (x, y));
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
224 }
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
225 else if (argy.is_scalar_type () == 1)
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
226 {
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
227 charNDArray x = octave_value_extract<charNDArray> (argx);
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
228 char y = octave_value_extract<char> (argy);
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
229
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
230 if (error_state)
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
231 ;
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
232 else if (ismin)
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
233 retval = NDArray (min (x, y));
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
234 else
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
235 retval = NDArray (max (x, y));
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
236 }
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
237 else
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
238 {
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
239 charNDArray x = octave_value_extract<charNDArray> (argx);
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
240 charNDArray y = octave_value_extract<charNDArray> (argy);
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
241
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
242 if (error_state)
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
243 ;
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
244 else if (ismin)
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
245 retval = NDArray (min (x, y));
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
246 else
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
247 retval = NDArray (max (x, y));
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
248 }
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
249
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
250 return retval;
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
251 }
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
252
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
253 static octave_value_list
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
254 do_minmax_body (const octave_value_list& args,
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
255 int nargout, bool ismin)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
256 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
257 octave_value_list retval;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
258
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
259 const char *func = ismin ? "min" : "max";
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
260
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
261 int nargin = args.length ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7662
diff changeset
262
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
263 if (nargin == 3 || nargin == 1)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
264 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
265 octave_value arg = args(0);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
266 int dim = -1;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
267 if (nargin == 3)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
268 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
269 dim = args(2).int_value (true) - 1;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
270 if (error_state || dim < 0)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
271 {
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
272 error ("%s: DIM must be a valid dimension", func);
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
273 return retval;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
274 }
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
275
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
276 if (! args(1).is_empty ())
13717
fcdf0993b8c9 Fix segfault in do_minmax_bin_op (bug #34589)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
277 warning ("%s: second argument is ignored", func);
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
278 }
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7017
diff changeset
279
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
280 switch (arg.builtin_type ())
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
281 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
282 case btyp_double:
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
283 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
284 if (arg.is_range () && (dim == -1 || dim == 1))
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
285 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
286 Range range = arg.range_value ();
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
287 if (range.nelem () == 0)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
288 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
289 retval(0) = arg;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
290 if (nargout > 1)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
291 retval(1) = arg;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
292 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
293 else if (ismin)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
294 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
295 retval(0) = range.min ();
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
296 if (nargout > 1)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
297 retval(1) = static_cast<double>
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
298 (range.inc () < 0 ? range.nelem () : 1);
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
299 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
300 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
301 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
302 retval(0) = range.max ();
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
303 if (nargout > 1)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
304 retval(1) = static_cast<double>
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
305 (range.inc () >= 0 ? range.nelem () : 1);
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
306 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
307 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
308 else if (arg.is_sparse_type ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
309 retval = do_minmax_red_op<SparseMatrix> (arg, nargout, dim,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
310 ismin);
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
311 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
312 retval = do_minmax_red_op<NDArray> (arg, nargout, dim, ismin);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
313 break;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
314 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
315 case btyp_complex:
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
316 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
317 if (arg.is_sparse_type ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
318 retval = do_minmax_red_op<SparseComplexMatrix> (arg, nargout, dim,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
319 ismin);
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
320 else
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
321 retval = do_minmax_red_op<ComplexNDArray> (arg, nargout, dim,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
322 ismin);
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
323 break;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
324 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
325 case btyp_float:
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
326 retval = do_minmax_red_op<FloatNDArray> (arg, nargout, dim, ismin);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
327 break;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
328 case btyp_float_complex:
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
329 retval = do_minmax_red_op<FloatComplexNDArray> (arg, nargout, dim,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
330 ismin);
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
331 break;
16370
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
332 case btyp_char:
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
333 retval = do_minmax_red_op<charNDArray> (arg, nargout, dim, ismin);
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
334 break;
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
335 #define MAKE_INT_BRANCH(X) \
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
336 case btyp_ ## X: \
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
337 retval = do_minmax_red_op<X ## NDArray> (arg, nargout, dim, ismin); \
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
338 break;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
339 MAKE_INT_BRANCH (int8);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
340 MAKE_INT_BRANCH (int16);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
341 MAKE_INT_BRANCH (int32);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
342 MAKE_INT_BRANCH (int64);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
343 MAKE_INT_BRANCH (uint8);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
344 MAKE_INT_BRANCH (uint16);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
345 MAKE_INT_BRANCH (uint32);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
346 MAKE_INT_BRANCH (uint64);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
347 #undef MAKE_INT_BRANCH
9993
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
348 case btyp_bool:
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
349 retval = do_minmax_red_op<boolNDArray> (arg, nargout, dim, ismin);
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
350 break;
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
351 default:
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
352 gripe_wrong_type_arg (func, arg);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
353 }
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
354 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
355 else if (nargin == 2)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
356 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
357 octave_value argx = args(0), argy = args(1);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
358 builtin_type_t xtyp = argx.builtin_type (), ytyp = argy.builtin_type ();
16370
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
359 builtin_type_t rtyp;
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
360 if (xtyp == btyp_char && ytyp == btyp_char)
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
361 rtyp = btyp_char;
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
362 else
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
363 rtyp = btyp_mixed_numeric (xtyp, ytyp);
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
364
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
365 switch (rtyp)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
366 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
367 case btyp_double:
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
368 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
369 if ((argx.is_sparse_type ()
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
370 && (argy.is_sparse_type () || argy.is_scalar_type ()))
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
371 || (argy.is_sparse_type () && argx.is_scalar_type ()))
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
372 retval = do_minmax_bin_op<SparseMatrix> (argx, argy, ismin);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
373 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
374 retval = do_minmax_bin_op<NDArray> (argx, argy, ismin);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
375 break;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
376 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
377 case btyp_complex:
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
378 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
379 if ((argx.is_sparse_type ()
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
380 && (argy.is_sparse_type () || argy.is_scalar_type ()))
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
381 || (argy.is_sparse_type () && argx.is_scalar_type ()))
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
382 retval = do_minmax_bin_op<SparseComplexMatrix> (argx, argy,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
383 ismin);
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
384 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
385 retval = do_minmax_bin_op<ComplexNDArray> (argx, argy, ismin);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
386 break;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
387 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
388 case btyp_float:
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
389 retval = do_minmax_bin_op<FloatNDArray> (argx, argy, ismin);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
390 break;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
391 case btyp_float_complex:
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
392 retval = do_minmax_bin_op<FloatComplexNDArray> (argx, argy, ismin);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
393 break;
16370
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
394 case btyp_char:
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
395 retval = do_minmax_bin_op<charNDArray> (argx, argy, ismin);
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
396 break;
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
397 #define MAKE_INT_BRANCH(X) \
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
398 case btyp_ ## X: \
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
399 retval = do_minmax_bin_op<X ## NDArray> (argx, argy, ismin); \
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
400 break;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
401 MAKE_INT_BRANCH (int8);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
402 MAKE_INT_BRANCH (int16);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
403 MAKE_INT_BRANCH (int32);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
404 MAKE_INT_BRANCH (int64);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
405 MAKE_INT_BRANCH (uint8);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
406 MAKE_INT_BRANCH (uint16);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
407 MAKE_INT_BRANCH (uint32);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
408 MAKE_INT_BRANCH (uint64);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
409 #undef MAKE_INT_BRANCH
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
410 default:
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
411 error ("%s: cannot compute %s (%s, %s)", func, func,
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
412 argx.type_name ().c_str (), argy.type_name ().c_str ());
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
413 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
414 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
415 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
416 print_usage ();
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
417
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
418 return retval;
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7231
diff changeset
419 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7231
diff changeset
420
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
421 DEFUN (min, args, nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
422 "-*- texinfo -*-\n\
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
423 @deftypefn {Built-in Function} {} min (@var{x})\n\
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
424 @deftypefnx {Built-in Function} {} min (@var{x}, @var{y})\n\
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
425 @deftypefnx {Built-in Function} {} min (@var{x}, [], @var{dim})\n\
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
426 @deftypefnx {Built-in Function} {} min (@var{x}, @var{y}, @var{dim})\n\
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
427 @deftypefnx {Built-in Function} {[@var{w}, @var{iw}] =} min (@var{x})\n\
3443
bf22deaf04ed [project @ 2000-01-17 08:28:27 by jwe]
jwe
parents: 3418
diff changeset
428 For a vector argument, return the minimum value. For a matrix\n\
bf22deaf04ed [project @ 2000-01-17 08:28:27 by jwe]
jwe
parents: 3418
diff changeset
429 argument, return the minimum value from each column, as a row\n\
13789
4de1e8778d48 Fix typo in @var macro in cset 8bb7bdbe9c69.
Rik <octave@nomad.inbox5.com>
parents: 13786
diff changeset
430 vector, or over the dimension @var{dim} if defined, in which case @var{y} \n\
13786
40dab5d70115 Clarify the third argument of max/min.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13717
diff changeset
431 should be set to the empty matrix (it's ignored otherwise). For two matrices\n\
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4522
diff changeset
432 (or a matrix and scalar), return the pair-wise minimum.\n\
4522
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
433 Thus,\n\
3443
bf22deaf04ed [project @ 2000-01-17 08:28:27 by jwe]
jwe
parents: 3418
diff changeset
434 \n\
bf22deaf04ed [project @ 2000-01-17 08:28:27 by jwe]
jwe
parents: 3418
diff changeset
435 @example\n\
bf22deaf04ed [project @ 2000-01-17 08:28:27 by jwe]
jwe
parents: 3418
diff changeset
436 min (min (@var{x}))\n\
bf22deaf04ed [project @ 2000-01-17 08:28:27 by jwe]
jwe
parents: 3418
diff changeset
437 @end example\n\
bf22deaf04ed [project @ 2000-01-17 08:28:27 by jwe]
jwe
parents: 3418
diff changeset
438 \n\
bf22deaf04ed [project @ 2000-01-17 08:28:27 by jwe]
jwe
parents: 3418
diff changeset
439 @noindent\n\
4522
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
440 returns the smallest element of @var{x}, and\n\
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
441 \n\
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
442 @example\n\
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
443 @group\n\
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
444 min (2:5, pi)\n\
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
445 @result{} 2.0000 3.0000 3.1416 3.1416\n\
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
446 @end group\n\
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
447 @end example\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10155
diff changeset
448 \n\
4522
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
449 @noindent\n\
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
450 compares each element of the range @code{2:5} with @code{pi}, and\n\
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
451 returns a row vector of the minimum values.\n\
3443
bf22deaf04ed [project @ 2000-01-17 08:28:27 by jwe]
jwe
parents: 3418
diff changeset
452 \n\
bf22deaf04ed [project @ 2000-01-17 08:28:27 by jwe]
jwe
parents: 3418
diff changeset
453 For complex arguments, the magnitude of the elements are used for\n\
3657
a908150a3a32 [project @ 2000-04-11 19:02:03 by jwe]
jwe
parents: 3443
diff changeset
454 comparison.\n\
a908150a3a32 [project @ 2000-04-11 19:02:03 by jwe]
jwe
parents: 3443
diff changeset
455 \n\
4522
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
456 If called with one input and two output arguments,\n\
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
457 @code{min} also returns the first index of the\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8949
diff changeset
458 minimum value(s). Thus,\n\
4522
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
459 \n\
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3747
diff changeset
460 @example\n\
4522
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
461 @group\n\
9165
8c71a86c4bf4 Update section 17.5 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9141
diff changeset
462 [x, ix] = min ([1, 3, 0, 2, 0])\n\
4522
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
463 @result{} x = 0\n\
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
464 ix = 3\n\
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
465 @end group\n\
3657
a908150a3a32 [project @ 2000-04-11 19:02:03 by jwe]
jwe
parents: 3443
diff changeset
466 @end example\n\
9141
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9086
diff changeset
467 @seealso{max, cummin, cummax}\n\
4522
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
468 @end deftypefn")
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
469 {
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
470 return do_minmax_body (args, nargout, true);
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
471 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
472
7600
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
473 /*
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
474 %!assert (min ([1, 4, 2, 3]), 1)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
475 %!assert (min ([1; -10; 5; -2]), -10)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
476 %!assert (min ([4, i; -2, 2]), [-2, i])
16370
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
477 %!assert (min (char(42)), 42)
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
478 %!assert (min (char(21), char(3)), 3)
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
479 %!assert (min([char(21), char(3)]), 3)
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
480 %!assert (min([char(100) char(3)], [char(42) char(42)]), [42 3])
7600
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
481
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
482 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
483 %! x = reshape (1:8, [2,2,2]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
484 %! assert (max (x, [], 1), reshape ([2, 4, 6, 8], [1,2,2]));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
485 %! assert (max (x, [], 2), reshape ([3, 4, 7, 8], [2,1,2]));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
486 %! [y, i] = max (x, [], 3);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
487 %! assert (ndims (y), 2);
7600
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
488 %! assert (y, [5, 7; 6, 8]);
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
489 %! assert (ndims (i), 2);
7600
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
490 %! assert (i, [2, 2; 2, 2]);
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
491
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
492 %!error min ()
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
493 %!error min (1, 2, 3, 4)
7600
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
494 */
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
495
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
496 DEFUN (max, args, nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
497 "-*- texinfo -*-\n\
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
498 @deftypefn {Built-in Function} {} max (@var{x})\n\
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
499 @deftypefnx {Built-in Function} {} max (@var{x}, @var{y})\n\
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
500 @deftypefnx {Built-in Function} {} max (@var{x}, [], @var{dim})\n\
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
501 @deftypefnx {Built-in Function} {} max (@var{x}, @var{y}, @var{dim})\n\
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
502 @deftypefnx {Built-in Function} {[@var{w}, @var{iw}] =} max (@var{x})\n\
3443
bf22deaf04ed [project @ 2000-01-17 08:28:27 by jwe]
jwe
parents: 3418
diff changeset
503 For a vector argument, return the maximum value. For a matrix\n\
bf22deaf04ed [project @ 2000-01-17 08:28:27 by jwe]
jwe
parents: 3418
diff changeset
504 argument, return the maximum value from each column, as a row\n\
13789
4de1e8778d48 Fix typo in @var macro in cset 8bb7bdbe9c69.
Rik <octave@nomad.inbox5.com>
parents: 13786
diff changeset
505 vector, or over the dimension @var{dim} if defined, in which case @var{y} \n\
13786
40dab5d70115 Clarify the third argument of max/min.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13717
diff changeset
506 should be set to the empty matrix (it's ignored otherwise). For two matrices\n\
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4522
diff changeset
507 (or a matrix and scalar), return the pair-wise maximum.\n\
4522
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
508 Thus,\n\
3443
bf22deaf04ed [project @ 2000-01-17 08:28:27 by jwe]
jwe
parents: 3418
diff changeset
509 \n\
bf22deaf04ed [project @ 2000-01-17 08:28:27 by jwe]
jwe
parents: 3418
diff changeset
510 @example\n\
bf22deaf04ed [project @ 2000-01-17 08:28:27 by jwe]
jwe
parents: 3418
diff changeset
511 max (max (@var{x}))\n\
bf22deaf04ed [project @ 2000-01-17 08:28:27 by jwe]
jwe
parents: 3418
diff changeset
512 @end example\n\
bf22deaf04ed [project @ 2000-01-17 08:28:27 by jwe]
jwe
parents: 3418
diff changeset
513 \n\
bf22deaf04ed [project @ 2000-01-17 08:28:27 by jwe]
jwe
parents: 3418
diff changeset
514 @noindent\n\
9141
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9086
diff changeset
515 returns the largest element of the matrix @var{x}, and\n\
4522
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
516 \n\
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
517 @example\n\
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
518 @group\n\
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
519 max (2:5, pi)\n\
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
520 @result{} 3.1416 3.1416 4.0000 5.0000\n\
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
521 @end group\n\
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
522 @end example\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10155
diff changeset
523 \n\
4522
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
524 @noindent\n\
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
525 compares each element of the range @code{2:5} with @code{pi}, and\n\
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
526 returns a row vector of the maximum values.\n\
3443
bf22deaf04ed [project @ 2000-01-17 08:28:27 by jwe]
jwe
parents: 3418
diff changeset
527 \n\
bf22deaf04ed [project @ 2000-01-17 08:28:27 by jwe]
jwe
parents: 3418
diff changeset
528 For complex arguments, the magnitude of the elements are used for\n\
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3747
diff changeset
529 comparison.\n\
3657
a908150a3a32 [project @ 2000-04-11 19:02:03 by jwe]
jwe
parents: 3443
diff changeset
530 \n\
4522
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
531 If called with one input and two output arguments,\n\
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
532 @code{max} also returns the first index of the\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8949
diff changeset
533 maximum value(s). Thus,\n\
4522
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
534 \n\
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3747
diff changeset
535 @example\n\
4522
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
536 @group\n\
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
537 [x, ix] = max ([1, 3, 5, 2, 5])\n\
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
538 @result{} x = 5\n\
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
539 ix = 3\n\
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
540 @end group\n\
3657
a908150a3a32 [project @ 2000-04-11 19:02:03 by jwe]
jwe
parents: 3443
diff changeset
541 @end example\n\
9141
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9086
diff changeset
542 @seealso{min, cummax, cummin}\n\
4522
abdcb14e598d [project @ 2003-09-28 22:04:01 by jwe]
jwe
parents: 4309
diff changeset
543 @end deftypefn")
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
544 {
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
545 return do_minmax_body (args, nargout, false);
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
546 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
547
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
548 /*
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
549 %!assert (max ([1, 4, 2, 3]), 4)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
550 %!assert (max ([1; -10; 5; -2]), 5)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
551 %!assert (max ([4, i 4.999; -2, 2, 3+4i]), [4, 2, 3+4i])
7600
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
552
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
553 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
554 %! x = reshape (1:8, [2,2,2]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
555 %! assert (min (x, [], 1), reshape ([1, 3, 5, 7], [1,2,2]));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
556 %! assert (min (x, [], 2), reshape ([1, 2, 5, 6], [2,1,2]));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
557 %! [y, i] = min (x, [], 3);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
558 %! assert (ndims(y), 2);
7600
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
559 %! assert (y, [1, 3; 2, 4]);
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
560 %! assert (ndims(i), 2);
7600
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
561 %! assert (i, [1, 1; 1, 1]);
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
562
18076
42e6cdc76f4b max.cc: Add %!test for bug #40743.
Rik <rik@octave.org>
parents: 17787
diff changeset
563 ## Test for bug #40743
42e6cdc76f4b max.cc: Add %!test for bug #40743.
Rik <rik@octave.org>
parents: 17787
diff changeset
564 %!assert (max (zeros (1,0), ones (1,1)), zeros (1,0))
42e6cdc76f4b max.cc: Add %!test for bug #40743.
Rik <rik@octave.org>
parents: 17787
diff changeset
565 %!assert (max (sparse (zeros (1,0)), sparse (ones (1,1))), sparse (zeros (1,0)))
42e6cdc76f4b max.cc: Add %!test for bug #40743.
Rik <rik@octave.org>
parents: 17787
diff changeset
566
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
567 %!error max ()
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
568 %!error max (1, 2, 3, 4)
7600
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
569 */
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
570
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
571 template <class ArrayType>
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
572 static octave_value_list
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
573 do_cumminmax_red_op (const octave_value& arg,
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
574 int nargout, int dim, bool ismin)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
575 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
576 octave_value_list retval;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
577 ArrayType array = octave_value_extract<ArrayType> (arg);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
578
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
579 if (error_state)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
580 return retval;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
581
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
582 if (nargout == 2)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
583 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
584 retval.resize (2);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
585 Array<octave_idx_type> idx;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
586 if (ismin)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
587 retval(0) = array.cummin (idx, dim);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
588 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
589 retval(0) = array.cummax (idx, dim);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
590
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
591 retval(1) = octave_value (idx, true, true);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
592 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
593 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
594 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
595 if (ismin)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
596 retval(0) = array.cummin (dim);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
597 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
598 retval(0) = array.cummax (dim);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
599 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
600
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
601 return retval;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
602 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
603
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
604 static octave_value_list
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
605 do_cumminmax_body (const octave_value_list& args,
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
606 int nargout, bool ismin)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
607 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
608 octave_value_list retval;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
609
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
610 const char *func = ismin ? "cummin" : "cummax";
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
611
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
612 int nargin = args.length ();
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
613
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
614 if (nargin == 1 || nargin == 2)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
615 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
616 octave_value arg = args(0);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
617 int dim = -1;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
618 if (nargin == 2)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
619 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
620 dim = args(1).int_value (true) - 1;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
621 if (error_state || dim < 0)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
622 {
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
623 error ("%s: DIM must be a valid dimension", func);
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
624 return retval;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
625 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
626 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
627
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
628 switch (arg.builtin_type ())
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
629 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
630 case btyp_double:
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
631 retval = do_cumminmax_red_op<NDArray> (arg, nargout, dim, ismin);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
632 break;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
633 case btyp_complex:
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
634 retval = do_cumminmax_red_op<ComplexNDArray> (arg, nargout, dim,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
635 ismin);
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
636 break;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
637 case btyp_float:
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
638 retval = do_cumminmax_red_op<FloatNDArray> (arg, nargout, dim, ismin);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
639 break;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
640 case btyp_float_complex:
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
641 retval = do_cumminmax_red_op<FloatComplexNDArray> (arg, nargout, dim,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
642 ismin);
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
643 break;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
644 #define MAKE_INT_BRANCH(X) \
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
645 case btyp_ ## X: \
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
646 retval = do_cumminmax_red_op<X ## NDArray> (arg, nargout, dim, \
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
647 ismin); \
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
648 break;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
649 MAKE_INT_BRANCH (int8);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
650 MAKE_INT_BRANCH (int16);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
651 MAKE_INT_BRANCH (int32);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
652 MAKE_INT_BRANCH (int64);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
653 MAKE_INT_BRANCH (uint8);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
654 MAKE_INT_BRANCH (uint16);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
655 MAKE_INT_BRANCH (uint32);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
656 MAKE_INT_BRANCH (uint64);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
657 #undef MAKE_INT_BRANCH
10017
1ce1ae448572 support cummin/cummax for bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9993
diff changeset
658 case btyp_bool:
1ce1ae448572 support cummin/cummax for bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9993
diff changeset
659 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
660 retval = do_cumminmax_red_op<int8NDArray> (arg, nargout, dim,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
661 ismin);
10017
1ce1ae448572 support cummin/cummax for bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9993
diff changeset
662 if (retval.length () > 0)
1ce1ae448572 support cummin/cummax for bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9993
diff changeset
663 retval(0) = retval(0).bool_array_value ();
1ce1ae448572 support cummin/cummax for bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9993
diff changeset
664 break;
1ce1ae448572 support cummin/cummax for bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9993
diff changeset
665 }
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
666 default:
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
667 gripe_wrong_type_arg (func, arg);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
668 }
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
669 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
670 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
671 print_usage ();
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
672
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
673 return retval;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
674 }
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
675
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
676 DEFUN (cummin, args, nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
677 "-*- texinfo -*-\n\
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
678 @deftypefn {Built-in Function} {} cummin (@var{x})\n\
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
679 @deftypefnx {Built-in Function} {} cummin (@var{x}, @var{dim})\n\
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
680 @deftypefnx {Built-in Function} {[@var{w}, @var{iw}] =} cummin (@var{x})\n\
17403
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
681 Return the cumulative minimum values along dimension @var{dim}.\n\
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
682 \n\
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
683 If @var{dim} is unspecified it defaults to column-wise operation. For\n\
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
684 example:\n\
9141
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9086
diff changeset
685 \n\
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9086
diff changeset
686 @example\n\
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9086
diff changeset
687 @group\n\
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9086
diff changeset
688 cummin ([5 4 6 2 3 1])\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
689 @result{} 5 4 4 2 2 1\n\
9141
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9086
diff changeset
690 @end group\n\
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9086
diff changeset
691 @end example\n\
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9086
diff changeset
692 \n\
17403
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
693 If called with two output arguments the index of the minimum value is also\n\
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
694 returned.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10155
diff changeset
695 \n\
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
696 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8949
diff changeset
697 @group\n\
17403
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
698 [w, iw] = cummin ([5 4 6 2 3 1])\n\
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
699 @result{}\n\
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
700 w = 5 4 4 2 2 1\n\
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
701 iw = 1 2 2 4 4 6\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8949
diff changeset
702 @end group\n\
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
703 @end example\n\
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
704 \n\
9141
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9086
diff changeset
705 @seealso{cummax, min, max}\n\
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
706 @end deftypefn")
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
707 {
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
708 return do_cumminmax_body (args, nargout, true);
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
709 }
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
710
17403
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
711 /*
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
712 %!assert (cummin ([1, 4, 2, 3]), [1 1 1 1])
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
713 %!assert (cummin ([1; -10; 5; -2]), [1; -10; -10; -10])
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
714 %!assert (cummin ([4, i; -2, 2]), [4, i; -2, i])
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
715
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
716 %!test
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
717 %! x = reshape (1:8, [2,2,2]);
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
718 %! assert (cummin (x, 1), reshape ([1 1 3 3 5 5 7 7], [2,2,2]));
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
719 %! assert (cummin (x, 2), reshape ([1 2 1 2 5 6 5 6], [2,2,2]));
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
720 %! [w, iw] = cummin (x, 3);
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
721 %! assert (ndims (w), 3);
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
722 %! assert (w, repmat ([1 3; 2 4], [1 1 2]));
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
723 %! assert (ndims (iw), 3);
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
724 %! assert (iw, ones (2,2,2));
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
725
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
726 %!error cummin ()
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
727 %!error cummin (1, 2, 3)
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
728 */
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
729
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
730 DEFUN (cummax, args, nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
731 "-*- texinfo -*-\n\
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
732 @deftypefn {Built-in Function} {} cummax (@var{x})\n\
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
733 @deftypefnx {Built-in Function} {} cummax (@var{x}, @var{dim})\n\
17403
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
734 @deftypefnx {Built-in Function} {[@var{w}, @var{iw}] =} cummax (@dots{})\n\
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
735 Return the cumulative maximum values along dimension @var{dim}.\n\
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
736 \n\
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
737 If @var{dim} is unspecified it defaults to column-wise operation. For\n\
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
738 example:\n\
9141
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9086
diff changeset
739 \n\
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
740 @example\n\
9141
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9086
diff changeset
741 @group\n\
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9086
diff changeset
742 cummax ([1 3 2 6 4 5])\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
743 @result{} 1 3 3 6 6 6\n\
9141
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9086
diff changeset
744 @end group\n\
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9086
diff changeset
745 @end example\n\
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9086
diff changeset
746 \n\
17403
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
747 If called with two output arguments the index of the maximum value is also\n\
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
748 returned.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10155
diff changeset
749 \n\
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
750 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8949
diff changeset
751 @group\n\
17403
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
752 [w, iw] = cummax ([1 3 2 6 4 5])\n\
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
753 @result{}\n\
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
754 w = 1 3 3 6 6 6\n\
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
755 iw = 1 2 2 4 4 4\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8949
diff changeset
756 @end group\n\
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
757 @end example\n\
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
758 \n\
9141
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9086
diff changeset
759 @seealso{cummin, max, min}\n\
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
760 @end deftypefn")
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
761 {
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
762 return do_cumminmax_body (args, nargout, false);
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
763 }
17403
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
764
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
765 /*
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
766 %!assert (cummax ([1, 4, 2, 3]), [1 4 4 4])
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
767 %!assert (cummax ([1; -10; 5; -2]), [1; 1; 5; 5])
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
768 %!assert (cummax ([4, i 4.9, -2, 2, 3+4i]), [4, 4, 4.9, 4.9, 4.9, 3+4i])
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
769
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
770 %!test
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
771 %! x = reshape (8:-1:1, [2,2,2]);
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
772 %! assert (cummax (x, 1), reshape ([8 8 6 6 4 4 2 2], [2,2,2]));
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
773 %! assert (cummax (x, 2), reshape ([8 7 8 7 4 3 4 3], [2,2,2]));
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
774 %! [w, iw] = cummax (x, 3);
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
775 %! assert (ndims (w), 3);
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
776 %! assert (w, repmat ([8 6; 7 5], [1 1 2]));
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
777 %! assert (ndims (iw), 3);
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
778 %! assert (iw, ones (2,2,2));
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
779
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
780 %!error cummax ()
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
781 %!error cummax (1, 2, 3)
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
782 */
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
783