annotate libinterp/corefcn/data.cc @ 24543:0c204cd762a4

Fix reversal of START,END in linspace BIST test in cset 22a2bc91cc7f. * data.cc: Reverse START, END in calculation of delta for x3.
author Rik <rik@octave.org>
date Sun, 07 Jan 2018 07:20:03 -0800
parents 46440078d73b
children c241918d4c92
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1 /*
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2
23219
3ac9f9ecfae5 maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
3 Copyright (C) 1994-2017 John W. Eaton
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
4 Copyright (C) 2009 Jaroslav Hajek
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 11435
diff changeset
5 Copyright (C) 2009-2010 VZLU Prague
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
6 Copyright (C) 2012 Carlo de Falco
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
7
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
8 This file is part of Octave.
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
9
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24518
diff changeset
10 Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22737
diff changeset
11 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24518
diff changeset
12 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22737
diff changeset
13 (at your option) any later version.
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22737
diff changeset
14
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22737
diff changeset
15 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22737
diff changeset
16 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22737
diff changeset
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22737
diff changeset
18 GNU General Public License for more details.
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
19
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
20 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: 7007
diff changeset
21 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24518
diff changeset
22 <https://www.gnu.org/licenses/>.
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
23
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
24 */
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21723
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
27 # include "config.h"
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
28 #endif
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
29
23625
b0a2367823f5 Use hypot, hypotf from C++ std library.
Rik <rik@octave.org>
parents: 23599
diff changeset
30 #include <cmath>
23455
73ff72d3d603 maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents: 23450
diff changeset
31 #include <cstddef>
73ff72d3d603 maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents: 23450
diff changeset
32 #include <cstdint>
10303
e4899d6320b6 data.cc: use CLOCKS_PER_SEC instead of HZ
John W. Eaton <jwe@octave.org>
parents: 10302
diff changeset
33 #include <ctime>
2184
dbbbb3559ee8 [project @ 1996-05-14 02:18:22 by jwe]
jwe
parents: 2086
diff changeset
34
23455
73ff72d3d603 maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents: 23450
diff changeset
35 #include <algorithm>
73ff72d3d603 maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents: 23450
diff changeset
36 #include <limits>
1728
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1572
diff changeset
37 #include <string>
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1572
diff changeset
38
2184
dbbbb3559ee8 [project @ 1996-05-14 02:18:22 by jwe]
jwe
parents: 2086
diff changeset
39 #include "lo-ieee.h"
23455
73ff72d3d603 maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents: 23450
diff changeset
40 #include "mx-base.h"
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
41 #include "oct-base64.h"
23455
73ff72d3d603 maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents: 23450
diff changeset
42 #include "oct-binmap.h"
10240
fa7b5751730c use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents: 10185
diff changeset
43 #include "oct-time.h"
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4114
diff changeset
44 #include "quit.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
45
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
46 #include "Cell.h"
23462
314d980bee93 maint: Add '#include "XXX.h"' to XXX.cc files.
Rik <rik@octave.org>
parents: 23455
diff changeset
47 #include "data.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1315
diff changeset
48 #include "defun.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1315
diff changeset
49 #include "error.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
50 #include "errwarn.h"
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
51 #include "interpreter-private.h"
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
52 #include "oct-map.h"
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
53 #include "ov-class.h"
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
54 #include "ov-complex.h"
23462
314d980bee93 maint: Add '#include "XXX.h"' to XXX.cc files.
Rik <rik@octave.org>
parents: 23455
diff changeset
55 #include "ov-cx-mat.h"
314d980bee93 maint: Add '#include "XXX.h"' to XXX.cc files.
Rik <rik@octave.org>
parents: 23455
diff changeset
56 #include "ov-cx-sparse.h"
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
57 #include "ov-float.h"
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
58 #include "ov-flt-complex.h"
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
59 #include "ov-flt-cx-mat.h"
23462
314d980bee93 maint: Add '#include "XXX.h"' to XXX.cc files.
Rik <rik@octave.org>
parents: 23455
diff changeset
60 #include "ov.h"
314d980bee93 maint: Add '#include "XXX.h"' to XXX.cc files.
Rik <rik@octave.org>
parents: 23455
diff changeset
61 #include "ovl.h"
314d980bee93 maint: Add '#include "XXX.h"' to XXX.cc files.
Rik <rik@octave.org>
parents: 23455
diff changeset
62 #include "pager.h"
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
63 #include "parse.h"
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
64 #include "pt-mat.h"
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
65 #include "utils.h"
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
66 #include "variables.h"
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
67 #include "xnorm.h"
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
68
20652
7a8096f8df5d more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents: 20651
diff changeset
69 static void
7a8096f8df5d more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents: 20651
diff changeset
70 index_error (const char *fmt, const std::string& idx, const std::string& msg)
7a8096f8df5d more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents: 20651
diff changeset
71 {
7a8096f8df5d more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents: 20651
diff changeset
72 error (fmt, idx.c_str (), msg.c_str ());
7a8096f8df5d more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents: 20651
diff changeset
73 }
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
74
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
75 DEFUN (all, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
76 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
77 @deftypefn {} {} all (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
78 @deftypefnx {} {} all (@var{x}, @var{dim})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
79 For a vector argument, return true (logical 1) if all elements of the vector
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
80 are nonzero.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
81
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
82 For a matrix argument, return a row vector of logical ones and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
83 zeros with each element indicating whether all of the elements of the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
84 corresponding column of the matrix are nonzero. For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
85
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
86 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
87 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
88 all ([2, 3; 1, 0])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
89 @result{} [ 1, 0 ]
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
90 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
91 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
92
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
93 If the optional argument @var{dim} is supplied, work along dimension
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
94 @var{dim}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
95 @seealso{any}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
96 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
97 {
20943
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
98 int nargin = args.length ();
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
99
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
100 if (nargin < 1 || nargin > 2)
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
101 print_usage ();
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
102
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
103 int dim = (nargin == 1 ? -1
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
104 : args(1).int_value ("all: DIM must be an integer")-1);
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
105
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
106 if (dim < -1)
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
107 error ("all: invalid dimension argument = %d", dim + 1);
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
108
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
109 return ovl (args(0).all (dim));
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
110 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
111
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
112 /*
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
113 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
114 %! x = ones (3);
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
115 %! x(1,1) = 0;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
116 %! assert (all (all (rand (3) + 1) == [1, 1, 1]) == 1);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
117 %! assert (all (all (x) == [0, 1, 1]) == 1);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
118 %! assert (all (x, 1) == [0, 1, 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
119 %! assert (all (x, 2) == [0; 1; 1]);
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
120
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
121 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
122 %! x = ones (3, "single");
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
123 %! x(1,1) = 0;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
124 %! assert (all (all (single (rand (3) + 1)) == [1, 1, 1]) == 1);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
125 %! assert (all (all (x) == [0, 1, 1]) == 1);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
126 %! assert (all (x, 1) == [0, 1, 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
127 %! assert (all (x, 2) == [0; 1; 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
128
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
129 %!error all ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
130 %!error all (1, 2, 3)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
131 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
132
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
133 DEFUN (any, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
134 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
135 @deftypefn {} {} any (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
136 @deftypefnx {} {} any (@var{x}, @var{dim})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
137 For a vector argument, return true (logical 1) if any element of the vector
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
138 is nonzero.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
139
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
140 For a matrix argument, return a row vector of logical ones and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
141 zeros with each element indicating whether any of the elements of the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
142 corresponding column of the matrix are nonzero. For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
143
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
144 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
145 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
146 any (eye (2, 4))
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
147 @result{} [ 1, 1, 0, 0 ]
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
148 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
149 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
150
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
151 If the optional argument @var{dim} is supplied, work along dimension
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
152 @var{dim}. For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
153
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
154 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
155 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
156 any (eye (2, 4), 2)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
157 @result{} [ 1; 1 ]
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
158 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
159 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
160 @seealso{all}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
161 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
162 {
20943
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
163 int nargin = args.length ();
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
164
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
165 if (nargin < 1 || nargin > 2)
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
166 print_usage ();
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
167
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
168 int dim = (nargin == 1 ? -1
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
169 : args(1).int_value ("any: DIM must be an integer")-1);
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
170
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
171 if (dim < -1)
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
172 error ("any: invalid dimension argument = %d", dim + 1);
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
173
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
174 return ovl (args(0).any (dim));
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
175 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
176
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
177 /*
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
178 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
179 %! x = zeros (3);
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
180 %! x(3,3) = 1;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
181 %! assert (all (any (x) == [0, 0, 1]) == 1);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
182 %! assert (all (any (ones (3)) == [1, 1, 1]) == 1);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
183 %! assert (any (x, 1) == [0, 0, 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
184 %! assert (any (x, 2) == [0; 0; 1]);
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
185
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
186 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
187 %! x = zeros (3, "single");
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
188 %! x(3,3) = 1;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
189 %! assert (all (any (x) == [0, 0, 1]) == 1);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
190 %! assert (all (any (ones (3, "single")) == [1, 1, 1]) == 1);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
191 %! assert (any (x, 1) == [0, 0, 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
192 %! assert (any (x, 2) == [0; 0; 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
193
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
194 %!error any ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
195 %!error any (1, 2, 3)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
196 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
197
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
198 // These mapping functions may also be useful in other places, eh?
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
199
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
200 DEFUN (atan2, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
201 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
202 @deftypefn {} {} atan2 (@var{y}, @var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
203 Compute atan (@var{y} / @var{x}) for corresponding elements of @var{y}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
204 and @var{x}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
205
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
206 @var{y} and @var{x} must match in size and orientation. The signs of
22440
20e6de770ca4 * data.cc (Fatan2): Fix typo "quadrats" → "quadrants".
Mike Miller <mtmiller@octave.org>
parents: 22429
diff changeset
207 elements of @var{y} and @var{x} are used to determine the quadrants of each
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
208 resulting value.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
209
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
210 This function is equivalent to @code{arg (complex (@var{x}, @var{y}))}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
211 @seealso{tan, tand, tanh, atanh}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
212 @end deftypefn */)
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
213 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
214 if (args.length () != 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
215 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
216
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4176
diff changeset
217 octave_value retval;
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
218
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
219 if (! args(0).isnumeric ())
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
220 err_wrong_type_arg ("atan2", args(0));
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
221
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
222 if (! args(1).isnumeric ())
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
223 err_wrong_type_arg ("atan2", args(1));
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
224
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
225 if (args(0).iscomplex () || args(1).iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
226 error ("atan2: not defined for complex numbers");
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
227
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
228 if (args(0).is_single_type () || args(1).is_single_type ())
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
229 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
230 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
231 retval = atan2f (args(0).float_value (), args(1).float_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
232 else
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
233 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
234 FloatNDArray a0 = args(0).float_array_value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
235 FloatNDArray a1 = args(1).float_array_value ();
24088
0160a3199b2d avoid warnings from GCC about ABI change with exception specifications
John W. Eaton <jwe@octave.org>
parents: 23803
diff changeset
236 retval = binmap<float> (a0, a1, std::atan2, "atan2");
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
237 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
238 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
239 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
240 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
241 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
242 retval = atan2 (args(0).scalar_value (), args(1).scalar_value ());
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
243 else if (args(0).issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
244 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
245 SparseMatrix m0 = args(0).sparse_matrix_value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
246 SparseMatrix m1 = args(1).sparse_matrix_value ();
24088
0160a3199b2d avoid warnings from GCC about ABI change with exception specifications
John W. Eaton <jwe@octave.org>
parents: 23803
diff changeset
247 retval = binmap<double> (m0, m1, std::atan2, "atan2");
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
248 }
7494
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
249 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
250 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
251 NDArray a0 = args(0).array_value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
252 NDArray a1 = args(1).array_value ();
24088
0160a3199b2d avoid warnings from GCC about ABI change with exception specifications
John W. Eaton <jwe@octave.org>
parents: 23803
diff changeset
253 retval = binmap<double> (a0, a1, std::atan2, "atan2");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
254 }
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
255 }
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
256
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
257 return retval;
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
258 }
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
259
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
260 /*
7741
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
261 %!assert (size (atan2 (zeros (0, 2), zeros (0, 2))), [0, 2])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
262 %!assert (size (atan2 (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
263 %!assert (size (atan2 (rand (2, 3, 4), 1)), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
264 %!assert (size (atan2 (1, rand (2, 3, 4))), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
265 %!assert (size (atan2 (1, 2)), [1, 1])
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
266
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
267 %!test
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
268 %! rt2 = sqrt (2);
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
269 %! rt3 = sqrt (3);
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
270 %! v = [0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0];
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
271 %! y = [0, rt3, 1, rt3, -rt3, -1, -rt3, 0];
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
272 %! x = [1, 3, 1, 1, 1, 1, 3, 1];
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
273 %! assert (atan2 (y, x), v, sqrt (eps));
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
274
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
275 %!test
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
276 %! rt2 = sqrt (2);
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
277 %! rt3 = sqrt (3);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
278 %! v = single ([0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
279 %! y = single ([0, rt3, 1, rt3, -rt3, -1, -rt3, 0]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
280 %! x = single ([1, 3, 1, 1, 1, 1, 3, 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
281 %! assert (atan2 (y, x), v, sqrt (eps ("single")));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
282
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
283 ## Test sparse implementations
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
284 %!shared xs
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
285 %! xs = sparse (0:3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
286 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
287 %! y = atan2 (1, xs);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
288 %! assert (issparse (y), false);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
289 %! assert (nnz (y), 4);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
290 %! assert (y, atan2 (1, 0:3));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
291 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
292 %! y = atan2 (0, xs);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
293 %! assert (issparse (y), false);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
294 %! assert (nnz (y), 0);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
295 %! assert (y, zeros (1,4));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
296 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
297 %! y = atan2 (xs, 1);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
298 %! assert (issparse (y));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
299 %! assert (nnz (y), 3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
300 %! assert (y, sparse (atan2 (0:3, 1)));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
301 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
302 %! y = atan2 (xs, 0);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
303 %! assert (issparse (y));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
304 %! assert (nnz (y), 3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
305 %! assert (y, sparse (atan2 (0:3, 0)));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
306 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
307 %! y = atan2 (xs, sparse (ones (1, 4)));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
308 %! assert (issparse (y));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
309 %! assert (nnz (y), 3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
310 %! assert (y, sparse (atan2 (0:3, ones (1,4))));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
311 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
312 %! y = atan2 (xs, sparse (zeros (1,4)));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
313 %! assert (issparse (y));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
314 %! assert (nnz (y), 3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
315 %! assert (y, sparse (atan2 (0:3, zeros (1,4))));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
316
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
317 %!error atan2 ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
318 %!error atan2 (1, 2, 3)
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
319 */
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
320
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
321 static octave_value
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
322 do_hypot (const octave_value& x, const octave_value& y)
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
323 {
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
324 octave_value retval;
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
325
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17915
diff changeset
326 octave_value arg0 = x;
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17915
diff changeset
327 octave_value arg1 = y;
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
328 if (! arg0.isnumeric ())
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
329 err_wrong_type_arg ("hypot", arg0);
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
330 if (! arg1.isnumeric ())
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
331 err_wrong_type_arg ("hypot", arg1);
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
332
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
333 if (arg0.iscomplex ())
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
334 arg0 = arg0.abs ();
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
335 if (arg1.iscomplex ())
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
336 arg1 = arg1.abs ();
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
337
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
338 if (arg0.is_single_type () || arg1.is_single_type ())
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
339 {
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
340 if (arg0.is_scalar_type () && arg1.is_scalar_type ())
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
341 retval = hypotf (arg0.float_value (), arg1.float_value ());
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
342 else
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
343 {
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
344 FloatNDArray a0 = arg0.float_array_value ();
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
345 FloatNDArray a1 = arg1.float_array_value ();
24088
0160a3199b2d avoid warnings from GCC about ABI change with exception specifications
John W. Eaton <jwe@octave.org>
parents: 23803
diff changeset
346 retval = binmap<float> (a0, a1, std::hypot, "hypot");
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
347 }
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
348 }
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
349 else
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
350 {
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
351 if (arg0.is_scalar_type () && arg1.is_scalar_type ())
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
352 retval = hypot (arg0.scalar_value (), arg1.scalar_value ());
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
353 else if (arg0.issparse () || arg1.issparse ())
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
354 {
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
355 SparseMatrix m0 = arg0.sparse_matrix_value ();
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
356 SparseMatrix m1 = arg1.sparse_matrix_value ();
23625
b0a2367823f5 Use hypot, hypotf from C++ std library.
Rik <rik@octave.org>
parents: 23599
diff changeset
357 retval = binmap<double> (m0, m1, std::hypot, "hypot");
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
358 }
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
359 else
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
360 {
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
361 NDArray a0 = arg0.array_value ();
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
362 NDArray a1 = arg1.array_value ();
23625
b0a2367823f5 Use hypot, hypotf from C++ std library.
Rik <rik@octave.org>
parents: 23599
diff changeset
363 retval = binmap<double> (a0, a1, std::hypot, "hypot");
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
364 }
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
365 }
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
366
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
367 return retval;
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
368 }
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
369
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
370 DEFUN (hypot, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
371 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
372 @deftypefn {} {} hypot (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
373 @deftypefnx {} {} hypot (@var{x}, @var{y}, @var{z}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
374 Compute the element-by-element square root of the sum of the squares of
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
375 @var{x} and @var{y}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
376
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
377 This is equivalent to
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
378 @code{sqrt (@var{x}.^2 + @var{y}.^2)}, but is calculated in a manner that
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
379 avoids overflows for large values of @var{x} or @var{y}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
380
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
381 @code{hypot} can also be called with more than 2 arguments; in this case,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
382 the arguments are accumulated from left to right:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
383
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
384 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
385 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
386 hypot (hypot (@var{x}, @var{y}), @var{z})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
387 hypot (hypot (hypot (@var{x}, @var{y}), @var{z}), @var{w}), etc.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
388 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
389 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
390 @end deftypefn */)
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
391 {
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
392 int nargin = args.length ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
393
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
394 if (nargin < 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
395 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
396
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
397 octave_value retval;
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
398
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
399 if (nargin == 2)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
400 retval = do_hypot (args(0), args(1));
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
401 else
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
402 {
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
403 retval = args(0);
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
404
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
405 for (int i = 1; i < nargin; i++)
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
406 retval = do_hypot (retval, args(i));
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
407 }
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
408
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
409 return retval;
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
410 }
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
411
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
412 /*
7741
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
413 %!assert (size (hypot (zeros (0, 2), zeros (0, 2))), [0, 2])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
414 %!assert (size (hypot (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
415 %!assert (size (hypot (rand (2, 3, 4), 1)), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
416 %!assert (size (hypot (1, rand (2, 3, 4))), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
417 %!assert (size (hypot (1, 2)), [1, 1])
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
418 %!assert (hypot (1:10, 1:10), sqrt (2) * [1:10], 16*eps)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
419 %!assert (hypot (single (1:10), single (1:10)), single (sqrt (2) * [1:10]))
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
420
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
421 ## Test sparse implementations
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
422 %!shared xs
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
423 %! xs = sparse (0:3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
424 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
425 %! y = hypot (1, xs);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
426 %! assert (nnz (y), 4);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
427 %! assert (y, sparse (hypot (1, 0:3)));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
428 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
429 %! y = hypot (0, xs);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
430 %! assert (nnz (y), 3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
431 %! assert (y, xs);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
432 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
433 %! y = hypot (xs, 1);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
434 %! assert (nnz (y), 4);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
435 %! assert (y, sparse (hypot (0:3, 1)));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
436 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
437 %! y = hypot (xs, 0);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
438 %! assert (nnz (y), 3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
439 %! assert (y, xs);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
440 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
441 %! y = hypot (sparse ([0 0]), sparse ([0 1]));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
442 %! assert (nnz (y), 1);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
443 %! assert (y, sparse ([0 1]));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
444 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
445 %! y = hypot (sparse ([0 1]), sparse ([0 0]));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
446 %! assert (nnz (y), 1);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
447 %! assert (y, sparse ([0 1]));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
448
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
449 */
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
450
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
451 template <typename T, typename ET>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
452 void
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
453 map_2_xlog2 (const Array<T>& x, Array<T>& f, Array<ET>& e)
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
454 {
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
455 f = Array<T>(x.dims ());
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
456 e = Array<ET>(x.dims ());
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
457 for (octave_idx_type i = 0; i < x.numel (); i++)
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
458 {
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
459 int exp;
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
460 f.xelem (i) = octave::math::log2 (x(i), exp);
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
461 e.xelem (i) = exp;
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
462 }
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
463 }
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
464
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
465 DEFUN (log2, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
466 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
467 @deftypefn {} {} log2 (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
468 @deftypefnx {} {[@var{f}, @var{e}] =} log2 (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
469 Compute the base-2 logarithm of each element of @var{x}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
470
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
471 If called with two output arguments, split @var{x} into
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
472 binary mantissa and exponent so that
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
473 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
474 ${1 \over 2} \le \left| f \right| < 1$
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
475 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
476 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
477 @w{@code{1/2 <= abs(f) < 1}}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
478 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
479 and @var{e} is an integer. If
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
480 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
481 $x = 0$, $f = e = 0$.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
482 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
483 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
484 @w{@code{x = 0}}, @w{@code{f = e = 0}}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
485 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
486 @seealso{pow2, log, log10, exp}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
487 @end deftypefn */)
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
488 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
489 if (args.length () != 1)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
490 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
491
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
492 octave_value_list retval;
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
493
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
494 if (nargout < 2)
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
495 retval = ovl (args(0).log2 ());
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
496 else if (args(0).is_single_type ())
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
497 {
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
498 if (args(0).isreal ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
499 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
500 FloatNDArray f;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
501 FloatNDArray x = args(0).float_array_value ();
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
502 // FIXME: should E be an int value?
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
503 FloatMatrix e;
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
504 map_2_xlog2 (x, f, e);
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
505 retval = ovl (f, e);
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
506 }
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
507 else if (args(0).iscomplex ())
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
508 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
509 FloatComplexNDArray f;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
510 FloatComplexNDArray x = args(0).float_complex_array_value ();
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
511 // FIXME: should E be an int value?
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
512 FloatNDArray e;
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
513 map_2_xlog2 (x, f, e);
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
514 retval = ovl (f, e);
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
515 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
516 }
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
517 else if (args(0).isreal ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
518 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
519 NDArray f;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
520 NDArray x = args(0).array_value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
521 // FIXME: should E be an int value?
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
522 Matrix e;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
523 map_2_xlog2 (x, f, e);
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
524 retval = ovl (f, e);
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
525 }
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
526 else if (args(0).iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
527 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
528 ComplexNDArray f;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
529 ComplexNDArray x = args(0).complex_array_value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
530 // FIXME: should E be an int value?
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
531 NDArray e;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
532 map_2_xlog2 (x, f, e);
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
533 retval = ovl (f, e);
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
534 }
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
535 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
536 err_wrong_type_arg ("log2", args(0));
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
537
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
538 return retval;
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
539 }
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
540
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
541 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
542 %!assert (log2 ([1/4, 1/2, 1, 2, 4]), [-2, -1, 0, 1, 2])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
543 %!assert (log2 (Inf), Inf)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
544 %!assert (isnan (log2 (NaN)))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
545 %!assert (log2 (4*i), 2 + log2 (1*i))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
546 %!assert (log2 (complex (0,Inf)), Inf + log2 (i))
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
547
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
548 %!test
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
549 %! [f, e] = log2 ([0,-1; 2,-4; Inf,-Inf]);
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
550 %! assert (f, [0,-0.5; 0.5,-0.5; Inf,-Inf]);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
551 %! assert (e(1:2,:), [0,1;2,3]);
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
552
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
553 %!test
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
554 %! [f, e] = log2 (complex (zeros (3, 2), [0,-1; 2,-4; Inf,-Inf]));
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
555 %! assert (f, complex (zeros (3, 2), [0,-0.5; 0.5,-0.5; Inf,-Inf]));
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
556 %! assert (e(1:2,:), [0,1; 2,3]);
18851
9d185537e5d1 * data.cc: New test for log2 (bug #42583).
John W. Eaton <jwe@octave.org>
parents: 18809
diff changeset
557
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
558 %!assert <*42583> (all (log2 (pow2 (-1074:1023)) == -1074:1023))
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
559 */
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
560
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
561 DEFUN (rem, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
562 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
563 @deftypefn {} {} rem (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
564 Return the remainder of the division @code{@var{x} / @var{y}}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
565
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
566 The remainder is computed using the expression
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
567
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
568 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
569 x - y .* fix (x ./ y)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
570 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
571
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
572 An error message is printed if the dimensions of the arguments do not agree,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
573 or if either argument is complex.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
574
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
575 Programming Notes: Floating point numbers within a few eps of an integer
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
576 will be rounded to an integer before computation for compatibility with
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
577 @sc{matlab}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
578
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
579 By convention,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
580
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
581 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
582 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
583 rem (@var{x}, 0) = NaN if @var{x} is a floating point variable
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
584 rem (@var{x}, 0) = 0 if @var{x} is an integer variable
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
585 rem (@var{x}, @var{y}) returns a value with the signbit from @var{x}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
586 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
587 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
588
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
589 For the opposite conventions see the @code{mod} function. In general,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
590 @code{rem} is best when computing the remainder after division of two
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
591 @emph{positive} numbers. For negative numbers, or when the values are
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
592 periodic, @code{mod} is a better choice.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
593 @seealso{mod}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
594 @end deftypefn */)
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
595 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
596 if (args.length () != 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
597 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
598
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
599 octave_value retval;
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
600
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
601 if (! args(0).isnumeric ())
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
602 err_wrong_type_arg ("rem", args(0));
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
603
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
604 if (! args(1).isnumeric ())
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
605 err_wrong_type_arg ("rem", args(1));
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
606
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
607 if (args(0).iscomplex () || args(1).iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
608 error ("rem: not defined for complex numbers");
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
609
23580
2230f9e10fb3 maint: Deprecate is_integer_type and replace with isinteger.
Rik <rik@octave.org>
parents: 23579
diff changeset
610 if (args(0).isinteger () || args(1).isinteger ())
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
611 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
612 builtin_type_t btyp0 = args(0).builtin_type ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
613 builtin_type_t btyp1 = args(1).builtin_type ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
614 if (btyp0 == btyp_double || btyp0 == btyp_float)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
615 btyp0 = btyp1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
616 if (btyp1 == btyp_double || btyp1 == btyp_float)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
617 btyp1 = btyp0;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
618
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
619 if (btyp0 != btyp1)
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
620 error ("rem: cannot combine %s and %d",
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
621 args(0).class_name ().c_str (),
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
622 args(1).class_name ().c_str ());
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
623
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
624 switch (btyp0)
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
625 {
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
626 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
627 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
628 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
629 X##NDArray a0 = args(0).X##_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
630 X##NDArray a1 = args(1).X##_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
631 retval = binmap<octave_##X,octave_##X,octave_##X> (a0, a1, rem, "rem"); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
632 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
633 break
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
634
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
635 MAKE_INT_BRANCH (int8);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
636 MAKE_INT_BRANCH (int16);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
637 MAKE_INT_BRANCH (int32);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
638 MAKE_INT_BRANCH (int64);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
639 MAKE_INT_BRANCH (uint8);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
640 MAKE_INT_BRANCH (uint16);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
641 MAKE_INT_BRANCH (uint32);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
642 MAKE_INT_BRANCH (uint64);
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
643
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
644 #undef MAKE_INT_BRANCH
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
645
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
646 default:
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
647 panic_impossible ();
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
648 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
649 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
650 else if (args(0).is_single_type () || args(1).is_single_type ())
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
651 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
652 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
653 retval = octave::math::rem (args(0).float_value (), args(1).float_value ());
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
654 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
655 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
656 FloatNDArray a0 = args(0).float_array_value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
657 FloatNDArray a1 = args(1).float_array_value ();
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
658 retval = binmap<float> (a0, a1, octave::math::rem<float>, "rem");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
659 }
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
660 }
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
661 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
662 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
663 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
664 retval = octave::math::rem (args(0).scalar_value (), args(1).scalar_value ());
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
665 else if (args(0).issparse () || args(1).issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
666 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
667 SparseMatrix m0 = args(0).sparse_matrix_value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
668 SparseMatrix m1 = args(1).sparse_matrix_value ();
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
669 retval = binmap<double> (m0, m1, octave::math::rem<double>, "rem");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
670 }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
671 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
672 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
673 NDArray a0 = args(0).array_value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
674 NDArray a1 = args(1).array_value ();
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
675 retval = binmap<double> (a0, a1, octave::math::rem<double>, "rem");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
676 }
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
677 }
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
678
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
679 return retval;
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
680 }
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
681
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
682 /*
19118
9c5a17d5fc19 Deprecate fmod function.
Rik <rik@octave.org>
parents: 19079
diff changeset
683 %!assert (size (rem (zeros (0, 2), zeros (0, 2))), [0, 2])
9c5a17d5fc19 Deprecate fmod function.
Rik <rik@octave.org>
parents: 19079
diff changeset
684 %!assert (size (rem (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4])
9c5a17d5fc19 Deprecate fmod function.
Rik <rik@octave.org>
parents: 19079
diff changeset
685 %!assert (size (rem (rand (2, 3, 4), 1)), [2, 3, 4])
9c5a17d5fc19 Deprecate fmod function.
Rik <rik@octave.org>
parents: 19079
diff changeset
686 %!assert (size (rem (1, rand (2, 3, 4))), [2, 3, 4])
9c5a17d5fc19 Deprecate fmod function.
Rik <rik@octave.org>
parents: 19079
diff changeset
687 %!assert (size (rem (1, 2)), [1, 1])
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
688
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
689 %!assert (rem ([1, 2, 3; -1, -2, -3], 2), [1, 0, 1; -1, 0, -1])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
690 %!assert (rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3)),[1, 0, 1; -1, 0, -1])
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
691 %!assert (rem ([0, 1, 2], [0, 0, 1]), [NaN, NaN, 0])
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
692 %!assert (rem (uint8 ([1, 2, 3; -1, -2, -3]), uint8 (2)), uint8 ([1, 0, 1; -1, 0, -1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
693 %!assert (uint8 (rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3))),uint8 ([1, 0, 1; -1, 0, -1]))
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
694 %!assert (rem (uint8 ([0, 1, 2]), [0, 0, 1]), uint8 ([0, 0, 0]))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
695
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
696 ## Test sparse implementations
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
697 %!shared xs
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
698 %! xs = sparse (0:3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
699 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
700 %! y = rem (11, xs);
20374
0cefba1a1030 Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents: 20232
diff changeset
701 %! assert (isnan (y(1)));
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
702 %! assert (y, sparse (rem (11, 0:3)));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
703 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
704 %! y = rem (0, xs);
20374
0cefba1a1030 Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents: 20232
diff changeset
705 %! assert (nnz (y), 1);
0cefba1a1030 Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents: 20232
diff changeset
706 %! assert (y, sparse ([NaN 0 0 0]));
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
707 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
708 %! y = rem (xs, 2);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
709 %! assert (nnz (y), 2);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
710 %! assert (y, sparse (rem (0:3, 2)));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
711 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
712 %! y = rem (xs, 1);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
713 %! assert (nnz (y), 0);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
714 %! assert (y, sparse (rem (0:3, 1)));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
715 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
716 %! y = rem (sparse ([11 11 11 11]), xs);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
717 %! assert (nnz (y), 3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
718 %! assert (y, sparse (rem (11, 0:3)));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
719 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
720 %! y = rem (sparse ([0 0 0 0]), xs);
20374
0cefba1a1030 Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents: 20232
diff changeset
721 %! assert (nnz (y), 1);
0cefba1a1030 Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents: 20232
diff changeset
722 %! assert (y, sparse ([NaN 0 0 0]));
0cefba1a1030 Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents: 20232
diff changeset
723
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
724 %!assert <*45587> (signbit (rem (-0, 1)))
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
725 %!assert <*45587> (! signbit (rem (0, 1)))
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
726
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
727 %!assert <*42627> (rem (0.94, 0.01), 0.0)
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
728
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
729 %!error rem (uint (8), int8 (5))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
730 %!error rem (uint8 ([1, 2]), uint8 ([3, 4, 5]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
731 %!error rem ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
732 %!error rem (1, 2, 3)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
733 %!error rem ([1, 2], [3, 4, 5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
734 %!error rem (i, 1)
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
735 */
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
736
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
737 DEFUN (mod, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
738 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
739 @deftypefn {} {} mod (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
740 Compute the modulo of @var{x} and @var{y}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
741
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
742 Conceptually this is given by
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
743
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
744 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
745 x - y .* floor (x ./ y)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
746 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
747
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
748 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
749 and is written such that the correct modulus is returned for integer types.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
750 This function handles negative values correctly. That is,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
751 @w{@code{mod (-1, 3)}} is 2, not -1, as @w{@code{rem (-1, 3)}} returns.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
752
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
753 An error results if the dimensions of the arguments do not agree, or if
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
754 either of the arguments is complex.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
755
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
756 Programming Notes: Floating point numbers within a few eps of an integer
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
757 will be rounded to an integer before computation for compatibility with
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
758 @sc{matlab}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
759
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
760 By convention,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
761
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
762 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
763 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
764 mod (@var{x}, 0) = @var{x}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
765 mod (@var{x}, @var{y}) returns a value with the signbit from @var{y}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
766 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
767 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
768
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
769 For the opposite conventions see the @code{rem} function. In general,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
770 @code{mod} is a better choice than @code{rem} when any of the inputs are
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
771 negative numbers or when the values are periodic.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
772 @seealso{rem}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
773 @end deftypefn */)
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
774 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
775 if (args.length () != 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
776 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
777
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
778 octave_value retval;
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
779
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
780 if (! args(0).isnumeric ())
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
781 err_wrong_type_arg ("mod", args(0));
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
782
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
783 if (! args(1).isnumeric ())
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
784 err_wrong_type_arg ("mod", args(1));
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
785
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
786 if (args(0).iscomplex () || args(1).iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
787 error ("mod: not defined for complex numbers");
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
788
23580
2230f9e10fb3 maint: Deprecate is_integer_type and replace with isinteger.
Rik <rik@octave.org>
parents: 23579
diff changeset
789 if (args(0).isinteger () || args(1).isinteger ())
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
790 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
791 builtin_type_t btyp0 = args(0).builtin_type ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
792 builtin_type_t btyp1 = args(1).builtin_type ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
793 if (btyp0 == btyp_double || btyp0 == btyp_float)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
794 btyp0 = btyp1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
795 if (btyp1 == btyp_double || btyp1 == btyp_float)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
796 btyp1 = btyp0;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
797
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
798 if (btyp0 != btyp1)
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
799 error ("mod: cannot combine %s and %d",
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
800 args(0).class_name ().c_str (),
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
801 args(1).class_name ().c_str ());
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
802
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
803 switch (btyp0)
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
804 {
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
805 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
806 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
807 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
808 X##NDArray a0 = args(0).X##_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
809 X##NDArray a1 = args(1).X##_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
810 retval = binmap<octave_##X,octave_##X,octave_##X> (a0, a1, mod, "mod"); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
811 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
812 break
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
813
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
814 MAKE_INT_BRANCH (int8);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
815 MAKE_INT_BRANCH (int16);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
816 MAKE_INT_BRANCH (int32);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
817 MAKE_INT_BRANCH (int64);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
818 MAKE_INT_BRANCH (uint8);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
819 MAKE_INT_BRANCH (uint16);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
820 MAKE_INT_BRANCH (uint32);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
821 MAKE_INT_BRANCH (uint64);
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
822
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
823 #undef MAKE_INT_BRANCH
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
824
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
825 default:
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
826 panic_impossible ();
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
827 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
828 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
829 else if (args(0).is_single_type () || args(1).is_single_type ())
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
830 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
831 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
832 retval = octave::math::mod (args(0).float_value (), args(1).float_value ());
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
833 else
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
834 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
835 FloatNDArray a0 = args(0).float_array_value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
836 FloatNDArray a1 = args(1).float_array_value ();
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
837 retval = binmap<float> (a0, a1, octave::math::mod<float>, "mod");
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
838 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
839 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
840 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
841 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
842 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
843 retval = octave::math::mod (args(0).scalar_value (), args(1).scalar_value ());
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
844 else if (args(0).issparse () || args(1).issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
845 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
846 SparseMatrix m0 = args(0).sparse_matrix_value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
847 SparseMatrix m1 = args(1).sparse_matrix_value ();
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
848 retval = binmap<double> (m0, m1, octave::math::mod<double>, "mod");
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
849 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
850 else
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
851 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
852 NDArray a0 = args(0).array_value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
853 NDArray a1 = args(1).array_value ();
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
854 retval = binmap<double> (a0, a1, octave::math::mod<double>, "mod");
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
855 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
856 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
857
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
858 return retval;
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
859 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
860
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
861 /*
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
862 ## empty input test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
863 %!assert (isempty (mod ([], [])))
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
864
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
865 ## x mod y, y != 0 tests
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
866 %!assert (mod (5, 3), 2)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
867 %!assert (mod (-5, 3), 1)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
868 %!assert (mod (0, 3), 0)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
869 %!assert (mod ([-5, 5, 0], [3, 3, 3]), [1, 2, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
870 %!assert (mod ([-5; 5; 0], [3; 3; 3]), [1; 2; 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
871 %!assert (mod ([-5, 5; 0, 3], [3, 3 ; 3, 1]), [1, 2 ; 0, 0])
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
872
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
873 ## x mod 0 tests
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
874 %!assert (mod (5, 0), 5)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
875 %!assert (mod (-5, 0), -5)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
876 %!assert (mod ([-5, 5, 0], [3, 0, 3]), [1, 5, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
877 %!assert (mod ([-5; 5; 0], [3; 0; 3]), [1; 5; 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
878 %!assert (mod ([-5, 5; 0, 3], [3, 0 ; 3, 1]), [1, 5 ; 0, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
879 %!assert (mod ([-5, 5; 0, 3], [0, 0 ; 0, 0]), [-5, 5; 0, 3])
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
880
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
881 ## mixed scalar/matrix tests
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
882 %!assert (mod ([-5, 5; 0, 3], 0), [-5, 5; 0, 3])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
883 %!assert (mod ([-5, 5; 0, 3], 3), [1, 2; 0, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
884 %!assert (mod (-5, [0,0; 0,0]), [-5, -5; -5, -5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
885 %!assert (mod (-5, [3,0; 3,1]), [1, -5; 1, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
886 %!assert (mod (-5, [3,2; 3,1]), [1, 1; 1, 0])
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
887
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
888 ## integer types
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
889 %!assert (mod (uint8 (5), uint8 (4)), uint8 (1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
890 %!assert (mod (uint8 ([1:5]), uint8 (4)), uint8 ([1,2,3,0,1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
891 %!assert (mod (uint8 ([1:5]), uint8 (0)), uint8 ([1:5]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
892 %!error (mod (uint8 (5), int8 (4)))
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
893
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
894 ## mixed integer/real types
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
895 %!assert (mod (uint8 (5), 4), uint8 (1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
896 %!assert (mod (5, uint8 (4)), uint8 (1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
897 %!assert (mod (uint8 ([1:5]), 4), uint8 ([1,2,3,0,1]))
11357
903c1a3df301 Add additional tests for mod with non-integer real values.
Rik <octave@nomad.inbox5.com>
parents: 11242
diff changeset
898
903c1a3df301 Add additional tests for mod with non-integer real values.
Rik <octave@nomad.inbox5.com>
parents: 11242
diff changeset
899 ## non-integer real numbers
903c1a3df301 Add additional tests for mod with non-integer real values.
Rik <octave@nomad.inbox5.com>
parents: 11242
diff changeset
900 %!assert (mod (2.1, 0.1), 0)
903c1a3df301 Add additional tests for mod with non-integer real values.
Rik <octave@nomad.inbox5.com>
parents: 11242
diff changeset
901 %!assert (mod (2.1, 0.2), 0.1, eps)
18869
23681c9ea7ba better guess if rem or mod could be zero (bug #42627)
Olaf Till <i7tiol@t-online.de>
parents: 18851
diff changeset
902
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
903 %!assert <*45587> (signbit (mod (-0, 0)))
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
904 %!assert <*45587> (! signbit (mod (0, -0)))
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
905
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
906 %!assert <*42627> (mod (0.94, 0.01), 0.0)
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
907 */
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
908
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
909 #define DATA_REDUCTION(FCN) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
910 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
911 int nargin = args.length (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
912 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
913 if (nargin < 1 || nargin > 2) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
914 print_usage (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
915 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
916 octave_value retval; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
917 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
918 octave_value arg = args(0); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
919 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
920 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
921 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
922 if (dim < -1) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
923 error (#FCN ": invalid dimension argument = %d", dim + 1); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
924 \
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
925 if (arg.isreal ()) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
926 { \
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
927 if (arg.issparse ()) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
928 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
929 SparseMatrix tmp = arg.sparse_matrix_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
930 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
931 retval = tmp.FCN (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
932 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
933 else if (arg.is_single_type ()) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
934 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
935 FloatNDArray tmp = arg.float_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
936 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
937 retval = tmp.FCN (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
938 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
939 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
940 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
941 NDArray tmp = arg.array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
942 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
943 retval = tmp.FCN (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
944 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
945 } \
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
946 else if (arg.iscomplex ()) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
947 { \
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
948 if (arg.issparse ()) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
949 { \
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
950 SparseComplexMatrix tmp = arg.sparse_complex_matrix_value (); \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
951 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
952 retval = tmp.FCN (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
953 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
954 else if (arg.is_single_type ()) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
955 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
956 FloatComplexNDArray tmp \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
957 = arg.float_complex_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
958 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
959 retval = tmp.FCN (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
960 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
961 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
962 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
963 ComplexNDArray tmp = arg.complex_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
964 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
965 retval = tmp.FCN (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
966 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
967 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
968 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
969 err_wrong_type_arg (#FCN, arg); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
970 \
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
971 return retval
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
972
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
973 DEFUN (cumprod, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
974 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
975 @deftypefn {} {} cumprod (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
976 @deftypefnx {} {} cumprod (@var{x}, @var{dim})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
977 Cumulative product of elements along dimension @var{dim}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
978
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
979 If @var{dim} is omitted, it defaults to the first non-singleton dimension.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
980 For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
981
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
982 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
983 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
984 cumprod ([1, 2; 3, 4; 5, 6])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
985 @result{} 1 2
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
986 3 8
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
987 15 48
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
988 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
989 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
990 @seealso{prod, cumsum}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
991 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
992 {
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
993 DATA_REDUCTION (cumprod);
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
994 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
995
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
996 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
997 %!assert (cumprod ([1, 2, 3]), [1, 2, 6])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
998 %!assert (cumprod ([-1; -2; -3]), [-1; 2; -6])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
999 %!assert (cumprod ([i, 2+i, -3+2i, 4]), [i, -1+2i, -1-8i, -4-32i])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1000 %!assert (cumprod ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [1, 2, 3; i, 4i, 9i; -1+i, -8+8i, -27+27i])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1001
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1002 %!assert (cumprod (single ([1, 2, 3])), single ([1, 2, 6]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1003 %!assert (cumprod (single ([-1; -2; -3])), single ([-1; 2; -6]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1004 %!assert (cumprod (single ([i, 2+i, -3+2i, 4])), single ([i, -1+2i, -1-8i, -4-32i]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1005 %!assert (cumprod (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single ([1, 2, 3; i, 4i, 9i; -1+i, -8+8i, -27+27i]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1006
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1007 %!assert (cumprod ([2, 3; 4, 5], 1), [2, 3; 8, 15])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1008 %!assert (cumprod ([2, 3; 4, 5], 2), [2, 6; 4, 20])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1009
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1010 %!assert (cumprod (single ([2, 3; 4, 5]), 1), single ([2, 3; 8, 15]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1011 %!assert (cumprod (single ([2, 3; 4, 5]), 2), single ([2, 6; 4, 20]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1012
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1013 %!error cumprod ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1014 */
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1015
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
1016 DEFUN (cumsum, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1017 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1018 @deftypefn {} {} cumsum (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1019 @deftypefnx {} {} cumsum (@var{x}, @var{dim})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1020 @deftypefnx {} {} cumsum (@dots{}, "native")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1021 @deftypefnx {} {} cumsum (@dots{}, "double")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1022 Cumulative sum of elements along dimension @var{dim}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1023
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1024 If @var{dim} is omitted, it defaults to the first non-singleton dimension.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1025 For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1026
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1027 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1028 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1029 cumsum ([1, 2; 3, 4; 5, 6])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1030 @result{} 1 2
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1031 4 6
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1032 9 12
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1033 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1034 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1035
24517
59d080a90f17 doc: Remove unimplemented option "extra" from cumsum documentation.
Rik <rik@octave.org>
parents: 24504
diff changeset
1036 See @code{sum} for an explanation of the optional parameters @qcode{"native"}
59d080a90f17 doc: Remove unimplemented option "extra" from cumsum documentation.
Rik <rik@octave.org>
parents: 24504
diff changeset
1037 and @qcode{"double"}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1038 @seealso{sum, cumprod}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1039 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1040 {
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1041 int nargin = args.length ();
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1042
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1043 bool isnative = false;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1044 bool isdouble = false;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1045
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1046 if (nargin > 1 && args(nargin - 1).is_string ())
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1047 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1048 std::string str = args(nargin - 1).string_value ();
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1049
19743
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1050 if (str == "native")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1051 isnative = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1052 else if (str == "double")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1053 isdouble = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1054 else
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1055 error ("cumsum: unrecognized string argument");
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
1056
21062
d9c1884d1aaa maint: Eliminate space between variable and decrement '--' operator.
Rik <rik@octave.org>
parents: 21055
diff changeset
1057 nargin--;
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1058 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1059
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1060 if (nargin < 1 || nargin > 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1061 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1062
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1063 int dim = -1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1064 if (nargin == 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1065 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1066 dim = args(1).int_value () - 1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1067 if (dim < 0)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1068 error ("cumsum: invalid dimension argument = %d", dim + 1);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1069 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1070
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
1071 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
1072 octave_value arg = args(0);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
1073
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1074 switch (arg.builtin_type ())
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1075 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1076 case btyp_double:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1077 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1078 retval = arg.sparse_matrix_value ().cumsum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1079 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1080 retval = arg.array_value ().cumsum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1081 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1082 case btyp_complex:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1083 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1084 retval = arg.sparse_complex_matrix_value ().cumsum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1085 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1086 retval = arg.complex_array_value ().cumsum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1087 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1088 case btyp_float:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1089 if (isdouble)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1090 retval = arg.array_value ().cumsum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1091 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1092 retval = arg.float_array_value ().cumsum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1093 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1094 case btyp_float_complex:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1095 if (isdouble)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1096 retval = arg.complex_array_value ().cumsum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1097 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1098 retval = arg.float_complex_array_value ().cumsum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1099 break;
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1100
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1101 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1102 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1103 if (isnative) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1104 retval = arg.X ## _array_value ().cumsum (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1105 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1106 retval = arg.array_value ().cumsum (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1107 break;
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1108
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1109 MAKE_INT_BRANCH (int8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1110 MAKE_INT_BRANCH (int16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1111 MAKE_INT_BRANCH (int32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1112 MAKE_INT_BRANCH (int64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1113 MAKE_INT_BRANCH (uint8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1114 MAKE_INT_BRANCH (uint16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1115 MAKE_INT_BRANCH (uint32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1116 MAKE_INT_BRANCH (uint64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1117
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1118 #undef MAKE_INT_BRANCH
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1119
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1120 case btyp_bool:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1121 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1122 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1123 SparseMatrix cs = arg.sparse_matrix_value ().cumsum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1124 if (isnative)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1125 retval = cs != 0.0;
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1126 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1127 retval = cs;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1128 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1129 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1130 {
22773
7f70e420e342 deprecate boolNDArray::sum and boolNDArray::cumsum
John W. Eaton <jwe@octave.org>
parents: 22763
diff changeset
1131 NDArray cs = arg.array_value ().cumsum (dim);
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1132 if (isnative)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1133 retval = cs != 0.0;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1134 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1135 retval = cs;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1136 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1137 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1138
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1139 default:
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
1140 err_wrong_type_arg ("cumsum", arg);
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1141 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1142
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1143 return retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1144 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1145
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1146 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1147 %!assert (cumsum ([1, 2, 3]), [1, 3, 6])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1148 %!assert (cumsum ([-1; -2; -3]), [-1; -3; -6])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1149 %!assert (cumsum ([i, 2+i, -3+2i, 4]), [i, 2+2i, -1+4i, 3+4i])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1150 %!assert (cumsum ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [1, 2, 3; 1+i, 2+2i, 3+3i; 2+2i, 4+4i, 6+6i])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1151
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1152 %!assert (cumsum (single ([1, 2, 3])), single ([1, 3, 6]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1153 %!assert (cumsum (single ([-1; -2; -3])), single ([-1; -3; -6]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1154 %!assert (cumsum (single ([i, 2+i, -3+2i, 4])), single ([i, 2+2i, -1+4i, 3+4i]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1155 %!assert (cumsum (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single ([1, 2, 3; 1+i, 2+2i, 3+3i; 2+2i, 4+4i, 6+6i]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1156
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1157 %!assert (cumsum ([1, 2; 3, 4], 1), [1, 2; 4, 6])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1158 %!assert (cumsum ([1, 2; 3, 4], 2), [1, 3; 3, 7])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1159
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1160 %!assert (cumsum (single ([1, 2; 3, 4]), 1), single ([1, 2; 4, 6]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1161 %!assert (cumsum (single ([1, 2; 3, 4]), 2), single ([1, 3; 3, 7]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1162
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1163 %!error cumsum ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1164 */
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1165
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
1166 DEFUN (diag, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1167 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1168 @deftypefn {} {@var{M} =} diag (@var{v})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1169 @deftypefnx {} {@var{M} =} diag (@var{v}, @var{k})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1170 @deftypefnx {} {@var{M} =} diag (@var{v}, @var{m}, @var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1171 @deftypefnx {} {@var{v} =} diag (@var{M})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1172 @deftypefnx {} {@var{v} =} diag (@var{M}, @var{k})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1173 Return a diagonal matrix with vector @var{v} on diagonal @var{k}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1174
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1175 The second argument is optional. If it is positive, the vector is placed on
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1176 the @var{k}-th superdiagonal. If it is negative, it is placed on the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1177 @var{-k}-th subdiagonal. The default value of @var{k} is 0, and the vector
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1178 is placed on the main diagonal. For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1179
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1180 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1181 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1182 diag ([1, 2, 3], 1)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1183 @result{} 0 1 0 0
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1184 0 0 2 0
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1185 0 0 0 3
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1186 0 0 0 0
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1187 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1188 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1189
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1190 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1191 The 3-input form returns a diagonal matrix with vector @var{v} on the main
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1192 diagonal and the resulting matrix being of size @var{m} rows x @var{n}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1193 columns.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1194
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1195 Given a matrix argument, instead of a vector, @code{diag} extracts the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1196 @var{k}-th diagonal of the matrix.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1197 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1198 {
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1199 int nargin = args.length ();
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1200
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1201 if (nargin < 1 || nargin > 3)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1202 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1203
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4176
diff changeset
1204 octave_value retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1205
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1206 if (nargin == 1)
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1207 retval = args(0).diag ();
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1208 else if (nargin == 2)
7620
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7618
diff changeset
1209 {
21041
63374982750b Usage of corresponding value extractor for octave_idx_type. Improves support
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 21014
diff changeset
1210 octave_idx_type k = args(1).xidx_type_value ("diag: invalid argument K");
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
1211
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
1212 retval = args(0).diag (k);
7620
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7618
diff changeset
1213 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1214 else
12570
1a93988610a3 Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents: 12567
diff changeset
1215 {
1a93988610a3 Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents: 12567
diff changeset
1216 octave_value arg0 = args(0);
14557
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1217
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1218 if (arg0.ndims () != 2 || (arg0.rows () != 1 && arg0.columns () != 1))
12570
1a93988610a3 Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents: 12567
diff changeset
1219 error ("diag: V must be a vector");
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1220
21041
63374982750b Usage of corresponding value extractor for octave_idx_type. Improves support
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 21014
diff changeset
1221 octave_idx_type m = args(1).xidx_type_value ("diag: invalid dimensions");
63374982750b Usage of corresponding value extractor for octave_idx_type. Improves support
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 21014
diff changeset
1222 octave_idx_type n = args(2).xidx_type_value ("diag: invalid dimensions");
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1223
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1224 retval = arg0.diag (m, n);
12570
1a93988610a3 Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents: 12567
diff changeset
1225 }
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1226
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1227 return retval;
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1228 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1229
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
1230 /*
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
1231
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1232 %!assert (full (diag ([1; 2; 3])), [1, 0, 0; 0, 2, 0; 0, 0, 3])
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1233 %!assert (diag ([1; 2; 3], 1), [0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0])
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1234 %!assert (diag ([1; 2; 3], 2), [0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0])
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1235 %!assert (diag ([1; 2; 3],-1), [0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0])
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1236 %!assert (diag ([1; 2; 3],-2), [0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0])
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1237
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1238 %!assert (diag ([1, 0, 0; 0, 2, 0; 0, 0, 3]), [1; 2; 3])
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1239 %!assert (diag ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0], 1), [1; 2; 3])
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1240 %!assert (diag ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0], -1), [1; 2; 3])
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1241 %!assert (diag (ones (1, 0), 2), zeros (2))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1242 %!assert (diag (1:3, 4, 2), [1, 0; 0, 2; 0, 0; 0, 0])
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1243
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1244 %!assert (full (diag (single ([1; 2; 3]))), single ([1, 0, 0; 0, 2, 0; 0, 0, 3]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1245 %!assert (diag (single ([1; 2; 3]), 1), single ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1246 %!assert (diag (single ([1; 2; 3]), 2), single ([0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1247 %!assert (diag (single ([1; 2; 3]),-1), single ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1248 %!assert (diag (single ([1; 2; 3]),-2), single ([0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1249
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1250 %!assert (diag (single ([1, 0, 0; 0, 2, 0; 0, 0, 3])), single ([1; 2; 3]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1251 %!assert (diag (single ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), single ([1; 2; 3]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1252 %!assert (diag (single ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), single ([1; 2; 3]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1253
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1254 %!assert (diag (int8 ([1; 2; 3])), int8 ([1, 0, 0; 0, 2, 0; 0, 0, 3]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1255 %!assert (diag (int8 ([1; 2; 3]), 1), int8 ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1256 %!assert (diag (int8 ([1; 2; 3]), 2), int8 ([0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1257 %!assert (diag (int8 ([1; 2; 3]),-1), int8 ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1258 %!assert (diag (int8 ([1; 2; 3]),-2), int8 ([0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1259
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1260 %!assert (diag (int8 ([1, 0, 0; 0, 2, 0; 0, 0, 3])), int8 ([1; 2; 3]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1261 %!assert (diag (int8 ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), int8 ([1; 2; 3]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1262 %!assert (diag (int8 ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), int8 ([1; 2; 3]))
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
1263
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
1264 %!assert <*37411> (diag (diag ([5, 2, 3])(:,1)), diag([5 0 0 ]))
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
1265 %!assert <*37411> (diag (diag ([5, 2, 3])(:,1), 2), [0 0 5 0 0; zeros(4, 5)])
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
1266 %!assert <*37411> (diag (diag ([5, 2, 3])(:,1), -2), [[0 0 5 0 0]', zeros(5, 4)])
15428
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14567
diff changeset
1267
14490
3959f3f81e33 Initialise memory in non-square diag call (bug #35946)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14171
diff changeset
1268 ## Test non-square size
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1269 %!assert (diag ([1,2,3], 6, 3), [1 0 0; 0 2 0; 0 0 3; 0 0 0; 0 0 0; 0 0 0])
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
1270 %!assert (diag (1, 2, 3), [1,0,0; 0,0,0])
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
1271 %!assert (diag ({1}, 2, 3), {1,[],[]; [],[],[]})
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
1272 %!assert (diag ({1,2}, 3, 4), {1,[],[],[]; [],2,[],[]; [],[],[],[]})
14490
3959f3f81e33 Initialise memory in non-square diag call (bug #35946)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14171
diff changeset
1273
18146
a86d608c413c Return empty matrix rather than issuing error when requested diagonal is out of range.
Marco Caliari <marco.caliari@univr.it>
parents: 18112
diff changeset
1274 ## Test out-of-range diagonals
a86d608c413c Return empty matrix rather than issuing error when requested diagonal is out of range.
Marco Caliari <marco.caliari@univr.it>
parents: 18112
diff changeset
1275 %!assert (diag (ones (3,3), 4), zeros (0, 1))
a86d608c413c Return empty matrix rather than issuing error when requested diagonal is out of range.
Marco Caliari <marco.caliari@univr.it>
parents: 18112
diff changeset
1276 %!assert (diag (cell (3,3), 4), cell (0, 1))
a86d608c413c Return empty matrix rather than issuing error when requested diagonal is out of range.
Marco Caliari <marco.caliari@univr.it>
parents: 18112
diff changeset
1277 %!assert (diag (sparse (ones (3,3)), 4), sparse (zeros (0, 1)))
a86d608c413c Return empty matrix rather than issuing error when requested diagonal is out of range.
Marco Caliari <marco.caliari@univr.it>
parents: 18112
diff changeset
1278
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
1279 ## Test input validation
14491
5bd9e47e9277 maint: periodic merge of stable to default
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14429 14490
diff changeset
1280 %!error <Invalid call to diag> diag ()
5bd9e47e9277 maint: periodic merge of stable to default
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14429 14490
diff changeset
1281 %!error <Invalid call to diag> diag (1,2,3,4)
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1282 %!error diag (ones (2), 3, 3)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1283 %!error diag (1:3, -4, 3)
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
1284
14557
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1285 %!assert (diag (1, 3, 3), diag ([1, 0, 0]))
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1286 %!assert (diag (i, 3, 3), diag ([i, 0, 0]))
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1287 %!assert (diag (single (1), 3, 3), diag ([single(1), 0, 0]))
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1288 %!assert (diag (single (i), 3, 3), diag ([single(i), 0, 0]))
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1289 %!assert (diag ([1, 2], 3, 3), diag ([1, 2, 0]))
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1290 %!assert (diag ([1, 2]*i, 3, 3), diag ([1, 2, 0]*i))
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1291 %!assert (diag (single ([1, 2]), 3, 3), diag (single ([1, 2, 0])))
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1292 %!assert (diag (single ([1, 2]*i), 3, 3), diag (single ([1, 2, 0]*i)))
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1293 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
1294
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
1295 DEFUN (prod, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1296 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1297 @deftypefn {} {} prod (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1298 @deftypefnx {} {} prod (@var{x}, @var{dim})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1299 @deftypefnx {} {} prod (@dots{}, "native")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1300 @deftypefnx {} {} prod (@dots{}, "double")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1301 Product of elements along dimension @var{dim}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1302
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1303 If @var{dim} is omitted, it defaults to the first non-singleton dimension.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1304
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1305 The optional @qcode{"type"} input determines the class of the variable
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1306 used for calculations. If the argument @qcode{"native"} is given, then
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1307 the operation is performed in the same type as the original argument, rather
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1308 than the default double type.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1309
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1310 For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1311
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1312 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1313 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1314 prod ([true, true])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1315 @result{} 1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1316 prod ([true, true], "native")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1317 @result{} true
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1318 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1319 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1320
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1321 On the contrary, if @qcode{"double"} is given, the operation is performed
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1322 in double precision even for single precision inputs.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1323 @seealso{cumprod, sum}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1324 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1325 {
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1326 int nargin = args.length ();
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1327
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1328 bool isnative = false;
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1329 bool isdouble = false;
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1330
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1331 if (nargin > 1 && args(nargin - 1).is_string ())
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1332 {
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1333 std::string str = args(nargin - 1).string_value ();
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1334
19743
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1335 if (str == "native")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1336 isnative = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1337 else if (str == "double")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1338 isdouble = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1339 else
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1340 error ("prod: unrecognized type argument '%s'", str.c_str ());
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
1341
21062
d9c1884d1aaa maint: Eliminate space between variable and decrement '--' operator.
Rik <rik@octave.org>
parents: 21055
diff changeset
1342 nargin--;
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1343 }
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1344
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1345 if (nargin < 1 || nargin > 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1346 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1347
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
1348 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
1349
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1350 octave_value arg = args(0);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1351
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1352 int dim = -1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1353 if (nargin == 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1354 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1355 dim = args(1).int_value () - 1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1356 if (dim < 0)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1357 error ("prod: invalid dimension DIM = %d", dim + 1);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1358 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1359
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1360 switch (arg.builtin_type ())
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1361 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1362 case btyp_double:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1363 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1364 retval = arg.sparse_matrix_value ().prod (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1365 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1366 retval = arg.array_value ().prod (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1367 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1368 case btyp_complex:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1369 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1370 retval = arg.sparse_complex_matrix_value ().prod (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1371 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1372 retval = arg.complex_array_value ().prod (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1373 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1374 case btyp_float:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1375 if (isdouble)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1376 retval = arg.float_array_value ().dprod (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1377 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1378 retval = arg.float_array_value ().prod (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1379 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1380 case btyp_float_complex:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1381 if (isdouble)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1382 retval = arg.float_complex_array_value ().dprod (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1383 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1384 retval = arg.float_complex_array_value ().prod (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1385 break;
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1386
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1387 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1388 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1389 if (isnative) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1390 retval = arg.X ## _array_value ().prod (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1391 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1392 retval = arg.array_value ().prod (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1393 break;
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1394
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1395 MAKE_INT_BRANCH (int8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1396 MAKE_INT_BRANCH (int16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1397 MAKE_INT_BRANCH (int32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1398 MAKE_INT_BRANCH (int64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1399 MAKE_INT_BRANCH (uint8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1400 MAKE_INT_BRANCH (uint16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1401 MAKE_INT_BRANCH (uint32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1402 MAKE_INT_BRANCH (uint64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1403
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1404 #undef MAKE_INT_BRANCH
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1405
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1406 // GAGME: Accursed Matlab compatibility...
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1407 case btyp_char:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1408 retval = arg.array_value (true).prod (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1409 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1410
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1411 case btyp_bool:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1412 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1413 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1414 if (isnative)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1415 retval = arg.sparse_bool_matrix_value ().all (dim);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1416 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1417 retval = arg.sparse_matrix_value ().prod (dim);
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1418 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1419 else if (isnative)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1420 retval = arg.bool_array_value ().all (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1421 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1422 retval = NDArray (arg.bool_array_value ().all (dim));
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1423 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1424
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1425 default:
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
1426 err_wrong_type_arg ("prod", arg);
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1427 }
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1428
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1429 return retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1430 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1431
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1432 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1433 %!assert (prod ([1, 2, 3]), 6)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1434 %!assert (prod ([-1; -2; -3]), -6)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1435 %!assert (prod ([i, 2+i, -3+2i, 4]), -4 - 32i)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1436 %!assert (prod ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [-1+i, -8+8i, -27+27i])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1437
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1438 %!assert (prod (single ([1, 2, 3])), single (6))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1439 %!assert (prod (single ([-1; -2; -3])), single (-6))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1440 %!assert (prod (single ([i, 2+i, -3+2i, 4])), single (-4 - 32i))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1441 %!assert (prod (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single ([-1+i, -8+8i, -27+27i]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1442
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
1443 ## Test sparse
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1444 %!assert (prod (sparse ([1, 2, 3])), sparse (6))
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1445 %!assert (prod (sparse ([-1; -2; -3])), sparse (-6))
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1446 ## Commented out until bug #42290 is fixed
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1447 #%!assert (prod (sparse ([i, 2+i, -3+2i, 4])), sparse (-4 - 32i))
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1448 #%!assert (prod (sparse ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), sparse ([-1+i, -8+8i, -27+27i]))
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1449
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1450 %!assert (prod ([1, 2; 3, 4], 1), [3, 8])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1451 %!assert (prod ([1, 2; 3, 4], 2), [2; 12])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1452 %!assert (prod (zeros (1, 0)), 1)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1453 %!assert (prod (zeros (1, 0), 1), zeros (1, 0))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1454 %!assert (prod (zeros (1, 0), 2), 1)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1455 %!assert (prod (zeros (0, 1)), 1)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1456 %!assert (prod (zeros (0, 1), 1), 1)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1457 %!assert (prod (zeros (0, 1), 2), zeros (0, 1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1458 %!assert (prod (zeros (2, 0)), zeros (1, 0))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1459 %!assert (prod (zeros (2, 0), 1), zeros (1, 0))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1460 %!assert (prod (zeros (2, 0), 2), [1; 1])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1461 %!assert (prod (zeros (0, 2)), [1, 1])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1462 %!assert (prod (zeros (0, 2), 1), [1, 1])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1463 %!assert (prod (zeros (0, 2), 2), zeros (0, 1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1464
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1465 %!assert (prod (single ([1, 2; 3, 4]), 1), single ([3, 8]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1466 %!assert (prod (single ([1, 2; 3, 4]), 2), single ([2; 12]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1467 %!assert (prod (zeros (1, 0, "single")), single (1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1468 %!assert (prod (zeros (1, 0, "single"), 1), zeros (1, 0, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1469 %!assert (prod (zeros (1, 0, "single"), 2), single (1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1470 %!assert (prod (zeros (0, 1, "single")), single (1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1471 %!assert (prod (zeros (0, 1, "single"), 1), single (1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1472 %!assert (prod (zeros (0, 1, "single"), 2), zeros (0, 1, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1473 %!assert (prod (zeros (2, 0, "single")), zeros (1, 0, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1474 %!assert (prod (zeros (2, 0, "single"), 1), zeros (1, 0, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1475 %!assert (prod (zeros (2, 0, "single"), 2), single ([1; 1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1476 %!assert (prod (zeros (0, 2, "single")), single ([1, 1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1477 %!assert (prod (zeros (0, 2, "single"), 1), single ([1, 1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1478 %!assert (prod (zeros (0, 2, "single"), 2), zeros (0, 1, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1479
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
1480 ## Test "double" type argument
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1481 %!assert (prod (single ([1, 2, 3]), "double"), 6)
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1482 %!assert (prod (single ([-1; -2; -3]), "double"), -6)
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1483 %!assert (prod (single ([i, 2+i, -3+2i, 4]), "double"), -4 - 32i)
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1484 %!assert (prod (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), "double"), [-1+i, -8+8i, -27+27i])
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1485
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
1486 ## Test "native" type argument
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1487 %!assert (prod (uint8 ([1, 2, 3]), "native"), uint8 (6))
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1488 %!assert (prod (uint8 ([-1; -2; -3]), "native"), uint8 (0))
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1489 %!assert (prod (int8 ([1, 2, 3]), "native"), int8 (6))
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1490 %!assert (prod (int8 ([-1; -2; -3]), "native"), int8 (-6))
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1491 %!assert (prod ([true false; true true], "native"), [true false])
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1492 %!assert (prod ([true false; true true], 2, "native"), [false; true])
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1493
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
1494 ## Test input validation
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1495 %!error prod ()
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1496 %!error prod (1,2,3)
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1497 %!error <unrecognized type argument 'foobar'> prod (1, "foobar")
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1498 */
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1499
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1500 static bool
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1501 all_scalar_1x1 (const octave_value_list& args)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1502 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1503 int n_args = args.length ();
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1504 for (int i = 0; i < n_args; i++)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1505 if (args(i).numel () != 1)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1506 return false;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1507
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1508 return true;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1509 }
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1510
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1511 template <typename TYPE, typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1512 static void
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1513 single_type_concat (Array<T>& result,
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1514 const octave_value_list& args,
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1515 int dim)
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1516 {
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1517 int n_args = args.length ();
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1518 if (! (equal_types<T, char>::value
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1519 || equal_types<T, octave_value>::value)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1520 && all_scalar_1x1 (args))
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1521 {
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1522 // Optimize all scalars case.
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1523 dim_vector dv (1, 1);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1524 if (dim == -1 || dim == -2)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1525 dim = -dim - 1;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1526 else if (dim >= 2)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1527 dv.resize (dim+1, 1);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1528 dv(dim) = n_args;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1529
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1530 result.clear (dv);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1531
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1532 for (int j = 0; j < n_args; j++)
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1533 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1534 octave_quit ();
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1535
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1536 result(j) = octave_value_extract<T> (args(j));
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1537 }
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1538 }
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1539 else
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1540 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1541 OCTAVE_LOCAL_BUFFER (Array<T>, array_list, n_args);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1542
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1543 for (int j = 0; j < n_args; j++)
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1544 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1545 octave_quit ();
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1546
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1547 array_list[j] = octave_value_extract<TYPE> (args(j));
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1548 }
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1549
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1550 result = Array<T>::cat (dim, n_args, array_list);
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1551 }
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1552 }
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1553
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1554 template <typename TYPE, typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1555 static void
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1556 single_type_concat (Sparse<T>& result,
10498
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1557 const octave_value_list& args,
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1558 int dim)
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1559 {
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1560 int n_args = args.length ();
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1561 OCTAVE_LOCAL_BUFFER (Sparse<T>, sparse_list, n_args);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1562
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1563 for (int j = 0; j < n_args; j++)
10498
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1564 {
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1565 octave_quit ();
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1566
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1567 sparse_list[j] = octave_value_extract<TYPE> (args(j));
10498
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1568 }
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1569
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1570 result = Sparse<T>::cat (dim, n_args, sparse_list);
10498
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1571 }
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1572
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1573 // Dispatcher.
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1574 template <typename TYPE>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1575 static TYPE
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1576 do_single_type_concat (const octave_value_list& args, int dim)
10498
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1577 {
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1578 TYPE result;
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1579
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1580 single_type_concat<TYPE, typename TYPE::element_type> (result, args, dim);
10498
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1581
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1582 return result;
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1583 }
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1584
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1585 template <typename MAP>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1586 static void
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1587 single_type_concat_map (octave_map& result,
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1588 const octave_value_list& args,
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1589 int dim)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1590 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1591 int n_args = args.length ();
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1592 OCTAVE_LOCAL_BUFFER (MAP, map_list, n_args);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1593
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1594 for (int j = 0; j < n_args; j++)
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1595 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1596 octave_quit ();
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1597
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1598 map_list[j] = octave_value_extract<MAP> (args(j));
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1599 }
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1600
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1601 result = octave_map::cat (dim, n_args, map_list);
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1602 }
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1603
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1604 static octave_map
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1605 do_single_type_concat_map (const octave_value_list& args,
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1606 int dim)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1607 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1608 octave_map result;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1609 if (all_scalar_1x1 (args)) // optimize all scalars case.
10763
b397b8edd8c5 fix off-by-1 dim in scalar map horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10758
diff changeset
1610 single_type_concat_map<octave_scalar_map> (result, args, dim);
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1611 else
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1612 single_type_concat_map<octave_map> (result, args, dim);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1613
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1614 return result;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1615 }
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1616
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1617 static octave_value
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1618 attempt_type_conversion (const octave_value& ov, std::string dtype)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1619 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1620 octave_value retval;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1621
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1622 // First try to find function in the class of OV that can convert to
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1623 // the dispatch type dtype. It will have the name of the dispatch
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1624 // type.
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1625
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1626 std::string cname = ov.class_name ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1627
23693
b9378eff6d13 move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
1628 octave::symbol_table& symtab = octave::__get_symbol_table__ ("attempt_type_conversion");
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
1629
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
1630 octave_value fcn = symtab.find_method (dtype, cname);
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1631
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1632 if (fcn.is_defined ())
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1633 {
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1634 octave_value_list result;
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1635
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1636 try
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1637 {
23473
55916f99b8b6 prefer feval over do_multi_index_op
John W. Eaton <jwe@octave.org>
parents: 23462
diff changeset
1638 result = octave::feval (fcn, ovl (ov), 1);
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1639 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1640 catch (octave::execution_exception& e)
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1641 {
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20741
diff changeset
1642 error (e, "conversion from %s to %s failed", dtype.c_str (),
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1643 cname.c_str ());
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1644 }
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1645
21885
0806871e3e1e maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents: 21782
diff changeset
1646 if (result.empty ())
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1647 error ("conversion from %s to %s failed", dtype.c_str (),
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1648 cname.c_str ());
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1649
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1650 retval = result(0);
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1651 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1652 else
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1653 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1654 // No conversion function available. Try the constructor for the
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1655 // dispatch type.
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1656
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
1657 fcn = symtab.find_method (dtype, dtype);
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1658
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1659 if (! fcn.is_defined ())
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1660 error ("no constructor for %s!", dtype.c_str ());
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1661
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1662 octave_value_list result;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1663
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1664 try
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1665 {
23473
55916f99b8b6 prefer feval over do_multi_index_op
John W. Eaton <jwe@octave.org>
parents: 23462
diff changeset
1666 result = octave::feval (fcn, ovl (ov), 1);
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1667 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1668 catch (octave::execution_exception& e)
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1669 {
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1670 error (e, "%s constructor failed for %s argument", dtype.c_str (),
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1671 cname.c_str ());
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1672 }
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1673
21885
0806871e3e1e maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents: 21782
diff changeset
1674 if (result.empty ())
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1675 error ("%s constructor failed for %s argument", dtype.c_str (),
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1676 cname.c_str ());
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1677
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1678 retval = result(0);
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1679 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1680
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1681 return retval;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1682 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1683
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1684 octave_value
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1685 do_class_concat (const octave_value_list& ovl, std::string cattype, int dim)
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1686 {
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1687 octave_value retval;
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1688
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1689 // Get dominant type for list
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1690
23693
b9378eff6d13 move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
1691 std::string dtype = octave::get_dispatch_type (ovl);
b9378eff6d13 move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
1692
b9378eff6d13 move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
1693 octave::symbol_table& symtab = octave::__get_symbol_table__ ("do_class_concat");
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
1694
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
1695 octave_value fcn = symtab.find_method (cattype, dtype);
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1696
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1697 if (fcn.is_defined ())
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1698 {
20726
25d676f9619c Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents: 20720
diff changeset
1699 // Have method for dominant type. Call it and let it handle conversions.
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1700
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1701 octave_value_list tmp2;
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1702
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1703 try
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1704 {
23473
55916f99b8b6 prefer feval over do_multi_index_op
John W. Eaton <jwe@octave.org>
parents: 23462
diff changeset
1705 tmp2 = octave::feval (fcn, ovl, 1);
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1706 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1707 catch (octave::execution_exception& e)
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1708 {
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20741
diff changeset
1709 error (e, "%s/%s method failed", dtype.c_str (), cattype.c_str ());
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1710 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1711
21885
0806871e3e1e maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents: 21782
diff changeset
1712 if (tmp2.empty ())
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1713 error ("%s/%s method did not return a value", dtype.c_str (),
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1714 cattype.c_str ());
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1715
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1716 retval = tmp2(0);
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1717 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1718 else
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1719 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1720 // No method for dominant type, so attempt type conversions for
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1721 // all elements that are not of the dominant type, then do the
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1722 // default operation for octave_class values.
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1723
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1724 octave_idx_type j = 0;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1725 octave_idx_type len = ovl.length ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1726 octave_value_list tmp (len, octave_value ());
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1727 for (octave_idx_type k = 0; k < len; k++)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1728 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1729 octave_value elt = ovl(k);
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1730
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1731 std::string t1_type = elt.class_name ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1732
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1733 if (t1_type == dtype)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1734 tmp(j++) = elt;
23587
0c468af9dc00 maint: Deprecate is_object and replace with isobject.
Rik <rik@octave.org>
parents: 23586
diff changeset
1735 else if (elt.isobject () || ! elt.isempty ())
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1736 tmp(j++) = attempt_type_conversion (elt, dtype);
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1737 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1738
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1739 tmp.resize (j);
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1740
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1741 octave_map m = do_single_type_concat_map (tmp, dim);
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1742
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1743 std::string cname = tmp(0).class_name ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1744 std::list<std::string> parents = tmp(0).parent_class_name_list ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1745
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1746 retval = octave_value (new octave_class (m, cname, parents));
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1747 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1748
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1749 return retval;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1750 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1751
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1752 static octave_value
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1753 do_cat (const octave_value_list& xargs, int dim, std::string fname)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1754 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1755 octave_value retval;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1756
20811
5979314bb15a Fix BIST tests for rows.
Rik <rik@octave.org>
parents: 20810
diff changeset
1757 // We may need to convert elements of the list to cells, so make a copy.
5979314bb15a Fix BIST tests for rows.
Rik <rik@octave.org>
parents: 20810
diff changeset
1758 // This should be efficient, it is done mostly by incrementing reference
5979314bb15a Fix BIST tests for rows.
Rik <rik@octave.org>
parents: 20810
diff changeset
1759 // counts.
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1760 octave_value_list args = xargs;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1761
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1762 int n_args = args.length ();
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1763
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1764 if (n_args == 0)
5714
24f6a13878c2 [project @ 2006-03-23 21:46:09 by jwe]
jwe
parents: 5677
diff changeset
1765 retval = Matrix ();
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1766 else if (n_args == 1)
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1767 retval = args(0);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1768 else if (n_args > 1)
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1769 {
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1770 std::string result_type;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1771
19399
2304ddfd736f Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents: 18869
diff changeset
1772 bool all_strings_p = true;
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1773 bool all_sq_strings_p = true;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1774 bool all_dq_strings_p = true;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1775 bool all_real_p = true;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1776 bool all_cmplx_p = true;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1777 bool any_sparse_p = false;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1778 bool any_cell_p = false;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1779 bool any_class_p = false;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1780
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1781 bool first_elem_is_struct = false;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1782
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1783 for (int i = 0; i < n_args; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1784 {
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1785 if (i == 0)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1786 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1787 result_type = args(i).class_name ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1788
23584
7ed6b258db91 maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents: 23583
diff changeset
1789 first_elem_is_struct = args(i).isstruct ();
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1790 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1791 else
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22895
diff changeset
1792 result_type = octave::get_concat_class (result_type, args(i).class_name ());
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1793
19399
2304ddfd736f Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents: 18869
diff changeset
1794 if (all_strings_p && ! args(i).is_string ())
2304ddfd736f Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents: 18869
diff changeset
1795 all_strings_p = false;
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1796 if (all_sq_strings_p && ! args(i).is_sq_string ())
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1797 all_sq_strings_p = false;
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1798 if (all_dq_strings_p && ! args(i).is_dq_string ())
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1799 all_dq_strings_p = false;
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
1800 if (all_real_p && ! args(i).isreal ())
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1801 all_real_p = false;
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
1802 if (all_cmplx_p && ! (args(i).iscomplex ()
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
1803 || args(i).isreal ()))
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1804 all_cmplx_p = false;
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1805 if (! any_sparse_p && args(i).issparse ())
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1806 any_sparse_p = true;
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23575
diff changeset
1807 if (! any_cell_p && args(i).iscell ())
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1808 any_cell_p = true;
23587
0c468af9dc00 maint: Deprecate is_object and replace with isobject.
Rik <rik@octave.org>
parents: 23586
diff changeset
1809 if (! any_class_p && args(i).isobject ())
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1810 any_class_p = true;
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1811 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1812
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1813 if (any_cell_p && ! any_class_p && ! first_elem_is_struct)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1814 {
22895
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
1815 int j = 0;
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1816 for (int i = 0; i < n_args; i++)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1817 {
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23575
diff changeset
1818 if (args(i).iscell ())
22895
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
1819 args(j++) = args(i);
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
1820 else
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
1821 {
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
1822 if (args(i).isempty ())
22895
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
1823 continue; // Delete empty non-cell arg
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
1824 else
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
1825 args(j++) = Cell (args(i));
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
1826 }
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1827 }
22895
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
1828 n_args = j;
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
1829 args.resize (n_args);
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1830 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1831
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1832 if (any_class_p)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1833 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1834 retval = do_class_concat (args, fname, dim);
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1835 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1836 else if (result_type == "double")
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1837 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1838 if (any_sparse_p)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1839 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1840 if (all_real_p)
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1841 retval = do_single_type_concat<SparseMatrix> (args, dim);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1842 else
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1843 retval = do_single_type_concat<SparseComplexMatrix> (args, dim);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1844 }
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1845 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1846 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1847 if (all_real_p)
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1848 retval = do_single_type_concat<NDArray> (args, dim);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1849 else
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1850 retval = do_single_type_concat<ComplexNDArray> (args, dim);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1851 }
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1852 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1853 else if (result_type == "single")
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1854 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1855 if (all_real_p)
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1856 retval = do_single_type_concat<FloatNDArray> (args, dim);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1857 else
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1858 retval = do_single_type_concat<FloatComplexNDArray> (args, dim);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1859 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1860 else if (result_type == "char")
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1861 {
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
1862 char type = (all_dq_strings_p ? '"' : '\'');
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1863
19399
2304ddfd736f Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents: 18869
diff changeset
1864 if (! all_strings_p)
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
1865 warn_implicit_conversion ("Octave:num-to-str",
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
1866 "numeric", result_type);
19399
2304ddfd736f Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents: 18869
diff changeset
1867 else
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22895
diff changeset
1868 octave::maybe_warn_string_concat (all_dq_strings_p, all_sq_strings_p);
19399
2304ddfd736f Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents: 18869
diff changeset
1869
2304ddfd736f Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents: 18869
diff changeset
1870 charNDArray result = do_single_type_concat<charNDArray> (args, dim);
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1871
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1872 retval = octave_value (result, type);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1873 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1874 else if (result_type == "logical")
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1875 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1876 if (any_sparse_p)
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1877 retval = do_single_type_concat<SparseBoolMatrix> (args, dim);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1878 else
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1879 retval = do_single_type_concat<boolNDArray> (args, dim);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1880 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1881 else if (result_type == "int8")
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1882 retval = do_single_type_concat<int8NDArray> (args, dim);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1883 else if (result_type == "int16")
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1884 retval = do_single_type_concat<int16NDArray> (args, dim);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1885 else if (result_type == "int32")
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1886 retval = do_single_type_concat<int32NDArray> (args, dim);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1887 else if (result_type == "int64")
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1888 retval = do_single_type_concat<int64NDArray> (args, dim);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1889 else if (result_type == "uint8")
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1890 retval = do_single_type_concat<uint8NDArray> (args, dim);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1891 else if (result_type == "uint16")
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1892 retval = do_single_type_concat<uint16NDArray> (args, dim);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1893 else if (result_type == "uint32")
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1894 retval = do_single_type_concat<uint32NDArray> (args, dim);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1895 else if (result_type == "uint64")
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1896 retval = do_single_type_concat<uint64NDArray> (args, dim);
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1897 else if (result_type == "cell")
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1898 retval = do_single_type_concat<Cell> (args, dim);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1899 else if (result_type == "struct")
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1900 retval = do_single_type_concat_map (args, dim);
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1901 else
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1902 {
20218
b2100e1659ac maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents: 20183
diff changeset
1903 dim_vector dv = args(0).dims ();
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1904
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1905 // Default concatenation.
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1906 bool (dim_vector::*concat_rule) (const dim_vector&, int)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1907 = &dim_vector::concat;
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1908
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1909 if (dim == -1 || dim == -2)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1910 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1911 concat_rule = &dim_vector::hvcat;
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1912 dim = -dim - 1;
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1913 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1914
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1915 for (int i = 1; i < args.length (); i++)
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1916 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1917 if (! (dv.*concat_rule) (args(i).dims (), dim))
20893
384ff5aa9437 2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents: 20884
diff changeset
1918 error ("cat: dimension mismatch");
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1919 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1920
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1921 // The lines below might seem crazy, since we take a copy
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1922 // of the first argument, resize it to be empty and then resize
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21730
diff changeset
1923 // it to be full. This is done since it means that there is no
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1924 // recopying of data, as would happen if we used a single resize.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1925 // It should be noted that resize operation is also significantly
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1926 // slower than the do_cat_op function, so it makes sense to have
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1927 // an empty matrix and copy all data.
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1928 //
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1929 // We might also start with a empty octave_value using
24540
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24536
diff changeset
1930 //
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24536
diff changeset
1931 // tmp = octave::type_info::lookup_type (args(1).type_name());
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24536
diff changeset
1932 //
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21730
diff changeset
1933 // and then directly resize. However, for some types there might
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1934 // be some additional setup needed, and so this should be avoided.
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1935
18112
b560bac0fca2 maint: Don't use space between 'args' and '(' when doing indexing.
Rik <rik@octave.org>
parents: 18100
diff changeset
1936 octave_value tmp = args(0);
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1937 tmp = tmp.resize (dim_vector (0,0)).resize (dv);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1938
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21602
diff changeset
1939 int dv_len = dv.ndims ();
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1940 Array<octave_idx_type> ra_idx (dim_vector (dv_len, 1), 0);
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1941
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1942 for (int j = 0; j < n_args; j++)
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1943 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1944 // Can't fast return here to skip empty matrices as something
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14853
diff changeset
1945 // like cat (1,[],single ([])) must return an empty matrix of
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1946 // the right type.
18112
b560bac0fca2 maint: Don't use space between 'args' and '(' when doing indexing.
Rik <rik@octave.org>
parents: 18100
diff changeset
1947 tmp = do_cat_op (tmp, args(j), ra_idx);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1948
18112
b560bac0fca2 maint: Don't use space between 'args' and '(' when doing indexing.
Rik <rik@octave.org>
parents: 18100
diff changeset
1949 dim_vector dv_tmp = args(j).dims ();
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1950
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1951 if (dim >= dv_len)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1952 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1953 if (j > 1)
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1954 error ("%s: indexing error", fname.c_str ());
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
1955
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1956 break;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1957 }
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1958 else
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21602
diff changeset
1959 ra_idx(dim) += (dim < dv_tmp.ndims () ? dv_tmp(dim) : 1);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1960 }
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1961 retval = tmp;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1962 }
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1963 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1964 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
1965 print_usage ();
8113
38a797766a2a Special case single type conacation in Fcat. Rework cell2mat to take advantage
David Bateman <dbateman@free.fr>
parents: 8111
diff changeset
1966
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1967 return retval;
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1968 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1969
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1970 DEFUN (horzcat, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1971 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1972 @deftypefn {} {} horzcat (@var{array1}, @var{array2}, @dots{}, @var{arrayN})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1973 Return the horizontal concatenation of N-D array objects, @var{array1},
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1974 @var{array2}, @dots{}, @var{arrayN} along dimension 2.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1975
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1976 Arrays may also be concatenated horizontally using the syntax for creating
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1977 new matrices. For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1978
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1979 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1980 @var{hcat} = [ @var{array1}, @var{array2}, @dots{} ]
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1981 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1982 @seealso{cat, vertcat}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1983 @end deftypefn */)
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1984 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1985 return do_cat (args, -2, "horzcat");
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1986 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1987
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1988 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1989 ## Test concatenation with all zero matrices
21575
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
1990 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
1991 %! warning ("off", "Octave:num-to-str", "local");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
1992 %! assert (horzcat ("", 65*ones (1,10)), "AAAAAAAAAA");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
1993 %! assert (horzcat (65*ones (1,10), ""), "AAAAAAAAAA");
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1994
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1995 %!assert (class (horzcat (int64 (1), int64 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1996 %!assert (class (horzcat (int64 (1), int32 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1997 %!assert (class (horzcat (int64 (1), int16 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1998 %!assert (class (horzcat (int64 (1), int8 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1999 %!assert (class (horzcat (int64 (1), uint64 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2000 %!assert (class (horzcat (int64 (1), uint32 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2001 %!assert (class (horzcat (int64 (1), uint16 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2002 %!assert (class (horzcat (int64 (1), uint8 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2003 %!assert (class (horzcat (int64 (1), single (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2004 %!assert (class (horzcat (int64 (1), double (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2005 %!assert (class (horzcat (int64 (1), cell (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2006 %!assert (class (horzcat (int64 (1), true)), "int64")
21575
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2007 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2008 %! warning ("off", "Octave:num-to-str", "local");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2009 %! assert (class (horzcat (int64 (1), "a")), "char");
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2010
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2011 %!assert (class (horzcat (int32 (1), int64 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2012 %!assert (class (horzcat (int32 (1), int32 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2013 %!assert (class (horzcat (int32 (1), int16 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2014 %!assert (class (horzcat (int32 (1), int8 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2015 %!assert (class (horzcat (int32 (1), uint64 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2016 %!assert (class (horzcat (int32 (1), uint32 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2017 %!assert (class (horzcat (int32 (1), uint16 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2018 %!assert (class (horzcat (int32 (1), uint8 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2019 %!assert (class (horzcat (int32 (1), single (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2020 %!assert (class (horzcat (int32 (1), double (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2021 %!assert (class (horzcat (int32 (1), cell (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2022 %!assert (class (horzcat (int32 (1), true)), "int32")
21575
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2023 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2024 %! warning ("off", "Octave:num-to-str", "local");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2025 %! assert (class (horzcat (int32 (1), "a")), "char");
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2026
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2027 %!assert (class (horzcat (int16 (1), int64 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2028 %!assert (class (horzcat (int16 (1), int32 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2029 %!assert (class (horzcat (int16 (1), int16 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2030 %!assert (class (horzcat (int16 (1), int8 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2031 %!assert (class (horzcat (int16 (1), uint64 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2032 %!assert (class (horzcat (int16 (1), uint32 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2033 %!assert (class (horzcat (int16 (1), uint16 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2034 %!assert (class (horzcat (int16 (1), uint8 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2035 %!assert (class (horzcat (int16 (1), single (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2036 %!assert (class (horzcat (int16 (1), double (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2037 %!assert (class (horzcat (int16 (1), cell (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2038 %!assert (class (horzcat (int16 (1), true)), "int16")
21575
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2039 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2040 %! warning ("off", "Octave:num-to-str", "local");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2041 %! assert (class (horzcat (int16 (1), "a")), "char");
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2042
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2043 %!assert (class (horzcat (int8 (1), int64 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2044 %!assert (class (horzcat (int8 (1), int32 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2045 %!assert (class (horzcat (int8 (1), int16 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2046 %!assert (class (horzcat (int8 (1), int8 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2047 %!assert (class (horzcat (int8 (1), uint64 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2048 %!assert (class (horzcat (int8 (1), uint32 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2049 %!assert (class (horzcat (int8 (1), uint16 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2050 %!assert (class (horzcat (int8 (1), uint8 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2051 %!assert (class (horzcat (int8 (1), single (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2052 %!assert (class (horzcat (int8 (1), double (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2053 %!assert (class (horzcat (int8 (1), cell (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2054 %!assert (class (horzcat (int8 (1), true)), "int8")
21575
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2055 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2056 %! warning ("off", "Octave:num-to-str", "local");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2057 %! assert (class (horzcat (int8 (1), "a")), "char");
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2058
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2059 %!assert (class (horzcat (uint64 (1), int64 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2060 %!assert (class (horzcat (uint64 (1), int32 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2061 %!assert (class (horzcat (uint64 (1), int16 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2062 %!assert (class (horzcat (uint64 (1), int8 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2063 %!assert (class (horzcat (uint64 (1), uint64 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2064 %!assert (class (horzcat (uint64 (1), uint32 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2065 %!assert (class (horzcat (uint64 (1), uint16 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2066 %!assert (class (horzcat (uint64 (1), uint8 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2067 %!assert (class (horzcat (uint64 (1), single (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2068 %!assert (class (horzcat (uint64 (1), double (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2069 %!assert (class (horzcat (uint64 (1), cell (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2070 %!assert (class (horzcat (uint64 (1), true)), "uint64")
21575
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2071 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2072 %! warning ("off", "Octave:num-to-str", "local");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2073 %! assert (class (horzcat (uint64 (1), "a")), "char");
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2074
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2075 %!assert (class (horzcat (uint32 (1), int64 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2076 %!assert (class (horzcat (uint32 (1), int32 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2077 %!assert (class (horzcat (uint32 (1), int16 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2078 %!assert (class (horzcat (uint32 (1), int8 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2079 %!assert (class (horzcat (uint32 (1), uint64 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2080 %!assert (class (horzcat (uint32 (1), uint32 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2081 %!assert (class (horzcat (uint32 (1), uint16 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2082 %!assert (class (horzcat (uint32 (1), uint8 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2083 %!assert (class (horzcat (uint32 (1), single (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2084 %!assert (class (horzcat (uint32 (1), double (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2085 %!assert (class (horzcat (uint32 (1), cell (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2086 %!assert (class (horzcat (uint32 (1), true)), "uint32")
21575
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2087 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2088 %! warning ("off", "Octave:num-to-str", "local");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2089 %! assert (class (horzcat (uint32 (1), "a")), "char");
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2090
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2091 %!assert (class (horzcat (uint16 (1), int64 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2092 %!assert (class (horzcat (uint16 (1), int32 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2093 %!assert (class (horzcat (uint16 (1), int16 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2094 %!assert (class (horzcat (uint16 (1), int8 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2095 %!assert (class (horzcat (uint16 (1), uint64 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2096 %!assert (class (horzcat (uint16 (1), uint32 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2097 %!assert (class (horzcat (uint16 (1), uint16 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2098 %!assert (class (horzcat (uint16 (1), uint8 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2099 %!assert (class (horzcat (uint16 (1), single (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2100 %!assert (class (horzcat (uint16 (1), double (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2101 %!assert (class (horzcat (uint16 (1), cell (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2102 %!assert (class (horzcat (uint16 (1), true)), "uint16")
21575
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2103 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2104 %! warning ("off", "Octave:num-to-str", "local");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2105 %! assert (class (horzcat (uint16 (1), "a")), "char");
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2106
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2107 %!assert (class (horzcat (uint8 (1), int64 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2108 %!assert (class (horzcat (uint8 (1), int32 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2109 %!assert (class (horzcat (uint8 (1), int16 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2110 %!assert (class (horzcat (uint8 (1), int8 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2111 %!assert (class (horzcat (uint8 (1), uint64 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2112 %!assert (class (horzcat (uint8 (1), uint32 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2113 %!assert (class (horzcat (uint8 (1), uint16 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2114 %!assert (class (horzcat (uint8 (1), uint8 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2115 %!assert (class (horzcat (uint8 (1), single (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2116 %!assert (class (horzcat (uint8 (1), double (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2117 %!assert (class (horzcat (uint8 (1), cell (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2118 %!assert (class (horzcat (uint8 (1), true)), "uint8")
21575
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2119 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2120 %! warning ("off", "Octave:num-to-str", "local");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2121 %! assert (class (horzcat (uint8 (1), "a")), "char");
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2122
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2123 %!assert (class (horzcat (single (1), int64 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2124 %!assert (class (horzcat (single (1), int32 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2125 %!assert (class (horzcat (single (1), int16 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2126 %!assert (class (horzcat (single (1), int8 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2127 %!assert (class (horzcat (single (1), uint64 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2128 %!assert (class (horzcat (single (1), uint32 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2129 %!assert (class (horzcat (single (1), uint16 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2130 %!assert (class (horzcat (single (1), uint8 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2131 %!assert (class (horzcat (single (1), single (1))), "single")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2132 %!assert (class (horzcat (single (1), double (1))), "single")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2133 %!assert (class (horzcat (single (1), cell (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2134 %!assert (class (horzcat (single (1), true)), "single")
21575
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2135 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2136 %! warning ("off", "Octave:num-to-str", "local");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2137 %! assert (class (horzcat (single (1), "a")), "char");
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2138
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2139 %!assert (class (horzcat (double (1), int64 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2140 %!assert (class (horzcat (double (1), int32 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2141 %!assert (class (horzcat (double (1), int16 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2142 %!assert (class (horzcat (double (1), int8 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2143 %!assert (class (horzcat (double (1), uint64 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2144 %!assert (class (horzcat (double (1), uint32 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2145 %!assert (class (horzcat (double (1), uint16 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2146 %!assert (class (horzcat (double (1), uint8 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2147 %!assert (class (horzcat (double (1), single (1))), "single")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2148 %!assert (class (horzcat (double (1), double (1))), "double")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2149 %!assert (class (horzcat (double (1), cell (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2150 %!assert (class (horzcat (double (1), true)), "double")
21575
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2151 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2152 %! warning ("off", "Octave:num-to-str", "local");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2153 %! assert (class (horzcat (double (1), "a")), "char");
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2154
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2155 %!assert (class (horzcat (cell (1), int64 (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2156 %!assert (class (horzcat (cell (1), int32 (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2157 %!assert (class (horzcat (cell (1), int16 (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2158 %!assert (class (horzcat (cell (1), int8 (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2159 %!assert (class (horzcat (cell (1), uint64 (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2160 %!assert (class (horzcat (cell (1), uint32 (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2161 %!assert (class (horzcat (cell (1), uint16 (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2162 %!assert (class (horzcat (cell (1), uint8 (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2163 %!assert (class (horzcat (cell (1), single (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2164 %!assert (class (horzcat (cell (1), double (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2165 %!assert (class (horzcat (cell (1), cell (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2166 %!assert (class (horzcat (cell (1), true)), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2167 %!assert (class (horzcat (cell (1), "a")), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2168
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2169 %!assert (class (horzcat (true, int64 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2170 %!assert (class (horzcat (true, int32 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2171 %!assert (class (horzcat (true, int16 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2172 %!assert (class (horzcat (true, int8 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2173 %!assert (class (horzcat (true, uint64 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2174 %!assert (class (horzcat (true, uint32 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2175 %!assert (class (horzcat (true, uint16 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2176 %!assert (class (horzcat (true, uint8 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2177 %!assert (class (horzcat (true, single (1))), "single")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2178 %!assert (class (horzcat (true, double (1))), "double")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2179 %!assert (class (horzcat (true, cell (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2180 %!assert (class (horzcat (true, true)), "logical")
21575
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2181 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2182 %! warning ("off", "Octave:num-to-str", "local");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2183 %! assert (class (horzcat (true, "a")), "char");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2184
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2185 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2186 %! warning ("off", "Octave:num-to-str", "local");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2187 %! assert (class (horzcat ("a", int64 (1))), "char");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2188 %! assert (class (horzcat ("a", int32 (1))), "char");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2189 %! assert (class (horzcat ("a", int16 (1))), "char");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2190 %! assert (class (horzcat ("a", int8 (1))), "char");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2191 %! assert (class (horzcat ("a", int64 (1))), "char");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2192 %! assert (class (horzcat ("a", int32 (1))), "char");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2193 %! assert (class (horzcat ("a", int16 (1))), "char");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2194 %! assert (class (horzcat ("a", int8 (1))), "char");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2195 %! assert (class (horzcat ("a", single (1))), "char");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2196 %! assert (class (horzcat ("a", double (1))), "char");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2197 %! assert (class (horzcat ("a", cell (1))), "cell");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2198 %! assert (class (horzcat ("a", true)), "char");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2199 %! assert (class (horzcat ("a", "a")), "char");
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2200
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2201 %!assert (class (horzcat (cell (1), struct ("foo", "bar"))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2202
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2203 %!error horzcat (struct ("foo", "bar"), cell (1))
23515
4d7928872999 Fix concatenation of a struct with an empty cell array (bug #39041)
Mike Miller <mtmiller@octave.org>
parents: 23473
diff changeset
2204
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
2205 %!test <*39041> assert (class (horzcat (cell(0), struct())), "cell")
23515
4d7928872999 Fix concatenation of a struct with an empty cell array (bug #39041)
Mike Miller <mtmiller@octave.org>
parents: 23473
diff changeset
2206 %!test <51086> assert (class (horzcat (struct(), cell(0))), "struct")
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2207 */
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2208
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2209 DEFUN (vertcat, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2210 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2211 @deftypefn {} {} vertcat (@var{array1}, @var{array2}, @dots{}, @var{arrayN})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2212 Return the vertical concatenation of N-D array objects, @var{array1},
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2213 @var{array2}, @dots{}, @var{arrayN} along dimension 1.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2214
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2215 Arrays may also be concatenated vertically using the syntax for creating
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2216 new matrices. For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2217
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2218 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2219 @var{vcat} = [ @var{array1}; @var{array2}; @dots{} ]
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2220 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2221 @seealso{cat, horzcat}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2222 @end deftypefn */)
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2223 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2224 return do_cat (args, -1, "vertcat");
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2225 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2226
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2227 /*
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2228 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2229 %! c = {"foo"; "bar"; "bazoloa"};
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2230 %! assert (vertcat (c, "a", "bc", "def"), {"foo"; "bar"; "bazoloa"; "a"; "bc"; "def"});
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2231 */
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2232
4758
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2233 DEFUN (cat, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2234 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2235 @deftypefn {} {} cat (@var{dim}, @var{array1}, @var{array2}, @dots{}, @var{arrayN})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2236 Return the concatenation of N-D array objects, @var{array1},
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2237 @var{array2}, @dots{}, @var{arrayN} along dimension @var{dim}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2238
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2239 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2240 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2241 A = ones (2, 2);
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2242 B = zeros (2, 2);
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2243 cat (2, A, B)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2244 @result{} 1 1 0 0
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2245 1 1 0 0
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2246 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2247 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2248
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2249 Alternatively, we can concatenate @var{A} and @var{B} along the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2250 second dimension in the following way:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2251
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2252 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2253 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2254 [A, B]
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2255 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2256 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2257
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2258 @var{dim} can be larger than the dimensions of the N-D array objects
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2259 and the result will thus have @var{dim} dimensions as the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2260 following example shows:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2261
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2262 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2263 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2264 cat (4, ones (2, 2), zeros (2, 2))
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2265 @result{} ans(:,:,1,1) =
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2266
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2267 1 1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2268 1 1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2269
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2270 ans(:,:,1,2) =
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2271
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2272 0 0
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2273 0 0
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2274 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2275 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2276 @seealso{horzcat, vertcat}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2277 @end deftypefn */)
4758
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2278 {
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2279 if (args.length () == 0)
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2280 print_usage ();
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2281
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2282 int dim = args(0).xint_value ("cat: DIM must be an integer") - 1;
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2283
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2284 if (dim < 0)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2285 error ("cat: DIM must be a valid dimension");
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2286
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
2287 return ovl (do_cat (args.slice (1, args.length () - 1), dim, "cat"));
4758
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2288 }
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2289
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
2290 /*
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2291 %!function ret = __testcat (t1, t2, tr, cmplx)
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
2292 %! assert (cat (1, cast ([], t1), cast ([], t2)), cast ([], tr));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2293 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2294 %! assert (cat (1, cast (1, t1), cast (2, t2)), cast ([1; 2], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2295 %! assert (cat (1, cast (1, t1), cast ([2; 3], t2)), cast ([1; 2; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2296 %! assert (cat (1, cast ([1; 2], t1), cast (3, t2)), cast ([1; 2; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2297 %! assert (cat (1, cast ([1; 2], t1), cast ([3; 4], t2)), cast ([1; 2; 3; 4], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2298 %! assert (cat (2, cast (1, t1), cast (2, t2)), cast ([1, 2], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2299 %! assert (cat (2, cast (1, t1), cast ([2, 3], t2)), cast ([1, 2, 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2300 %! assert (cat (2, cast ([1, 2], t1), cast (3, t2)), cast ([1, 2, 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2301 %! assert (cat (2, cast ([1, 2], t1), cast ([3, 4], t2)), cast ([1, 2, 3, 4], tr));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2302 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2303 %! assert ([cast(1, t1); cast(2, t2)], cast ([1; 2], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2304 %! assert ([cast(1, t1); cast([2; 3], t2)], cast ([1; 2; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2305 %! assert ([cast([1; 2], t1); cast(3, t2)], cast ([1; 2; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2306 %! assert ([cast([1; 2], t1); cast([3; 4], t2)], cast ([1; 2; 3; 4], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2307 %! assert ([cast(1, t1), cast(2, t2)], cast ([1, 2], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2308 %! assert ([cast(1, t1), cast([2, 3], t2)], cast ([1, 2, 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2309 %! assert ([cast([1, 2], t1), cast(3, t2)], cast ([1, 2, 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2310 %! assert ([cast([1, 2], t1), cast([3, 4], t2)], cast ([1, 2, 3, 4], tr));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2311 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2312 %! if (nargin == 3 || cmplx)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2313 %! assert (cat (1, cast (1i, t1), cast (2, t2)), cast ([1i; 2], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2314 %! assert (cat (1, cast (1i, t1), cast ([2; 3], t2)), cast ([1i; 2; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2315 %! assert (cat (1, cast ([1i; 2], t1), cast (3, t2)), cast ([1i; 2; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2316 %! assert (cat (1, cast ([1i; 2], t1), cast ([3; 4], t2)), cast ([1i; 2; 3; 4], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2317 %! assert (cat (2, cast (1i, t1), cast (2, t2)), cast ([1i, 2], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2318 %! assert (cat (2, cast (1i, t1), cast ([2, 3], t2)), cast ([1i, 2, 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2319 %! assert (cat (2, cast ([1i, 2], t1), cast (3, t2)), cast ([1i, 2, 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2320 %! assert (cat (2, cast ([1i, 2], t1), cast ([3, 4], t2)), cast ([1i, 2, 3, 4], tr));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2321 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2322 %! assert ([cast(1i, t1); cast(2, t2)], cast ([1i; 2], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2323 %! assert ([cast(1i, t1); cast([2; 3], t2)], cast ([1i; 2; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2324 %! assert ([cast([1i; 2], t1); cast(3, t2)], cast ([1i; 2; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2325 %! assert ([cast([1i; 2], t1); cast([3; 4], t2)], cast ([1i; 2; 3; 4], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2326 %! assert ([cast(1i, t1), cast(2, t2)], cast ([1i, 2], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2327 %! assert ([cast(1i, t1), cast([2, 3], t2)], cast ([1i, 2, 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2328 %! assert ([cast([1i, 2], t1), cast(3, t2)], cast ([1i, 2, 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2329 %! assert ([cast([1i, 2], t1), cast([3, 4], t2)], cast ([1i, 2, 3, 4], tr));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2330 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2331 %! assert (cat (1, cast (1, t1), cast (2i, t2)), cast ([1; 2i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2332 %! assert (cat (1, cast (1, t1), cast ([2i; 3], t2)), cast ([1; 2i; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2333 %! assert (cat (1, cast ([1; 2], t1), cast (3i, t2)), cast ([1; 2; 3i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2334 %! assert (cat (1, cast ([1; 2], t1), cast ([3i; 4], t2)), cast ([1; 2; 3i; 4], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2335 %! assert (cat (2, cast (1, t1), cast (2i, t2)), cast ([1, 2i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2336 %! assert (cat (2, cast (1, t1), cast ([2i, 3], t2)), cast ([1, 2i, 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2337 %! assert (cat (2, cast ([1, 2], t1), cast (3i, t2)), cast ([1, 2, 3i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2338 %! assert (cat (2, cast ([1, 2], t1), cast ([3i, 4], t2)), cast ([1, 2, 3i, 4], tr));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2339 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2340 %! assert ([cast(1, t1); cast(2i, t2)], cast ([1; 2i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2341 %! assert ([cast(1, t1); cast([2i; 3], t2)], cast ([1; 2i; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2342 %! assert ([cast([1; 2], t1); cast(3i, t2)], cast ([1; 2; 3i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2343 %! assert ([cast([1; 2], t1); cast([3i; 4], t2)], cast ([1; 2; 3i; 4], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2344 %! assert ([cast(1, t1), cast(2i, t2)], cast ([1, 2i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2345 %! assert ([cast(1, t1), cast([2i, 3], t2)], cast ([1, 2i, 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2346 %! assert ([cast([1, 2], t1), cast(3i, t2)], cast ([1, 2, 3i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2347 %! assert ([cast([1, 2], t1), cast([3i, 4], t2)], cast ([1, 2, 3i, 4], tr));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2348 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2349 %! assert (cat (1, cast (1i, t1), cast (2i, t2)), cast ([1i; 2i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2350 %! assert (cat (1, cast (1i, t1), cast ([2i; 3], t2)), cast ([1i; 2i; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2351 %! assert (cat (1, cast ([1i; 2], t1), cast (3i, t2)), cast ([1i; 2; 3i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2352 %! assert (cat (1, cast ([1i; 2], t1), cast ([3i; 4], t2)), cast ([1i; 2; 3i; 4], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2353 %! assert (cat (2, cast (1i, t1), cast (2i, t2)), cast ([1i, 2i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2354 %! assert (cat (2, cast (1i, t1), cast ([2i, 3], t2)), cast ([1i, 2i, 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2355 %! assert (cat (2, cast ([1i, 2], t1), cast (3i, t2)), cast ([1i, 2, 3i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2356 %! assert (cat (2, cast ([1i, 2], t1), cast ([3i, 4], t2)), cast ([1i, 2, 3i, 4], tr));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2357 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2358 %! assert ([cast(1i, t1); cast(2i, t2)], cast ([1i; 2i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2359 %! assert ([cast(1i, t1); cast([2i; 3], t2)], cast ([1i; 2i; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2360 %! assert ([cast([1i; 2], t1); cast(3i, t2)], cast ([1i; 2; 3i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2361 %! assert ([cast([1i; 2], t1); cast([3i; 4], t2)], cast ([1i; 2; 3i; 4], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2362 %! assert ([cast(1i, t1), cast(2i, t2)], cast ([1i, 2i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2363 %! assert ([cast(1i, t1), cast([2i, 3], t2)], cast ([1i, 2i, 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2364 %! assert ([cast([1i, 2], t1), cast(3i, t2)], cast ([1i, 2, 3i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2365 %! assert ([cast([1i, 2], t1), cast([3i, 4], t2)], cast ([1i, 2, 3i, 4], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2366 %! endif
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2367 %! ret = true;
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2368 %!endfunction
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2369
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2370 %!assert (__testcat ("double", "double", "double"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2371 %!assert (__testcat ("single", "double", "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2372 %!assert (__testcat ("double", "single", "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2373 %!assert (__testcat ("single", "single", "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2374
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2375 %!assert (__testcat ("double", "int8", "int8", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2376 %!assert (__testcat ("int8", "double", "int8", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2377 %!assert (__testcat ("single", "int8", "int8", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2378 %!assert (__testcat ("int8", "single", "int8", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2379 %!assert (__testcat ("int8", "int8", "int8", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2380 %!assert (__testcat ("double", "int16", "int16", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2381 %!assert (__testcat ("int16", "double", "int16", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2382 %!assert (__testcat ("single", "int16", "int16", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2383 %!assert (__testcat ("int16", "single", "int16", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2384 %!assert (__testcat ("int16", "int16", "int16", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2385 %!assert (__testcat ("double", "int32", "int32", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2386 %!assert (__testcat ("int32", "double", "int32", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2387 %!assert (__testcat ("single", "int32", "int32", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2388 %!assert (__testcat ("int32", "single", "int32", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2389 %!assert (__testcat ("int32", "int32", "int32", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2390 %!assert (__testcat ("double", "int64", "int64", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2391 %!assert (__testcat ("int64", "double", "int64", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2392 %!assert (__testcat ("single", "int64", "int64", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2393 %!assert (__testcat ("int64", "single", "int64", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2394 %!assert (__testcat ("int64", "int64", "int64", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2395
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2396 %!assert (__testcat ("double", "uint8", "uint8", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2397 %!assert (__testcat ("uint8", "double", "uint8", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2398 %!assert (__testcat ("single", "uint8", "uint8", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2399 %!assert (__testcat ("uint8", "single", "uint8", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2400 %!assert (__testcat ("uint8", "uint8", "uint8", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2401 %!assert (__testcat ("double", "uint16", "uint16", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2402 %!assert (__testcat ("uint16", "double", "uint16", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2403 %!assert (__testcat ("single", "uint16", "uint16", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2404 %!assert (__testcat ("uint16", "single", "uint16", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2405 %!assert (__testcat ("uint16", "uint16", "uint16", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2406 %!assert (__testcat ("double", "uint32", "uint32", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2407 %!assert (__testcat ("uint32", "double", "uint32", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2408 %!assert (__testcat ("single", "uint32", "uint32", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2409 %!assert (__testcat ("uint32", "single", "uint32", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2410 %!assert (__testcat ("uint32", "uint32", "uint32", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2411 %!assert (__testcat ("double", "uint64", "uint64", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2412 %!assert (__testcat ("uint64", "double", "uint64", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2413 %!assert (__testcat ("single", "uint64", "uint64", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2414 %!assert (__testcat ("uint64", "single", "uint64", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2415 %!assert (__testcat ("uint64", "uint64", "uint64", false))
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2416
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2417 %!assert (cat (3, [], [1,2;3,4]), [1,2;3,4])
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2418 %!assert (cat (3, [1,2;3,4], []), [1,2;3,4])
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2419 %!assert (cat (3, [], [1,2;3,4], []), [1,2;3,4])
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2420 %!assert (cat (3, [], [], []), zeros (0, 0, 3))
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2421
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2422 %!assert (cat (3, [], [], 1, 2), cat (3, 1, 2))
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2423 %!assert (cat (3, [], [], [1,2;3,4]), [1,2;3,4])
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2424 %!assert (cat (4, [], [], [1,2;3,4]), [1,2;3,4])
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2425
18678
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18676
diff changeset
2426 %!assert ([zeros(3,2,2); ones(1,2,2)], repmat ([0;0;0;1],[1,2,2]))
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18676
diff changeset
2427 %!assert ([zeros(3,2,2); ones(1,2,2)], vertcat (zeros (3,2,2), ones (1,2,2)))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2428
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
2429 %!test <*49759>
22895
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
2430 %! A = [];
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
2431 %! B = {1; 2};
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
2432 %! assert (cat (1, A, B), {1; 2});
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
2433 %! assert (cat (2, A, B), {1; 2});
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
2434
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2435 %!error <dimension mismatch> cat (3, cat (3, [], []), [1,2;3,4])
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2436 %!error <dimension mismatch> cat (3, zeros (0, 0, 2), [1,2;3,4])
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
2437 */
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
2438
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2439 static octave_value
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6953
diff changeset
2440 do_permute (const octave_value_list& args, bool inv)
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2441 {
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2442 if (args.length () != 2 || args(1).length () < args(1).ndims ())
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2443 print_usage ();
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2444
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2445 Array<int> vec = args(1).int_vector_value ();
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2446
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2447 // FIXME: maybe we should create an idx_vector object here
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2448 // and pass that to permute?
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2449 int n = vec.numel ();
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2450 for (int i = 0; i < n; i++)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2451 vec(i)--;
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2452
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2453 return octave_value (args(0).permute (vec, inv));
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2454 }
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2455
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2456 DEFUN (permute, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2457 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2458 @deftypefn {} {} permute (@var{A}, @var{perm})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2459 Return the generalized transpose for an N-D array object @var{A}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2460
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2461 The permutation vector @var{perm} must contain the elements
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2462 @w{@code{1:ndims (A)}} (in any order, but each element must appear only
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2463 once). The @var{N}th dimension of @var{A} gets remapped to dimension
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2464 @code{@var{PERM}(@var{N})}. For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2465
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2466 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2467 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2468 @var{x} = zeros ([2, 3, 5, 7]);
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2469 size (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2470 @result{} 2 3 5 7
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2471
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2472 size (permute (@var{x}, [2, 1, 3, 4]))
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2473 @result{} 3 2 5 7
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2474
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2475 size (permute (@var{x}, [1, 3, 4, 2]))
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2476 @result{} 2 5 7 3
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2477
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2478 ## The identity permutation
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2479 size (permute (@var{x}, [1, 2, 3, 4]))
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2480 @result{} 2 3 5 7
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2481 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2482 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2483 @seealso{ipermute}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2484 @end deftypefn */)
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2485 {
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6953
diff changeset
2486 return do_permute (args, false);
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2487 }
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2488
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2489 DEFUN (ipermute, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2490 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2491 @deftypefn {} {} ipermute (@var{A}, @var{iperm})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2492 The inverse of the @code{permute} function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2493
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2494 The expression
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2495
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2496 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2497 ipermute (permute (A, perm), perm)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2498 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2499
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2500 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2501 returns the original array @var{A}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2502 @seealso{permute}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2503 @end deftypefn */)
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2504 {
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6953
diff changeset
2505 return do_permute (args, true);
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2506 }
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2507
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2508 DEFUN (length, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2509 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2510 @deftypefn {} {} length (@var{a})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2511 Return the length of the object @var{a}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2512
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2513 The length is 0 for empty objects, 1 for scalars, and the number of elements
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2514 for vectors. For matrix or N-dimensional objects, the length is the number
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2515 of elements along the largest dimension
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2516 (equivalent to @w{@code{max (size (@var{a}))}}).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2517 @seealso{numel, size}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2518 @end deftypefn */)
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2519 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2520 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2521 print_usage ();
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2522
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
2523 return ovl (args(0).length ());
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2524 }
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2525
4554
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2526 DEFUN (ndims, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2527 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2528 @deftypefn {} {} ndims (@var{a})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2529 Return the number of dimensions of @var{a}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2530
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2531 For any array, the result will always be greater than or equal to 2.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2532 Trailing singleton dimensions are not counted.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2533
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2534 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2535 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2536 ndims (ones (4, 1, 2, 1))
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2537 @result{} 3
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2538 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2539 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2540 @seealso{size}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2541 @end deftypefn */)
4554
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2542 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2543 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2544 print_usage ();
4554
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2545
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
2546 return ovl (args(0).ndims ());
4554
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2547 }
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2548
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2549 DEFUN (numel, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2550 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2551 @deftypefn {} {} numel (@var{a})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2552 @deftypefnx {} {} numel (@var{a}, @var{idx1}, @var{idx2}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2553 Return the number of elements in the object @var{a}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2554
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2555 Optionally, if indices @var{idx1}, @var{idx2}, @dots{} are supplied,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2556 return the number of elements that would result from the indexing
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2557
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2558 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2559 @var{a}(@var{idx1}, @var{idx2}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2560 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2561
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2562 Note that the indices do not have to be scalar numbers. For example,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2563
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2564 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2565 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2566 @var{a} = 1;
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2567 @var{b} = ones (2, 3);
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2568 numel (@var{a}, @var{b})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2569 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2570 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2571
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2572 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2573 will return 6, as this is the number of ways to index with @var{b}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2574 Or the index could be the string @qcode{":"} which represents the colon
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2575 operator. For example,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2576
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2577 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2578 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2579 @var{a} = ones (5, 3);
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2580 numel (@var{a}, 2, ":")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2581 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2582 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2583
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2584 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2585 will return 3 as the second row has three column entries.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2586
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2587 This method is also called when an object appears as lvalue with cs-list
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2588 indexing, i.e., @code{object@{@dots{}@}} or @code{object(@dots{}).field}.
22429
00986ee43956 doc: Add more @seealso links to numel, size, size_equal.
Rik <rik@octave.org>
parents: 22407
diff changeset
2589 @seealso{size, length, ndims}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2590 @end deftypefn */)
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2591 {
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2592 int nargin = args.length ();
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2593
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2594 if (nargin == 0)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2595 print_usage ();
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2596
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2597 octave_value retval;
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
2598
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2599 if (nargin == 1)
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2600 retval = args(0).numel ();
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2601 else if (nargin > 1)
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2602 {
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2603 // Don't use numel (const octave_value_list&) here as that corresponds to
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2604 // an overloaded call, not to builtin!
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2605 retval = dims_to_numel (args(0).dims (), args.slice (1, nargin-1));
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2606 }
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2607
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2608 return retval;
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2609 }
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2610
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
2611 DEFUN (size, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2612 doc: /* -*- texinfo -*-
22699
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2613 @deftypefn {} {@var{sz} =} size (@var{a})
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2614 @deftypefnx {} {@var{dim_sz} =} size (@var{a}, @var{dim})
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2615 @deftypefnx {} {[@var{rows}, @var{cols}, @dots{}, @var{dim_N_sz}] =} size (@dots{})
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2616 Return a row vector with the size (number of elements) of each dimension for
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2617 the object @var{a}.
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2618
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2619 When given a second argument, @var{dim}, return the size of the corresponding
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2620 dimension.
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2621
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2622 With a single output argument, @code{size} returns a row vector. When called
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2623 with multiple output arguments, @code{size} returns the size of dimension N
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2624 in the Nth argument. The number of rows, dimension 1, is returned in the
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2625 first argument, the number of columns, dimension 2, is returned in the
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2626 second argument, etc. If there are more dimensions in @var{a} then there are
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2627 output arguments, @code{size} returns the total number of elements in the
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2628 remaining dimensions in the final output argument.
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2629
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2630 Example 1: single row vector output
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2631
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2632 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2633 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2634 size ([1, 2; 3, 4; 5, 6])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2635 @result{} [ 3, 2 ]
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2636 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2637 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2638
22699
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2639 Example 2: number of elements in 2nd dimension (columns)
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2640
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2641 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2642 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2643 size ([1, 2; 3, 4; 5, 6], 2)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2644 @result{} 2
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2645 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2646 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2647
22699
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2648 Example 3: number of output arguments == number of dimensions
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2649
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2650 @example
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2651 @group
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2652 [nr, nc] = size ([1, 2; 3, 4; 5, 6])
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2653 @result{} nr = 3
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2654 @result{} nc = 2
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2655 @end group
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2656 @end example
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2657
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2658 Example 4: number of output arguments != number of dimensions
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2659
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2660 @example
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2661 @group
22845
e23f7f47d8a3 doc: Small fixes to docstrings (bug #49733).
Rik <rik@octave.org>
parents: 22827
diff changeset
2662 [nr, remainder] = size (ones (2, 3, 4, 5))
22699
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2663 @result{} nr = 2
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2664 @result{} remainder = 60
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2665 @end group
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2666 @end example
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2667
22429
00986ee43956 doc: Add more @seealso links to numel, size, size_equal.
Rik <rik@octave.org>
parents: 22407
diff changeset
2668 @seealso{numel, ndims, length, rows, columns, size_equal, common_size}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2669 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2670 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 1996
diff changeset
2671 octave_value_list retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2672
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2673 int nargin = args.length ();
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2674
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
2675 if (nargin == 1)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2676 {
9706
71160b139b07 simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents: 9705
diff changeset
2677 const dim_vector dimensions = args(0).dims ();
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
2678
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
2679 if (nargout > 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2680 {
9706
71160b139b07 simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents: 9705
diff changeset
2681 const dim_vector rdims = dimensions.redim (nargout);
71160b139b07 simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents: 9705
diff changeset
2682 retval.resize (nargout);
71160b139b07 simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents: 9705
diff changeset
2683 for (int i = 0; i < nargout; i++)
71160b139b07 simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents: 9705
diff changeset
2684 retval(i) = rdims(i);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2685 }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
2686 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2687 {
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21602
diff changeset
2688 int ndims = dimensions.ndims ();
9706
71160b139b07 simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents: 9705
diff changeset
2689
71160b139b07 simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents: 9705
diff changeset
2690 NoAlias<Matrix> m (1, ndims);
71160b139b07 simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents: 9705
diff changeset
2691
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2692 for (int i = 0; i < ndims; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2693 m(i) = dimensions(i);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2694
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2695 retval(0) = m;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2696 }
1031
59f5eb2d5eb3 [project @ 1995-01-15 21:11:11 by jwe]
jwe
parents: 1009
diff changeset
2697 }
59f5eb2d5eb3 [project @ 1995-01-15 21:11:11 by jwe]
jwe
parents: 1009
diff changeset
2698 else if (nargin == 2 && nargout < 2)
59f5eb2d5eb3 [project @ 1995-01-15 21:11:11 by jwe]
jwe
parents: 1009
diff changeset
2699 {
22021
e67ff2b11147 Check that second argument to size () is a scalar (bug #48368).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21966
diff changeset
2700 if (! args(1).is_real_scalar ())
e67ff2b11147 Check that second argument to size () is a scalar (bug #48368).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21966
diff changeset
2701 error ("size: DIM must be a positive integer");
e67ff2b11147 Check that second argument to size () is a scalar (bug #48368).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21966
diff changeset
2702
e67ff2b11147 Check that second argument to size () is a scalar (bug #48368).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21966
diff changeset
2703 octave_idx_type nd = args(1).idx_type_value ();
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
2704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
2705 const dim_vector dv = args(0).dims ();
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
2706
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2707 if (nd < 1)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2708 error ("size: requested dimension DIM (= %d) out of range", nd);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2709
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21602
diff changeset
2710 if (nd <= dv.ndims ())
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2711 retval(0) = dv(nd-1);
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
2712 else
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2713 retval(0) = 1;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2714 }
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
2715 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2716 print_usage ();
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2717
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2718 return retval;
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2719 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2720
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2721 DEFUN (size_equal, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2722 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2723 @deftypefn {} {} size_equal (@var{a}, @var{b}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2724 Return true if the dimensions of all arguments agree.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2725
22429
00986ee43956 doc: Add more @seealso links to numel, size, size_equal.
Rik <rik@octave.org>
parents: 22407
diff changeset
2726 Trailing singleton dimensions are ignored. When called with a single argument,
00986ee43956 doc: Add more @seealso links to numel, size, size_equal.
Rik <rik@octave.org>
parents: 22407
diff changeset
2727 or no argument, @code{size_equal} returns true.
00986ee43956 doc: Add more @seealso links to numel, size, size_equal.
Rik <rik@octave.org>
parents: 22407
diff changeset
2728 @seealso{size, numel, ndims, common_size}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2729 @end deftypefn */)
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2730 {
6561
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2731 int nargin = args.length ();
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2732
8947
1e4b3149365a allow size_equal called with 1 arg
Jaroslav Hajek <highegg@gmail.com>
parents: 8934
diff changeset
2733 if (nargin >= 1)
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2734 {
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2735 dim_vector a_dims = args(0).dims ();
6561
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2736
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2737 for (int i = 1; i < nargin; ++i)
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2738 {
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2739 dim_vector b_dims = args(i).dims ();
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2740
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2741 if (a_dims != b_dims)
21078
49852ff04747 maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents: 21062
diff changeset
2742 return ovl (false);
6561
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2743 }
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2744 }
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2745
21078
49852ff04747 maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents: 21062
diff changeset
2746 return ovl (true);
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2747 }
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2748
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2749 DEFUN (nnz, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2750 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2751 @deftypefn {} {@var{n} =} nnz (@var{a})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2752 Return the number of nonzero elements in @var{a}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2753 @seealso{nzmax, nonzeros, find}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2754 @end deftypefn */)
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2755 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2756 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2757 print_usage ();
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2758
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
2759 return ovl (args(0).nnz ());
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2760 }
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2761
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2762 DEFUN (nzmax, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2763 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2764 @deftypefn {} {@var{n} =} nzmax (@var{SM})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2765 Return the amount of storage allocated to the sparse matrix @var{SM}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2766
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2767 Note that Octave tends to crop unused memory at the first opportunity
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2768 for sparse objects. Thus, in general the value of @code{nzmax} will be the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2769 same as @code{nnz} except for some cases of user-created sparse objects.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2770 @seealso{nnz, spalloc, sparse}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2771 @end deftypefn */)
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2772 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2773 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2774 print_usage ();
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2775
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
2776 return ovl (args(0).nzmax ());
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2777 }
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2778
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2779 DEFUN (rows, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2780 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2781 @deftypefn {} {} rows (@var{a})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2782 Return the number of rows of @var{a}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2783 @seealso{columns, size, length, numel, isscalar, isvector, ismatrix}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2784 @end deftypefn */)
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2785 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2786 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2787 print_usage ();
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2788
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
2789 return ovl (args(0).rows ());
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2790 }
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2791
20810
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
2792 /*
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
2793 %!assert (rows (ones (2,5)), 2)
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
2794 %!assert (rows (ones (5,2)), 5)
20811
5979314bb15a Fix BIST tests for rows.
Rik <rik@octave.org>
parents: 20810
diff changeset
2795 %!assert (rows (ones (5,4,3,2)), 5)
20810
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
2796 %!assert (rows (ones (3,4,5,2)), 3)
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
2797
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
2798 %!assert (rows (cell (2,5)), 2)
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
2799 %!assert (rows (cell (5,2)), 5)
20811
5979314bb15a Fix BIST tests for rows.
Rik <rik@octave.org>
parents: 20810
diff changeset
2800 %!assert (rows (cell (5,4,3,2)), 5)
20810
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
2801 %!assert (rows (cell (3,4,5,2)), 3)
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
2802
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
2803 %!test
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
2804 %! x(2,5,3).a = 1;
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
2805 %! assert (rows (x), 2);
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
2806 %! y(5,4,3).b = 2;
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
2807 %! assert (rows (y), 5);
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
2808
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
2809 %!assert (rows ("Hello World"), 1)
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
2810
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
2811 %!assert (rows ([]), 0)
20815
6935b8f038cc Fix BIST tests for rows()
Rik <rik@octave.org>
parents: 20811
diff changeset
2812 %!assert (rows (zeros (2,0)), 2)
20810
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
2813
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
2814 ## Test input validation
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
2815 %!error rows ()
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
2816 %!error rows (1,2)
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
2817 */
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2818
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2819 DEFUN (columns, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2820 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2821 @deftypefn {} {} columns (@var{a})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2822 Return the number of columns of @var{a}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2823 @seealso{rows, size, length, numel, isscalar, isvector, ismatrix}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2824 @end deftypefn */)
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2825 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2826 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2827 print_usage ();
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2828
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
2829 return ovl (args(0).columns ());
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2830 }
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2831
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
2832 DEFUN (sum, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2833 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2834 @deftypefn {} {} sum (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2835 @deftypefnx {} {} sum (@var{x}, @var{dim})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2836 @deftypefnx {} {} sum (@dots{}, "native")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2837 @deftypefnx {} {} sum (@dots{}, "double")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2838 @deftypefnx {} {} sum (@dots{}, "extra")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2839 Sum of elements along dimension @var{dim}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2840
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2841 If @var{dim} is omitted, it defaults to the first non-singleton dimension.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2842
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2843 The optional @qcode{"type"} input determines the class of the variable
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2844 used for calculations. If the argument @qcode{"native"} is given, then
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2845 the operation is performed in the same type as the original argument, rather
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2846 than the default double type.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2847
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2848 For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2849
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2850 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2851 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2852 sum ([true, true])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2853 @result{} 2
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2854 sum ([true, true], "native")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2855 @result{} true
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2856 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2857 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2858
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2859 On the contrary, if @qcode{"double"} is given, the sum is performed in
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2860 double precision even for single precision inputs.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2861
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2862 For double precision inputs, the @qcode{"extra"} option will use a more
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2863 accurate algorithm than straightforward summation. For single precision
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2864 inputs, @qcode{"extra"} is the same as @qcode{"double"}. Otherwise,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2865 @qcode{"extra"} has no effect.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2866 @seealso{cumsum, sumsq, prod}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2867 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2868 {
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2869 int nargin = args.length ();
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2870
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2871 bool isnative = false;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2872 bool isdouble = false;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2873 bool isextra = false;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2874
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2875 if (nargin > 1 && args(nargin - 1).is_string ())
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2876 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2877 std::string str = args(nargin - 1).string_value ();
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2878
19743
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
2879 if (str == "native")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
2880 isnative = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
2881 else if (str == "double")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
2882 isdouble = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
2883 else if (str == "extra")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
2884 isextra = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
2885 else
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
2886 error ("sum: unrecognized type argument '%s'", str.c_str ());
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
2887
21062
d9c1884d1aaa maint: Eliminate space between variable and decrement '--' operator.
Rik <rik@octave.org>
parents: 21055
diff changeset
2888 nargin--;
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2889 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2890
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2891 if (nargin < 1 || nargin > 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2892 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2893
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2894 int dim = -1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2895 if (nargin == 2)
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2896 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2897 dim = args(1).int_value () - 1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2898 if (dim < 0)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2899 error ("sum: invalid dimension DIM = %d", dim + 1);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2900 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2901
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2902 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2903 octave_value arg = args(0);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2904
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2905 switch (arg.builtin_type ())
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2906 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2907 case btyp_double:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
2908 if (arg.issparse ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2909 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2910 if (isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2911 warning ("sum: 'extra' not yet implemented for sparse matrices");
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2912 retval = arg.sparse_matrix_value ().sum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2913 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2914 else if (isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2915 retval = arg.array_value ().xsum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2916 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2917 retval = arg.array_value ().sum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2918 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2919
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2920 case btyp_complex:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
2921 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2922 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2923 if (isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2924 warning ("sum: 'extra' not yet implemented for sparse matrices");
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2925 retval = arg.sparse_complex_matrix_value ().sum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2926 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2927 else if (isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2928 retval = arg.complex_array_value ().xsum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2929 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2930 retval = arg.complex_array_value ().sum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2931 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2932
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2933 case btyp_float:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2934 if (isdouble || isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2935 retval = arg.float_array_value ().dsum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2936 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2937 retval = arg.float_array_value ().sum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2938 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2939
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2940 case btyp_float_complex:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2941 if (isdouble || isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2942 retval = arg.float_complex_array_value ().dsum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2943 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2944 retval = arg.float_complex_array_value ().sum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2945 break;
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2946
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
2947 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
2948 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
2949 if (isnative) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
2950 retval = arg.X ## _array_value ().sum (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
2951 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
2952 retval = arg.X ## _array_value ().dsum (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
2953 break;
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2954
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2955 MAKE_INT_BRANCH (int8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2956 MAKE_INT_BRANCH (int16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2957 MAKE_INT_BRANCH (int32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2958 MAKE_INT_BRANCH (int64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2959 MAKE_INT_BRANCH (uint8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2960 MAKE_INT_BRANCH (uint16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2961 MAKE_INT_BRANCH (uint32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2962 MAKE_INT_BRANCH (uint64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2963
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2964 #undef MAKE_INT_BRANCH
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19596
diff changeset
2965
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
2966 // GAGME: Accursed Matlab compatibility...
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2967 case btyp_char:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2968 if (isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2969 retval = arg.array_value (true).xsum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2970 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2971 retval = arg.array_value (true).sum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2972 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2973
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2974 case btyp_bool:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
2975 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2976 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2977 if (isnative)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2978 retval = arg.sparse_bool_matrix_value ().any (dim);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2979 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2980 retval = arg.sparse_bool_matrix_value ().sum (dim);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2981 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2982 else if (isnative)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2983 retval = arg.bool_array_value ().any (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2984 else
22773
7f70e420e342 deprecate boolNDArray::sum and boolNDArray::cumsum
John W. Eaton <jwe@octave.org>
parents: 22763
diff changeset
2985 retval = arg.array_value ().sum (dim);
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2986 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2987
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2988 default:
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
2989 err_wrong_type_arg ("sum", arg);
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2990 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2991
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2992 return retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2993 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2994
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
2995 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2996 %!assert (sum ([1, 2, 3]), 6)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2997 %!assert (sum ([-1; -2; -3]), -6)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2998 %!assert (sum ([i, 2+i, -3+2i, 4]), 3+4i)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2999 %!assert (sum ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [2+2i, 4+4i, 6+6i])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3000
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3001 %!assert (sum (single ([1, 2, 3])), single (6))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3002 %!assert (sum (single ([-1; -2; -3])), single (-6))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3003 %!assert (sum (single ([i, 2+i, -3+2i, 4])), single (3+4i))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3004 %!assert (sum (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single ([2+2i, 4+4i, 6+6i]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3005
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3006 %!assert (sum ([1, 2; 3, 4], 1), [4, 6])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3007 %!assert (sum ([1, 2; 3, 4], 2), [3; 7])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3008 %!assert (sum (zeros (1, 0)), 0)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3009 %!assert (sum (zeros (1, 0), 1), zeros (1, 0))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3010 %!assert (sum (zeros (1, 0), 2), 0)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3011 %!assert (sum (zeros (0, 1)), 0)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3012 %!assert (sum (zeros (0, 1), 1), 0)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3013 %!assert (sum (zeros (0, 1), 2), zeros (0, 1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3014 %!assert (sum (zeros (2, 0)), zeros (1, 0))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3015 %!assert (sum (zeros (2, 0), 1), zeros (1, 0))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3016 %!assert (sum (zeros (2, 0), 2), [0; 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3017 %!assert (sum (zeros (0, 2)), [0, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3018 %!assert (sum (zeros (0, 2), 1), [0, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3019 %!assert (sum (zeros (0, 2), 2), zeros (0, 1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3020 %!assert (sum (zeros (2, 2, 0, 3)), zeros (1, 2, 0, 3))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3021 %!assert (sum (zeros (2, 2, 0, 3), 2), zeros (2, 1, 0, 3))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3022 %!assert (sum (zeros (2, 2, 0, 3), 3), zeros (2, 2, 1, 3))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3023 %!assert (sum (zeros (2, 2, 0, 3), 4), zeros (2, 2, 0))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3024 %!assert (sum (zeros (2, 2, 0, 3), 7), zeros (2, 2, 0, 3))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3025
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3026 %!assert (sum (single ([1, 2; 3, 4]), 1), single ([4, 6]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3027 %!assert (sum (single ([1, 2; 3, 4]), 2), single ([3; 7]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3028 %!assert (sum (zeros (1, 0, "single")), single (0))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3029 %!assert (sum (zeros (1, 0, "single"), 1), zeros (1, 0, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3030 %!assert (sum (zeros (1, 0, "single"), 2), single (0))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3031 %!assert (sum (zeros (0, 1, "single")), single (0))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3032 %!assert (sum (zeros (0, 1, "single"), 1), single (0))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3033 %!assert (sum (zeros (0, 1, "single"), 2), zeros (0, 1, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3034 %!assert (sum (zeros (2, 0, "single")), zeros (1, 0, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3035 %!assert (sum (zeros (2, 0, "single"), 1), zeros (1, 0, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3036 %!assert (sum (zeros (2, 0, "single"), 2), single ([0; 0]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3037 %!assert (sum (zeros (0, 2, "single")), single ([0, 0]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3038 %!assert (sum (zeros (0, 2, "single"), 1), single ([0, 0]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3039 %!assert (sum (zeros (0, 2, "single"), 2), zeros (0, 1, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3040 %!assert (sum (zeros (2, 2, 0, 3, "single")), zeros (1, 2, 0, 3, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3041 %!assert (sum (zeros (2, 2, 0, 3, "single"), 2), zeros (2, 1, 0, 3, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3042 %!assert (sum (zeros (2, 2, 0, 3, "single"), 3), zeros (2, 2, 1, 3, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3043 %!assert (sum (zeros (2, 2, 0, 3, "single"), 4), zeros (2, 2, 0, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3044 %!assert (sum (zeros (2, 2, 0, 3, "single"), 7), zeros (2, 2, 0, 3, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3045
18726
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3046 ## Test "native"
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3047 %!assert (sum ([true,true]), 2)
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3048 %!assert (sum ([true,true], "native"), true)
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3049 %!assert (sum (int8 ([127,10,-20])), 117)
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3050 %!assert (sum (int8 ([127,10,-20]), "native"), int8 (107))
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3051
15623
d928ad126b66 maint: add a new test for Fsum corresponding to cset e9d842dcfc91
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15621
diff changeset
3052 ;-)
d928ad126b66 maint: add a new test for Fsum corresponding to cset e9d842dcfc91
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15621
diff changeset
3053 %!assert (sum ("Octave") + "8", sumsq (primes (17)))
d928ad126b66 maint: add a new test for Fsum corresponding to cset e9d842dcfc91
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15621
diff changeset
3054
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3055 %!error sum ()
18726
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3056 %!error sum (1,2,3)
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3057 %!error <unrecognized type argument 'foobar'> sum (1, "foobar")
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
3058 */
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
3059
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
3060 DEFUN (sumsq, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3061 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3062 @deftypefn {} {} sumsq (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3063 @deftypefnx {} {} sumsq (@var{x}, @var{dim})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3064 Sum of squares of elements along dimension @var{dim}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3065
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3066 If @var{dim} is omitted, it defaults to the first non-singleton dimension.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3067
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3068 This function is conceptually equivalent to computing
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3069
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3070 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3071 sum (x .* conj (x), dim)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3072 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3073
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3074 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3075 but it uses less memory and avoids calling @code{conj} if @var{x} is real.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3076 @seealso{sum, prod}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3077 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3078 {
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
3079 DATA_REDUCTION (sumsq);
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3080 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3081
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
3082 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3083 %!assert (sumsq ([1, 2, 3]), 14)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3084 %!assert (sumsq ([-1; -2; 4i]), 21)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3085 %!assert (sumsq ([1, 2, 3; 2, 3, 4; 4i, 6i, 2]), [21, 49, 29])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3086
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3087 %!assert (sumsq (single ([1, 2, 3])), single (14))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3088 %!assert (sumsq (single ([-1; -2; 4i])), single (21))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3089 %!assert (sumsq (single ([1, 2, 3; 2, 3, 4; 4i, 6i, 2])), single ([21, 49, 29]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3090
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3091 %!assert (sumsq ([1, 2; 3, 4], 1), [10, 20])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3092 %!assert (sumsq ([1, 2; 3, 4], 2), [5; 25])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3093
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3094 %!assert (sumsq (single ([1, 2; 3, 4]), 1), single ([10, 20]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3095 %!assert (sumsq (single ([1, 2; 3, 4]), 2), single ([5; 25]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3096
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3097 %!error sumsq ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3098 */
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
3099
6688
b26a8e0e42cd [project @ 2007-06-04 06:25:21 by jwe]
jwe
parents: 6671
diff changeset
3100 DEFUN (islogical, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3101 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3102 @deftypefn {} {} islogical (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3103 @deftypefnx {} {} isbool (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3104 Return true if @var{x} is a logical object.
24474
0b65949870e3 isstring.m: Add new function for identifying string arrays.
Rik <rik@octave.org>
parents: 24441
diff changeset
3105 @seealso{ischar, isfloat, isinteger, isstring, isnumeric, isa}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3106 @end deftypefn */)
3209
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
3107 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3108 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3109 print_usage ();
3209
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
3110
23579
c20a0fa91c0c maint: Deprecate is_bool_type and replace with islogical.
Rik <rik@octave.org>
parents: 23577
diff changeset
3111 return ovl (args(0).islogical ());
3209
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
3112 }
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
3113
6688
b26a8e0e42cd [project @ 2007-06-04 06:25:21 by jwe]
jwe
parents: 6671
diff changeset
3114 DEFALIAS (isbool, islogical);
3209
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
3115
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
3116 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3117 %!assert (islogical (true), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3118 %!assert (islogical (false), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3119 %!assert (islogical ([true, false]), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3120 %!assert (islogical (1), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3121 %!assert (islogical (1i), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3122 %!assert (islogical ([1,1]), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3123 %!assert (islogical (single (1)), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3124 %!assert (islogical (single (1i)), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3125 %!assert (islogical (single ([1,1])), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3126 %!assert (islogical (sparse ([true, false])), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3127 %!assert (islogical (sparse ([1, 0])), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3128 */
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
3129
6223
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
3130 DEFUN (isinteger, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3131 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3132 @deftypefn {} {} isinteger (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3133 Return true if @var{x} is an integer object (int8, uint8, int16, etc.).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3134
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3135 Note that @w{@code{isinteger (14)}} is false because numeric constants in
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3136 Octave are double precision floating point values.
24474
0b65949870e3 isstring.m: Add new function for identifying string arrays.
Rik <rik@octave.org>
parents: 24441
diff changeset
3137 @seealso{isfloat, ischar, islogical, isstring, isnumeric, isa}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3138 @end deftypefn */)
6223
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
3139 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3140 if (args.length () != 1)
6223
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
3141 print_usage ();
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
3142
23580
2230f9e10fb3 maint: Deprecate is_integer_type and replace with isinteger.
Rik <rik@octave.org>
parents: 23579
diff changeset
3143 return ovl (args(0).isinteger ());
6223
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
3144 }
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
3145
22749
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3146 /*
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3147 %!assert (isinteger (int8 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3148 %!assert (isinteger (int16 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3149 %!assert (isinteger (int32 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3150 %!assert (isinteger (int64 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3151
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3152 %!assert (isinteger (uint8 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3153 %!assert (isinteger (uint16 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3154 %!assert (isinteger (uint32 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3155 %!assert (isinteger (uint64 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3156
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3157 %!assert (isinteger (intmax ("int8")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3158 %!assert (isinteger (intmax ("int16")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3159 %!assert (isinteger (intmax ("int32")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3160 %!assert (isinteger (intmax ("int64")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3161
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3162 %!assert (isinteger (intmax ("uint8")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3163 %!assert (isinteger (intmax ("uint16")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3164 %!assert (isinteger (intmax ("uint32")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3165 %!assert (isinteger (intmax ("uint64")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3166
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3167 %!assert (isinteger (intmin ("int8")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3168 %!assert (isinteger (intmin ("int16")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3169 %!assert (isinteger (intmin ("int32")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3170 %!assert (isinteger (intmin ("int64")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3171
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3172 %!assert (isinteger (intmin ("uint8")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3173 %!assert (isinteger (intmin ("uint16")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3174 %!assert (isinteger (intmin ("uint32")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3175 %!assert (isinteger (intmin ("uint64")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3176
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3177 %!assert (isinteger (uint8 ([1:10])))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3178 %!assert (isinteger (uint8 ([1:10; 1:10])))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3179
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3180 %!assert (! isinteger (16))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3181 %!assert (! isinteger ("parrot"))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3182 %!assert (! isinteger ([1, 2, 3]))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3183
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3184 %!error isinteger ()
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3185 %!error isinteger ("multiple", "parameters")
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3186 */
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3187
4028
ef75c970c8f5 [project @ 2002-08-09 07:19:02 by jwe]
jwe
parents: 4025
diff changeset
3188 DEFUN (iscomplex, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3189 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3190 @deftypefn {} {} iscomplex (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3191 Return true if @var{x} is a complex-valued numeric object.
24474
0b65949870e3 isstring.m: Add new function for identifying string arrays.
Rik <rik@octave.org>
parents: 24441
diff changeset
3192 @seealso{isreal, isnumeric, ischar, isfloat, islogical, isstring, isa}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3193 @end deftypefn */)
3186
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
3194 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3195 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3196 print_usage ();
3186
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
3197
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
3198 return ovl (args(0).iscomplex ());
3186
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
3199 }
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
3200
7576
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3201 DEFUN (isfloat, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3202 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3203 @deftypefn {} {} isfloat (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3204 Return true if @var{x} is a floating-point numeric object.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3205
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3206 Objects of class double or single are floating-point objects.
24474
0b65949870e3 isstring.m: Add new function for identifying string arrays.
Rik <rik@octave.org>
parents: 24441
diff changeset
3207 @seealso{isinteger, ischar, islogical, isnumeric, isstring, isa}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3208 @end deftypefn */)
7576
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3209 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3210 if (args.length () != 1)
7576
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3211 print_usage ();
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3212
23585
570170b6eb09 maint: Deprecate is_float_type and replace with isfloat.
Rik <rik@octave.org>
parents: 23584
diff changeset
3213 return ovl (args(0).isfloat ());
7576
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3214 }
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3215
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3216 // FIXME: perhaps this should be implemented with an
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3217 // octave_value member function?
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3218
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3219 DEFUN (complex, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3220 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3221 @deftypefn {} {} complex (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3222 @deftypefnx {} {} complex (@var{re}, @var{im})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3223 Return a complex value from real arguments.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3224
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3225 With 1 real argument @var{x}, return the complex result
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3226 @w{@code{@var{x} + 0i}}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3227
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3228 With 2 real arguments, return the complex result
24440
f8bbaacefc33 doc: Fix various inconsistencies in manual (bug #52712).
Rik <rik@octave.org>
parents: 23219
diff changeset
3229 @w{@code{@var{re} + @var{im}i}}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3230 @code{complex} can often be more convenient than expressions such as
24440
f8bbaacefc33 doc: Fix various inconsistencies in manual (bug #52712).
Rik <rik@octave.org>
parents: 23219
diff changeset
3231 @w{@code{a + b*i}}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3232 For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3233
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3234 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3235 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3236 complex ([1, 2], [3, 4])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3237 @result{} [ 1 + 3i 2 + 4i ]
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3238 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3239 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3240 @seealso{real, imag, iscomplex, abs, arg}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3241 @end deftypefn */)
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3242 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3243 int nargin = args.length ();
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3244
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3245 if (nargin < 1 || nargin > 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3246 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3247
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3248 octave_value retval;
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3249
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3250 if (nargin == 1)
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3251 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3252 octave_value arg = args(0);
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3253
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
3254 if (arg.iscomplex ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3255 retval = arg;
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3256 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3257 {
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
3258 if (arg.issparse ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3259 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
3260 SparseComplexMatrix val = arg.xsparse_complex_matrix_value ("complex: invalid conversion");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3261
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3262 retval = octave_value (new octave_sparse_complex_matrix (val));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3263 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3264 else if (arg.is_single_type ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3265 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3266 if (arg.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3267 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
3268 FloatComplex val = arg.xfloat_complex_value ("complex: invalid conversion");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3269
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3270 retval = octave_value (new octave_float_complex (val));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3271 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3272 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3273 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
3274 FloatComplexNDArray val = arg.xfloat_complex_array_value ("complex: invalid conversion");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3275
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3276 retval = octave_value (new octave_float_complex_matrix (val));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3277 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3278 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3279 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3280 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3281 if (arg.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3282 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
3283 Complex val = arg.xcomplex_value ("complex: invalid conversion");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3284
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3285 retval = octave_value (new octave_complex (val));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3286 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3287 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3288 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
3289 ComplexNDArray val = arg.xcomplex_array_value ("complex: invalid conversion");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3290
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3291 retval = octave_value (new octave_complex_matrix (val));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3292 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3293 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3294 }
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3295 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3296 else
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3297 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3298 octave_value re = args(0);
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3299 octave_value im = args(1);
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3300
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
3301 if (re.issparse () && im.issparse ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3302 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3303 const SparseMatrix re_val = re.sparse_matrix_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3304 const SparseMatrix im_val = im.sparse_matrix_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3305
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3306 if (re.numel () == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3307 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3308 SparseComplexMatrix result;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3309 if (re_val.nnz () == 0)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3310 result = Complex (0, 1) * SparseComplexMatrix (im_val);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3311 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3312 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3313 octave_idx_type nr = im_val.rows ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3314 octave_idx_type nc = im_val.cols ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3315 result = SparseComplexMatrix (nr, nc, re_val(0));
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3316
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3317 for (octave_idx_type j = 0; j < nc; j++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3318 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3319 octave_idx_type off = j * nr;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3320 for (octave_idx_type i = im_val.cidx (j);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3321 i < im_val.cidx (j + 1); i++)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3322 result.data (im_val.ridx (i) + off) +=
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3323 Complex (0, im_val.data (i));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3324 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3325 }
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3326 retval = octave_value (new octave_sparse_complex_matrix (result));
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3327 }
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3328 else if (im.numel () == 1)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3329 {
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3330 SparseComplexMatrix result;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3331 if (im_val.nnz () == 0)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3332 result = SparseComplexMatrix (re_val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3333 else
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3334 {
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3335 octave_idx_type nr = re_val.rows ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3336 octave_idx_type nc = re_val.cols ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3337 result = SparseComplexMatrix (nr, nc,
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3338 Complex (0, im_val(0)));
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3339
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3340 for (octave_idx_type j = 0; j < nc; j++)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3341 {
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3342 octave_idx_type off = j * nr;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3343 for (octave_idx_type i = re_val.cidx (j);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3344 i < re_val.cidx (j + 1); i++)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3345 result.data (re_val.ridx (i) + off) +=
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3346 re_val.data (i);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3347 }
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3348 }
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3349 retval = octave_value (new octave_sparse_complex_matrix (result));
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3350 }
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3351 else
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3352 {
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3353 if (re_val.dims () != im_val.dims ())
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3354 error ("complex: dimension mismatch");
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3355
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3356 SparseComplexMatrix result;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3357 result = SparseComplexMatrix (re_val)
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3358 + Complex (0, 1) * SparseComplexMatrix (im_val);
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3359 retval = octave_value (new octave_sparse_complex_matrix (result));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3360 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3361 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
3362 else if (re.is_single_type () || im.is_single_type ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3363 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3364 if (re.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3365 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3366 float re_val = re.float_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3367
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3368 if (im.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3369 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3370 float im_val = im.double_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3371
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3372 retval = octave_value (new octave_float_complex
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3373 (FloatComplex (re_val, im_val)));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3374 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3375 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3376 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3377 const FloatNDArray im_val = im.float_array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3378
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3379 FloatComplexNDArray result (im_val.dims (),
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3380 FloatComplex ());
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3381
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3382 for (octave_idx_type i = 0; i < im_val.numel (); i++)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3383 result.xelem (i) = FloatComplex (re_val, im_val(i));
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3384
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3385 retval = octave_value (new octave_float_complex_matrix
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3386 (result));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3387 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3388 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3389 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3390 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3391 const FloatNDArray re_val = re.float_array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3392
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3393 if (im.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3394 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3395 float im_val = im.float_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3396
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3397 FloatComplexNDArray result (re_val.dims (),
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3398 FloatComplex ());
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3399
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3400 for (octave_idx_type i = 0; i < re_val.numel (); i++)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3401 result.xelem (i) = FloatComplex (re_val(i), im_val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3402
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3403 retval = octave_value (new octave_float_complex_matrix
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3404 (result));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3405 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3406 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3407 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3408 const FloatNDArray im_val = im.float_array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3409
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3410 if (re_val.dims () != im_val.dims ())
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3411 error ("complex: dimension mismatch");
20921
4d3daf7e43f3 eliminate trailing whitespace in source files
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
3412
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3413 FloatComplexNDArray result (re_val.dims (),
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3414 FloatComplex ());
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3415
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3416 for (octave_idx_type i = 0; i < re_val.numel (); i++)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3417 result.xelem (i) = FloatComplex (re_val(i),
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3418 im_val(i));
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3419
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3420 retval = octave_value (new octave_float_complex_matrix
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3421 (result));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3422 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3423 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3424 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
3425 else if (re.numel () == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3426 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3427 double re_val = re.double_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3428
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3429 if (im.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3430 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3431 double im_val = im.double_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3432
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3433 retval = octave_value (new octave_complex
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3434 (Complex (re_val, im_val)));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3435 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3436 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3437 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3438 const NDArray im_val = im.array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3439
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3440 ComplexNDArray result (im_val.dims (), Complex ());
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3441
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3442 for (octave_idx_type i = 0; i < im_val.numel (); i++)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3443 result.xelem (i) = Complex (re_val, im_val(i));
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3444
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3445 retval = octave_value (new octave_complex_matrix (result));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3446 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3447 }
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3448 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3449 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3450 const NDArray re_val = re.array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3451
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3452 if (im.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3453 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3454 double im_val = im.double_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3455
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3456 ComplexNDArray result (re_val.dims (), Complex ());
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3457
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3458 for (octave_idx_type i = 0; i < re_val.numel (); i++)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3459 result.xelem (i) = Complex (re_val(i), im_val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3460
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3461 retval = octave_value (new octave_complex_matrix (result));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3462 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3463 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3464 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3465 const NDArray im_val = im.array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3466
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3467 if (re_val.dims () != im_val.dims ())
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3468 error ("complex: dimension mismatch");
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3469
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3470 ComplexNDArray result (re_val.dims (), Complex ());
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3471
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3472 for (octave_idx_type i = 0; i < re_val.numel (); i++)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3473 result.xelem (i) = Complex (re_val(i), im_val(i));
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3474
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3475 retval = octave_value (new octave_complex_matrix (result));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3476 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3477 }
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3478 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3479
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3480 return retval;
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3481 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3482
22590
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3483 /*
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3484 %!error <undefined> 1+Infj
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3485 %!error <undefined> 1+Infi
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3486
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3487 %!test <31974>
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3488 %! assert (Inf + Inf*i, complex (Inf, Inf))
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3489 %!
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3490 %! assert (1 + Inf*i, complex (1, Inf))
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3491 %! assert (1 + Inf*j, complex (1, Inf))
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3492 %!
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3493 %! ## whitespace should not affect parsing
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3494 %! assert (1+Inf*i, complex (1, Inf))
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3495 %! assert (1+Inf*j, complex (1, Inf))
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3496 %!
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3497 %! assert (NaN*j, complex (0, NaN))
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3498 %!
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3499 %! assert (Inf * 4j, complex (0, Inf))
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3500
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3501 %!test <31974>
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3502 %! x = Inf;
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3503 %! assert (x * j, complex (0, Inf))
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3504 %! j = complex (0, 1);
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3505 %! assert (Inf * j, complex (0, Inf))
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3506
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3507 %!test <31974>
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3508 %! exp = complex (zeros (2, 2), Inf (2, 2));
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3509 %! assert (Inf (2, 2) * j, exp)
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3510 %! assert (Inf (2, 2) .* j, exp)
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3511 %! assert (Inf * (ones (2, 2) * j), exp)
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3512 %! assert (Inf (2, 2) .* (ones (2, 2) * j), exp)
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3513
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3514 %!test <31974>
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3515 %! assert ([Inf; 0] * [i, 0], complex ([NaN NaN; 0 0], [Inf NaN; 0 0]))
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3516 %! assert ([Inf, 0] * [i; 0], complex (NaN, Inf))
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3517 %! assert ([Inf, 0] .* [i, 0], complex ([0 0], [Inf 0]))
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3518
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3519 %!test <31974>
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3520 %! m = @(x, y) x * y;
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3521 %! d = @(x, y) x / y;
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3522 %! assert (m (Inf, i), complex (0, +Inf))
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3523 %! assert (d (Inf, i), complex (0, -Inf))
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3524 */
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3525
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3526 DEFUN (isreal, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3527 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3528 @deftypefn {} {} isreal (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3529 Return true if @var{x} is a non-complex matrix or scalar.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3530
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3531 For compatibility with @sc{matlab}, this includes logical and character
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3532 matrices.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3533 @seealso{iscomplex, isnumeric, isa}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3534 @end deftypefn */)
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3535 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3536 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3537 print_usage ();
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3538
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
3539 return ovl (args(0).isreal ());
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3540 }
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3541
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3542 DEFUN (isempty, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3543 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3544 @deftypefn {} {} isempty (@var{a})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3545 Return true if @var{a} is an empty matrix (any one of its dimensions is
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3546 zero).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3547 @seealso{isnull, isa}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3548 @end deftypefn */)
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3549 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3550 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3551 print_usage ();
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3552
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
3553 return ovl (args(0).isempty ());
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3554 }
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3555
16779
8fce0ed4894a Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents: 16077
diff changeset
3556 /*
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
3557 ## Debian bug #706376
16779
8fce0ed4894a Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents: 16077
diff changeset
3558 %!assert (isempty (speye(2^16)), false)
8fce0ed4894a Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents: 16077
diff changeset
3559 */
8fce0ed4894a Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents: 16077
diff changeset
3560
3206
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3561 DEFUN (isnumeric, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3562 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3563 @deftypefn {} {} isnumeric (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3564 Return true if @var{x} is a numeric object, i.e., an integer, real, or
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3565 complex array.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3566
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3567 Logical and character arrays are not considered to be numeric.
24474
0b65949870e3 isstring.m: Add new function for identifying string arrays.
Rik <rik@octave.org>
parents: 24441
diff changeset
3568 @seealso{isinteger, isfloat, isreal, iscomplex, ischar, islogical, isstring, iscell, isstruct, isa}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3569 @end deftypefn */)
3206
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3570 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3571 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3572 print_usage ();
3206
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3573
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
3574 return ovl (args(0).isnumeric ());
3206
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3575 }
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3576
11435
20f53b3a558f Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
3577 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3578 %!assert (isnumeric (1), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3579 %!assert (isnumeric (1i), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3580 %!assert (isnumeric ([1,1]), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3581 %!assert (isnumeric (single (1)), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3582 %!assert (isnumeric (single (1i)), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3583 %!assert (isnumeric (single ([1,1])), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3584 %!assert (isnumeric (int8 (1)), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3585 %!assert (isnumeric (uint8 ([1,1])), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3586 %!assert (isnumeric ("Hello World"), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3587 %!assert (isnumeric (true), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3588 %!assert (isnumeric (false), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3589 %!assert (isnumeric ([true, false]), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3590 %!assert (isnumeric (sparse ([true, false])), false)
11435
20f53b3a558f Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
3591 */
20f53b3a558f Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
3592
18813
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3593 DEFUN (isscalar, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3594 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3595 @deftypefn {} {} isscalar (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3596 Return true if @var{x} is a scalar.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3597 @seealso{isvector, ismatrix}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3598 @end deftypefn */)
18813
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3599 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3600 if (args.length () != 1)
18813
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3601 print_usage ();
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3602
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
3603 return ovl (args(0).numel () == 1);
18813
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3604 }
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3605
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3606 /*
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3607 %!assert (isscalar (1))
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3608 %!assert (isscalar ([1, 2]), false)
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3609 %!assert (isscalar ([]), false)
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3610 %!assert (isscalar ([1, 2; 3, 4]), false)
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3611
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3612 %!assert (isscalar ("t"))
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3613 %!assert (isscalar ("test"), false)
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3614 %!assert (isscalar (["test"; "ing"]), false)
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3615
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3616 %!test
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3617 %! s.a = 1;
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3618 %! assert (isscalar (s));
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3619
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
3620 ## Test input validation
18813
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3621 %!error isscalar ()
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3622 %!error isscalar (1, 2)
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3623 */
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3624
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3625 DEFUN (isvector, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3626 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3627 @deftypefn {} {} isvector (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3628 Return true if @var{x} is a vector.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3629
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3630 A vector is a 2-D array where one of the dimensions is equal to 1. As a
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3631 consequence a 1x1 array, or scalar, is also a vector.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3632 @seealso{isscalar, ismatrix, size, rows, columns, length}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3633 @end deftypefn */)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3634 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3635 if (args.length () != 1)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3636 print_usage ();
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3637
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3638 dim_vector sz = args(0).dims ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3639
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21602
diff changeset
3640 return ovl (sz.ndims () == 2 && (sz(0) == 1 || sz(1) == 1));
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3641 }
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3642
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3643 /*
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3644 %!assert (isvector (1), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3645 %!assert (isvector ([1; 2; 3]), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3646 %!assert (isvector ([1, 2, 3]), true)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3647 %!assert (isvector ([]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3648 %!assert (isvector ([1, 2; 3, 4]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3649
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3650 %!assert (isvector ("t"), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3651 %!assert (isvector ("test"), true)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3652 %!assert (isvector (["test"; "ing"]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3653
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3654 %!test
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3655 %! s.a = 1;
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3656 %! assert (isvector (s), true);
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3657
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
3658 ## Test input validation
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3659 %!error isvector ()
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3660 %!error isvector ([1, 2], 2)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3661 */
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3662
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3663 DEFUN (isrow, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3664 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3665 @deftypefn {} {} isrow (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3666 Return true if @var{x} is a row vector 1xN with non-negative N.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3667 @seealso{iscolumn, isscalar, isvector, ismatrix}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3668 @end deftypefn */)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3669 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3670 if (args.length () != 1)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3671 print_usage ();
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3672
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3673 dim_vector sz = args(0).dims ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3674
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21602
diff changeset
3675 return ovl (sz.ndims () == 2 && sz(0) == 1);
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3676 }
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3677
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3678 /*
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3679 %!assert (isrow ([1, 2, 3]))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3680 %!assert (isrow ([1; 2; 3]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3681 %!assert (isrow (1))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3682 %!assert (isrow ([]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3683 %!assert (isrow ([1, 2; 3, 4]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3684
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3685 %!assert (isrow (ones (1, 0)), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3686 %!assert (isrow (ones (1, 1)), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3687 %!assert (isrow (ones (1, 2)), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3688 %!assert (isrow (ones (1, 1, 1)), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3689 %!assert (isrow (ones (1, 1, 1, 1)), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3690
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3691 %!assert (isrow (ones (0, 0)), false)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3692 %!assert (isrow (ones (1, 1, 0)), false)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3693
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3694 %!assert (isrow ("t"), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3695 %!assert (isrow ("test"), true)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3696 %!assert (isrow (["test"; "ing"]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3697
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3698 %!test
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3699 %! s.a = 1;
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3700 %! assert (isrow (s), true);
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3701
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
3702 ## Test input validation
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3703 %!error isrow ()
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3704 %!error isrow ([1, 2], 2)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3705 */
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3706
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3707 DEFUN (iscolumn, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3708 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3709 @deftypefn {} {} iscolumn (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3710 Return true if @var{x} is a column vector Nx1 with non-negative N.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3711 @seealso{isrow, isscalar, isvector, ismatrix}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3712 @end deftypefn */)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3713 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3714 if (args.length () != 1)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3715 print_usage ();
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3716
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3717 dim_vector sz = args(0).dims ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3718
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21602
diff changeset
3719 return ovl (sz.ndims () == 2 && sz(1) == 1);
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3720 }
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3721
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3722 /*
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3723 %!assert (iscolumn ([1, 2, 3]), false)
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3724 %!assert (iscolumn ([1; 2; 3]), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3725 %!assert (iscolumn (1), true)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3726 %!assert (iscolumn ([]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3727 %!assert (iscolumn ([1, 2; 3, 4]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3728
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3729 %!assert (iscolumn ("t"), true)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3730 %!assert (iscolumn ("test"), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3731 %!assert (iscolumn (["test"; "ing"]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3732
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3733 %!assert (iscolumn (ones (0, 1)), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3734 %!assert (iscolumn (ones (1, 1)), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3735 %!assert (iscolumn (ones (2, 1)), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3736 %!assert (iscolumn (ones (1, 1, 1)), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3737 %!assert (iscolumn (ones (1, 1, 1, 1)), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3738
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3739 %!assert (iscolumn (ones (0, 0)), false)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3740 %!assert (iscolumn (ones (0, 1, 0)), false)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3741
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3742 %!test
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3743 %! s.a = 1;
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3744 %! assert (iscolumn (s));
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3745
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
3746 ## Test input validation
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3747 %!error iscolumn ()
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3748 %!error iscolumn ([1, 2], 2)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3749 */
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3750
4028
ef75c970c8f5 [project @ 2002-08-09 07:19:02 by jwe]
jwe
parents: 4025
diff changeset
3751 DEFUN (ismatrix, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3752 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3753 @deftypefn {} {} ismatrix (@var{a})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3754 Return true if @var{a} is a 2-D array.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3755 @seealso{isscalar, isvector, iscell, isstruct, issparse, isa}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3756 @end deftypefn */)
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3757 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3758 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3759 print_usage ();
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3760
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3761 dim_vector sz = args(0).dims ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3762
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21602
diff changeset
3763 return ovl (sz.ndims () == 2 && sz(0) >= 0 && sz(1) >= 0);
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3764 }
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3765
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
3766 /*
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3767 %!assert (ismatrix ([]), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3768 %!assert (ismatrix (1), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3769 %!assert (ismatrix ([1, 2, 3]), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3770 %!assert (ismatrix ([1, 2; 3, 4]), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3771
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3772 %!assert (ismatrix (zeros (0)), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3773 %!assert (ismatrix (zeros (0, 0)), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3774 %!assert (ismatrix (zeros (0, 0, 0)), false)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3775 %!assert (ismatrix (zeros (3, 2, 4)), false)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3776
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3777 %!assert (ismatrix (single ([])), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3778 %!assert (ismatrix (single (1)), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3779 %!assert (ismatrix (single ([1, 2, 3])), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3780 %!assert (ismatrix (single ([1, 2; 3, 4])), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3781
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3782 %!assert (ismatrix ("t"), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3783 %!assert (ismatrix ("test"), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3784 %!assert (ismatrix (["test"; "ing"]), true)
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
3785
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
3786 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
3787 %! s.a = 1;
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3788 %! assert (ismatrix (s), true);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3789
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3790 %!error ismatrix ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3791 %!error ismatrix ([1, 2; 3, 4], 2)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3792 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
3793
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3794 DEFUN (issquare, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3795 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3796 @deftypefn {} {} issquare (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3797 Return true if @var{x} is a square matrix.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3798 @seealso{isscalar, isvector, ismatrix, size}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3799 @end deftypefn */)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3800 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3801 if (args.length () != 1)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3802 print_usage ();
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3803
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3804 dim_vector sz = args(0).dims ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3805
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21602
diff changeset
3806 return ovl (sz.ndims () == 2 && sz(0) == sz(1));
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3807 }
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3808
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3809 /*
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3810 %!assert (issquare ([]))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3811 %!assert (issquare (1))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3812 %!assert (! issquare ([1, 2]))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3813 %!assert (issquare ([1, 2; 3, 4]))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3814 %!assert (! issquare ([1, 2; 3, 4; 5, 6]))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3815 %!assert (! issquare (ones (3,3,3)))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3816 %!assert (issquare ("t"))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3817 %!assert (! issquare ("test"))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3818 %!assert (issquare (["test"; "ing"; "1"; "2"]))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3819 %!test
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3820 %! s.a = 1;
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3821 %! assert (issquare (s));
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3822 %!assert (issquare ({1, 2; 3, 4}))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3823 %!assert (sparse (([1, 2; 3, 4])))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3824
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
3825 ## Test input validation
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3826 %!error issquare ()
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3827 %!error issquare ([1, 2; 3, 4], 2)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3828 */
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3829
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
3830 static octave_value
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3831 fill_matrix (const octave_value_list& args, int val, const char *fcn)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3832 {
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
3833 octave_value retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3834
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3835 int nargin = args.length ();
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3836
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
3837 oct_data_conv::data_type dt = oct_data_conv::dt_double;
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3838
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
3839 dim_vector dims (1, 1);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
3840
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3841 if (nargin > 0 && args(nargin-1).is_string ())
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3842 {
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
3843 std::string nm = args(nargin-1).string_value ();
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3844 nargin--;
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3845
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
3846 dt = oct_data_conv::string_to_data_type (nm);
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3847 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3848
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3849 switch (nargin)
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3850 {
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
3851 case 0:
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
3852 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 767
diff changeset
3853
610
14b2a186a5c0 [project @ 1994-08-14 00:55:49 by jwe]
jwe
parents: 597
diff changeset
3854 case 1:
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3855 get_dimensions (args(0), fcn, dims);
610
14b2a186a5c0 [project @ 1994-08-14 00:55:49 by jwe]
jwe
parents: 597
diff changeset
3856 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 767
diff changeset
3857
4563
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
3858 default:
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
3859 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3860 dims.resize (nargin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3861
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3862 for (int i = 0; i < nargin; i++)
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
3863 dims(i) = (args(i).isempty ()
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20704
diff changeset
3864 ? 0 : args(i).xidx_type_value ("%s: dimension arguments must be scalar integers", fcn));
4563
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
3865 }
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
3866 break;
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3867 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3868
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3869 dims.chop_trailing_singletons ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3870
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3871 check_dimensions (dims, fcn);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3872
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3873 // FIXME: perhaps this should be made extensible by
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3874 // using the class name to lookup a function to call to create
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3875 // the new value.
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3876
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3877 // Note that automatic narrowing will handle conversion from
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3878 // NDArray to scalar.
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3879
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3880 switch (dt)
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3881 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3882 case oct_data_conv::dt_int8:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3883 retval = int8NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3884 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3885
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3886 case oct_data_conv::dt_uint8:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3887 retval = uint8NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3888 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3889
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3890 case oct_data_conv::dt_int16:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3891 retval = int16NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3892 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3893
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3894 case oct_data_conv::dt_uint16:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3895 retval = uint16NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3896 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3897
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3898 case oct_data_conv::dt_int32:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3899 retval = int32NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3900 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3901
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3902 case oct_data_conv::dt_uint32:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3903 retval = uint32NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3904 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3905
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3906 case oct_data_conv::dt_int64:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3907 retval = int64NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3908 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3909
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3910 case oct_data_conv::dt_uint64:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3911 retval = uint64NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3912 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3913
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3914 case oct_data_conv::dt_single:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3915 retval = FloatNDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3916 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3917
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3918 case oct_data_conv::dt_double:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3919 {
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21602
diff changeset
3920 if (val == 1 && dims.ndims () == 2 && dims(0) == 1)
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3921 retval = Range (1.0, 0.0, dims(1)); // packed form
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3922 else
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3923 retval = NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3924 }
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3925 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3926
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3927 case oct_data_conv::dt_logical:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3928 retval = boolNDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3929 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3930
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3931 default:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3932 error ("%s: invalid class name", fcn);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3933 break;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3934 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3935
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3936 return retval;
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3937 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3938
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3939 static octave_value
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
3940 fill_matrix (const octave_value_list& args, double val, float fval,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3941 const char *fcn)
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3942 {
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3943 octave_value retval;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3944
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3945 int nargin = args.length ();
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3946
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3947 oct_data_conv::data_type dt = oct_data_conv::dt_double;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3948
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3949 dim_vector dims (1, 1);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
3950
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3951 if (nargin > 0 && args(nargin-1).is_string ())
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3952 {
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3953 std::string nm = args(nargin-1).string_value ();
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3954 nargin--;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3955
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3956 dt = oct_data_conv::string_to_data_type (nm);
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3957 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3958
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3959 switch (nargin)
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3960 {
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3961 case 0:
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3962 break;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3963
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3964 case 1:
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3965 get_dimensions (args(0), fcn, dims);
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3966 break;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3967
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3968 default:
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3969 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3970 dims.resize (nargin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3971
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3972 for (int i = 0; i < nargin; i++)
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
3973 dims(i) = (args(i).isempty ()
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20704
diff changeset
3974 ? 0 : args(i).xidx_type_value ("%s: dimension arguments must be scalar integers", fcn));
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3975 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3976 break;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3977 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3978
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3979 dims.chop_trailing_singletons ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3980
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3981 check_dimensions (dims, fcn);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3982
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3983 // Note that automatic narrowing will handle conversion from
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3984 // NDArray to scalar.
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3985
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3986 switch (dt)
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3987 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3988 case oct_data_conv::dt_single:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3989 retval = FloatNDArray (dims, fval);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3990 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3991
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3992 case oct_data_conv::dt_double:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3993 retval = NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3994 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3995
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3996 default:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3997 error ("%s: invalid class name", fcn);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3998 break;
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3999 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4000
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4001 return retval;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4002 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4003
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4004 static octave_value
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4005 fill_matrix (const octave_value_list& args, double val, const char *fcn)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4006 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4007 octave_value retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4008
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4009 int nargin = args.length ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4010
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4011 oct_data_conv::data_type dt = oct_data_conv::dt_double;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4012
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4013 dim_vector dims (1, 1);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4014
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4015 if (nargin > 0 && args(nargin-1).is_string ())
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4016 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4017 std::string nm = args(nargin-1).string_value ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4018 nargin--;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4019
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4020 dt = oct_data_conv::string_to_data_type (nm);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4021 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4022
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4023 switch (nargin)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4024 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4025 case 0:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4026 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4027
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4028 case 1:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4029 get_dimensions (args(0), fcn, dims);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4030 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4031
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4032 default:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4033 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4034 dims.resize (nargin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4035
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4036 for (int i = 0; i < nargin; i++)
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
4037 dims(i) = (args(i).isempty ()
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20704
diff changeset
4038 ? 0 : args(i).xidx_type_value ("%s: dimension arguments must be scalar integers", fcn));
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4039 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4040 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4041 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4042
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4043 dims.chop_trailing_singletons ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4044
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4045 check_dimensions (dims, fcn);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4046
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4047 // Note that automatic narrowing will handle conversion from
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4048 // NDArray to scalar.
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4049
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4050 switch (dt)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4051 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4052 case oct_data_conv::dt_single:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4053 retval = FloatNDArray (dims, static_cast<float> (val));
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4054 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4055
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4056 case oct_data_conv::dt_double:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4057 retval = NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4058 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4059
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4060 default:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4061 error ("%s: invalid class name", fcn);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4062 break;
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4063 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4064
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4065 return retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4066 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4067
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4068 static octave_value
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4069 fill_matrix (const octave_value_list& args, const Complex& val,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4070 const char *fcn)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4071 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4072 octave_value retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4073
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4074 int nargin = args.length ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4075
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4076 oct_data_conv::data_type dt = oct_data_conv::dt_double;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4077
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4078 dim_vector dims (1, 1);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4079
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4080 if (nargin > 0 && args(nargin-1).is_string ())
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4081 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4082 std::string nm = args(nargin-1).string_value ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4083 nargin--;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4084
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4085 dt = oct_data_conv::string_to_data_type (nm);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4086 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4087
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4088 switch (nargin)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4089 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4090 case 0:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4091 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4092
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4093 case 1:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4094 get_dimensions (args(0), fcn, dims);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4095 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4096
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4097 default:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4098 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4099 dims.resize (nargin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4100
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4101 for (int i = 0; i < nargin; i++)
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
4102 dims(i) = (args(i).isempty ()
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20704
diff changeset
4103 ? 0 : args(i).xidx_type_value ("%s: dimension arguments must be scalar integers", fcn));
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4104 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4105 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4106 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4107
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4108 dims.chop_trailing_singletons ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4109
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4110 check_dimensions (dims, fcn);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4111
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4112 // Note that automatic narrowing will handle conversion from
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4113 // NDArray to scalar.
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4114
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4115 switch (dt)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4116 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4117 case oct_data_conv::dt_single:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4118 retval = FloatComplexNDArray (dims,
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4119 static_cast<FloatComplex> (val));
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4120 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4121
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4122 case oct_data_conv::dt_double:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4123 retval = ComplexNDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4124 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4125
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4126 default:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4127 error ("%s: invalid class name", fcn);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4128 break;
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4129 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4130
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4131 return retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4132 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4133
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4134 static octave_value
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4135 fill_matrix (const octave_value_list& args, bool val, const char *fcn)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4136 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4137 octave_value retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4138
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4139 int nargin = args.length ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4140
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4141 dim_vector dims (1, 1);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4142
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4143 switch (nargin)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4144 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4145 case 0:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4146 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4147
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4148 case 1:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4149 get_dimensions (args(0), fcn, dims);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4150 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4151
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4152 default:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4153 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4154 dims.resize (nargin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4155
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4156 for (int i = 0; i < nargin; i++)
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
4157 dims(i) = (args(i).isempty ()
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20704
diff changeset
4158 ? 0 : args(i).xidx_type_value ("%s: dimension arguments must be scalar integers", fcn));
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4159 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4160 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4161 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4162
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4163 dims.chop_trailing_singletons ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4164
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4165 check_dimensions (dims, fcn);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4166
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4167 // Note that automatic narrowing will handle conversion from
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4168 // NDArray to scalar.
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4169
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4170 retval = boolNDArray (dims, val);
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4171
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4172 return retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4173 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4174
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
4175 DEFUN (ones, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4176 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4177 @deftypefn {} {} ones (@var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4178 @deftypefnx {} {} ones (@var{m}, @var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4179 @deftypefnx {} {} ones (@var{m}, @var{n}, @var{k}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4180 @deftypefnx {} {} ones ([@var{m} @var{n} @dots{}])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4181 @deftypefnx {} {} ones (@dots{}, @var{class})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4182 Return a matrix or N-dimensional array whose elements are all 1.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4183
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4184 If invoked with a single scalar integer argument @var{n}, return a square
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4185 @nospell{NxN} matrix.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4186
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4187 If invoked with two or more scalar integer arguments, or a vector of integer
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4188 values, return an array with the given dimensions.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4189
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4190 To create a constant matrix whose values are all the same use an expression
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4191 such as
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4192
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4193 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4194 val_matrix = val * ones (m, n)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4195 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4196
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4197 The optional argument @var{class} specifies the class of the return array
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4198 and defaults to double. For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4199
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4200 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4201 val = ones (m,n, "uint8")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4202 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4203 @seealso{zeros}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4204 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4205 {
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4206 return fill_matrix (args, 1, "ones");
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4207 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4208
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4209 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4210 %!assert (ones (3), [1, 1, 1; 1, 1, 1; 1, 1, 1])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4211 %!assert (ones (2, 3), [1, 1, 1; 1, 1, 1])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4212 %!assert (ones (3, 2), [1, 1; 1, 1; 1, 1])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4213 %!assert (size (ones (3, 4, 5)), [3, 4, 5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4214
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4215 %!assert (ones (3, "single"), single ([1, 1, 1; 1, 1, 1; 1, 1, 1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4216 %!assert (ones (2, 3, "single"), single ([1, 1, 1; 1, 1, 1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4217 %!assert (ones (3, 2, "single"), single ([1, 1; 1, 1; 1, 1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4218 %!assert (size (ones (3, 4, 5, "single")), [3, 4, 5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4219
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4220 %!assert (ones (3, "int8"), int8 ([1, 1, 1; 1, 1, 1; 1, 1, 1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4221 %!assert (ones (2, 3, "int8"), int8 ([1, 1, 1; 1, 1, 1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4222 %!assert (ones (3, 2, "int8"), int8 ([1, 1; 1, 1; 1, 1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4223 %!assert (size (ones (3, 4, 5, "int8")), [3, 4, 5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4224 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4225
21405
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4226 /*
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4227 ## Tests for bug #47298
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4228 ## Matlab requires the size to be a row vector. In that logic, it supports
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4229 ## n to be a 1x0 vector (returns 0x0) but not a 0x1 vector. Octave supports
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4230 ## any vector and therefore must support 0x1, 1x0, and 0x0x1 (but not 0x1x1).
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
4231 %!test <*47298>
21405
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4232 %! funcs = {@zeros, @ones, @inf, @nan, @NA, @i, @pi, @e};
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4233 %! for idx = 1:numel (funcs)
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4234 %! func = funcs{idx};
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21575
diff changeset
4235 %! assert (func (zeros (1, 0)), zeros (0, 0));
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21575
diff changeset
4236 %! assert (func (zeros (0, 1)), zeros (0, 0));
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21575
diff changeset
4237 %! assert (func (zeros (0, 1, 1)), zeros (0, 0));
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21575
diff changeset
4238 %! fail ([func2str(func) " ([])"]);
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21575
diff changeset
4239 %! fail ([func2str(func) " (zeros (0, 0, 1))"]);
21405
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4240 %! endfor
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4241 */
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4242
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
4243 DEFUN (zeros, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4244 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4245 @deftypefn {} {} zeros (@var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4246 @deftypefnx {} {} zeros (@var{m}, @var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4247 @deftypefnx {} {} zeros (@var{m}, @var{n}, @var{k}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4248 @deftypefnx {} {} zeros ([@var{m} @var{n} @dots{}])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4249 @deftypefnx {} {} zeros (@dots{}, @var{class})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4250 Return a matrix or N-dimensional array whose elements are all 0.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4251
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4252 If invoked with a single scalar integer argument, return a square
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4253 @nospell{NxN} matrix.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4254
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4255 If invoked with two or more scalar integer arguments, or a vector of integer
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4256 values, return an array with the given dimensions.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4257
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4258 The optional argument @var{class} specifies the class of the return array
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4259 and defaults to double. For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4260
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4261 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4262 val = zeros (m,n, "uint8")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4263 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4264 @seealso{ones}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4265 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4266 {
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4267 return fill_matrix (args, 0, "zeros");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4268 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4269
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4270 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4271 %!assert (zeros (3), [0, 0, 0; 0, 0, 0; 0, 0, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4272 %!assert (zeros (2, 3), [0, 0, 0; 0, 0, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4273 %!assert (zeros (3, 2), [0, 0; 0, 0; 0, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4274 %!assert (size (zeros (3, 4, 5)), [3, 4, 5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4275
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4276 %!assert (zeros (3, "single"), single ([0, 0, 0; 0, 0, 0; 0, 0, 0]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4277 %!assert (zeros (2, 3, "single"), single ([0, 0, 0; 0, 0, 0]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4278 %!assert (zeros (3, 2, "single"), single ([0, 0; 0, 0; 0, 0]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4279 %!assert (size (zeros (3, 4, 5, "single")), [3, 4, 5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4280
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4281 %!assert (zeros (3, "int8"), int8 ([0, 0, 0; 0, 0, 0; 0, 0, 0]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4282 %!assert (zeros (2, 3, "int8"), int8 ([0, 0, 0; 0, 0, 0]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4283 %!assert (zeros (3, 2, "int8"), int8 ([0, 0; 0, 0; 0, 0]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4284 %!assert (size (zeros (3, 4, 5, "int8")), [3, 4, 5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4285 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4286
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4287 DEFUN (Inf, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4288 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4289 @c List other form of function in documentation index
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4290 @findex inf
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4291
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4292 @deftypefn {} {} Inf
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4293 @deftypefnx {} {} Inf (@var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4294 @deftypefnx {} {} Inf (@var{n}, @var{m})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4295 @deftypefnx {} {} Inf (@var{n}, @var{m}, @var{k}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4296 @deftypefnx {} {} Inf (@dots{}, @var{class})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4297 Return a scalar, matrix or N-dimensional array whose elements are all equal
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4298 to the IEEE representation for positive infinity.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4299
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4300 Infinity is produced when results are too large to be represented using the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4301 IEEE floating point format for numbers. Two common examples which produce
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4302 infinity are division by zero and overflow.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4303
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4304 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4305 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4306 [ 1/0 e^800 ]
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4307 @result{} Inf Inf
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4308 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4309 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4310
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4311 When called with no arguments, return a scalar with the value @samp{Inf}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4312
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4313 When called with a single argument, return a square matrix with the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4314 dimension specified.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4315
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4316 When called with more than one scalar argument the first two arguments are
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4317 taken as the number of rows and columns and any further arguments specify
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4318 additional matrix dimensions.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4319
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4320 The optional argument @var{class} specifies the return type and may be
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4321 either @qcode{"double"} or @qcode{"single"}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4322 @seealso{isinf, NaN}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4323 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4324 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4325 return fill_matrix (args, lo_ieee_inf_value (),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4326 lo_ieee_float_inf_value (), "Inf");
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4327 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4328
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4329 DEFALIAS (inf, Inf);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4330
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4331 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4332 %!assert (inf (3), [Inf, Inf, Inf; Inf, Inf, Inf; Inf, Inf, Inf])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4333 %!assert (inf (2, 3), [Inf, Inf, Inf; Inf, Inf, Inf])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4334 %!assert (inf (3, 2), [Inf, Inf; Inf, Inf; Inf, Inf])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4335 %!assert (size (inf (3, 4, 5)), [3, 4, 5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4336
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4337 %!assert (inf (3, "single"), single ([Inf, Inf, Inf; Inf, Inf, Inf; Inf, Inf, Inf]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4338 %!assert (inf (2, 3, "single"), single ([Inf, Inf, Inf; Inf, Inf, Inf]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4339 %!assert (inf (3, 2, "single"), single ([Inf, Inf; Inf, Inf; Inf, Inf]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4340 %!assert (size (inf (3, 4, 5, "single")), [3, 4, 5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4341
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4342 %!error (inf (3, "int8"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4343 %!error (inf (2, 3, "int8"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4344 %!error (inf (3, 2, "int8"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4345 %!error (inf (3, 4, 5, "int8"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4346 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4347
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4348 DEFUN (NaN, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4349 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4350 @c List other form of function in documentation index
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4351 @findex nan
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4352
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4353 @deftypefn {} {} NaN
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4354 @deftypefnx {} {} NaN (@var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4355 @deftypefnx {} {} NaN (@var{n}, @var{m})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4356 @deftypefnx {} {} NaN (@var{n}, @var{m}, @var{k}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4357 @deftypefnx {} {} NaN (@dots{}, @var{class})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4358 Return a scalar, matrix, or N-dimensional array whose elements are all equal
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4359 to the IEEE symbol NaN (Not a Number).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4360
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4361 NaN is the result of operations which do not produce a well defined
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4362 numerical result. Common operations which produce a NaN are arithmetic
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4363 with infinity
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4364 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4365 ($\infty - \infty$), zero divided by zero ($0/0$),
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4366 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4367 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4368 (Inf - Inf), zero divided by zero (0/0),
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4369 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4370 and any operation involving another NaN value (5 + NaN).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4371
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4372 Note that NaN always compares not equal to NaN (NaN != NaN). This behavior
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4373 is specified by the IEEE standard for floating point arithmetic. To find
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4374 NaN values, use the @code{isnan} function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4375
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4376 When called with no arguments, return a scalar with the value @samp{NaN}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4377
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4378 When called with a single argument, return a square matrix with the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4379 dimension specified.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4380
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4381 When called with more than one scalar argument the first two arguments are
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4382 taken as the number of rows and columns and any further arguments specify
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4383 additional matrix dimensions.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4384
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4385 The optional argument @var{class} specifies the return type and may be
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4386 either @qcode{"double"} or @qcode{"single"}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4387 @seealso{isnan, Inf}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4388 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4389 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4390 return fill_matrix (args, lo_ieee_nan_value (),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4391 lo_ieee_float_nan_value (), "NaN");
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4392 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4393
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4394 DEFALIAS (nan, NaN);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4395
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4396 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4397 %!assert (NaN (3), [NaN, NaN, NaN; NaN, NaN, NaN; NaN, NaN, NaN])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4398 %!assert (NaN (2, 3), [NaN, NaN, NaN; NaN, NaN, NaN])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4399 %!assert (NaN (3, 2), [NaN, NaN; NaN, NaN; NaN, NaN])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4400 %!assert (size (NaN (3, 4, 5)), [3, 4, 5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4401
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4402 %!assert (NaN (3, "single"), single ([NaN, NaN, NaN; NaN, NaN, NaN; NaN, NaN, NaN]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4403 %!assert (NaN (2, 3, "single"), single ([NaN, NaN, NaN; NaN, NaN, NaN]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4404 %!assert (NaN (3, 2, "single"), single ([NaN, NaN; NaN, NaN; NaN, NaN]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4405 %!assert (size (NaN (3, 4, 5, "single")), [3, 4, 5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4406
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4407 %!error (NaN (3, "int8"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4408 %!error (NaN (2, 3, "int8"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4409 %!error (NaN (3, 2, "int8"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4410 %!error (NaN (3, 4, 5, "int8"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4411 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4412
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4413 DEFUN (e, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4414 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4415 @deftypefn {} {} e
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4416 @deftypefnx {} {} e (@var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4417 @deftypefnx {} {} e (@var{n}, @var{m})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4418 @deftypefnx {} {} e (@var{n}, @var{m}, @var{k}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4419 @deftypefnx {} {} e (@dots{}, @var{class})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4420 Return a scalar, matrix, or N-dimensional array whose elements are all equal
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4421 to the base of natural logarithms.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4422
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4423 The constant
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4424 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4425 $e$ satisfies the equation $\log (e) = 1$.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4426 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4427 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4428 @samp{e} satisfies the equation @code{log} (e) = 1.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4429 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4430
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4431 When called with no arguments, return a scalar with the value @math{e}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4432
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4433 When called with a single argument, return a square matrix with the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4434 dimension specified.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4435
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4436 When called with more than one scalar argument the first two arguments are
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4437 taken as the number of rows and columns and any further arguments specify
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4438 additional matrix dimensions.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4439
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4440 The optional argument @var{class} specifies the return type and may be
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4441 either @qcode{"double"} or @qcode{"single"}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4442 @seealso{log, exp, pi, I}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4443 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4444 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4445 #if defined (M_E)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4446 double e_val = M_E;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4447 #else
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4448 double e_val = exp (1.0);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4449 #endif
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4450
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4451 return fill_matrix (args, e_val, "e");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4452 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4453
24295
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4454 template <typename T>
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4455 T
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4456 eps (const T& x)
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4457 {
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4458 T epsval = x.abs ();
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4459 typedef typename T::value_type P;
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4460 for (octave_idx_type i = 0; i < x.numel (); i++)
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4461 {
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4462 P val = epsval.xelem (i);
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4463 if (octave::math::isnan (val) || octave::math::isinf (val))
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4464 epsval(i) = octave::numeric_limits<P>::NaN ();
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4465 else if (val < std::numeric_limits<P>::min ())
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4466 epsval(i) = std::numeric_limits<P>::denorm_min ();
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4467 else
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4468 {
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4469 int exponent;
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4470 octave::math::frexp (val, &exponent);
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4471 const P digits = std::numeric_limits<P>::digits;
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4472 epsval(i) = std::pow (static_cast<P> (2.0),
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4473 static_cast<P> (exponent - digits));
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4474 }
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4475 }
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4476 return epsval;
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4477 }
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4478
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4479 DEFUN (eps, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4480 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4481 @deftypefn {} {} eps
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4482 @deftypefnx {} {} eps (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4483 @deftypefnx {} {} eps (@var{n}, @var{m})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4484 @deftypefnx {} {} eps (@var{n}, @var{m}, @var{k}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4485 @deftypefnx {} {} eps (@dots{}, @var{class})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4486 Return a scalar, matrix or N-dimensional array whose elements are all eps,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4487 the machine precision.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4488
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4489 More precisely, @code{eps} is the relative spacing between any two adjacent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4490 numbers in the machine's floating point system. This number is obviously
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4491 system dependent. On machines that support IEEE floating point arithmetic,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4492 @code{eps} is approximately
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4493 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4494 $2.2204\times10^{-16}$ for double precision and $1.1921\times10^{-7}$
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4495 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4496 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4497 2.2204e-16 for double precision and 1.1921e-07
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4498 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4499 for single precision.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4500
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4501 When called with no arguments, return a scalar with the value
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4502 @code{eps (1.0)}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4503
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4504 Given a single argument @var{x}, return the distance between @var{x} and the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4505 next largest value.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4506
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4507 When called with more than one argument the first two arguments are taken as
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4508 the number of rows and columns and any further arguments specify additional
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4509 matrix dimensions. The optional argument @var{class} specifies the return
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4510 type and may be either @qcode{"double"} or @qcode{"single"}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4511 @seealso{realmax, realmin, intmax, flintmax}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4512 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4513 {
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4514 octave_value retval;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4515
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20816
diff changeset
4516 if (args.length () == 1 && ! args(0).is_string ())
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4517 {
24295
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4518 octave_value arg0 = args(0);
23287
953cb077757c use magnitude when computing eps for complex values (bug #50553)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
4519 if (arg0.is_single_type ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4520 {
24295
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4521 FloatNDArray epsval = eps (arg0.float_array_value ());
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4522 retval = epsval;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4523 }
24296
3981e3a11150 eps: error if input is not of floating point type
Carnë Draug <carandraug@octave.org>
parents: 24295
diff changeset
4524 else if (arg0.is_double_type ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4525 {
24295
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4526 NDArray epsval = eps (arg0.array_value ());
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4527 retval = epsval;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4528 }
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4529 else
24296
3981e3a11150 eps: error if input is not of floating point type
Carnë Draug <carandraug@octave.org>
parents: 24295
diff changeset
4530 error ("eps: X must be of a floating point type");
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4531 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4532 else
15213
336f42406671 use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
4533 retval = fill_matrix (args, std::numeric_limits<double>::epsilon (),
336f42406671 use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
4534 std::numeric_limits<float>::epsilon (), "eps");
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4535
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4536 return retval;
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4537 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4538
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4539 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4540 %!assert (eps (1/2), 2^(-53))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4541 %!assert (eps (1), 2^(-52))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4542 %!assert (eps (2), 2^(-51))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4543 %!assert (eps (realmax), 2^971)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4544 %!assert (eps (0), 2^(-1074))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4545 %!assert (eps (realmin/2), 2^(-1074))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4546 %!assert (eps (realmin/16), 2^(-1074))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4547 %!assert (eps (Inf), NaN)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4548 %!assert (eps (NaN), NaN)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4549 %!assert (eps ([1/2 1 2 realmax 0 realmin/2 realmin/16 Inf NaN]),
15509
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4550 %! [2^(-53) 2^(-52) 2^(-51) 2^971 2^(-1074) 2^(-1074) 2^(-1074) NaN NaN])
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4551 %!assert (eps (single (1/2)), single (2^(-24)))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4552 %!assert (eps (single (1)), single (2^(-23)))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4553 %!assert (eps (single (2)), single (2^(-22)))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4554 %!assert (eps (realmax ("single")), single (2^104))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4555 %!assert (eps (single (0)), single (2^(-149)))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4556 %!assert (eps (realmin ("single")/2), single (2^(-149)))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4557 %!assert (eps (realmin ("single")/16), single (2^(-149)))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4558 %!assert (eps (single (Inf)), single (NaN))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4559 %!assert (eps (single (NaN)), single (NaN))
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4560 %!assert (eps (single ([1/2 1 2 realmax("single") 0 realmin("single")/2 realmin("single")/16 Inf NaN])),
15509
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4561 %! single ([2^(-24) 2^(-23) 2^(-22) 2^104 2^(-149) 2^(-149) 2^(-149) NaN NaN]))
24296
3981e3a11150 eps: error if input is not of floating point type
Carnë Draug <carandraug@octave.org>
parents: 24295
diff changeset
4562 %!error <X must be of a floating point type> eps (uint8 ([0 1 2]))
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4563 */
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4564
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4565 DEFUN (pi, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4566 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4567 @deftypefn {} {} pi
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4568 @deftypefnx {} {} pi (@var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4569 @deftypefnx {} {} pi (@var{n}, @var{m})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4570 @deftypefnx {} {} pi (@var{n}, @var{m}, @var{k}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4571 @deftypefnx {} {} pi (@dots{}, @var{class})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4572 Return a scalar, matrix, or N-dimensional array whose elements are all equal
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4573 to the ratio of the circumference of a circle to its
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4574 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4575 diameter($\pi$).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4576 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4577 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4578 diameter.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4579 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4580
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4581 Internally, @code{pi} is computed as @samp{4.0 * atan (1.0)}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4582
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4583 When called with no arguments, return a scalar with the value of
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4584 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4585 $\pi$.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4586 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4587 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4588 pi.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4589 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4590
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4591 When called with a single argument, return a square matrix with the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4592 dimension specified.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4593
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4594 When called with more than one scalar argument the first two arguments are
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4595 taken as the number of rows and columns and any further arguments specify
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4596 additional matrix dimensions.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4597
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4598 The optional argument @var{class} specifies the return type and may be
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4599 either @qcode{"double"} or @qcode{"single"}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4600 @seealso{e, I}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4601 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4602 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4603 #if defined (M_PI)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4604 double pi_val = M_PI;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4605 #else
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4606 double pi_val = 4.0 * atan (1.0);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4607 #endif
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4608
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4609 return fill_matrix (args, pi_val, "pi");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4610 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4611
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4612 DEFUN (realmax, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4613 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4614 @deftypefn {} {} realmax
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4615 @deftypefnx {} {} realmax (@var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4616 @deftypefnx {} {} realmax (@var{n}, @var{m})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4617 @deftypefnx {} {} realmax (@var{n}, @var{m}, @var{k}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4618 @deftypefnx {} {} realmax (@dots{}, @var{class})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4619 Return a scalar, matrix, or N-dimensional array whose elements are all equal
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4620 to the largest floating point number that is representable.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4621
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4622 The actual value is system dependent. On machines that support IEEE
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4623 floating point arithmetic, @code{realmax} is approximately
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4624 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4625 $1.7977\times10^{308}$ for double precision and $3.4028\times10^{38}$
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4626 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4627 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4628 1.7977e+308 for double precision and 3.4028e+38
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4629 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4630 for single precision.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4631
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4632 When called with no arguments, return a scalar with the value
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4633 @code{realmax (@qcode{"double"})}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4634
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4635 When called with a single argument, return a square matrix with the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4636 dimension specified.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4637
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4638 When called with more than one scalar argument the first two arguments are
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4639 taken as the number of rows and columns and any further arguments specify
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4640 additional matrix dimensions.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4641
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4642 The optional argument @var{class} specifies the return type and may be
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4643 either @qcode{"double"} or @qcode{"single"}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4644 @seealso{realmin, intmax, flintmax, eps}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4645 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4646 {
15213
336f42406671 use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
4647 return fill_matrix (args, std::numeric_limits<double>::max (),
336f42406671 use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
4648 std::numeric_limits<float>::max (), "realmax");
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4649 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4650
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4651 DEFUN (realmin, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4652 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4653 @deftypefn {} {} realmin
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4654 @deftypefnx {} {} realmin (@var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4655 @deftypefnx {} {} realmin (@var{n}, @var{m})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4656 @deftypefnx {} {} realmin (@var{n}, @var{m}, @var{k}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4657 @deftypefnx {} {} realmin (@dots{}, @var{class})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4658 Return a scalar, matrix, or N-dimensional array whose elements are all equal
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4659 to the smallest normalized floating point number that is representable.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4660
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4661 The actual value is system dependent. On machines that support
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4662 IEEE floating point arithmetic, @code{realmin} is approximately
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4663 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4664 $2.2251\times10^{-308}$ for double precision and $1.1755\times10^{-38}$
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4665 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4666 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4667 2.2251e-308 for double precision and 1.1755e-38
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4668 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4669 for single precision.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4670
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4671 When called with no arguments, return a scalar with the value
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4672 @code{realmin (@qcode{"double"})}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4673
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4674 When called with a single argument, return a square matrix with the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4675 dimension specified.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4676
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4677 When called with more than one scalar argument the first two arguments are
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4678 taken as the number of rows and columns and any further arguments specify
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4679 additional matrix dimensions.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4680
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4681 The optional argument @var{class} specifies the return type and may be
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4682 either @qcode{"double"} or @qcode{"single"}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4683 @seealso{realmax, intmin, eps}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4684 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4685 {
15213
336f42406671 use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
4686 return fill_matrix (args, std::numeric_limits<double>::min (),
336f42406671 use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
4687 std::numeric_limits<float>::min (), "realmin");
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4688 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4689
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4690 DEFUN (I, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4691 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4692 @c List other forms of function in documentation index
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4693 @findex i
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4694 @findex j
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4695 @findex J
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4696
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4697 @deftypefn {} {} I
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4698 @deftypefnx {} {} I (@var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4699 @deftypefnx {} {} I (@var{n}, @var{m})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4700 @deftypefnx {} {} I (@var{n}, @var{m}, @var{k}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4701 @deftypefnx {} {} I (@dots{}, @var{class})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4702 Return a scalar, matrix, or N-dimensional array whose elements are all equal
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4703 to the pure imaginary unit, defined as
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4704 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4705 $\sqrt{-1}$.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4706 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4707 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4708 @w{@code{sqrt (-1)}}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4709 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4710
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4711 I, and its equivalents i, j, and J, are functions so any of the names may
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4712 be reused for other purposes (such as i for a counter variable).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4713
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4714 When called with no arguments, return a scalar with the value @math{i}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4715
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4716 When called with a single argument, return a square matrix with the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4717 dimension specified.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4718
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4719 When called with more than one scalar argument the first two arguments are
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4720 taken as the number of rows and columns and any further arguments specify
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4721 additional matrix dimensions.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4722
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4723 The optional argument @var{class} specifies the return type and may be
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4724 either @qcode{"double"} or @qcode{"single"}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4725 @seealso{e, pi, log, exp}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4726 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4727 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4728 return fill_matrix (args, Complex (0.0, 1.0), "I");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4729 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4730
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4731 DEFALIAS (i, I);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4732 DEFALIAS (J, I);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4733 DEFALIAS (j, I);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4734
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4735 DEFUN (NA, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4736 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4737 @deftypefn {} {} NA
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4738 @deftypefnx {} {} NA (@var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4739 @deftypefnx {} {} NA (@var{n}, @var{m})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4740 @deftypefnx {} {} NA (@var{n}, @var{m}, @var{k}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4741 @deftypefnx {} {} NA (@dots{}, @var{class})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4742 Return a scalar, matrix, or N-dimensional array whose elements are all equal
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4743 to the special constant used to designate missing values.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4744
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4745 Note that NA always compares not equal to NA (NA != NA).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4746 To find NA values, use the @code{isna} function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4747
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4748 When called with no arguments, return a scalar with the value @samp{NA}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4749
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4750 When called with a single argument, return a square matrix with the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4751 dimension specified.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4752
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4753 When called with more than one scalar argument the first two arguments are
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4754 taken as the number of rows and columns and any further arguments specify
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4755 additional matrix dimensions.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4756
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4757 The optional argument @var{class} specifies the return type and may be
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4758 either @qcode{"double"} or @qcode{"single"}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4759 @seealso{isna}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4760 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4761 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4762 return fill_matrix (args, lo_ieee_na_value (),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4763 lo_ieee_float_na_value (), "NA");
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4764 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4765
7991
139f47cf17ab Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents: 7919
diff changeset
4766 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4767 %!assert (single (NA ("double")), NA ("single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4768 %!assert (double (NA ("single")), NA ("double"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4769 */
7991
139f47cf17ab Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents: 7919
diff changeset
4770
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4771 DEFUN (false, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4772 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4773 @deftypefn {} {} false (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4774 @deftypefnx {} {} false (@var{n}, @var{m})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4775 @deftypefnx {} {} false (@var{n}, @var{m}, @var{k}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4776 Return a matrix or N-dimensional array whose elements are all logical 0.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4777
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4778 If invoked with a single scalar integer argument, return a square
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4779 matrix of the specified size.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4780
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4781 If invoked with two or more scalar integer arguments, or a vector of integer
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4782 values, return an array with given dimensions.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4783 @seealso{true}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4784 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4785 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4786 return fill_matrix (args, false, "false");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4787 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4788
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4789 DEFUN (true, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4790 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4791 @deftypefn {} {} true (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4792 @deftypefnx {} {} true (@var{n}, @var{m})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4793 @deftypefnx {} {} true (@var{n}, @var{m}, @var{k}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4794 Return a matrix or N-dimensional array whose elements are all logical 1.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4795
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4796 If invoked with a single scalar integer argument, return a square
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4797 matrix of the specified size.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4798
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4799 If invoked with two or more scalar integer arguments, or a vector of integer
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4800 values, return an array with given dimensions.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4801 @seealso{false}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4802 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4803 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4804 return fill_matrix (args, true, "true");
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
4805 }
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4806
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
4807 template <typename MT>
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4808 octave_value
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4809 identity_matrix (int nr, int nc)
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4810 {
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4811 octave_value retval;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4812
9685
e793865ede63 implement builtin_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9658
diff changeset
4813 typename MT::element_type one (1);
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4814
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4815 if (nr == 1 && nc == 1)
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4816 retval = one;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4817 else
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4818 {
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4819 dim_vector dims (nr, nc);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4820
9685
e793865ede63 implement builtin_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9658
diff changeset
4821 typename MT::element_type zero (0);
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4822
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4823 MT m (dims, zero);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4824
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4825 if (nr > 0 && nc > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4826 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4827 int n = std::min (nr, nc);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4828
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4829 for (int i = 0; i < n; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4830 m(i,i) = one;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4831 }
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4832
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4833 retval = m;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4834 }
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4835
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4836 return retval;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4837 }
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4838
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
4839 #define INSTANTIATE_EYE(T) \
5058
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4840 template octave_value identity_matrix<T> (int, int)
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4841
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4842 INSTANTIATE_EYE (int8NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4843 INSTANTIATE_EYE (uint8NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4844 INSTANTIATE_EYE (int16NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4845 INSTANTIATE_EYE (uint16NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4846 INSTANTIATE_EYE (int32NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4847 INSTANTIATE_EYE (uint32NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4848 INSTANTIATE_EYE (int64NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4849 INSTANTIATE_EYE (uint64NDArray);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
4850 INSTANTIATE_EYE (FloatNDArray);
5058
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4851 INSTANTIATE_EYE (NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4852 INSTANTIATE_EYE (boolNDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4853
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4854 static octave_value
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
4855 identity_matrix (int nr, int nc, oct_data_conv::data_type dt)
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4856 {
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4857 octave_value retval;
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4858
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4859 // FIXME: perhaps this should be made extensible by using
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4860 // the class name to lookup a function to call to create the new
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4861 // value.
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4862
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4863 switch (dt)
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4864 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4865 case oct_data_conv::dt_int8:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4866 retval = identity_matrix<int8NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4867 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4868
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4869 case oct_data_conv::dt_uint8:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4870 retval = identity_matrix<uint8NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4871 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4872
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4873 case oct_data_conv::dt_int16:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4874 retval = identity_matrix<int16NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4875 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4876
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4877 case oct_data_conv::dt_uint16:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4878 retval = identity_matrix<uint16NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4879 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4880
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4881 case oct_data_conv::dt_int32:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4882 retval = identity_matrix<int32NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4883 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4884
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4885 case oct_data_conv::dt_uint32:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4886 retval = identity_matrix<uint32NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4887 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4888
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4889 case oct_data_conv::dt_int64:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4890 retval = identity_matrix<int64NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4891 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4892
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4893 case oct_data_conv::dt_uint64:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4894 retval = identity_matrix<uint64NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4895 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4896
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4897 case oct_data_conv::dt_single:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4898 retval = FloatDiagMatrix (nr, nc, 1.0f);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4899 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4900
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4901 case oct_data_conv::dt_double:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4902 retval = DiagMatrix (nr, nc, 1.0);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4903 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4904
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4905 case oct_data_conv::dt_logical:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4906 retval = identity_matrix<boolNDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4907 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4908
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4909 default:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4910 error ("eye: invalid class name");
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4911 break;
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4912 }
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4913
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4914 return retval;
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4915 }
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4916
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4917 #undef INT_EYE_MATRIX
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4918
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
4919 DEFUN (eye, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4920 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4921 @deftypefn {} {} eye (@var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4922 @deftypefnx {} {} eye (@var{m}, @var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4923 @deftypefnx {} {} eye ([@var{m} @var{n}])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4924 @deftypefnx {} {} eye (@dots{}, @var{class})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4925 Return an identity matrix.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4926
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4927 If invoked with a single scalar argument @var{n}, return a square
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4928 @nospell{NxN} identity matrix.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4929
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4930 If supplied two scalar arguments (@var{m}, @var{n}), @code{eye} takes them
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4931 to be the number of rows and columns. If given a vector with two elements,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4932 @code{eye} uses the values of the elements as the number of rows and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4933 columns, respectively. For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4934
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4935 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4936 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4937 eye (3)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4938 @result{} 1 0 0
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4939 0 1 0
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4940 0 0 1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4941 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4942 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4943
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4944 The following expressions all produce the same result:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4945
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4946 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4947 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4948 eye (2)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4949 @equiv{}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4950 eye (2, 2)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4951 @equiv{}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4952 eye (size ([1, 2; 3, 4]))
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4953 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4954 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4955
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4956 The optional argument @var{class}, allows @code{eye} to return an array of
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4957 the specified type, like
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4958
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4959 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4960 val = zeros (n,m, "uint8")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4961 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4962
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4963 Calling @code{eye} with no arguments is equivalent to calling it with an
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4964 argument of 1. Any negative dimensions are treated as zero. These odd
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4965 definitions are for compatibility with @sc{matlab}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4966 @seealso{speye, ones, zeros}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4967 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4968 {
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
4969 int nargin = args.length ();
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4970
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
4971 oct_data_conv::data_type dt = oct_data_conv::dt_double;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4972
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4973 // Check for type information.
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4974
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4975 if (nargin > 0 && args(nargin-1).is_string ())
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4976 {
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
4977 std::string nm = args(nargin-1).string_value ();
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4978 nargin--;
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
4979
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
4980 dt = oct_data_conv::string_to_data_type (nm);
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4981 }
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4982
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4983 if (nargin > 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4984 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4985
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
4986 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
4987
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4988 if (nargin == 0)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4989 retval = identity_matrix (1, 1, dt);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4990 else if (nargin == 1)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4991 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4992 octave_idx_type nr, nc;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4993 get_dimensions (args(0), "eye", nr, nc);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4994
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4995 retval = identity_matrix (nr, nc, dt);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4996 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4997 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4998 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4999 octave_idx_type nr, nc;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5000 get_dimensions (args(0), args(1), "eye", nr, nc);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5001
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5002 retval = identity_matrix (nr, nc, dt);
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5003 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5004
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5005 return retval;
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5006 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5007
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5008 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5009 %!assert (full (eye (3)), [1, 0, 0; 0, 1, 0; 0, 0, 1])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5010 %!assert (full (eye (2, 3)), [1, 0, 0; 0, 1, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5011
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5012 %!assert (full (eye (3,"single")), single ([1, 0, 0; 0, 1, 0; 0, 0, 1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5013 %!assert (full (eye (2, 3,"single")), single ([1, 0, 0; 0, 1, 0]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5014
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5015 %!assert (eye (3, "int8"), int8 ([1, 0, 0; 0, 1, 0; 0, 0, 1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5016 %!assert (eye (2, 3, "int8"), int8 ([1, 0, 0; 0, 1, 0]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5017
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5018 %!error eye (1, 2, 3)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5019 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5020
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
5021 template <typename MT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
5022 static octave_value
9658
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5023 do_linspace (const octave_value& base, const octave_value& limit,
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5024 octave_idx_type n)
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5025 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5026 typedef typename MT::column_vector_type CVT;
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5027 typedef typename MT::element_type T;
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5028
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5029 octave_value retval;
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5030
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5031 if (base.is_scalar_type ())
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5032 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5033 T bs = octave_value_extract<T> (base);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5034 if (limit.is_scalar_type ())
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5035 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5036 T ls = octave_value_extract<T> (limit);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5037 retval = linspace (bs, ls, n);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5038 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5039 else
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5040 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5041 CVT lv = octave_value_extract<CVT> (limit);
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
5042 CVT bv (lv.numel (), bs);
9658
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5043 retval = linspace (bv, lv, n);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5044 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5045 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5046 else
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5047 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5048 CVT bv = octave_value_extract<CVT> (base);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5049 if (limit.is_scalar_type ())
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5050 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5051 T ls = octave_value_extract<T> (limit);
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
5052 CVT lv (bv.numel (), ls);
9658
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5053 retval = linspace (bv, lv, n);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5054 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5055 else
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5056 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5057 CVT lv = octave_value_extract<CVT> (limit);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5058 retval = linspace (bv, lv, n);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5059 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5060 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5061
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5062 return retval;
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5063 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5064
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
5065 DEFUN (linspace, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5066 doc: /* -*- texinfo -*-
24504
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5067 @deftypefn {} {} linspace (@var{start}, @var{end})
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5068 @deftypefnx {} {} linspace (@var{start}, @var{end}, @var{n})
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5069 Return a row vector with @var{n} linearly spaced elements between @var{start}
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5070 and @var{end}.
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5071
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5072 If the number of elements is greater than one, then the endpoints @var{start}
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5073 and @var{end} are always included in the range. If @var{start} is greater than
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5074 @var{end}, the elements are stored in decreasing order. If the number of
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5075 points is not specified, a value of 100 is used.
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5076
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5077 The @code{linspace} function returns a row vector when both @var{start} and
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5078 @var{end} are scalars. If one, or both, inputs are vectors, then
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5079 @code{linspace} transforms them to column vectors and returns a matrix where
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5080 each row is an independent sequence between
24504
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5081 @w{@code{@var{start}(@var{row_n}), @var{end}(@var{row_n})}}.
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5082
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5083 For compatibility with @sc{matlab}, return the second argument (@var{end}) when
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5084 only a single value (@var{n} = 1) is requested.
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5085 @seealso{colon, logspace}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5086 @end deftypefn */)
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5087 {
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5088 int nargin = args.length ();
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5089
1940
1b193e313c56 [project @ 1996-02-13 16:28:47 by jwe]
jwe
parents: 1884
diff changeset
5090 if (nargin != 2 && nargin != 3)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5091 print_usage ();
1940
1b193e313c56 [project @ 1996-02-13 16:28:47 by jwe]
jwe
parents: 1884
diff changeset
5092
6133
e0065af38cf4 [project @ 2006-11-02 03:33:50 by jwe]
jwe
parents: 5991
diff changeset
5093 octave_idx_type npoints = 100;
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5094 if (nargin == 3)
16077
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
5095 {
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
5096 // Apparently undocumented Matlab. If the third arg is an empty
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
5097 // numeric value, the number of points defaults to 1.
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
5098 octave_value arg_3 = args(2);
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
5099
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
5100 if (arg_3.isnumeric () && arg_3.isempty ())
16077
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
5101 npoints = 1;
20466
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5102 else if (! arg_3.is_scalar_type ())
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5103 error ("linspace: N must be a scalar");
16077
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
5104 else
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5105 // Even if third arg is not an integer, it must be cast to int
16077
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
5106 npoints = arg_3.idx_type_value ();
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
5107 }
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5108
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5109 octave_value arg_1 = args(0);
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5110 octave_value arg_2 = args(1);
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5111
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5112 dim_vector sz1 = arg_1.dims ();
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21602
diff changeset
5113 bool isvector1 = sz1.ndims () == 2 && (sz1(0) == 1 || sz1(1) == 1);
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5114 dim_vector sz2 = arg_2.dims ();
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21602
diff changeset
5115 bool isvector2 = sz2.ndims () == 2 && (sz2(0) == 1 || sz2(1) == 1);
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5116
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5117 if (! isvector1 || ! isvector2)
24535
22a2bc91cc7f Add more BIST tests for linspace.
Rik <rik@octave.org>
parents: 24534
diff changeset
5118 error ("linspace: START, END must be scalars or vectors");
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5119
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5120 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5121
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5122 if (arg_1.is_single_type () || arg_2.is_single_type ())
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5123 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
5124 if (arg_1.iscomplex () || arg_2.iscomplex ())
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5125 retval = do_linspace<FloatComplexMatrix> (arg_1, arg_2, npoints);
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5126 else
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5127 retval = do_linspace<FloatMatrix> (arg_1, arg_2, npoints);
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5128 }
4732
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4685
diff changeset
5129 else
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5130 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
5131 if (arg_1.iscomplex () || arg_2.iscomplex ())
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5132 retval = do_linspace<ComplexMatrix> (arg_1, arg_2, npoints);
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5133 else
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5134 retval = do_linspace<Matrix> (arg_1, arg_2, npoints);
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5135 }
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5136
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5137 return retval;
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5138 }
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5139
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5140 /*
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5141 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5142 %! x1 = linspace (1, 2);
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5143 %! x2 = linspace (1, 2, 10);
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5144 %! x3 = linspace (1, -2, 10);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5145 %! assert (size (x1) == [1, 100] && x1(1) == 1 && x1(100) == 2);
24536
bcaeb5439707 Fix typos and add tolerance to linspace BIST tests in 22a2bc91cc7f.
Rik <rik@octave.org>
parents: 24535
diff changeset
5146 %! assert (x1(2) - x1(1), (2 - 1)/ (100 - 1), eps);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5147 %! assert (size (x2) == [1, 10] && x2(1) == 1 && x2(10) == 2);
24536
bcaeb5439707 Fix typos and add tolerance to linspace BIST tests in 22a2bc91cc7f.
Rik <rik@octave.org>
parents: 24535
diff changeset
5148 %! assert (x2(2) - x2(1), (2 - 1)/ (10 - 1), eps);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5149 %! assert (size (x3) == [1, 10] && x3(1) == 1 && x3(10) == -2);
24543
0c204cd762a4 Fix reversal of START,END in linspace BIST test in cset 22a2bc91cc7f.
Rik <rik@octave.org>
parents: 24540
diff changeset
5150 %! assert (x3(2) - x3(1), (-2 - 1)/ (10 - 1), eps);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5151
20466
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5152 ## Test complex values
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5153 %!test
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5154 %! exp = [1+0i, 2-1.25i, 3-2.5i, 4-3.75i, 5-5i];
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5155 %! obs = linspace (1, 5-5i, 5);
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5156 %! assert (obs, exp);
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5157
24535
22a2bc91cc7f Add more BIST tests for linspace.
Rik <rik@octave.org>
parents: 24534
diff changeset
5158 ## Test support for vectors in START and END
20574
780431fc4137 linspace: add tests for the use of vectors as base and limit.
Carnë Draug <carandraug@octave.org>
parents: 20573
diff changeset
5159 %!assert (linspace ([1 2 3], [7 8 9]),
22495
ad815427f376 Add 10*eps tolerance for linspace tests to pass on Windows (bug #49092).
Rik <rik@octave.org>
parents: 22489
diff changeset
5160 %! [linspace(1, 7); linspace(2, 8); linspace(3, 9)], 10*eps)
20574
780431fc4137 linspace: add tests for the use of vectors as base and limit.
Carnë Draug <carandraug@octave.org>
parents: 20573
diff changeset
5161 %!assert (linspace ([1 2 3]', [7 8 9]'),
22495
ad815427f376 Add 10*eps tolerance for linspace tests to pass on Windows (bug #49092).
Rik <rik@octave.org>
parents: 22489
diff changeset
5162 %! [linspace(1, 7); linspace(2, 8); linspace(3, 9)], 10*eps)
20574
780431fc4137 linspace: add tests for the use of vectors as base and limit.
Carnë Draug <carandraug@octave.org>
parents: 20573
diff changeset
5163 %!assert (linspace ([1 2 3], 9),
22495
ad815427f376 Add 10*eps tolerance for linspace tests to pass on Windows (bug #49092).
Rik <rik@octave.org>
parents: 22489
diff changeset
5164 %! [linspace(1, 9); linspace(2, 9); linspace(3, 9)], 10*eps)
20574
780431fc4137 linspace: add tests for the use of vectors as base and limit.
Carnë Draug <carandraug@octave.org>
parents: 20573
diff changeset
5165 %!assert (linspace ([1 2 3]', 9),
22495
ad815427f376 Add 10*eps tolerance for linspace tests to pass on Windows (bug #49092).
Rik <rik@octave.org>
parents: 22489
diff changeset
5166 %! [linspace(1, 9); linspace(2, 9); linspace(3, 9)], 10*eps)
20574
780431fc4137 linspace: add tests for the use of vectors as base and limit.
Carnë Draug <carandraug@octave.org>
parents: 20573
diff changeset
5167 %!assert (linspace (1, [7 8 9]),
22495
ad815427f376 Add 10*eps tolerance for linspace tests to pass on Windows (bug #49092).
Rik <rik@octave.org>
parents: 22489
diff changeset
5168 %! [linspace(1, 7); linspace(1, 8); linspace(1, 9)], 10*eps)
20574
780431fc4137 linspace: add tests for the use of vectors as base and limit.
Carnë Draug <carandraug@octave.org>
parents: 20573
diff changeset
5169 %!assert (linspace (1, [7 8 9]'),
22495
ad815427f376 Add 10*eps tolerance for linspace tests to pass on Windows (bug #49092).
Rik <rik@octave.org>
parents: 22489
diff changeset
5170 %! [linspace(1, 7); linspace(1, 8); linspace(1, 9)], 10*eps)
20574
780431fc4137 linspace: add tests for the use of vectors as base and limit.
Carnë Draug <carandraug@octave.org>
parents: 20573
diff changeset
5171
20466
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5172 ## Test class of output
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5173 %!assert (class (linspace (1, 2)), "double")
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5174 %!assert (class (linspace (single (1), 2)), "single")
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5175 %!assert (class (linspace (1, single (2))), "single")
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5176
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5177 ## Test obscure Matlab compatibility options
17206
ea5830dc6b19 test: Correct typo '%assert' -> '%!assert' to have test blocks run.
Rik <rik@octave.org>
parents: 17115
diff changeset
5178 %!assert (linspace (0, 1, []), 1)
20466
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5179 %!assert (linspace (10, 20, 2), [10 20])
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5180 %!assert (linspace (10, 20, 1), [20])
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5181 %!assert (linspace (10, 20, 0), zeros (1, 0))
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5182 %!assert (linspace (10, 20, -1), zeros (1, 0))
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5183 %!assert (numel (linspace (0, 1, 2+eps)), 2)
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5184 %!assert (numel (linspace (0, 1, 2-eps)), 1)
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5185 %!assert (linspace (10, 20, 2.1), [10 20])
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5186 %!assert (linspace (10, 20, 2.9), [10 20])
24535
22a2bc91cc7f Add more BIST tests for linspace.
Rik <rik@octave.org>
parents: 24534
diff changeset
5187 %!assert (1 ./ linspace (-0, 0, 4), [-Inf, Inf, Inf, Inf])
16077
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
5188
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5189 %!error linspace ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5190 %!error linspace (1, 2, 3, 4)
20466
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5191 %!error <N must be a scalar> linspace (1, 2, [3, 4])
24535
22a2bc91cc7f Add more BIST tests for linspace.
Rik <rik@octave.org>
parents: 24534
diff changeset
5192 %!error <START, END must be scalars or vectors> linspace (ones (2,2), 2, 3)
22a2bc91cc7f Add more BIST tests for linspace.
Rik <rik@octave.org>
parents: 24534
diff changeset
5193 %!error <START, END must be scalars or vectors> linspace (2, ones (2,2), 3)
22a2bc91cc7f Add more BIST tests for linspace.
Rik <rik@octave.org>
parents: 24534
diff changeset
5194 %!error <START, END must be scalars or vectors> linspace (1, [], 3)
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5195 */
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5196
20726
25d676f9619c Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents: 20720
diff changeset
5197 // FIXME: should accept dimensions as separate args for N-D
25d676f9619c Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents: 20720
diff changeset
5198 // arrays as well as 1-D and 2-D arrays.
5734
a7d2c47371d2 [project @ 2006-04-04 18:29:13 by jwe]
jwe
parents: 5731
diff changeset
5199
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5200 DEFUN (resize, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5201 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5202 @deftypefn {} {} resize (@var{x}, @var{m})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5203 @deftypefnx {} {} resize (@var{x}, @var{m}, @var{n}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5204 @deftypefnx {} {} resize (@var{x}, [@var{m} @var{n} @dots{}])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5205 Resize @var{x} cutting off elements as necessary.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5206
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5207 In the result, element with certain indices is equal to the corresponding
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5208 element of @var{x} if the indices are within the bounds of @var{x};
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5209 otherwise, the element is set to zero.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5210
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5211 In other words, the statement
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5212
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5213 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5214 y = resize (x, dv)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5215 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5216
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5217 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5218 is equivalent to the following code:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5219
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5220 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5221 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5222 y = zeros (dv, class (x));
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5223 sz = min (dv, size (x));
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5224 for i = 1:length (sz)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5225 idx@{i@} = 1:sz(i);
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5226 endfor
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5227 y(idx@{:@}) = x(idx@{:@});
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5228 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5229 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5230
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5231 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5232 but is performed more efficiently.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5233
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5234 If only @var{m} is supplied, and it is a scalar, the dimension of the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5235 result is @var{m}-by-@var{m}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5236 If @var{m}, @var{n}, @dots{} are all scalars, then the dimensions of
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5237 the result are @var{m}-by-@var{n}-by-@dots{}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5238 If given a vector as input, then the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5239 dimensions of the result are given by the elements of that vector.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5240
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5241 An object can be resized to more dimensions than it has;
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5242 in such case the missing dimensions are assumed to be 1.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5243 Resizing an object to fewer dimensions is not possible.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5244 @seealso{reshape, postpad, prepad, cat}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5245 @end deftypefn */)
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5246 {
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5247 int nargin = args.length ();
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5248
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5249 if (nargin < 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5250 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5251
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5252 octave_value retval;
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5253
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5254 if (nargin == 2)
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5255 {
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5256 Array<double> vec = args(1).vector_value ();
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
5257 int ndim = vec.numel ();
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5258 if (ndim == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5259 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5260 octave_idx_type m = static_cast<octave_idx_type> (vec(0));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5261 retval = args(0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5262 retval = retval.resize (dim_vector (m, m), true);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5263 }
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5264 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5265 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5266 dim_vector dv;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5267 dv.resize (ndim);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5268 for (int i = 0; i < ndim; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5269 dv(i) = static_cast<octave_idx_type> (vec(i));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5270 retval = args(0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5271 retval = retval.resize (dv, true);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5272 }
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5273 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5274 else
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5275 {
8799
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
5276 dim_vector dv;
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
5277 dv.resize (nargin - 1);
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
5278 for (octave_idx_type i = 1; i < nargin; i++)
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
5279 dv(i-1) = static_cast<octave_idx_type> (args(i).scalar_value ());
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5280
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5281 retval = args(0);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5282 retval = retval.resize (dv, true);
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5283 }
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5284
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5285 return retval;
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5286 }
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5287
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5288 // FIXME: should use octave_idx_type for dimensions.
5734
a7d2c47371d2 [project @ 2006-04-04 18:29:13 by jwe]
jwe
parents: 5731
diff changeset
5289
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5290 DEFUN (reshape, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5291 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5292 @deftypefn {} {} reshape (@var{A}, @var{m}, @var{n}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5293 @deftypefnx {} {} reshape (@var{A}, [@var{m} @var{n} @dots{}])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5294 @deftypefnx {} {} reshape (@var{A}, @dots{}, [], @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5295 @deftypefnx {} {} reshape (@var{A}, @var{size})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5296 Return a matrix with the specified dimensions (@var{m}, @var{n}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5297 whose elements are taken from the matrix @var{A}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5298
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5299 The elements of the matrix are accessed in column-major order (like Fortran
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5300 arrays are stored).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5301
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5302 The following code demonstrates reshaping a 1x4 row vector into a 2x2 square
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5303 matrix.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5304
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5305 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5306 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5307 reshape ([1, 2, 3, 4], 2, 2)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5308 @result{} 1 3
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5309 2 4
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5310 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5311 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5312
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5313 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5314 Note that the total number of elements in the original matrix
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5315 (@code{prod (size (@var{A}))}) must match the total number of elements
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5316 in the new matrix (@code{prod ([@var{m} @var{n} @dots{}])}).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5317
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5318 A single dimension of the return matrix may be left unspecified and Octave
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5319 will determine its size automatically. An empty matrix ([]) is used to flag
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5320 the unspecified dimension.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5321 @seealso{resize, vec, postpad, cat, squeeze}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5322 @end deftypefn */)
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5323 {
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5324 int nargin = args.length ();
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5325
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5326 if (nargin < 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5327 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5328
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5329 octave_value retval;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5330
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5331 dim_vector new_dims;
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5332
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5333 if (nargin == 2)
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5334 {
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5335 Array<octave_idx_type> new_size = args(1).octave_idx_type_vector_value ();
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5336
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
5337 if (new_size.numel () < 2)
20893
384ff5aa9437 2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents: 20884
diff changeset
5338 error ("reshape: SIZE must have 2 or more dimensions");
17915
56d2b6838405 Issue an error if reshape called with just a single dimension.
Rik <rik@octave.org>
parents: 17843
diff changeset
5339
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
5340 new_dims = dim_vector::alloc (new_size.numel ());
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
5341
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
5342 for (octave_idx_type i = 0; i < new_size.numel (); i++)
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5343 {
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5344 if (new_size(i) < 0)
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5345 error ("reshape: SIZE must be non-negative");
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5346
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5347 new_dims(i) = new_size(i);
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5348 }
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5349 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5350 else
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5351 {
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5352 new_dims = dim_vector::alloc (nargin-1);
5013
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
5353 int empty_dim = -1;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
5354
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5355 for (int i = 1; i < nargin; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5356 {
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
5357 if (args(i).isempty ())
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5358 {
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5359 if (empty_dim > 0)
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5360 error ("reshape: only a single dimension can be unknown");
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5361
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5362 empty_dim = i;
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5363 new_dims(i-1) = 1;
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5364 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5365 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5366 {
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5367 new_dims(i-1) = args(i).idx_type_value ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5368
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5369 if (new_dims(i-1) < 0)
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5370 error ("reshape: SIZE must be non-negative");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5371 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5372 }
5013
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
5373
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5374 if (empty_dim > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5375 {
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5376 octave_idx_type nel = new_dims.numel ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5377
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5378 if (nel == 0)
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5379 new_dims(empty_dim-1) = 0;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5380 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5381 {
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5382 octave_idx_type a_nel = args(0).numel ();
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5383 octave_idx_type size_empty_dim = a_nel / nel;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
5384
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5385 if (a_nel != size_empty_dim * nel)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5386 error ("reshape: SIZE is not divisible by the product of known dimensions (= %d)",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5387 nel);
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5388
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5389 new_dims(empty_dim-1) = size_empty_dim;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5390 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5391 }
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5392 }
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5393
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5394 retval = args(0).reshape (new_dims);
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5395
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5396 return retval;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5397 }
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5398
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5399 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5400 %!assert (size (reshape (ones (4, 4), 2, 8)), [2, 8])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5401 %!assert (size (reshape (ones (4, 4), 8, 2)), [8, 2])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5402 %!assert (size (reshape (ones (15, 4), 1, 60)), [1, 60])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5403 %!assert (size (reshape (ones (15, 4), 60, 1)), [60, 1])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5404
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5405 %!assert (size (reshape (ones (4, 4, "single"), 2, 8)), [2, 8])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5406 %!assert (size (reshape (ones (4, 4, "single"), 8, 2)), [8, 2])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5407 %!assert (size (reshape (ones (15, 4, "single"), 1, 60)), [1, 60])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5408 %!assert (size (reshape (ones (15, 4, "single"), 60, 1)), [60, 1])
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5409
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5410 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5411 %! s.a = 1;
17915
56d2b6838405 Issue an error if reshape called with just a single dimension.
Rik <rik@octave.org>
parents: 17843
diff changeset
5412 %! fail ("reshape (s, 2, 3)", "can't reshape 1x1 array to 2x3 array");
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5413
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5414 %!error reshape ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5415 %!error reshape (1, 2, 3, 4)
17915
56d2b6838405 Issue an error if reshape called with just a single dimension.
Rik <rik@octave.org>
parents: 17843
diff changeset
5416 %!error <SIZE must have 2 or more dimensions> reshape (1:3, 3)
56d2b6838405 Issue an error if reshape called with just a single dimension.
Rik <rik@octave.org>
parents: 17843
diff changeset
5417 %!error <SIZE must be non-negative> reshape (1:3, [3 -1])
56d2b6838405 Issue an error if reshape called with just a single dimension.
Rik <rik@octave.org>
parents: 17843
diff changeset
5418 %!error <only a single dimension can be unknown> reshape (1:3, 1,[],[],3)
56d2b6838405 Issue an error if reshape called with just a single dimension.
Rik <rik@octave.org>
parents: 17843
diff changeset
5419 %!error <SIZE must be non-negative> reshape (1:3, 3, -1)
56d2b6838405 Issue an error if reshape called with just a single dimension.
Rik <rik@octave.org>
parents: 17843
diff changeset
5420 %!error <SIZE is not divisible> reshape (1:3, 3, [], 2)
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5421 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5422
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5423 DEFUN (vec, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5424 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5425 @deftypefn {} {@var{v} =} vec (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5426 @deftypefnx {} {@var{v} =} vec (@var{x}, @var{dim})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5427 Return the vector obtained by stacking the columns of the matrix @var{x}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5428 one above the other.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5429
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5430 Without @var{dim} this is equivalent to @code{@var{x}(:)}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5431
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5432 If @var{dim} is supplied, the dimensions of @var{v} are set to @var{dim}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5433 with all elements along the last dimension. This is equivalent to
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5434 @code{shiftdim (@var{x}(:), 1-@var{dim})}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5435 @seealso{vech, resize, cat}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5436 @end deftypefn */)
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5437 {
11402
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5438 int nargin = args.length ();
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5439
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5440 if (nargin < 1 || nargin > 2)
21602
47c76e56a1de maint: Remove extra space between end of statement and semicolon.
Rik <rik@octave.org>
parents: 21580
diff changeset
5441 print_usage ();
11402
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5442
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5443 int dim = 1;
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5444 if (nargin == 2)
11402
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5445 {
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5446 dim = args(1).idx_type_value ();
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5447
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5448 if (dim < 1)
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
5449 error ("vec: DIM must be greater than zero");
11402
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5450 }
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5451
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5452 octave_value colon (octave_value::magic_colon_t);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5453 octave_value arg = args(0);
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5454
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5455 octave_value retval = arg.single_subsref ("(", colon);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5456
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5457 if (dim > 1)
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5458 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5459 dim_vector new_dims = dim_vector::alloc (dim);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5460
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5461 for (int i = 0; i < dim-1; i++)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5462 new_dims(i) = 1;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5463
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5464 new_dims(dim-1) = retval.numel ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5465
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5466 retval = retval.reshape (new_dims);
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5467 }
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5468
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5469 return retval;
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5470 }
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5471
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5472 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5473 %!assert (vec ([1, 2; 3, 4]), [1; 3; 2; 4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5474 %!assert (vec ([1, 3, 2, 4]), [1; 3; 2; 4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5475 %!assert (vec ([1, 2, 3, 4], 2), [1, 2, 3, 4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5476 %!assert (vec ([1, 2; 3, 4]), vec ([1, 2; 3, 4], 1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5477 %!assert (vec ([1, 2; 3, 4], 1), [1; 3; 2; 4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5478 %!assert (vec ([1, 2; 3, 4], 2), [1, 3, 2, 4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5479 %!assert (vec ([1, 3; 2, 4], 3), reshape ([1, 2, 3, 4], 1, 1, 4))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5480 %!assert (vec ([1, 3; 2, 4], 3), shiftdim (vec ([1, 3; 2, 4]), -2))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5481
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5482 %!error vec ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5483 %!error vec (1, 2, 3)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5484 %!error vec ([1, 2; 3, 4], 0)
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5485 */
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5486
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
5487 DEFUN (squeeze, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5488 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5489 @deftypefn {} {} squeeze (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5490 Remove singleton dimensions from @var{x} and return the result.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5491
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5492 Note that for compatibility with @sc{matlab}, all objects have
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5493 a minimum of two dimensions and row vectors are left unchanged.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5494 @seealso{reshape}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5495 @end deftypefn */)
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
5496 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5497 if (args.length () != 1)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
5498 print_usage ();
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
5499
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
5500 return ovl (args(0).squeeze ());
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
5501 }
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
5502
8458
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
5503 DEFUN (full, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5504 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5505 @deftypefn {} {@var{FM} =} full (@var{SM})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5506 Return a full storage matrix from a sparse, diagonal, or permutation matrix,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5507 or a range.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5508 @seealso{sparse, issparse}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5509 @end deftypefn */)
8458
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
5510 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5511 if (args.length () != 1)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
5512 print_usage ();
8458
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
5513
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
5514 return ovl (args(0).full_value ());
8458
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
5515 }
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
5516
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6887
diff changeset
5517 // Compute various norms of the vector X.
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6887
diff changeset
5518
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
5519 DEFUN (norm, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5520 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5521 @deftypefn {} {} norm (@var{A})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5522 @deftypefnx {} {} norm (@var{A}, @var{p})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5523 @deftypefnx {} {} norm (@var{A}, @var{p}, @var{opt})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5524 Compute the p-norm of the matrix @var{A}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5525
22827
c3d3a81ad986 doc: Update documentation for norm, normest, normest1, condest.
Rik <rik@octave.org>
parents: 22791
diff changeset
5526 If the second argument is not given, @w{@code{p = 2}} is used.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5527
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5528 If @var{A} is a matrix (or sparse matrix):
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5529
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5530 @table @asis
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5531 @item @var{p} = @code{1}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5532 1-norm, the largest column sum of the absolute values of @var{A}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5533
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5534 @item @var{p} = @code{2}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5535 Largest singular value of @var{A}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5536
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5537 @item @var{p} = @code{Inf} or @qcode{"inf"}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5538 @cindex infinity norm
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5539 Infinity norm, the largest row sum of the absolute values of @var{A}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5540
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5541 @item @var{p} = @qcode{"fro"}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5542 @cindex Frobenius norm
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5543 Frobenius norm of @var{A}, @code{sqrt (sum (diag (@var{A}' * @var{A})))}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5544
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5545 @item other @var{p}, @code{@var{p} > 1}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5546 @cindex general p-norm
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5547 maximum @code{norm (A*x, p)} such that @code{norm (x, p) == 1}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5548 @end table
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5549
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5550 If @var{A} is a vector or a scalar:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5551
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5552 @table @asis
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5553 @item @var{p} = @code{Inf} or @qcode{"inf"}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5554 @code{max (abs (@var{A}))}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5555
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5556 @item @var{p} = @code{-Inf}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5557 @code{min (abs (@var{A}))}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5558
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5559 @item @var{p} = @qcode{"fro"}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5560 Frobenius norm of @var{A}, @code{sqrt (sumsq (abs (A)))}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5561
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5562 @item @var{p} = 0
22827
c3d3a81ad986 doc: Update documentation for norm, normest, normest1, condest.
Rik <rik@octave.org>
parents: 22791
diff changeset
5563 Hamming norm---the number of nonzero elements.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5564
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5565 @item other @var{p}, @code{@var{p} > 1}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5566 p-norm of @var{A}, @code{(sum (abs (@var{A}) .^ @var{p})) ^ (1/@var{p})}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5567
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5568 @item other @var{p} @code{@var{p} < 1}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5569 the p-pseudonorm defined as above.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5570 @end table
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5571
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5572 If @var{opt} is the value @qcode{"rows"}, treat each row as a vector and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5573 compute its norm. The result is returned as a column vector.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5574 Similarly, if @var{opt} is @qcode{"columns"} or @qcode{"cols"} then
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5575 compute the norms of each column and return a row vector.
24219
3d96400df713 Add function vecnorm (bug #52342).
Marco Caliari <marco.caliari@univr.it>
parents: 24088
diff changeset
5576 @seealso{normest, normest1, vecnorm, cond, svd}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5577 @end deftypefn */)
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
5578 {
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
5579 int nargin = args.length ();
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
5580
22789
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
5581 if (nargin < 1 || nargin > 3)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5582 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5583
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5584 octave_value x_arg = args(0);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5585
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5586 if (x_arg.ndims () != 2)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5587 error ("norm: only valid for 2-D objects");
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5588
23147
eb5a162c1342 Accept case-insensitive string value for p-value input to norm (bug #50195);
Rik <rik@octave.org>
parents: 23141
diff changeset
5589 enum {sfmatrix, sfcols, sfrows, sffrob, sfinf, sfneginf} strflag = sfmatrix;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5590 if (nargin > 1 && args(nargin-1).is_string ())
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
5591 {
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5592 std::string str = args(nargin-1).string_value ();
23147
eb5a162c1342 Accept case-insensitive string value for p-value input to norm (bug #50195);
Rik <rik@octave.org>
parents: 23141
diff changeset
5593 std::transform (str.begin (), str.end (), str.begin (), tolower);
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5594 if (str == "cols" || str == "columns")
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5595 strflag = sfcols;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5596 else if (str == "rows")
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5597 strflag = sfrows;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5598 else if (str == "fro")
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5599 strflag = sffrob;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5600 else if (str == "inf")
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5601 strflag = sfinf;
23147
eb5a162c1342 Accept case-insensitive string value for p-value input to norm (bug #50195);
Rik <rik@octave.org>
parents: 23141
diff changeset
5602 else if (str == "-inf")
eb5a162c1342 Accept case-insensitive string value for p-value input to norm (bug #50195);
Rik <rik@octave.org>
parents: 23141
diff changeset
5603 strflag = sfneginf;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5604 else
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5605 error ("norm: unrecognized option: %s", str.c_str ());
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
5606
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5607 // we've handled the last parameter, so act as if it was removed
21062
d9c1884d1aaa maint: Eliminate space between variable and decrement '--' operator.
Rik <rik@octave.org>
parents: 21055
diff changeset
5608 nargin--;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5609 }
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5610
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5611 octave_value p_arg = (nargin > 1) ? args(1) : octave_value (2);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5612
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
5613 if (p_arg.isempty ())
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5614 p_arg = octave_value (2);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5615 else if (p_arg.is_string ())
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
5616 {
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5617 std::string str = p_arg.string_value ();
23147
eb5a162c1342 Accept case-insensitive string value for p-value input to norm (bug #50195);
Rik <rik@octave.org>
parents: 23141
diff changeset
5618 std::transform (str.begin (), str.end (), str.begin (), tolower);
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5619 if (strflag != sfcols && strflag != sfrows)
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5620 error ("norm: invalid combination of options");
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5621
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5622 if (str == "cols" || str == "columns" || str == "rows")
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5623 error ("norm: invalid combination of options");
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5624
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5625 if (str == "fro")
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5626 p_arg = octave_value (2);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5627 else if (str == "inf")
21723
bae585228161 use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents: 21721
diff changeset
5628 p_arg = octave::numeric_limits<double>::Inf ();
23147
eb5a162c1342 Accept case-insensitive string value for p-value input to norm (bug #50195);
Rik <rik@octave.org>
parents: 23141
diff changeset
5629 else if (str == "-inf")
eb5a162c1342 Accept case-insensitive string value for p-value input to norm (bug #50195);
Rik <rik@octave.org>
parents: 23141
diff changeset
5630 p_arg = -octave::numeric_limits<double>::Inf ();
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
5631 else
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5632 error ("norm: unrecognized option: %s", str.c_str ());
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
5633 }
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5634 else if (! p_arg.is_scalar_type ())
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
5635 err_wrong_type_arg ("norm", p_arg);
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5636
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5637 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5638
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5639 switch (strflag)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5640 {
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5641 case sfmatrix:
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5642 retval = xnorm (x_arg, p_arg);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5643 break;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5644
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5645 case sfcols:
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5646 retval = xcolnorms (x_arg, p_arg);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5647 break;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5648
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5649 case sfrows:
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5650 retval = xrownorms (x_arg, p_arg);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5651 break;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5652
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5653 case sffrob:
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5654 retval = xfrobnorm (x_arg);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5655 break;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5656
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5657 case sfinf:
21723
bae585228161 use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents: 21721
diff changeset
5658 retval = xnorm (x_arg, octave::numeric_limits<double>::Inf ());
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5659 break;
23147
eb5a162c1342 Accept case-insensitive string value for p-value input to norm (bug #50195);
Rik <rik@octave.org>
parents: 23141
diff changeset
5660
eb5a162c1342 Accept case-insensitive string value for p-value input to norm (bug #50195);
Rik <rik@octave.org>
parents: 23141
diff changeset
5661 case sfneginf:
eb5a162c1342 Accept case-insensitive string value for p-value input to norm (bug #50195);
Rik <rik@octave.org>
parents: 23141
diff changeset
5662 retval = xnorm (x_arg, -octave::numeric_limits<double>::Inf ());
eb5a162c1342 Accept case-insensitive string value for p-value input to norm (bug #50195);
Rik <rik@octave.org>
parents: 23141
diff changeset
5663 break;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5664 }
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
5665
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
5666 return retval;
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
5667 }
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
5668
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5669 /*
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5670 %!shared x
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5671 %! x = [1, -3, 4, 5, -7];
23141
bfa4ad642fa0 Disallow p-norm of -Inf for matrices (bug #50194).
Rik <rik@octave.org>
parents: 23127
diff changeset
5672 %!assert (norm (x,0), 5)
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5673 %!assert (norm (x,1), 20)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5674 %!assert (norm (x,2), 10)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5675 %!assert (norm (x,3), 8.24257059961711, -4*eps)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5676 %!assert (norm (x,Inf), 7)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5677 %!assert (norm (x,-Inf), 1)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5678 %!assert (norm (x,"inf"), 7)
23147
eb5a162c1342 Accept case-insensitive string value for p-value input to norm (bug #50195);
Rik <rik@octave.org>
parents: 23141
diff changeset
5679 %!assert (norm (x,"-Inf"), 1)
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5680 %!assert (norm (x,"fro"), 10, -eps)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5681 %!assert (norm (x), 10)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5682 %!assert (norm ([1e200, 1]), 1e200)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5683 %!assert (norm ([3+4i, 3-4i, sqrt(31)]), 9, -4*eps)
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5684 %!shared m
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5685 %! m = magic (4);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5686 %!assert (norm (m,1), 34)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5687 %!assert (norm (m,2), 34, -eps)
23141
bfa4ad642fa0 Disallow p-norm of -Inf for matrices (bug #50194).
Rik <rik@octave.org>
parents: 23127
diff changeset
5688 %!assert (norm (m,3), 34, -sqrt (eps))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5689 %!assert (norm (m,Inf), 34)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5690 %!assert (norm (m,"inf"), 34)
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5691 %!shared m2, flo, fhi
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5692 %! m2 = [1,2;3,4];
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5693 %! flo = 1e-300;
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5694 %! fhi = 1e+300;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5695 %!assert (norm (flo*m2,"fro"), sqrt (30)*flo, -eps)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5696 %!assert (norm (fhi*m2,"fro"), sqrt (30)*fhi, -eps)
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5697
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5698 %!shared x
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5699 %! x = single ([1, -3, 4, 5, -7]);
23141
bfa4ad642fa0 Disallow p-norm of -Inf for matrices (bug #50194).
Rik <rik@octave.org>
parents: 23127
diff changeset
5700 %!assert (norm (x,0), single (5))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5701 %!assert (norm (x,1), single (20))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5702 %!assert (norm (x,2), single (10))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5703 %!assert (norm (x,3), single (8.24257059961711), -4*eps ("single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5704 %!assert (norm (x,Inf), single (7))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5705 %!assert (norm (x,-Inf), single (1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5706 %!assert (norm (x,"inf"), single (7))
23147
eb5a162c1342 Accept case-insensitive string value for p-value input to norm (bug #50195);
Rik <rik@octave.org>
parents: 23141
diff changeset
5707 %!assert (norm (x,"-Inf"), single (1))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5708 %!assert (norm (x,"fro"), single (10), -eps ("single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5709 %!assert (norm (x), single (10))
18676
5bd1ca29c5f0 Clean up questionable code bits identified by clang sanitize.
Rik <rik@octave.org>
parents: 18212
diff changeset
5710 %!assert (norm (single ([1e38, 1])), single (1e38))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5711 %!assert (norm (single ([3+4i, 3-4i, sqrt(31)])), single (9), -4*eps ("single"))
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5712 %!shared m
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5713 %! m = single (magic (4));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5714 %!assert (norm (m,1), single (34))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5715 %!assert (norm (m,2), single (34), -eps ("single"))
23141
bfa4ad642fa0 Disallow p-norm of -Inf for matrices (bug #50194).
Rik <rik@octave.org>
parents: 23127
diff changeset
5716 %!assert (norm (m,3), single (34), -sqrt (eps ("single")))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5717 %!assert (norm (m,Inf), single (34))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5718 %!assert (norm (m,"inf"), single (34))
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5719 %!shared m2, flo, fhi
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5720 %! m2 = single ([1,2;3,4]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5721 %! flo = single (1e-300);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5722 %! fhi = single (1e+300);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5723 %!assert (norm (flo*m2,"fro"), single (sqrt (30)*flo), -eps ("single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5724 %!assert (norm (fhi*m2,"fro"), single (sqrt (30)*fhi), -eps ("single"))
14520
c4ed0fdf2b62 Fix initialization in Higham's method for norm estimate (bug #36031).
Marco Caliari <marco.caliari@univr.it>
parents: 14491
diff changeset
5725
23141
bfa4ad642fa0 Disallow p-norm of -Inf for matrices (bug #50194).
Rik <rik@octave.org>
parents: 23127
diff changeset
5726 ## Hamming norm (p == 0)
bfa4ad642fa0 Disallow p-norm of -Inf for matrices (bug #50194).
Rik <rik@octave.org>
parents: 23127
diff changeset
5727 %!assert (norm ([1, 0, 0, 0, 1], 0), 2)
bfa4ad642fa0 Disallow p-norm of -Inf for matrices (bug #50194).
Rik <rik@octave.org>
parents: 23127
diff changeset
5728
17115
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5729 %!shared q
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5730 %! q = rand (1e3, 3);
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
5731 %!assert (norm (q, 3, "rows"), sum (q.^3, 2).^(1/3), sqrt (eps))
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
5732 %!assert (norm (q, "fro", "rows"), sum (q.^2, 2).^(1/2), sqrt (eps))
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
5733 %!assert (norm (q, "fro", "rows"), sqrt (sumsq (q, 2)), sqrt (eps))
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
5734 %!assert (norm (q, "fro", "cols"), sqrt (sumsq (q, 1)), sqrt (eps))
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
5735 %!assert (norm (q, 3, "cols"), sum (q.^3, 1).^(1/3), sqrt (eps))
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
5736 %!assert (norm (q, "inf", "rows"), norm (q, Inf, "rows"))
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
5737 %!assert (norm (q, "inf", "cols"), norm (q, Inf, "cols"))
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
5738 %!assert (norm (q, [], "rows"), norm (q, 2, "rows"))
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
5739 %!assert (norm (q, [], "cols"), norm (q, 2, "cols"))
17115
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5740
22489
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22440
diff changeset
5741 %!test <30631>
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22440
diff changeset
5742 %! ## Test for norm returning NaN on sparse matrix
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5743 %! A = sparse (2,2);
14520
c4ed0fdf2b62 Fix initialization in Higham's method for norm estimate (bug #36031).
Marco Caliari <marco.caliari@univr.it>
parents: 14491
diff changeset
5744 %! A(2,1) = 1;
c4ed0fdf2b62 Fix initialization in Higham's method for norm estimate (bug #36031).
Marco Caliari <marco.caliari@univr.it>
parents: 14491
diff changeset
5745 %! assert (norm (A), 1);
22789
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
5746
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
5747 ## Test input validation
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
5748 %!error norm ()
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
5749 %!error norm (1,2,3,4)
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
5750 %!error <unrecognized option> norm (1, "invalid")
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
5751 %!error <unrecognized option> norm (1, "rows", "invalid")
22791
da106618264a norm: fix input validation tests
Mike Miller <mtmiller@octave.org>
parents: 22789
diff changeset
5752 %!error <unrecognized option> norm (1, "invalid", "rows")
da106618264a norm: fix input validation tests
Mike Miller <mtmiller@octave.org>
parents: 22789
diff changeset
5753 %!error <invalid combination of options> norm (1, "cols", "rows")
22789
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
5754 %!error <invalid combination of options> norm (1, "rows", "rows")
23141
bfa4ad642fa0 Disallow p-norm of -Inf for matrices (bug #50194).
Rik <rik@octave.org>
parents: 23127
diff changeset
5755 %!error <p must be .= 1> norm (ones (2,2), -Inf)
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5756 */
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5757
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5758 static octave_value
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5759 unary_op_defun_body (octave_value::unary_op op,
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5760 const octave_value_list& args)
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5761 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5762 if (args.length () != 1)
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5763 print_usage ();
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5764
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5765 return do_unary_op (op, args(0));
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5766 }
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5767
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5768 DEFUN (not, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5769 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5770 @deftypefn {} {@var{z} =} not (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5771 Return the logical NOT of @var{x}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5772
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5773 This function is equivalent to the operator syntax @w{@code{! x}}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5774 @seealso{and, or, xor}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5775 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5776 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5777 return unary_op_defun_body (octave_value::op_not, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5778 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5779
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5780 DEFUN (uplus, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5781 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5782 @deftypefn {} {} uplus (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5783 This function and @w{@tcode{+ x}} are equivalent.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5784 @seealso{uminus, plus, minus}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5785 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5786 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5787 return unary_op_defun_body (octave_value::op_uplus, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5788 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5789
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5790 DEFUN (uminus, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5791 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5792 @deftypefn {} {} uminus (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5793 This function and @w{@tcode{- x}} are equivalent.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5794 @seealso{uplus, minus}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5795 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5796 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5797 return unary_op_defun_body (octave_value::op_uminus, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5798 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5799
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5800 DEFUN (transpose, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5801 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5802 @deftypefn {} {} transpose (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5803 Return the transpose of @var{x}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5804
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5805 This function and @tcode{x.'} are equivalent.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5806 @seealso{ctranspose}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5807 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5808 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5809 return unary_op_defun_body (octave_value::op_transpose, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5810 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5811
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5812 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5813 %!assert (2.', 2)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5814 %!assert (2i.', 2i)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5815 %!assert ([1:4].', [1;2;3;4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5816 %!assert ([1;2;3;4].', [1:4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5817 %!assert ([1,2;3,4].', [1,3;2,4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5818 %!assert ([1,2i;3,4].', [1,3;2i,4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5819
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5820 %!assert (transpose ([1,2;3,4]), [1,3;2,4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5821
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5822 %!assert (single (2).', single (2))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5823 %!assert (single (2i).', single (2i))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5824 %!assert (single ([1:4]).', single ([1;2;3;4]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5825 %!assert (single ([1;2;3;4]).', single ([1:4]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5826 %!assert (single ([1,2;3,4]).', single ([1,3;2,4]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5827 %!assert (single ([1,2i;3,4]).', single ([1,3;2i,4]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5828
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5829 %!assert (transpose (single ([1,2;3,4])), single ([1,3;2,4]))
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5830 */
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5831
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5832 DEFUN (ctranspose, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5833 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5834 @deftypefn {} {} ctranspose (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5835 Return the complex conjugate transpose of @var{x}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5836
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5837 This function and @tcode{x'} are equivalent.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5838 @seealso{transpose}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5839 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5840 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5841 return unary_op_defun_body (octave_value::op_hermitian, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5842 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5843
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5844 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5845 %!assert (2', 2)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5846 %!assert (2i', -2i)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5847 %!assert ([1:4]', [1;2;3;4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5848 %!assert ([1;2;3;4]', [1:4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5849 %!assert ([1,2;3,4]', [1,3;2,4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5850 %!assert ([1,2i;3,4]', [1,3;-2i,4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5851
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5852 %!assert (ctranspose ([1,2i;3,4]), [1,3;-2i,4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5853
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5854 %!assert (single (2)', single (2))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5855 %!assert (single (2i)', single (-2i))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5856 %!assert (single ([1:4])', single ([1;2;3;4]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5857 %!assert (single ([1;2;3;4])', single ([1:4]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5858 %!assert (single ([1,2;3,4])', single ([1,3;2,4]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5859 %!assert (single ([1,2i;3,4])', single ([1,3;-2i,4]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5860
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5861 %!assert (ctranspose (single ([1,2i;3,4])), single ([1,3;-2i,4]))
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5862 */
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5863
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5864 static octave_value
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5865 binary_op_defun_body (octave_value::binary_op op,
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5866 const octave_value_list& args)
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5867 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5868 if (args.length () != 2)
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5869 print_usage ();
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5870
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5871 return do_binary_op (op, args(0), args(1));
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5872 }
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5873
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5874 static octave_value
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5875 binary_assoc_op_defun_body (octave_value::binary_op op,
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5876 octave_value::assign_op aop,
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5877 const octave_value_list& args)
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5878 {
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5879 int nargin = args.length ();
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5880
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5881 if (nargin == 0)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5882 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5883
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5884 octave_value retval;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5885
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5886 if (nargin == 1)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5887 retval = args(0);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5888 else if (nargin == 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5889 retval = do_binary_op (op, args(0), args(1));
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5890 else
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5891 {
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5892 retval = do_binary_op (op, args(0), args(1));
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5893
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5894 for (int i = 2; i < nargin; i++)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5895 retval.assign (aop, args(i));
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5896 }
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5897
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5898 return retval;
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5899 }
9339
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5900
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5901 DEFUN (plus, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5902 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5903 @deftypefn {} {} plus (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5904 @deftypefnx {} {} plus (@var{x1}, @var{x2}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5905 This function and @w{@tcode{x + y}} are equivalent.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5906
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5907 If more arguments are given, the summation is applied
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5908 cumulatively from left to right:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5909
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5910 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5911 (@dots{}((x1 + x2) + x3) + @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5912 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5913
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5914 At least one argument is required.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5915 @seealso{minus, uplus}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5916 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5917 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5918 return binary_assoc_op_defun_body (octave_value::op_add,
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5919 octave_value::op_add_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5920 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5921
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5922 DEFUN (minus, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5923 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5924 @deftypefn {} {} minus (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5925 This function and @w{@tcode{x - y}} are equivalent.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5926 @seealso{plus, uminus}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5927 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5928 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5929 return binary_op_defun_body (octave_value::op_sub, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5930 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5931
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5932 DEFUN (mtimes, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5933 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5934 @deftypefn {} {} mtimes (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5935 @deftypefnx {} {} mtimes (@var{x1}, @var{x2}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5936 Return the matrix multiplication product of inputs.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5937
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5938 This function and @w{@tcode{x * y}} are equivalent.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5939 If more arguments are given, the multiplication is applied
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5940 cumulatively from left to right:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5941
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5942 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5943 (@dots{}((x1 * x2) * x3) * @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5944 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5945
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5946 At least one argument is required.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5947 @seealso{times, plus, minus, rdivide, mrdivide, mldivide, mpower}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5948 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5949 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5950 return binary_assoc_op_defun_body (octave_value::op_mul,
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5951 octave_value::op_mul_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5952 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5953
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5954 DEFUN (mrdivide, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5955 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5956 @deftypefn {} {} mrdivide (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5957 Return the matrix right division of @var{x} and @var{y}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5958
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5959 This function and @w{@tcode{x / y}} are equivalent.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5960 @seealso{mldivide, rdivide, plus, minus}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5961 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5962 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5963 return binary_op_defun_body (octave_value::op_div, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5964 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5965
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5966 DEFUN (mpower, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5967 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5968 @deftypefn {} {} mpower (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5969 Return the matrix power operation of @var{x} raised to the @var{y} power.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5970
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5971 This function and @w{@tcode{x ^ y}} are equivalent.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5972 @seealso{power, mtimes, plus, minus}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5973 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5974 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5975 return binary_op_defun_body (octave_value::op_pow, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5976 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5977
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5978 DEFUN (mldivide, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5979 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5980 @deftypefn {} {} mldivide (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5981 Return the matrix left division of @var{x} and @var{y}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5982
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5983 This function and @w{@tcode{x @xbackslashchar{} y}} are equivalent.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5984 @seealso{mrdivide, ldivide, rdivide}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5985 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5986 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5987 return binary_op_defun_body (octave_value::op_ldiv, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5988 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5989
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5990 DEFUN (lt, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5991 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5992 @deftypefn {} {} lt (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5993 This function is equivalent to @w{@code{x < y}}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5994 @seealso{le, eq, ge, gt, ne}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5995 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5996 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5997 return binary_op_defun_body (octave_value::op_lt, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5998 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5999
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6000 DEFUN (le, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6001 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6002 @deftypefn {} {} le (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6003 This function is equivalent to @w{@code{x <= y}}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6004 @seealso{eq, ge, gt, ne, lt}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6005 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6006 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6007 return binary_op_defun_body (octave_value::op_le, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6008 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6009
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6010 DEFUN (eq, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6011 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6012 @deftypefn {} {} eq (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6013 Return true if the two inputs are equal.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6014
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6015 This function is equivalent to @w{@code{x == y}}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6016 @seealso{ne, isequal, le, ge, gt, ne, lt}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6017 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6018 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6019 return binary_op_defun_body (octave_value::op_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6020 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6021
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6022 DEFUN (ge, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6023 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6024 @deftypefn {} {} ge (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6025 This function is equivalent to @w{@code{x >= y}}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6026 @seealso{le, eq, gt, ne, lt}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6027 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6028 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6029 return binary_op_defun_body (octave_value::op_ge, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6030 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6031
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6032 DEFUN (gt, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6033 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6034 @deftypefn {} {} gt (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6035 This function is equivalent to @w{@code{x > y}}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6036 @seealso{le, eq, ge, ne, lt}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6037 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6038 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6039 return binary_op_defun_body (octave_value::op_gt, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6040 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6041
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6042 DEFUN (ne, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6043 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6044 @deftypefn {} {} ne (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6045 Return true if the two inputs are not equal.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6046
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6047 This function is equivalent to @w{@code{x != y}}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6048 @seealso{eq, isequal, le, ge, lt}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6049 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6050 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6051 return binary_op_defun_body (octave_value::op_ne, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6052 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6053
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6054 DEFUN (times, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6055 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6056 @deftypefn {} {} times (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6057 @deftypefnx {} {} times (@var{x1}, @var{x2}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6058 Return the element-by-element multiplication product of inputs.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6059
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6060 This function and @w{@tcode{x .* y}} are equivalent.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6061 If more arguments are given, the multiplication is applied
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6062 cumulatively from left to right:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6063
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6064 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6065 (@dots{}((x1 .* x2) .* x3) .* @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6066 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6067
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6068 At least one argument is required.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6069 @seealso{mtimes, rdivide}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6070 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6071 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6072 return binary_assoc_op_defun_body (octave_value::op_el_mul,
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6073 octave_value::op_el_mul_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6074 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6075
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6076 DEFUN (rdivide, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6077 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6078 @deftypefn {} {} rdivide (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6079 Return the element-by-element right division of @var{x} and @var{y}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6080
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6081 This function and @w{@tcode{x ./ y}} are equivalent.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6082 @seealso{ldivide, mrdivide, times, plus}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6083 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6084 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6085 return binary_op_defun_body (octave_value::op_el_div, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6086 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6087
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6088 DEFUN (power, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6089 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6090 @deftypefn {} {} power (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6091 Return the element-by-element operation of @var{x} raised to the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6092 @var{y} power.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6093
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6094 This function and @w{@tcode{x .^ y}} are equivalent.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6095
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6096 If several complex results are possible, returns the one with smallest
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6097 non-negative argument (angle). Use @code{realpow}, @code{realsqrt},
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6098 @code{cbrt}, or @code{nthroot} if a real result is preferred.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6099
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6100 @seealso{mpower, realpow, realsqrt, cbrt, nthroot}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6101 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6102 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6103 return binary_op_defun_body (octave_value::op_el_pow, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6104 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6105
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6106 DEFUN (ldivide, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6107 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6108 @deftypefn {} {} ldivide (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6109 Return the element-by-element left division of @var{x} and @var{y}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6110
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6111 This function and @w{@tcode{x .@xbackslashchar{} y}} are equivalent.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6112 @seealso{rdivide, mldivide, times, plus}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6113 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6114 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6115 return binary_op_defun_body (octave_value::op_el_ldiv, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6116 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6117
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6118 DEFUN (and, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6119 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6120 @deftypefn {} {@var{z} =} and (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6121 @deftypefnx {} {@var{z} =} and (@var{x1}, @var{x2}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6122 Return the logical AND of @var{x} and @var{y}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6123
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6124 This function is equivalent to the operator syntax @w{@code{x & y}}. If
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6125 more than two arguments are given, the logical AND is applied cumulatively
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6126 from left to right:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6127
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6128 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6129 (@dots{}((x1 & x2) & x3) & @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6130 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6131
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6132 At least one argument is required.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6133 @seealso{or, not, xor}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6134 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6135 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6136 return binary_assoc_op_defun_body (octave_value::op_el_and,
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6137 octave_value::op_el_and_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6138 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6139
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6140 DEFUN (or, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6141 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6142 @deftypefn {} {@var{z} =} or (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6143 @deftypefnx {} {@var{z} =} or (@var{x1}, @var{x2}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6144 Return the logical OR of @var{x} and @var{y}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6145
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6146 This function is equivalent to the operator syntax @w{@code{x | y}}. If
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6147 more than two arguments are given, the logical OR is applied cumulatively
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6148 from left to right:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6149
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6150 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6151 (@dots{}((x1 | x2) | x3) | @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6152 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6153
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6154 At least one argument is required.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6155 @seealso{and, not, xor}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6156 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6157 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6158 return binary_assoc_op_defun_body (octave_value::op_el_or,
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6159 octave_value::op_el_or_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6160 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6161
19749
c913247c85a8 make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents: 19743
diff changeset
6162 DEFUN (colon, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6163 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6164 @deftypefn {} {@var{r} =} colon (@var{base}, @var{limit})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6165 @deftypefnx {} {@var{r} =} colon (@var{base}, @var{increment}, @var{limit})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6166 Return the result of the colon expression corresponding to @var{base},
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6167 @var{limit}, and optionally, @var{increment}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6168
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6169 This function is equivalent to the operator syntax @w{@code{base : limit}}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6170 or @w{@code{base : increment : limit}}.
24504
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
6171 @seealso{linspace}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6172 @end deftypefn */)
19749
c913247c85a8 make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents: 19743
diff changeset
6173 {
c913247c85a8 make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents: 19743
diff changeset
6174 int nargin = args.length ();
c913247c85a8 make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents: 19743
diff changeset
6175
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6176 if (nargin < 2 || nargin > 3)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6177 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6178
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
6179 return (nargin == 2 ? do_colon_op (args(0), args(1))
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
6180 : do_colon_op (args(0), args(1), args(2)));
19749
c913247c85a8 make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents: 19743
diff changeset
6181 }
c913247c85a8 make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents: 19743
diff changeset
6182
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
6183 static double tic_toc_timestamp = -1.0;
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6184
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6185 DEFUN (tic, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6186 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6187 @deftypefn {} {} tic ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6188 @deftypefnx {} {@var{id} =} tic ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6189 @deftypefnx {} {} toc ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6190 @deftypefnx {} {} toc (@var{id})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6191 @deftypefnx {} {@var{val} =} toc (@dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6192 Set or check a wall-clock timer.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6193
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6194 Calling @code{tic} without an output argument sets the internal timer state.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6195 Subsequent calls to @code{toc} return the number of seconds since the timer
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6196 was set.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6197 For example,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6198
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6199 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6200 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6201 tic ();
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6202 # many computations later@dots{}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6203 elapsed_time = toc ();
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6204 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6205 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6206
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6207 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6208 will set the variable @code{elapsed_time} to the number of seconds since
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6209 the most recent call to the function @code{tic}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6210
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6211 If called with one output argument, @code{tic} returns a scalar
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6212 of type @code{uint64} that may be later passed to @code{toc}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6213
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6214 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6215 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6216 id = tic; pause (5); toc (id)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6217 @result{} 5.0010
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6218 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6219 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6220
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6221 Calling @code{tic} and @code{toc} this way allows nested timing calls.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6222
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6223 If you are more interested in the CPU time that your process used, you
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6224 should use the @code{cputime} function instead. The @code{tic} and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6225 @code{toc} functions report the actual wall clock time that elapsed
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6226 between the calls. This may include time spent processing other jobs or
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6227 doing nothing at all.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6228 @seealso{toc, cputime}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6229 @end deftypefn */)
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6230 {
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20816
diff changeset
6231 if (args.length () != 0)
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6232 warning ("tic: ignoring extra arguments");
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6233
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6234 octave_value retval;
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
6235 octave::sys::time now;
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
6236 double tmp = now.double_value ();
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
6237
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6238 if (nargout > 0)
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6239 {
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6240 double ip = 0.0;
23639
b488e958d024 Use modf, pow from C++ std library.
Rik <rik@octave.org>
parents: 23625
diff changeset
6241 double frac = std::modf (tmp, &ip);
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6242 uint64_t microsecs = static_cast<uint64_t> (CLOCKS_PER_SEC * frac);
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6243 microsecs += CLOCKS_PER_SEC * static_cast<uint64_t> (ip);
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6244 retval = octave_uint64 (microsecs);
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6245 }
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6246 else
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
6247 tic_toc_timestamp = tmp;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6248
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6249 return retval;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6250 }
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6251
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6252 DEFUN (toc, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6253 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6254 @deftypefn {} {} toc ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6255 @deftypefnx {} {} toc (@var{id})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6256 @deftypefnx {} {@var{val} =} toc (@dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6257 @seealso{tic, cputime}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6258 @end deftypefn */)
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6259 {
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6260 int nargin = args.length ();
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6261
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6262 if (nargin > 1)
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6263 print_usage ();
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6264
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6265 double start_time = tic_toc_timestamp;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6266
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6267 if (nargin == 1)
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
6268 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6269 octave_uint64 id = args(0).xuint64_scalar_value ("toc: invalid ID");
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6270
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6271 uint64_t val = id.value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6272
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6273 start_time
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6274 = (static_cast<double> (val / CLOCKS_PER_SEC)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6275 + static_cast<double> (val % CLOCKS_PER_SEC)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6276 / CLOCKS_PER_SEC);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6277
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6278 // FIXME: should we also check to see whether the start
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6279 // time is after the beginning of this Octave session?
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
6280 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6281
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6282 if (start_time < 0)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6283 error ("toc called before timer set");
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6284
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
6285 octave::sys::time now;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6286
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6287 double etime = now.double_value () - start_time;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6288
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6289 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6290 if (nargout > 0)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6291 retval = etime;
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6292 else
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6293 octave_stdout << "Elapsed time is " << etime << " seconds.\n";
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6294
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6295 return retval;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6296 }
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6297
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6298 /*
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6299 %!shared id
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6300 %! id = tic ();
14849
f6d3d5b0bd42 test: Use Octave coding conventions for tests for line() and toc().
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
6301 %!assert (isa (id, "uint64"))
f6d3d5b0bd42 test: Use Octave coding conventions for tests for line() and toc().
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
6302 %!assert (isa (toc (id), "double"))
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6303 */
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6304
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6305 DEFUN (cputime, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6306 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6307 @deftypefn {} {[@var{total}, @var{user}, @var{system}] =} cputime ();
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6308 Return the CPU time used by your Octave session.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6309
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6310 The first output is the total time spent executing your process and is equal
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6311 to the sum of second and third outputs, which are the number of CPU seconds
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6312 spent executing in user mode and the number of CPU seconds spent executing
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6313 in system mode, respectively.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6314
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6315 If your system does not have a way to report CPU time usage, @code{cputime}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6316 returns 0 for each of its output values.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6317
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6318 Note that because Octave used some CPU time to start, it is reasonable
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6319 to check to see if @code{cputime} works by checking to see if the total
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6320 CPU time used is nonzero.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6321 @seealso{tic, toc}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6322 @end deftypefn */)
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6323 {
21078
49852ff04747 maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents: 21062
diff changeset
6324 if (args.length () != 0)
21930
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
6325 print_usage ();
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
6326
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
6327 octave::sys::cpu_time cpu_tm;
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
6328
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
6329 double usr = cpu_tm.user ();
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
6330 double sys = cpu_tm.system ();
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
6331
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
6332 return ovl (usr + sys, usr, sys);
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6333 }
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6334
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6335 DEFUN (sort, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6336 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6337 @deftypefn {} {[@var{s}, @var{i}] =} sort (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6338 @deftypefnx {} {[@var{s}, @var{i}] =} sort (@var{x}, @var{dim})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6339 @deftypefnx {} {[@var{s}, @var{i}] =} sort (@var{x}, @var{mode})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6340 @deftypefnx {} {[@var{s}, @var{i}] =} sort (@var{x}, @var{dim}, @var{mode})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6341 Return a copy of @var{x} with the elements arranged in increasing order.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6342
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6343 For matrices, @code{sort} orders the elements within columns
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6344
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6345 For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6346
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6347 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6348 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6349 sort ([1, 2; 2, 3; 3, 1])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6350 @result{} 1 1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6351 2 2
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6352 3 3
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6353 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6354 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6355
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6356 If the optional argument @var{dim} is given, then the matrix is sorted
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6357 along the dimension defined by @var{dim}. The optional argument @code{mode}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6358 defines the order in which the values will be sorted. Valid values of
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6359 @code{mode} are @qcode{"ascend"} or @qcode{"descend"}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6360
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6361 The @code{sort} function may also be used to produce a matrix
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6362 containing the original row indices of the elements in the sorted
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6363 matrix. For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6364
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6365 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6366 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6367 [s, i] = sort ([1, 2; 2, 3; 3, 1])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6368 @result{} s = 1 1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6369 2 2
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6370 3 3
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6371 @result{} i = 1 3
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6372 2 1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6373 3 2
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6374 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6375 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6376
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6377 For equal elements, the indices are such that equal elements are listed
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6378 in the order in which they appeared in the original list.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6379
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6380 Sorting of complex entries is done first by magnitude
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6381 (@w{@code{abs (@var{z})}}) and for any ties by phase angle
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6382 (@w{@code{angle (z)}}). For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6383
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6384 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6385 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6386 sort ([1+i; 1; 1-i])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6387 @result{} 1 + 0i
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6388 1 - 1i
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6389 1 + 1i
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6390 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6391 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6392
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6393 NaN values are treated as being greater than any other value and are sorted
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6394 to the end of the list.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6395
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6396 The @code{sort} function may also be used to sort strings and cell arrays
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6397 of strings, in which case ASCII dictionary order (uppercase 'A' precedes
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6398 lowercase 'a') of the strings is used.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6399
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6400 The algorithm used in @code{sort} is optimized for the sorting of partially
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6401 ordered lists.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6402 @seealso{sortrows, issorted}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6403 @end deftypefn */)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6404 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6405 int nargin = args.length ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6406
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6407 if (nargin < 1 || nargin > 3)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6408 print_usage ();
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6409
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
6410 sortmode smode = ASCENDING;
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
6411 bool return_idx = (nargout > 1);
20921
4d3daf7e43f3 eliminate trailing whitespace in source files
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
6412 bool have_sortmode = (nargin > 1 && args(1).is_string ());
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6413 octave_value arg = args(0);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6414
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6415 int dim = 0;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6416 if (nargin > 1)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6417 {
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
6418 if (have_sortmode)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6419 {
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14843
diff changeset
6420 std::string mode = args(1).string_value ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6421 if (mode == "ascend")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6422 smode = ASCENDING;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6423 else if (mode == "descend")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6424 smode = DESCENDING;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6425 else
23803
90689bdbe048 Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents: 23748
diff changeset
6426 error (R"(sort: MODE must be either "ascend" or "descend")");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6427 }
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6428 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6429 dim = args(1).nint_value () - 1;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6430 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6431
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6432 if (nargin > 2)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6433 {
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
6434 if (have_sortmode)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6435 error ("sort: DIM must be a valid dimension");
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6436
20700
68e3a747ca02 rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
6437 std::string mode = args(2).xstring_value ("sort: MODE must be a string");
20582
ba2b07c13913 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20574
diff changeset
6438
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6439 if (mode == "ascend")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6440 smode = ASCENDING;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6441 else if (mode == "descend")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6442 smode = DESCENDING;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6443 else
23803
90689bdbe048 Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents: 23748
diff changeset
6444 error (R"(sort: MODE must be either "ascend" or "descend")");
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6445 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6446
10285
22a7913bbeb5 optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents: 10277
diff changeset
6447 const dim_vector dv = arg.dims ();
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
6448 if (nargin == 1 || have_sortmode)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6449 {
10285
22a7913bbeb5 optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents: 10277
diff changeset
6450 dim = dv.first_non_singleton ();
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6451 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6452 else
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6453 {
10703
5eb420d92307 fix sort and nth_element when trailing singleton dim is specified
Jaroslav Hajek <highegg@gmail.com>
parents: 10695
diff changeset
6454 if (dim < 0)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6455 error ("sort: DIM must be a valid dimension");
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6456 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6457
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
6458 octave_value_list retval (return_idx ? 2 : 1);
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
6459
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6460 if (return_idx)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6461 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6462 Array<octave_idx_type> sidx;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6463
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
6464 // NOTE: Can not change this to ovl() call because arg.sort changes sidx
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
6465 // and objects are declared const in ovl prototype.
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
6466 retval(0) = arg.sort (sidx, dim, smode);
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
6467 retval(1) = idx_vector (sidx, dv(dim)); // No checking, extent is known.
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6468 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6469 else
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
6470 retval = ovl (arg.sort (dim, smode));
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6471
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6472 return retval;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6473 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6474
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6475 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6476 ## Double
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6477 %!assert (sort ([NaN, 1, -1, 2, Inf]), [-1, 1, 2, Inf, NaN])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6478 %!assert (sort ([NaN, 1, -1, 2, Inf], 1), [NaN, 1, -1, 2, Inf])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6479 %!assert (sort ([NaN, 1, -1, 2, Inf], 2), [-1, 1, 2, Inf, NaN])
10707
69c5f5ec55d7 fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
6480 %!assert (sort ([NaN, 1, -1, 2, Inf], 3), [NaN, 1, -1, 2, Inf])
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6481 %!assert (sort ([NaN, 1, -1, 2, Inf], "ascend"), [-1, 1, 2, Inf, NaN])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6482 %!assert (sort ([NaN, 1, -1, 2, Inf], 2, "ascend"), [-1, 1, 2, Inf, NaN])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6483 %!assert (sort ([NaN, 1, -1, 2, Inf], "descend"), [NaN, Inf, 2, 1, -1])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6484 %!assert (sort ([NaN, 1, -1, 2, Inf], 2, "descend"), [NaN, Inf, 2, 1, -1])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6485 %!assert (sort ([3, 1, 7, 5; 8, 2, 6, 4]), [3, 1, 6, 4; 8, 2, 7, 5])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6486 %!assert (sort ([3, 1, 7, 5; 8, 2, 6, 4], 1), [3, 1, 6, 4; 8, 2, 7, 5])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6487 %!assert (sort ([3, 1, 7, 5; 8, 2, 6, 4], 2), [1, 3, 5, 7; 2, 4, 6, 8])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6488 %!assert (sort (1), 1)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6489
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6490 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6491 %! [v, i] = sort ([NaN, 1, -1, Inf, 1]);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6492 %! assert (v, [-1, 1, 1, Inf, NaN]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6493 %! assert (i, [3, 2, 5, 4, 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6494
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6495 ## Complex
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6496 %!assert (sort ([NaN, 1i, -1, 2, Inf]), [1i, -1, 2, Inf, NaN])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6497 %!assert (sort ([NaN, 1i, -1, 2, Inf], 1), [NaN, 1i, -1, 2, Inf])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6498 %!assert (sort ([NaN, 1i, -1, 2, Inf], 2), [1i, -1, 2, Inf, NaN])
10707
69c5f5ec55d7 fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
6499 %!assert (sort ([NaN, 1i, -1, 2, Inf], 3), [NaN, 1i, -1, 2, Inf])
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6500 %!assert (sort ([NaN, 1i, -1, 2, Inf], "ascend"), [1i, -1, 2, Inf, NaN])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6501 %!assert (sort ([NaN, 1i, -1, 2, Inf], 2, "ascend"), [1i, -1, 2, Inf, NaN])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6502 %!assert (sort ([NaN, 1i, -1, 2, Inf], "descend"), [NaN, Inf, 2, -1, 1i])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6503 %!assert (sort ([NaN, 1i, -1, 2, Inf], 2, "descend"), [NaN, Inf, 2, -1, 1i])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6504 %!assert (sort ([3, 1i, 7, 5; 8, 2, 6, 4]), [3, 1i, 6, 4; 8, 2, 7, 5])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6505 %!assert (sort ([3, 1i, 7, 5; 8, 2, 6, 4], 1), [3, 1i, 6, 4; 8, 2, 7, 5])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6506 %!assert (sort ([3, 1i, 7, 5; 8, 2, 6, 4], 2), [1i, 3, 5, 7; 2, 4, 6, 8])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6507 %!assert (sort (1i), 1i)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6508
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6509 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6510 %! [v, i] = sort ([NaN, 1i, -1, Inf, 1, 1i]);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6511 %! assert (v, [1, 1i, 1i, -1, Inf, NaN]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6512 %! assert (i, [5, 2, 6, 3, 4, 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6513
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6514 ## Single
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6515 %!assert (sort (single ([NaN, 1, -1, 2, Inf])), single ([-1, 1, 2, Inf, NaN]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6516 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), 1), single ([NaN, 1, -1, 2, Inf]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6517 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), 2), single ([-1, 1, 2, Inf, NaN]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6518 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), 3), single ([NaN, 1, -1, 2, Inf]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6519 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), "ascend"), single ([-1, 1, 2, Inf, NaN]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6520 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), 2, "ascend"), single ([-1, 1, 2, Inf, NaN]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6521 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), "descend"), single ([NaN, Inf, 2, 1, -1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6522 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), 2, "descend"), single ([NaN, Inf, 2, 1, -1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6523 %!assert (sort (single ([3, 1, 7, 5; 8, 2, 6, 4])), single ([3, 1, 6, 4; 8, 2, 7, 5]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6524 %!assert (sort (single ([3, 1, 7, 5; 8, 2, 6, 4]), 1), single ([3, 1, 6, 4; 8, 2, 7, 5]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6525 %!assert (sort (single ([3, 1, 7, 5; 8, 2, 6, 4]), 2), single ([1, 3, 5, 7; 2, 4, 6, 8]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6526 %!assert (sort (single (1)), single (1))
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6527
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6528 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6529 %! [v, i] = sort (single ([NaN, 1, -1, Inf, 1]));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6530 %! assert (v, single ([-1, 1, 1, Inf, NaN]));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6531 %! assert (i, [3, 2, 5, 4, 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6532
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6533 ## Single Complex
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6534 %!assert (sort (single ([NaN, 1i, -1, 2, Inf])), single ([1i, -1, 2, Inf, NaN]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6535 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 1), single ([NaN, 1i, -1, 2, Inf]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6536 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 2), single ([1i, -1, 2, Inf, NaN]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6537 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 3), single ([NaN, 1i, -1, 2, Inf]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6538 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), "ascend"), single ([1i, -1, 2, Inf, NaN]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6539 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 2, "ascend"), single ([1i, -1, 2, Inf, NaN]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6540 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), "descend"), single ([NaN, Inf, 2, -1, 1i]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6541 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 2, "descend"), single ([NaN, Inf, 2, -1, 1i]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6542 %!assert (sort (single ([3, 1i, 7, 5; 8, 2, 6, 4])), single ([3, 1i, 6, 4; 8, 2, 7, 5]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6543 %!assert (sort (single ([3, 1i, 7, 5; 8, 2, 6, 4]), 1), single ([3, 1i, 6, 4; 8, 2, 7, 5]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6544 %!assert (sort (single ([3, 1i, 7, 5; 8, 2, 6, 4]), 2), single ([1i, 3, 5, 7; 2, 4, 6, 8]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6545 %!assert (sort (single (1i)), single (1i))
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6546
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6547 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6548 %! [v, i] = sort (single ([NaN, 1i, -1, Inf, 1, 1i]));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6549 %! assert (v, single ([1, 1i, 1i, -1, Inf, NaN]));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6550 %! assert (i, [5, 2, 6, 3, 4, 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6551
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6552 ## Bool
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6553 %!assert (sort ([true, false, true, false]), [false, false, true, true])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6554 %!assert (sort ([true, false, true, false], 1), [true, false, true, false])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6555 %!assert (sort ([true, false, true, false], 2), [false, false, true, true])
10707
69c5f5ec55d7 fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
6556 %!assert (sort ([true, false, true, false], 3), [true, false, true, false])
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6557 %!assert (sort ([true, false, true, false], "ascend"), [false, false, true, true])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6558 %!assert (sort ([true, false, true, false], 2, "ascend"), [false, false, true, true])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6559 %!assert (sort ([true, false, true, false], "descend"), [true, true, false, false])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6560 %!assert (sort ([true, false, true, false], 2, "descend"), [true, true, false, false])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6561 %!assert (sort (true), true)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6562
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6563 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6564 %! [v, i] = sort ([true, false, true, false]);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6565 %! assert (v, [false, false, true, true]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6566 %! assert (i, [2, 4, 1, 3]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6567
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6568 ## Sparse Double
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6569 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf])), sparse ([-1, 0, 0, 1, 2, Inf, NaN]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6570 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 1), sparse ([0, NaN, 1, 0, -1, 2, Inf]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6571 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2), sparse ([-1, 0, 0, 1, 2, Inf, NaN]))
10707
69c5f5ec55d7 fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
6572 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 3), sparse ([0, NaN, 1, 0, -1, 2, Inf]))
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6573 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), "ascend"), sparse ([-1, 0, 0, 1, 2, Inf, NaN]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6574 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2, "ascend"), sparse ([-1, 0, 0, 1, 2, Inf, NaN]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6575 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), "descend"), sparse ([NaN, Inf, 2, 1, 0, 0, -1]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6576 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2, "descend"), sparse ([NaN, Inf, 2, 1, 0, 0, -1]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6577
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6578 %!shared a
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6579 %! a = randn (10, 10);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6580 %! a(a < 0) = 0;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6581 %!assert (sort (sparse (a)), sparse (sort (a)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6582 %!assert (sort (sparse (a), 1), sparse (sort (a, 1)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6583 %!assert (sort (sparse (a), 2), sparse (sort (a, 2)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6584 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6585 %! [v, i] = sort (a);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6586 %! [vs, is] = sort (sparse (a));
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6587 %! assert (vs, sparse (v));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6588 %! assert (is, i);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6589
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6590 ## Sparse Complex
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6591 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf])), sparse ([0, 0, 1i, -1, 2, Inf, NaN]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6592 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 1), sparse ([0, NaN, 1i, 0, -1, 2, Inf]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6593 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2), sparse ([0, 0, 1i, -1, 2, Inf, NaN]))
10707
69c5f5ec55d7 fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
6594 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 3), sparse ([0, NaN, 1i, 0, -1, 2, Inf]))
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6595 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), "ascend"), sparse ([0, 0, 1i, -1, 2, Inf, NaN]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6596 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2, "ascend"), sparse ([0, 0, 1i, -1, 2, Inf, NaN]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6597 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), "descend"), sparse ([NaN, Inf, 2, -1, 1i, 0, 0]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6598 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2, "descend"), sparse ([NaN, Inf, 2, -1, 1i, 0, 0]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6599
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6600 %!shared a
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6601 %! a = randn (10, 10);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6602 %! a(a < 0) = 0;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6603 %! a = 1i * a;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6604 %!assert (sort (sparse (a)), sparse (sort (a)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6605 %!assert (sort (sparse (a), 1), sparse (sort (a, 1)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6606 %!assert (sort (sparse (a), 2), sparse (sort (a, 2)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6607 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6608 %! [v, i] = sort (a);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6609 %! [vs, is] = sort (sparse (a));
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6610 %! assert (vs, sparse (v));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6611 %! assert (is, i);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6612
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6613 ## Sparse Bool
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6614 %!assert (sort (sparse ([true, false, true, false])), sparse ([false, false, true, true]))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6615 %!assert (sort (sparse ([true, false, true, false]), 1), sparse ([true, false, true, false]))
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6616 %!assert (sort (sparse ([true, false, true, false]), 2), sparse ([false, false, true, true]))
10707
69c5f5ec55d7 fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
6617 %!assert (sort (sparse ([true, false, true, false]), 3), sparse ([true, false, true, false]))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6618 %!assert (sort (sparse ([true, false, true, false]), "ascend"), sparse ([false, false, true, true]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6619 %!assert (sort (sparse ([true, false, true, false]), 2, "ascend"), sparse ([false, false, true, true]))
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6620 %!assert (sort (sparse ([true, false, true, false]), "descend"), sparse ([true, true, false, false]))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6621 %!assert (sort (sparse ([true, false, true, false]), 2, "descend"), sparse ([true, true, false, false]))
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6622
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6623 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6624 %! [v, i] = sort (sparse ([true, false, true, false]));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6625 %! assert (v, sparse ([false, false, true, true]));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6626 %! assert (i, [2, 4, 1, 3]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6627
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6628 ## Cell string array
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6629 %!shared a, b, c
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6630 %! a = {"Alice", "Cecile", "Eric", "Barry", "David"};
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6631 %! b = {"Alice", "Barry", "Cecile", "David", "Eric"};
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6632 %! c = {"Eric", "David", "Cecile", "Barry", "Alice"};
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6633 %!assert (sort (a), b)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6634 %!assert (sort (a, 1), a)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6635 %!assert (sort (a, 2), b)
10707
69c5f5ec55d7 fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
6636 %!assert (sort (a, 3), a)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6637 %!assert (sort (a, "ascend"), b)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6638 %!assert (sort (a, 2, "ascend"), b)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6639 %!assert (sort (a, "descend"), c)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6640 %!assert (sort (a, 2, "descend"), c)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6641
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6642 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6643 %! [v, i] = sort (a);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6644 %! assert (i, [1, 4, 2, 5, 3]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6645
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6646 %!error sort ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6647 %!error sort (1, 2, 3, 4)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6648 */
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6649
8812
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8799
diff changeset
6650 // Sort the rows of the matrix @var{a} according to the order
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 15428
diff changeset
6651 // specified by @var{mode}, which can either be 'ascend' or 'descend'
8812
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8799
diff changeset
6652 // and return the index vector corresponding to the sort order.
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8799
diff changeset
6653 //
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8799
diff changeset
6654 // This function does not yet support sparse matrices.
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8799
diff changeset
6655
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6656 // FIXME: Is this function used anymore? 12/14/2015
8733
3ef774603887 rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents: 8721
diff changeset
6657 DEFUN (__sort_rows_idx__, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6658 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6659 @deftypefn {} {} __sort_rows_idx__ (@var{a}, @var{mode})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6660 Undocumented internal function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6661 @end deftypefn */)
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6662 {
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6663 int nargin = args.length ();
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6664
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6665 if (nargin < 1 || nargin > 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6666 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6667
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6668 if (nargin == 2 && ! args(1).is_string ())
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6669 error ("__sort_rows_idx__: second argument must be a string");
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6670
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6671 sortmode smode = ASCENDING;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6672 if (nargin > 1)
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6673 {
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14843
diff changeset
6674 std::string mode = args(1).string_value ();
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6675 if (mode == "ascend")
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6676 smode = ASCENDING;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6677 else if (mode == "descend")
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6678 smode = DESCENDING;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6679 else
23803
90689bdbe048 Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents: 23748
diff changeset
6680 error (R"(__sort_rows_idx__: MODE must be either "ascend" or "descend")");
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6681 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6682
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6683 octave_value arg = args(0);
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6684
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
6685 if (arg.issparse ())
8733
3ef774603887 rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents: 8721
diff changeset
6686 error ("__sort_rows_idx__: sparse matrices not yet supported");
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6687
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6688 if (arg.ndims () != 2)
21014
b9d4c3615e89 maint: Capitalize D for dimension in messages and comments.
Rik <rik@octave.org>
parents: 20980
diff changeset
6689 error ("__sort_rows_idx__: needs a 2-D object");
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6690
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6691 Array<octave_idx_type> idx = arg.sort_rows_idx (smode);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6692
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
6693 // This cannot be ovl(), relies on special overloaded octave_value call.
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6694 return octave_value (idx, true, true);
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6695 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6696
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6697 static sortmode
20720
7c21b151b8b4 build: Fix warning messages from compiler.
Rik <rik@octave.org>
parents: 20711
diff changeset
6698 get_sort_mode_option (const octave_value& arg)
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6699 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6700 // FIXME: we initialize to UNSORTED here to avoid a GCC warning
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6701 // about possibly using sortmode uninitialized.
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6702 // FIXME: shouldn't these modes be scoped inside a class?
10076
4b270d1540f7 avoid various GCC warnings
John W. Eaton <jwe@octave.org>
parents: 10073
diff changeset
6703 sortmode smode = UNSORTED;
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6704
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20704
diff changeset
6705 std::string mode = arg.xstring_value ("issorted: MODE must be a string");
20582
ba2b07c13913 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20574
diff changeset
6706
ba2b07c13913 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20574
diff changeset
6707 if (mode == "ascending")
ba2b07c13913 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20574
diff changeset
6708 smode = ASCENDING;
ba2b07c13913 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20574
diff changeset
6709 else if (mode == "descending")
ba2b07c13913 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20574
diff changeset
6710 smode = DESCENDING;
ba2b07c13913 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20574
diff changeset
6711 else if (mode == "either")
ba2b07c13913 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20574
diff changeset
6712 smode = UNSORTED;
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6713 else
23803
90689bdbe048 Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents: 23748
diff changeset
6714 error (R"(issorted: MODE must be "ascending", "descending", or "either")");
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6715
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6716 return smode;
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6717 }
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6718
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6719 DEFUN (issorted, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6720 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6721 @deftypefn {} {} issorted (@var{a})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6722 @deftypefnx {} {} issorted (@var{a}, @var{mode})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6723 @deftypefnx {} {} issorted (@var{a}, "rows", @var{mode})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6724 Return true if the array is sorted according to @var{mode}, which
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6725 may be either @qcode{"ascending"}, @qcode{"descending"}, or
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6726 @qcode{"either"}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6727
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6728 By default, @var{mode} is @qcode{"ascending"}. NaNs are treated in the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6729 same manner as @code{sort}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6730
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6731 If the optional argument @qcode{"rows"} is supplied, check whether
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6732 the array is sorted by rows as output by the function @code{sortrows}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6733 (with no options).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6734
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6735 This function does not support sparse matrices.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6736 @seealso{sort, sortrows}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6737 @end deftypefn */)
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6738 {
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6739 int nargin = args.length ();
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6740
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6741 if (nargin < 1 || nargin > 3)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6742 print_usage ();
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6743
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6744 bool by_rows = false;
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6745
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6746 sortmode smode = ASCENDING;
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6747
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6748 if (nargin > 1)
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6749 {
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6750 if (nargin == 3)
20720
7c21b151b8b4 build: Fix warning messages from compiler.
Rik <rik@octave.org>
parents: 20711
diff changeset
6751 smode = get_sort_mode_option (args(2));
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6752
20700
68e3a747ca02 rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
6753 std::string tmp = args(1).xstring_value ("issorted: second argument must be a string");
20582
ba2b07c13913 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20574
diff changeset
6754 if (tmp == "rows")
ba2b07c13913 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20574
diff changeset
6755 by_rows = true;
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6756 else
20720
7c21b151b8b4 build: Fix warning messages from compiler.
Rik <rik@octave.org>
parents: 20711
diff changeset
6757 smode = get_sort_mode_option (args(1));
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6758 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6759
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6760 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6761
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6762 octave_value arg = args(0);
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6763
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6764 if (by_rows)
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6765 {
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
6766 if (arg.issparse ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6767 error ("issorted: sparse matrices not yet supported");
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6768
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6769 if (arg.ndims () != 2)
21014
b9d4c3615e89 maint: Capitalize D for dimension in messages and comments.
Rik <rik@octave.org>
parents: 20980
diff changeset
6770 error ("issorted: A must be a 2-D object");
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6771
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6772 retval = arg.is_sorted_rows (smode) != UNSORTED;
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6773 }
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6774 else
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6775 {
23592
80e3bfb7bd5a maint: Deprecate is_vector and replace with isvector.
Rik <rik@octave.org>
parents: 23588
diff changeset
6776 if (! arg.dims ().isvector ())
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6777 error ("issorted: needs a vector");
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6778
23588
0549061d35b9 maint: Deprecate is_sorted and replace with issorted.
Rik <rik@octave.org>
parents: 23587
diff changeset
6779 retval = args(0).issorted (smode) != UNSORTED;
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6780 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6781
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6782 return retval;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6783 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6784
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6785 /*
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6786 %!shared sm, um, sv, uv
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6787 %! sm = [1, 2; 3, 4];
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6788 %! um = [3, 1; 2, 4];
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6789 %! sv = [1, 2, 3, 4];
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6790 %! uv = [2, 1, 4, 3];
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
6791
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6792 %!assert (issorted (sm, "rows"))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
6793 %!assert (! issorted (um, "rows"))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6794 %!assert (issorted (sv))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
6795 %!assert (! issorted (uv))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6796 %!assert (issorted (sv'))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
6797 %!assert (! issorted (uv'))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6798 %!assert (issorted (sm, "rows", "ascending"))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
6799 %!assert (! issorted (um, "rows", "ascending"))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6800 %!assert (issorted (sv, "ascending"))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
6801 %!assert (! issorted (uv, "ascending"))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6802 %!assert (issorted (sv', "ascending"))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
6803 %!assert (! issorted (uv', "ascending"))
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
6804 %!assert (! issorted (sm, "rows", "descending"))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6805 %!assert (issorted (flipud (sm), "rows", "descending"))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
6806 %!assert (! issorted (sv, "descending"))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6807 %!assert (issorted (fliplr (sv), "descending"))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
6808 %!assert (! issorted (sv', "descending"))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6809 %!assert (issorted (fliplr (sv)', "descending"))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
6810 %!assert (! issorted (um, "rows", "either"))
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
6811 %!assert (! issorted (uv, "either"))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6812 %!assert (issorted (sm, "rows", "either"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6813 %!assert (issorted (flipud (sm), "rows", "either"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6814 %!assert (issorted (sv, "either"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6815 %!assert (issorted (fliplr (sv), "either"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6816 %!assert (issorted (sv', "either"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6817 %!assert (issorted (fliplr (sv)', "either"))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
6818
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
6819 %!error <needs a vector> issorted ([])
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
6820
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
6821 ## Test input validation
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
6822 %!error issorted ()
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
6823 %!error issorted (1,2,3,4)
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
6824 %!error <second argument must be a string> issorted (1, 2)
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
6825 %!error <second argument must be a string> issorted (1, {"rows"})
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
6826 %!error <sparse matrices not yet supported> issorted (sparse ([1 2 3]), "rows")
21014
b9d4c3615e89 maint: Capitalize D for dimension in messages and comments.
Rik <rik@octave.org>
parents: 20980
diff changeset
6827 %!error <A must be a 2-D object> issorted (rand (2,2,2), "rows")
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
6828 %!error <needs a vector> issorted (ones (2,2))
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6829 */
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6830
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6831 DEFUN (nth_element, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6832 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6833 @deftypefn {} {} nth_element (@var{x}, @var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6834 @deftypefnx {} {} nth_element (@var{x}, @var{n}, @var{dim})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6835 Select the n-th smallest element of a vector, using the ordering defined by
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6836 @code{sort}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6837
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6838 The result is equivalent to @code{sort(@var{x})(@var{n})}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6839
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6840 @var{n} can also be a contiguous range, either ascending @code{l:u}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6841 or descending @code{u:-1:l}, in which case a range of elements is returned.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6842
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6843 If @var{x} is an array, @code{nth_element} operates along the dimension
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6844 defined by @var{dim}, or the first non-singleton dimension if @var{dim} is
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6845 not given.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6846
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6847 Programming Note: nth_element encapsulates the C++ standard library
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6848 algorithms nth_element and partial_sort. On average, the complexity of the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6849 operation is O(M*log(K)), where @w{@code{M = size (@var{x}, @var{dim})}} and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6850 @w{@code{K = length (@var{n})}}. This function is intended for cases where
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6851 the ratio K/M is small; otherwise, it may be better to use @code{sort}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6852 @seealso{sort, min, max}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6853 @end deftypefn */)
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6854 {
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6855 int nargin = args.length ();
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6856
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6857 if (nargin < 2 || nargin > 3)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6858 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6859
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6860 int dim = -1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6861 if (nargin == 3)
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6862 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6863 dim = args(2).int_value (true) - 1;
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6864 if (dim < 0)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6865 error ("nth_element: DIM must be a valid dimension");
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6866 }
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6867
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6868 octave_value argx = args(0);
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6869 if (dim < 0)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6870 dim = argx.dims ().first_non_singleton ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6871
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6872 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6873
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6874 try
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6875 {
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6876 idx_vector n = args(1).index_vector ();
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6877
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6878 switch (argx.builtin_type ())
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6879 {
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6880 case btyp_double:
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6881 retval = argx.array_value ().nth_element (n, dim);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6882 break;
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6883 case btyp_float:
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6884 retval = argx.float_array_value ().nth_element (n, dim);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6885 break;
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6886 case btyp_complex:
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6887 retval = argx.complex_array_value ().nth_element (n, dim);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6888 break;
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6889 case btyp_float_complex:
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6890 retval = argx.float_complex_array_value ().nth_element (n, dim);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6891 break;
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
6892
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
6893 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
6894 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
6895 retval = argx.X ## _array_value ().nth_element (n, dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
6896 break;
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6897
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6898 MAKE_INT_BRANCH (int8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6899 MAKE_INT_BRANCH (int16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6900 MAKE_INT_BRANCH (int32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6901 MAKE_INT_BRANCH (int64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6902 MAKE_INT_BRANCH (uint8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6903 MAKE_INT_BRANCH (uint16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6904 MAKE_INT_BRANCH (uint32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6905 MAKE_INT_BRANCH (uint64);
21540
ffb4770ba079 Make median preserve discrete types (bug #47515).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21458
diff changeset
6906 MAKE_INT_BRANCH (bool);
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
6907
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6908 #undef MAKE_INT_BRANCH
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
6909
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6910 default:
23575
e95738a119da maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents: 23573
diff changeset
6911 if (argx.iscellstr ())
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6912 retval = argx.cellstr_value ().nth_element (n, dim);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6913 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
6914 err_wrong_type_arg ("nth_element", argx);
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6915 }
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6916 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
6917 catch (const octave::index_exception& e)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6918 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6919 index_error ("nth_element: invalid N value %s. %s",
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6920 e.idx (), e.details ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6921 }
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6922
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6923 return retval;
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6924 }
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6925
23734
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
6926 /*
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
6927 %!assert (nth_element ([1:10], 1), 1)
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
6928 %!assert (nth_element ([1:10], 10), 10)
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
6929 %!assert (nth_element ([1:10], 1:3), [1 2 3])
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
6930 %!assert (nth_element ([1:10], 1:10), [1:10])
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
6931
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
6932 %!assert <*51329> (nth_element ([1:10], [1:10]), [1:10])
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
6933
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
6934 %!error nth_element ()
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
6935 %!error nth_element (1)
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
6936 %!error nth_element (1, 1.5)
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
6937 %!error nth_element (1, 2, 3, 4)
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
6938 %!error nth_element ("abcd", 3)
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
6939 */
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
6940
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
6941 template <typename NDT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6942 static NDT
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6943 do_accumarray_sum (const idx_vector& idx, const NDT& vals,
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6944 octave_idx_type n = -1)
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6945 {
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6946 typedef typename NDT::element_type T;
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6947 if (n < 0)
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6948 n = idx.extent (0);
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6949 else if (idx.extent (n) > n)
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6950 error ("accumarray: index out of range");
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6951
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14843
diff changeset
6952 NDT retval (dim_vector (n, 1), T ());
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6953
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6954 if (vals.numel () == 1)
9858
47c5af1868df move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents: 9856
diff changeset
6955 retval.idx_add (idx, vals (0));
47c5af1868df move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents: 9856
diff changeset
6956 else if (vals.numel () == idx.length (n))
47c5af1868df move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents: 9856
diff changeset
6957 retval.idx_add (idx, vals);
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6958 else
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6959 error ("accumarray: dimensions mismatch");
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6960
9858
47c5af1868df move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents: 9856
diff changeset
6961 return retval;
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6962 }
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6963
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6964 DEFUN (__accumarray_sum__, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6965 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6966 @deftypefn {} {} __accumarray_sum__ (@var{idx}, @var{vals}, @var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6967 Undocumented internal function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6968 @end deftypefn */)
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6969 {
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6970 int nargin = args.length ();
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6971
22789
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
6972 if (nargin < 2 || nargin > 3)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6973 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6974
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
6975 if (! args(0).isnumeric ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6976 error ("__accumarray_sum__: first argument must be numeric");
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6977
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6978 octave_value retval;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6979
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6980 try
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6981 {
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6982 idx_vector idx = args(0).index_vector ();
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6983 octave_idx_type n = -1;
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6984 if (nargin == 3)
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6985 n = args(2).idx_type_value (true);
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6986
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6987 octave_value vals = args(1);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6988
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6989 if (vals.is_range ())
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6990 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6991 Range r = vals.range_value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6992 if (r.inc () == 0)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6993 vals = r.base ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6994 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6995
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6996 if (vals.is_single_type ())
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6997 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
6998 if (vals.iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6999 retval = do_accumarray_sum (idx,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7000 vals.float_complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7001 n);
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7002 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7003 retval = do_accumarray_sum (idx, vals.float_array_value (), n);
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7004 }
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
7005 else if (vals.isnumeric () || vals.islogical ())
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
7006 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
7007 if (vals.iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7008 retval = do_accumarray_sum (idx,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7009 vals.complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7010 n);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7011 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7012 retval = do_accumarray_sum (idx, vals.array_value (), n);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
7013 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7014 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
7015 err_wrong_type_arg ("accumarray", vals);
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7016 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
7017 catch (const octave::index_exception& e)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7018 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7019 index_error ("__accumarray_sum__: invalid IDX %s. %s",
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7020 e.idx (), e.details ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7021 }
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7022
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7023 return retval;
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7024 }
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7025
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
7026 template <typename NDT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7027 static NDT
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7028 do_accumarray_minmax (const idx_vector& idx, const NDT& vals,
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7029 octave_idx_type n, bool ismin,
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7030 const typename NDT::element_type& zero_val)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7031 {
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7032 typedef typename NDT::element_type T;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7033 if (n < 0)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7034 n = idx.extent (0);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7035 else if (idx.extent (n) > n)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7036 error ("accumarray: index out of range");
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7037
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7038 NDT retval (dim_vector (n, 1), zero_val);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7039
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7040 // Pick minimizer or maximizer.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7041 void (MArray<T>::*op) (const idx_vector&, const MArray<T>&) =
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
7042 ismin ? (&MArray<T>::idx_min) : (&MArray<T>::idx_max);
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7043
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7044 octave_idx_type l = idx.length (n);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7045 if (vals.numel () == 1)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7046 (retval.*op) (idx, NDT (dim_vector (l, 1), vals(0)));
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7047 else if (vals.numel () == l)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7048 (retval.*op) (idx, vals);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7049 else
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7050 error ("accumarray: dimensions mismatch");
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7051
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7052 return retval;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7053 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7054
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7055 static octave_value_list
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7056 do_accumarray_minmax_fun (const octave_value_list& args,
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7057 bool ismin)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7058 {
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7059 int nargin = args.length ();
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7060
22789
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
7061 if (nargin < 3 || nargin > 4)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7062 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7063
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
7064 if (! args(0).isnumeric ())
20811
5979314bb15a Fix BIST tests for rows.
Rik <rik@octave.org>
parents: 20810
diff changeset
7065 error ("accumarray: first argument must be numeric");
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7066
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7067 octave_value retval;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7068
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7069 try
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7070 {
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7071 idx_vector idx = args(0).index_vector ();
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7072 octave_idx_type n = -1;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7073 if (nargin == 4)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7074 n = args(3).idx_type_value (true);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7075
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7076 octave_value vals = args(1);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7077 octave_value zero = args(2);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7078
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7079 switch (vals.builtin_type ())
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7080 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7081 case btyp_double:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7082 retval = do_accumarray_minmax (idx, vals.array_value (), n, ismin,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7083 zero.double_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7084 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7085
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7086 case btyp_float:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7087 retval = do_accumarray_minmax (idx, vals.float_array_value (), n,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7088 ismin, zero.float_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7089 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7090
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7091 case btyp_complex:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7092 retval = do_accumarray_minmax (idx, vals.complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7093 n, ismin, zero.complex_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7094 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7095
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7096 case btyp_float_complex:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7097 retval = do_accumarray_minmax (idx,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7098 vals.float_complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7099 n, ismin,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7100 zero.float_complex_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7101 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7102
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7103 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7104 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7105 retval = do_accumarray_minmax (idx, vals.X ## _array_value (), \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7106 n, ismin, zero.X ## _scalar_value ()); \
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7107 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7108
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7109 MAKE_INT_BRANCH (int8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7110 MAKE_INT_BRANCH (int16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7111 MAKE_INT_BRANCH (int32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7112 MAKE_INT_BRANCH (int64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7113 MAKE_INT_BRANCH (uint8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7114 MAKE_INT_BRANCH (uint16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7115 MAKE_INT_BRANCH (uint32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7116 MAKE_INT_BRANCH (uint64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7117
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7118 #undef MAKE_INT_BRANCH
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7119
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7120 case btyp_bool:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7121 retval = do_accumarray_minmax (idx, vals.array_value (), n, ismin,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7122 zero.bool_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7123 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7124
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7125 default:
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
7126 err_wrong_type_arg ("accumarray", vals);
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7127 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7128 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
7129 catch (const octave::index_exception& e)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7130 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7131 index_error ("do_accumarray_minmax_fun: invalid index %s. %s",
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7132 e.idx (), e.details ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7133 }
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7134
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7135 return retval;
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7136 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7137
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7138 DEFUN (__accumarray_min__, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7139 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7140 @deftypefn {} {} __accumarray_min__ (@var{idx}, @var{vals}, @var{zero}, @var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7141 Undocumented internal function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7142 @end deftypefn */)
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7143 {
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7144 return do_accumarray_minmax_fun (args, true);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7145 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7146
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7147 DEFUN (__accumarray_max__, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7148 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7149 @deftypefn {} {} __accumarray_max__ (@var{idx}, @var{vals}, @var{zero}, @var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7150 Undocumented internal function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7151 @end deftypefn */)
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7152 {
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7153 return do_accumarray_minmax_fun (args, false);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7154 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7155
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
7156 template <typename NDT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7157 static NDT
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7158 do_accumdim_sum (const idx_vector& idx, const NDT& vals,
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7159 int dim = -1, octave_idx_type n = -1)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7160 {
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7161 typedef typename NDT::element_type T;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7162 if (n < 0)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7163 n = idx.extent (0);
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7164 else if (idx.extent (n) > n)
14113
dac62c415e8b Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14100
diff changeset
7165 error ("accumdim: index out of range");
dac62c415e8b Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14100
diff changeset
7166
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17915
diff changeset
7167 dim_vector vals_dim = vals.dims ();
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17915
diff changeset
7168 dim_vector rdv = vals_dim;
14113
dac62c415e8b Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14100
diff changeset
7169
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7170 if (dim < 0)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7171 dim = vals.dims ().first_non_singleton ();
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21602
diff changeset
7172 else if (dim >= rdv.ndims ())
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7173 rdv.resize (dim+1, 1);
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7174
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7175 rdv(dim) = n;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7176
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14843
diff changeset
7177 NDT retval (rdv, T ());
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7178
14113
dac62c415e8b Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14100
diff changeset
7179 if (idx.length () != vals_dim(dim))
dac62c415e8b Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14100
diff changeset
7180 error ("accumdim: dimension mismatch");
dac62c415e8b Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14100
diff changeset
7181
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7182 retval.idx_add_nd (idx, vals, dim);
14113
dac62c415e8b Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14100
diff changeset
7183
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7184 return retval;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7185 }
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7186
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7187 DEFUN (__accumdim_sum__, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7188 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7189 @deftypefn {} {} __accumdim_sum__ (@var{idx}, @var{vals}, @var{dim}, @var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7190 Undocumented internal function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7191 @end deftypefn */)
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7192 {
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7193 int nargin = args.length ();
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7194
22789
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
7195 if (nargin < 2 || nargin > 4)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7196 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7197
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
7198 if (! args(0).isnumeric ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7199 error ("__accumdim_sum__: first argument must be numeric");
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7200
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7201 octave_value retval;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7202
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7203 try
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7204 {
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7205 idx_vector idx = args(0).index_vector ();
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7206 int dim = -1;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7207 if (nargin >= 3)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7208 dim = args(2).int_value () - 1;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7209
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7210 octave_idx_type n = -1;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7211 if (nargin == 4)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7212 n = args(3).idx_type_value (true);
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7213
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7214 octave_value vals = args(1);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7215
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7216 if (vals.is_single_type ())
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7217 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
7218 if (vals.iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7219 retval = do_accumdim_sum (idx,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7220 vals.float_complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7221 dim, n);
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7222 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7223 retval = do_accumdim_sum (idx, vals.float_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7224 dim, n);
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7225 }
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
7226 else if (vals.isnumeric () || vals.islogical ())
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7227 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
7228 if (vals.iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7229 retval = do_accumdim_sum (idx, vals.complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7230 dim, n);
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7231 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7232 retval = do_accumdim_sum (idx, vals.array_value (), dim, n);
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7233 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7234 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
7235 err_wrong_type_arg ("accumdim", vals);
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7236 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
7237 catch (const octave::index_exception& e)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7238 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7239 index_error ("__accumdim_sum__: invalid IDX %s. %s",
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7240 e.idx (), e.details ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7241 }
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7242
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7243 return retval;
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7244 }
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7245
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
7246 template <typename NDT>
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7247 static NDT
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7248 do_merge (const Array<bool>& mask,
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7249 const NDT& tval, const NDT& fval)
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7250 {
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7251 typedef typename NDT::element_type T;
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7252 dim_vector dv = mask.dims ();
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7253 NDT retval (dv);
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7254
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17915
diff changeset
7255 bool tscl = tval.numel () == 1;
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17915
diff changeset
7256 bool fscl = fval.numel () == 1;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7257
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7258 if ((! tscl && tval.dims () != dv) || (! fscl && fval.dims () != dv))
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
7259 error ("merge: MASK, TVAL, and FVAL dimensions must match");
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7260
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7261 T *rv = retval.fortran_vec ();
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7262 octave_idx_type n = retval.numel ();
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7263
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7264 const T *tv = tval.data ();
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7265 const T *fv = fval.data ();
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7266 const bool *mv = mask.data ();
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7267
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7268 if (tscl)
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7269 {
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7270 if (fscl)
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7271 {
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7272 T ts = tv[0];
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7273 T fs = fv[0];
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7274 for (octave_idx_type i = 0; i < n; i++)
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
7275 rv[i] = (mv[i] ? ts : fs);
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7276 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7277 else
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7278 {
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7279 T ts = tv[0];
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7280 for (octave_idx_type i = 0; i < n; i++)
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
7281 rv[i] = (mv[i] ? ts : fv[i]);
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7282 }
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7283 }
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7284 else
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7285 {
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7286 if (fscl)
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7287 {
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7288 T fs = fv[0];
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7289 for (octave_idx_type i = 0; i < n; i++)
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
7290 rv[i] = (mv[i] ? tv[i] : fs);
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7291 }
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7292 else
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7293 {
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7294 for (octave_idx_type i = 0; i < n; i++)
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
7295 rv[i] = (mv[i] ? tv[i] : fv[i]);
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7296 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7297 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7298
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7299 return retval;
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7300 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7301
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7302 #define MAKE_INT_BRANCH(INTX) \
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7303 else if (tval.is_ ## INTX ## _type () && fval.is_ ## INTX ## _type ()) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7304 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7305 retval = do_merge (mask, \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7306 tval.INTX ## _array_value (), \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7307 fval.INTX ## _array_value ()); \
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7308 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7309
9505
a321a1c227c8 make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents: 9475
diff changeset
7310 DEFUN (merge, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7311 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7312 @deftypefn {} {} merge (@var{mask}, @var{tval}, @var{fval})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7313 @deftypefnx {} {} ifelse (@var{mask}, @var{tval}, @var{fval})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7314 Merge elements of @var{true_val} and @var{false_val}, depending on the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7315 value of @var{mask}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7316
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7317 If @var{mask} is a logical scalar, the other two arguments can be arbitrary
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7318 values. Otherwise, @var{mask} must be a logical array, and @var{tval},
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7319 @var{fval} should be arrays of matching class, or cell arrays. In the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7320 scalar mask case, @var{tval} is returned if @var{mask} is true, otherwise
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7321 @var{fval} is returned.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7322
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7323 In the array mask case, both @var{tval} and @var{fval} must be either
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7324 scalars or arrays with dimensions equal to @var{mask}. The result is
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7325 constructed as follows:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7326
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7327 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7328 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7329 result(mask) = tval(mask);
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7330 result(! mask) = fval(! mask);
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7331 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7332 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7333
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7334 @var{mask} can also be arbitrary numeric type, in which case it is first
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7335 converted to logical.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7336 @seealso{logical, diff}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7337 @end deftypefn */)
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7338 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7339 if (args.length () != 3)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7340 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7341
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
7342 if (! (args(0).islogical () || args(0).isnumeric ()))
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7343 error ("merge: first argument must be logical or numeric");
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7344
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7345 octave_value retval;
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7346
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7347 octave_value mask_val = args(0);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7348
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7349 if (mask_val.is_scalar_type ())
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
7350 retval = (mask_val.is_true () ? args(1) : args(2));
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7351 else
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7352 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7353 boolNDArray mask = mask_val.bool_array_value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7354
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7355 octave_value tval = args(1);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7356 octave_value fval = args(2);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7357
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7358 if (tval.is_double_type () && fval.is_double_type ())
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7359 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
7360 if (tval.iscomplex () || fval.iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7361 retval = do_merge (mask,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7362 tval.complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7363 fval.complex_array_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7364 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7365 retval = do_merge (mask,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7366 tval.array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7367 fval.array_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7368 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7369 else if (tval.is_single_type () && fval.is_single_type ())
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7370 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
7371 if (tval.iscomplex () || fval.iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7372 retval = do_merge (mask,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7373 tval.float_complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7374 fval.float_complex_array_value ());
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7375 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7376 retval = do_merge (mask,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7377 tval.float_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7378 fval.float_array_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7379 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7380 else if (tval.is_string () && fval.is_string ())
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7381 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7382 bool sq_string = tval.is_sq_string () || fval.is_sq_string ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7383 retval = octave_value (do_merge (mask,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7384 tval.char_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7385 fval.char_array_value ()),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7386 sq_string ? '\'' : '"');
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7387 }
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23575
diff changeset
7388 else if (tval.iscell () && fval.iscell ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7389 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7390 retval = do_merge (mask,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7391 tval.cell_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7392 fval.cell_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7393 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7394
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
7395 MAKE_INT_BRANCH (int8)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
7396 MAKE_INT_BRANCH (int16)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
7397 MAKE_INT_BRANCH (int32)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
7398 MAKE_INT_BRANCH (int64)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
7399 MAKE_INT_BRANCH (uint8)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
7400 MAKE_INT_BRANCH (uint16)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
7401 MAKE_INT_BRANCH (uint32)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
7402 MAKE_INT_BRANCH (uint64)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7403
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7404 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7405 error ("merge: cannot merge %s with %s with array mask",
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7406 tval.class_name ().c_str (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7407 fval.class_name ().c_str ());
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7408 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7409
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7410 return retval;
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7411 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7412
9505
a321a1c227c8 make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents: 9475
diff changeset
7413 DEFALIAS (ifelse, merge);
a321a1c227c8 make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents: 9475
diff changeset
7414
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7415 #undef MAKE_INT_BRANCH
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7416
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
7417 template <typename SparseT>
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7418 static SparseT
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7419 do_sparse_diff (const SparseT& array, octave_idx_type order,
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7420 int dim)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7421 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7422 SparseT retval = array;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7423 if (dim == 1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7424 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7425 octave_idx_type k = retval.columns ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7426 while (order > 0 && k > 0)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7427 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7428 idx_vector col1 (':'), col2 (':'), sl1 (1, k), sl2 (0, k-1);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7429 retval = SparseT (retval.index (col1, sl1))
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
7430 - SparseT (retval.index (col2, sl2));
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7431 assert (retval.columns () == k-1);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7432 order--;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7433 k--;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7434 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7435 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7436 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7437 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7438 octave_idx_type k = retval.rows ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7439 while (order > 0 && k > 0)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7440 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7441 idx_vector col1 (':'), col2 (':'), sl1 (1, k), sl2 (0, k-1);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7442 retval = SparseT (retval.index (sl1, col1))
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
7443 - SparseT (retval.index (sl2, col2));
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7444 assert (retval.rows () == k-1);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7445 order--;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7446 k--;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7447 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7448 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7449
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7450 return retval;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7451 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7452
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7453 static octave_value
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7454 do_diff (const octave_value& array, octave_idx_type order,
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7455 int dim = -1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7456 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7457 octave_value retval;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7458
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7459 const dim_vector& dv = array.dims ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7460 if (dim == -1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7461 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7462 dim = array.dims ().first_non_singleton ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7463
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21730
diff changeset
7464 // Bother Matlab. This behavior is really wicked.
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7465 if (dv(dim) <= order)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7466 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7467 if (dv(dim) == 1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7468 retval = array.resize (dim_vector (0, 0));
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7469 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7470 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7471 retval = array;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7472 while (order > 0)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7473 {
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21602
diff changeset
7474 if (dim == dv.ndims ())
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7475 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7476 retval = do_diff (array, order, dim - 1);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7477 order = 0;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7478 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7479 else if (dv(dim) == 1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7480 dim++;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7481 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7482 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7483 retval = do_diff (array, dv(dim) - 1, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7484 order -= dv(dim) - 1;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7485 dim++;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7486 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7487 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7488 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7489
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7490 return retval;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7491 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7492 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7493
23580
2230f9e10fb3 maint: Deprecate is_integer_type and replace with isinteger.
Rik <rik@octave.org>
parents: 23579
diff changeset
7494 if (array.isinteger ())
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7495 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7496 if (array.is_int8_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7497 retval = array.int8_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7498 else if (array.is_int16_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7499 retval = array.int16_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7500 else if (array.is_int32_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7501 retval = array.int32_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7502 else if (array.is_int64_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7503 retval = array.int64_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7504 else if (array.is_uint8_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7505 retval = array.uint8_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7506 else if (array.is_uint16_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7507 retval = array.uint16_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7508 else if (array.is_uint32_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7509 retval = array.uint32_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7510 else if (array.is_uint64_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7511 retval = array.uint64_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7512 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7513 panic_impossible ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7514 }
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
7515 else if (array.issparse ())
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7516 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
7517 if (array.iscomplex ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7518 retval = do_sparse_diff (array.sparse_complex_matrix_value (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7519 order, dim);
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7520 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7521 retval = do_sparse_diff (array.sparse_matrix_value (), order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7522 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7523 else if (array.is_single_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7524 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
7525 if (array.iscomplex ())
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7526 retval = array.float_complex_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7527 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7528 retval = array.float_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7529 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7530 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7531 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
7532 if (array.iscomplex ())
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7533 retval = array.complex_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7534 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7535 retval = array.array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7536 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7537
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7538 return retval;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7539 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7540
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7541 DEFUN (diff, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7542 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7543 @deftypefn {} {} diff (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7544 @deftypefnx {} {} diff (@var{x}, @var{k})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7545 @deftypefnx {} {} diff (@var{x}, @var{k}, @var{dim})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7546 If @var{x} is a vector of length @math{n}, @w{@code{diff (@var{x})}} is the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7547 vector of first differences
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7548 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7549 $x_2 - x_1, \ldots{}, x_n - x_{n-1}$.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7550 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7551 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7552 @var{x}(2) - @var{x}(1), @dots{}, @var{x}(n) - @var{x}(n-1).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7553 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7554
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7555 If @var{x} is a matrix, @w{@code{diff (@var{x})}} is the matrix of column
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7556 differences along the first non-singleton dimension.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7557
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7558 The second argument is optional. If supplied,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7559 @w{@code{diff (@var{x}, @var{k})}}, where @var{k} is a non-negative integer,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7560 returns the @var{k}-th differences. It is possible that @var{k} is larger
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7561 than the first non-singleton dimension of the matrix. In this case,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7562 @code{diff} continues to take the differences along the next
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7563 non-singleton dimension.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7564
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7565 The dimension along which to take the difference can be explicitly
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7566 stated with the optional variable @var{dim}. In this case the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7567 @var{k}-th order differences are calculated along this dimension.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7568 In the case where @var{k} exceeds @w{@code{size (@var{x}, @var{dim})}}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7569 an empty matrix is returned.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7570 @seealso{sort, merge}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7571 @end deftypefn */)
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7572 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7573 int nargin = args.length ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7574
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7575 if (nargin < 1 || nargin > 3)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7576 print_usage ();
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7577
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
7578 if (! (args(0).isnumeric () || args(0).islogical ()))
10880
92c3e8068f28 allow diff(logical)
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
7579 error ("diff: X must be numeric or logical");
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7580
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
7581 int dim = -1;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
7582 octave_idx_type order = 1;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
7583 if (nargin > 1)
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7584 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
7585 if (args(1).is_scalar_type ())
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
7586 order = args(1).idx_type_value (true, false);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
7587 else if (! args(1).is_zero_by_zero ())
20726
25d676f9619c Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents: 20720
diff changeset
7588 error ("diff: order K must be a scalar or []");
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
7589 if (order < 0)
20726
25d676f9619c Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents: 20720
diff changeset
7590 error ("diff: order K must be non-negative");
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7591 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7592
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
7593 if (nargin > 2)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
7594 {
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
7595 dim = args(2).int_value (true, false);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
7596 if (dim < 1 || dim > args(0).ndims ())
20726
25d676f9619c Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents: 20720
diff changeset
7597 error ("diff: DIM must be a valid dimension");
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
7598
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
7599 dim -= 1;
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
7600 }
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
7601
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7602 return do_diff (args(0), order, dim);
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7603 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7604
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7605 /*
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7606 %!assert (diff ([1, 2, 3, 4]), [1, 1, 1])
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7607 %!assert (diff ([1, 3, 7, 19], 2), [2, 8])
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7608 %!assert (diff ([1, 2; 5, 4; 8, 7; 9, 6; 3, 1]), [4, 2; 3, 3; 1, -1; -6, -5])
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7609 %!assert (diff ([1, 2; 5, 4; 8, 7; 9, 6; 3, 1], 3), [-1, -5; -5, 0])
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7610 %!assert (isempty (diff (1)))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7611
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7612 %!error diff ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7613 %!error diff (1, 2, 3, 4)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7614 %!error diff ("foo")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7615 %!error diff ([1, 2; 3, 4], -1)
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7616 */
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7617
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
7618 template <typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7619 static Array<T>
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7620 do_repelems (const Array<T>& src, const Array<octave_idx_type>& rep)
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7621 {
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7622 Array<T> retval;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7623
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7624 assert (rep.ndims () == 2 && rep.rows () == 2);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7625
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17915
diff changeset
7626 octave_idx_type n = rep.columns ();
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17915
diff changeset
7627 octave_idx_type l = 0;
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7628 for (octave_idx_type i = 0; i < n; i++)
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7629 {
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7630 octave_idx_type k = rep(1, i);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7631 if (k < 0)
20893
384ff5aa9437 2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents: 20884
diff changeset
7632 error ("repelems: second row must contain non-negative numbers");
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7633
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7634 l += k;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7635 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7636
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7637 retval.clear (1, l);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7638 T *dest = retval.fortran_vec ();
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7639 l = 0;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7640 for (octave_idx_type i = 0; i < n; i++)
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7641 {
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7642 octave_idx_type k = rep(1, i);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7643 std::fill_n (dest, k, src.checkelem (rep(0, i) - 1));
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7644 dest += k;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7645 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7646
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7647 return retval;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7648 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7649
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7650 DEFUN (repelems, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7651 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7652 @deftypefn {} {} repelems (@var{x}, @var{r})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7653 Construct a vector of repeated elements from @var{x}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7654
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7655 @var{r} is a 2x@var{N} integer matrix specifying which elements to repeat
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7656 and how often to repeat each element. Entries in the first row,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7657 @var{r}(1,j), select an element to repeat. The corresponding entry in the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7658 second row, @var{r}(2,j), specifies the repeat count. If @var{x} is a
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7659 matrix then the columns of @var{x} are imagined to be stacked on top of
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7660 each other for purposes of the selection index. A row vector is always
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7661 returned.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7662
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7663 Conceptually the result is calculated as follows:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7664
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7665 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7666 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7667 y = [];
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7668 for i = 1:columns (@var{r})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7669 y = [y, @var{x}(@var{r}(1,i)*ones(1, @var{r}(2,i)))];
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7670 endfor
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7671 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7672 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7673 @seealso{repmat, cat}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7674 @end deftypefn */)
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7675 {
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7676 if (args.length () != 2)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7677 print_usage ();
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7678
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7679 octave_value retval;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7680
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7681 const Matrix rm = args(1).matrix_value ();
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7682
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7683 if (rm.rows () != 2 || rm.ndims () != 2)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7684 error ("repelems: R must be a matrix with two rows");
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7685
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7686 octave_value x = args(0);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7687
23534
b6498c088fca maint: Don't write '> >' for declaration of templates that use templates.
Rik <rik@octave.org>
parents: 23515
diff changeset
7688 NoAlias< Array<octave_idx_type>> r (rm.dims ());
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7689
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7690 for (octave_idx_type i = 0; i < rm.numel (); i++)
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7691 {
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7692 octave_idx_type rx = rm(i);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7693 if (static_cast<double> (rx) != rm(i))
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7694 error ("repelems: R must be a matrix of integers");
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7695
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7696 r(i) = rx;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7697 }
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7698
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7699 switch (x.builtin_type ())
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7700 {
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7701 #define BTYP_BRANCH(X, EX) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7702 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7703 retval = do_repelems (x.EX ## _value (), r); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7704 break;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7705
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7706 BTYP_BRANCH (double, array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7707 BTYP_BRANCH (float, float_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7708 BTYP_BRANCH (complex, complex_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7709 BTYP_BRANCH (float_complex, float_complex_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7710 BTYP_BRANCH (bool, bool_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7711 BTYP_BRANCH (char, char_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7712
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7713 BTYP_BRANCH (int8, int8_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7714 BTYP_BRANCH (int16, int16_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7715 BTYP_BRANCH (int32, int32_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7716 BTYP_BRANCH (int64, int64_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7717 BTYP_BRANCH (uint8, uint8_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7718 BTYP_BRANCH (uint16, uint16_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7719 BTYP_BRANCH (uint32, uint32_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7720 BTYP_BRANCH (uint64, uint64_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7721
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7722 BTYP_BRANCH (cell, cell);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7723 //BTYP_BRANCH (struct, map);//FIXME
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7724
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7725 #undef BTYP_BRANCH
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7726
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7727 default:
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
7728 err_wrong_type_arg ("repelems", x);
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7729 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7730
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7731 return retval;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7732 }
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7733
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
7734 DEFUN (base64_encode, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7735 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7736 @deftypefn {} {@var{s} =} base64_encode (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7737 Encode a double matrix or array @var{x} into the base64 format string
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7738 @var{s}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7739
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7740 @seealso{base64_decode}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7741 @end deftypefn */)
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7742 {
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20816
diff changeset
7743 if (args.length () != 1)
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7744 print_usage ();
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7745
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
7746 if (! args(0).isnumeric ())
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7747 error ("base64_encode: encoding is supported only for numeric arrays");
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
7748
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
7749 if (args(0).iscomplex () || args(0).issparse ())
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7750 error ("base64_encode: encoding complex or sparse data is not supported");
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7751
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7752 octave_value_list retval;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7753
23580
2230f9e10fb3 maint: Deprecate is_integer_type and replace with isinteger.
Rik <rik@octave.org>
parents: 23579
diff changeset
7754 if (args(0).isinteger ())
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7755 {
23447
db1fdf4384dd maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents: 23289
diff changeset
7756 #define MAKE_INT_BRANCH(X) \
db1fdf4384dd maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents: 23289
diff changeset
7757 if (args(0).is_ ## X ## _type ()) \
db1fdf4384dd maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents: 23289
diff changeset
7758 { \
db1fdf4384dd maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents: 23289
diff changeset
7759 const X##NDArray in = args(0). X## _array_value (); \
db1fdf4384dd maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents: 23289
diff changeset
7760 size_t inlen = in.numel () * sizeof (X## _t) / sizeof (char); \
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
7761 const char *inc = reinterpret_cast<const char *> (in.data ()); \
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
7762 char *out; \
23748
6e86d3b5a063 move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23734
diff changeset
7763 if (octave::base64_encode (inc, inlen, &out)) \
23447
db1fdf4384dd maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents: 23289
diff changeset
7764 { \
db1fdf4384dd maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents: 23289
diff changeset
7765 retval(0) = octave_value (out); \
db1fdf4384dd maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents: 23289
diff changeset
7766 ::free (out); \
db1fdf4384dd maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents: 23289
diff changeset
7767 } \
15111
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7768 }
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7769
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7770 MAKE_INT_BRANCH(int8)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7771 else MAKE_INT_BRANCH(int16)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7772 else MAKE_INT_BRANCH(int32)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7773 else MAKE_INT_BRANCH(int64)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7774 else MAKE_INT_BRANCH(uint8)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7775 else MAKE_INT_BRANCH(uint16)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7776 else MAKE_INT_BRANCH(uint32)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7777 else MAKE_INT_BRANCH(uint64)
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7778
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7779 #undef MAKE_INT_BRANCH
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7780
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7781 else
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7782 panic_impossible ();
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7783 }
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7784 else if (args(0).is_single_type ())
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7785 {
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7786 const Array<float> in = args(0).float_array_value ();
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7787 size_t inlen;
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7788 inlen = in.numel () * sizeof (float) / sizeof (char);
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7789 const char* inc;
23447
db1fdf4384dd maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents: 23289
diff changeset
7790 inc = reinterpret_cast<const char *> (in.data ());
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
7791 char *out;
23748
6e86d3b5a063 move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23734
diff changeset
7792 if (octave::base64_encode (inc, inlen, &out))
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7793 {
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7794 retval(0) = octave_value (out);
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7795 ::free (out);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7796 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7797 }
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7798 else // double_type
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7799 {
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7800 const Array<double> in = args(0).array_value ();
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7801 size_t inlen;
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7802 inlen = in.numel () * sizeof (double) / sizeof (char);
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7803 const char* inc;
23447
db1fdf4384dd maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents: 23289
diff changeset
7804 inc = reinterpret_cast<const char *> (in.data ());
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
7805 char *out;
23748
6e86d3b5a063 move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23734
diff changeset
7806 if (octave::base64_encode (inc, inlen, &out))
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7807 {
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7808 retval(0) = octave_value (out);
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7809 ::free (out);
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7810 }
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7811 }
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7812
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7813 return retval;
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7814 }
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7815
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7816 /*
21458
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
7817 %!test
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
7818 %! ## FIXME: better test for endianness?
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
7819 %! if (bitunpack (uint16 (1))(1) == 1)
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
7820 %! expected = "2w9JQA==";
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
7821 %! else
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
7822 %! expected = "QEkP2w==";
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
7823 %! endif
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
7824 %! assert (base64_encode (single (pi)), expected);
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
7825
15111
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7826 %!assert (base64_encode (uint8 ([0 0 0])), "AAAA")
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7827 %!assert (base64_encode (uint16 ([0 0 0])), "AAAAAAAA")
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7828 %!assert (base64_encode (uint32 ([0 0 0])), "AAAAAAAAAAAAAAAA")
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7829 %!assert (base64_encode (uint64 ([0 0 0])), "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7830 %!assert (base64_encode (uint8 ([255 255 255])), "////")
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7831
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7832 %!error base64_encode ()
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7833 %!error base64_encode (1,2)
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7834 %!error base64_encode ("A string")
15111
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7835 %!error base64_encode ({"A cell array"})
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7836 %!error base64_encode (struct ())
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7837 */
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7838
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
7839 DEFUN (base64_decode, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7840 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7841 @deftypefn {} {@var{x} =} base64_decode (@var{s})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7842 @deftypefnx {} {@var{x} =} base64_decode (@var{s}, @var{dims})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7843 Decode the double matrix or array @var{x} from the base64 encoded string
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7844 @var{s}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7845
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7846 The optional input parameter @var{dims} should be a vector containing the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7847 dimensions of the decoded array.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7848 @seealso{base64_encode}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7849 @end deftypefn */)
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7850 {
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7851 int nargin = args.length ();
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7852
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7853 if (nargin < 1 || nargin > 2)
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7854 print_usage ();
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7855
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7856 std::string str = args(0).string_value ();
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7857
23748
6e86d3b5a063 move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23734
diff changeset
7858 Array<double> retval = octave::base64_decode (str);
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7859
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7860 if (nargin == 2)
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7861 {
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
7862 dim_vector dims;
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7863
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7864 const Array<octave_idx_type> size =
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7865 args(1).octave_idx_type_vector_value ();
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7866
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7867 dims = dim_vector::alloc (size.numel ());
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7868 for (octave_idx_type i = 0; i < size.numel (); i++)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7869 dims(i) = size(i);
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7870
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
7871 retval = retval.reshape (dims);
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7872 }
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7873
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
7874 return ovl (retval);
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7875 }
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7876
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7877 /*
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7878 %!assert (base64_decode (base64_encode (pi)), pi)
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7879 %!
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7880 %!test
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7881 %! in = randn (10);
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7882 %! outv = base64_decode (base64_encode (in));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7883 %! outm = base64_decode (base64_encode (in), size (in));
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7884 %! assert (outv, in(:).');
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7885 %! assert (outm, in);
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7886
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7887 %!error base64_decode ()
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7888 %!error base64_decode (1,2,3)
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7889 %!error base64_decode (1, "this is not a valid set of dimensions")
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7890 %!error <input was not valid base64> base64_decode (1)
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7891 %!error <input was not valid base64> base64_decode ("AQ=")
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7892 %!error <incorrect input size> base64_decode ("AQ==")
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7893 */